From 7f7167c007a4c18331a23849e6e7e489b038f2e3 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 27 Jan 2020 17:49:24 +0100 Subject: Rename own address flag --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 201f249..3ff04f2 100644 --- a/build.gradle +++ b/build.gradle @@ -59,7 +59,7 @@ ext.fallbackContacts = { } ext.ownAddr = { - return System.getProperty("ownZone") ?: "localhost" + return System.getProperty("ownAddr") ?: "localhost" } /* -- cgit v1.2.3 From 336a924911fdb6ed832c5245c7f02c2f7556dfba Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 27 Jan 2020 17:49:40 +0100 Subject: Set default fallback contacts to empty set --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3ff04f2..143bae9 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ Example: -DfallbackContacts=\{\"/uw/violet07\":[192,168,0,11]} escape at the beginning and before " */ ext.fallbackContacts = { - return System.getProperty("fallbackContacts") ?: "{\"" + zonePath() + "\":[127,0,0,1]}" + return System.getProperty("fallbackContacts") ?: "{}" } ext.ownAddr = { -- cgit v1.2.3 From e3599820c3a2bcd85053f186128ba65d0ceab5a9 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 27 Jan 2020 17:49:53 +0100 Subject: Set leaf contacts regularly --- src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java b/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java index 096e4e3..8916b13 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java @@ -114,9 +114,12 @@ public class Fetcher { api.setFallbackContacts(ClientController.parseContactsString(fallbackContactsString)); ValueContact initialContact = new ValueContact(new PathName(zonePath), InetAddress.getByName(ownAddr)); - api.setAttributeValue(zonePath, "contacts", initialContact); + Set initialContacts = new HashSet(); + initialContacts.add(initialContact); + ValueSet initialContactsValue = new ValueSet(initialContacts, TypePrimitive.CONTACT); while((jsonAttribs = bufferRead.readLine()) != null) { + api.setAttributeValue(zonePath, "contacts", initialContactsValue); System.out.println(jsonAttribs); System.out.flush(); deserializedAttribs = deserializeAttribs(jsonAttribs); -- cgit v1.2.3 From 1383166dd80b8cec4d7b20e81725eaa219717d5d Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 27 Jan 2020 18:29:26 +0100 Subject: Filter our contact when gossipping --- .../mimuw/cloudatlas/agent/HierarchyConfig.java | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) 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 4d8842f..1087b8a 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/HierarchyConfig.java @@ -14,11 +14,13 @@ public class HierarchyConfig { private GossipGirlStrategies gossipGirlStrategies; private GossipGirlStrategies.ZoneSelectionStrategy zoneSelectionStrategy; private Random random = new Random(); + private PathName ourPath; private EventBus eventBus; HierarchyConfig(EventBus eventBus, String zonePath, String zoneStrategy) { zoneSelectionStrategy = parseStrategy(zoneStrategy); - gossipGirlStrategies = new GossipGirlStrategies(new PathName(zonePath)); + ourPath = new PathName(zonePath); + gossipGirlStrategies = new GossipGirlStrategies(ourPath); this.eventBus = eventBus; } @@ -81,9 +83,25 @@ public class HierarchyConfig { ZMI zmi = selectZMI(siblings); ValueSet contactsValue = (ValueSet) zmi.getAttributes().getOrNull("contacts"); Set valueSet = contactsValue.getValue(); + filterOurContact(valueSet); return selectContactFromSet(valueSet); } + private void filterOurContact(Set contacts) { + Iterator it = contacts.iterator(); + while (it.hasNext()) { + Value value = (Value) it.next(); + if (value.getType().getPrimaryType() == Type.PrimaryType.CONTACT) { + ValueContact contact = (ValueContact) value; + if (!contact.getName().equals(ourPath)) { + it.remove(); + } + } else { + System.out.println("WARN: non contact value passed to filterOurContact"); + } + } + } + private StateMessage getState() throws Exception { CompletableFuture responseFuture = new CompletableFuture(); this.eventBus.addMessage(new RequestStateMessage("", 0, responseFuture)); @@ -143,12 +161,27 @@ public class HierarchyConfig { while (iterator.hasNext()) { ZMI zmi = iterator.next(); ValueSet contacts = (ValueSet) zmi.getAttributes().getOrNull("contacts"); - if (contacts == null || contacts.isNull() || contacts.isEmpty()) { + if (contacts == null || contacts.isNull() || contacts.isEmpty() || onlyContactIsUs(contacts)) { iterator.remove(); } } } + private boolean onlyContactIsUs(ValueSet contacts) { + for (Value value : contacts) { + if (value.getType().getPrimaryType() == Type.PrimaryType.CONTACT) { + ValueContact contact = (ValueContact) value; + if (!contact.getName().equals(ourPath)) { + return true; + } + } else { + System.out.println("WARN: non contact value passed to onlyContactIsUs"); + } + } + + return false; + } + public void startQueries(long queriesPeriod) { Supplier taskSupplier = () -> new TimerScheduledTask() { -- cgit v1.2.3