http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadData.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadData.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadData.java new file mode 100644 index 0000000..963e88b --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadData.java @@ -0,0 +1,69 @@ +/* + * 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.applications.payload; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public abstract class PayloadData implements Serializable { + + private BasicPayloadData basicPayloadData; + private Map<String, String> completePayloadMap; + public PayloadData(BasicPayloadData basicPayloadData) { + + this.setBasicPayloadData(basicPayloadData); + completePayloadMap = new HashMap<String, String>(); + } + + public void add (String payloadDataName, String payloadDataValue) { + completePayloadMap.put(payloadDataName, payloadDataValue); + } + + public StringBuilder getCompletePayloadData () { + + //return completePayloadMap; + StringBuilder completePayload = new StringBuilder(); + completePayload.append(basicPayloadData.getPayloadData()); + Iterator< String > iter = completePayloadMap.keySet().iterator(); + while(iter.hasNext()) { + String key = iter.next(); + String val = completePayloadMap.get(key); + if(completePayload.length() > 0){ + completePayload.append(","); + } + completePayload.append(key + "=" + val); + } + return completePayload; + } + + public BasicPayloadData getBasicPayloadData() { + return basicPayloadData; + } + + public void setBasicPayloadData(BasicPayloadData basicPayloadData) { + this.basicPayloadData = basicPayloadData; + } + + public String toString () { + return getCompletePayloadData().toString(); + } +}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadFactory.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadFactory.java new file mode 100755 index 0000000..53bac96 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadFactory.java @@ -0,0 +1,59 @@ +/** + * 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.applications.payload; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.autoscaler.exception.ApplicationDefinitionException; + + +public class PayloadFactory { + + private static Log log = LogFactory.getLog(PayloadFactory.class); + + /** + * Creates and returns a PayloadData instance + * + * @param cartridgeProvider Cartridge provider + * @param cartridgeType Cartridge type + * @param basicPayloadData BasicPayloadData instance + * @return Payload subscription + */ + public static PayloadData getPayloadDataInstance(String cartridgeProvider, String cartridgeType, + BasicPayloadData basicPayloadData) + throws ApplicationDefinitionException { + + PayloadData payloadData = null; + + //TODO: fix after adding the property Category to Cartridge Definition + if (cartridgeProvider.equals("data")) { + payloadData = new DataCartridgePayloadData(basicPayloadData); + } else { + payloadData = new FrameworkCartridgePayloadData(basicPayloadData); + } + + if(payloadData == null) { + throw new ApplicationDefinitionException("Unable to find matching payload for cartridge type " + cartridgeType + + ", provider " + cartridgeProvider); + } + + return payloadData; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationClusterContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationClusterContext.java new file mode 100644 index 0000000..39b8214 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationClusterContext.java @@ -0,0 +1,137 @@ +/* + * 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.applications.pojo; + +public class ApplicationClusterContext { + + // cluster id + private String clusterId; + // cartridge type + private String cartridgeType; + // payload as a String + private String textPayload; + // host name + private String hostName; + // flag to indicate LB cluster + private boolean isLbCluster; + // autoscaling policy + private String autoscalePolicyName; + // deployment policy + private String deploymentPolicyName; + // tenant rance + private String tenantRange; + + public ApplicationClusterContext (String cartridgeType, String clusterId, String hostName, + String textPayload, String deploymentPolicyName, boolean isLbCluster) { + + this.cartridgeType = cartridgeType; + this.clusterId = clusterId; + this.hostName = hostName; + this.textPayload = textPayload; + this.deploymentPolicyName = deploymentPolicyName; + this.isLbCluster = isLbCluster; + this.tenantRange = "*"; + } + + public String getClusterId() { + return clusterId; + } + + public void setClusterId(String clusterId) { + this.clusterId = clusterId; + } + + public String getCartridgeType() { + return cartridgeType; + } + + public void setCartridgeType(String cartridgeType) { + this.cartridgeType = cartridgeType; + } + + public String getTextPayload() { + return textPayload; + } + + public void setTextPayload(String textPayload) { + this.textPayload = textPayload; + } + + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + public boolean isLbCluster() { + return isLbCluster; + } + + public void setLbCluster(boolean lbCluster) { + isLbCluster = lbCluster; + } + + public String getAutoscalePolicyName() { + return autoscalePolicyName; + } + + public void setAutoscalePolicyName(String autoscalePolicyName) { + this.autoscalePolicyName = autoscalePolicyName; + } + + public String getDeploymentPolicyName() { + return deploymentPolicyName; + } + + public void setDeploymentPolicyName(String deploymentPolicyName) { + this.deploymentPolicyName = deploymentPolicyName; + } + + public String getTenantRange() { + return tenantRange; + } + + public void setTenantRange(String tenantRange) { + this.tenantRange = tenantRange; + } + + public boolean equals(Object other) { + + if(other == null || !(other instanceof ApplicationClusterContext)) { + return false; + } + + if(this == other) { + return true; + } + + ApplicationClusterContext that = (ApplicationClusterContext)other; + + return this.cartridgeType.equals(that.cartridgeType) && + this.clusterId.equals(that.clusterId); + } + + public int hashCode () { + return this.cartridgeType.hashCode() + this.clusterId.hashCode(); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationContext.java new file mode 100644 index 0000000..1b9c516 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationContext.java @@ -0,0 +1,93 @@ +/* + * 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.applications.pojo; + +public class ApplicationContext { + + private int tenantId; + + private String tenantDomain; + + private String teantAdminUsername; + + private String applicationId; + + private String alias; + + private ComponentContext componentContext; + + private SubscribableInfoContext[] subscribableInfoContexts; + + public String getApplicationId() { + return applicationId; + } + + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; + } + + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public ComponentContext getComponents() { + return componentContext; + } + + public void setComponents(ComponentContext componentContext) { + this.componentContext = componentContext; + } + + public SubscribableInfoContext[] getSubscribableInfoContext() { + return subscribableInfoContexts; + } + + public void setSubscribableInfoContext(SubscribableInfoContext[] subscribableInfoContexts) { + this.subscribableInfoContexts = subscribableInfoContexts; + } + + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public void setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; + } + + public String getTeantAdminUsername() { + return teantAdminUsername; + } + + public void setTeantAdminUsername(String teantAdminUsername) { + this.teantAdminUsername = teantAdminUsername; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ComponentContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ComponentContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ComponentContext.java new file mode 100644 index 0000000..b39b07f --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ComponentContext.java @@ -0,0 +1,54 @@ +/* + * 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.applications.pojo; + +public class ComponentContext { + + private GroupContext[] groupContexts; + + private SubscribableContext[] subscribableContexts; + + private DependencyContext dependencyContext; + + + public GroupContext[] getGroupContexts() { + return groupContexts; + } + + public void setGroupContexts(GroupContext[] groupContexts) { + this.groupContexts = groupContexts; + } + + public SubscribableContext[] getSubscribableContexts() { + return subscribableContexts; + } + + public void setSubscribableContexts(SubscribableContext[] subscribableContexts) { + this.subscribableContexts = subscribableContexts; + } + + public DependencyContext getDependencyContext() { + return dependencyContext; + } + + public void setDependencyContext(DependencyContext dependencyContext) { + this.dependencyContext = dependencyContext; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/DependencyContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/DependencyContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/DependencyContext.java new file mode 100644 index 0000000..ccb17f0 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/DependencyContext.java @@ -0,0 +1,44 @@ +/* + * 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.applications.pojo; + + +public class DependencyContext { + + private String [] startupOrdersContexts; + + private String terminationBehaviour; + + public String getTerminationBehaviour() { + return terminationBehaviour; + } + + public void setTerminationBehaviour(String terminationBehaviour) { + this.terminationBehaviour = terminationBehaviour; + } + + public String [] getStartupOrdersContexts() { + return startupOrdersContexts; + } + + public void setStartupOrdersContexts(String [] startupOrdersContexts) { + this.startupOrdersContexts = startupOrdersContexts; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/GroupContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/GroupContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/GroupContext.java new file mode 100644 index 0000000..c05a5d5 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/GroupContext.java @@ -0,0 +1,84 @@ +/* + * 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.applications.pojo; + +public class GroupContext { + + private String name; + + private String alias; + + private String deploymentPolicy; + + private String autoscalingPolicy; + + private SubscribableContext[] subscribableContexts; + + private GroupContext[] groupContexts; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public String getDeploymentPolicy() { + return deploymentPolicy; + } + + public void setDeploymentPolicy(String deploymentPolicy) { + this.deploymentPolicy = deploymentPolicy; + } + + public String getAutoscalingPolicy() { + return autoscalingPolicy; + } + + public void setAutoscalingPolicy(String autoscalingPolicy) { + this.autoscalingPolicy = autoscalingPolicy; + } + + public SubscribableContext[] getSubscribableContexts() { + return subscribableContexts; + } + + public void setSubscribableContexts(SubscribableContext[] subscribableContexts) { + this.subscribableContexts = subscribableContexts; + } + + public GroupContext[] getGroupContexts() { + return groupContexts; + } + + public void setGroupContexts(GroupContext[] groupContexts) { + this.groupContexts = groupContexts; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableContext.java new file mode 100644 index 0000000..7ae4864 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableContext.java @@ -0,0 +1,44 @@ +/* + * 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.applications.pojo; + +public class SubscribableContext { + + private String type; + + private String alias; + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java new file mode 100644 index 0000000..62d32df --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java @@ -0,0 +1,103 @@ +/* + * 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.applications.pojo; + +public class SubscribableInfoContext { + + private String alias; + + private String deploymentPolicy; + + private String autoscalingPolicy; + + private String repoUrl; + + private boolean privateRepo; + + private String repoUsername; + + private String repoPassword; + + private String[] dependencyAliases; + + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public String getDeploymentPolicy() { + return deploymentPolicy; + } + + public void setDeploymentPolicy(String deploymentPolicy) { + this.deploymentPolicy = deploymentPolicy; + } + + public String getAutoscalingPolicy() { + return autoscalingPolicy; + } + + public void setAutoscalingPolicy(String autoscalingPolicy) { + this.autoscalingPolicy = autoscalingPolicy; + } + + public String getRepoUrl() { + return repoUrl; + } + + public void setRepoUrl(String repoUrl) { + this.repoUrl = repoUrl; + } + + public boolean isPrivateRepo() { + return privateRepo; + } + + public void setPrivateRepo(boolean privateRepo) { + this.privateRepo = privateRepo; + } + + public String getRepoUsername() { + return repoUsername; + } + + public void setRepoUsername(String repoUsername) { + this.repoUsername = repoUsername; + } + + public String getRepoPassword() { + return repoPassword; + } + + public void setRepoPassword(String repoPassword) { + this.repoPassword = repoPassword; + } + + public String[] getDependencyAliases() { + return dependencyAliases; + } + + public void setDependencyAliases(String[] dependencyAliases) { + this.dependencyAliases = dependencyAliases; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java index 9d4db75..07ddfb6 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java @@ -21,6 +21,7 @@ package org.apache.stratos.autoscaler.applications.topic; 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.pojo.ApplicationClusterContext; import org.apache.stratos.messaging.domain.applications.*; import java.util.Collection; @@ -142,6 +143,49 @@ public class ApplicationBuilder { ApplicationsEventPublisher.sendApplicationUndeployedEvent(applicationId, clusterData); }*/ + public static void handleApplicationCreated (Application application, + Set<ApplicationClusterContext> appClusterCtxts) { + + Applications applications = ApplicationHolder.getApplications(); + + ApplicationHolder.acquireWriteLock(); + + try { + if (applications.getApplication(application.getUniqueIdentifier()) != null) { + ApplicationHolder.persistApplication(application); + } else { + log.warn("Application [ " + application.getUniqueIdentifier() + " ] already exists in Applications"); + } + + } finally { + ApplicationHolder.releaseWriteLock(); + } + + ApplicationsEventPublisher.sendApplicationCreatedEvent(application); + } + + public static void handleApplicationUndeployed (String applicationId) { + + Applications applications = ApplicationHolder.getApplications(); + + ApplicationHolder.acquireWriteLock(); + Application applicationToRemove = applications.getApplication(applicationId); + Set<ClusterDataHolder> clusterData = null; + + try { + if (applicationToRemove != null) { + clusterData = applicationToRemove.getClusterDataRecursively(); + ApplicationHolder.removeApplication(applicationId); + } else { + log.warn("Application [ " + applicationId + " ] not found among existing Applications"); + } + + } finally { + ApplicationHolder.releaseWriteLock(); + } + + ApplicationsEventPublisher.sendApplicationUndeployedEvent(applicationId, clusterData); + } public static void handleGroupTerminatedEvent(String appId, String groupId) { Applications applications = ApplicationHolder.getApplications(); http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java index 7a1203a..7ca224e 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java @@ -7,6 +7,7 @@ import org.apache.stratos.messaging.broker.publish.EventPublisherPool; import org.apache.stratos.messaging.domain.applications.*; import org.apache.stratos.messaging.event.Event; import org.apache.stratos.messaging.event.applications.*; +import org.apache.stratos.messaging.event.topology.ApplicationUndeployedEvent; import org.apache.stratos.messaging.message.receiver.applications.ApplicationManager; import org.apache.stratos.messaging.util.Constants; @@ -23,13 +24,14 @@ public class ApplicationsEventPublisher { publishEvent(new CompleteApplicationsEvent(completeApplications)); } - public static void sendCompleteTopologyEvent(Applications applications) { - CompleteApplicationsEvent applicationsEvent = new CompleteApplicationsEvent(applications); + public static void sendApplicationCreatedEvent (Application application) { - if(log.isDebugEnabled()) { - log.debug(String.format("Publishing complete Applications event")); - } - publishEvent(applicationsEvent); + publishEvent(new ApplicationCreatedEvent(application)); + } + + public static void sendApplicationUndeployedEvent (String appId, Set<ClusterDataHolder> clusterData) { + + publishEvent(new ApplicationUndeployedEvent(appId, clusterData)); } public static void sendGroupCreatedEvent(String appId, String groupId) { http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java index dff493d..b13465f 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java @@ -25,12 +25,14 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.autoscaler.Constants; import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy; +import org.apache.stratos.autoscaler.exception.CartridgeInformationException; import org.apache.stratos.autoscaler.exception.PartitionValidationException; import org.apache.stratos.autoscaler.exception.SpawningException; import org.apache.stratos.autoscaler.exception.TerminationException; import org.apache.stratos.autoscaler.util.ConfUtil; import org.apache.stratos.cloud.controller.stub.*; import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; +import org.apache.stratos.cloud.controller.stub.pojo.CartridgeInfo; import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; import org.apache.stratos.cloud.controller.stub.pojo.Properties; import org.apache.stratos.cloud.controller.stub.pojo.Property; @@ -226,6 +228,20 @@ public class CloudControllerClient { } } + public CartridgeInfo getCartrdgeInformation (String cartridgeType) throws CartridgeInformationException { + try { + return stub.getCartridgeInfo(cartridgeType); + + } catch (RemoteException e) { + String msg = e.getMessage(); + log.error(msg, e); + throw new CartridgeInformationException(msg, e); + } catch (CloudControllerServiceUnregisteredCartridgeExceptionException e) { + String msg = e.getMessage(); + log.error(msg, e); + throw new CartridgeInformationException(msg, e); + } + } } http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/ApplicationDefinitionException.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/ApplicationDefinitionException.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/ApplicationDefinitionException.java new file mode 100644 index 0000000..d904e8d --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/ApplicationDefinitionException.java @@ -0,0 +1,48 @@ +/* + * 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.exception; + +public class ApplicationDefinitionException extends Exception { + + private String message; + + public ApplicationDefinitionException () { + super(); + } + + public ApplicationDefinitionException (String message, Throwable cause) { + super(message, cause); + this.message = message; + } + + public ApplicationDefinitionException (String message) { + super(message); + this.message = message; + } + + public ApplicationDefinitionException (Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } +} + http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/CartridgeInformationException.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/CartridgeInformationException.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/CartridgeInformationException.java new file mode 100644 index 0000000..53bea79 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/CartridgeInformationException.java @@ -0,0 +1,47 @@ +/* + * 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.exception; + +public class CartridgeInformationException extends Exception { + + private String message; + + public CartridgeInformationException () { + super(); + } + + public CartridgeInformationException (String message, Throwable cause) { + super(message, cause); + this.message = message; + } + + public CartridgeInformationException (String message) { + super(message); + this.message = message; + } + + public CartridgeInformationException (Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java index 9f289ab..74cbb56 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java @@ -21,7 +21,9 @@ package org.apache.stratos.autoscaler.interfaces; */ +import org.apache.stratos.autoscaler.applications.pojo.ApplicationContext; import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy; +import org.apache.stratos.autoscaler.exception.ApplicationDefinitionException; import org.apache.stratos.autoscaler.exception.InvalidPartitionException; import org.apache.stratos.autoscaler.exception.InvalidPolicyException; import org.apache.stratos.autoscaler.exception.NonExistingLBException; @@ -86,4 +88,20 @@ public interface AutoScalerServiceInterface { public String getDefaultLBClusterId (String deploymentPolicyName); public String getServiceLBClusterId (String serviceType, String deploymentPolicyName); + + /** + * deploys an Application Definition + * + * @param applicationContext {@link org.apache.stratos.autoscaler.applications.pojo.ApplicationContext} object + * @throws ApplicationDefinitionException if an error is encountered + */ + public void deployApplicationDefinition (ApplicationContext applicationContext) throws ApplicationDefinitionException; + + /** + * undeploys an Application Definition + * + * @param applicationId Id of the Application to be undeployed + * @throws ApplicationDefinitionException if an error is encountered + */ + public void unDeployApplicationDefinition (String applicationId, int tenantId, String tenantDomain) throws ApplicationDefinitionException; } http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java index 0e1417e..5e995da 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java @@ -185,6 +185,11 @@ public class RegistryManager { return null; } + public void removeApplication (String applicationId) { + delete(AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.APPLICATIONS_RESOURCE + + "/" + applicationId); + } + public void persistServiceGroup(ServiceGroup servicegroup) { if(servicegroup == null || StringUtils.isEmpty(servicegroup.getName())){ throw new IllegalArgumentException("Service group or group name can not be null"); http://git-wip-us.apache.org/repos/asf/stratos/blob/b9aabfdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java index 4b95118..835e284 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java @@ -72,6 +72,10 @@ public class AutoscalerUtil { return RegistryManager.getInstance().getApplication(appResourcePath); } + public static void removeApplication (String applicationId) { + RegistryManager.getInstance().removeApplication(applicationId); + } + /*public static LbClusterMonitor getLBClusterMonitor(Cluster cluster) throws PolicyValidationException, PartitionValidationException { // FIXME fix the following code to correctly update // AutoscalerContext context = AutoscalerContext.getInstance();
