Updated Branches: refs/heads/master d9ca9e3b0 -> faca01666
start instance method now takes a MemberContext as the argument, fixed the Partition bean, removed file based persistence of CC Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/e7e52770 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/e7e52770 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/e7e52770 Branch: refs/heads/master Commit: e7e5277032b7312d960e0cb4dd1d28648bc67326 Parents: 9f69444 Author: Nirmal Fernando <[email protected]> Authored: Sat Nov 30 11:58:05 2013 +0530 Committer: Nirmal Fernando <[email protected]> Committed: Sat Nov 30 11:58:05 2013 +0530 ---------------------------------------------------------------------- .../deployment/partition/Partition.java | 4 +- .../impl/CloudControllerServiceImpl.java | 186 ++++--------------- .../interfaces/CloudControllerService.java | 3 +- .../cloud/controller/pojo/MemberContext.java | 66 +++++-- .../controller/topology/TopologyManager.java | 60 +++--- 5 files changed, 118 insertions(+), 201 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e7e52770/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployment/partition/Partition.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployment/partition/Partition.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployment/partition/Partition.java index e434a86..99e0c10 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployment/partition/Partition.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployment/partition/Partition.java @@ -43,7 +43,7 @@ public class Partition implements Serializable{ * Gets the value of the partitionMax property. * */ - public int getPartitionMembersMax() { + public int getPartitionMax() { return partitionMax; } @@ -59,7 +59,7 @@ public class Partition implements Serializable{ * Gets the value of the partitionMin property. * */ - public int getPartitionMembersMin() { + public int getPartitionMin() { return partitionMin; } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e7e52770/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java index b6aed38..2785df0 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java @@ -285,13 +285,21 @@ public class CloudControllerServiceImpl implements CloudControllerService { } @Override - public String startInstance(String clusterId, Partition partition) throws IllegalArgumentException, UnregisteredCartridgeException { + public MemberContext startInstance(MemberContext member) throws IllegalArgumentException, UnregisteredCartridgeException { + if (member == null) { + String msg = "Instance start-up failed. Member is null."; + log.error(msg); + throw new IllegalArgumentException(msg); + } + + String clusterId = member.getClusterId(); + Partition partition = member.getPartition(); + log.info("Starting new instance of cluster : " + clusterId); ComputeService computeService = null; Template template = null; - String ip; if(partition == null) { String msg = "Instance start-up failed. Specified Partition is null. Cluster id: "+clusterId; @@ -318,44 +326,10 @@ public class CloudControllerServiceImpl implements CloudControllerService { throw new UnregisteredCartridgeException(msg); } + member.setCartridgeType(cartridgeType); -// Partition partition_ = TopologyManager.getInstance().getTopology().getPartition(partitionId); -// Scope scope = partition_.getScope(); -// String provider = partition_.getProperty("provider"); final Lock lock = new ReentrantLock(); - // get the subjected ServiceContext -// ServiceContext serviceCtxt = dataHolder -// .getServiceContextFromDomain(clusterId); -// -// if (serviceCtxt == null) { -// String msg = "Not a registered service: domain - " + clusterId; -// log.fatal(msg); -// throw new CloudControllerException(msg); -// } -// -// // load Cartridge -// serviceCtxt.setCartridge(loadCartridge(serviceCtxt.getCartridgeType(), -// dataHolder -// .getCartridges())); -// -// if (serviceCtxt.getCartridge() == null) { -// String msg = "There's no registered Cartridge found. Domain - " -// + clusterId; -// log.fatal(msg); -// throw new CloudControllerException(msg); -// } -// -// if (serviceCtxt.getCartridge().getIaases().isEmpty()) { -// String msg = "There's no registered IaaSes found for Cartridge type: " -// + serviceCtxt.getCartridge().getType(); -// log.fatal(msg); -// throw new CloudControllerException(msg); -// } - - -// for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) { - IaasProvider iaas = cartridge.getIaasProviderOfPartition(partitionId); if(iaas == null) { String msg = "Instance start-up failed for cluster: "+clusterId+". " + @@ -364,13 +338,10 @@ public class CloudControllerServiceImpl implements CloudControllerService { log.fatal(msg); throw new CloudControllerException(msg); } -// IaasContext ctxt; -// if ((ctxt = serviceCtxt.getIaasContext(iaas.getType())) == null) { -// ctxt = serviceCtxt.addIaasContext(iaas.getType()); -// } try { //generating the Unique member ID... String memberID = generateMemberId(clusterId); + member.setMemberId(memberID); //have to add memberID to the payload StringBuilder payload = new StringBuilder(ctxt.getPayload()); payload.append(","); @@ -383,37 +354,6 @@ public class CloudControllerServiceImpl implements CloudControllerService { computeService = iaas.getComputeService(); template = iaas.getTemplate(); -// if(scope == null || scope.name().equals(Scope.PROVIDER.name())) { -// computeService = iaas.getComputeService(); -// template = iaas.getTemplate(); -// } else if(scope.name().equals(Scope.REGION.name())) { -// for(Region region : iaas.getListOfRegions()) { -// if(region.getId().equals(partitionId)) { -// computeService = region.getComputeService(); -// template = region.getTemplate(); -// } -// } -// } else if(scope.name().equals(Scope.ZONE.name())) { -// for(Region region : iaas.getListOfRegions()) { -// for(Zone zone : region.getListOfZones()) { -// if(zone.getId().equals(partitionId)) { -// computeService = zone.getComputeService(); -// template = zone.getTemplate(); -// } -// } -// } -// } else if(scope.name().equals(Scope.HOST.name())) { -// for(Region region : iaas.getListOfRegions()) { -// for(Zone zone : region.getListOfZones()) { -// for(Host host: zone.getListOfHosts()) { -// if(host.getId().equals(partitionId)) { -// computeService = host.getComputeService(); -// template = host.getTemplate(); -// } -// } -// } -// } -// } if (template == null) { String msg = "Failed to start an instance in " + iaas.getType() @@ -424,12 +364,6 @@ public class CloudControllerServiceImpl implements CloudControllerService { throw new CloudControllerException(msg); } - // set instance name as the host name - // template.getOptions().userMetadata("Name", - // serviceCtxt.getHostName()); - // template.getOptions().as(TemplateOptions.class).userMetadata("Name", - // serviceCtxt.getHostName()); - // generate the group id from domain name and sub domain // name. // Should have lower-case ASCII letters, numbers, or dashes. @@ -452,52 +386,42 @@ public class CloudControllerServiceImpl implements CloudControllerService { lock.lock(); try { + // node id + String nodeId = node.getId(); + if (nodeId == null) { + String msg = "Node id of the starting instance is null.\n" + node.toString(); + log.fatal(msg); + throw new CloudControllerException(msg); + } + + member.setNodeId(nodeId); + // reset ip - ip = ""; + String ip = ""; // default behavior is autoIpAssign=false if (autoAssignIpProp == null || (autoAssignIpProp != null && autoAssignIpProp.equals("false"))) { // allocate an IP address - manual IP assigning mode ip = iaas.getIaas().associateAddress(iaas, node); + member.setAllocatedIpAddress(ip); log.info("Allocated ip address: " + ip); } - if (ip.isEmpty() && node.getPublicAddresses() != null && node.getPublicAddresses().iterator().hasNext()) { + // public ip + if (node.getPublicAddresses() != null && node.getPublicAddresses().iterator().hasNext()) { ip = node.getPublicAddresses().iterator().next(); + member.setPublicIpAddress(ip); log.info("Public ip address: " + ip); } - // if not public IP is assigned, we're using private IP - if (ip.isEmpty() && node.getPrivateAddresses() != null && node.getPrivateAddresses().iterator().hasNext()) { + // private IP + if (node.getPrivateAddresses() != null && node.getPrivateAddresses().iterator().hasNext()) { ip = node.getPrivateAddresses().iterator().next(); + member.setPrivateIpAddress(ip); log.info("Private ip address: " + ip); } - String nodeId = node.getId(); - if (nodeId == null) { - String msg = "Node id of the starting instance is null.\n" + node.toString(); - log.fatal(msg); - throw new CloudControllerException(msg); - } - MemberContext memberCtxt = new MemberContext(memberID, nodeId, clusterId, partitionId, cartridgeType, ip); - dataHolder.addMemberContext(memberCtxt); - - // add node ID -// ctxt.addNodeId(node.getId()); -// ctxt.addNodeToPublicIp(node.getId(), ip); - - // to faster look up -// dataHolder.addNodeId( -// node.getId(), serviceCtxt); -// -// dataHolder.addNodeId(memberID, node.getId()); -// -// serviceCtxt.getCartridge().setLastlyUsedIaas(iaas); -// -// // add this ip to the topology -// appendToPublicIpProperty(ip, serviceCtxt); -// -// dataHolder.updateActiveInstanceCount(iaas.getType(), 1); + dataHolder.addMemberContext(member); // persist in registry persist(); @@ -508,7 +432,6 @@ public class CloudControllerServiceImpl implements CloudControllerService { //update the topology with the newly spawned member // publish data -// CartridgeInstanceDataPublisherTask.publish(); if (log.isDebugEnabled()) { log.debug("Node details: \n" + node.toString() + "\n***************\n"); @@ -520,7 +443,7 @@ public class CloudControllerServiceImpl implements CloudControllerService { + ip + "\tNode Id: " + nodeId); - return ip; + return member; } finally { // release the lock @@ -651,7 +574,7 @@ public class CloudControllerServiceImpl implements CloudControllerService { String memberId = ctxt.getMemberId(); String clusterId = ctxt.getClusterId(); - String partitionId = ctxt.getPartitionId(); + String partitionId = ctxt.getPartition().getId(); String cartridgeType = ctxt.getCartridgeType(); String nodeId = ctxt.getNodeId(); @@ -1008,52 +931,11 @@ public class CloudControllerServiceImpl implements CloudControllerService { */ private IaasProvider terminate(IaasProvider iaasTemp, String nodeId, MemberContext ctxt) { -// Scope scope = partition.getScope(); -// String partitionId = partition.getId(); -// // this is just to be safe -// if (iaasTemp.getComputeService() == null) { -// String msg = "Unexpeced error occured! IaasContext's ComputeService is null!"; -// log.error(msg); -// throw new CloudControllerException(msg); -// } -// -// if(scope == null || scope.name().equals(Scope.PROVIDER.name())) { -// iaasTemp.getComputeService().destroyNode(nodeId); -// } else if(scope.name().equals(Scope.REGION.name())) { -// for(Region region : iaasTemp.getListOfRegions()) { -// if(region.getId().equals(partitionId)) { -// region.getComputeService(); -// } -// } -// } else if(scope.name().equals(Scope.ZONE.name())) { -// for(Region region : iaasTemp.getListOfRegions()) { -// for(Zone zone : region.getListOfZones()) { -// if(zone.getId().equals(partitionId)) { -// zone.getComputeService().destroyNode(nodeId); -// } -// } -// } -// } else if(scope.name().equals(Scope.HOST.name())) { -// for(Region region : iaasTemp.getListOfRegions()) { -// for(Zone zone : region.getListOfZones()) { -// for(Host host: zone.getListOfHosts()) { -// if(host.getId().equals(partitionId)) { -// host.getComputeService().destroyNode(nodeId); -// } -// } -// } -// } -// } // destroy the node iaasTemp.getComputeService().destroyNode(nodeId); - String autoAssignIpProp = iaasTemp - .getProperty(CloudControllerConstants.AUTO_ASSIGN_IP_PROPERTY); - // release allocated IP address - if (autoAssignIpProp == null - || (autoAssignIpProp - .equals("false"))) { + if (ctxt.getAllocatedIpAddress() != null) { // allocate an IP address - manual IP assigning mode iaasTemp.getIaas().releaseAddress(iaasTemp, ctxt.getAllocatedIpAddress()); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e7e52770/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java index bae0922..ee71f62 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java @@ -27,6 +27,7 @@ import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; import org.apache.stratos.cloud.controller.exception.UnregisteredCartridgeException; import org.apache.stratos.cloud.controller.exception.UnregisteredClusterException; import org.apache.stratos.cloud.controller.pojo.CartridgeInfo; +import org.apache.stratos.cloud.controller.pojo.MemberContext; import org.apache.stratos.cloud.controller.pojo.Registrant; /** @@ -84,7 +85,7 @@ public interface CloudControllerService { * an instance need to be started. * @return public IP which is associated with the newly started instance. */ - public String startInstance(String clusterId, Partition partition) throws IllegalArgumentException, UnregisteredCartridgeException; + public MemberContext startInstance(MemberContext member) throws IllegalArgumentException, UnregisteredCartridgeException; /** * Calling this method will spawn more than one ininstances in the http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e7e52770/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/MemberContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/MemberContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/MemberContext.java index 64fd3c2..11ebb8a 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/MemberContext.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/MemberContext.java @@ -18,8 +18,10 @@ */ package org.apache.stratos.cloud.controller.pojo; +import org.apache.stratos.cloud.controller.deployment.partition.Partition; + /** - * Holds runtime data of a Member. + * Holds information about a Member. * @author nirmal * */ @@ -31,21 +33,26 @@ public class MemberContext { private String nodeId; // cluster id of this member private String clusterId; - // partition id this member is in. - private String partitionId; + // partition this member is in. + private Partition partition; // cartridge type this member belongs to. private String cartridgeType; - // allocated ip + // private ip + private String privateIpAddress; + // public ip + private String publicIpAddress; + // manually allocated ip private String allocatedIpAddress; + // member initiated time + private long initTime; - public MemberContext(String id, String nodeId, String clusterId, String partitionId, String cartridgeType, String ip) { + public MemberContext(String id, String clusterId, Partition partition) { this.memberId = id; - this.nodeId = nodeId; this.clusterId = clusterId; - this.partitionId = partitionId; - this.cartridgeType = cartridgeType; - this.allocatedIpAddress = ip; - + this.setPartition(partition); + } + + public MemberContext() { } public String getMemberId() { @@ -66,24 +73,51 @@ public class MemberContext { public void setClusterId(String clusterId) { this.clusterId = clusterId; } - public String getPartitionId() { - return partitionId; - } - public void setPartitionId(String partitionId) { - this.partitionId = partitionId; - } public String getCartridgeType() { return cartridgeType; } public void setCartridgeType(String cartridgeType) { this.cartridgeType = cartridgeType; } + public Partition getPartition() { + return partition; + } + + public void setPartition(Partition partition) { + this.partition = partition; + } + + public String getPublicIpAddress() { + return publicIpAddress; + } + + public void setPublicIpAddress(String publicIpAddress) { + this.publicIpAddress = publicIpAddress; + } + + public String getPrivateIpAddress() { + return privateIpAddress; + } + + public void setPrivateIpAddress(String privateIpAddress) { + this.privateIpAddress = privateIpAddress; + } + public String getAllocatedIpAddress() { return allocatedIpAddress; } + public void setAllocatedIpAddress(String allocatedIpAddress) { this.allocatedIpAddress = allocatedIpAddress; } + + public long getInitTime() { + return initTime; + } + + public void setInitTime(long initTime) { + this.initTime = initTime; + } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e7e52770/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java index 8d8d58a..7c36613 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java @@ -80,24 +80,24 @@ public class TopologyManager { synchronized (TopologyManager.class) { if(this.topology == null) { //need to initialize the topology - if(this.topologyFile.exists()) { - try { - currentContent = FileUtils.readFileToString(this.topologyFile); - Gson gson = new Gson(); - this.topology = gson.fromJson(currentContent, Topology.class); - if(log.isDebugEnabled()) { - log.debug("The current topology is: " + currentContent); - } - } catch (IOException e) { - log.error(e.getMessage()); - throw new CloudControllerException(e.getMessage(), e); - } - } else { +// if(this.topologyFile.exists()) { +// try { +// currentContent = FileUtils.readFileToString(this.topologyFile); +// Gson gson = new Gson(); +// this.topology = gson.fromJson(currentContent, Topology.class); +// if(log.isDebugEnabled()) { +// log.debug("The current topology is: " + currentContent); +// } +// } catch (IOException e) { +// log.error(e.getMessage()); +// throw new CloudControllerException(e.getMessage(), e); +// } +// } else { if(log.isDebugEnabled()) { log.debug("Creating new topology"); } this.topology = new Topology(); - } +// } } } if(log.isDebugEnabled()) { @@ -109,22 +109,22 @@ public class TopologyManager { public synchronized void updateTopology(Topology topology) { synchronized (TopologyManager.class) { this.topology = topology; - if (this.topologyFile.exists()) { - this.backup.delete(); - this.topologyFile.renameTo(backup); - } - Gson gson = new Gson(); - String message = gson.toJson(topology); - // overwrite the topology file - try { - FileUtils.writeStringToFile(this.topologyFile, message); - if(log.isDebugEnabled()) { - log.debug("The updated topology is: " + message); - } - } catch (IOException e) { - log.error(e.getMessage()); - throw new CloudControllerException(e.getMessage(), e); - } +// if (this.topologyFile.exists()) { +// this.backup.delete(); +// this.topologyFile.renameTo(backup); +// } +// Gson gson = new Gson(); +// String message = gson.toJson(topology); +// // overwrite the topology file +// try { +// FileUtils.writeStringToFile(this.topologyFile, message); +// if(log.isDebugEnabled()) { +// log.debug("The updated topology is: " + message); +// } +// } catch (IOException e) { +// log.error(e.getMessage()); +// throw new CloudControllerException(e.getMessage(), e); +// } } }
