You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/10/01 14:18:33 UTC

[3/3] git commit: Formatting the code.

Formatting the code.


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

Branch: refs/heads/master
Commit: 2db1eeaf0faa9d07abc6b5b36349ae1d4219d1a9
Parents: ac49040
Author: Nirmal Fernando <ni...@gmail.com>
Authored: Wed Oct 1 17:48:11 2014 +0530
Committer: Nirmal Fernando <ni...@gmail.com>
Committed: Wed Oct 1 17:48:11 2014 +0530

----------------------------------------------------------------------
 .../MemberContextToKubernetesContainer.java     | 196 +++++++++----------
 .../MemberContextToKubernetesService.java       |  37 ++--
 .../MemberContextToReplicationController.java   |  83 ++++----
 3 files changed, 157 insertions(+), 159 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/2db1eeaf/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesContainer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesContainer.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesContainer.java
index 1d1ecdc..dd45b3e 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesContainer.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesContainer.java
@@ -38,114 +38,110 @@ import org.apache.stratos.kubernetes.client.model.Port;
 import com.google.common.base.Function;
 
 /**
- *	Is responsible for converting a {@link MemberContext} object to a Kubernetes {@link Container}
- *	Object.
+ * Is responsible for converting a {@link MemberContext} object to a Kubernetes
+ * {@link Container} Object.
  */
-public class MemberContextToKubernetesContainer implements Function<MemberContext, Container>{
-	
-	private static final Log log = LogFactory.getLog(MemberContextToKubernetesContainer.class);
-	private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
-
-	@Override
-	public Container apply(MemberContext memberContext) {
-		String clusterId = memberContext.getClusterId();
+public class MemberContextToKubernetesContainer implements Function<MemberContext, Container> {
+
+    private static final Log log = LogFactory.getLog(MemberContextToKubernetesContainer.class);
+    private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+
+    @Override
+    public Container apply(MemberContext memberContext) {
+        String clusterId = memberContext.getClusterId();
         ClusterContext clusterContext = dataHolder.getClusterContext(clusterId);
-        
-		Container container = new Container();
-		container.setName(getCompatibleName(clusterContext.getHostName()));
-
-		Cartridge cartridge = dataHolder.getCartridge(clusterContext
-				.getCartridgeType());
-		
-		if (cartridge == null) {
-			log.error("Cannot find a Cartridge of type : "
-					+ clusterContext.getCartridgeType());
-			return null;
-		}
-		
-		container.setImage(cartridge.getContainer().getImageName());
-
-		container.setPorts(getPorts(clusterContext, cartridge));
-		
-		container.setEnv(getEnvironmentVars(memberContext, clusterContext));
-
-		return container;
-	}
-	
-	private String getCompatibleName(String hostName) {
-		if (hostName.indexOf('.') != -1) {
-			hostName = hostName.replace('.', '-');
-		}
-		return hostName;
-	}
-
-	private Port[] getPorts(ClusterContext ctxt, Cartridge cartridge) {
-		Port[] ports = new Port[cartridge.getPortMappings().size()];
-		List<Port> portList = new ArrayList<Port>();
-		
-		for (PortMapping portMapping : cartridge.getPortMappings()) {
-			Port p = new Port();
-			p.setContainerPort(Integer.parseInt(portMapping.getPort()));
-			p.setHostPort(Integer.parseInt(portMapping.getPort()));
-			// In kubernetes transport protocol always be 'tcp'
-			p.setProtocol("tcp");
-			p.setName(p.getProtocol()+p.getContainerPort());
-			portList.add(p);
-		}
-		
-		return portList.toArray(ports);
-	}
-	
-	private EnvironmentVariable[] getEnvironmentVars(MemberContext memberCtxt, 
-			ClusterContext ctxt) {
-		
-		String kubernetesClusterId = CloudControllerUtil.getProperty(ctxt.getProperties(), 
-        		StratosConstants.KUBERNETES_CLUSTER_ID);
-		
-		List<EnvironmentVariable> envVars = new ArrayList<EnvironmentVariable>();
-		addToEnvironment(envVars, ctxt.getPayload());
-		//FIXME member id, should it be unique for a container?
-		addToEnvironment(envVars, StratosConstants.MEMBER_ID, memberCtxt.getMemberId());
-		addToEnvironment(envVars, StratosConstants.LB_CLUSTER_ID, memberCtxt.getLbClusterId());
-		addToEnvironment(envVars, StratosConstants.NETWORK_PARTITION_ID, memberCtxt.getNetworkPartitionId());
-		addToEnvironment(envVars, StratosConstants.KUBERNETES_CLUSTER_ID, kubernetesClusterId);
-        if(memberCtxt.getProperties() != null) {
-        	org.apache.stratos.cloud.controller.pojo.Properties props1 = memberCtxt.getProperties();
+
+        Container container = new Container();
+        container.setName(getCompatibleName(clusterContext.getHostName()));
+
+        Cartridge cartridge = dataHolder.getCartridge(clusterContext.getCartridgeType());
+
+        if (cartridge == null) {
+            log.error("Cannot find a Cartridge of type : " + clusterContext.getCartridgeType());
+            return null;
+        }
+
+        container.setImage(cartridge.getContainer().getImageName());
+
+        container.setPorts(getPorts(clusterContext, cartridge));
+
+        container.setEnv(getEnvironmentVars(memberContext, clusterContext));
+
+        return container;
+    }
+
+    private String getCompatibleName(String hostName) {
+        if (hostName.indexOf('.') != -1) {
+            hostName = hostName.replace('.', '-');
+        }
+        return hostName;
+    }
+
+    private Port[] getPorts(ClusterContext ctxt, Cartridge cartridge) {
+        Port[] ports = new Port[cartridge.getPortMappings().size()];
+        List<Port> portList = new ArrayList<Port>();
+
+        for (PortMapping portMapping : cartridge.getPortMappings()) {
+            Port p = new Port();
+            p.setContainerPort(Integer.parseInt(portMapping.getPort()));
+            p.setHostPort(Integer.parseInt(portMapping.getPort()));
+            // In kubernetes transport protocol always be 'tcp'
+            p.setProtocol("tcp");
+            p.setName(p.getProtocol() + p.getContainerPort());
+            portList.add(p);
+        }
+
+        return portList.toArray(ports);
+    }
+
+    private EnvironmentVariable[] getEnvironmentVars(MemberContext memberCtxt, ClusterContext ctxt) {
+
+        String kubernetesClusterId = CloudControllerUtil.getProperty(ctxt.getProperties(),
+                StratosConstants.KUBERNETES_CLUSTER_ID);
+
+        List<EnvironmentVariable> envVars = new ArrayList<EnvironmentVariable>();
+        addToEnvironment(envVars, ctxt.getPayload());
+        // FIXME member id, should it be unique for a container?
+        addToEnvironment(envVars, StratosConstants.MEMBER_ID, memberCtxt.getMemberId());
+        addToEnvironment(envVars, StratosConstants.LB_CLUSTER_ID, memberCtxt.getLbClusterId());
+        addToEnvironment(envVars, StratosConstants.NETWORK_PARTITION_ID,
+                memberCtxt.getNetworkPartitionId());
+        addToEnvironment(envVars, StratosConstants.KUBERNETES_CLUSTER_ID, kubernetesClusterId);
+        if (memberCtxt.getProperties() != null) {
+            org.apache.stratos.cloud.controller.pojo.Properties props1 = memberCtxt.getProperties();
             if (props1 != null) {
                 for (Property prop : props1.getProperties()) {
-                	addToEnvironment(envVars, prop.getName(), prop.getValue());
+                    addToEnvironment(envVars, prop.getName(), prop.getValue());
                 }
             }
         }
-        
+
         EnvironmentVariable[] vars = new EnvironmentVariable[envVars.size()];
-        
+
         return envVars.toArray(vars);
-        
-	}
-
-	private void addToEnvironment(List<EnvironmentVariable> envVars,
-			String payload) {
-
-		if (payload != null) {
-			String[] entries = payload.split(",");
-			for (String entry : entries) {
-				String[] var = entry.split("=");
-				if(var.length != 2) {
-					continue;
-				}
-				addToEnvironment(envVars, var[0], var[1]);
-			}
-		}
-	}
-
-	private void addToEnvironment(List<EnvironmentVariable> envVars,
-			String name, String value) {
-
-		EnvironmentVariable var = new EnvironmentVariable();
-		var.setName(name);
-		var.setValue(value);
-		envVars.add(var);
-	}
+
+    }
+
+    private void addToEnvironment(List<EnvironmentVariable> envVars, String payload) {
+
+        if (payload != null) {
+            String[] entries = payload.split(",");
+            for (String entry : entries) {
+                String[] var = entry.split("=");
+                if (var.length != 2) {
+                    continue;
+                }
+                addToEnvironment(envVars, var[0], var[1]);
+            }
+        }
+    }
+
+    private void addToEnvironment(List<EnvironmentVariable> envVars, String name, String value) {
+
+        EnvironmentVariable var = new EnvironmentVariable();
+        var.setName(name);
+        var.setValue(value);
+        envVars.add(var);
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2db1eeaf/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesService.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesService.java
index 6aa4050..724891e 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesService.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToKubernetesService.java
@@ -30,35 +30,36 @@ import org.apache.stratos.kubernetes.client.model.Service;
 import com.google.common.base.Function;
 
 /**
- *	Is responsible for converting a {@link MemberContext} object to a Kubernetes {@link Service}
- *	Object.
+ * Is responsible for converting a {@link MemberContext} object to a Kubernetes
+ * {@link Service} Object.
  */
-public class MemberContextToKubernetesService implements Function<MemberContext, Service>{
+public class MemberContextToKubernetesService implements Function<MemberContext, Service> {
 
-	private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
-	
-	@Override
-	public Service apply(MemberContext memberContext) {
-		
-		String clusterId = memberContext.getClusterId();
+    private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+
+    @Override
+    public Service apply(MemberContext memberContext) {
+
+        String clusterId = memberContext.getClusterId();
         ClusterContext clusterContext = dataHolder.getClusterContext(clusterId);
-        
-		String kubernetesClusterId = CloudControllerUtil.getProperty(clusterContext.getProperties(), 
-		StratosConstants.KUBERNETES_CLUSTER_ID);
-		KubernetesClusterContext kubClusterContext = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
-        
+
+        String kubernetesClusterId = CloudControllerUtil.getProperty(
+                clusterContext.getProperties(), StratosConstants.KUBERNETES_CLUSTER_ID);
+        KubernetesClusterContext kubClusterContext = dataHolder
+                .getKubernetesClusterContext(kubernetesClusterId);
+
         Service service = new Service();
         service.setApiVersion("v1beta1");
         service.setId(CloudControllerUtil.getCompatibleId(clusterId));
         service.setKind("Service");
         int hostPort = kubClusterContext.getAnAvailableHostPort();
         clusterContext.addProperty(StratosConstants.ALLOCATED_SERVICE_HOST_PORT, hostPort);
-		service.setPort(hostPort);
+        service.setPort(hostPort);
         Selector selector = new Selector();
         selector.setName(clusterId);
         service.setSelector(selector);
-        
-		return service;
-	}
+
+        return service;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2db1eeaf/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToReplicationController.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToReplicationController.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToReplicationController.java
index 9bc1cf9..b2805cb 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToReplicationController.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/MemberContextToReplicationController.java
@@ -34,56 +34,57 @@ import org.apache.stratos.kubernetes.client.model.State;
 import com.google.common.base.Function;
 
 /**
- *	Is responsible for converting a {@link MemberContext} object to a Kubernetes {@link ReplicationController}
- *	Object.
+ * Is responsible for converting a {@link MemberContext} object to a Kubernetes
+ * {@link ReplicationController} Object.
  */
-public class MemberContextToReplicationController implements Function<MemberContext, ReplicationController>{
+public class MemberContextToReplicationController implements
+        Function<MemberContext, ReplicationController> {
 
-	private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
-	
-	@Override
-	public ReplicationController apply(MemberContext memberContext) {
-		
-		String clusterId = memberContext.getClusterId();
+    private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+
+    @Override
+    public ReplicationController apply(MemberContext memberContext) {
+
+        String clusterId = memberContext.getClusterId();
         ClusterContext clusterContext = dataHolder.getClusterContext(clusterId);
-        
-		ReplicationController contr = new ReplicationController();
-		contr.setId(clusterContext.getClusterId());
-		contr.setKind("ReplicationController");
-		contr.setApiVersion("v1beta1");
-		State desiredState = new State();
-		String minReplicas = CloudControllerUtil.getProperty(clusterContext.getProperties(), 
-				StratosConstants.KUBERNETES_MIN_REPLICAS);
-		desiredState.setReplicas(Integer.parseInt(minReplicas));
-		Selector selector = new Selector();
-		selector.setName(clusterContext.getClusterId());
-		desiredState.setReplicaSelector(selector);
 
-		Pod podTemplate = new Pod();
-		State podState = new State();
-		Manifest manifest = new Manifest();
-		manifest.setVersion("v1beta1");
-		manifest.setId(clusterContext.getClusterId());
+        ReplicationController contr = new ReplicationController();
+        contr.setId(clusterContext.getClusterId());
+        contr.setKind("ReplicationController");
+        contr.setApiVersion("v1beta1");
+        State desiredState = new State();
+        String minReplicas = CloudControllerUtil.getProperty(clusterContext.getProperties(),
+                StratosConstants.KUBERNETES_MIN_REPLICAS);
+        desiredState.setReplicas(Integer.parseInt(minReplicas));
+        Selector selector = new Selector();
+        selector.setName(clusterContext.getClusterId());
+        desiredState.setReplicaSelector(selector);
+
+        Pod podTemplate = new Pod();
+        State podState = new State();
+        Manifest manifest = new Manifest();
+        manifest.setVersion("v1beta1");
+        manifest.setId(clusterContext.getClusterId());
 
-		MemberContextToKubernetesContainer containerFunc = new MemberContextToKubernetesContainer();
-		Container container = containerFunc.apply(memberContext);
+        MemberContextToKubernetesContainer containerFunc = new MemberContextToKubernetesContainer();
+        Container container = containerFunc.apply(memberContext);
 
-		manifest.setContainers(new Container[] { container });
+        manifest.setContainers(new Container[] { container });
 
-		podState.setManifest(manifest);
-		podTemplate.setDesiredState(podState);
-		Label l1 = new Label();
-		l1.setName(clusterContext.getClusterId());
-		podTemplate.setLabels(l1);
+        podState.setManifest(manifest);
+        podTemplate.setDesiredState(podState);
+        Label l1 = new Label();
+        l1.setName(clusterContext.getClusterId());
+        podTemplate.setLabels(l1);
 
-		desiredState.setPodTemplate(podTemplate);
-		contr.setDesiredState(desiredState);
+        desiredState.setPodTemplate(podTemplate);
+        contr.setDesiredState(desiredState);
 
-		Label l2 = new Label();
-		l2.setName(clusterContext.getClusterId());
-		contr.setLabels(l2);
+        Label l2 = new Label();
+        l2.setName(clusterContext.getClusterId());
+        contr.setLabels(l2);
 
-		return contr;
-	}
+        return contr;
+    }
 
 }