helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swaroop...@apache.org
Subject git commit: first cut of app spec related changes
Date Sat, 18 Jan 2014 06:33:41 GMT
Updated Branches:
  refs/heads/helix-provisioning 8b1763585 -> e03a9228c


first cut of app spec related changes


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

Branch: refs/heads/helix-provisioning
Commit: e03a9228c031335619cede2c4633338429707551
Parents: 8b17635
Author: Swaroop <swaroop.aj@gmail.com>
Authored: Fri Jan 17 22:33:30 2014 -0800
Committer: Swaroop <swaroop.aj@gmail.com>
Committed: Fri Jan 17 22:33:30 2014 -0800

----------------------------------------------------------------------
 .../helix/provisioning/yarn/AppConfig.java      | 13 ++++++
 .../provisioning/yarn/ApplicationSpec.java      | 11 +++++
 .../helix/provisioning/yarn/ServiceConfig.java  | 13 ++++++
 .../yarn/YamlApplicationSpecFactory.java        | 49 ++++++++++++++++++++
 .../yarn/example/HelloWorldService.java         | 23 +++++++++
 .../yarn/example/HelloWorldStateModel.java      | 29 ++++++++++++
 .../example/HelloWorldStateModelFactory.java    | 12 +++++
 7 files changed, 150 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/e03a9228/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/AppConfig.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/AppConfig.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/AppConfig.java
new file mode 100644
index 0000000..82f6536
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/AppConfig.java
@@ -0,0 +1,13 @@
+package org.apache.helix.provisioning.yarn;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class AppConfig {
+	public Map<String, String> config = new HashMap<String, String>();
+	
+	public String getValue(String key) {
+		return (config != null ? config.get(key) : null);
+	}
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/e03a9228/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/ApplicationSpec.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/ApplicationSpec.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/ApplicationSpec.java
new file mode 100644
index 0000000..6773b4a
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/ApplicationSpec.java
@@ -0,0 +1,11 @@
+package org.apache.helix.provisioning.yarn;
+
+import java.util.List;
+
+public interface ApplicationSpec {
+	public String getAppName();
+	public int getMinContainers();
+	public int getMaxContainers();
+	public AppConfig getConfig();
+	public List<ServiceConfig> getServices();
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/e03a9228/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/ServiceConfig.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/ServiceConfig.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/ServiceConfig.java
new file mode 100644
index 0000000..4d9173e
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/ServiceConfig.java
@@ -0,0 +1,13 @@
+package org.apache.helix.provisioning.yarn;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ServiceConfig {
+	public Map<String, String> config = new HashMap<String, String>();
+	
+	public String getValue(String key) {
+		return (config != null ? config.get(key) : null);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/e03a9228/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/YamlApplicationSpecFactory.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/YamlApplicationSpecFactory.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/YamlApplicationSpecFactory.java
new file mode 100644
index 0000000..0c50fc0
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/YamlApplicationSpecFactory.java
@@ -0,0 +1,49 @@
+package org.apache.helix.provisioning.yarn;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.yaml.snakeyaml.Yaml;
+
+class DefaultApplicationSpec implements ApplicationSpec {
+	public String appName;
+	public Integer minContainers;
+	public Integer maxContainers;
+	
+	public AppConfig appConfig;
+
+	public List<ServiceConfig> serviceConfig;
+
+	@Override
+	public String getAppName() {
+		return appName;
+	}
+
+	@Override
+	public int getMinContainers() {
+		return minContainers;
+	}
+
+	@Override
+	public int getMaxContainers() {
+		return maxContainers;
+	}
+
+	@Override
+	public AppConfig getConfig() {
+		return appConfig;
+	}
+
+	@Override
+	public List<ServiceConfig> getServices() {
+		return serviceConfig;
+	}
+	
+}
+
+public class YamlApplicationSpecFactory {
+	ApplicationSpec fromYaml(InputStream input) {
+	    Yaml yaml = new Yaml();
+	    return yaml.loadAs(input, DefaultApplicationSpec.class);
+	}
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/e03a9228/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldService.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldService.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldService.java
new file mode 100644
index 0000000..055bfd7
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldService.java
@@ -0,0 +1,23 @@
+package org.apache.helix.provisioning.yarn.example;
+
+import org.apache.helix.HelixConnection;
+import org.apache.helix.api.id.ClusterId;
+import org.apache.helix.api.id.ParticipantId;
+import org.apache.helix.api.id.StateModelDefId;
+import org.apache.helix.provisioning.yarn.ContainerParticipant;
+
+
+public class HelloWorldService extends ContainerParticipant {
+
+	public HelloWorldService(HelixConnection connection, ClusterId clusterId,
+			ParticipantId participantId) {
+		super(connection, clusterId, participantId);
+	}
+	
+	@Override
+	public void init() {
+		HelloWorldStateModelFactory stateModelFactory = new HelloWorldStateModelFactory();
+		getParticipant().getStateMachineEngine().registerStateModelFactory(StateModelDefId.from("OnlineOffline"),
stateModelFactory);
+	}
+}
+

http://git-wip-us.apache.org/repos/asf/helix/blob/e03a9228/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldStateModel.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldStateModel.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldStateModel.java
new file mode 100644
index 0000000..95f66e3
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldStateModel.java
@@ -0,0 +1,29 @@
+package org.apache.helix.provisioning.yarn.example;
+
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.id.PartitionId;
+import org.apache.helix.model.Message;
+import org.apache.helix.participant.statemachine.StateModel;
+import org.apache.helix.participant.statemachine.StateModelInfo;
+import org.apache.helix.participant.statemachine.Transition;
+
+@StateModelInfo(initialState = "OFFLINE", states = { "OFFLINE", "ONLINE",
+		"ERROR" })
+public class HelloWorldStateModel extends StateModel {
+
+	public HelloWorldStateModel(PartitionId partitionId) {
+		// TODO Auto-generated constructor stub
+	}
+
+	@Transition(to = "ONLINE", from = "OFFLINE")
+	public void onBecomeOnlineFromOffline(Message message,
+			NotificationContext context) throws Exception {
+		System.out.println("Started HelloWorld service");
+	}
+
+	@Transition(to = "OFFLINE", from = "ONLINE")
+	public void onBecomeOfflineFromOnline(Message message,
+			NotificationContext context) throws InterruptedException {
+		System.out.println("Stopped HelloWorld service");
+	}
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/e03a9228/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldStateModelFactory.java
b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldStateModelFactory.java
new file mode 100644
index 0000000..850cc19
--- /dev/null
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/yarn/example/HelloWorldStateModelFactory.java
@@ -0,0 +1,12 @@
+package org.apache.helix.provisioning.yarn.example;
+
+import org.apache.helix.api.id.PartitionId;
+import org.apache.helix.participant.statemachine.HelixStateModelFactory;
+import org.apache.helix.participant.statemachine.StateModel;
+
+public class HelloWorldStateModelFactory extends HelixStateModelFactory<StateModel>
{
+	@Override
+	public StateModel createNewStateModel(PartitionId partitionId) {
+		return new HelloWorldStateModel(partitionId);
+	}
+}


Mime
View raw message