* 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
pull/1/head
f1ori 14 years ago
parent 18d33b5c6d
commit 4915d1781a

@ -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;

@ -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();

@ -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<String, String> initProps;
if (networkUnitDefinition.startsWith("http://")) {
// multiple definitions may be given, split the definition line in multiple addresses
String[] netdefs = networkUnitDefinition.split(",");
Map<String, String> 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<String, String> 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);

@ -499,6 +499,11 @@ public final class FileUtils {
}
public static Map<String, String> table(Reader r) {
BufferedReader br = new BufferedReader(r);
return table(new StringsIterator(br));
}
public static Map<String, String> table(Iterator<String> li) {
int pos;
String line;

Loading…
Cancel
Save