helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject [24/50] [abbrv] git commit: Adding container admin to start/stop participants
Date Thu, 10 Jul 2014 17:05:07 GMT
Adding container admin to start/stop participants


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/7d5bd789
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/7d5bd789
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/7d5bd789

Branch: refs/heads/master
Commit: 7d5bd789f37eb807f28d0e00810920b699b3d080
Parents: 2339465
Author: Kishore Gopalakrishna <g.kishore@gmail.com>
Authored: Mon Feb 24 17:49:29 2014 -0800
Committer: Kishore Gopalakrishna <g.kishore@gmail.com>
Committed: Mon Feb 24 17:49:29 2014 -0800

----------------------------------------------------------------------
 .../stages/ContainerProvisioningStage.java      |  2 +-
 helix-provisioning/pom.xml                      |  4 +
 .../provisioning/tools/ContainerAdmin.java      | 98 ++++++++++++++++++++
 3 files changed, 103 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/7d5bd789/helix-core/src/main/java/org/apache/helix/controller/stages/ContainerProvisioningStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/ContainerProvisioningStage.java
b/helix-core/src/main/java/org/apache/helix/controller/stages/ContainerProvisioningStage.java
index bc3e0c6..ae433e0 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/ContainerProvisioningStage.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/ContainerProvisioningStage.java
@@ -276,7 +276,7 @@ public class ContainerProvisioningStage extends AbstractBaseStage {
               if (participant.isAlive()) {
                 Message message = new Message(MessageType.SHUTDOWN, UUID.randomUUID().toString());
                 message.setTgtName(participant.getId().toString());
-                message.setTgtSessionId("*");
+                message.setTgtSessionId(participant.getRunningInstance().getSessionId());
                 message.setMsgId(message.getId());
                 accessor.createProperty(
                     keyBuilder.message(participant.getId().toString(), message.getId()),
message);

http://git-wip-us.apache.org/repos/asf/helix/blob/7d5bd789/helix-provisioning/pom.xml
----------------------------------------------------------------------
diff --git a/helix-provisioning/pom.xml b/helix-provisioning/pom.xml
index 4a2e523..410c2be 100644
--- a/helix-provisioning/pom.xml
+++ b/helix-provisioning/pom.xml
@@ -89,6 +89,10 @@ under the License.
               <mainClass>org.apache.helix.provisioning.tools.UpdateProvisionerConfig</mainClass>
               <name>update-provisioner-config</name>
             </program>
+            <program>
+              <mainClass>org.apache.helix.provisioning.tools.ContainerAdmin</mainClass>
+              <name>container-admin</name>
+            </program>
           </programs>
         </configuration>
       </plugin>

http://git-wip-us.apache.org/repos/asf/helix/blob/7d5bd789/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
new file mode 100644
index 0000000..8154996
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/ContainerAdmin.java
@@ -0,0 +1,98 @@
+package org.apache.helix.provisioning.tools;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.helix.HelixConnection;
+import org.apache.helix.api.Participant;
+import org.apache.helix.api.accessor.ParticipantAccessor;
+import org.apache.helix.api.id.ClusterId;
+import org.apache.helix.api.id.MessageId;
+import org.apache.helix.api.id.ParticipantId;
+import org.apache.helix.manager.zk.ZkHelixConnection;
+import org.apache.helix.model.Message;
+import org.apache.helix.model.Message.MessageType;
+import org.apache.log4j.Logger;
+
+/**
+ * 
+ *
+ */
+public class ContainerAdmin {
+
+  private static Logger LOG = Logger.getLogger(ContainerAdmin.class);
+  private static String stopContainer = "stopContainer";
+  private HelixConnection _connection;
+
+  public ContainerAdmin(String zkAddress) {
+    _connection = new ZkHelixConnection(zkAddress);
+    _connection.connect();
+  }
+
+  public void stopContainer(String appName, String participantName) throws Exception {
+    ClusterId clusterId = ClusterId.from(appName);
+    ParticipantAccessor participantAccessor = _connection.createParticipantAccessor(clusterId);
+    ParticipantId participantId = ParticipantId.from(participantName);
+    Participant participant = participantAccessor.readParticipant(participantId);
+    if (participant != null && participant.isAlive()) {
+      Message message = new Message(MessageType.SHUTDOWN, UUID.randomUUID().toString());
+      message.setTgtName(participant.getId().toString());
+      message.setTgtSessionId(participant.getRunningInstance().getSessionId());
+      message.setMsgId(message.getId());
+      Map<MessageId, Message> msgMap = new HashMap<MessageId, Message>();
+      msgMap.put(MessageId.from(message.getId()), message);
+      participantAccessor.insertMessagesToParticipant(participantId, msgMap);
+      do {
+        participant = participantAccessor.readParticipant(participantId);
+        Thread.sleep(1000);
+        LOG.info("Waiting for container:" + participantName + " to shutdown");
+      } while (participant!=null && participant.isAlive());
+    }
+    
+  }
+
+  @SuppressWarnings("static-access")
+  public static void main(String[] args) throws Exception {
+    Option zkServerOption =
+        OptionBuilder.withLongOpt("zookeeperAddress").withDescription("Provide zookeeper
address")
+            .create();
+    zkServerOption.setArgs(1);
+    zkServerOption.setRequired(true);
+    zkServerOption.setArgName("zookeeperAddress(Required)");
+
+    OptionGroup group = new OptionGroup();
+    group.setRequired(true);
+
+    // update container count per service
+    Option stopContainerOption =
+        OptionBuilder.withLongOpt(stopContainer).withDescription("appName participantName")
+            .create();
+    stopContainerOption.setArgs(2);
+    stopContainerOption.setRequired(false);
+    stopContainerOption.setArgName("appName participantName");
+
+    group.addOption(stopContainerOption);
+
+    Options options = new Options();
+    options.addOption(zkServerOption);
+    options.addOptionGroup(group);
+    CommandLine cliParser = new GnuParser().parse(options, args);
+
+    String zkAddress = cliParser.getOptionValue("zookeeperAddress");
+    ContainerAdmin admin = new ContainerAdmin(zkAddress);
+
+    if (cliParser.hasOption(stopContainer)) {
+      String appName = cliParser.getOptionValues(stopContainer)[0];
+      String participantName = cliParser.getOptionValues(stopContainer)[1];
+      admin.stopContainer(appName, participantName);
+    }
+  }
+}


Mime
View raw message