Skip to content

Commit

Permalink
tried to fix principal bug .. not succeeded
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@440 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jul 27, 2005
1 parent 2181982 commit 8587741
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 60 deletions.
74 changes: 33 additions & 41 deletions htroot/SettingsAck_p.java
Expand Up @@ -345,59 +345,51 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
}

if (post.containsKey("seedUploadRetry")) {
try {
// trying to upload the seed-list file
yacyCore.saveSeedList(env);
String error;
if ((error = yacyCore.saveSeedList(env)) == null) {
// trying to upload the seed-list file
prop.put("info", 13);
prop.put("info_success",1);
} catch (Exception e) {
} else {
prop.put("info",14);
prop.put("info_errormsg",e.getMessage().replaceAll("\n","<br>"));
prop.put("info_errormsg",error.replaceAll("\n","<br>"));
env.setConfig("seedUploadMethod","none");
}
return prop;
}

if (post.containsKey("seedSettings")) {
try {
// getting the currently used uploading method
String oldSeedUploadMethod = env.getConfig("seedUploadMethod","none");
String newSeedUploadMethod = (String)post.get("seedUploadMethod");
String oldSeedURLStr = env.getConfig("seedURL","");
String newSeedURLStr = (String)post.get("seedURL");
new URL(newSeedURLStr);
if (post.containsKey("seedSettings")) {
// getting the currently used uploading method
String oldSeedUploadMethod = env.getConfig("seedUploadMethod","none");
String newSeedUploadMethod = (String)post.get("seedUploadMethod");
String oldSeedURLStr = env.getConfig("seedURL","");
String newSeedURLStr = (String)post.get("seedURL");

boolean seedUrlChanged = !oldSeedURLStr.equals(newSeedURLStr);
boolean uploadMethodChanged = !oldSeedUploadMethod.equals(newSeedUploadMethod);
if (uploadMethodChanged) {
uploadMethodChanged = yacyCore.changeSeedUploadMethod(newSeedUploadMethod);
}

if (seedUrlChanged || uploadMethodChanged) {
env.setConfig("seedUploadMethod", newSeedUploadMethod);
env.setConfig("seedURL", newSeedURLStr);

boolean seedUrlChanged = !oldSeedURLStr.equals(newSeedURLStr);
boolean uploadMethodChanged = !oldSeedUploadMethod.equals(newSeedUploadMethod);
if (uploadMethodChanged) {
uploadMethodChanged = yacyCore.changeSeedUploadMethod(newSeedUploadMethod);
}

if (seedUrlChanged || uploadMethodChanged) {
env.setConfig("seedUploadMethod", newSeedUploadMethod);
env.setConfig("seedURL", newSeedURLStr);

// trying to upload the seed-list file
yacyCore.saveSeedList(env);

// try an upload
String error;
if ((error = yacyCore.saveSeedList(env)) == null) {
// we have successfully uploaded the seed-list file
prop.put("info_seedUploadMethod",newSeedUploadMethod);
prop.put("info_seedURL",newSeedURLStr);
prop.put("info_success",(newSeedUploadMethod.equalsIgnoreCase("none")?0:1));
prop.put("info", 19);
prop.put("info", 19);
} else {
prop.put("info_seedUploadMethod",newSeedUploadMethod);
prop.put("info_seedURL",newSeedURLStr);
prop.put("info_success",0);
prop.put("info", 19);

prop.put("info",14);
prop.put("info_errormsg",error.replaceAll("\n","<br>"));
env.setConfig("seedUploadMethod","none");
}
} catch (Exception e) {
prop.put("info",14);
prop.put("info_errormsg",e.getMessage().replaceAll("\n","<br>"));
env.setConfig("seedUploadMethod","none");
return prop;
}
return prop;
}

/*
Expand Down Expand Up @@ -430,16 +422,16 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
// if the seed upload method is equal to the seed uploader whose settings
// were changed, we now try to upload the seed list with the new settings
if (env.getConfig("seedUploadMethod","none").equalsIgnoreCase(uploaderName)) {
try {
yacyCore.saveSeedList(env);
String error;
if ((error = yacyCore.saveSeedList(env)) == null) {;

// we have successfully uploaded the seed file
prop.put("info", 13);
prop.put("info_success",1);
} catch (Exception e) {
} else {
// if uploading failed we print out an error message
prop.put("info", 14);
prop.put("info_errormsg",e.getMessage().replaceAll("\n","<br>"));
prop.put("info_errormsg",error.replaceAll("\n","<br>"));
env.setConfig("seedUploadMethod","none");
}
} else {
Expand Down
36 changes: 17 additions & 19 deletions source/de/anomic/yacy/yacyCore.java
Expand Up @@ -607,24 +607,20 @@ public static boolean changeSeedUploadMethod(String method) {
}
}

public boolean saveSeedList() {
try {
saveSeedList(this.switchboard);
return true;
} catch (Exception e) {
return false;
}
public String saveSeedList() {
// return an error if this is not successful, and NULL if everything is fine
return saveSeedList(this.switchboard);
}

public static void saveSeedList(serverSwitch sb)
throws Exception {
public static String saveSeedList(serverSwitch sb) {
// return an error if this is not successful, and NULL if everything is fine
String logt;

// be shure that we have something to say
if (seedDB.mySeed.getAddress() == null) {
String errorMsg = "We have no valid IP address until now";
log.logWarning("SaveSeedList: " + errorMsg);
throw new Exception (errorMsg);
return errorMsg;
}

// getting the configured seed uploader
Expand All @@ -648,14 +644,14 @@ public static void saveSeedList(serverSwitch sb)
}

// determine the seed uploader that should be used ...
if (seedUploadMethod.equalsIgnoreCase("none")) return;
if (seedUploadMethod.equalsIgnoreCase("none")) return "no uploader specified";

yacySeedUploader uploader = getSeedUploader(seedUploadMethod);
if (uploader == null) {
String errorMsg = "Unable to get the proper uploader-class for seed uploading method '" + seedUploadMethod + "'.";
log.logWarning("SaveSeedList: " + errorMsg);
throw new Exception (errorMsg);
}
return errorMsg;
}

// ensure that the seed file url is configured properly
URL seedURL;
Expand All @@ -667,7 +663,7 @@ public static void saveSeedList(serverSwitch sb)
}catch(MalformedURLException e){
String errorMsg = "Malformed seed file URL '" + sb.getConfig("seedURL","") + "'. " + e.getMessage();
log.logWarning("SaveSeedList: " + errorMsg);
throw new Exception(errorMsg);
return errorMsg;
}

// upload the seed-list using the configured uploader class
Expand All @@ -685,20 +681,22 @@ public static void saveSeedList(serverSwitch sb)
if (logt != null) {
if (logt.indexOf("Error") >= 0) {
seedDB.mySeed.put("PeerType", prevStatus);
log.logError("SaveSeedList: seed upload failed using " + uploader.getClass().getName() + " (error): " + logt.substring(logt.indexOf("Error") + 6));
throw new Exception("Seed-list uploading failed using uploader '" + uploader.getClass().getName() + "'\n(error): " + logt.substring(logt.indexOf("Error") + 6));
String errorMsg = "SaveSeedList: seed upload failed using " + uploader.getClass().getName() + " (error): " + logt.substring(logt.indexOf("Error") + 6);
log.logError(errorMsg);
return errorMsg;
}
log.logInfo(logt);
}

// finally, set the principal status
sb.setConfig("yacyStatus","principal");
return;
return null;
} catch (Exception e) {
seedDB.mySeed.put("PeerType", prevStatus);
sb.setConfig("yacyStatus", prevStatus);
log.logInfo("SaveSeedList: Seed upload failed (IO error): " + e.getMessage());
throw new Exception("Seed-list uploading failed using uploader '" + uploader.getClass().getName() + "'\n(error): " + e.getMessage());
String errorMsg = "SaveSeedList: Seed upload failed (IO error): " + e.getMessage();
log.logInfo(errorMsg);
return errorMsg;
}
}

Expand Down

0 comments on commit 8587741

Please sign in to comment.