You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/09/09 20:44:22 UTC
[1/2] stratos git commit: Fixing string formatting issue in log
messages in kubernetes iaas
Repository: stratos
Updated Branches:
refs/heads/stratos-4.1.x 3af354cf0 -> 597437184
Fixing string formatting issue in log messages in kubernetes iaas
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/a29d4586
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/a29d4586
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/a29d4586
Branch: refs/heads/stratos-4.1.x
Commit: a29d4586d50b4c623a2164c359e12f769de95525
Parents: 3af354c
Author: Imesh Gunaratne <im...@apache.org>
Authored: Thu Sep 10 00:08:27 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Thu Sep 10 00:08:27 2015 +0530
----------------------------------------------------------------------
.../cloud/controller/iaases/kubernetes/KubernetesIaas.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/a29d4586/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
index 8d81ceb..eb78404 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
@@ -233,7 +233,7 @@ public class KubernetesIaas extends Iaas {
updateMemberContext(memberContext, pod, kubernetesCluster);
log.info(String.format("Container started successfully: [application] %s [cartridge] %s [member] %s " +
- "[pod] %s [cpu] %d [memory] %d MB",
+ "[pod] %s [cpu] %s [memory] %s",
memberContext.getApplicationId(), memberContext.getCartridgeType(),
memberContext.getMemberId(), memberContext.getKubernetesPodId(),
memberContext.getInstanceMetadata().getCpu(), memberContext.getInstanceMetadata().getRam()));
@@ -416,14 +416,14 @@ public class KubernetesIaas extends Iaas {
List<ContainerPort> ports = KubernetesIaasUtil.convertPortMappings(Arrays.asList(cartridge.getPortMappings()));
log.info(String.format("Starting pod: [application] %s [cartridge] %s [member] %s " +
- "[cpu] %d [memory] %d MB",
+ "[cpu] %s [memory] %s",
memberContext.getApplicationId(), memberContext.getCartridgeType(),
memberContext.getMemberId(), cpu, memory));
kubernetesApi.createPod(podId, podLabel, dockerImage, cpu, memory, ports, environmentVariables);
log.info(String.format("Pod started successfully: [application] %s [cartridge] %s [member] %s " +
- "[pod] %s [pod-label] %s [cpu] %d [memory] %d MB",
+ "[pod] %s [pod-label] %s [cpu] %s [memory] %s",
memberContext.getApplicationId(), memberContext.getCartridgeType(),
memberContext.getMemberId(), podId, podLabel, cpu, memory));
[2/2] stratos git commit: Adding logic to clear application metadata
when undeploying an application
Posted by im...@apache.org.
Adding logic to clear application metadata when undeploying an application
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/59743718
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/59743718
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/59743718
Branch: refs/heads/stratos-4.1.x
Commit: 597437184ab50b24eab7caf027db3147bf4cb617
Parents: a29d458
Author: Imesh Gunaratne <im...@apache.org>
Authored: Thu Sep 10 00:14:09 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Thu Sep 10 00:14:09 2015 +0530
----------------------------------------------------------------------
.../metadata/service/api/MetadataApi.java | 4 +-
.../service/registry/CarbonRegistry.java | 307 -------------------
.../metadata/service/registry/DataStore.java | 2 -
.../service/registry/MetadataApiRegistry.java | 307 +++++++++++++++++++
.../rest/endpoint/api/StratosApiV41Utils.java | 35 +++
5 files changed, 344 insertions(+), 311 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/59743718/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
index 48f369b..712bcaa 100644
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
@@ -22,7 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.metadata.service.definition.Property;
import org.apache.stratos.metadata.service.exception.RestAPIException;
-import org.apache.stratos.metadata.service.registry.CarbonRegistry;
+import org.apache.stratos.metadata.service.registry.MetadataApiRegistry;
import org.apache.stratos.metadata.service.registry.DataStore;
import org.wso2.carbon.registry.api.RegistryException;
@@ -44,7 +44,7 @@ public class MetadataApi {
* Meta data admin configuration loading
*/
public MetadataApi() {
- registry = new CarbonRegistry();
+ registry = new MetadataApiRegistry();
}
@GET
http://git-wip-us.apache.org/repos/asf/stratos/blob/59743718/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java
deleted file mode 100644
index f2dd846..0000000
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java
+++ /dev/null
@@ -1,307 +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.metadata.service.registry;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.metadata.service.definition.Property;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.registry.core.Registry;
-import org.wso2.carbon.registry.core.Resource;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.session.UserRegistry;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Context;
-import java.util.*;
-
-
-/**
- * Carbon registry implementation
- */
-
-public class CarbonRegistry implements DataStore {
-
- private static final String mainResource = "metadata/";
- private static Log log = LogFactory.getLog(CarbonRegistry.class);
- @Context
- HttpServletRequest httpServletRequest;
-
- public CarbonRegistry() {
- }
-
- public List<Property> getApplicationProperties(String applicationName) throws RegistryException {
- Registry tempRegistry = getRegistry();
- String resourcePath = mainResource + applicationName;
-
- if (!tempRegistry.resourceExists(resourcePath)) {
- return null;
- }
- // We are using only super tenant registry to persist
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
- ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
-
- Resource regResource = tempRegistry.get(resourcePath);
- ArrayList<Property> newProperties = new ArrayList<Property>();
-
- Properties props = regResource.getProperties();
- Enumeration<?> x = props.propertyNames();
- while (x.hasMoreElements()) {
- String key = (String) x.nextElement();
- List<String> values = regResource.getPropertyValues(key);
- Property property = new Property();
- property.setKey(key);
- String[] valueArr = new String[values.size()];
- property.setValues(values.toArray(valueArr));
-
- newProperties.add(property);
- }
- return newProperties;
- }
-
- /**
- * Get Properties of clustor
- *
- * @param applicationName
- * @param clusterId
- * @return
- * @throws RegistryException
- */
- public List<Property> getClusterProperties(String applicationName, String clusterId) throws RegistryException {
- Registry tempRegistry = getRegistry();
- String resourcePath = mainResource + applicationName + "/" + clusterId;
-
-
- if (!tempRegistry.resourceExists(resourcePath)) {
- return null;
- }
-
- // We are using only super tenant registry to persist
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
- ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
-
- Resource regResource = tempRegistry.get(resourcePath);
-
- ArrayList<Property> newProperties = new ArrayList<Property>();
-
- Properties props = regResource.getProperties();
- Enumeration<?> x = props.propertyNames();
- while (x.hasMoreElements()) {
- String key = (String) x.nextElement();
- List<String> values = regResource.getPropertyValues(key);
- Property property = new Property();
- property.setKey(key);
- String[] valueArr = new String[values.size()];
- property.setValues(values.toArray(valueArr));
-
- newProperties.add(property);
- }
-
- return newProperties;
- }
-
- public void addPropertyToApplication(String applicationId, Property property) throws RegistryException {
- Registry registry = getRegistry();
- String resourcePath = mainResource + applicationId;
-
- try {
- // We are using only super tenant registry to persist
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
- ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
-
- //registry.beginTransaction();
- Resource nodeResource = null;
- if (registry.resourceExists(resourcePath)) {
- nodeResource = registry.get(resourcePath);
- } else {
- nodeResource = registry.newCollection();
- if (log.isDebugEnabled()) {
- log.debug("Registry resource is create at path for application: " + nodeResource.getPath());
- }
- }
-
- boolean updated = false;
- for (String value : property.getValues()) {
- if (!propertyValueExist(nodeResource, property.getKey(), value)) {
- updated = true;
- log.info(String.format("Registry property is added: [resource-path] %s " +
- "[Property Name] %s [Property Value] %s",
- resourcePath, property.getKey(), value));
- nodeResource.addProperty(property.getKey(), value);
- } else {
- log.info(String.format("Property value already exist property=%s value=%s", property.getKey(), value));
- }
- }
-
- if (updated) {
- registry.put(resourcePath, nodeResource);
- }
- //registry.commitTransaction();
- } catch (Exception e) {
- String msg = "Failed to persist properties in registry: " + resourcePath;
- //registry.rollbackTransaction();
- log.error(msg, e);
- throw new RegistryException(msg, e);
- }
- }
-
- private boolean propertyValueExist(Resource nodeResource, String key, String value) {
- List<String> properties = nodeResource.getPropertyValues(key);
- if (properties == null) {
- return false;
- } else {
- return properties.contains(value);
- }
-
- }
-
- public boolean removePropertyValueFromApplication(String applicationId, String propertyName, String valueToRemove)
- throws RegistryException {
- Registry registry = getRegistry();
- String resourcePath = mainResource + applicationId;
-
- // We are using only super tenant registry to persist
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
- ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
-
- registry.beginTransaction();
- Resource nodeResource;
- if (registry.resourceExists(resourcePath)) {
- nodeResource = registry.get(resourcePath);
- } else {
- log.warn(String.format("Registry [resource] %s not found ", resourcePath));
- return false;
- }
- nodeResource.removePropertyValue(propertyName, valueToRemove);
- registry.put(resourcePath, nodeResource);
- registry.commitTransaction();
-
- log.info(String.format("Application %s property %s value %s is removed from metadata ",
- applicationId, propertyName, valueToRemove));
-
- return true;
- }
-
- /**
- * Add property to cluster
- *
- * @param applicationId
- * @param clusterId
- * @param property
- * @throws RegistryException
- */
- public void addPropertyToCluster(String applicationId, String clusterId, Property property) throws RegistryException {
- Registry registry = getRegistry();
- String resourcePath = mainResource + applicationId + "/" + clusterId;
-
- // We are using only super tenant registry to persist
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
- ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
-
- Resource nodeResource = null;
- if (registry.resourceExists(resourcePath)) {
- nodeResource = registry.get(resourcePath);
- } else {
- nodeResource = registry.newResource();
- if (log.isDebugEnabled()) {
- log.debug("Registry resource is create at path for cluster" + nodeResource.getPath() + " for cluster");
- }
- }
-
- nodeResource.setProperty(property.getKey(), Arrays.asList(property.getValues()));
- registry.put(resourcePath, nodeResource);
-
- log.info(String.format("Registry property is persisted: [resource-path] %s [Property Name] %s [Property Values] %s",
- resourcePath, property.getKey(), Arrays.asList(property.getValues())));
- }
-
- private UserRegistry getRegistry() throws RegistryException {
- return org.apache.stratos.common.internal.ServiceReferenceHolder.getInstance().
- getRegistryService().getGovernanceSystemRegistry();
- }
-
- /**
- * Delete the resource identified by the applicationId, if exist.
- *
- * @param applicationId ID of the application.
- * @return True if resource exist and able to delete, else false.
- * @throws RegistryException
- */
- public boolean deleteApplicationProperties(String applicationId) throws RegistryException {
- if (StringUtils.isBlank(applicationId)) {
- throw new IllegalArgumentException("Application ID can not be null");
- }
-
- // We are using only super tenant registry to persist
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
- ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
-
- Registry registry;
- String resourcePath = mainResource + applicationId;
- registry = getRegistry();
- registry.beginTransaction();
- if (registry.resourceExists(resourcePath)) {
- registry.delete(resourcePath);
- registry.commitTransaction();
- log.info(String.format("Application [application-id ] properties removed from registry %s", applicationId));
- return true;
- }
-
- return false;
- }
-
- public boolean removePropertyFromApplication(String applicationId, String propertyName)
- throws org.wso2.carbon.registry.api.RegistryException {
- Registry registry = getRegistry();
- String resourcePath = mainResource + applicationId;
- // We are using only super tenant registry to persist
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
- ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
-
- Resource nodeResource;
- if (registry.resourceExists(resourcePath)) {
- nodeResource = registry.get(resourcePath);
- if (nodeResource.getProperty(propertyName) == null) {
- log.info(String.format("[application-id] %s does not have a property [property-name] %s ", applicationId,
- propertyName));
- return false;
- } else {
- nodeResource.removeProperty(propertyName);
- registry.put(resourcePath, nodeResource);
- }
- } else {
- log.error("Registry resource not not found at " + resourcePath);
- return false;
- }
-
- log.info(String.format("Application [application-id] %s property [property-name] %s removed from Registry ",
- applicationId, propertyName));
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/59743718/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
index c11a2b9..a6415bd 100644
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
@@ -43,6 +43,4 @@ public interface DataStore {
public boolean removePropertyFromApplication(String applicationId, String propertyName) throws RegistryException;
public boolean removePropertyValueFromApplication(String applicationId, String propertyName, String valueToRemove) throws RegistryException;
-
-
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/59743718/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java
new file mode 100644
index 0000000..8cd9cb6
--- /dev/null
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java
@@ -0,0 +1,307 @@
+/*
+ * 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.metadata.service.registry;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.metadata.service.definition.Property;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.registry.core.Registry;
+import org.wso2.carbon.registry.core.Resource;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import java.util.*;
+
+
+/**
+ * Carbon registry implementation
+ */
+
+public class MetadataApiRegistry implements DataStore {
+
+ private static final String mainResource = "metadata/";
+ private static Log log = LogFactory.getLog(MetadataApiRegistry.class);
+ @Context
+ HttpServletRequest httpServletRequest;
+
+ public MetadataApiRegistry() {
+ }
+
+ public List<Property> getApplicationProperties(String applicationName) throws RegistryException {
+ Registry tempRegistry = getRegistry();
+ String resourcePath = mainResource + applicationName;
+
+ if (!tempRegistry.resourceExists(resourcePath)) {
+ return null;
+ }
+ // We are using only super tenant registry to persist
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ Resource regResource = tempRegistry.get(resourcePath);
+ ArrayList<Property> newProperties = new ArrayList<Property>();
+
+ Properties props = regResource.getProperties();
+ Enumeration<?> x = props.propertyNames();
+ while (x.hasMoreElements()) {
+ String key = (String) x.nextElement();
+ List<String> values = regResource.getPropertyValues(key);
+ Property property = new Property();
+ property.setKey(key);
+ String[] valueArr = new String[values.size()];
+ property.setValues(values.toArray(valueArr));
+
+ newProperties.add(property);
+ }
+ return newProperties;
+ }
+
+ /**
+ * Get Properties of clustor
+ *
+ * @param applicationName
+ * @param clusterId
+ * @return
+ * @throws RegistryException
+ */
+ public List<Property> getClusterProperties(String applicationName, String clusterId) throws RegistryException {
+ Registry tempRegistry = getRegistry();
+ String resourcePath = mainResource + applicationName + "/" + clusterId;
+
+
+ if (!tempRegistry.resourceExists(resourcePath)) {
+ return null;
+ }
+
+ // We are using only super tenant registry to persist
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ Resource regResource = tempRegistry.get(resourcePath);
+
+ ArrayList<Property> newProperties = new ArrayList<Property>();
+
+ Properties props = regResource.getProperties();
+ Enumeration<?> x = props.propertyNames();
+ while (x.hasMoreElements()) {
+ String key = (String) x.nextElement();
+ List<String> values = regResource.getPropertyValues(key);
+ Property property = new Property();
+ property.setKey(key);
+ String[] valueArr = new String[values.size()];
+ property.setValues(values.toArray(valueArr));
+
+ newProperties.add(property);
+ }
+
+ return newProperties;
+ }
+
+ public void addPropertyToApplication(String applicationId, Property property) throws RegistryException {
+ Registry registry = getRegistry();
+ String resourcePath = mainResource + applicationId;
+
+ try {
+ // We are using only super tenant registry to persist
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ //registry.beginTransaction();
+ Resource nodeResource = null;
+ if (registry.resourceExists(resourcePath)) {
+ nodeResource = registry.get(resourcePath);
+ } else {
+ nodeResource = registry.newCollection();
+ if (log.isDebugEnabled()) {
+ log.debug("Registry resource is create at path for application: " + nodeResource.getPath());
+ }
+ }
+
+ boolean updated = false;
+ for (String value : property.getValues()) {
+ if (!propertyValueExist(nodeResource, property.getKey(), value)) {
+ updated = true;
+ log.info(String.format("Registry property is added: [resource-path] %s " +
+ "[Property Name] %s [Property Value] %s",
+ resourcePath, property.getKey(), value));
+ nodeResource.addProperty(property.getKey(), value);
+ } else {
+ log.info(String.format("Property value already exist property=%s value=%s", property.getKey(), value));
+ }
+ }
+
+ if (updated) {
+ registry.put(resourcePath, nodeResource);
+ }
+ //registry.commitTransaction();
+ } catch (Exception e) {
+ String msg = "Failed to persist properties in registry: " + resourcePath;
+ //registry.rollbackTransaction();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ private boolean propertyValueExist(Resource nodeResource, String key, String value) {
+ List<String> properties = nodeResource.getPropertyValues(key);
+ if (properties == null) {
+ return false;
+ } else {
+ return properties.contains(value);
+ }
+
+ }
+
+ public boolean removePropertyValueFromApplication(String applicationId, String propertyName, String valueToRemove)
+ throws RegistryException {
+ Registry registry = getRegistry();
+ String resourcePath = mainResource + applicationId;
+
+ // We are using only super tenant registry to persist
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ registry.beginTransaction();
+ Resource nodeResource;
+ if (registry.resourceExists(resourcePath)) {
+ nodeResource = registry.get(resourcePath);
+ } else {
+ log.warn(String.format("Registry [resource] %s not found ", resourcePath));
+ return false;
+ }
+ nodeResource.removePropertyValue(propertyName, valueToRemove);
+ registry.put(resourcePath, nodeResource);
+ registry.commitTransaction();
+
+ log.info(String.format("Application %s property %s value %s is removed from metadata ",
+ applicationId, propertyName, valueToRemove));
+
+ return true;
+ }
+
+ /**
+ * Add property to cluster
+ *
+ * @param applicationId
+ * @param clusterId
+ * @param property
+ * @throws RegistryException
+ */
+ public void addPropertyToCluster(String applicationId, String clusterId, Property property) throws RegistryException {
+ Registry registry = getRegistry();
+ String resourcePath = mainResource + applicationId + "/" + clusterId;
+
+ // We are using only super tenant registry to persist
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ Resource nodeResource = null;
+ if (registry.resourceExists(resourcePath)) {
+ nodeResource = registry.get(resourcePath);
+ } else {
+ nodeResource = registry.newResource();
+ if (log.isDebugEnabled()) {
+ log.debug("Registry resource is create at path for cluster" + nodeResource.getPath() + " for cluster");
+ }
+ }
+
+ nodeResource.setProperty(property.getKey(), Arrays.asList(property.getValues()));
+ registry.put(resourcePath, nodeResource);
+
+ log.info(String.format("Registry property is persisted: [resource-path] %s [Property Name] %s [Property Values] %s",
+ resourcePath, property.getKey(), Arrays.asList(property.getValues())));
+ }
+
+ private UserRegistry getRegistry() throws RegistryException {
+ return org.apache.stratos.common.internal.ServiceReferenceHolder.getInstance().
+ getRegistryService().getGovernanceSystemRegistry();
+ }
+
+ /**
+ * Delete the resource identified by the applicationId, if exist.
+ *
+ * @param applicationId ID of the application.
+ * @return True if resource exist and able to delete, else false.
+ * @throws RegistryException
+ */
+ public boolean deleteApplicationProperties(String applicationId) throws RegistryException {
+ if (StringUtils.isBlank(applicationId)) {
+ throw new IllegalArgumentException("Application ID can not be null");
+ }
+
+ // We are using only super tenant registry to persist
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ Registry registry;
+ String resourcePath = mainResource + applicationId;
+ registry = getRegistry();
+ registry.beginTransaction();
+ if (registry.resourceExists(resourcePath)) {
+ registry.delete(resourcePath);
+ registry.commitTransaction();
+ log.info(String.format("Application [application-id ] properties removed from registry %s", applicationId));
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean removePropertyFromApplication(String applicationId, String propertyName)
+ throws org.wso2.carbon.registry.api.RegistryException {
+ Registry registry = getRegistry();
+ String resourcePath = mainResource + applicationId;
+ // We are using only super tenant registry to persist
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ Resource nodeResource;
+ if (registry.resourceExists(resourcePath)) {
+ nodeResource = registry.get(resourcePath);
+ if (nodeResource.getProperty(propertyName) == null) {
+ log.info(String.format("[application-id] %s does not have a property [property-name] %s ", applicationId,
+ propertyName));
+ return false;
+ } else {
+ nodeResource.removeProperty(propertyName);
+ registry.put(resourcePath, nodeResource);
+ }
+ } else {
+ log.error("Registry resource not not found at " + resourcePath);
+ return false;
+ }
+
+ log.info(String.format("Application [application-id] %s property [property-name] %s removed from Registry ",
+ applicationId, propertyName));
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/59743718/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 b584cfe..baff88d 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
@@ -81,6 +81,7 @@ import org.apache.stratos.rest.endpoint.util.converter.ObjectConverter;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.RegistryType;
+import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.session.UserRegistry;
import org.wso2.carbon.stratos.common.exception.StratosException;
@@ -107,6 +108,9 @@ public class StratosApiV41Utils {
public static final String APPLICATION_STATUS_UNDEPLOYING = "Undeploying";
public static final String KUBERNETES_IAAS_PROVIDER = "kubernetes";
+ private static final String METADATA_REG_PATH = "metadata/";
+
+
/**
* Add New Cartridge
*
@@ -1896,6 +1900,14 @@ public class StratosApiV41Utils {
if (autoscalerServiceClient != null) {
try {
autoscalerServiceClient.undeployApplication(applicationId, force);
+
+ try {
+ clearMetadata(applicationId);
+ } catch (RegistryException e) {
+ String message = "Could not remove application metadata: [application-id] " + applicationId;
+ log.error(message, e);
+ throw new RestAPIException(message, e);
+ }
} catch (RemoteException e) {
String message = "Could not undeploy application: [application-id] " + applicationId;
log.error(message, e);
@@ -1908,6 +1920,29 @@ public class StratosApiV41Utils {
}
}
+ private static void clearMetadata(String applicationId) throws RegistryException {
+
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ String resourcePath = METADATA_REG_PATH + applicationId;
+ Registry registry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext()
+ .getRegistry(RegistryType.SYSTEM_GOVERNANCE);
+ try {
+ registry.beginTransaction();
+ if (registry.resourceExists(resourcePath)) {
+ registry.delete(resourcePath);
+ registry.commitTransaction();
+ log.info(String.format("Application metadata removed: [application-id] %s", applicationId));
+ }
+ } catch (RegistryException e) {
+ registry.rollbackTransaction();
+ throw e;
+ }
+ }
+
+
/**
* Get Application Runtime
*