You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by sw...@apache.org on 2013/09/24 20:55:02 UTC
git commit: first cut of helix yarn test
Updated Branches:
refs/heads/helix-yarn b9ada66a8 -> 0b2da84e4
first cut of helix yarn test
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/0b2da84e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/0b2da84e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/0b2da84e
Branch: refs/heads/helix-yarn
Commit: 0b2da84e487efcdab9504e974db8aacc50bad91b
Parents: b9ada66
Author: Swaroop Jagadish <sj...@sjagadis-ld.linkedin.biz>
Authored: Tue Sep 24 11:54:27 2013 -0700
Committer: Swaroop Jagadish <sj...@sjagadis-ld.linkedin.biz>
Committed: Tue Sep 24 11:54:27 2013 -0700
----------------------------------------------------------------------
.../main/java/org/apache/helix/task/Task.java | 5 +++
.../autoscale/container/ContainerProcess.java | 14 +++----
.../apache/helix/autoscale/AbstractTask.java | 12 ------
.../helix/autoscale/HelixYarnProcess.java | 43 +++++++++++++++-----
.../apache/helix/autoscale/HelixYarnTest.java | 2 +
.../org/apache/helix/autoscale/MyAppTask.java | 12 +++---
.../src/test/resources/myapp.properties | 2 -
7 files changed, 52 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0b2da84e/helix-core/src/main/java/org/apache/helix/task/Task.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/Task.java b/helix-core/src/main/java/org/apache/helix/task/Task.java
index 2741f9e..c1c7ad9 100644
--- a/helix-core/src/main/java/org/apache/helix/task/Task.java
+++ b/helix-core/src/main/java/org/apache/helix/task/Task.java
@@ -1,5 +1,7 @@
package org.apache.helix.task;
+import java.util.Properties;
+
/**
* The interface that is to be implemented by a specific task implementation.
@@ -9,6 +11,9 @@ package org.apache.helix.task;
*/
public interface Task
{
+
+ //public void configure(Properties config);
+
/**
* Execute the task.
*
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0b2da84e/recipes/auto-scale/src/main/java/org/apache/helix/autoscale/container/ContainerProcess.java
----------------------------------------------------------------------
diff --git a/recipes/auto-scale/src/main/java/org/apache/helix/autoscale/container/ContainerProcess.java b/recipes/auto-scale/src/main/java/org/apache/helix/autoscale/container/ContainerProcess.java
index 343e426..1c0701a 100644
--- a/recipes/auto-scale/src/main/java/org/apache/helix/autoscale/container/ContainerProcess.java
+++ b/recipes/auto-scale/src/main/java/org/apache/helix/autoscale/container/ContainerProcess.java
@@ -21,14 +21,14 @@ public abstract class ContainerProcess implements Service {
static final Logger log = Logger.getLogger(ContainerProcess.class);
private ContainerProcessProperties properties;
- private HelixManager participantManager;
+ protected HelixManager participantManager;
- private String modelName;
- private StateModelFactory<? extends StateModel> modelFactory;
+ protected String modelName;
+ protected StateModelFactory<? extends StateModel> modelFactory;
- private String instanceName;
- private String clusterName;
- private String zookeeperAddress;
+ protected String instanceName;
+ protected String clusterName;
+ protected String zookeeperAddress;
private boolean active = false;
private boolean failed = false;
@@ -76,7 +76,7 @@ public abstract class ContainerProcess implements Service {
protected abstract void startContainer() throws Exception;
- private final void startParticipant() throws Exception {
+ protected void startParticipant() throws Exception {
participantManager = HelixManagerFactory.getZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT, zookeeperAddress);
participantManager.getStateMachineEngine().registerStateModelFactory(modelName, modelFactory);
participantManager.connect();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0b2da84e/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/AbstractTask.java
----------------------------------------------------------------------
diff --git a/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/AbstractTask.java b/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/AbstractTask.java
deleted file mode 100644
index 8af29af..0000000
--- a/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/AbstractTask.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.apache.helix.autoscale;
-import java.util.Properties;
-
-import org.apache.helix.task.Task;
-
-public abstract class AbstractTask implements Task {
- protected Properties _taskConfig;
-
- public AbstractTask(Properties config) {
- _taskConfig = config;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0b2da84e/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnProcess.java
----------------------------------------------------------------------
diff --git a/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnProcess.java b/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnProcess.java
index f4abd5f..decc198 100644
--- a/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnProcess.java
+++ b/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnProcess.java
@@ -4,24 +4,21 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-import org.apache.helix.HelixManager;
import org.apache.helix.HelixManagerFactory;
import org.apache.helix.InstanceType;
import org.apache.helix.autoscale.container.ContainerProcess;
import org.apache.helix.autoscale.container.ContainerProcessProperties;
-import org.apache.helix.autoscale.impl.container.RedisServerProcess.RedisServerModelFactory;
-import org.apache.helix.integration.task.WorkflowGenerator;
import org.apache.helix.task.Task;
-import org.apache.helix.task.TaskConfig;
-import org.apache.helix.task.TaskDriver;
import org.apache.helix.task.TaskFactory;
-import org.apache.helix.task.Workflow;
+import org.apache.helix.task.TaskStateModelFactory;
+import org.apache.log4j.Logger;
-import com.google.common.base.Preconditions;
public abstract class HelixYarnProcess extends ContainerProcess {
protected final String _appName;
private String _taskClassName;
+ static final Logger log = Logger.getLogger(HelixYarnProcess.class);
+
public HelixYarnProcess(ContainerProcessProperties properties) throws Exception {
configure(properties);
@@ -35,23 +32,47 @@ public abstract class HelixYarnProcess extends ContainerProcess {
protected void startContainer() throws Exception {
}
- protected void startParticipant() throws Exception {
+ protected final void startParticipant() throws Exception {
participantManager = HelixManagerFactory.getZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT, zookeeperAddress);
-
+ modelName = "Task";
+ modelFactory = new TaskStateModelFactory(participantManager, getTaskFactoryReg());
+ participantManager.getStateMachineEngine().registerStateModelFactory(modelName, modelFactory);
}
- private Map<String, TaskFactory> getTaskFactoryReg(String appName, String taskClassName, Properties taskConfig) {
+ private Map<String, TaskFactory> getTaskFactoryReg() {
Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
taskFactoryReg.put(_appName, new TaskFactory()
{
@Override
public Task createNewTask(String config)
{
- return null;
+ Class<?> clazz;
+ try {
+ clazz = Class.forName(_taskClassName);
+ Task task = createInstance(clazz);
+ //Properties taskConfig = new Properties(); //TODO: Get this from participantManager
+ //task.configure(taskConfig);
+ return task;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
}
});
return taskFactoryReg;
}
+
+ @SuppressWarnings("unchecked")
+ private <T> T createInstance(Class<?> clazz) throws Exception {
+ try {
+ log.debug(String.format("checking for default constructor in class '%s'", clazz.getSimpleName()));
+ return (T) clazz.getConstructor().newInstance();
+ } catch (Exception e) {
+ log.debug("no default constructor found");
+ }
+
+ throw new Exception(String.format("no suitable constructor for class '%s'", clazz.getSimpleName()));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0b2da84e/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnTest.java
----------------------------------------------------------------------
diff --git a/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnTest.java b/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnTest.java
index 50ca9ab..04bce10 100644
--- a/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnTest.java
+++ b/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/HelixYarnTest.java
@@ -49,6 +49,8 @@ public class HelixYarnTest {
TargetProviderService targetProvider = getTargetProviderService(applicationSpec);
TestUtils.startTestCluster(targetProvider, _containerStatusProvider, _containerProvider);
+ TestUtils.admin.addResource(TestUtils.managedClusterName, WorkflowGenerator.DEFAULT_TGT_DB, 2, "MasterSlave");
+
HelixManager taskClusterManager = HelixManagerFactory.getZKHelixManager(TestUtils.managedClusterName,
"Admin", InstanceType.ADMINISTRATOR, TestUtils.zkAddress);
taskClusterManager.connect();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0b2da84e/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/MyAppTask.java
----------------------------------------------------------------------
diff --git a/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/MyAppTask.java b/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/MyAppTask.java
index 96f87df..28c256f 100644
--- a/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/MyAppTask.java
+++ b/recipes/auto-scale/src/test/java/org/apache/helix/autoscale/MyAppTask.java
@@ -2,14 +2,10 @@ package org.apache.helix.autoscale;
import java.util.Properties;
+import org.apache.helix.task.Task;
import org.apache.helix.task.TaskResult;
-public class MyAppTask extends AbstractTask {
-
- public MyAppTask(Properties config) {
- super(config);
- }
-
+public class MyAppTask implements Task {
@Override
public TaskResult run() {
System.out.println("Task running");
@@ -24,4 +20,8 @@ public class MyAppTask extends AbstractTask {
@Override
public void cancel() {
}
+
+ //@Override
+ public void configure(Properties config) {
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0b2da84e/recipes/auto-scale/src/test/resources/myapp.properties
----------------------------------------------------------------------
diff --git a/recipes/auto-scale/src/test/resources/myapp.properties b/recipes/auto-scale/src/test/resources/myapp.properties
index 38a23f8..f44a5de 100644
--- a/recipes/auto-scale/src/test/resources/myapp.properties
+++ b/recipes/auto-scale/src/test/resources/myapp.properties
@@ -6,5 +6,3 @@ targetProviderClass=MyAppTargetProvider
serviceClass=MyAppService
numTasks=50
maxTasksPerContainer=10
-taskConfig.key1=foo
-taskConfig.key2=bar