From 93dd589450bb61e57588065f03d1582f0ffc2f6a Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Tue, 28 Jan 2020 02:09:08 +0000 Subject: Fix contact selection and add excessive logs --- .../mimuw/cloudatlas/agent/HierarchyConfig.java | 42 ++++++++++++++++------ .../mimuw/cloudatlas/client/ClientController.java | 11 ++++++ 2 files changed, 43 insertions(+), 10 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java index 1087b8a..11d6ef0 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java @@ -50,8 +50,10 @@ public class HierarchyConfig { PathName gossipLevel = gossipGirlStrategies.selectStrategy(zoneSelectionStrategy); ValueContact contact; if (random.nextDouble() < 0.2) { + System.out.println("FORCING FALLBACK"); contact = selectFallbackContact(state.getContacts()); } else { + System.out.println("LOOKING FOR CONTACT"); contact = selectContactFromLevel(gossipLevel, state); } @@ -66,6 +68,7 @@ public class HierarchyConfig { System.out.println("Interrupted while initiating gossip"); } catch (Exception e) { System.out.println("ERROR: something happened " + e.toString()); + e.printStackTrace(); } } }; @@ -77,13 +80,21 @@ public class HierarchyConfig { ZMI root = state.getZMI(); List siblings = getSiblings(root, path); filterEmptyContacts(siblings); + System.out.println("filtered siblings: " + siblings.toString()); if (siblings.isEmpty()) { + System.out.println("SIBLINGS IS EMPTY!!!"); return selectFallbackContact(state.getContacts()); } ZMI zmi = selectZMI(siblings); + System.out.println("SELECTED: " + zmi.toString()); ValueSet contactsValue = (ValueSet) zmi.getAttributes().getOrNull("contacts"); - Set valueSet = contactsValue.getValue(); + System.out.println("ITS CONTACTS: " + contactsValue.toString()); + Set valueSetOrig = contactsValue.getValue(); + System.out.println("valueSetOrig: " + valueSetOrig.toString()); + Set valueSet = new HashSet(valueSetOrig); + System.out.println("valueSet: " + valueSet.toString()); filterOurContact(valueSet); + System.out.println("FILTERED VALUE SET: " + valueSet.toString()); return selectContactFromSet(valueSet); } @@ -93,7 +104,7 @@ public class HierarchyConfig { Value value = (Value) it.next(); if (value.getType().getPrimaryType() == Type.PrimaryType.CONTACT) { ValueContact contact = (ValueContact) value; - if (!contact.getName().equals(ourPath)) { + if (contact.getName().equals(ourPath)) { it.remove(); } } else { @@ -129,7 +140,12 @@ public class HierarchyConfig { } private ValueContact selectContactFromSet(Set contacts) throws Exception { + if (contacts.size() == 0) { + System.out.println("GOT EMPTY SET FOR SELECTION"); + return null; + } int i = random.nextInt(contacts.size()); + System.out.println("ROLLED RANDOM: " + Integer.toString(i)); for (T contact : contacts) { if (i == 0) { return (ValueContact) contact; @@ -142,13 +158,14 @@ public class HierarchyConfig { private List getSiblings(ZMI root, PathName path) { try { - List siblingsAndI = root.findDescendant(path).getFather().getSons(); + System.out.println("DEBUG: path in getSiblings: " + path.toString()); + List siblingsImm = root.findDescendant(path).getFather().getSons(); + System.out.println("DEBUG: siblingsImm: " + siblingsImm.toString()); List siblings = new ArrayList(); - for (ZMI siblingOrI : siblingsAndI) { - if (!siblingOrI.getPathName().equals(path)) { - siblings.add(siblingOrI); - } + for (ZMI siblingOrI : siblingsImm) { + siblings.add(siblingOrI); } + System.out.println("found siblings: " + siblings.toString()); return siblings; } catch (ZMI.NoSuchZoneException e) { System.out.println("ERROR: didn't find path when looking for siblings"); @@ -161,9 +178,14 @@ public class HierarchyConfig { while (iterator.hasNext()) { ZMI zmi = iterator.next(); ValueSet contacts = (ValueSet) zmi.getAttributes().getOrNull("contacts"); + System.out.println("checking zmi " + zmi.toString()); + System.out.println("its contacts: " + contacts.toString()); if (contacts == null || contacts.isNull() || contacts.isEmpty() || onlyContactIsUs(contacts)) { + System.out.println("Let's remove it!"); iterator.remove(); - } + } else { + System.out.println("Let's keep it!"); + } } } @@ -172,14 +194,14 @@ public class HierarchyConfig { if (value.getType().getPrimaryType() == Type.PrimaryType.CONTACT) { ValueContact contact = (ValueContact) value; if (!contact.getName().equals(ourPath)) { - return true; + return false; } } else { System.out.println("WARN: non contact value passed to onlyContactIsUs"); } } - return false; + return true; } public void startQueries(long queriesPeriod) { diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java index b11a8b7..bbdb8dc 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -45,10 +45,21 @@ public class ClientController { String agentHostname = System.getProperty("agent_hostname"); Registry registry = LocateRegistry.getRegistry(agentHostname); this.agentApi = (Api) registry.lookup("Api"); + System.out.println("agent api:"); + System.out.println(this.agentApi); String querySignerHostname = System.getProperty("query_signer_hostname"); Registry querySignerRegistry = LocateRegistry.getRegistry(querySignerHostname); + System.out.println("querySignerHostname: " + querySignerHostname); + System.out.println(InetAddress.getByName("localhost")); + System.out.println(InetAddress.getByName(querySignerHostname)); + System.out.println("LIST:"); + System.out.println(querySignerRegistry.list()); + System.out.println("registry:"); + System.out.println(querySignerRegistry); this.querySignerApi = (QuerySignerApi) querySignerRegistry.lookup("QuerySignerApi"); + System.out.println("api:"); + System.out.println(this.querySignerApi); } catch (Exception e) { System.err.println("Client exception:"); e.printStackTrace(); -- cgit v1.2.3