You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ud...@apache.org on 2015/02/23 09:00:41 UTC

stratos git commit: metadata service add super admin flow when doing registry operations.

Repository: stratos
Updated Branches:
  refs/heads/master 0e177fe6d -> 0f1f85812


metadata service add super admin flow when doing registry operations.


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/0f1f8581
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/0f1f8581
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/0f1f8581

Branch: refs/heads/master
Commit: 0f1f85812dfd5af0b9a2a24fedbe38a864d1014c
Parents: 0e177fe
Author: Udara Liyanage <ud...@wso2.com>
Authored: Mon Feb 23 13:27:52 2015 +0530
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Mon Feb 23 13:30:06 2015 +0530

----------------------------------------------------------------------
 .../service/registry/CarbonRegistry.java        | 104 ++++++++++++++-----
 .../service/services/MetaDataAdmin.java         |   4 +
 .../src/main/extensions/payload/launch-params   |   2 +
 3 files changed, 82 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/0f1f8581/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
index 836520a..aaef6ea 100644
--- 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
@@ -21,11 +21,13 @@ 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.manager.internal.ServiceReferenceHolder;
 import org.apache.stratos.metadata.service.definition.NewProperty;
-import org.wso2.carbon.registry.api.Registry;
-import org.wso2.carbon.registry.api.RegistryException;
-import org.wso2.carbon.registry.api.Resource;
+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;
@@ -34,7 +36,6 @@ import java.util.*;
 
 /**
  * Carbon registry implementation
- *
  */
 
 public class CarbonRegistry implements DataStore {
@@ -43,7 +44,7 @@ public class CarbonRegistry implements DataStore {
     @Context
     HttpServletRequest httpServletRequest;
 
-    private static final String mainResource = "/stratos/";
+    private static final String mainResource = "metadata/";
 
     public CarbonRegistry() {
     }
@@ -51,18 +52,26 @@ public class CarbonRegistry implements DataStore {
 
     /**
      * Get Properties of clustor
+     *
      * @param applicationName
      * @param clusterId
      * @return
      * @throws RegistryException
      */
     public List<NewProperty> getPropertiesOfCluster(String applicationName, String clusterId) throws RegistryException {
-        Registry tempRegistry = ServiceReferenceHolder.getInstance().getRegistryService().getRegistry();
+        Registry tempRegistry = getRegistry();
         String resourcePath = mainResource + applicationName + "/" + clusterId;
+
+
         if (!tempRegistry.resourceExists(resourcePath)) {
             return null;
             //throw new RegistryException("Cluster does not exist at " + resourcePath);
         }
+
+        PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+        ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+        ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
         Resource regResource = tempRegistry.get(resourcePath);
 
         ArrayList<NewProperty> newProperties = new ArrayList<NewProperty>();
@@ -85,67 +94,105 @@ public class CarbonRegistry implements DataStore {
 
     /**
      * Add property to cluster
+     *
      * @param applicationId
      * @param clusterId
      * @param property
      * @throws RegistryException
      */
     public void addPropertyToCluster(String applicationId, String clusterId, NewProperty property) throws RegistryException {
-        Registry tempRegistry = ServiceReferenceHolder.getInstance().getRegistryService().getRegistry();
+        Registry registry = getRegistry();
         String resourcePath = mainResource + applicationId + "/" + clusterId;
-        Resource regResource = createOrGetResourceforCluster(tempRegistry, resourcePath);
 
-        regResource.setProperty(property.getKey(), Arrays.asList(property.getValues()));
-        tempRegistry.put(resourcePath, regResource);
-        log.info(String.format("Property %s is added to cluster %s of application %s", property.getKey(), clusterId, applicationId));
+        try {
+            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.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);
+
+            registry.commitTransaction();
+
+            log.info(String.format("Registry property is persisted: [resource-path] %s [Property Name] %s [Property Values] %s",
+                    resourcePath, property.getKey(), Arrays.asList(property.getValues())));
+
+        } catch (Exception e) {
+            String msg = "Failed to persist properties in registry: " + resourcePath;
+            registry.rollbackTransaction();
+            log.error(msg, e);
+            throw new RegistryException(msg, e);
+        }
+
+    }
 
+    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 deleteApplication(String applicationId) throws RegistryException {
-        if(StringUtils.isBlank(applicationId)){
+        if (StringUtils.isBlank(applicationId)) {
             throw new IllegalArgumentException("Application ID can not be null");
         }
-        Registry tempRegistry = ServiceReferenceHolder.getInstance().getRegistryService().getRegistry();
-        String resourcePath = mainResource + applicationId;
 
-        if(tempRegistry.resourceExists(resourcePath)){
-            tempRegistry.delete(resourcePath);
-            log.info(String.format("Application removed from registry %s", applicationId));
-            return true;
-        }
+        PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+        ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+        ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
 
+        Registry registry = null;
+        String resourcePath = mainResource + applicationId;
+        try {
+            registry = getRegistry();
+            registry.beginTransaction();
+            if (registry.resourceExists(resourcePath)) {
+                registry.delete(resourcePath);
+                registry.commitTransaction();
+                log.info(String.format("Application removed from registry %s", applicationId));
+                return true;
+            }
+        } catch (RegistryException e) {
+            registry.rollbackTransaction();
+            log.error("Could not remove registry resource: [resource-path] " + resourcePath);
+        }
         return false;
     }
 
     /**
      * Add properties to cluster
+     *
      * @param applicationName
      * @param clusterId
      * @param properties
      * @throws RegistryException
      */
     public void addPropertiesToCluster(String applicationName, String clusterId, NewProperty[] properties) throws RegistryException {
-        Registry tempRegistry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry();
-        String resourcePath = mainResource + applicationName + "/" + clusterId;
-        Resource regResource;
-        regResource = createOrGetResourceforCluster(tempRegistry, resourcePath);
-
         for (NewProperty property : properties) {
-            regResource.setProperty(property.getKey(), (Arrays.asList(property.getValues())));
+            this.addPropertyToCluster(applicationName, clusterId, property);
 
         }
-        tempRegistry.put(resourcePath, regResource);
-        log.info(String.format("Properties  are added to cluster %s of application %s", clusterId, applicationName));
     }
 
     /**
      * Create or get resource for application
+     *
      * @param tempRegistry
      * @param resourcePath
      * @return
@@ -166,6 +213,7 @@ public class CarbonRegistry implements DataStore {
 
     /**
      * Create and get resources for Clustor
+     *
      * @param tempRegistry
      * @param resourcePath
      * @return

http://git-wip-us.apache.org/repos/asf/stratos/blob/0f1f8581/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java
index 9b8ce94..0a73b0a 100644
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java
@@ -19,6 +19,7 @@
 package org.apache.stratos.metadata.service.services;
 
 import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.metadata.service.annotation.AuthorizationAction;
@@ -135,6 +136,9 @@ public class MetaDataAdmin {
             throws RestAPIException {
 
         URI url =  uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + clusterId + "/" + property.getKey()).build();
+        if(StringUtils.isEmpty(property.getKey())){
+            throw new RestAPIException("Property key can not be empty");
+        }
 
 	    try {
 		    registry.addPropertyToCluster(applicationId, clusterId, property);

http://git-wip-us.apache.org/repos/asf/stratos/blob/0f1f8581/products/cartridge-agent/modules/distribution/src/main/extensions/payload/launch-params
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/src/main/extensions/payload/launch-params b/products/cartridge-agent/modules/distribution/src/main/extensions/payload/launch-params
new file mode 100644
index 0000000..165c634
--- /dev/null
+++ b/products/cartridge-agent/modules/distribution/src/main/extensions/payload/launch-params
@@ -0,0 +1,2 @@
+APPLICATION_ID=single-cartridge-app,GROUP_NAME=null,SERVICE_NAME=tomcat,HOST_NAME=tomcat1.tomcat.stratos.org,MULTITENANT=false,TENANT_ID=-1234,TENANT_RANGE=*,CARTRIDGE_ALIAS=tomcat1,CLUSTER_ID=tomcat1.tomcat.domain,CARTRIDGE_KEY=U4OYk2Pnu09TK34x,DEPLOYMENT=default,REPO_URL=https://github.com/imesh/stratos-php-applications.git,PORTS=22,PROVIDER=apache,PUPPET_IP=192.168.30.90,PUPPET_HOSTNAME=puppet.stratostest.org,PUPPET_DNS_AVAILABLE=null,PUPPET_ENV=false,,,DEPENDENCY_CLUSTER_IDS=,EXPORT_METADATA_KEYS=,IMPORT_METADATA_KEYS=,TOKEN=eyJhbGciOiJSUzI1NiJ9.eyJleHAiOi0xNjc2MzY4MDM0LCJzdWIiOiJhZG1pbiIsImF6cCI6IkZaRElJMFhxN0hBZ1YzRzJmb2FUNDNrRUFUSWEiLCJhcHBJZCI6InNpbmdsZS1jYXJ0cmlkZ2UtYXBwIiwiYXVkIjpbIkZaRElJMFhxN0hBZ1YzRzJmb2FUNDNrRUFUSWEiXSwiaXNzIjoiaHR0cHM6XC9cL2xvY2FsaG9zdDo5NDQzXC9vYXV0aDJlbmRwb2ludHNcL3Rva2VuIiwiaWF0IjotMTY3NjM2NzAzM30.PM26FJN3Bm6v92o_4pu_TaMXhgxZYjdkAM9BZbz1iEcOMNkO1KYTQkEAJeTmelGZAsJn_gcj7M18-C9pI1GIulM0sMJKXsH9is-BqLLTn3PGdzhjOrXOmvh95Trk2wY3cW50Hf52hrlHgAZoqWN_C1n6j
 ZPwboyI40A1aPatKuc,MEMBER_ID=tomcat1.tomcat.domain54e2ebf4-ded5-4892-ada3-61a14a6c59ab,INSTANCE_ID=null,CLUSTER_INSTANCE_ID=single-cartridge-app-1,LB_CLUSTER_ID=null,NETWORK_PARTITION_ID=network-partition-1,PARTITION_ID=partition-1,INTERNAL=false,PRIMARY=false,MIN_COUNT=1
+