Updated Branches: refs/heads/master 6247adc74 -> 07f805074
implementing rest of the mock services Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/6ff39243 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/6ff39243 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/6ff39243 Branch: refs/heads/master Commit: 6ff392438164eb4ec420f68d485a8150a75774f3 Parents: 93fbed7 Author: Pradeep Fernando <[email protected]> Authored: Thu Jan 9 21:14:37 2014 +0530 Committer: Pradeep Fernando <[email protected]> Committed: Thu Jan 9 21:14:37 2014 +0530 ---------------------------------------------------------------------- .../stratos/common/beans/TenantInfoBean.java | 19 ++ .../org.apache.stratos.rest.endpoint/pom.xml | 2 +- .../stratos/rest/endpoint/mock/MockContext.java | 131 +++++++++++- .../rest/endpoint/mock/StratosTestAdmin.java | 203 ++++++++++++++++--- 4 files changed, 328 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6ff39243/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/TenantInfoBean.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/TenantInfoBean.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/TenantInfoBean.java index 431dc3c..71b7b7b 100755 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/TenantInfoBean.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/TenantInfoBean.java @@ -41,6 +41,25 @@ public class TenantInfoBean { private String originatedService; private String usagePlan; + + public TenantInfoBean(){} + + /*copy constructor*/ + public TenantInfoBean(TenantInfoBean tenantInfoBean) { + this.admin = tenantInfoBean.admin; + this.firstname = tenantInfoBean.firstname; + this.lastname = tenantInfoBean.lastname; + this.adminPassword = tenantInfoBean.adminPassword; + this.tenantDomain = tenantInfoBean.tenantDomain; + this.tenantId = tenantInfoBean.tenantId; + this.email = tenantInfoBean.email; + this.active = tenantInfoBean.active; + this.successKey = tenantInfoBean.successKey; + this.createdDate = (Calendar)tenantInfoBean.createdDate.clone(); + this.originatedService = tenantInfoBean.originatedService; + this.usagePlan = tenantInfoBean.usagePlan; + } + public String getFirstname() { return firstname; } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6ff39243/components/org.apache.stratos.rest.endpoint/pom.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/pom.xml b/components/org.apache.stratos.rest.endpoint/pom.xml index 847405d..d0904c1 100644 --- a/components/org.apache.stratos.rest.endpoint/pom.xml +++ b/components/org.apache.stratos.rest.endpoint/pom.xml @@ -75,7 +75,7 @@ <directory>src/main/webapp/${appName}</directory> </resource> </webResources> - <warName>${appName}</warName> + <warName>stratos</warName> </configuration> </plugin> </plugins> http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6ff39243/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java index 1efd593..b3897ce 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java @@ -16,10 +16,16 @@ package org.apache.stratos.rest.endpoint.mock;/* * under the License. */ +import org.apache.stratos.common.beans.TenantInfoBean; import org.apache.stratos.manager.dto.Cartridge; import org.apache.stratos.manager.dto.SubscriptionInfo; 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.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.exception.RestAPIException; import java.util.*; @@ -29,6 +35,10 @@ public class MockContext { private Map<String,Cartridge> availableSingleTenantCartridges = new HashMap<String,Cartridge>(); private Map<String,Cartridge> availableMultiTenantCartridges = new HashMap<String,Cartridge>(); private Map<String,Cartridge> subscribedCartridges = new HashMap<String,Cartridge>(); + private Map<String,TenantInfoBean> tenantMap = new HashMap<String, TenantInfoBean>(); + private Map<String,Partition> partitionMap = new HashMap<String, Partition>(); + private Map<String,AutoscalePolicy> autoscalePolicyMap = new HashMap<String, AutoscalePolicy>(); + private Map<String,DeploymentPolicy> deploymentPolicyMap = new HashMap<String, DeploymentPolicy>(); private Set<Cartridge> temp = new HashSet<Cartridge>(); @@ -77,10 +87,10 @@ public class MockContext { String alias = cartridgeInfoBean.getAlias(); Cartridge subscribedCartridge; // retrieve the cartridge from available ones - if(availableSingleTenantCartridges.containsKey(alias)){ + if(availableSingleTenantCartridges.containsKey(cartridgeType)){ subscribedCartridge = availableSingleTenantCartridges.get(cartridgeType); - }else if(availableMultiTenantCartridges.containsKey(alias)){ + }else if(availableMultiTenantCartridges.containsKey(cartridgeType)){ subscribedCartridge = availableMultiTenantCartridges.get(cartridgeType); }else { throw new RuntimeException("Wrong programme sequence"); // TODO; handle properly @@ -111,4 +121,121 @@ public class MockContext { subscribedCartridges.remove(alias); } } + + public void addTenant(TenantInfoBean tenantInfoBean){ + tenantMap.put(tenantInfoBean.getTenantDomain(),tenantInfoBean); + } + + public TenantInfoBean getTenant(String tenantDomain){ + return tenantMap.get(tenantDomain); + } + + public void deleteTenant(String tenantDomain) { + tenantMap.remove(tenantDomain); + } + + public TenantInfoBean[] getTenants() { + return tenantMap.values().toArray(new TenantInfoBean[0]); + } + + public TenantInfoBean[] retrievePartialSearchTenants(String searchDomain) { + List<TenantInfoBean> searchResult = new LinkedList<TenantInfoBean>(); + for(String tenantDomain : tenantMap.keySet()){ + if(tenantDomain.contains(searchDomain)){ + searchResult.add(new TenantInfoBean(tenantMap.get(tenantDomain))); + } + } + return searchResult.toArray(new TenantInfoBean[0]); + } + + public void activateTenant(String tenantDomain) throws RestAPIException{ + if(tenantMap.containsKey(tenantDomain)){ + tenantMap.get(tenantDomain).setActive(true); + } else{ + throw new RestAPIException("Invalid tenant domain"); + } + } + + public void deactivateTenant(String tenantDomain) throws RestAPIException{ + if(tenantMap.containsKey(tenantDomain)){ + tenantMap.get(tenantDomain).setActive(false); + } else{ + throw new RestAPIException("Invalid tenant domain"); + } + } + + public void deleteCartridgeDefinition(String cartridgeType) throws RestAPIException{ + if(availableSingleTenantCartridges.containsKey(cartridgeType)){ + availableSingleTenantCartridges.remove(cartridgeType); + } else if(availableMultiTenantCartridges.containsKey(cartridgeType)){ + availableMultiTenantCartridges.remove(cartridgeType); + } else{ + throw new RestAPIException("invalid cartridge type"); + } + } + + public boolean addPartition(Partition partition) { + partitionMap.put(partition.id, partition); + return true; + } + + public boolean addAutoScalingPolicyDefinition(AutoscalePolicy autoscalePolicy) { + autoscalePolicyMap.put(autoscalePolicy.getId(), autoscalePolicy); + return true; + } + + public boolean addDeploymentPolicyDefinition(DeploymentPolicy deploymentPolicy) { + deploymentPolicyMap.put(deploymentPolicy.id,deploymentPolicy); + return true; + + } + + public Partition[] getPartitions() { + return partitionMap.values().toArray(new Partition[0]); + } + + public Partition getPartition(String partitionId) { + return partitionMap.get(partitionId); + } + + + public Partition[] getPartitionsOfPolicy(String deploymentPolicyId) { + return deploymentPolicyMap.get(deploymentPolicyId).partition.toArray(new Partition[0]); + } + + public PartitionGroup[] getPartitionGroups(String deploymentPolicyId) { + return deploymentPolicyMap.get(deploymentPolicyId).partitionGroup.toArray(new PartitionGroup[0]); + } + + public AutoscalePolicy[] getAutoscalePolicies() { + return autoscalePolicyMap.values().toArray(new AutoscalePolicy[0]); + } + + public AutoscalePolicy getAutoscalePolicies(String autoscalePolicyId) { + return autoscalePolicyMap.get(autoscalePolicyId); + } + + public DeploymentPolicy[] getDeploymentPolicies() { + return deploymentPolicyMap.values().toArray(new DeploymentPolicy[0]); + } + + public DeploymentPolicy getDeploymentPolicies(String deploymentPolicyId) { + return deploymentPolicyMap.get(deploymentPolicyId); + } + + public Partition[] getPartitions(String deploymentPolicyId, String partitionGroupId) { + DeploymentPolicy deploymentPolicy = deploymentPolicyMap.get(deploymentPolicyId); + for(PartitionGroup partitionGroup : deploymentPolicy.partitionGroup){ + if(partitionGroup.id.equals(partitionGroupId)){ + return partitionGroup.partition.toArray(new Partition[0]); + } + } + return new Partition[0]; + } + + /*public DeploymentPolicy[] getValidDeploymentPolicies(String cartridgeType) { + for(DeploymentPolicy deploymentPolicy : deploymentPolicyMap.values()){ + deploymentPolicy. + } + }*/ } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6ff39243/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/StratosTestAdmin.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/StratosTestAdmin.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/StratosTestAdmin.java index 987abb0..208d521 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/StratosTestAdmin.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/StratosTestAdmin.java @@ -18,14 +18,20 @@ */ package org.apache.stratos.rest.endpoint.mock; +import org.apache.catalina.tribes.membership.McastService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.TenantInfoBean; import org.apache.stratos.manager.dto.Cartridge; import org.apache.stratos.manager.dto.SubscriptionInfo; import org.apache.stratos.manager.exception.ADCException; 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.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.exception.RestAPIException; @@ -35,21 +41,6 @@ import javax.ws.rs.*; public class StratosTestAdmin { private static Log log = LogFactory.getLog(StratosTestAdmin.class); - - - @POST - @Path("/cartridge/definition/") - @Produces("application/json") - @Consumes("application/json") - @AuthorizationAction("/permission/protected/manage/monitor/tenants") - @SuperTenantService(true) - public void deployCartridgeDefinition (CartridgeDefinitionBean cartridgeDefinitionBean) - throws RestAPIException { - log.info("Cartridge definition : " + cartridgeDefinitionBean.toString()); - MockContext.getInstance().addCartirdgeDefinition(cartridgeDefinitionBean); - } - - @GET @Path("/cartridge/tenanted/list") @Produces("application/json") @@ -97,7 +88,7 @@ public class StratosTestAdmin { public void unsubscribe(String alias){ MockContext.getInstance().unsubscribe(alias); } - /* + @POST @Path("/tenant") @Consumes("application/json") @@ -105,7 +96,8 @@ public class StratosTestAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) public String addTenant(TenantInfoBean tenantInfoBean) throws Exception { - + MockContext.getInstance().addTenant(tenantInfoBean); + return "tenant added successfully..."; // why this string return type ?? } @@ -115,7 +107,7 @@ public class StratosTestAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) public void updateTenant(TenantInfoBean tenantInfoBean) throws Exception { - + MockContext.getInstance().addTenant(tenantInfoBean); } @GET @@ -125,7 +117,7 @@ public class StratosTestAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) public TenantInfoBean getTenant(@PathParam("tenantDomain") String tenantDomain) throws Exception { - + return MockContext.getInstance().getTenant(tenantDomain); } @DELETE @@ -135,7 +127,7 @@ public class StratosTestAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) public void deleteTenant(@PathParam("tenantDomain") String tenantDomain) throws Exception { - + MockContext.getInstance().deleteTenant(tenantDomain); } @@ -145,7 +137,7 @@ public class StratosTestAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) public TenantInfoBean[] retrieveTenants() throws Exception { - + return MockContext.getInstance().getTenants(); } @GET @@ -155,7 +147,7 @@ public class StratosTestAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) public TenantInfoBean[] retrievePartialSearchTenants(@PathParam("domain")String domain) throws Exception { - + return MockContext.getInstance().retrievePartialSearchTenants(domain); } @@ -165,8 +157,7 @@ public class StratosTestAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) public void activateTenant(@PathParam("tenantDomain") String tenantDomain) throws Exception { - - + MockContext.getInstance().activateTenant(tenantDomain); } @POST @@ -175,7 +166,171 @@ public class StratosTestAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) public void deactivateTenant(@PathParam("tenantDomain") String tenantDomain) throws Exception { + MockContext.getInstance().deactivateTenant(tenantDomain); + } + + @POST + @Path("/cartridge/definition/") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + @SuperTenantService(true) + public void deployCartridgeDefinition (CartridgeDefinitionBean cartridgeDefinitionBean) + throws RestAPIException { + MockContext.getInstance().addCartirdgeDefinition(cartridgeDefinitionBean); + } + + @DELETE + @Path("/cartridge/definition/{cartridgeType}") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + @SuperTenantService(true) + public void unDeployCartridgeDefinition (@PathParam("cartridgeType") String cartridgeType) throws RestAPIException { + MockContext.getInstance().deleteCartridgeDefinition(cartridgeType); + } + + @POST + @Path("/policy/deployment/partition") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + @SuperTenantService(true) + public boolean deployPartition (Partition partition) + throws RestAPIException { + return MockContext.getInstance().addPartition(partition); + } + + @POST + @Path("/policy/autoscale") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + @SuperTenantService(true) + public boolean deployAutoscalingPolicyDefintion (AutoscalePolicy autoscalePolicy) + throws RestAPIException { + return MockContext.getInstance().addAutoScalingPolicyDefinition(autoscalePolicy); + + } + + @POST + @Path("/policy/deployment") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + @SuperTenantService(true) + public boolean deployDeploymentPolicyDefinition (DeploymentPolicy deploymentPolicy) + throws RestAPIException { + return MockContext.getInstance().addDeploymentPolicyDefinition(deploymentPolicy); + + } + + @GET + @Path("/partition") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public Partition[] getPartitions () throws RestAPIException { + return MockContext.getInstance().getPartitions(); + + } + + @GET + @Path("/partition/{partitionId}") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public Partition getPartition (@PathParam("partitionId") String partitionId) throws RestAPIException { + return MockContext.getInstance().getPartition(partitionId); + + } + + @GET + @Path("/partition/group/{deploymentPolicyId}") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public PartitionGroup[] getPartitionGroups (@PathParam("deploymentPolicyId") String deploymentPolicyId) + throws RestAPIException { + return MockContext.getInstance().getPartitionGroups(deploymentPolicyId); + + } + + @GET + @Path("/partition/{deploymentPolicyId}/{partitionGroupId}") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public Partition[] getPartitions (@PathParam("deploymentPolicyId") String deploymentPolicyId, + @PathParam("partitionGroupId") String partitionGroupId) throws RestAPIException { + return MockContext.getInstance().getPartitions(deploymentPolicyId,partitionGroupId); + + } + + @GET + @Path("/partition/{deploymentPolicyId}") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public Partition [] getPartitionsOfPolicy (@PathParam("deploymentPolicyId") String deploymentPolicyId) + throws RestAPIException { + return MockContext.getInstance().getPartitionsOfPolicy(deploymentPolicyId); + + } + + @GET + @Path("/policy/autoscale") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public AutoscalePolicy[] getAutoscalePolicies () throws RestAPIException { + return MockContext.getInstance().getAutoscalePolicies(); + + } + + @GET + @Path("/policy/autoscale/{autoscalePolicyId}") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public AutoscalePolicy getAutoscalePolicies (@PathParam("autoscalePolicyId") String autoscalePolicyId) + throws RestAPIException { + return MockContext.getInstance().getAutoscalePolicies(autoscalePolicyId); + + } + + @GET + @Path("/policy/deployment") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public DeploymentPolicy[] getDeploymentPolicies () throws RestAPIException { + return MockContext.getInstance().getDeploymentPolicies(); + + } + + @GET + @Path("/policy/deployment/{deploymentPolicyId}") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public DeploymentPolicy getDeploymentPolicies (@PathParam("deploymentPolicyId") String deploymentPolicyId) + throws RestAPIException { + return MockContext.getInstance().getDeploymentPolicies(deploymentPolicyId); + + } + + /* @GET + @Path("{cartridgeType}/policy/deployment") + @Produces("application/json") + @Consumes("application/json") + @AuthorizationAction("/permission/protected/manage/monitor/tenants") + public DeploymentPolicy[] getValidDeploymentPolicies (@PathParam("cartridgeType") String cartridgeType) + throws RestAPIException { + return MockContext.getInstance().getValidDeploymentPolicies(cartridgeType); }*/ + + }
