From 4915d1781a22713f466980d2235c12557374926b Mon Sep 17 00:00:00 2001 From: f1ori Date: Mon, 6 Dec 2010 11:09:16 +0000 Subject: [PATCH] * use local backup-file, if remote network-definition is not availible * resolve single point of failure in networks, managed by central network-definitions git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7363 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/ConfigBasic.java | 4 +- htroot/ConfigNetwork_p.java | 4 +- source/de/anomic/search/Switchboard.java | 47 +++++--------------- source/net/yacy/kelondro/util/FileUtils.java | 5 +++ 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/htroot/ConfigBasic.java b/htroot/ConfigBasic.java index 18090606b..c100badb9 100644 --- a/htroot/ConfigBasic.java +++ b/htroot/ConfigBasic.java @@ -29,6 +29,8 @@ // if the shell's current path is HTROOT import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.regex.Pattern; import net.yacy.cora.protocol.Domains; @@ -56,7 +58,7 @@ public class ConfigBasic { private static final int NEXTSTEP_PEERPORT = 3; private static final int NEXTSTEP_RECONNECT = 4; - public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { + public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws FileNotFoundException, IOException { // return variable that accumulates replacements final Switchboard sb = (Switchboard) env; diff --git a/htroot/ConfigNetwork_p.java b/htroot/ConfigNetwork_p.java index 816f15d3b..a1797d23f 100644 --- a/htroot/ConfigNetwork_p.java +++ b/htroot/ConfigNetwork_p.java @@ -26,6 +26,8 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Set; import net.yacy.cora.protocol.RequestHeader; @@ -41,7 +43,7 @@ import de.anomic.server.serverSwitch; public class ConfigNetwork_p { - public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { + public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws FileNotFoundException, IOException { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java index a2e3c578d..354fbc6b9 100644 --- a/source/de/anomic/search/Switchboard.java +++ b/source/de/anomic/search/Switchboard.java @@ -693,7 +693,7 @@ public final class Switchboard extends serverSwitch { this.indexingStorageProcessor.queueSize(); } - public void overwriteNetworkDefinition() { + public void overwriteNetworkDefinition() throws FileNotFoundException, IOException { // load network configuration into settings String networkUnitDefinition = getConfig("network.unit.definition", "defaults/yacy.network.freeworld.unit"); @@ -722,40 +722,15 @@ public final class Switchboard extends serverSwitch { // the network definition should be made either consistent for all peers, // or independently using a bootstrap URL Map initProps; - if (networkUnitDefinition.startsWith("http://")) { - // multiple definitions may be given, split the definition line in multiple addresses - String[] netdefs = networkUnitDefinition.split(","); - Map netdefmap; - netload: for (String netdef: netdefs) { - netdef = netdef.trim(); - try { - netdefmap = Switchboard.loadFileAsMap(new DigestURI(netdef)); - if (netdefmap == null || netdefmap.isEmpty()) continue netload; - setConfig(netdefmap); - break netload; - } catch (final Exception e) { - continue netload; - } - } - } else { - final File networkUnitDefinitionFile = (networkUnitDefinition.length() > 0 && networkUnitDefinition.charAt(0) == '/') ? new File(networkUnitDefinition) : new File(getAppPath(), networkUnitDefinition); - if (networkUnitDefinitionFile.exists()) { - initProps = FileUtils.loadMap(networkUnitDefinitionFile); - setConfig(initProps); - } - } - if (networkGroupDefinition.startsWith("http://")) { - try { - setConfig(Switchboard.loadFileAsMap(new DigestURI(networkGroupDefinition))); - } catch (final MalformedURLException e) { } - } else { - final File networkGroupDefinitionFile = new File(getAppPath(), networkGroupDefinition); - if (networkGroupDefinitionFile.exists()) { - initProps = FileUtils.loadMap(networkGroupDefinitionFile); - setConfig(initProps); - } - } - + Reader netDefReader = getConfigFileFromWebOrLocally(networkUnitDefinition, getAppPath().getAbsolutePath(), new File(workPath, "network.definition.backup")); + initProps = FileUtils.table(netDefReader); + setConfig(initProps); + + Map initGroupProps; + Reader netGroupDefReader = getConfigFileFromWebOrLocally(networkGroupDefinition, getAppPath().getAbsolutePath(), new File(workPath, "network.group.backup")); + initGroupProps = FileUtils.table(netGroupDefReader); + setConfig(initGroupProps); + // set release locations int i = 0; CryptoLib cryptoLib; @@ -820,7 +795,7 @@ public final class Switchboard extends serverSwitch { } - public void switchNetwork(final String networkDefinition) { + public void switchNetwork(final String networkDefinition) throws FileNotFoundException, IOException { log.logInfo("SWITCH NETWORK: switching to '" + networkDefinition + "'"); // pause crawls final boolean lcp = crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL); diff --git a/source/net/yacy/kelondro/util/FileUtils.java b/source/net/yacy/kelondro/util/FileUtils.java index e7a2a986a..5dc22f722 100644 --- a/source/net/yacy/kelondro/util/FileUtils.java +++ b/source/net/yacy/kelondro/util/FileUtils.java @@ -499,6 +499,11 @@ public final class FileUtils { } + public static Map table(Reader r) { + BufferedReader br = new BufferedReader(r); + return table(new StringsIterator(br)); + } + public static Map table(Iterator li) { int pos; String line;