Repository: stratos Updated Branches: refs/heads/tenant-isolation 4676e749a -> 6ce6d5470
Removing UUID and tenantId from KubernetesCluster Bean and Application Bean Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/f2080dcb Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/f2080dcb Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/f2080dcb Branch: refs/heads/tenant-isolation Commit: f2080dcb4a6d22768615a1e0cc969c1811a66a66 Parents: 464ee1e Author: Dinithi <[email protected]> Authored: Fri Aug 7 14:11:18 2015 +0530 Committer: Dinithi <[email protected]> Committed: Fri Aug 7 14:11:18 2015 +0530 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 4 +- .../beans/application/ApplicationBean.java | 18 ----- .../beans/kubernetes/KubernetesClusterBean.java | 18 ----- .../rest/endpoint/api/StratosApiV41.java | 70 +++++++++++------- .../rest/endpoint/api/StratosApiV41Utils.java | 78 ++++++++++---------- .../util/converter/ObjectConverter.java | 32 ++++---- 6 files changed, 98 insertions(+), 122 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/f2080dcb/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java index 140959b..a06cb3b 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java @@ -990,7 +990,7 @@ public class RestCommandLineService { RowMapper<ApplicationBean> rowMapper = new RowMapper<ApplicationBean>() { public String[] getData(ApplicationBean applicationDefinition) { String[] data = new String[3]; - data[0] = applicationDefinition.getApplicationUuid(); + data[0] = applicationDefinition.getApplicationId(); data[1] = applicationDefinition.getAlias(); data[2] = applicationDefinition.getStatus(); return data; @@ -1146,7 +1146,7 @@ public class RestCommandLineService { RowMapper<KubernetesClusterBean> partitionMapper = new RowMapper<KubernetesClusterBean>() { public String[] getData(KubernetesClusterBean kubernetesCluster) { String[] data = new String[2]; - data[0] = kubernetesCluster.getClusterUuid(); + data[0] = kubernetesCluster.getClusterId(); data[1] = kubernetesCluster.getDescription(); return data; } http://git-wip-us.apache.org/repos/asf/stratos/blob/f2080dcb/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java index 8c08dc9..f6e6745 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java @@ -30,7 +30,6 @@ public class ApplicationBean implements Serializable { private static final long serialVersionUID = -2829206180707597651L; - private String applicationUuid; private String applicationId; private boolean multiTenant; private String name; @@ -39,15 +38,6 @@ public class ApplicationBean implements Serializable { private String status; private ComponentBean components; private List<PropertyBean> property; - private int tenantId; - - public String getApplicationUuid() { - return applicationUuid; - } - - public void setApplicationUuid(String applicationUuid) { - this.applicationUuid = applicationUuid; - } public boolean isMultiTenant() { return multiTenant; @@ -105,14 +95,6 @@ public class ApplicationBean implements Serializable { this.property = property; } - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; - } - public String getApplicationId() { return applicationId; } http://git-wip-us.apache.org/repos/asf/stratos/blob/f2080dcb/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/kubernetes/KubernetesClusterBean.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/kubernetes/KubernetesClusterBean.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/kubernetes/KubernetesClusterBean.java index cc930da..53e292a 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/kubernetes/KubernetesClusterBean.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/kubernetes/KubernetesClusterBean.java @@ -27,22 +27,12 @@ import java.util.List; @XmlRootElement public class KubernetesClusterBean { - private String clusterUuid; private String clusterId; private String description; private List<KubernetesHostBean> kubernetesHosts; private KubernetesMasterBean kubernetesMaster; private PortRangeBean portRange; private List<PropertyBean> property; - private int tenantId; - - public String getClusterUuid() { - return clusterUuid; - } - - public void setClusterUuid(String clusterUuid) { - this.clusterUuid = clusterUuid; - } public List<KubernetesHostBean> getKubernetesHosts() { return kubernetesHosts; @@ -91,12 +81,4 @@ public class KubernetesClusterBean { public void setClusterId(String clusterId) { this.clusterId = clusterId; } - - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; - } } http://git-wip-us.apache.org/repos/asf/stratos/blob/f2080dcb/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 f0d9bc8..fe548d4 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 @@ -21,7 +21,9 @@ package org.apache.stratos.rest.endpoint.api; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.autoscaler.stub.*; +import org.apache.stratos.autoscaler.stub.pojo.ApplicationContext; import org.apache.stratos.cloud.controller.stub.*; +import org.apache.stratos.cloud.controller.stub.domain.kubernetes.KubernetesCluster; import org.apache.stratos.common.beans.IaasProviderInfoBean; import org.apache.stratos.common.beans.ResponseMessageBean; import org.apache.stratos.common.beans.TenantInfoBean; @@ -44,6 +46,8 @@ import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean; import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean; import org.apache.stratos.common.beans.topology.ApplicationInfoBean; import org.apache.stratos.common.beans.topology.ClusterBean; +import org.apache.stratos.common.client.AutoscalerServiceClient; +import org.apache.stratos.common.client.CloudControllerServiceClient; import org.apache.stratos.common.exception.InvalidEmailException; import org.apache.stratos.manager.service.stub.StratosManagerServiceApplicationSignUpExceptionException; import org.apache.stratos.manager.service.stub.StratosManagerServiceDomainMappingExceptionException; @@ -780,16 +784,14 @@ public class StratosApiV41 extends AbstractApi { public Response addApplication(ApplicationBean applicationDefinition) throws RestAPIException { try { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - applicationDefinition.setTenantId(carbonContext.getTenantId()); - applicationDefinition.setApplicationUuid(UUID.randomUUID().toString()); - StratosApiV41Utils.addApplication(applicationDefinition, getConfigContext(), + int tenantId = carbonContext.getTenantId(); + String applicationUuid = UUID.randomUUID().toString(); + StratosApiV41Utils.addApplication(applicationDefinition, applicationUuid, tenantId, getConfigContext(), getUsername(), getTenantDomain()); - - URI url = uriInfo.getAbsolutePathBuilder().path(applicationDefinition.getApplicationUuid()).build(); + URI url = uriInfo.getAbsolutePathBuilder().path(applicationUuid).build(); return Response.created(url).entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS, - String.format("Application added successfully: [application] %s", - applicationDefinition.getApplicationUuid()))).build(); + String.format("Application added successfully: [application] %s", applicationUuid))).build(); } catch (ApplicationAlreadyExistException e) { return Response.status(Response.Status.CONFLICT).entity(new ResponseMessageBean( ResponseMessageBean.ERROR, "Application already exists")).build(); @@ -823,12 +825,17 @@ public class StratosApiV41 extends AbstractApi { public Response updateApplication(ApplicationBean applicationDefinition) throws RestAPIException { try { - StratosApiV41Utils.updateApplication(applicationDefinition, getConfigContext(), - getUsername(), getTenantDomain()); - URI url = uriInfo.getAbsolutePathBuilder().path(applicationDefinition.getApplicationUuid()).build(); + PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ApplicationContext applicationContext = AutoscalerServiceClient.getInstance().getApplicationByTenant + (applicationDefinition.getApplicationId(), carbonContext.getTenantId()); + StratosApiV41Utils.updateApplication(applicationDefinition, applicationContext.getApplicationUuid(), + carbonContext.getTenantId(), getConfigContext(), getUsername(), getTenantDomain()); + URI url = uriInfo.getAbsolutePathBuilder().path(applicationContext.getApplicationUuid()).build(); return Response.created(url).entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS, String.format("Application updated successfully: [application] %s", - applicationDefinition.getApplicationUuid()))).build(); + applicationContext.getApplicationUuid()))).build(); + } catch (RemoteException e) { + throw new RestAPIException(e.getMessage()); } catch (AutoscalerServiceCartridgeNotFoundExceptionException e) { String backendErrorMessage = e.getFaultMessage().getCartridgeNotFoundException(). getMessage(); @@ -840,7 +847,6 @@ public class StratosApiV41 extends AbstractApi { return Response.status(Response.Status.BAD_REQUEST).entity(new ResponseMessageBean( ResponseMessageBean.ERROR, backendErrorMessage)).build(); } - } /** @@ -1287,7 +1293,8 @@ public class StratosApiV41 extends AbstractApi { @PathParam("applicationId") String applicationId, @QueryParam("force") @DefaultValue("false") boolean force) throws RestAPIException { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - ApplicationBean applicationDefinition = StratosApiV41Utils.getApplication(applicationId,carbonContext.getTenantId()); + ApplicationBean applicationDefinition = StratosApiV41Utils.getApplication(applicationId, + carbonContext.getTenantId()); if (applicationDefinition == null) { String message = String.format("Application does not exist [application-id] %s", applicationId); log.error(message); @@ -1301,7 +1308,15 @@ public class StratosApiV41 extends AbstractApi { return Response.status(Response.Status.CONFLICT).entity(new ResponseMessageBean( ResponseMessageBean.ERROR, message)).build(); } - StratosApiV41Utils.undeployApplication(applicationDefinition.getApplicationUuid(), force); + + ApplicationContext applicationContext = null; + try { + applicationContext = AutoscalerServiceClient.getInstance().getApplicationByTenant(applicationId, + carbonContext.getTenantId()); + } catch (RemoteException e) { + throw new RestAPIException(e.getMessage()); + } + StratosApiV41Utils.undeployApplication(applicationContext.getApplicationUuid(), force); return Response.accepted().entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS, String.format("Application undeploy process started successfully: [application-id] %s", applicationId))).build(); } @@ -1904,15 +1919,13 @@ public class StratosApiV41 extends AbstractApi { try { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - kubernetesCluster.setTenantId(carbonContext.getTenantId()); - kubernetesCluster.setClusterUuid(UUID.randomUUID().toString()); - StratosApiV41Utils.addKubernetesCluster(kubernetesCluster); - URI url = uriInfo.getAbsolutePathBuilder().path(kubernetesCluster.getClusterUuid()).build(); + int tenantId = carbonContext.getTenantId(); + String kubernetesClusterUuid = UUID.randomUUID().toString(); + StratosApiV41Utils.addKubernetesCluster(kubernetesCluster, kubernetesClusterUuid, tenantId); + URI url = uriInfo.getAbsolutePathBuilder().path(kubernetesClusterUuid).build(); return Response.created(url).entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS, String.format("Kubernetes cluster added successfully: [kub-host-cluster] %s", - kubernetesCluster.getClusterUuid()))).build(); - } catch (RestAPIException e) { - throw e; + kubernetesClusterUuid))).build(); } catch (CloudControllerServiceKubernetesClusterAlreadyExistsExceptionException e) { return Response.status(Response.Status.CONFLICT).entity(new ResponseMessageBean( ResponseMessageBean.ERROR, "Kubernetes cluster already exists")).build(); @@ -1925,7 +1938,7 @@ public class StratosApiV41 extends AbstractApi { /** * Update kubernetes host cluster. * - * @param kubernetesCluster the kubernetes cluster + * @param kubernetesClusterBean the kubernetes cluster * @return 200 if the kubernetes cluster is successfully updated * @throws RestAPIException the rest api exception */ @@ -1935,18 +1948,21 @@ public class StratosApiV41 extends AbstractApi { @Consumes("application/json") @AuthorizationAction("/permission/admin/stratos/kubernetesClusters/manage") public Response updateKubernetesCluster( - KubernetesClusterBean kubernetesCluster) throws RestAPIException { + KubernetesClusterBean kubernetesClusterBean) throws RestAPIException { try { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - kubernetesCluster.setTenantId(carbonContext.getTenantId()); - StratosApiV41Utils.updateKubernetesCluster(kubernetesCluster); + KubernetesCluster kubernetesCluster = CloudControllerServiceClient.getInstance().getKubernetesClusterByTenantId + (kubernetesClusterBean + .getClusterId(), carbonContext.getTenantId()); + StratosApiV41Utils.updateKubernetesCluster(kubernetesClusterBean, kubernetesCluster.getClusterUuid(), + kubernetesCluster.getTenantId()); URI url = uriInfo.getAbsolutePathBuilder().path(kubernetesCluster.getClusterUuid()).build(); return Response.ok(url).entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS, String.format("Kubernetes cluster updated successfully: [kub-host-cluster] %s", kubernetesCluster.getClusterUuid()))).build(); - } catch (RestAPIException e) { - throw e; + } catch (RemoteException e) { + throw new RestAPIException(e.getMessage()); } catch (CloudControllerServiceInvalidKubernetesClusterExceptionException e) { return Response.status(Response.Status.BAD_REQUEST).entity(new ResponseMessageBean( ResponseMessageBean.ERROR, "Kubernetes cluster is invalid")).build(); http://git-wip-us.apache.org/repos/asf/stratos/blob/f2080dcb/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java index d9934b3..543dd44 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java @@ -32,6 +32,7 @@ import org.apache.stratos.autoscaler.stub.pojo.ServiceGroup; import org.apache.stratos.cloud.controller.stub.*; import org.apache.stratos.cloud.controller.stub.domain.Cartridge; import org.apache.stratos.cloud.controller.stub.domain.NetworkPartition; +import org.apache.stratos.cloud.controller.stub.domain.kubernetes.KubernetesCluster; import org.apache.stratos.common.beans.IaasProviderInfoBean; import org.apache.stratos.common.beans.PropertyBean; import org.apache.stratos.common.beans.TenantInfoBean; @@ -109,6 +110,7 @@ public class StratosApiV41Utils { public static final String APPLICATION_STATUS_DEPLOYED = "Deployed"; public static final String APPLICATION_STATUS_CREATED = "Created"; public static final String APPLICATION_STATUS_UNDEPLOYING = "Undeploying"; + public static final int SUPER_TENANT_ID = -1234; private static final Log log = LogFactory.getLog(StratosApiV41Utils.class); @@ -1441,7 +1443,8 @@ public class StratosApiV41Utils { * @param tenantDomain Tenant Domain * @throws RestAPIException */ - public static void addApplication(ApplicationBean appDefinition, ConfigurationContext ctxt, String userName, + public static void addApplication(ApplicationBean appDefinition, String applicationUuid, int tenantId, + ConfigurationContext ctxt, String userName, String tenantDomain) throws RestAPIException, AutoscalerServiceCartridgeNotFoundExceptionException, AutoscalerServiceCartridgeGroupNotFoundExceptionException { @@ -1453,9 +1456,9 @@ public class StratosApiV41Utils { } // check if an application with same id already exists try { - if (AutoscalerServiceClient.getInstance().existApplication(appDefinition.getApplicationId(),appDefinition.getTenantId())) { + if (AutoscalerServiceClient.getInstance().existApplication(appDefinition.getApplicationId(), tenantId)) { String msg = String.format("Application already exists: [application-uuid] %s [application-name] %s", - appDefinition.getApplicationUuid(), appDefinition.getName()); + applicationUuid, appDefinition.getName()); throw new RestAPIException(msg); } } catch (RemoteException e) { @@ -1469,7 +1472,7 @@ public class StratosApiV41Utils { ApplicationContext applicationContext = ObjectConverter.convertApplicationDefinitionToStubApplicationContext( - appDefinition); + appDefinition, applicationUuid, tenantId); applicationContext.setTenantId(ApplicationManagementUtil.getTenantId(ctxt)); applicationContext.setTenantDomain(tenantDomain); applicationContext.setTenantAdminUsername(userName); @@ -1492,12 +1495,9 @@ public class StratosApiV41Utils { List<String> usedCartridgeGroups = new ArrayList<String>(); findCartridgesAndGroupsInApplication(appDefinition, usedCartridges, usedCartridgeGroups); StratosManagerServiceClient smServiceClient = getStratosManagerServiceClient(); - smServiceClient.addUsedCartridgesInApplications( - appDefinition.getApplicationUuid(), + smServiceClient.addUsedCartridgesInApplications(applicationUuid, usedCartridges.toArray(new String[usedCartridges.size()])); - - smServiceClient.addUsedCartridgeGroupsInApplications( - appDefinition.getApplicationUuid(), + smServiceClient.addUsedCartridgeGroupsInApplications(applicationUuid, usedCartridgeGroups.toArray(new String[usedCartridgeGroups.size()])); } catch (AutoscalerServiceApplicationDefinitionExceptionException e) { @@ -1517,11 +1517,11 @@ public class StratosApiV41Utils { * @param tenantDomain Tenant Domain * @throws RestAPIException */ - public static void updateApplication(ApplicationBean appDefinition, ConfigurationContext ctxt, - String userName, String tenantDomain) + public static void updateApplication(ApplicationBean appDefinition, String applicationUuid, int tenantId, + ConfigurationContext ctxt, String userName, String tenantDomain) throws RestAPIException, AutoscalerServiceCartridgeNotFoundExceptionException, AutoscalerServiceCartridgeGroupNotFoundExceptionException { - if (StringUtils.isBlank(appDefinition.getApplicationUuid())) { + if (StringUtils.isBlank(applicationUuid)) { String message = "Please specify the application name"; log.error(message); throw new RestAPIException(message); @@ -1530,7 +1530,7 @@ public class StratosApiV41Utils { validateApplication(appDefinition); ApplicationContext applicationContext = ObjectConverter.convertApplicationDefinitionToStubApplicationContext( - appDefinition); + appDefinition, applicationUuid, tenantId); applicationContext.setTenantId(ApplicationManagementUtil.getTenantId(ctxt)); applicationContext.setTenantDomain(tenantDomain); applicationContext.setTenantAdminUsername(userName); @@ -1889,25 +1889,26 @@ public class StratosApiV41Utils { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); AutoscalerServiceClient asServiceClient = getAutoscalerServiceClient(); - ApplicationContext asApplication = asServiceClient.getApplicationByTenant(applicationId,carbonContext.getTenantId()); + ApplicationContext asApplication = asServiceClient.getApplicationByTenant(applicationId, + carbonContext.getTenantId()); log.info(String.format("Starting to remove application: [application-uuid %s [application-id] %s", asApplication.getApplicationUuid(), applicationId)); ApplicationBean application = ObjectConverter.convertStubApplicationContextToApplicationDefinition( asApplication); - asServiceClient.deleteApplication(application.getApplicationUuid()); + asServiceClient.deleteApplication(asApplication.getApplicationUuid()); List<String> usedCartridges = new ArrayList<String>(); List<String> usedCartridgeGroups = new ArrayList<String>(); findCartridgesAndGroupsInApplication(application, usedCartridges, usedCartridgeGroups); StratosManagerServiceClient smServiceClient = getStratosManagerServiceClient(); smServiceClient.removeUsedCartridgesInApplications( - application.getApplicationUuid(), + asApplication.getApplicationUuid(), usedCartridges.toArray(new String[usedCartridges.size()])); smServiceClient.removeUsedCartridgeGroupsInApplications( - application.getApplicationUuid(), + asApplication.getApplicationUuid(), usedCartridgeGroups.toArray(new String[usedCartridgeGroups.size()])); } catch (RemoteException e) { @@ -2161,14 +2162,15 @@ public class StratosApiV41Utils { * @return add status * @throws RestAPIException */ - public static boolean addKubernetesCluster(KubernetesClusterBean kubernetesClusterBean) throws RestAPIException, + public static boolean addKubernetesCluster(KubernetesClusterBean kubernetesClusterBean, + String kubernetesClusterUuid, int tenantId) throws RestAPIException, CloudControllerServiceInvalidKubernetesClusterExceptionException, CloudControllerServiceKubernetesClusterAlreadyExistsExceptionException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { org.apache.stratos.cloud.controller.stub.domain.kubernetes.KubernetesCluster kubernetesCluster = - ObjectConverter.convertToCCKubernetesClusterPojo(kubernetesClusterBean); + ObjectConverter.convertToCCKubernetesClusterPojo(kubernetesClusterBean, kubernetesClusterUuid, tenantId); try { return cloudControllerServiceClient.deployKubernetesCluster(kubernetesCluster); @@ -2188,13 +2190,15 @@ public class StratosApiV41Utils { * @return add status * @throws RestAPIException */ - public static boolean updateKubernetesCluster(KubernetesClusterBean kubernetesClusterBean) throws RestAPIException, + public static boolean updateKubernetesCluster(KubernetesClusterBean kubernetesClusterBean, + String kubernetesClusterUuid, int tenantId) throws RestAPIException, CloudControllerServiceInvalidKubernetesClusterExceptionException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); if (cloudControllerServiceClient != null) { org.apache.stratos.cloud.controller.stub.domain.kubernetes.KubernetesCluster kubernetesCluster = - ObjectConverter.convertToCCKubernetesClusterPojo(kubernetesClusterBean); + ObjectConverter.convertToCCKubernetesClusterPojo(kubernetesClusterBean, kubernetesClusterUuid, + tenantId); try { return cloudControllerServiceClient.updateKubernetesCluster(kubernetesCluster); @@ -2313,19 +2317,16 @@ public class StratosApiV41Utils { public static KubernetesClusterBean getKubernetesCluster(String kubernetesClusterId) throws RestAPIException { CloudControllerServiceClient cloudControllerServiceClient = getCloudControllerServiceClient(); + PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); if (cloudControllerServiceClient != null) { try { - org.apache.stratos.cloud.controller.stub.domain.kubernetes.KubernetesCluster - kubernetesCluster = cloudControllerServiceClient.getKubernetesCluster(kubernetesClusterId); + KubernetesCluster kubernetesCluster = cloudControllerServiceClient.getKubernetesClusterByTenantId + (kubernetesClusterId, carbonContext.getTenantId()); return ObjectConverter.convertStubKubernetesClusterToKubernetesCluster(kubernetesCluster); } catch (RemoteException e) { log.error(e.getMessage(), e); throw new RestAPIException(e.getMessage(), e); - } catch (CloudControllerServiceNonExistingKubernetesClusterExceptionException e) { - String message = e.getFaultMessage().getNonExistingKubernetesClusterException().getMessage(); - log.error(message); - throw new RestAPIException(message, e); } } return null; @@ -2488,16 +2489,16 @@ public class StratosApiV41Utils { //multi tenant application can be added by only the super tenant.Hence passing the super tenant id to retrieve // the application - ApplicationBean applicationBean = getApplication(applicationId,-1234); - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationId, -1234); + ApplicationBean applicationBean = getApplication(applicationId, SUPER_TENANT_ID); + Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationId, SUPER_TENANT_ID); if ((applicationBean == null) || (application == null)) { throw new RestAPIException("Application not found: [application-id] " + applicationId); } if (!APPLICATION_STATUS_DEPLOYED.equals(applicationBean.getStatus())) { - throw new RestAPIException(String.format("Application has not been deployed: [application-uuid] %s " + - "[application-id] %s ", applicationBean.getApplicationUuid(), applicationId)); + throw new RestAPIException(String.format("Application has not been deployed: [application-id] %s ", + applicationId)); } if (!applicationBean.isMultiTenant()) { @@ -2510,8 +2511,7 @@ public class StratosApiV41Utils { try { if (log.isInfoEnabled()) { - log.info(String.format("Adding applicationBean signup: [application-uuid] %s [application-id] %s", - applicationBean.getApplicationUuid(), applicationId)); + log.info(String.format("Adding applicationBean signup: [application-id] %s", applicationId)); } int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -2531,19 +2531,17 @@ public class StratosApiV41Utils { serviceClient.addApplicationSignUp(applicationSignUp); if (log.isInfoEnabled()) { - log.info(String.format("Application signup added successfully: [application-uuid] %s [application-id]" + - " %s [tenant-id] %d", - applicationBean.getApplicationUuid(), applicationId, tenantId)); + log.info(String.format("Application signup added successfully: [application-id]" + + " %s [tenant-id] %d", applicationId, tenantId)); } serviceClient.notifyArtifactUpdatedEventForSignUp(applicationId, tenantId); if (log.isInfoEnabled()) { - log.info(String.format("Artifact updated event sent: [application-uuid] %s [application-id] %s " + - "[tenant-id] %d", applicationBean.getApplicationUuid(), applicationId, tenantId)); + log.info(String.format("Artifact updated event sent: [application-id] %s " + + "[tenant-id] %d", applicationId, tenantId)); } } catch (Exception e) { - String message = String.format("Error in applicationBean signup: [application-uuid] %s [application-id] " + - "%s", applicationBean.getApplicationUuid(), applicationId); + String message = String.format("Error in applicationBean signup: [application-id] %s", applicationId); log.error(message, e); throw new RestAPIException(message, e); } http://git-wip-us.apache.org/repos/asf/stratos/blob/f2080dcb/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 861fd20..f1726a1 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 @@ -939,22 +939,23 @@ public class ObjectConverter { } public static org.apache.stratos.cloud.controller.stub.domain.kubernetes.KubernetesCluster - convertToCCKubernetesClusterPojo(KubernetesClusterBean kubernetesClusterBean) throws RestAPIException { + convertToCCKubernetesClusterPojo(KubernetesClusterBean kubernetesClusterBean, String kubernetesClusterUuid, + int tenantId) throws RestAPIException { org.apache.stratos.cloud.controller.stub.domain.kubernetes.KubernetesCluster kubernetesCluster = new org.apache.stratos.cloud.controller.stub.domain.kubernetes.KubernetesCluster(); - kubernetesCluster.setClusterUuid(kubernetesClusterBean.getClusterUuid()); + kubernetesCluster.setClusterUuid(kubernetesClusterUuid); kubernetesCluster.setClusterId(kubernetesClusterBean.getClusterId()); kubernetesCluster.setDescription(kubernetesClusterBean.getDescription()); kubernetesCluster.setKubernetesMaster(convertStubKubernetesMasterToKubernetesMaster( - kubernetesClusterBean.getKubernetesMaster(),kubernetesClusterBean.getTenantId())); + kubernetesClusterBean.getKubernetesMaster(), tenantId)); kubernetesCluster.setPortRange(convertPortRangeToStubPortRange(kubernetesClusterBean.getPortRange())); kubernetesCluster.setKubernetesHosts(convertToASKubernetesHostsPojo(kubernetesClusterBean.getKubernetesHosts(), - kubernetesClusterBean.getTenantId())); + tenantId)); kubernetesCluster.setProperties((convertPropertyBeansToCCStubProperties(kubernetesClusterBean.getProperty(), - kubernetesClusterBean.getTenantId()))); - kubernetesCluster.setTenantId(kubernetesClusterBean.getTenantId()); + tenantId))); + kubernetesCluster.setTenantId(tenantId); return kubernetesCluster; } @@ -1045,7 +1046,7 @@ public class ObjectConverter { return null; } KubernetesClusterBean kubernetesClusterBean = new KubernetesClusterBean(); - kubernetesClusterBean.setClusterUuid(kubernetesCluster.getClusterId()); + kubernetesClusterBean.setClusterId(kubernetesCluster.getClusterId()); kubernetesClusterBean.setDescription(kubernetesCluster.getDescription()); kubernetesClusterBean.setPortRange(convertStubPortRangeToPortRange(kubernetesCluster.getPortRange())); kubernetesClusterBean.setKubernetesHosts(convertStubKubernetesHostsToKubernetesHosts(kubernetesCluster.getKubernetesHosts())); @@ -1132,18 +1133,18 @@ public class ObjectConverter { } public static ApplicationContext convertApplicationDefinitionToStubApplicationContext( - ApplicationBean applicationDefinition) throws RestAPIException { + ApplicationBean applicationDefinition, String applicationUuid, int tenantId) throws RestAPIException { org.apache.stratos.autoscaler.stub.pojo.ApplicationContext applicationContext = new org.apache.stratos.autoscaler.stub.pojo.ApplicationContext(); - applicationContext.setApplicationUuid(applicationDefinition.getApplicationUuid()); + applicationContext.setApplicationUuid(applicationUuid); applicationContext.setApplicationId(applicationDefinition.getApplicationId()); applicationContext.setAlias(applicationDefinition.getAlias()); applicationContext.setMultiTenant(applicationDefinition.isMultiTenant()); applicationContext.setName(applicationDefinition.getName()); applicationContext.setDescription(applicationDefinition.getDescription()); applicationContext.setStatus(applicationDefinition.getStatus()); - applicationContext.setTenantId(applicationDefinition.getTenantId()); + applicationContext.setTenantId(tenantId); // convert and set components if (applicationDefinition.getComponents() != null) { @@ -1154,7 +1155,7 @@ public class ObjectConverter { if (applicationDefinition.getComponents().getGroups() != null) { componentContext.setGroupContexts( convertGroupDefinitionsToStubGroupContexts(applicationDefinition.getComponents().getGroups(), - applicationDefinition.getTenantId())); + tenantId)); } // top level dependency information if (applicationDefinition.getComponents().getDependencies() != null) { @@ -1164,7 +1165,7 @@ public class ObjectConverter { // top level cartridge context information if (applicationDefinition.getComponents().getCartridges() != null) { componentContext.setCartridgeContexts(convertCartridgeReferenceBeansToStubCartridgeContexts - (applicationDefinition.getComponents().getCartridges(), applicationDefinition.getTenantId())); + (applicationDefinition.getComponents().getCartridges(), tenantId)); } applicationContext.setComponents(componentContext); } @@ -1178,14 +1179,12 @@ public class ObjectConverter { } ApplicationBean applicationDefinition = new ApplicationBean(); - applicationDefinition.setApplicationUuid(applicationContext.getApplicationUuid()); applicationDefinition.setApplicationId(applicationContext.getApplicationId()); applicationDefinition.setAlias(applicationContext.getAlias()); applicationDefinition.setMultiTenant(applicationContext.getMultiTenant()); applicationDefinition.setName(applicationContext.getName()); applicationDefinition.setDescription(applicationContext.getDescription()); applicationDefinition.setStatus(applicationContext.getStatus()); - applicationDefinition.setApplicationUuid(applicationContext.getApplicationUuid()); // convert and set components if (applicationContext.getComponents() != null) { applicationDefinition.setComponents(new ComponentBean()); @@ -1536,7 +1535,6 @@ public class ObjectConverter { return prop; } - private static DependencyContext convertDependencyDefinitionsToDependencyContexts(DependencyBean dependencyBean) { if (dependencyBean == null) { return null; @@ -1734,8 +1732,8 @@ public class ObjectConverter { } ApplicationInfoBean applicationBean = new ApplicationInfoBean(); - applicationBean.setId(application.getUniqueIdentifier()); - applicationBean.setName(application.getId()); + applicationBean.setId(application.getId()); + applicationBean.setName(application.getName()); applicationBean.setStatus(application.getStatus().name()); applicationBean.setDescription(application.getDescription()); applicationBean.setTenantDomain(application.getTenantDomain());
