Permalink
Browse files

Fixed some login in node manager

  • Loading branch information...
1 parent e66a65b commit 5f36c07c6cbe70f3e0c3c80adb0bb63e782d4308 pubudu committed Jul 20, 2011
Showing with 40 additions and 43 deletions.
  1. +40 −43 node-manager/src/main/java/org/esbhive/node/mgt/NodeManager.java
View
83 node-manager/src/main/java/org/esbhive/node/mgt/NodeManager.java
@@ -12,6 +12,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.wso2.carbon.utils.ConfigurationContextService;
@@ -112,16 +114,6 @@ protected void activate(ComponentContext context) {
}
public void process(WatchedEvent event) {
- if (event.getPath().contains(NODES)) {
- handleNodeEvent(event);
- } else if (event.getPath().contains(ELECTION)) {
- if (amITheLeader()) {
- repairFailures();
- }
- }
- }
-
- private void handleNodeEvent(WatchedEvent event) {
EventType et = event.getType();
if (et == EventType.None) {
} else if (et == EventType.NodeChildrenChanged) {
@@ -142,9 +134,16 @@ private void handleNodeEvent(WatchedEvent event) {
String ip = iter.next();
nodeMap.remove(ip);
log.info("Node Failed. Ip : " + ip + ". Current Nodes = " + nodeMap.keySet());
- if (amITheLeader()) {
- String path = zk.create(FAILURES + "/" + ip, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ String path = null;
+ try {
+ path = zk.create(FAILURES + "/" + ip, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
log.info("Created znode " + path);
+ } catch (KeeperException ex) {
+ log.error("Could not create znode for failed node " + ip, ex);
+ } catch (InterruptedException ex) {
+ log.error("Could not create znode for failed node " + ip, ex);
+ }
+ if (amITheLeader()) {
this.repairFailures();
}
}
@@ -160,37 +159,9 @@ private void handleNodeEvent(WatchedEvent event) {
}
}
- }
- private ESBNode createESBNodeFromZnode(String zNode) throws IOException, KeeperException,
- ClassNotFoundException, InterruptedException {
- byte[] bytes = zk.getData(this.NODES + "/" + zNode, false, null);
- ESBNode node = toESBNode(bytes);
- node.setIp(zNode);
- return node;
}
- private ESBNode thisNode() {
- String synapsePort = (String) configurationContextService.getServerConfigContext().getAxisConfiguration().getTransportIn("http").getParameter("port").getValue();
-
- String httpsPort = (String) configurationContextService.getServerConfigContext().getAxisConfiguration().getTransportIn("https").
- getParameter("port").getValue();
-
- String carbonHttpsPort = System.getProperty("carbon.https.port");
-
- String ip = System.getProperty(ServerConstants.LOCAL_IP_ADDRESS);
-
- ESBNode thisNode = new ESBNode();
- thisNode.setHttpsPort(carbonHttpsPort);
- thisNode.setIp(ip);
- thisNode.setIpAndPort(ip + ":" + carbonHttpsPort);
- thisNode.setSynapsePort(synapsePort);
- thisNode.setUsername(serverConfig.getFirstProperty("ESBhive.UserName"));
- thisNode.setPassword(serverConfig.getFirstProperty("ESBhive.PassWord"));
- return thisNode;
- }
-
-
private void repairFailures() {
try {
List<String> failures = zk.getChildren(FAILURES, false);
@@ -217,16 +188,43 @@ private boolean amITheLeader() {
if (myElectionString.substring(myElectionString.lastIndexOf("/") + 1).equals(chidrenArray[0])) {
log.info(thisNode().getIpAndPort() + ": I'm the leader.");
return true;
- }else{
+ } else {
log.info(thisNode().getIpAndPort() + ": I'm not the leader.");
}
//TODO listen for leader failure
} catch (Exception ex) {
- log.error("Error when trying to check for leadership",ex);
+ log.error("Error when trying to check for leadership", ex);
}
return false;
}
+ private ESBNode createESBNodeFromZnode(String zNode) throws IOException, KeeperException,
+ ClassNotFoundException, InterruptedException {
+ byte[] bytes = zk.getData(this.NODES + "/" + zNode, false, null);
+ ESBNode node = toESBNode(bytes);
+ node.setIp(zNode);
+ return node;
+ }
+
+ private ESBNode thisNode() {
+ String synapsePort = (String) configurationContextService.getServerConfigContext().getAxisConfiguration().getTransportIn("http").getParameter("port").getValue();
+
+ String httpsPort = (String) configurationContextService.getServerConfigContext().getAxisConfiguration().getTransportIn("https").
+ getParameter("port").getValue();
+
+ String carbonHttpsPort = System.getProperty("carbon.https.port");
+
+ String ip = System.getProperty(ServerConstants.LOCAL_IP_ADDRESS);
+
+ ESBNode thisNode = new ESBNode();
+ thisNode.setHttpsPort(carbonHttpsPort);
+ thisNode.setIp(ip);
+ thisNode.setIpAndPort(ip + ":" + carbonHttpsPort);
+ thisNode.setSynapsePort(synapsePort);
+ thisNode.setUsername(serverConfig.getFirstProperty("ESBhive.UserName"));
+ thisNode.setPassword(serverConfig.getFirstProperty("ESBhive.PassWord"));
+ return thisNode;
+ }
//taken from
//http://scr4tchp4d.blogspot.com/2008/07/object-to-byte-array-and-byte-array-to.html
@@ -269,5 +267,4 @@ protected void unsetServerConfiguration(ServerConfiguration serverConfig) {
public org.esbhive.node.mgt.ESBNode[] getNodes() {
return nodeMap.values().toArray(new ESBNode[0]);
}
-
}

0 comments on commit 5f36c07

Please sign in to comment.