catch error when initializing hazelcast

should fix https://github.com/yacy/yacy_search_server/issues/468
pull/489/head
Michael Peter Christen 2 years ago
parent c049c8d4a4
commit 3d138d3fdd

@ -41,14 +41,14 @@ public class localpeers {
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, @SuppressWarnings("unused") final serverObjects post, @SuppressWarnings("unused") final serverSwitch env) { public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, @SuppressWarnings("unused") final serverObjects post, @SuppressWarnings("unused") final serverSwitch env) {
final servletProperties prop = new servletProperties(); final servletProperties prop = new servletProperties();
int c = 0; int c = 0;
for (String urlstub: Switchboard.getSwitchboard().localcluster_scan) { for (final String urlstub: Switchboard.getSwitchboard().localcluster_scan) {
prop.putJSON("peers_" + c + "_urlstub", urlstub); // a usrlstub is a full url with protocol, host and port up the the path start including first "/" prop.putJSON("peers_" + c + "_urlstub", urlstub); // a usrlstub is a full url with protocol, host and port up the the path start including first "/"
c++; c++;
} }
prop.put("peers", c); prop.put("peers", c);
try { try {
prop.put("status", systemStatus().toString(2)); prop.put("status", systemStatus().toString(2));
} catch (JSONException e) { } catch (final JSONException e) {
prop.put("status", ""); prop.put("status", "");
} }
// return rewrite properties // return rewrite properties
@ -58,32 +58,35 @@ public class localpeers {
public static JSONObject systemStatus() throws JSONException { public static JSONObject systemStatus() throws JSONException {
// generate json // generate json
JSONObject systemStatus = new JSONObject(true); final JSONObject systemStatus = new JSONObject(true);
Memory.status().forEach((k, v) -> {try {systemStatus.put(k, v);} catch (JSONException e) {}}); Memory.status().forEach((k, v) -> {try {systemStatus.put(k, v);} catch (final JSONException e) {}});
JSONArray members = new JSONArray(); final JSONArray members = new JSONArray();
HazelcastInstance hi = Switchboard.getSwitchboard().localcluster_hazelcast; final HazelcastInstance hi = Switchboard.getSwitchboard().localcluster_hazelcast;
String uuid = hi.getCluster().getLocalMember().getUuid().toString(); if (hi != null) {
hi.getMap("status").put(uuid, Memory.status()); String uuid = hi.getCluster().getLocalMember().getUuid().toString();
for (Member member: hi.getCluster().getMembers()) { hi.getMap("status").put(uuid, Memory.status());
JSONObject m = new JSONObject(true); for (final Member member: hi.getCluster().getMembers()) {
uuid = member.getUuid().toString(); final JSONObject m = new JSONObject(true);
m.put("uuid", uuid); uuid = member.getUuid().toString();
m.put("host", member.getAddress().getHost()); m.put("uuid", uuid);
try {m.put("ip", member.getAddress().getInetAddress().getHostAddress());} catch (JSONException | UnknownHostException e) {} m.put("host", member.getAddress().getHost());
m.put("port", member.getAddress().getPort()); try {m.put("ip", member.getAddress().getInetAddress().getHostAddress());} catch (JSONException | UnknownHostException e) {}
m.put("isLite", member.isLiteMember()); m.put("port", member.getAddress().getPort());
m.put("isLocal", member.localMember()); m.put("isLite", member.isLiteMember());
@SuppressWarnings("unchecked") m.put("isLocal", member.localMember());
Map<String, Object> status = (Map<String, Object>) hi.getMap("status").get(uuid); @SuppressWarnings("unchecked")
m.put("status", status); final
members.put(m); Map<String, Object> status = (Map<String, Object>) hi.getMap("status").get(uuid);
m.put("status", status);
members.put(m);
}
systemStatus.put("hazelcast_cluster_name", hi.getConfig().getClusterName());
systemStatus.put("hazelcast_instance_name", hi.getConfig().getInstanceName());
final Collection<String> interfaces = hi.getConfig().getNetworkConfig().getInterfaces().getInterfaces();
systemStatus.put("hazelcast_interfaces", interfaces);
systemStatus.put("hazelcast_members", members);
systemStatus.put("hazelcast_members_count", members.length());
} }
systemStatus.put("hazelcast_cluster_name", hi.getConfig().getClusterName());
systemStatus.put("hazelcast_instance_name", hi.getConfig().getInstanceName());
Collection<String> interfaces = hi.getConfig().getNetworkConfig().getInterfaces().getInterfaces();
systemStatus.put("hazelcast_interfaces", interfaces);
systemStatus.put("hazelcast_members", members);
systemStatus.put("hazelcast_members_count", members.length());
return systemStatus; return systemStatus;
} }

@ -665,9 +665,14 @@ public final class Switchboard extends serverSwitch {
join.getMulticastConfig().setEnabled(true); join.getMulticastConfig().setEnabled(true);
final Config config = new Config().setClusterName("YaCyP2P").setInstanceName("Peer").setNetworkConfig(networkConfig); final Config config = new Config().setClusterName("YaCyP2P").setInstanceName("Peer").setNetworkConfig(networkConfig);
config.getCPSubsystemConfig().setCPMemberCount(3); config.getCPSubsystemConfig().setCPMemberCount(3);
this.localcluster_hazelcast = Hazelcast.newHazelcastInstance(config); try {
final String uuid = this.localcluster_hazelcast.getCluster().getLocalMember().getUuid().toString(); this.localcluster_hazelcast = Hazelcast.newHazelcastInstance(config);
this.localcluster_hazelcast.getMap("status").put(uuid, Memory.status()); final String uuid = this.localcluster_hazelcast.getCluster().getLocalMember().getUuid().toString();
this.localcluster_hazelcast.getMap("status").put(uuid, Memory.status());
} catch (final Exception e) {
this.log.warn(e);
this.localcluster_hazelcast = null;
}
// load domainList // load domainList
try { try {
@ -1345,7 +1350,7 @@ public final class Switchboard extends serverSwitch {
} }
@Override @Override
public void setHttpServer(YaCyHttpServer server) { public void setHttpServer(final YaCyHttpServer server) {
super.setHttpServer(server); super.setHttpServer(server);
// finally start jobs which shall be started after start-up // finally start jobs which shall be started after start-up
@ -2255,7 +2260,7 @@ public final class Switchboard extends serverSwitch {
return moved; return moved;
} }
private boolean processSurrogateJson(File infile, File outfile) { private boolean processSurrogateJson(final File infile, final File outfile) {
// parse a file that can be generated with yacy_grid_parser // parse a file that can be generated with yacy_grid_parser
// see https://github.com/yacy/yacy_grid_parser/blob/master/README.md // see https://github.com/yacy/yacy_grid_parser/blob/master/README.md
this.log.info("processing json surrogate " + infile); this.log.info("processing json surrogate " + infile);
@ -3062,7 +3067,7 @@ public final class Switchboard extends serverSwitch {
* *
* @param jobType * @param jobType
*/ */
public void pauseCrawlJob(final String jobType, String cause) { public void pauseCrawlJob(final String jobType, final String cause) {
final Object[] status = this.crawlJobsStatus.get(jobType); final Object[] status = this.crawlJobsStatus.get(jobType);
synchronized ( status[SwitchboardConstants.CRAWLJOB_SYNC] ) { synchronized ( status[SwitchboardConstants.CRAWLJOB_SYNC] ) {
status[SwitchboardConstants.CRAWLJOB_STATUS] = Boolean.TRUE; status[SwitchboardConstants.CRAWLJOB_STATUS] = Boolean.TRUE;
@ -3807,7 +3812,7 @@ public final class Switchboard extends serverSwitch {
* @param url * @param url
* @return null if this was ok. If this failed, return a string with a fail reason * @return null if this was ok. If this failed, return a string with a fail reason
*/ */
public String stackUrl(CrawlProfile profile, DigestURL url) { public String stackUrl(final CrawlProfile profile, final DigestURL url) {
final byte[] handle = ASCII.getBytes(profile.handle()); final byte[] handle = ASCII.getBytes(profile.handle());
@ -4186,11 +4191,11 @@ public final class Switchboard extends serverSwitch {
return 1; return 1;
} }
public String encodeDigestAuth(String user, String pw) { public String encodeDigestAuth(final String user, final String pw) {
return "MD5:" + Digest.encodeMD5Hex(user + ":" + sb.getConfig(SwitchboardConstants.ADMIN_REALM,"YaCy") + ":" + pw); return "MD5:" + Digest.encodeMD5Hex(user + ":" + sb.getConfig(SwitchboardConstants.ADMIN_REALM,"YaCy") + ":" + pw);
} }
public String encodeBasicAuth(String user, String pw) { public String encodeBasicAuth(final String user, final String pw) {
return Digest.encodeMD5Hex(user + ":" + pw); return Digest.encodeMD5Hex(user + ":" + pw);
} }

Loading…
Cancel
Save