Repository: stratos
Updated Branches:
  refs/heads/stratos-4.1.x b1c70bedc -> 62b8d38c9


Fix metadata test case, refactor logs in metadata api


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

Branch: refs/heads/stratos-4.1.x
Commit: 62b8d38c93ab00e3b1421f2c0003608ba610f81d
Parents: b1c70be
Author: Akila Perera <[email protected]>
Authored: Tue Nov 24 21:54:04 2015 +0530
Committer: Akila Perera <[email protected]>
Committed: Tue Nov 24 21:54:44 2015 +0530

----------------------------------------------------------------------
 .../service/registry/MetadataApiRegistry.java   | 78 +++++++++++---------
 .../integration/common/rest/RestClient.java     | 25 +++----
 .../application/MetadataServiceTestCase.java    | 12 +--
 3 files changed, 58 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/62b8d38c/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
index 11ab2d2..11d1468 100644
--- 
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
@@ -75,8 +75,9 @@ public class MetadataApiRegistry implements DataStore {
             acquireReadLock(applicationId);
             return getRegistryResourceProperties(resourcePath, applicationId);
         } catch (Exception e) {
-            String msg = String.format("Failed to get application properties 
from registry [resource-path] %s for "
-                    + "[application-id] %s", resourcePath, applicationId);
+            String msg = String
+                    .format("Failed to get properties from registry 
[resource-path] %s for " + "[application-id] %s",
+                            resourcePath, applicationId);
             log.error(msg, e);
             throw new RegistryException(msg, e);
         } finally {
@@ -101,9 +102,8 @@ public class MetadataApiRegistry implements DataStore {
             acquireReadLock(applicationId);
             return getRegistryResourceProperties(resourcePath, applicationId);
         } catch (Exception e) {
-            String msg = String
-                    .format("Failed to get cluster properties from registry 
[resource-path] %s for [application-id] "
-                            + "%s, [cluster-id] %s", resourcePath, 
applicationId, clusterId);
+            String msg = String.format("Failed to get properties from registry 
[resource-path] %s for [application-id] "
+                    + "%s, [cluster-id] %s", resourcePath, applicationId, 
clusterId);
             log.error(msg, e);
             throw new RegistryException(msg, e);
         } finally {
@@ -159,7 +159,7 @@ public class MetadataApiRegistry implements DataStore {
             } else {
                 nodeResource = registry.newCollection();
                 if (log.isDebugEnabled()) {
-                    log.debug("Registry resource created for application: " + 
applicationId);
+                    log.debug(String.format("Registry resource created: 
[resource-path] %s", resourcePath));
                 }
             }
 
@@ -168,27 +168,29 @@ public class MetadataApiRegistry implements DataStore {
                 if (!propertyValueExist(nodeResource, property.getKey(), 
value)) {
                     updated = true;
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("Registry property is added: 
[resource-path] %s "
-                                + "[Property Name] %s [Property Value] %s", 
resourcePath, property.getKey(), value));
+                        log.debug(String.format("Registry property updated: 
[resource-path] %s, [key] %s [value] %s",
+                                resourcePath, property.getKey(), value));
                     }
                     nodeResource.addProperty(property.getKey(), value);
                 } else {
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("Property value already exist 
property=%s value=%s", property.getKey(),
-                                value));
+                        log.debug(
+                                String.format("Registry value already exists: 
[resource-path] %s, [key] %s, [value] %s",
+                                        resourcePath, property.getKey(), 
value));
                     }
                 }
             }
             if (updated) {
                 registry.put(resourcePath, nodeResource);
                 if (log.isDebugEnabled()) {
-                    log.debug(String.format(
-                            "Registry property is persisted: [resource-path] 
%s [Property Name] %s [Property Values] "
-                                    + "%s", resourcePath, property.getKey(), 
Arrays.asList(property.getValues())));
+                    log.debug(String.format("Registry property is persisted: 
[resource-path] %s, [key] %s, [values] %s",
+                            resourcePath, property.getKey(), 
Arrays.asList(property.getValues())));
                 }
             }
         } catch (Exception e) {
-            String msg = "Failed to persist properties in registry: " + 
resourcePath;
+            String msg = String
+                    .format("Failed to persist properties in registry: 
[resource-path] %s, [key] %s, [values] %s",
+                            resourcePath, property.getKey(), 
Arrays.asList(property.getValues()));
             log.error(msg, e);
             throw new RegistryException(msg, e);
         } finally {
@@ -205,7 +207,7 @@ public class MetadataApiRegistry implements DataStore {
 
     }
 
-    public boolean removePropertyValueFromApplication(String applicationId, 
String propertyName, String valueToRemove)
+    public boolean removePropertyValueFromApplication(String applicationId, 
String propertyKey, String valueToRemove)
             throws RegistryException {
         Registry registry = getRegistry();
         String resourcePath = mainResource + applicationId;
@@ -220,16 +222,20 @@ public class MetadataApiRegistry implements DataStore {
             if (registry.resourceExists(resourcePath)) {
                 nodeResource = registry.get(resourcePath);
             } else {
-                log.warn(String.format("Registry [resource] %s not found ", 
resourcePath));
+                log.warn(String.format("Registry property not found: 
[resource-path] %s, [key] %s", resourcePath,
+                        propertyKey));
                 return false;
             }
-            nodeResource.removePropertyValue(propertyName, valueToRemove);
+            nodeResource.removePropertyValue(propertyKey, valueToRemove);
             registry.put(resourcePath, nodeResource);
-            log.info(String.format("Application %s property %s value %s is 
removed from metadata ", applicationId,
-                    propertyName, valueToRemove));
+            log.info(
+                    String.format("Registry property removed: [application-id] 
%s, [key] %s, [value] %s", applicationId,
+                            propertyKey, valueToRemove));
             return true;
         } catch (Exception e) {
-            throw new RegistryException("Could not remove registry resource: 
[resource-path] " + resourcePath, e);
+            throw new RegistryException(
+                    String.format("Could not remove registry resource: 
[resource-path] %s, [key] %s, [value] %s",
+                            resourcePath, propertyKey, valueToRemove), e);
         } finally {
             try {
                 releaseWriteLock(applicationId);
@@ -263,16 +269,18 @@ public class MetadataApiRegistry implements DataStore {
             } else {
                 nodeResource = registry.newResource();
                 if (log.isDebugEnabled()) {
-                    log.debug("Registry resource created for cluster" + 
clusterId);
+                    log.debug(String.format("Registry resource created for 
[cluster-id] %s", clusterId));
                 }
             }
             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",
+                    "Registry property persisted: [resource-path] %s [Property 
Name] %s [Property Values] %s",
                     resourcePath, property.getKey(), 
Arrays.asList(property.getValues())));
         } catch (Exception e) {
-            throw new RegistryException("Could not add registry resource: 
[resource-path] " + resourcePath, e);
+            throw new RegistryException(
+                    String.format("Could not add registry resource: 
[resource-path] %s, [key] %s, [value] %s",
+                            resourcePath, property.getKey(), 
Arrays.asList(property.getValues())), e);
 
         } finally {
             try {
@@ -308,12 +316,12 @@ public class MetadataApiRegistry implements DataStore {
             ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
             if (registry.resourceExists(resourcePath)) {
                 registry.delete(resourcePath);
-                log.info(String.format("Application [application-id ] 
properties removed from registry %s",
-                        applicationId));
+                log.info(String.format("Registry properties removed for 
[application-id] %s", applicationId));
             }
             return true;
         } catch (Exception e) {
-            throw new RegistryException("Could not remove registry resource: 
[resource-path] " + resourcePath, e);
+            throw new RegistryException(
+                    String.format("Could not remove registry resource: 
[resource-path] %s", resourcePath), e);
         } finally {
             try {
                 releaseWriteLock(applicationId);
@@ -322,7 +330,7 @@ public class MetadataApiRegistry implements DataStore {
         }
     }
 
-    public boolean removePropertyFromApplication(String applicationId, String 
propertyName)
+    public boolean removePropertyFromApplication(String applicationId, String 
propertyKey)
             throws org.wso2.carbon.registry.api.RegistryException {
         Registry registry = getRegistry();
         String resourcePath = mainResource + applicationId;
@@ -336,12 +344,12 @@ public class MetadataApiRegistry implements DataStore {
             ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
             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));
+                if (nodeResource.getProperty(propertyKey) == null) {
+                    log.info(String.format("Registry property not found: 
[application-id] %s [key] %s ", applicationId,
+                            propertyKey));
                     return false;
                 } else {
-                    nodeResource.removeProperty(propertyName);
+                    nodeResource.removeProperty(propertyKey);
                     registry.put(resourcePath, nodeResource);
                 }
             } else {
@@ -349,11 +357,13 @@ public class MetadataApiRegistry implements DataStore {
                 return false;
             }
 
-            log.info(String.format("Application [application-id] %s property 
[property-name] %s removed from Registry ",
-                    applicationId, propertyName));
+            log.info(String.format("Registry property removed: 
[application-id] %s, [key] %s", applicationId,
+                    propertyKey));
             return true;
         } catch (Exception e) {
-            throw new RegistryException("Could not remove registry resource: 
[resource-path] " + resourcePath, e);
+            throw new RegistryException(
+                    String.format("Could not remove registry resource: 
[resource-path] %s, [key] %s", resourcePath,
+                            propertyKey), e);
         } finally {
             try {
                 releaseWriteLock(applicationId);

http://git-wip-us.apache.org/repos/asf/stratos/blob/62b8d38c/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
 
b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
index c996eb8..cb1cb18 100644
--- 
a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
+++ 
b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
@@ -495,25 +495,22 @@ public class RestClient {
         @Override
         public PropertyBean deserialize(JsonElement json, Type typeOfT, 
JsonDeserializationContext context)
                 throws JsonParseException {
-            JsonObject jObj = json.getAsJsonObject();
-            JsonElement jsonElement = 
jObj.get(RestConstants.METADATA_RESPONSE_ATTRIBUTE_VALUES);
-            JsonPrimitive jsonPrimitive = 
jObj.getAsJsonPrimitive(RestConstants.METADATA_RESPONSE_ATTRIBUTE_KEY);
+            JsonObject responseJsonObject = json.getAsJsonObject();
+            JsonElement valuesJsonEl = 
responseJsonObject.get(RestConstants.METADATA_RESPONSE_ATTRIBUTE_VALUES);
+            JsonPrimitive keyJsonPrimitive = responseJsonObject
+                    
.getAsJsonPrimitive(RestConstants.METADATA_RESPONSE_ATTRIBUTE_KEY);
             List<String> tags = new ArrayList<>();
 
-            // Json structure is invalid. Return an empty property
-            if (jsonPrimitive == null) {
-                return new PropertyBean("", "");
-            }
-            // Json structure is invalid. Return a property with empty values 
list
-            String metadataKey = jsonPrimitive.getAsString();
-            if (jsonElement == null) {
-                return new PropertyBean(metadataKey, tags);
+            // Json structure is invalid
+            if (keyJsonPrimitive == null || valuesJsonEl == null) {
+                return null;
             }
-            if (jsonElement.isJsonArray()) {
-                tags = context.deserialize(jsonElement.getAsJsonArray(), new 
TypeToken<List<String>>() {
+            String metadataKey = keyJsonPrimitive.getAsString();
+            if (valuesJsonEl.isJsonArray()) {
+                tags = context.deserialize(valuesJsonEl.getAsJsonArray(), new 
TypeToken<List<String>>() {
                 }.getType());
             } else {
-                tags.add(metadataKey);
+                tags.add(valuesJsonEl.getAsString());
             }
             return new PropertyBean(metadataKey, tags);
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/62b8d38c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
index 9a40357..f33ecad 100644
--- 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
@@ -52,6 +52,7 @@ import static org.testng.AssertJUnit.assertTrue;
  * Deploy a sample application on mock IaaS and load test metadata service 
with high load of concurrent read/write
  * operations from multiple clients
  */
+@Test(groups = { "stratos.application.deployment", "metadata" })
 public class MetadataServiceTestCase extends StratosIntegrationTest {
     private static final Log log = 
LogFactory.getLog(MetadataServiceTestCase.class);
     private static final String RESOURCES_PATH = "/metadata-service-test";
@@ -76,8 +77,7 @@ public class MetadataServiceTestCase extends 
StratosIntegrationTest {
     public static final String APPLICATION_POLICY_ID = 
"application-policy-metadata-service-test";
     public static final String DEPLOYMENT_POLICY_ID = 
"deployment-policy-metadata-service-test";
 
-    @BeforeTest(timeOut = APPLICATION_TEST_TIMEOUT,
-                groups = { "stratos.application.deployment" })
+    @BeforeTest(timeOut = APPLICATION_TEST_TIMEOUT)
     public void deployApplications() throws Exception {
         startTime = System.currentTimeMillis();
         log.info("Adding autoscaling policy [autoscale policy id] " + 
AUTOSCALE_POLICY_ID);
@@ -202,7 +202,6 @@ public class MetadataServiceTestCase extends 
StratosIntegrationTest {
 
     @Test(timeOut = APPLICATION_TEST_TIMEOUT,
           description = "Application startup, activation and metadata service 
basic test",
-          groups = { "stratos.application.deployment" },
           priority = 1)
     public void testBasicOperations() throws Exception {
         String key = "mykey";
@@ -264,13 +263,11 @@ public class MetadataServiceTestCase extends 
StratosIntegrationTest {
         PropertyBean propertyBeanCleaned = 
restClient.getApplicationProperty(APPLICATION_1_ID, key, app1AccessToken);
         log.info("Retrieved metadata property: " + 
gson.toJson(propertyBeanCleaned));
         Assert.assertNull(propertyBeanCleaned, "Metadata properties have not 
been cleaned properly");
-
         log.info("Metadata service basic test completed successfully");
     }
 
     @Test(timeOut = APPLICATION_TEST_TIMEOUT,
           description = "Application startup, activation and metadata service 
concurrency test",
-          groups = { "stratos.application.deployment" },
           priority = 2)
     public void metadataConcurrencyTest() throws Exception {
         log.info("Starting multiple clients to add properties");
@@ -294,7 +291,6 @@ public class MetadataServiceTestCase extends 
StratosIntegrationTest {
 
     @Test(timeOut = APPLICATION_TEST_TIMEOUT,
           description = "Application startup, activation and metadata service 
security test",
-          groups = { "stratos.application.deployment" },
           priority = 3)
     public void metadataSecurityTest() throws Exception {
         String key = "mykey";
@@ -327,7 +323,6 @@ public class MetadataServiceTestCase extends 
StratosIntegrationTest {
 
     @Test(timeOut = APPLICATION_TEST_TIMEOUT,
           description = "Application startup, activation and metadata service 
concurrency test",
-          groups = { "stratos.application.deployment" },
           priority = 10)
     public void cleanupAfterUndeployingAppTest() throws Exception {
         // undeploy the app and check whether metadata entries are cleared
@@ -372,8 +367,7 @@ public class MetadataServiceTestCase extends 
StratosIntegrationTest {
         };
     }
 
-    @AfterTest(timeOut = APPLICATION_TEST_TIMEOUT,
-               groups = { "stratos.application.deployment" })
+    @AfterTest(timeOut = APPLICATION_TEST_TIMEOUT)
     public void cleanup() throws Exception {
         // remove app-1
         log.info("Removing the application [application id] " + 
APPLICATION_1_ID);

Reply via email to