Skip to content

Commit

Permalink
Ok, I can print keys and know when I need to train again dynamically …
Browse files Browse the repository at this point in the history
…without breaking CI. I need to test multiple trainings from a client with kubexec
  • Loading branch information
AndrewQuijano committed Jun 20, 2023
1 parent b8497ba commit 24f732e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,9 @@ To get the results, access the logs as described in the previous steps for both
#### Re-running with different experiments
- *Case 1: Re-run with different testing set*
First, you need to edit the `client_testing_job.yaml` file to point to both the new VALUES file.
Also, you should set the environment variable `TEST_AGAIN` to `1`.
As the job created the pod, you would connect to the pod and run the modified gradle command with the other VALUES file.
```bash
# Delete job and re-run evaluation
kubectl delete -f k8/client
kubectl apply -f k8/client
kubectl exec <CLIENT-SITE-POD> -- bash -c "gradle run -PchooseRole=weka.finito.client --args <NEW-VALUES-FILE>"
```
- *Case 2: Train level-sites with new DT and new testing set*
First, you need to edit the `client_testing_job.yaml` file to point to a new VALUES file.
Expand Down
3 changes: 0 additions & 3 deletions k8/client/client_testing_job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ spec:
- name: SERVER
value: "ppdt-server-site-service"

- name: TEST_AGAIN
value: "0"

- name: GRADLE_USER_HOME
value: "gradle_user_home"

Expand Down
54 changes: 28 additions & 26 deletions src/main/java/weka/finito/client.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class client implements Runnable {
private DGKPrivateKey dgk_private_key;
private PaillierPrivateKey paillier_private_key;
private final HashMap<String, String> hashed_classification = new HashMap<>();
private final boolean talk_to_server_site;
private boolean talk_to_server_site;
private final String server_ip;
private final int server_port;

Expand All @@ -59,7 +59,6 @@ public static void main(String[] args) {
int key_size = -1;
int precision = -1;
int port = -1;
int test_again = -1;
String level_site_string;
String server_ip;

Expand Down Expand Up @@ -98,29 +97,21 @@ public static void main(String[] args) {
System.exit(1);
}

try {
test_again = Integer.parseInt(System.getenv("TEST_AGAIN"));
} catch (NumberFormatException e) {
System.out.println("No integer value for repeat provided.");
System.exit(1);
}

client test = null;
if (args.length == 1) {
test = new client(key_size, args[0], level_domains, port, precision,server_ip, port, test_again == 1);
test = new client(key_size, args[0], level_domains, port, precision,server_ip, port);
}
else {
System.out.println("Missing Testing Data set as an argument parameter");
System.exit(1);
}
test.read_keys();
test.run();
System.exit(0);
}

// For local host testing
// For local host testing with GitHub Actions
public client(int key_size, String features_file, String [] level_site_ips, int [] level_site_ports,
int precision, String server_ip, int server_port, boolean talk_to_server_site) {
int precision, String server_ip, int server_port) {
this.key_size = key_size;
this.features_file = features_file;
this.level_site_ips = level_site_ips;
Expand All @@ -129,11 +120,11 @@ public client(int key_size, String features_file, String [] level_site_ips, int
this.port = -1;
this.server_ip = server_ip;
this.server_port = server_port;
this.talk_to_server_site = talk_to_server_site;
}

// Testing using Kubernetes
public client(int key_size, String features_file, String [] level_site_ips, int port,
int precision, String server_ip, int server_port, boolean talk_to_server_site) {
int precision, String server_ip, int server_port) {
this.key_size = key_size;
this.features_file = features_file;
this.level_site_ips = level_site_ips;
Expand All @@ -142,7 +133,6 @@ public client(int key_size, String features_file, String [] level_site_ips, int
this.port = port;
this.server_ip = server_ip;
this.server_port = server_port;
this.talk_to_server_site = talk_to_server_site;
}

public void generate_keys() {
Expand All @@ -159,11 +149,6 @@ public void generate_keys() {
paillier_public_key = (PaillierPublicKey) paillier.getPublic();
dgk_private_key = (DGKPrivateKey) dgk.getPrivate();
paillier_private_key = (PaillierPrivateKey) paillier.getPrivate();

//dgk_public_key.writeKey("dgk.pub");
//paillier_public_key.writeKey("paillier.pub");
//dgk_private_key.writeKey("dgk");
//paillier_private_key.writeKey("paillier");
}

public static String hash(String text) throws NoSuchAlgorithmException {
Expand All @@ -172,11 +157,17 @@ public static String hash(String text) throws NoSuchAlgorithmException {
return Base64.getEncoder().encodeToString(hash);
}

private void read_keys() {
dgk_public_key = DGKPublicKey.readKey("dgk.pub");
paillier_public_key = PaillierPublicKey.readKey("paillier.pub");
dgk_private_key = DGKPrivateKey.readKey("dgk");
paillier_private_key = PaillierPrivateKey.readKey("paillier");
private boolean need_keys() {
try {
dgk_public_key = DGKPublicKey.readKey("dgk.pub");
paillier_public_key = PaillierPublicKey.readKey("paillier.pub");
dgk_private_key = DGKPrivateKey.readKey("dgk");
paillier_private_key = PaillierPrivateKey.readKey("paillier");
return false;
}
catch (RuntimeException e) {
return true;
}
}

// Used for set-up
Expand Down Expand Up @@ -319,12 +310,17 @@ else if (comparison_type == 1) {

// Function used to Evaluate
public void run() {
this.talk_to_server_site = this.need_keys();

try {
// Don't regenerate keys if you are just using a different VALUES file
if (talk_to_server_site) {
System.out.println("Need to generate keys...");
generate_keys();
}
else {
System.out.println("I already read the keys from a file made from a previous run...");
}

feature = read_features(features_file, paillier_public_key, dgk_public_key, precision);

Expand Down Expand Up @@ -379,5 +375,11 @@ public void run() {
catch (Exception e) {
throw new RuntimeException(e);
}

// At the end, write your keys...
dgk_public_key.writeKey("dgk.pub");
paillier_public_key.writeKey("paillier.pub");
dgk_private_key.writeKey("dgk");
paillier_private_key.writeKey("paillier");
}
}
18 changes: 16 additions & 2 deletions src/test/java/PrivacyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class PrivacyTest {
private String data_directory;
private int server_port;
private String server_ip;

private final static String [] delete_files = {"dgk", "dgk.pub", "paillier", "paillier.pub"};
@Before
public void read_properties() throws IOException {
// Arguments:
Expand Down Expand Up @@ -96,7 +96,7 @@ public static String test_case(String training_data, String features_file, int l

// Create client
client evaluate = new client(key_size, features_file, level_site_ips, level_site_ports, precision,
server_ip, server_port, true);
server_ip, server_port);
Thread client = new Thread(evaluate);
client.start();

Expand All @@ -108,7 +108,21 @@ public static String test_case(String training_data, String features_file, int l
for (level_site_server levelSite : level_sites) {
levelSite.stop();
}
// Be sure to delete any keys you made...
for (String file: delete_files) {
delete_file(file);
}

return evaluate.getClassification();
}

public static void delete_file(String file_name){
File myObj = new File(file_name);
if (myObj.delete()) {
System.out.println("Deleted the file: " + myObj.getName());
} else {
System.out.println("Failed to delete the file.");
}
}
}

0 comments on commit 24f732e

Please sign in to comment.