Fixing tenant management rest api methods
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/1df52c42 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/1df52c42 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/1df52c42 Branch: refs/heads/master Commit: 1df52c42124c85921e6e55559343c2078def93aa Parents: 05d5535 Author: Imesh Gunaratne <[email protected]> Authored: Wed Dec 17 15:28:00 2014 +0530 Committer: Udara Liyanage <[email protected]> Committed: Thu Dec 18 12:06:58 2014 +0530 ---------------------------------------------------------------------- .../deployer/DefaultServiceGroupDeployer.java | 14 ++++--- .../rest/endpoint/api/StratosApiV41.java | 38 +++++++++-------- .../util/converter/ObjectConverter.java | 43 ++++++++++++++++---- 3 files changed, 62 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/1df52c42/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java index 789d116..275b179 100644 --- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java +++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java @@ -26,7 +26,6 @@ import org.apache.stratos.autoscaler.stub.AutoScalerServiceAutoScalerExceptionEx import org.apache.stratos.autoscaler.stub.AutoScalerServiceInvalidServiceGroupExceptionException; import org.apache.stratos.autoscaler.stub.pojo.Dependencies; import org.apache.stratos.autoscaler.stub.pojo.ServiceGroup; -import org.apache.stratos.autoscaler.stub.exception.*; import org.apache.stratos.cloud.controller.stub.CloudControllerServiceUnregisteredCartridgeExceptionException; import org.apache.stratos.manager.client.AutoscalerServiceClient; import org.apache.stratos.manager.client.CloudControllerServiceClient; @@ -36,7 +35,6 @@ import org.apache.stratos.manager.exception.ServiceGroupDefinitioException; import org.apache.stratos.manager.grouping.definitions.DependencyDefinitions; import org.apache.stratos.manager.grouping.definitions.ServiceGroupDefinition; -import java.lang.reflect.Array; import java.rmi.RemoteException; import java.util.*; @@ -199,7 +197,7 @@ public class DefaultServiceGroupDeployer implements ServiceGroupDeployer { return null; } - ServiceGroupDefinition serviceGroupDef = populateServiceGroupDefinitionPojo(serviceGroup); + ServiceGroupDefinition serviceGroupDef = convertServiceGroupToServiceGroupDefinition(serviceGroup); return serviceGroupDef; } catch (AxisFault axisFault) { @@ -227,7 +225,7 @@ public class DefaultServiceGroupDeployer implements ServiceGroupDeployer { ServiceGroupDefinition[] serviceGroupDefinitions = new ServiceGroupDefinition[serviceGroups.length]; for (int i = 0; i < serviceGroups.length; i++) { - serviceGroupDefinitions[i] = populateServiceGroupDefinitionPojo(serviceGroups[i]); + serviceGroupDefinitions[i] = convertServiceGroupToServiceGroupDefinition(serviceGroups[i]); } return serviceGroupDefinitions; @@ -322,7 +320,11 @@ public class DefaultServiceGroupDeployer implements ServiceGroupDeployer { return servicegroup; } - private ServiceGroupDefinition populateServiceGroupDefinitionPojo(ServiceGroup serviceGroup) { + private ServiceGroupDefinition convertServiceGroupToServiceGroupDefinition(ServiceGroup serviceGroup) { + if(serviceGroup == null) { + return null; + } + ServiceGroupDefinition servicegroupDef = new ServiceGroupDefinition(); servicegroupDef.setName(serviceGroup.getName()); String[] cartridges = serviceGroup.getCartridges(); @@ -332,7 +334,7 @@ public class DefaultServiceGroupDeployer implements ServiceGroupDeployer { List<ServiceGroupDefinition> groupDefinitions = new ArrayList<ServiceGroupDefinition>(groups.length); for (ServiceGroup group : groups) { if (group != null) { - groupDefinitions.add(populateServiceGroupDefinitionPojo(group)); + groupDefinitions.add(convertServiceGroupToServiceGroupDefinition(group)); } } http://git-wip-us.apache.org/repos/asf/stratos/blob/1df52c42/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java index f7dc1c3..2e1c7f3 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java @@ -662,7 +662,7 @@ public class StratosApiV41 extends AbstractApi { @Produces("application/json") @AuthorizationAction("/permission/protected/manage/modify/tenants") @SuperTenantService(true) - public Response createTenant(TenantInfoBean tenantInfoBean) throws RestAPIException { + public Response createTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException { try { CommonUtil.validateEmail(tenantInfoBean.getEmail()); } catch (Exception e) { @@ -693,7 +693,8 @@ public class StratosApiV41 extends AbstractApi { throw new RestAPIException("Invalid data"); // obscure error message. } - Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean); + Tenant tenant = TenantMgtUtil.initializeTenant( + ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean)); TenantPersistor persistor = ServiceHolder.getTenantPersistor(); // not validating the domain ownership, since created by super tenant int tenantId = 0; //TODO verify whether this is the correct approach (isSkeleton) @@ -717,7 +718,7 @@ public class StratosApiV41 extends AbstractApi { //Notify tenant addition try { - TenantMgtUtil.triggerAddTenant(tenantInfoBean); + TenantMgtUtil.triggerAddTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean)); } catch (StratosException e) { String msg = "Error in notifying tenant addition."; log.error(msg, e); @@ -725,7 +726,7 @@ public class StratosApiV41 extends AbstractApi { } // For the super tenant tenant creation, tenants are always activated as they are created. try { - TenantMgtUtil.activateTenantInitially(tenantInfoBean, tenantId); + TenantMgtUtil.activateTenantInitially(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean), tenantId); } catch (Exception e) { String msg = "Error in initial activation of tenant " + tenantDomain; log.error(msg, e); @@ -756,11 +757,10 @@ public class StratosApiV41 extends AbstractApi { @Consumes("application/json") @AuthorizationAction("/permission/protected/manage/modify/tenants") @SuperTenantService(true) - public Response updateTenant(TenantInfoBean tenantInfoBean) throws RestAPIException { + public Response updateTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException { try { updateExistingTenant(tenantInfoBean); - } catch (TenantNotFoundException ex) { Response.status(Response.Status.NOT_FOUND).build(); } catch (Exception e) { @@ -772,7 +772,7 @@ public class StratosApiV41 extends AbstractApi { return Response.noContent().build(); } - private void updateExistingTenant(TenantInfoBean tenantInfoBean) throws Exception { + private void updateExistingTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws Exception { TenantManager tenantManager = ServiceHolder.getTenantManager(); UserStoreManager userStoreManager; @@ -885,7 +885,7 @@ public class StratosApiV41 extends AbstractApi { //Notify tenant update to all listeners try { - TenantMgtUtil.triggerUpdateTenant(tenantInfoBean); + TenantMgtUtil.triggerUpdateTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean)); } catch (StratosException e) { String msg = "Error in notifying tenant update."; log.error(msg, e); @@ -906,7 +906,7 @@ public class StratosApiV41 extends AbstractApi { @Produces("application/json") @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) - public TenantInfoBean getTenantForDomain(@PathParam("tenantDomain") String tenantDomain) throws RestAPIException { + public org.apache.stratos.common.beans.TenantInfoBean getTenantForDomain(@PathParam("tenantDomain") String tenantDomain) throws RestAPIException { try { return getTenantByDomain(tenantDomain); @@ -917,7 +917,7 @@ public class StratosApiV41 extends AbstractApi { } } - private TenantInfoBean getTenantByDomain(String tenantDomain) throws Exception { + private org.apache.stratos.common.beans.TenantInfoBean getTenantByDomain(String tenantDomain) throws Exception { TenantManager tenantManager = ServiceHolder.getTenantManager(); @@ -939,7 +939,8 @@ public class StratosApiV41 extends AbstractApi { throw new Exception(msg, e); } - TenantInfoBean bean = TenantMgtUtil.initializeTenantInfoBean(tenantId, tenant); + org.apache.stratos.common.beans.TenantInfoBean bean = + ObjectConverter.convertCarbonTenantInfoBeanToTenantInfoBean(TenantMgtUtil.initializeTenantInfoBean(tenantId, tenant)); // retrieve first and last names from the UserStoreManager bean.setFirstname(ClaimsMgtUtil.getFirstNamefromUserStoreManager( @@ -1037,7 +1038,7 @@ public class StratosApiV41 extends AbstractApi { List<org.apache.stratos.common.beans.TenantInfoBean> tenantList = new ArrayList<org.apache.stratos.common.beans.TenantInfoBean>(); for (Tenant tenant : tenants) { - org.apache.stratos.common.beans.TenantInfoBean bean = ObjectConverter.convertTenantInfoBean( + org.apache.stratos.common.beans.TenantInfoBean bean = ObjectConverter.convertCarbonTenantInfoBeanToTenantInfoBean( TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant)); tenantList.add(bean); } @@ -1057,10 +1058,10 @@ public class StratosApiV41 extends AbstractApi { @Produces("application/json") @AuthorizationAction("/permission/protected/manage/monitor/tenants") @SuperTenantService(true) - public TenantInfoBean[] getPartialSearchTenants(@PathParam("tenantDomain") String tenantDomain) + public org.apache.stratos.common.beans.TenantInfoBean[] getPartialSearchTenants(@PathParam("tenantDomain") String tenantDomain) throws RestAPIException { - List<TenantInfoBean> tenantList = null; + List<org.apache.stratos.common.beans.TenantInfoBean> tenantList = null; try { tenantList = searchPartialTenantsDomains(tenantDomain); } catch (Exception e) { @@ -1068,10 +1069,10 @@ public class StratosApiV41 extends AbstractApi { log.error(msg, e); throw new RestAPIException(msg); } - return tenantList.toArray(new TenantInfoBean[tenantList.size()]); + return tenantList.toArray(new org.apache.stratos.common.beans.TenantInfoBean[tenantList.size()]); } - private List<TenantInfoBean> searchPartialTenantsDomains(String domain) throws RestAPIException { + private List<org.apache.stratos.common.beans.TenantInfoBean> searchPartialTenantsDomains(String domain) throws RestAPIException { TenantManager tenantManager = ServiceHolder.getTenantManager(); Tenant[] tenants; try { @@ -1083,9 +1084,10 @@ public class StratosApiV41 extends AbstractApi { throw new RestAPIException(msg); } - List<TenantInfoBean> tenantList = new ArrayList<TenantInfoBean>(); + List<org.apache.stratos.common.beans.TenantInfoBean> tenantList = new ArrayList<org.apache.stratos.common.beans.TenantInfoBean>(); for (Tenant tenant : tenants) { - TenantInfoBean bean = TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant); + org.apache.stratos.common.beans.TenantInfoBean bean = ObjectConverter.convertCarbonTenantInfoBeanToTenantInfoBean( + TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant)); tenantList.add(bean); } return tenantList; http://git-wip-us.apache.org/repos/asf/stratos/blob/1df52c42/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java index c1ed810..86bade3 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java @@ -1492,17 +1492,42 @@ public class ObjectConverter { return instanceList; } - public static org.apache.stratos.common.beans.TenantInfoBean convertTenantInfoBean(TenantInfoBean tenantInfoBean) { + public static org.apache.stratos.common.beans.TenantInfoBean convertCarbonTenantInfoBeanToTenantInfoBean( + TenantInfoBean carbonTenantInfoBean) { + + if(carbonTenantInfoBean == null) { + return null; + } + org.apache.stratos.common.beans.TenantInfoBean stratosTenantInfoBean = new org.apache.stratos.common.beans.TenantInfoBean(); - stratosTenantInfoBean.setTenantId(tenantInfoBean.getTenantId()); - stratosTenantInfoBean.setTenantDomain(tenantInfoBean.getTenantDomain()); - stratosTenantInfoBean.setActive(tenantInfoBean.isActive()); - stratosTenantInfoBean.setAdmin(tenantInfoBean.getAdmin()); - stratosTenantInfoBean.setEmail(tenantInfoBean.getEmail()); - stratosTenantInfoBean.setFirstname(tenantInfoBean.getFirstname()); - stratosTenantInfoBean.setLastname(tenantInfoBean.getLastname()); - stratosTenantInfoBean.setCreatedDate(tenantInfoBean.getCreatedDate()); + stratosTenantInfoBean.setTenantId(carbonTenantInfoBean.getTenantId()); + stratosTenantInfoBean.setTenantDomain(carbonTenantInfoBean.getTenantDomain()); + stratosTenantInfoBean.setActive(carbonTenantInfoBean.isActive()); + stratosTenantInfoBean.setAdmin(carbonTenantInfoBean.getAdmin()); + stratosTenantInfoBean.setEmail(carbonTenantInfoBean.getEmail()); + stratosTenantInfoBean.setFirstname(carbonTenantInfoBean.getFirstname()); + stratosTenantInfoBean.setLastname(carbonTenantInfoBean.getLastname()); + stratosTenantInfoBean.setCreatedDate(carbonTenantInfoBean.getCreatedDate()); return stratosTenantInfoBean; } + + public static TenantInfoBean convertTenantInfoBeanToCarbonTenantInfoBean( + org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) { + + if(tenantInfoBean == null) { + return null; + } + + TenantInfoBean carbonTenantInfoBean = new TenantInfoBean(); + carbonTenantInfoBean.setTenantId(tenantInfoBean.getTenantId()); + carbonTenantInfoBean.setTenantDomain(tenantInfoBean.getTenantDomain()); + carbonTenantInfoBean.setActive(tenantInfoBean.isActive()); + carbonTenantInfoBean.setAdmin(tenantInfoBean.getAdmin()); + carbonTenantInfoBean.setEmail(tenantInfoBean.getEmail()); + carbonTenantInfoBean.setFirstname(tenantInfoBean.getFirstname()); + carbonTenantInfoBean.setLastname(tenantInfoBean.getLastname()); + carbonTenantInfoBean.setCreatedDate(tenantInfoBean.getCreatedDate()); + return carbonTenantInfoBean; + } }
