You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/01/24 07:40:53 UTC

[1/5] stratos git commit: Merge pull request #1 from apache/master

Repository: stratos
Updated Branches:
  refs/heads/master eac4d2974 -> 42fef0919


Merge pull request #1 from apache/master

Synchronizing latest changes

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

Branch: refs/heads/master
Commit: e1c3e6b5c6a8a86424d871269317deb0745b0e17
Parents: 0944065 eac4d29
Author: Imesh Guaratne <im...@gmail.com>
Authored: Sat Jan 24 12:06:47 2015 +0530
Committer: Imesh Guaratne <im...@gmail.com>
Committed: Sat Jan 24 12:06:47 2015 +0530

----------------------------------------------------------------------

----------------------------------------------------------------------



[4/5] stratos git commit: Delete AutoscalerConstants.java

Posted by im...@apache.org.
Delete AutoscalerConstants.java

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

Branch: refs/heads/master
Commit: 626167f4bcfa2292bb04847aee7c787ea7a38b3e
Parents: 6074be7
Author: Imesh Guaratne <im...@gmail.com>
Authored: Sat Jan 24 12:08:09 2015 +0530
Committer: Imesh Guaratne <im...@gmail.com>
Committed: Sat Jan 24 12:08:09 2015 +0530

----------------------------------------------------------------------
 .../autoscaler/util/AutoscalerConstants.java    | 73 --------------------
 1 file changed, 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/626167f4/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerConstants.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerConstants.java
deleted file mode 100644
index 9472b9f..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerConstants.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one 
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
- * KIND, either express or implied.  See the License for the 
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.autoscaler.util;
-
-import org.wso2.carbon.utils.CarbonUtils;
-
-import java.io.File;
-
-public final class AutoscalerConstants {
-
-    /**
-     * Constant values for Autoscaler
-     */
-    public static final String ID_ELEMENT = "id";
-    public static final String PARTITION_ELEMENT = "partition";
-    public static final String PARTITIONS_ELEMENT = "partitions";
-    public static final String PROPERTY_ELEMENT = "property";
-    public static final String PROPERTY_NAME_ATTR= "name";
-    public static final String PROPERTY_VALUE_ATTR = "value";
-    public static final String AUTOSCALER_THREAD_POOL_ID = "autoscaler.thread.pool";
-    public static final String THREAD_POOL_SIZE_KEY = "autoscaler.thread.pool.size";
-    public static final int AUTOSCALER_THREAD_POOL_SIZE = 10;
-    public static final String COMPONENTS_CONFIG = CarbonUtils.getCarbonConfigDirPath() +
-            File.separator + "stratos-config.xml";
-    
-    /**
-	 * Persistence
-	 */
-	public static final String AUTOSCALER_RESOURCE = "/autoscaler";
-	public static final String PARTITION_RESOURCE = "/partitions";
-	public static final String NETWORK_PARTITIONS_RESOURCE = "/networkPartitions";
-	public static final String AS_POLICY_RESOURCE = "/policies/autoscalingPolicies";
-	public static final String DEPLOYMENT_POLICY_RESOURCE = "/policies/deploymentPolicies";
-    public static final String APPLICATIONS_RESOURCE = "/applications";
-    public static final String APPLICATION_CONTEXTS_RESOURCE = "/applicationContexts";
-
-    /**
-     * Cluster monitoring  interval
-     */
-    public static final String AUTOSCALER_MONITOR_INTERVAL = "autoscaler.monitorInterval";
-
-    public static final String SERVICE_GROUP = "/groups";
-    public static final String VMService_Cluster_MONITOR_INTERVAL = "autoscaler.monitorInterval.vm.service";
-    public static final String VMLb_Cluster_MONITOR_INTERVAL = "autoscaler.monitorInterval.vm.lb";
-    public static final String KubernetesService_Cluster_MONITOR_INTERVAL = "autoscaler.monitorInterval.kubernetes.service";
-
-    /**
-     * PortRange min max
-     */
-    public static final int PORT_RANGE_MAX = 65535;
-    public static final int PORT_RANGE_MIN = 1;
-    
-    /**
-     * Payload values
-     */
-    public static final String PAYLOAD_DEPLOYMENT = "default";
-}


[2/5] stratos git commit: Delete AutoscalerService.java

Posted by im...@apache.org.
Delete AutoscalerService.java

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

Branch: refs/heads/master
Commit: 178bafa86db4f29c277724f2e7d576dd31e12e9a
Parents: e1c3e6b
Author: Imesh Guaratne <im...@gmail.com>
Authored: Sat Jan 24 12:07:34 2015 +0530
Committer: Imesh Guaratne <im...@gmail.com>
Committed: Sat Jan 24 12:07:34 2015 +0530

----------------------------------------------------------------------
 .../autoscaler/services/AutoscalerService.java  | 172 -------------------
 1 file changed, 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/178bafa8/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java
deleted file mode 100644
index 952747c..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-package org.apache.stratos.autoscaler.services;
-
-import org.apache.stratos.autoscaler.applications.pojo.ApplicationContext;
-import org.apache.stratos.autoscaler.exception.kubernetes.InvalidServiceGroupException;
-import org.apache.stratos.autoscaler.pojo.policy.deployment.DeploymentPolicy;
-import org.apache.stratos.autoscaler.exception.*;
-import org.apache.stratos.autoscaler.exception.application.ApplicationDefinitionException;
-import org.apache.stratos.autoscaler.exception.policy.InvalidPolicyException;
-import org.apache.stratos.autoscaler.pojo.ServiceGroup;
-import org.apache.stratos.autoscaler.pojo.policy.autoscale.AutoscalePolicy;
-import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.ChildLevelNetworkPartition;
-import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.NetworkPartition;
-import org.apache.stratos.common.Properties;
-
-public interface AutoscalerService {
-    /**
-     * Add autoscaling policy
-     * @param autoscalePolicy
-     * @return
-     * @throws InvalidPolicyException
-     */
-    public boolean addAutoScalingPolicy(AutoscalePolicy autoscalePolicy) throws InvalidPolicyException;
-
-    /**
-     * Get an autoscaling policy
-     * @param autoscalingPolicyId
-     * @return
-     */
-    public AutoscalePolicy getAutoscalingPolicy(String autoscalingPolicyId);
-
-    /**
-     * Get autoscaling policies
-     * @return
-     */
-    public AutoscalePolicy[] getAutoScalingPolicies();
-
-    /**
-     * Update an autoscaling policy
-     * @param autoscalePolicy
-     * @return
-     * @throws InvalidPolicyException
-     */
-    public boolean updateAutoScalingPolicy(AutoscalePolicy autoscalePolicy) throws InvalidPolicyException;
-
-	/**
-	 * Remove autoscaling policy
-	 * @param autoscalingPolicyId
-	 * @return
-	 * @throws InvalidPolicyException
-	 */
-	public boolean removeAutoScalingPolicy(String autoscalingPolicyId) throws InvalidPolicyException;
-
-    /**
-     * Add an application
-     *
-     * @param applicationContext {@link org.apache.stratos.autoscaler.applications.pojo.ApplicationContext}
-     * @throws ApplicationDefinitionException if an error occurs
-     */
-    public void addApplication(ApplicationContext applicationContext) throws ApplicationDefinitionException;
-
-    /**
-     * Get an application
-     * @param applicationId
-     */
-    public ApplicationContext getApplication(String applicationId);
-
-    /**
-     * Get all applications
-     */
-    public ApplicationContext[] getApplications();
-
-    /**
-     * Deploy an application in created state
-     * @param applicationId
-     * @param deploymentPolicy
-     * @return
-     */
-    public boolean deployApplication(String applicationId, DeploymentPolicy deploymentPolicy) throws ApplicationDefinitionException;
-
-    /**
-     * Undeploy an application in deployed state
-     * @param applicationId
-     * @return
-     */
-    public void undeployApplication(String applicationId);
-
-    /**
-     * Delete an application
-     * @param applicationId
-     */
-    public void deleteApplication(String applicationId);
-
-    /**
-     * Returns a deployment policy of an application
-     * @param applicationId
-     * @return
-     */
-    public DeploymentPolicy getDeploymentPolicy(String applicationId);
-
-    /**
-     * Dynamically update the properties of an Autoscaling Cluster Monitor
-     * @param clusterId id of the cluster.
-     * @param properties updated properties.
-     */
-    void updateClusterMonitor(String clusterId, Properties properties) throws InvalidArgumentException;
-
-    /**
-     * Add a cartridge group
-     * @param servicegroup
-     * @throws InvalidServiceGroupException
-     */
-    public void addServiceGroup(ServiceGroup servicegroup) throws InvalidServiceGroupException;
-
-    /**
-     * Remove a cartridge group
-     * @param groupName
-     */
-    public void removeServiceGroup(String groupName);
-
-    /**
-     * Get cartridge group
-     * @param name
-     * @return
-     */
-    public ServiceGroup getServiceGroup(String name);
-
-    /**
-     * Add network partition
-     * @param networkPartition
-     */
-    public void addNetworkPartition(NetworkPartition networkPartition);
-
-    /**
-     * Remove network partition
-     * @param networkPartitionId
-     */
-    public void removeNetworkPartition(String networkPartitionId);
-
-    /**
-     * Get network partitions
-     * @return
-     */
-    public NetworkPartition[] getNetworkPartitions();
-
-    /**
-     * Get network partition by network partition id
-     * @param networkPartitionId
-     * @return
-     */
-    public NetworkPartition getNetworkPartition(String networkPartitionId);
-}


[3/5] stratos git commit: Delete AutoscalerServiceImpl.java

Posted by im...@apache.org.
Delete AutoscalerServiceImpl.java

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

Branch: refs/heads/master
Commit: 6074be773cce0e7cd36ea9a52bc8498dc3460396
Parents: 178bafa
Author: Imesh Guaratne <im...@gmail.com>
Authored: Sat Jan 24 12:07:49 2015 +0530
Committer: Imesh Guaratne <im...@gmail.com>
Committed: Sat Jan 24 12:07:49 2015 +0530

----------------------------------------------------------------------
 .../services/impl/AutoscalerServiceImpl.java    | 712 -------------------
 1 file changed, 712 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/6074be77/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
deleted file mode 100644
index 3f595ca..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
+++ /dev/null
@@ -1,712 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one 
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
- * KIND, either express or implied.  See the License for the 
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.autoscaler.services.impl;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.applications.ApplicationHolder;
-import org.apache.stratos.autoscaler.applications.parser.ApplicationParser;
-import org.apache.stratos.autoscaler.applications.parser.DefaultApplicationParser;
-import org.apache.stratos.autoscaler.applications.pojo.*;
-import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
-import org.apache.stratos.autoscaler.client.CloudControllerClient;
-import org.apache.stratos.autoscaler.context.AutoscalerContext;
-import org.apache.stratos.autoscaler.exception.AutoScalerException;
-import org.apache.stratos.autoscaler.exception.InvalidArgumentException;
-import org.apache.stratos.autoscaler.exception.application.ApplicationDefinitionException;
-import org.apache.stratos.autoscaler.exception.application.TopologyInConsistentException;
-import org.apache.stratos.autoscaler.exception.kubernetes.InvalidServiceGroupException;
-import org.apache.stratos.autoscaler.exception.partition.PartitionValidationException;
-import org.apache.stratos.autoscaler.exception.policy.InvalidPolicyException;
-import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
-import org.apache.stratos.autoscaler.pojo.Dependencies;
-import org.apache.stratos.autoscaler.pojo.ServiceGroup;
-import org.apache.stratos.autoscaler.pojo.policy.PolicyManager;
-import org.apache.stratos.autoscaler.pojo.policy.autoscale.AutoscalePolicy;
-import org.apache.stratos.autoscaler.pojo.policy.deployment.ChildPolicy;
-import org.apache.stratos.autoscaler.pojo.policy.deployment.DeploymentPolicy;
-import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.ChildLevelNetworkPartition;
-import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.NetworkPartition;
-import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.network.Partition;
-import org.apache.stratos.autoscaler.registry.RegistryManager;
-import org.apache.stratos.autoscaler.services.AutoscalerService;
-import org.apache.stratos.autoscaler.util.AutoscalerObjectConverter;
-import org.apache.stratos.autoscaler.util.AutoscalerUtil;
-import org.apache.stratos.common.Properties;
-import org.apache.stratos.common.Property;
-import org.apache.stratos.common.client.CloudControllerServiceClient;
-import org.apache.stratos.common.client.StratosManagerServiceClient;
-import org.apache.stratos.common.util.CommonUtil;
-import org.apache.stratos.manager.service.stub.domain.application.signup.ApplicationSignUp;
-import org.apache.stratos.manager.service.stub.domain.application.signup.ArtifactRepository;
-import org.apache.stratos.messaging.domain.application.Application;
-import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
-import org.apache.stratos.messaging.domain.application.Group;
-import org.apache.stratos.metadata.client.defaults.DefaultMetaDataServiceClient;
-import org.apache.stratos.metadata.client.defaults.MetaDataServiceClient;
-import org.apache.stratos.metadata.client.exception.MetaDataServiceClientException;
-import org.wso2.carbon.registry.api.RegistryException;
-
-import java.text.MessageFormat;
-import java.util.*;
-
-/**
- * Auto Scaler Service API is responsible getting Partitions and Policies.
- */
-public class AutoscalerServiceImpl implements AutoscalerService {
-
-    private static final Log log = LogFactory.getLog(AutoscalerServiceImpl.class);
-
-    public AutoscalePolicy[] getAutoScalingPolicies() {
-        return PolicyManager.getInstance().getAutoscalePolicyList();
-    }
-
-    private boolean validateDeploymentPolicy(DeploymentPolicy deploymentPolicy) {
-        try {
-            ApplicationHolder.acquireReadLock();
-
-            for (ChildPolicy childPolicy : deploymentPolicy.getChildPolicies()) {
-                String alias = childPolicy.getAlias();
-                List<Partition> partitionList = new ArrayList<Partition>();
-                for (ChildLevelNetworkPartition networkPartition : childPolicy.getChildLevelNetworkPartitions()) {
-                    Partition[] partitions = deploymentPolicy.getApplicationLevelNetworkPartition(
-                            networkPartition.getId()).getPartitions();
-                    for (Partition partition : partitions) {
-                        partitionList.add(partition);
-                    }
-                }
-
-                Application application = ApplicationHolder.getApplications().getApplication(
-                        deploymentPolicy.getApplicationId());
-                Partition[] partitions = new Partition[partitionList.size()];
-                if (application != null) {
-                    Group group = application.getGroupRecursively(alias);
-                    if (group != null) {
-                        Set<ClusterDataHolder> clusterDataHolders = group.getClusterDataHoldersOfGroup();
-                        //validating the group deployment policy against the leaf cartridges
-                        for (ClusterDataHolder clusterDataHolder : clusterDataHolders) {
-                            CloudControllerClient.getInstance().validateDeploymentPolicy(
-                                    clusterDataHolder.getServiceType(), partitionList.toArray(partitions));
-                        }
-                    } else {
-                        //Validating the cartridge level deployment policy
-                        ClusterDataHolder clusterDataHolder = application.
-                                getClusterDataHolderRecursivelyByAlias(alias);
-                        if (clusterDataHolder != null) {
-                            CloudControllerClient.getInstance().validateDeploymentPolicy(
-                                    clusterDataHolder.getServiceType(), partitionList.toArray(partitions));
-                        } else {
-                            String msg = "Error while retrieving the group/cluster for the deployment " +
-                                    "policy: " + alias;
-                            log.error(msg);
-                            throw new TopologyInConsistentException(msg);
-                        }
-                    }
-                } else {
-                    String msg = "Error while retrieving the application for the deployment policy: " +
-                            deploymentPolicy.getApplicationId();
-                    log.error(msg);
-                    throw new TopologyInConsistentException(msg);
-                }
-            }
-        } catch (PartitionValidationException e) {
-            log.error("Error while validating the deployment policy", e);
-            //TODO throw exception
-        } catch (TopologyInConsistentException e) {
-            log.error("Error while validating the deployment policy", e);
-            //TODO throw exception
-        } finally {
-            ApplicationHolder.releaseReadLock();
-        }
-        return true;
-    }
-
-    @Override
-    public boolean addAutoScalingPolicy(AutoscalePolicy autoscalePolicy) throws InvalidPolicyException {
-        return PolicyManager.getInstance().addAutoscalePolicy(autoscalePolicy);
-    }
-
-    @Override
-    public boolean updateAutoScalingPolicy(AutoscalePolicy autoscalePolicy) throws InvalidPolicyException {
-        return PolicyManager.getInstance().updateAutoscalePolicy(autoscalePolicy);
-    }
-
-	@Override
-	public boolean removeAutoScalingPolicy(String autoscalePolicyId) throws InvalidPolicyException {
-		if(validateAutoScalerPolicy(autoscalePolicyId)) {
-			return PolicyManager.getInstance().removeAutoscalePolicy(autoscalePolicyId);
-		}
-		else{
-			throw new InvalidPolicyException("This auto-scalar policy cannot remove, since it is used in applications.");
-		}
-	}
-
-	/**
-	 * Validate the Auto Scalar policy removal
-	 * @param autoscalePolicyId Auto Scalar policy id boolean
-	 * @return
-	 */
-	private boolean validateAutoScalerPolicy(String autoscalePolicyId) {
-		boolean canRemove=true;
-		Collection<ApplicationContext> appContexts= AutoscalerContext.getInstance().getApplicationContexts();
-		for(ApplicationContext app:appContexts){
-			CartridgeContext[] cartrideContexts=app.getComponents().getCartridgeContexts();
-			for(CartridgeContext cartridgeContext: cartrideContexts) {
-				SubscribableInfoContext subscribableInfoContexts = cartridgeContext.getSubscribableInfoContext();
-				if (subscribableInfoContexts.getAutoscalingPolicy().equals(autoscalePolicyId)) {
-						canRemove=false;
-				}
-			}
-		}
-		return canRemove;
-	}
-
-	@Override
-    public DeploymentPolicy getDeploymentPolicy(String deploymentPolicyId) {
-        return PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId);
-    }
-
-    @Override
-    public AutoscalePolicy getAutoscalingPolicy(String autoscalingPolicyId) {
-        return PolicyManager.getInstance().getAutoscalePolicy(autoscalingPolicyId);
-    }
-
-    @Override
-    public void addApplication(ApplicationContext applicationContext)
-            throws ApplicationDefinitionException {
-
-        if(log.isInfoEnabled()) {
-            log.info(String.format("Adding application: [application-id] %s",
-                    applicationContext.getApplicationId()));
-        }
-
-        ApplicationParser applicationParser = new DefaultApplicationParser();
-        applicationParser.parse(applicationContext);
-        applicationContext.setStatus(ApplicationContext.STATUS_CREATED);
-        AutoscalerContext.getInstance().addApplicationContext(applicationContext);
-        if(log.isInfoEnabled()) {
-            log.info(String.format("Application added successfully: [application-id] %s",
-                    applicationContext.getApplicationId()));
-        }
-    }
-
-    @Override
-    public ApplicationContext getApplication(String applicationId) {
-        return AutoscalerContext.getInstance().getApplicationContext(applicationId);
-    }
-
-    @Override
-    public ApplicationContext[] getApplications() {
-        return AutoscalerContext.getInstance().getApplicationContexts().
-                toArray(new ApplicationContext[AutoscalerContext.getInstance().getApplicationContexts().size()]);
-    }
-
-    @Override
-    public boolean deployApplication(String applicationId, DeploymentPolicy deploymentPolicy) throws ApplicationDefinitionException {
-        try {
-            ApplicationContext applicationContext = RegistryManager.getInstance().getApplicationContext(applicationId);
-            if (applicationContext == null) {
-                throw new RuntimeException("Application not found: " + applicationId);
-            }
-
-            ApplicationParser applicationParser = new DefaultApplicationParser();
-            Application application = applicationParser.parse(applicationContext);
-
-
-            // Create application clusters in cloud controller and send application created event
-            ApplicationBuilder.handleApplicationCreatedEvent(application, applicationParser.getApplicationClusterContexts());
-
-            try {
-                // Update kubernetes cluster ids
-                updateKubernetesClusterIds(deploymentPolicy);
-                // Validate deployment policy via cloud controller
-                validateDeploymentPolicy(deploymentPolicy);
-                // Add deployment policy
-                PolicyManager.getInstance().addDeploymentPolicy(deploymentPolicy);
-                // Add application signup in stratos manager
-                addApplicationSignUp(applicationContext, application.getKey());
-
-                applicationContext.setStatus(ApplicationContext.STATUS_DEPLOYED);
-                AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
-            } catch (InvalidPolicyException e) {
-                String message = "Deployment policy is not valid: [application-id] " + deploymentPolicy.getApplicationId();
-                log.error(message, e);
-                throw new RuntimeException(message, e);
-            }
-
-            // Check whether all the clusters are there
-            boolean allClusterInitialized = false;
-            try {
-                ApplicationHolder.acquireReadLock();
-                application = ApplicationHolder.getApplications().getApplication(deploymentPolicy.getApplicationId());
-                if (application != null) {
-                    allClusterInitialized = AutoscalerUtil.allClustersInitialized(application);
-                }
-            } finally {
-                ApplicationHolder.releaseReadLock();
-            }
-
-            if (!AutoscalerContext.getInstance().containsPendingMonitor(applicationId)
-                    || !AutoscalerContext.getInstance().monitorExists(applicationId)) {
-                if (allClusterInitialized) {
-                    AutoscalerUtil.getInstance().startApplicationMonitor(applicationId);
-                } else {
-                    log.info("The application clusters are not yet created. " +
-                            "Waiting for them to be created");
-                }
-            } else {
-                log.info("The application monitor has already been created: [application-id] " + applicationId);
-            }
-            return true;
-        } catch (Exception e) {
-            ApplicationContext applicationContext = RegistryManager.getInstance().getApplicationContext(applicationId);
-            if(applicationContext != null) {
-                // Revert application status
-                applicationContext.setStatus(ApplicationContext.STATUS_CREATED);
-                AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
-            }
-            String message = "Application deployment failed";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
-    }
-
-    private void addApplicationSignUp(ApplicationContext applicationContext, String applicationKey) {
-        try {
-            if(log.isInfoEnabled()) {
-                log.info(String.format("Adding application signup: [application-id] %s",
-                        applicationContext.getApplicationId()));
-            }
-
-            ComponentContext components = applicationContext.getComponents();
-            if (components != null) {
-                ApplicationSignUp applicationSignUp = new ApplicationSignUp();
-                applicationSignUp.setApplicationId(applicationContext.getApplicationId());
-                applicationSignUp.setTenantId(applicationContext.getTenantId());
-
-                List<ArtifactRepository> artifactRepositoryList = new ArrayList<ArtifactRepository>();
-                CartridgeContext[] cartridgeContexts = components.getCartridgeContexts();
-                if (cartridgeContexts != null) {
-                    updateArtifactRepositoryList(artifactRepositoryList, cartridgeContexts);
-                }
-
-                GroupContext[] groupContexts = components.getGroupContexts();
-                if (groupContexts != null) {
-                    for (GroupContext groupContext : groupContexts) {
-                        if (groupContext != null) {
-                            updateArtifactRepositoryList(artifactRepositoryList, groupContext.getCartridgeContexts());
-                        }
-                    }
-                }
-
-                ArtifactRepository[] artifactRepositoryArray = artifactRepositoryList.toArray(
-                        new ArtifactRepository[artifactRepositoryList.size()]);
-                applicationSignUp.setArtifactRepositories(artifactRepositoryArray);
-
-                // Encrypt artifact repository passwords
-                encryptRepositoryPasswords(applicationSignUp, applicationKey);
-
-                StratosManagerServiceClient serviceClient = StratosManagerServiceClient.getInstance();
-                serviceClient.addApplicationSignUp(applicationSignUp);
-
-                if(log.isInfoEnabled()) {
-                    log.info(String.format("Application signup added successfully: [application-id] %s",
-                            applicationContext.getApplicationId()));
-                }
-            }
-        } catch (Exception e) {
-            String message = "Could not add application signup";
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
-    }
-
-    /**
-     * Encrypt artifact repository passwords.
-     * @param applicationSignUp
-     * @param applicationKey
-     */
-    private void encryptRepositoryPasswords(ApplicationSignUp applicationSignUp, String applicationKey) {
-        if (applicationSignUp.getArtifactRepositories() != null) {
-            for (ArtifactRepository artifactRepository : applicationSignUp.getArtifactRepositories()) {
-                String repoPassword = artifactRepository.getRepoPassword();
-                if ((artifactRepository != null) && (StringUtils.isNotBlank(repoPassword))) {
-                    String encryptedRepoPassword = CommonUtil.encryptPassword(repoPassword,
-                            applicationKey);
-                    artifactRepository.setRepoPassword(encryptedRepoPassword);
-
-                    if (log.isDebugEnabled()) {
-                        log.debug(String.format("Artifact repository password encrypted: [application-id] %s " +
-                                        "[tenant-id] %d [repo-url] %s", applicationSignUp.getApplicationId(),
-                                applicationSignUp.getTenantId(), artifactRepository.getRepoUrl()));
-                    }
-                }
-            }
-        }
-    }
-
-    private void updateArtifactRepositoryList(List<ArtifactRepository> artifactRepositoryList, CartridgeContext[] cartridgeContexts) {
-        for(CartridgeContext cartridgeContext : cartridgeContexts) {
-            SubscribableInfoContext subscribableInfoContext = cartridgeContext.getSubscribableInfoContext();
-            ArtifactRepositoryContext artifactRepositoryContext = subscribableInfoContext.getArtifactRepositoryContext();
-            if(artifactRepositoryContext != null) {
-
-                ArtifactRepository artifactRepository = new ArtifactRepository();
-                artifactRepository.setCartridgeType(cartridgeContext.getType());
-                artifactRepository.setAlias(subscribableInfoContext.getAlias());
-                artifactRepository.setRepoUrl(artifactRepositoryContext.getRepoUrl());
-                artifactRepository.setPrivateRepo(artifactRepositoryContext.isPrivateRepo());
-                artifactRepository.setRepoUsername(artifactRepositoryContext.getRepoUsername());
-                artifactRepository.setRepoPassword(artifactRepositoryContext.getRepoPassword());
-
-                artifactRepositoryList.add(artifactRepository);
-            }
-        }
-    }
-
-    /**
-     * Overwrite partition's kubernetes cluster ids with network partition's kubernetes cluster ids.
-     * @param deploymentPolicy
-     */
-    private void updateKubernetesClusterIds(DeploymentPolicy deploymentPolicy) {
-        NetworkPartition[] networkPartitions =
-                deploymentPolicy.getApplicationLevelNetworkPartitions();
-        if(networkPartitions != null) {
-            for(NetworkPartition networkPartition : networkPartitions) {
-                if(StringUtils.isNotBlank(networkPartition.getKubernetesClusterId())) {
-                    Partition[] partitions = networkPartition.getPartitions();
-                    if(partitions != null) {
-                        for(Partition partition : partitions) {
-                            if(partition != null) {
-                                if(log.isInfoEnabled()) {
-                                    log.info(String.format("Overwriting partition's kubernetes cluster id: " +
-                                                    "[application-id] %s [network-partition-id] %s [partition-id] %s " +
-                                                    "[kubernetes-cluster-id] %s",
-                                            deploymentPolicy.getApplicationId(), networkPartition.getId(),
-                                            partition.getId(), networkPartition.getKubernetesClusterId()));
-                                }
-                                partition.setKubernetesClusterId(networkPartition.getKubernetesClusterId());
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    public void undeployApplication(String applicationId) {
-        try {
-            if (log.isInfoEnabled()) {
-                log.info("Starting to undeploy application: [application-id] " + applicationId);
-            }
-
-            ApplicationContext application = AutoscalerContext.getInstance().getApplicationContext(applicationId);
-            if ( application == null){
-                String msg = String.format("Application not found : [application-id] %s", applicationId);
-                throw new RuntimeException(msg);
-            }
-
-            if (!application.getStatus().equals(ApplicationContext.STATUS_DEPLOYED)) {
-                String message = String.format("Application is not deployed: [application-id] %s", applicationId);
-                log.error(message);
-                throw new RuntimeException(message);
-            }
-
-            ApplicationBuilder.handleApplicationUndeployed(applicationId);
-
-            ApplicationContext applicationContext = AutoscalerContext.getInstance().getApplicationContext(applicationId);
-            applicationContext.setStatus(ApplicationContext.STATUS_CREATED);
-            AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
-
-            DeploymentPolicy deploymentPolicy = PolicyManager.getInstance().getDeploymentPolicy(applicationId);
-            PolicyManager.getInstance().removeDeploymentPolicy(deploymentPolicy);
-
-            if (log.isInfoEnabled()) {
-                log.info("Application undeployed successfully: [application-id] " + applicationId);
-            }
-        } catch (Exception e) {
-            String message = "Could not undeploy application: [application-id] " + applicationId;
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
-    }
-
-    @Override
-    public void deleteApplication(String applicationId) {
-        //TODO oAuth application/service provider deletion is removed since app name is random. It should be equal to
-        // name of the composite application.
-        /*
-        try {
-            oAuthAdminServiceClient.getServiceClient().removeOauthApplication(applicationId);
-            IdentityApplicationManagementServiceClient.getServiceClient().removeApplication(applicationId);
-        } catch (RemoteException e) {
-           log.error(String.format("Error ocured while deleting oAuth application %s", applicationId), e);
-            throw new AutoScalerException(e);
-        } catch (OAuthAdminServiceException e) {
-            log.error(String.format("Error ocured while deleting oAuth application %s", applicationId), e);
-            throw new AutoScalerException(e);
-        } catch (IdentityApplicationManagementServiceIdentityApplicationManagementException e) {
-        }
-        */
-
-        if (AutoscalerContext.getInstance().removeApplicationContext(applicationId) == null) {
-            String msg = String.format("Application not found : [application-id] %s", applicationId);
-            throw new RuntimeException(msg);
-        }
-        log.info(String.format("Application deleted successfully: [application-id] ", applicationId));
-    }
-
-    public void updateClusterMonitor(String clusterId, Properties properties) throws InvalidArgumentException {
-        if (log.isDebugEnabled()) {
-            log.debug(String.format("Updating Cluster monitor [Cluster id] %s ", clusterId));
-        }
-        AutoscalerContext asCtx = AutoscalerContext.getInstance();
-        ClusterMonitor monitor = asCtx.getClusterMonitor(clusterId);
-
-        if (monitor != null) {
-            monitor.handleDynamicUpdates(properties);
-        } else {
-            log.debug(String.format("Updating Cluster monitor failed: Cluster monitor [Cluster id] %s not found.",
-                    clusterId));
-        }
-    }
-
-    public void addServiceGroup(ServiceGroup servicegroup) throws InvalidServiceGroupException {
-
-        if (servicegroup == null || StringUtils.isEmpty(servicegroup.getName())) {
-            String msg = "Cartridge group can not be null service name can not be empty.";
-            log.error(msg);
-            throw new IllegalArgumentException(msg);
-
-        }
-
-        if(log.isInfoEnabled()) {
-            log.info(String.format("Adding cartridge group: [group-name] %s", servicegroup.getName()));
-        }
-        String groupName = servicegroup.getName();
-        if (RegistryManager.getInstance().serviceGroupExist(groupName)) {
-            throw new InvalidServiceGroupException("Cartridge group with the name " + groupName + " already exist.");
-        }
-
-        if (log.isDebugEnabled()) {
-            log.debug(MessageFormat.format("Adding cartridge group {0}", servicegroup.getName()));
-        }
-
-        String[] subGroups = servicegroup.getCartridges();
-        if (log.isDebugEnabled()) {
-            log.debug("SubGroups" + subGroups);
-            if (subGroups != null) {
-                log.debug("subGroups:size" + subGroups.length);
-            } else {
-                log.debug("subGroups: are null");
-            }
-        }
-
-        Dependencies dependencies = servicegroup.getDependencies();
-        if (log.isDebugEnabled()) {
-            log.debug("Dependencies" + dependencies);
-        }
-
-        if (dependencies != null) {
-            String[] startupOrders = dependencies.getStartupOrders();
-
-            if (log.isDebugEnabled()) {
-                log.debug("StartupOrders " + startupOrders);
-
-                if (startupOrders != null) {
-                    log.debug("StartupOrder:size  " + startupOrders.length);
-                } else {
-                    log.debug("StartupOrder: is null");
-                }
-            }
-            String[] scalingDependents = dependencies.getScalingDependants();
-
-            if (log.isDebugEnabled()) {
-                log.debug("ScalingDependent " + scalingDependents);
-
-                if (scalingDependents != null) {
-                    log.debug("ScalingDependents:size " + scalingDependents.length);
-                } else {
-                    log.debug("ScalingDependent: is null");
-                }
-            }
-        }
-
-        RegistryManager.getInstance().persistServiceGroup(servicegroup);
-        if(log.isInfoEnabled()) {
-            log.info(String.format("Cartridge group successfully added: [group-name] %s", servicegroup.getName()));
-        }
-    }
-
-    @Override
-    public void removeServiceGroup(String groupName) {
-        try {
-            if(log.isInfoEnabled()) {
-                log.info(String.format("Starting to remove cartridge group: [group-name] %s", groupName));
-            }
-            if(RegistryManager.getInstance().serviceGroupExist(groupName)) {
-                RegistryManager.getInstance().removeServiceGroup(groupName);
-                if(log.isInfoEnabled()) {
-                    log.info(String.format("Cartridge group removed: [group-name] %s", groupName));
-                }
-            } else {
-                if(log.isWarnEnabled()) {
-                    log.warn(String.format("Cartridge group not found: [group-name] %s", groupName));
-                }
-            }
-        } catch (org.wso2.carbon.registry.core.exceptions.RegistryException e) {
-            String message = "Could not remove cartridge group: " + groupName;
-            log.error(message, e);
-            throw new RuntimeException(message, e);
-        }
-    }
-
-    public ServiceGroup getServiceGroup(String name) {
-        if (StringUtils.isEmpty(name)) {
-            return null;
-        }
-        try {
-            return RegistryManager.getInstance().getServiceGroup(name);
-        } catch (Exception e) {
-            throw new AutoScalerException("Error occurred while retrieving cartridge group", e);
-        }
-    }
-
-    @Override
-    public void addNetworkPartition(NetworkPartition networkPartition) {
-        try {
-            if(log.isInfoEnabled()) {
-                log.info(String.format("Adding network partition: [network-partition-id] %s", networkPartition.getId()));
-            }
-
-            CloudControllerServiceClient cloudControllerServiceClient = CloudControllerServiceClient.getInstance();
-            if(networkPartition.getPartitions() != null) {
-                for(Partition partition : networkPartition.getPartitions()) {
-                    if(partition != null) {
-                        if(log.isInfoEnabled()) {
-                            log.info(String.format("Validating partition: [network-partition-id] %s [partition-id] %s",
-                                    networkPartition.getId(), partition.getId()));
-                        }
-
-                        cloudControllerServiceClient.validatePartition(
-                                AutoscalerObjectConverter.convertASPartitionToCCPartition(partition));
-
-                        if(log.isInfoEnabled()) {
-                            log.info(String.format("Partition validated successfully: [network-partition-id] %s " +
-                                            "[partition-id] %s", networkPartition.getId(), partition.getId()));
-                        }
-                    }
-                }
-            }
-            RegistryManager.getInstance().persistNetworkPartition(networkPartition);
-
-            if(log.isInfoEnabled()) {
-                log.info(String.format("Network partition added successfully: [network-partition-id] %s",
-                        networkPartition.getId()));
-            }
-        } catch (Exception e) {
-            String message = "Could not add network partition";
-            log.error(message);
-            throw new AutoScalerException(message, e);
-        }
-    }
-
-    @Override
-    public void removeNetworkPartition(String networkPartitionId) {
-        try {
-            if(log.isInfoEnabled()) {
-                log.info(String.format("Removing network partition: [network-partition-id] %s", networkPartitionId));
-            }
-
-            // TODO: Add validation logic
-            RegistryManager.getInstance().removeNetworkPartition(networkPartitionId);
-
-            if(log.isInfoEnabled()) {
-                log.info(String.format("Network partition removed successfully: [network-partition-id] %s",
-                        networkPartitionId));
-            }
-        } catch (Exception e) {
-            String message = "Could not remove network partition";
-            log.error(message);
-            throw new AutoScalerException(message, e);
-        }
-    }
-
-    @Override
-    public NetworkPartition[] getNetworkPartitions() {
-        try {
-            List<NetworkPartition> networkPartitionList = RegistryManager.getInstance().getNetworkPartitions();
-            return networkPartitionList.toArray(new NetworkPartition[networkPartitionList.size()]);
-        } catch (Exception e) {
-            String message = "Could not get network partitions";
-            log.error(message);
-            throw new AutoScalerException(message, e);
-        }
-    }
-
-    @Override
-    public NetworkPartition getNetworkPartition(String networkPartitionId) {
-        try {
-            return RegistryManager.getInstance().getNetworkPartition(networkPartitionId);
-        } catch (Exception e) {
-            String message = String.format("Could not get network partition: [network-partition-id] %s",
-                    networkPartitionId);
-            log.error(message);
-            throw new AutoScalerException(message, e);
-        }
-    }
-
-    public ServiceGroup[] getServiceGroups() throws AutoScalerException {
-        return RegistryManager.getInstance().getServiceGroups();
-    }
-
-    public boolean serviceGroupExist(String serviceName) {
-        return false;
-    }
-
-    public void undeployServiceGroup(String name) throws AutoScalerException {
-        try {
-            RegistryManager.getInstance().removeServiceGroup(name);
-        } catch (RegistryException e) {
-            throw new AutoScalerException("Error occurred while removing the cartridge groups", e);
-        }
-
-    }
-
-    private void publishMetadata(ApplicationParser applicationParser, String appId) {
-        MetaDataServiceClient metaDataServiceClien = null;
-        try {
-            metaDataServiceClien = new DefaultMetaDataServiceClient();
-            for (Map.Entry<String, Properties> entry : applicationParser.getAliasToProperties().entrySet()) {
-                String alias = entry.getKey();
-                Properties properties = entry.getValue();
-                if (properties != null) {
-                    for (Property property : properties.getProperties()) {
-                        metaDataServiceClien.addPropertyToCluster(appId, alias, property.getName(),
-                                String.valueOf(property.getValue()));
-                    }
-                }
-            }
-        } catch (MetaDataServiceClientException e) {
-            log.error("Could not publish to metadata service ", e);
-        }
-    }
-}


[5/5] stratos git commit: This closes #184 on GitHub

Posted by im...@apache.org.
This closes #184 on GitHub


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

Branch: refs/heads/master
Commit: 42fef091994fb0581b9781e399c14fc6f8823323
Parents: 626167f
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sat Jan 24 12:10:39 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat Jan 24 12:10:39 2015 +0530

----------------------------------------------------------------------

----------------------------------------------------------------------