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 2013/11/27 19:55:17 UTC
[20/26] git commit: fixing merge conflicts
fixing merge conflicts
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/61f8d8c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/61f8d8c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/61f8d8c8
Branch: refs/heads/master
Commit: 61f8d8c81071f2b2217fe42927fcead0682f72f2
Parents: 961cbd8 757f7bf
Author: Nirmal Fernando <ni...@apache.org>
Authored: Wed Nov 27 11:32:43 2013 +0530
Committer: Nirmal Fernando <ni...@apache.org>
Committed: Wed Nov 27 11:32:43 2013 +0530
----------------------------------------------------------------------
components/org.apache.stratos.adc.mgt/pom.xml | 5 +
.../adc/mgt/dao/CartridgeSubscriptionInfo.java | 9 +
.../org/apache/stratos/adc/mgt/dao/Cluster.java | 71 +
.../stratos/adc/mgt/dao/DataCartridge.java | 10 +
.../stratos/adc/mgt/dto/SubscriptionInfo.java | 2 +
.../exception/PersistenceManagerException.java | 49 +
.../internal/ADCManagementServerComponent.java | 5 +-
.../mgt/listener/InstanceStatusListener.java | 31 +-
.../manager/CartridgeSubscriptionManager.java | 15 +-
.../adc/mgt/payload/NonCarbonPayload.java | 1 +
.../apache/stratos/adc/mgt/payload/Payload.java | 4 +-
.../stratos/adc/mgt/payload/PayloadArg.java | 9 +
.../stratos/adc/mgt/payload/PayloadFactory.java | 2 +-
.../DatabaseBasedPersistenceManager.java | 1408 ++++++++++++++++++
.../adc/mgt/persistence/PersistenceManager.java | 79 +
.../mgt/publisher/ArtifactUpdatePublisher.java | 44 +-
.../stratos/adc/mgt/repository/Repository.java | 9 +
.../mgt/service/RepoNotificationService.java | 11 +-
.../service/RepositoryInformationService.java | 6 +-
.../mgt/subscription/CartridgeSubscription.java | 67 +-
.../subscription/DataCartridgeSubscription.java | 47 +-
.../MultiTenantCartridgeSubscription.java | 12 +-
.../SingleTenantCartridgeSubscription.java | 38 +-
.../mgt/utils/ApplicationManagementUtil.java | 3 +-
.../adc/mgt/utils/PersistenceManager.java | 44 +-
.../adc/mgt/utils/RepoPasswordMgtUtil.java | 25 +-
.../stratos/autoscaler/ClusterContext.java | 22 +-
.../algorithm/AutoscaleAlgorithm.java | 6 +-
.../autoscaler/algorithm/OneAfterAnother.java | 178 ++-
.../PartitionGroupOneAfterAnother.java | 146 ++
.../autoscaler/algorithm/RoundRobin.java | 172 +--
.../cloud/controller/CloudControllerClient.java | 2 +-
.../deployers/DeploymentPolicyReader.java | 19 +-
.../rule/AutoscalerRuleEvaluator.java | 14 +-
.../stratos/autoscaler/util/AutoscalerUtil.java | 4 +-
.../src/main/resources/autoscaler.drl | 114 --
.../stratos/autoscaler/TestKnowledgeBase.java | 50 +
.../impl/CloudControllerServiceImpl.java | 51 +-
.../controller/topology/TopologyBuilder.java | 6 +-
.../topology/TopologyEventSender.java | 1 +
.../statistics/LoadBalancerStatsPublisher.java | 11 +
.../statistics/WSO2CEPStatsPublisher.java | 40 +-
.../extension/api/LoadBalancerExtension.java | 2 +-
.../api/LoadBalancerStatsNotifier.java | 7 +-
.../load/balancer/LoadBalancerContext.java | 58 +-
.../balancer/LoadBalancerTopologyReceiver.java | 207 +++
.../stratos/load/balancer/RequestDelegator.java | 42 +-
.../algorithm/LoadBalanceAlgorithm.java | 10 +-
.../algorithm/LoadBalanceAlgorithmFactory.java | 2 +-
.../load/balancer/algorithm/RoundRobin.java | 18 +-
.../TenantAwareLoadBalanceEndpoint.java | 36 +-
.../internal/LoadBalancerServiceComponent.java | 49 +-
.../observers/WSO2CEPStatsObserver.java | 10 +-
components/org.apache.stratos.messaging/pom.xml | 6 +-
.../broker/heartbeat/TopicHealthChecker.java | 11 +-
.../messaging/domain/topology/Cluster.java | 10 +-
.../stratos/messaging/event/EventListener.java | 50 -
.../messaging/event/EventObservable.java | 2 +
.../synchronization/ArtifactUpdatedEvent.java | 11 +-
.../event/topology/ClusterCreatedEvent.java | 3 +-
.../topology/ClusterCreatedEventListener.java | 30 -
.../event/topology/ClusterRemovedEvent.java | 15 +
.../topology/ClusterRemovedEventListener.java | 30 -
.../topology/CompleteTopologyEventListener.java | 30 -
.../topology/InstanceSpawnedEventListener.java | 30 -
.../topology/MemberActivatedEventListener.java | 30 -
.../topology/MemberStartedEventListener.java | 30 -
.../topology/MemberSuspendedEventListener.java | 30 -
.../topology/MemberTerminatedEventListener.java | 30 -
.../topology/ServiceCreatedEventListener.java | 30 -
.../topology/ServiceRemovedEventListener.java | 30 -
.../messaging/listener/EventListener.java | 51 +
.../topology/ClusterCreatedEventListener.java | 30 +
.../topology/ClusterRemovedEventListener.java | 30 +
.../topology/CompleteTopologyEventListener.java | 30 +
.../topology/InstanceSpawnedEventListener.java | 30 +
.../topology/MemberActivatedEventListener.java | 30 +
.../topology/MemberStartedEventListener.java | 30 +
.../topology/MemberSuspendedEventListener.java | 30 +
.../topology/MemberTerminatedEventListener.java | 30 +
.../topology/ServiceCreatedEventListener.java | 30 +
.../topology/ServiceRemovedEventListener.java | 30 +
.../message/filter/topology/ClusterFilter.java | 83 ++
.../message/filter/topology/ServiceFilter.java | 83 ++
.../topology/ClusterCreatedEventProcessor.java | 33 +-
.../topology/ClusterRemovedEventProcessor.java | 35 +-
.../CompleteTopologyEventProcessor.java | 43 +-
.../topology/InstanceSpawnedEventProcessor.java | 27 +-
.../topology/MemberActivatedEventProcessor.java | 24 +
.../topology/MemberStartedEventProcessor.java | 24 +
.../topology/MemberSuspendedEventProcessor.java | 24 +
.../MemberTerminatedEventProcessor.java | 24 +
.../topology/ServiceCreatedEventProcessor.java | 12 +
.../topology/ServiceRemovedEventProcessor.java | 12 +
.../topology/TopologyEventProcessorChain.java | 4 +-
.../topology/TopologyEventMessageDelegator.java | 3 +-
components/pom.xml | 36 +-
.../HealthStatisticsEventBuilder.xml | 10 +
.../AverageLoadAverageEventFormatter.xml | 11 +
.../AverageMemoryConsumptionEventFormatter.xml | 11 +
.../FaultMessageEventFormatter.xml | 11 +
.../GradientLoadAverageEventFormatter.xml | 11 +
.../GradientMemoryConsumptionEventFormatter.xml | 11 +
...econdDerivativeLoadAverageEventFormatter.xml | 11 +
...erivativeMemoryConsumptionEventFormatter.xml | 11 +
.../executionplans/AverageHeathRequest.xml | 21 +
.../executionplans/GradientOfHealthRequest.xml | 24 +
.../SecondDerivativeOfHealthRequest.xml | 21 +
.../extension/FaultHandlingWindowProcessor.java | 180 +++
.../src/main/bin/haproxy-extension.sh | 1 +
.../pom.xml | 17 +-
.../pom.xml | 1 +
pom.xml | 4 +-
.../distribution/src/main/assembly/bin.xml | 6 +-
.../main/autoscale-policies/economyPolicy.xml | 60 +-
.../distribution/src/main/conf/autoscaler.drl | 52 +-
.../distribution/src/main/conf/log4j.properties | 18 +-
.../deployment-policies/economy-deployment.xml | 57 +-
.../src/main/resources/log4j.properties | 168 ---
.../cartridge-agent/ec2/php/cartridge-agent.sh | 123 --
.../modules/deployment-synchronizer/pom.xml | 81 +
.../synchronizer/ArtifactRepository.java | 31 +
.../synchronizer/RepositoryInformation.java | 65 +
.../git/impl/GitBasedArtifactRepository.java | 666 +++++++++
.../CustomJschConfigSessionFactory.java | 64 +
.../GitDeploymentSynchronizerConstants.java | 61 +
.../git/internal/RepositoryContext.java | 131 ++
.../GitDeploymentSyncronizerConfiguration.java | 29 +
.../synchronizer/git/util/Utilities.java | 73 +
.../modules/event-subscriber/pom.xml | 13 +-
.../src/main/bin/event-subscriber.sh | 4 +-
.../event/subscriber/ArtifactListener.java | 90 +-
.../cartridge/agent/event/subscriber/Main.java | 1 +
.../src/main/bin/health-publisher.sh | 2 +-
.../agent/health/publisher/HealthPublisher.java | 23 +-
.../health/publisher/HealthPublisherClient.java | 57 +-
.../cartridge/agent/health/publisher/Main.java | 26 +-
products/cartridge-agent/pom.xml | 1 +
.../distribution/src/main/assembly/bin.xml | 10 +-
.../distribution/src/main/conf/log4j.properties | 224 ++-
.../src/main/resources/log4j.properties | 196 ---
.../distribution/src/main/bin/stratos.bat | 2 +-
.../distribution/src/main/bin/stratos.sh | 3 +
.../load-balancer/modules/p2-profile/pom.xml | 8 +
.../resources/stratos_foundation.sql | 1 +
145 files changed, 5467 insertions(+), 1744 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/61f8d8c8/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/61f8d8c8/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/utils/ApplicationManagementUtil.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/utils/ApplicationManagementUtil.java
index 6d673b6,0450def..a5c3437
--- a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/utils/ApplicationManagementUtil.java
+++ b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/utils/ApplicationManagementUtil.java
@@@ -20,9 -19,23 +20,8 @@@ package org.apache.stratos.adc.mgt.util
*
*/
-package org.apache.stratos.adc.mgt.utils;
-
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.rmi.RemoteException;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.regex.Pattern;
+import com.google.gson.Gson;
-
import org.apache.axis2.clustering.ClusteringAgent;
import org.apache.axis2.clustering.Member;
import org.apache.axis2.clustering.management.GroupManagementAgent;
@@@ -58,22 -79,8 +57,21 @@@ import org.eclipse.jgit.lib.Ref
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
+import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
-
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.rmi.RemoteException;
+import java.text.DecimalFormat;
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
/**
* This class contains utility methods used by ApplicationManagementService.
*/
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/61f8d8c8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
index bc6877a,b50bc89..3ee7fae
--- 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
@@@ -18,33 -18,27 +18,36 @@@
*/
package org.apache.stratos.cloud.controller.impl;
+ import com.google.common.collect.Lists;
+ import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.concurrent.ThreadExecutor;
import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.exception.InvalidCartridgeTypeException;
+import org.apache.stratos.cloud.controller.exception.InvalidClusterException;
+import org.apache.stratos.cloud.controller.exception.InvalidMemberException;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
import org.apache.stratos.cloud.controller.exception.UnregisteredCartridgeException;
-import org.apache.stratos.cloud.controller.exception.UnregisteredServiceException;
+import org.apache.stratos.cloud.controller.exception.UnregisteredClusterException;
import org.apache.stratos.cloud.controller.interfaces.CloudControllerService;
+import org.apache.stratos.cloud.controller.interfaces.Iaas;
import org.apache.stratos.cloud.controller.persist.Deserializer;
+import org.apache.stratos.cloud.controller.pojo.ClusterContext;
+import org.apache.stratos.cloud.controller.pojo.MemberContext;
+import org.apache.stratos.cloud.controller.pojo.Registrant;
import org.apache.stratos.cloud.controller.publisher.CartridgeInstanceDataPublisherTask;
import org.apache.stratos.cloud.controller.registry.RegistryManager;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
import org.apache.stratos.cloud.controller.topic.TopologySynchronizerTask;
import org.apache.stratos.cloud.controller.topology.TopologyBuilder;
import org.apache.stratos.cloud.controller.topology.TopologyEventMessageDelegator;
+ import org.apache.stratos.cloud.controller.topology.TopologyManager;
import org.apache.stratos.cloud.controller.util.*;
-import org.apache.stratos.cloud.controller.util.Properties;
-import org.apache.stratos.messaging.domain.topology.Member;
-import org.apache.stratos.messaging.domain.topology.Partition;
-import org.apache.stratos.messaging.domain.topology.Scope;
+import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
+import org.apache.stratos.messaging.domain.policy.DeploymentPolicy;
+import org.apache.stratos.messaging.domain.policy.Partition;
+import org.apache.stratos.messaging.domain.policy.PartitionGroup;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.NodeMetadata;
@@@ -58,8 -52,9 +61,10 @@@ import org.wso2.carbon.ntask.core.TaskM
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
+ import java.io.File;
+ import java.io.IOException;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@@ -535,8 -482,9 +527,9 @@@ public class CloudControllerServiceImp
+ ". Hence, will try to start in another IaaS if available.",
e);
}
+ }
- }
+// }
return null;
}
@@@ -604,339 -552,175 +597,330 @@@
}
}
+
+ @Override
+ public void terminateInstance(String memberId) throws InvalidMemberException, InvalidCartridgeTypeException,
+ IllegalArgumentException{
- @Override
- public boolean terminateInstance(String clusterId, Partition partition) {
-
- String partitionId = partition.getId();
- String provider = partition.getProperty("provider");
- log.info("Starting to terminate an instance of domain : " + clusterId);
+ if(memberId == null) {
+ String msg = "Termination failed. Null member id.";
+ log.error(msg);
+ throw new IllegalArgumentException(msg);
+ }
+// String nodeId = dataHolder.getNodeId(memberId);
+ MemberContext ctxt = dataHolder.getMemberContextOfMemberId(memberId);
+
+ if(ctxt == null) {
+ String msg = "Termination failed. Invalid Member Id: "+memberId;
+ log.error(msg);
+ throw new InvalidMemberException(msg);
+ }
+
+ ThreadExecutor exec = new ThreadExecutor();
+ exec.execute(new InstanceTerminator(ctxt));
+ exec.shutdown();
-
- // return true;
- 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, if null
- //if (serviceCtxt.getCartridge() == null) {
- serviceCtxt.setCartridge(loadCartridge(
- serviceCtxt.getCartridgeType(),
- dataHolder.getCartridges()));
- //}
-
- // if still, Cartridge is null
- if (serviceCtxt.getCartridge() == null) {
- String msg = "There's no registered Cartridge found. Domain - "
- + clusterId;
- log.fatal(msg);
- throw new CloudControllerException(msg);
- }
+// log.info("Termination of an instance which is belong to domain '"
+// + clusterId
+// + "' , failed! Reason: No matching "
+// + "running instance found in any available IaaS.");
+//
+// return false;
- for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+ }
+
+ private class InstanceTerminator implements Runnable {
- String msg = "Failed to terminate an instance in "
- + iaas.getType()
- + ". Hence, will try to terminate an instance in another IaaS if possible.";
- //TODO adding more locations and retrieve it from the request received
- if(iaas.getType().equals(provider)) {
- String nodeId = null;
+ private MemberContext ctxt;
- IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
+ public InstanceTerminator(MemberContext ctxt) {
+ this.ctxt = ctxt;
+ }
- // terminate the last instance first
- for (String id : Lists.reverse(ctxt.getNodeIds())) {
- if (id != null) {
- nodeId = id;
- break;
- }
+ @Override
+ public void run() {
+
+ String memberId = ctxt.getMemberId();
+ String clusterId = ctxt.getClusterId();
+ String partitionId = ctxt.getPartitionId();
+ String cartridgeType = ctxt.getCartridgeType();
+ String nodeId = ctxt.getNodeId();
+
+ try {
+ // these will never be null, since we do not add null values for these.
+ Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+
+ log.info("Starting to terminate an instance with member id : " + memberId +
+ " in partition id: " + partitionId + " of cluster id: " + clusterId +
+ " and of cartridge type: " + cartridgeType);
+
+ if (cartridge == null) {
+ String msg =
+ "Termination of Member Id: " + memberId + " failed. " +
+ "Cannot find a matching Cartridge for type: " +
+ cartridgeType;
+ log.error(msg);
+ throw new InvalidCartridgeTypeException(msg);
}
// if no matching node id can be found.
if (nodeId == null) {
- log.warn(msg
- + " : Reason- No matching instance found for domain: "
- + clusterId
- + ".");
- continue;
+ String msg =
+ "Termination failed. Cannot find a node id for Member Id: " +
+ memberId;
+ log.error(msg);
+ throw new InvalidMemberException(msg);
}
- //get the partition for the member
- //TODO Fix ME with autoscalers input
- Partition partition_ = TopologyManager.getInstance().getTopology().getService(serviceCtxt.getCartridgeType()).
- getCluster(serviceCtxt.getClusterId()).getMemberFromIaasNodeId(nodeId).getPartition();
+ // 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, if null
+ // //if (serviceCtxt.getCartridge() == null) {
+ // serviceCtxt.setCartridge(loadCartridge(
+ // serviceCtxt.getCartridgeType(),
+ // dataHolder.getCartridges()));
+ // //}
+ //
+ // // if still, Cartridge is null
+ // if (serviceCtxt.getCartridge() == null) {
+ // String msg = "There's no registered Cartridge found. Domain - "
+ // + clusterId;
+ // log.fatal(msg);
+ // throw new CloudControllerException(msg);
+ // }
+
+ // for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+
+ IaasProvider iaas = cartridge.getIaasProviderOfPartition(partitionId);
+
- // String msg = "Failed to terminate an instance in "
- // + iaas.getType()
- // + ". Hence, will try to terminate an instance in another IaaS if possible.";
- // //TODO adding more locations and retrieve it from the request received
- // String nodeId = null;
+
- // IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
+
+ // // terminate the last instance first
+ // for (String id : Lists.reverse(ctxt.getNodeIds())) {
+ // if (id != null) {
+ // nodeId = id;
+ // break;
+ // }
+ // }
// terminate it!
- terminate(iaas, ctxt, nodeId, partition_);
+ terminate(iaas, nodeId, ctxt);
// log information
- logTermination(nodeId, ctxt, serviceCtxt);
+ logTermination(nodeId, ctxt);
+
+ } catch (Exception e) {
+ String msg =
+ "Starting to terminate an instance with member id : " + memberId +
+ " in partition id: " + partitionId + " of cluster id: " +
+ clusterId + " and of cartridge type: " + cartridgeType;
+ log.error(msg);
+ throw new CloudControllerException(msg);
}
-
-
- return true;
-
- }
-
- log.info("Termination of an instance which is belong to domain '"
- + clusterId
- + "' , failed! Reason: No matching "
- + "running instance found in any available IaaS.");
-
- return false;
-
- }
-
- @Override
- public boolean terminateInstances(int noOfInstances, String clusterId, Partition partition) {
- log.info("vvvvvvvvvvvvvvvvv");
- return false; //TODO
+ }
}
- @Override
- public boolean terminateUnhealthyInstances(List<String> instancesToBeTerminated) {
- log.info("vvvvvvvvvvdddvvvvvvv");
- return false; //TODO
- }
+// private
+// void
+// terminateInstance(MemberContext ctxt) throws InvalidCartridgeTypeException,
+// InvalidMemberException {
+// // these will never be null, since we do not add null values for these.
+// String memberId = ctxt.getMemberId();
+// String clusterId = ctxt.getClusterId();
+// String partitionId = ctxt.getPartitionId();
+// String cartridgeType = ctxt.getCartridgeType();
+// String nodeId = ctxt.getNodeId();
+//
+// Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+//
+// log.info("Starting to terminate an instance with member id : " + memberId+
+// " in partition id: "+partitionId+" of cluster id: "+clusterId+ " and of cartridge type: "+cartridgeType);
+//
+// if(cartridge == null) {
+// String msg = "Termination of Member Id: "+memberId+" failed. " +
+// "Cannot find a matching Cartridge for type: "+cartridgeType;
+// log.error(msg);
+// throw new InvalidCartridgeTypeException(msg);
+// }
+//
+//// Scope scope = partition.getScope();
+//// String provider = partition.getProperty("provider");
+//
+// // if no matching node id can be found.
+// if (nodeId == null) {
+//
+// String msg = "Termination failed. Cannot find a node id for Member Id: "+memberId;
+// log.error(msg);
+// throw new InvalidMemberException(msg);
+// }
+//// 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, if null
+//// //if (serviceCtxt.getCartridge() == null) {
+//// serviceCtxt.setCartridge(loadCartridge(
+//// serviceCtxt.getCartridgeType(),
+//// dataHolder.getCartridges()));
+//// //}
+////
+//// // if still, Cartridge is null
+//// if (serviceCtxt.getCartridge() == null) {
+//// String msg = "There's no registered Cartridge found. Domain - "
+//// + clusterId;
+//// log.fatal(msg);
+//// throw new CloudControllerException(msg);
+//// }
+//
+//// for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+//
+// IaasProvider iaas = cartridge.getIaasProviderOfPartition(partitionId);
+//
+//// String msg = "Failed to terminate an instance in "
+//// + iaas.getType()
+//// + ". Hence, will try to terminate an instance in another IaaS if possible.";
+//// //TODO adding more locations and retrieve it from the request received
+//// String nodeId = null;
+//
+//// IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
+//
+//// // terminate the last instance first
+//// for (String id : Lists.reverse(ctxt.getNodeIds())) {
+//// if (id != null) {
+//// nodeId = id;
+//// break;
+//// }
+//// }
+//
+//
+//
+// // terminate it!
+// terminate(iaas, nodeId, ctxt);
+//
+// // log information
+// logTermination(nodeId, ctxt);
+// }
+
+// @Override
+// public boolean terminateInstances(String[] memberIds) throws IllegalArgumentException, InvalidMemberException, InvalidCartridgeTypeException {
+// for (String memberId : memberIds) {
+// terminateInstance(memberId);
+// }
+// }
+
+// @Override
+// public boolean terminateUnhealthyInstances(List<String> instancesToBeTerminated) {
+// log.info("vvvvvvvvvvdddvvvvvvv");
+// return false; //TODO
+// }
@Override
- public boolean terminateAllInstances(String clusterId) {
-
- boolean isAtLeastOneTerminated = false;
+ public void terminateAllInstances(String clusterId) throws IllegalArgumentException, InvalidClusterException {
-
- log.info("Starting to terminate all instances of domain : "
+ log.info("Starting to terminate all instances of cluster : "
+ clusterId);
-
- 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, if null
- 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);
- }
-
- for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
-
- IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
-
- if (ctxt == null) {
- log.error("Iaas Context for " + iaas.getType()
- + " not found. Cannot terminate instances");
- continue;
- }
-
- ArrayList<String> temp = new ArrayList<String>(ctxt.getNodeIds());
- for (String id : temp) {
- if (id != null) {
- // terminate it!
- Collection<Member> members = TopologyManager.getInstance().getTopology().
- getService(serviceCtxt.getCartridgeType()).
- getCluster(serviceCtxt.getClusterId()).getMembers();
- for (Iterator iterator = members.iterator(); iterator.hasNext();) {
- Member member = (Member) iterator.next();
- terminate(iaas, ctxt, member.getIaasNodeId(), member.getPartition());
- }
-
- // log information
- logTermination(id, ctxt, serviceCtxt);
-
- isAtLeastOneTerminated = true;
- }
- }
+
+ if(clusterId == null) {
+ String msg = "Instance termination failed. Cluster id is null.";
+ log.error(msg);
+ throw new IllegalArgumentException(msg);
}
-
- if (isAtLeastOneTerminated) {
- return true;
+
+ List<MemberContext> ctxts = dataHolder.getMemberContextsOfClusterId(clusterId);
+
+ if(ctxts == null) {
+ String msg = "Instance termination failed. No members found for cluster id: "+clusterId;
+ log.error(msg);
+ throw new InvalidClusterException(msg);
}
-
- log.info("Termination of an instance which is belong to domain '"
- + clusterId + "', failed! Reason: No matching "
- + "running instance found in lastly used IaaS.");
-
- return false;
+
+ ThreadExecutor exec = new ThreadExecutor();
+ for (MemberContext memberContext : ctxts) {
+ exec.execute(new InstanceTerminator(memberContext));
+ }
+
+ exec.shutdown();
+
+// 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, if null
+// 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);
+// }
+
+// for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+//
+// IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
+//
+// if (ctxt == null) {
+// log.error("Iaas Context for " + iaas.getType()
+// + " not found. Cannot terminate instances");
+// continue;
+// }
+//
+// ArrayList<String> temp = new ArrayList<String>(ctxt.getNodeIds());
+// for (String id : temp) {
+// if (id != null) {
+// // terminate it!
+// //TODO need to enable once partition added to the topology
+// /*Collection<Member> members = TopologyManager.getInstance().getTopology().
+// getService(serviceCtxt.getCartridgeType()).
+// getCluster(serviceCtxt.getClusterId()).getMembers();
+// for (Iterator iterator = members.iterator(); iterator.hasNext();) {
+// Member member = (Member) iterator.next();
+// terminate(iaas, ctxt, member.getIaasNodeId(), member.getPartition());
+// }*/
+//
+// // log information
+// logTermination(id, ctxt, serviceCtxt);
+//
+// isAtLeastOneTerminated = true;
+// }
+// }
+// }
+//
+// if (isAtLeastOneTerminated) {
+// return true;
+// }
+//
+// log.info("Termination of an instance which is belong to domain '"
+// + clusterId + "', failed! Reason: No matching "
+// + "running instance found in lastly used IaaS.");
+//
+// return false;
}
@@@ -1307,95 -1060,20 +1291,96 @@@
//subDomain = checkSubDomain(subDomain);
// find the service context
- ServiceContext subjectedSerCtxt = dataHolder
- .getServiceContextFromDomain(clusterId);
- TopologyBuilder.handleClusterRemoved(subjectedSerCtxt);
+// ServiceContext subjectedSerCtxt = dataHolder
+// .getServiceContextFromDomain(clusterId);
+
+
+
+// TopologyBuilder.handleClusterRemoved(subjectedSerCtxt);
+
+// if (subjectedSerCtxt == null) {
+// throw new UnregisteredClusterException(
+// "No registered service found for domain: " + clusterId);
+// }
+//
+// // get the service definition file.
+// File serviceDefFile = subjectedSerCtxt.getFile();
+//
+// // delete that file, so that it gets automatically undeployed.
+// return serviceDefFile.delete();
+ }
- if (subjectedSerCtxt == null) {
- throw new UnregisteredServiceException(
- "No registered service found for domain: " + clusterId);
- }
++
- // get the service definition file.
- File serviceDefFile = subjectedSerCtxt.getFile();
+ @Override
+ public boolean validateDeploymentPolicy(String cartridgeType, DeploymentPolicy deploymentPolicy)
+ throws InvalidPartitionException, InvalidCartridgeTypeException {
+
+ Map<String, IaasProvider> partitionToIaasProviders = new ConcurrentHashMap<String, IaasProvider>();
+
+ Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+
+ if(cartridge == null) {
+ String msg = "Invalid Cartridge Type: "+cartridgeType;
+ log.error(msg);
+ throw new InvalidCartridgeTypeException(msg);
+ }
+
+ if(deploymentPolicy == null) {
+ String msg = "Deployment Policy is null.";
+ log.error(msg);
+ throw new InvalidPartitionException(msg);
+ }
+
+ for (PartitionGroup partitionGroup : deploymentPolicy.getPartitionGroups()) {
+ for (Partition partition : partitionGroup.getPartitions()) {
+ String provider = partition.getProvider();
+ IaasProvider iaasProvider = cartridge.getIaasProvider(provider);
+
+ if(iaasProvider == null) {
+ String msg = "Invalid Partition - "+partition.toString() +", in "+deploymentPolicy.toString()+
+ ". Cause: Iaas Provider is null for: "+provider;
+ log.error(msg);
+ throw new InvalidPartitionException(msg);
+ }
+
+ Iaas iaas = iaasProvider.getIaas();
+ PartitionValidator validator = iaas.getPartitionValidator();
+ validator.setIaasProvider(iaasProvider);
+ IaasProvider updatedIaasProvider = validator.validate(partition.getId(),
+ CloudControllerUtil.toJavaUtilProperties(partition.getProperties()));
+ // add to a temporary Map
+ partitionToIaasProviders.put(partition.getId(), updatedIaasProvider);
+
+ }
+ }
+
+ // if and only if the deployment policy valid
+ cartridge.addIaasProviders(partitionToIaasProviders);
+
+ return true;
+ }
- // delete that file, so that it gets automatically undeployed.
- return serviceDefFile.delete();
- }
+ @Override
+ public boolean validatePartition(Partition partition) throws InvalidPartitionException {
+ String provider = partition.getProvider();
+ IaasProvider iaasProvider = dataHolder.getIaasProvider(provider);
+
+ if (iaasProvider == null) {
+ String msg =
+ "Invalid Partition - " + partition.toString()+". Cause: Iaas Provider is null for: "+provider;
+ log.error(msg);
+ throw new InvalidPartitionException(msg);
+ }
+
+ Iaas iaas = iaasProvider.getIaas();
+ PartitionValidator validator = iaas.getPartitionValidator();
+ validator.setIaasProvider(iaasProvider);
+ validator.validate(partition.getId(),
+ CloudControllerUtil.toJavaUtilProperties(partition.getProperties()));
+ TopologyBuilder.handlePartitionCreated(partition);
+
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/61f8d8c8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/61f8d8c8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/61f8d8c8/components/org.apache.stratos.messaging/pom.xml
----------------------------------------------------------------------