helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject [21/50] [abbrv] git commit: Adding tool to update a container count for a given service
Date Thu, 10 Jul 2014 17:05:04 GMT
Adding tool to update a container count for a given service


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

Branch: refs/heads/master
Commit: 2339465ddc934862b71425953a64cc476f1e63c5
Parents: 224c7ea
Author: Kishore Gopalakrishna <g.kishore@gmail.com>
Authored: Mon Feb 24 13:30:39 2014 -0800
Committer: Kishore Gopalakrishna <g.kishore@gmail.com>
Committed: Mon Feb 24 13:30:39 2014 -0800

----------------------------------------------------------------------
 helix-provisioning/pom.xml                      |  8 +-
 .../tools/UpdateProvisionerConfig.java          | 87 ++++++++++++++++++++
 .../java/tools/UpdateProvisionerConfig.java     | 87 --------------------
 .../yarn/example/HelloWordAppSpecFactory.java   | 67 ++-------------
 4 files changed, 96 insertions(+), 153 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/2339465d/helix-provisioning/pom.xml
----------------------------------------------------------------------
diff --git a/helix-provisioning/pom.xml b/helix-provisioning/pom.xml
index 3ba7d39..4a2e523 100644
--- a/helix-provisioning/pom.xml
+++ b/helix-provisioning/pom.xml
@@ -81,14 +81,14 @@ under the License.
         <artifactId>appassembler-maven-plugin</artifactId>
         <configuration>
           <programs>
-            <program>
-              <mainClass>org.apache.helix.provisioning.yarn.Client</mainClass>
-              <name>yarn-job-launcher</name>
-            </program>
              <program>
               <mainClass>org.apache.helix.provisioning.yarn.AppLauncher</mainClass>
               <name>app-launcher</name>
             </program>
+            <program>
+              <mainClass>org.apache.helix.provisioning.tools.UpdateProvisionerConfig</mainClass>
+              <name>update-provisioner-config</name>
+            </program>
           </programs>
         </configuration>
       </plugin>

http://git-wip-us.apache.org/repos/asf/helix/blob/2339465d/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/UpdateProvisionerConfig.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/UpdateProvisionerConfig.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/UpdateProvisionerConfig.java
new file mode 100644
index 0000000..f3cce42
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/tools/UpdateProvisionerConfig.java
@@ -0,0 +1,87 @@
+package org.apache.helix.provisioning.tools;
+
+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.Resource;
+import org.apache.helix.api.accessor.ResourceAccessor;
+import org.apache.helix.api.config.ResourceConfig;
+import org.apache.helix.api.id.ClusterId;
+import org.apache.helix.api.id.ResourceId;
+import org.apache.helix.manager.zk.ZkHelixConnection;
+import org.apache.helix.provisioning.yarn.YarnProvisionerConfig;
+import org.apache.log4j.Logger;
+/**
+ * Update the provisioner config
+ */
+public class UpdateProvisionerConfig {
+  private static Logger LOG = Logger.getLogger(UpdateProvisionerConfig.class);
+  private static String updateContainerCount = "updateContainerCount";
+  private HelixConnection _connection;
+
+  public UpdateProvisionerConfig(String zkAddress) {
+    _connection = new ZkHelixConnection(zkAddress);
+    _connection.connect();
+  }
+
+  public void setNumContainers(String appName, String serviceName, int numContainers) {
+    ResourceId resourceId = ResourceId.from(serviceName);
+
+    ResourceAccessor resourceAccessor = _connection.createResourceAccessor(ClusterId.from(appName));
+    Resource resource = resourceAccessor.readResource(resourceId);
+    LOG.info("Current provisioner config:"+ resource.getProvisionerConfig());
+
+    ResourceConfig.Delta delta = new ResourceConfig.Delta(resourceId);
+    YarnProvisionerConfig config = new YarnProvisionerConfig(resourceId);
+    config.setNumContainers(numContainers);
+    delta.setProvisionerConfig(config);
+    ResourceConfig updatedResourceConfig = resourceAccessor.updateResource(resourceId, delta);
+    LOG.info("Update provisioner config:"+ updatedResourceConfig.getProvisionerConfig());
+
+  }
+
+  @SuppressWarnings("static-access")
+  public static void main(String[] args) throws ParseException {
+    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 updateContainerCountOption =
+        OptionBuilder.withLongOpt(updateContainerCount)
+            .withDescription("appName serviceName numContainers").create();
+    updateContainerCountOption.setArgs(3);
+    updateContainerCountOption.setRequired(false);
+    updateContainerCountOption.setArgName("appName serviceName numContainers");
+
+    group.addOption(updateContainerCountOption);
+
+    Options options = new Options();
+    options.addOption(zkServerOption);
+    options.addOptionGroup(group);
+    CommandLine cliParser = new GnuParser().parse(options, args);
+
+    String zkAddress = cliParser.getOptionValue("zookeeperAddress");
+    UpdateProvisionerConfig updater = new UpdateProvisionerConfig(zkAddress);
+
+    if (cliParser.hasOption(updateContainerCount)) {
+      String appName = cliParser.getOptionValues(updateContainerCount)[0];
+      String serviceName = cliParser.getOptionValues(updateContainerCount)[1];
+      int numContainers = Integer.parseInt(
+        cliParser.getOptionValues(updateContainerCount)[2]);
+      updater.setNumContainers(appName, serviceName, numContainers);
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/2339465d/helix-provisioning/src/main/java/tools/UpdateProvisionerConfig.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/tools/UpdateProvisionerConfig.java b/helix-provisioning/src/main/java/tools/UpdateProvisionerConfig.java
deleted file mode 100644
index 89ee1c5..0000000
--- a/helix-provisioning/src/main/java/tools/UpdateProvisionerConfig.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package tools;
-
-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.Resource;
-import org.apache.helix.api.accessor.ResourceAccessor;
-import org.apache.helix.api.config.ResourceConfig;
-import org.apache.helix.api.id.ClusterId;
-import org.apache.helix.api.id.ResourceId;
-import org.apache.helix.manager.zk.ZkHelixConnection;
-import org.apache.helix.provisioning.yarn.YarnProvisionerConfig;
-import org.apache.log4j.Logger;
-/**
- * Update the provisioner config
- */
-public class UpdateProvisionerConfig {
-  private static Logger LOG = Logger.getLogger(UpdateProvisionerConfig.class);
-  private static String updateContainerCount = "updateContainerCount";
-  private HelixConnection _connection;
-
-  public UpdateProvisionerConfig(String zkAddress) {
-    _connection = new ZkHelixConnection(zkAddress);
-    _connection.connect();
-  }
-
-  public void setNumContainers(String appName, String serviceName, int numContainers) {
-    ResourceId resourceId = ResourceId.from(serviceName);
-
-    ResourceAccessor resourceAccessor = _connection.createResourceAccessor(ClusterId.from(appName));
-    Resource resource = resourceAccessor.readResource(resourceId);
-    LOG.info("Current provisioner config:"+ resource.getProvisionerConfig());
-
-    ResourceConfig.Delta delta = new ResourceConfig.Delta(resourceId);
-    YarnProvisionerConfig config = new YarnProvisionerConfig(resourceId);
-    config.setNumContainers(numContainers);
-    delta.setProvisionerConfig(config);
-    ResourceConfig updatedResourceConfig = resourceAccessor.updateResource(resourceId, delta);
-    LOG.info("Update provisioner config:"+ updatedResourceConfig.getProvisionerConfig());
-
-  }
-
-  @SuppressWarnings("static-access")
-  public static void main(String[] args) throws ParseException {
-    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 updateContainerCountOption =
-        OptionBuilder.withLongOpt(updateContainerCount)
-            .withDescription("set the number of containers per service").create();
-    updateContainerCountOption.setArgs(3);
-    updateContainerCountOption.setRequired(false);
-    updateContainerCountOption.setArgName("appName serviceName numContainers");
-
-    group.addOption(updateContainerCountOption);
-
-    Options options = new Options();
-    options.addOption(zkServerOption);
-    options.addOptionGroup(group);
-    CommandLine cliParser = new GnuParser().parse(options, args);
-
-    String zkAddress = cliParser.getOptionValue("zookeeperAddress");
-    UpdateProvisionerConfig updater = new UpdateProvisionerConfig(zkAddress);
-
-    if (cliParser.hasOption(updateContainerCount)) {
-      String appName = cliParser.getOptionValues(updateContainerCount)[0];
-      String serviceName = cliParser.getOptionValues(updateContainerCount)[1];
-      int numContainers = Integer.parseInt(
-        cliParser.getOptionValues(updateContainerCount)[2]);
-      updater.setNumContainers(appName, serviceName, numContainers);
-    }
-
-  }
-}

http://git-wip-us.apache.org/repos/asf/helix/blob/2339465d/recipes/helloworld-provisioning-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWordAppSpecFactory.java
----------------------------------------------------------------------
diff --git a/recipes/helloworld-provisioning-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWordAppSpecFactory.java
b/recipes/helloworld-provisioning-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWordAppSpecFactory.java
index 03c1341..20591cf 100644
--- a/recipes/helloworld-provisioning-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWordAppSpecFactory.java
+++ b/recipes/helloworld-provisioning-yarn/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWordAppSpecFactory.java
@@ -16,33 +16,6 @@ import org.yaml.snakeyaml.Yaml;
 
 public class HelloWordAppSpecFactory implements ApplicationSpecFactory {
 
-  static HelloworldAppSpec data;
-
-  static {
-    HelloworldAppSpec data = new HelloworldAppSpec();
-    AppConfig appConfig = new AppConfig();
-    appConfig.setValue("k1", "v1");
-    data.setAppConfig(appConfig);
-    data.setAppName("testApp");
-    data.setAppMasterPackageUri(
-        "/Users/kgopalak/Documents/projects/incubator-helix/helix-provisioning/helix-provisioning-0.7.1-incubating-SNAPSHOT-pkg.tar");
-    HashMap<String, Map<String, String>> serviceConfigMap = new HashMap<String,
Map<String, String>>();
-    serviceConfigMap.put("HelloWorld", new HashMap<String, String>());
-    serviceConfigMap.get("HelloWorld").put("k1", "v1");
-    data.setServiceConfigMap(serviceConfigMap);
-    HashMap<String, String> serviceMainClassMap = new HashMap<String, String>();
-    serviceMainClassMap.put("HelloWorld", HelloWorldService.class.getCanonicalName());
-    data.setServiceMainClassMap(serviceMainClassMap);
-    HashMap<String, String> servicePackageURIMap = new HashMap<String, String>();
-    servicePackageURIMap
-        .put(
-            "HelloWorld",
-            "/Users/kgopalak/Documents/projects/incubator-helix/helix-provisioning/helix-provisioning-0.7.1-incubating-SNAPSHOT-pkg.tar");
-    data.setServicePackageURIMap(servicePackageURIMap);
-    data.setServices(Arrays.asList(new String[] {
-      "HelloWorld"
-    }));  }
-
   @Override
   public ApplicationSpec fromYaml(InputStream inputstream) {
     return (ApplicationSpec) new Yaml().load(inputstream);
@@ -50,43 +23,13 @@ public class HelloWordAppSpecFactory implements ApplicationSpecFactory
{
   }
 
   public static void main(String[] args) {
-    DumperOptions options = new DumperOptions();
-    options.setPrettyFlow(true);
 
-    Yaml yaml = new Yaml(options);
-    HelloworldAppSpec data = new HelloworldAppSpec();
-    AppConfig appConfig = new AppConfig();
-    appConfig.setValue("k1", "v1");
-    data.setAppConfig(appConfig);
-    data.setAppName("testApp");
-    data.setAppMasterPackageUri(
-        "/Users/kgopalak/Documents/projects/incubator-helix/helix-provisioning/helix-provisioning-0.7.1-incubating-SNAPSHOT-pkg.tar");
-    HashMap<String, Map<String, String>> serviceConfigMap = new HashMap<String,
Map<String, String>>();
-    serviceConfigMap.put("HelloWorld", new HashMap<String, String>());
-    serviceConfigMap.get("HelloWorld").put("k1", "v1");
-    data.setServiceConfigMap(serviceConfigMap);
-    HashMap<String, String> serviceMainClassMap = new HashMap<String, String>();
-    serviceMainClassMap.put("HelloWorld", HelloWorldService.class.getCanonicalName());
-    data.setServiceMainClassMap(serviceMainClassMap);
-    HashMap<String, String> servicePackageURIMap = new HashMap<String, String>();
-    servicePackageURIMap
-        .put(
-            "HelloWorld",
-            "/Users/kgopalak/Documents/projects/incubator-helix/helix-provisioning/helix-provisioning-0.7.1-incubating-SNAPSHOT-pkg.tar");
-    data.setServicePackageURIMap(servicePackageURIMap);
-    data.setServices(Arrays.asList(new String[] {
-      "HelloWorld"
-    }));
-    String dump = yaml.dump(data);
+    Yaml yaml = new Yaml();
+    InputStream resourceAsStream =
+        ClassLoader.getSystemClassLoader().getResourceAsStream("hello_world_app_spec.yaml");
+    HelloworldAppSpec spec = yaml.loadAs(resourceAsStream, HelloworldAppSpec.class);
+    String dump = yaml.dump(spec);
     System.out.println(dump);
 
-    InputStream resourceAsStream = ClassLoader.getSystemClassLoader().getResourceAsStream("hello_world_app_spec.yaml");
-    HelloworldAppSpec load = yaml.loadAs(resourceAsStream,HelloworldAppSpec.class);
-    String dumpnew = yaml.dump(load);
-    System.out.println(dumpnew.equals(dump));
-    
-    System.out.println("==================================");
-    System.out.println(dumpnew);
-
   }
 }


Mime
View raw message