Updated Branches: refs/heads/master b6591566f -> 2d4c62af5
initial impl of getting DeploymentPolicies through Rest API Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/2d4c62af Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/2d4c62af Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/2d4c62af Branch: refs/heads/master Commit: 2d4c62af59108acb9fdf1473890f873553273610 Parents: b659156 Author: Isuru <[email protected]> Authored: Thu Dec 5 20:27:22 2013 +0530 Committer: Isuru <[email protected]> Committed: Thu Dec 5 20:27:22 2013 +0530 ---------------------------------------------------------------------- .../autoscaler/partition/PartitionGroup.java | 34 +++++++++ .../bean/autoscaler/policy/AutoscalePolicy.java | 30 -------- .../policy/autoscale/AutoscalePolicy.java | 32 ++++++++ .../policy/deployment/DeploymentPolicy.java | 35 +++++++++ .../service/client/AutoscalerServiceClient.java | 16 ++++ .../rest/endpoint/services/ServiceUtils.java | 78 +++++++++++++++++++- .../rest/endpoint/services/StratosAdmin.java | 13 +++- 7 files changed, 205 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2d4c62af/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/partition/PartitionGroup.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/partition/PartitionGroup.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/partition/PartitionGroup.java new file mode 100644 index 0000000..563cecd --- /dev/null +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/partition/PartitionGroup.java @@ -0,0 +1,34 @@ +/* + * 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.rest.endpoint.bean.autoscaler.partition; + +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement +public class PartitionGroup { + + public String id; + + public String partitionAlgo; + + //partition Ids + public List<String> partition; +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2d4c62af/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/AutoscalePolicy.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/AutoscalePolicy.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/AutoscalePolicy.java deleted file mode 100644 index 43c565f..0000000 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/AutoscalePolicy.java +++ /dev/null @@ -1,30 +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.rest.endpoint.bean.autoscaler.policy; - -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -public class AutoscalePolicy { - - public String id; - public String displayName; - public String description; -} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2d4c62af/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/autoscale/AutoscalePolicy.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/autoscale/AutoscalePolicy.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/autoscale/AutoscalePolicy.java new file mode 100644 index 0000000..a37431e --- /dev/null +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/autoscale/AutoscalePolicy.java @@ -0,0 +1,32 @@ +/* + * 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.rest.endpoint.bean.autoscaler.policy.autoscale; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class AutoscalePolicy { + + public String id; + + public String displayName; + + public String description; +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2d4c62af/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java new file mode 100644 index 0000000..b818d91 --- /dev/null +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java @@ -0,0 +1,35 @@ +/* + * 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.rest.endpoint.bean.autoscaler.policy.deployment; + + +import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.PartitionGroup; + +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement +public class DeploymentPolicy { + + public String id; + + //partition groups + public List<PartitionGroup> partitionGroup; +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2d4c62af/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java index 571b89c..9ca19fc 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java @@ -92,4 +92,20 @@ public class AutoscalerServiceClient { return autoscalePolicies; } + + public org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy [] getDeploymentPolicies() + throws Exception { + + org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy[] deploymentPolicies; + try { + deploymentPolicies = stub.getAllDeploymentPolicies(); + + } catch (RemoteException e) { + String errorMsg = "Error in getting available deployment policies"; + log.error(errorMsg, e); + throw new Exception(errorMsg, e); + } + + return deploymentPolicies; + } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2d4c62af/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java index 4de74a8..ae87419 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java @@ -36,7 +36,9 @@ import org.apache.stratos.adc.mgt.utils.PersistenceManager; import org.apache.stratos.adc.topology.mgt.service.TopologyManagementService; import org.apache.stratos.cloud.controller.pojo.*; import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.Partition; -import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.AutoscalePolicy; +import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.PartitionGroup; +import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.autoscale.AutoscalePolicy; +import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.deployment.DeploymentPolicy; import org.apache.stratos.rest.endpoint.bean.cartridge.definition.CartridgeDefinitionBean; import org.apache.stratos.rest.endpoint.bean.cartridge.definition.IaasProviderBean; import org.apache.stratos.rest.endpoint.bean.cartridge.definition.PortMappingBean; @@ -286,7 +288,7 @@ public class ServiceUtils { autoscalePolicies = autoscalerServiceClient.getAutoScalePolicies(); } catch (Exception e) { - String errorMsg = "Error getting available partitions"; + String errorMsg = "Error getting available autoscaling policies"; log.error(errorMsg, e); throw new RestAPIException(errorMsg, e); } @@ -316,6 +318,78 @@ public class ServiceUtils { return autoscalePolicyBeans; } + + public static DeploymentPolicy[] getDeploymentPolicies () throws RestAPIException { + + org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy [] deploymentPolicies = null; + AutoscalerServiceClient autoscalerServiceClient = getAutoscalerServiceClient(); + if (autoscalerServiceClient != null) { + try { + deploymentPolicies = autoscalerServiceClient.getDeploymentPolicies(); + + } catch (Exception e) { + String errorMsg = "Error getting available deployment policies"; + log.error(errorMsg, e); + throw new RestAPIException(errorMsg, e); + } + } + + return populateDeploymentPolicyPojo(deploymentPolicies); + } + + private static DeploymentPolicy[] populateDeploymentPolicyPojo (org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy [] + deploymentPolicies) { + DeploymentPolicy[] deploymentPolicyBeans; + if(deploymentPolicies == null) { + deploymentPolicyBeans = new DeploymentPolicy[0]; + return deploymentPolicyBeans; + } + + deploymentPolicyBeans = new DeploymentPolicy[deploymentPolicies.length]; + for (int i = 0 ; i < deploymentPolicies.length ; i++) { + DeploymentPolicy deploymentPolicy = new DeploymentPolicy(); + deploymentPolicy.id = deploymentPolicies[i].getId(); + + //if(deploymentPolicies[i].getPartitionGroups() != null && + // deploymentPolicies[i].getPartitionGroups().length > 0) { + // deploymentPolicy.partitionGroup = getPartitionGroups(deploymentPolicies[i].getPartitionGroups()); + //} + + deploymentPolicyBeans[i] = deploymentPolicy; + } + + return deploymentPolicyBeans; + } + + private static List<PartitionGroup> getPartitionGroups (org.apache.stratos.autoscaler.partition.xsd.PartitionGroup[] partitionGroups) { + + List<PartitionGroup> partitionGroupList = new ArrayList<PartitionGroup>(); + for (int i = 0 ; i < partitionGroups.length ; i ++) { + PartitionGroup partitionGroup = new PartitionGroup(); + partitionGroup.id = partitionGroups[i].getId(); + partitionGroup.partitionAlgo = partitionGroups[i].getPartitionAlgo(); + + if(partitionGroups[i].getPartitions() != null && partitionGroups[i].getPartitions().length > 0){ + partitionGroup.partition = getPartitionIdsList(partitionGroups[i].getPartitions()); + } + + partitionGroupList.add(partitionGroup); + } + + return partitionGroupList; + } + + private static List<String> getPartitionIdsList(org.apache.stratos.cloud.controller.deployment.partition.Partition[] + partitions) { + + ArrayList<String> partitionIdList = new ArrayList<String>(); + for (int i = 0 ; i < partitions.length ; i++) { + partitionIdList.add(partitions[i].getId()); + } + + return partitionIdList; + } + static List<Cartridge> getAvailableCartridges(String cartridgeSearchString, Boolean multiTenant, ConfigurationContext configurationContext) throws ADCException { List<Cartridge> cartridges = new ArrayList<Cartridge>(); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2d4c62af/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java index 60688f5..c7a646d 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java @@ -32,7 +32,8 @@ import org.apache.stratos.rest.endpoint.annotation.AuthorizationAction; import org.apache.stratos.rest.endpoint.annotation.SuperTenantService; import org.apache.stratos.rest.endpoint.bean.CartridgeInfoBean; import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.Partition; -import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.AutoscalePolicy; +import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.autoscale.AutoscalePolicy; +import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.deployment.DeploymentPolicy; import org.apache.stratos.rest.endpoint.bean.cartridge.definition.CartridgeDefinitionBean; import org.apache.stratos.rest.endpoint.exception.RestAPIException; import org.apache.stratos.tenant.mgt.util.TenantMgtUtil; @@ -99,6 +100,16 @@ public class StratosAdmin extends AbstractAdmin { } @GET + @Path("/policy/deployment") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public DeploymentPolicy[] getDeploymentPolicies () throws RestAPIException { + + return ServiceUtils.getDeploymentPolicies(); + } + + @GET @Path("/cartridge/tenanted/list") @Produces("application/json") @Consumes("application/json")
