stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ud...@apache.org
Subject [2/3] git commit: Re-factoring of the meta data service
Date Thu, 09 Oct 2014 08:37:16 GMT
Re-factoring of the meta data service


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

Branch: refs/heads/4.0.0-grouping
Commit: 86dbc56e2ae378b6b5c0a823cf313b7b7fbc3b5f
Parents: 2414be5
Author: gayan <gayan@puppet.gayan.org>
Authored: Thu Oct 9 13:10:37 2014 +0530
Committer: gayan <gayan@puppet.gayan.org>
Committed: Thu Oct 9 13:10:37 2014 +0530

----------------------------------------------------------------------
 .../stratos/metadataservice/Constants.java      |   3 +-
 .../definition/CartridgeMetaData.java           |  15 +-
 .../metadataservice/listener/TopologyAgent.java |  30 ++-
 .../listener/TopologyListener.java              | 119 +++------
 .../registry/CarbonRegistry.java                | 192 +++++++++++----
 .../metadataservice/registry/DataStore.java     |   8 +
 .../metadataservice/registry/GRegRegistry.java  | 242 ++++++++++++++-----
 .../src/main/conf/metadataservice.xml           |   2 +-
 .../all/repository/conf/metadataservice.xml     |   2 +-
 9 files changed, 395 insertions(+), 218 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/Constants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/Constants.java
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/Constants.java
index bd84c5f..f526d9e 100644
--- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/Constants.java
+++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/Constants.java
@@ -23,7 +23,6 @@ package org.apache.stratos.metadataservice;
  */
 public class Constants {
 
-	public static final String SUPER_TENANT_SERVICE = "super.tenant.service";
-	public static final String METADATASERVICE_CONFIG_FILE_NAME = "metadataservice.xml";
+    public static final String METADATASERVICE_CONFIG_FILE_NAME = "metadataservice.xml";
 
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/CartridgeMetaData.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/CartridgeMetaData.java
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/CartridgeMetaData.java
index fbe15ba..1875434 100644
--- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/CartridgeMetaData.java
+++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/CartridgeMetaData.java
@@ -1,6 +1,8 @@
 package org.apache.stratos.metadataservice.definition;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.xml.bind.annotation.XmlRootElement;
 
@@ -20,24 +22,15 @@ public class CartridgeMetaData {
 
 	public String version;
 
-	public List<PropertyBean> properties;
+	public String properties;
 
 	@Override
 	public String toString() {
 
 		return "applicationName: " + applicationName + ", displayName: " + displayName +
 		       ", description: " + description + ", type: " + type + ", provider: " + provider
+
-		       ", host: " + host + ", Version: " + version + ", properties: " + getProperties();
+		       ", host: " + host + ", Version: " + version + ", properties: " + properties;
 	}
 
-	private String getProperties() {
 
-		StringBuilder propertyBuilder = new StringBuilder();
-		if (properties != null) {
-			for (PropertyBean propertyBean : properties) {
-				propertyBuilder.append(propertyBean.toString());
-			}
-		}
-		return propertyBuilder.toString();
-	}
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
index 8e39364..f9afd78 100644
--- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
+++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
@@ -1,5 +1,3 @@
-package org.apache.stratos.metadataservice.listener;
-
 /*
  * 
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -20,6 +18,9 @@ package org.apache.stratos.metadataservice.listener;
  * under the License.
  */
 
+package org.apache.stratos.metadataservice.listener;
+
+import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.messaging.event.Event;
@@ -29,7 +30,8 @@ import org.apache.stratos.messaging.listener.topology.MemberSuspendedEventListen
 import org.apache.stratos.messaging.listener.topology.MemberTerminatedEventListener;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-import org.apache.stratos.metadataservice.services.MetaDataAdmin;
+import org.apache.stratos.metadataservice.registry.DataRegistryFactory;
+import org.apache.stratos.metadataservice.util.ConfUtil;
 
 /**
  * Cartridge agent runnable.
@@ -38,7 +40,6 @@ public class TopologyAgent implements Runnable {
 
 	private static final Log log = LogFactory.getLog(TopologyAgent.class);
 
-	private boolean terminated;
 
 	@Override
 	public void run() {
@@ -51,10 +52,24 @@ public class TopologyAgent implements Runnable {
 
 	}
 
-	protected void registerTopologyEventListeners() {
+    /**
+     * Register the topology event listener
+     */
+	private void registerTopologyEventListeners() {
+        final String defaultRegType = "carbon";
+
+         XMLConfiguration conf;
+        log.info("==================Starting topology event message receiver thread=================");
 		if (log.isDebugEnabled()) {
 			log.debug("Starting topology event message receiver thread");
 		}
+        conf = ConfUtil.getInstance(null).getConfiguration();
+
+       final String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+
+
 		TopologyEventReceiver topologyEventReceiver = new TopologyEventReceiver();
 
 		topologyEventReceiver.addEventListener(new MemberTerminatedEventListener() {
@@ -71,7 +86,7 @@ public class TopologyAgent implements Runnable {
 						log.debug("Terminated event :::::::::::::::::::: " +
 					                   memberTerminatedEvent.getServiceName());
 					}
-					new MetaDataAdmin().removeCartridgeMetaDataDetails("appA", "php");
+                    DataRegistryFactory.getDataRegistryFactory(registryType).removeCartridgeMetaDataDetails("appA",
"php");
 
 				} catch (Exception e) {
 					if (log.isErrorEnabled()) {
@@ -93,7 +108,8 @@ public class TopologyAgent implements Runnable {
 						log.debug("Member suspended event received");
 					}
 					MemberSuspendedEvent memberSuspendedEvent = (MemberSuspendedEvent) event;
-					// extensionHandler.onMemberSuspendedEvent(memberSuspendedEvent);
+                    //TODO : Add the funtionalilty for the suspended event
+
 				} catch (Exception e) {
 					if (log.isErrorEnabled()) {
 						log.error("Error processing member suspended event", e);

http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyListener.java
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyListener.java
index fbca388..6c018b4 100644
--- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyListener.java
+++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyListener.java
@@ -1,3 +1,24 @@
+/*
+ *
+ * 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.metadataservice.listener;
 
 import javax.servlet.ServletContextEvent;
@@ -5,16 +26,6 @@ import javax.servlet.ServletContextListener;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.event.topology.MemberStartedEvent;
-import org.apache.stratos.messaging.event.topology.MemberSuspendedEvent;
-import org.apache.stratos.messaging.event.topology.MemberTerminatedEvent;
-import org.apache.stratos.messaging.listener.topology.MemberStartedEventListener;
-import org.apache.stratos.messaging.listener.topology.MemberSuspendedEventListener;
-import org.apache.stratos.messaging.listener.topology.MemberTerminatedEventListener;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-import org.apache.stratos.metadataservice.services.MetaDataAdmin;
 
 public class TopologyListener implements ServletContextListener {
 
@@ -23,6 +34,10 @@ public class TopologyListener implements ServletContextListener {
 	private TopologyAgent topologyThread = null;
 	private Thread thread = null;
 
+    /**
+     * Initialization of the context
+     * @param arg0 ServletContextEvent
+     */
 	@Override
 	public void contextInitialized(ServletContextEvent arg0) {
 		log.info("Topology literner started....");
@@ -39,88 +54,16 @@ public class TopologyListener implements ServletContextListener {
 
 	}
 
+    /**
+     * Destroy the context
+     * @param arg0 ServletContextEvent
+     */
 	@Override
-	public void contextDestroyed(ServletContextEvent arg0) {
+	public void contextDestroyed(ServletContextEvent arg0)
+    {
 		thread.stop();
 	}
 
-	protected void registerTopologyEventListeners() {
-		if (log.isDebugEnabled()) {
-			log.debug("Starting topology event message receiver thread");
-		}
-		TopologyEventReceiver topologyEventReceiver = new TopologyEventReceiver();
-
-		topologyEventReceiver.addEventListener(new MemberTerminatedEventListener() {
-			@Override
-			protected void onEvent(Event event) {
-				try {
-					TopologyManager.acquireReadLock();
-					if (log.isDebugEnabled()) {
-						log.debug("Member terminated event received");
-					}
-					MemberTerminatedEvent memberTerminatedEvent = (MemberTerminatedEvent) event;
-					if(log.isDebugEnabled()){
-    					log.info("Terminated event :::::::::::::::::::: " +
-    					                   memberTerminatedEvent.getServiceName());
-					}
-					new MetaDataAdmin().removeCartridgeMetaDataDetails("appA", "php");
 
-					// extensionHandler.onMemberTerminatedEvent(memberTerminatedEvent);
-				} catch (Exception e) {
-					if (log.isErrorEnabled()) {
-						log.error("Error processing member terminated event", e);
-					}
-				} finally {
-					TopologyManager.releaseReadLock();
-				}
-			}
-		});
-
-		topologyEventReceiver.addEventListener(new MemberSuspendedEventListener() {
-			@Override
-			protected void onEvent(Event event) {
-				try {
-					TopologyManager.acquireReadLock();
-					if (log.isDebugEnabled()) {
-						log.debug("Member suspended event received");
-					}
-					MemberSuspendedEvent memberSuspendedEvent = (MemberSuspendedEvent) event;
-					// extensionHandler.onMemberSuspendedEvent(memberSuspendedEvent);
-				} catch (Exception e) {
-					if (log.isErrorEnabled()) {
-						log.error("Error processing member suspended event", e);
-					}
-				} finally {
-					TopologyManager.releaseReadLock();
-				}
-			}
-		});
-
-		topologyEventReceiver.addEventListener(new MemberStartedEventListener() {
-			@Override
-			protected void onEvent(Event event) {
-				try {
-					TopologyManager.acquireReadLock();
-					if (log.isDebugEnabled()) {
-						log.debug("Member started event received");
-					}
-					MemberStartedEvent memberStartedEvent = (MemberStartedEvent) event;
-					// extensionHandler.onMemberStartedEvent(memberStartedEvent);
-				} catch (Exception e) {
-					if (log.isErrorEnabled()) {
-						log.error("Error processing member started event", e);
-					}
-				} finally {
-					TopologyManager.releaseReadLock();
-				}
-			}
-		});
-
-		Thread thread = new Thread(topologyEventReceiver);
-		thread.start();
-		if (log.isDebugEnabled()) {
-			log.info("Cartridge Agent topology receiver thread started");
-		}
-	}
 
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
index 3ae47ce..e1526aa 100644
--- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
+++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
@@ -23,7 +23,7 @@ import java.util.*;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 
-import org.apache.axis2.context.ConfigurationContext;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.metadataservice.definition.*;
@@ -31,44 +31,121 @@ import org.wso2.carbon.core.AbstractAdmin;
 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.registry.core.service.RegistryService;
+
+
+/**
+ * Carbon registry implementation
+ */
 
 public class CarbonRegistry extends AbstractAdmin implements DataStore {
 
-	private static Log log = LogFactory.getLog(CarbonRegistry.class);
-	@Context
-	HttpServletRequest httpServletRequest;
+    private static Log log = LogFactory.getLog(CarbonRegistry.class);
+    @Context
+    HttpServletRequest httpServletRequest;
 
-	private static ConfigurationContext configContext = null;
+    private static final String mainResource = "/startos/";
 
-	private static String defaultAxis2Repo = "repository/deployment/client";
-	private static String defaultAxis2Conf = "repository/conf/axis2/axis2_client.xml";
 
-	private static final String defaultUsername = "admin@org.com";
-	private static final String defaultPassword = "admin123";
-	private static final String serverURL = "https://localhost:9445/services/";
-	private static final String mainResource = "/stratos/";
-	private static final int defaultRank = 3;
-	private RegistryService registryService;
+    public CarbonRegistry() {
 
-	public CarbonRegistry() {
+    }
 
-	}
 
-    /*
+    /**
+     * Add the meta data to governance registry
      *
+     * @param applicationName Application Name
+     * @param cartridgeType Cartridge Type
+     * @param cartridgeMetaData Cartridge Meta Data
+     * @throws Exception
+     */
+    @Override
+    public void addCartridgeMetaDataDetails(String applicationName, String cartridgeType,
+                                            CartridgeMetaData cartridgeMetaData) throws Exception
{
+        log.debug("Adding meta data details");
+
+        Registry tempRegistry = getGovernanceUserRegistry();
+
+
+        Resource resource = tempRegistry.newResource();
+
+        String type = cartridgeMetaData.type;
+
+        resource.setContent("Application description :: " + type);
+
+        String resourcePath = mainResource + applicationName + "/" + cartridgeType;
+
+        resource.addProperty("Application Name", cartridgeMetaData.applicationName);
+        resource.addProperty("Display Name", cartridgeMetaData.displayName);
+        resource.addProperty("Description", cartridgeMetaData.description);
+        resource.addProperty("Cartidge Type", cartridgeMetaData.type);
+        resource.addProperty("provider", cartridgeMetaData.provider);
+        resource.addProperty("Version", cartridgeMetaData.version);
+        resource.addProperty("Host", cartridgeMetaData.host);
+        resource.addProperty("Properties", cartridgeMetaData.properties);
+
+        tempRegistry.put(resourcePath, resource);
+
+        if (log.isDebugEnabled()) {
+            log.debug("A resource added to: " + resourcePath);
+        }
+
+
+    }
+
+    /**
+     * Get the meta data from the registry
+     *
+     * @param applicationName name of the application
+     * @param cartridgeType cartridge type
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public String getCartridgeMetaDataDetails(String applicationName, String cartridgeType)
+            throws Exception {
+        Registry registry = getGovernanceUserRegistry();
+        CartridgeMetaData cartridgeMetaData = new CartridgeMetaData();
+
+
+        String resourcePath = mainResource + applicationName + "/" + cartridgeType;
+        if (registry.resourceExists(resourcePath)) {
+
+            Resource getResource = registry.get(resourcePath);
+
+            cartridgeMetaData.type = getResource.getProperty("Cartidge Type");
+            cartridgeMetaData.applicationName = getResource.getProperty("Application Name");
+            cartridgeMetaData.description = getResource.getProperty("Description");
+            cartridgeMetaData.displayName = getResource.getProperty("Display Name");
+            cartridgeMetaData.host = getResource.getProperty("host");
+            cartridgeMetaData.provider = getResource.getProperty("provider");
+            cartridgeMetaData.version = getResource.getProperty("Version");
+            cartridgeMetaData.properties = getResource.getProperty("Properties");
+
+
+        }
+
+
+        return cartridgeMetaData.toString();
+    }
+
+
+    /**
      * Remove the meta data from the registry
      *
-     * @see org.apache.stratos.metadataservice.registry.DataStore#
-     * removeCartridgeMetaDataDetails(java.lang.String, java.lang.String)
+     * @param applicationName name of the application
+     * @param cartridgeType cartridge type
+     * @return
+     * @throws Exception
      */
-	@Override
-	public boolean removeCartridgeMetaDataDetails(String applicationName, String cartridgeType)
-	                                                                                       
   throws Exception {
-		Registry registry = getGovernanceUserRegistry();
-		String resourcePath = mainResource + applicationName + "/" + cartridgeType;
+    @Override
+    public boolean removeCartridgeMetaDataDetails(String applicationName, String cartridgeType)
+            throws Exception {
+        Registry registry = getGovernanceUserRegistry();
+        String resourcePath = mainResource + applicationName + "/" + cartridgeType;
+
         if (registry != null) {
-		    registry.delete(resourcePath);
+            registry.delete(resourcePath);
             return true;
         } else {
             if (log.isDebugEnabled()) {
@@ -76,14 +153,20 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
             }
             return false;
         }
-	}
-
-
+    }
 
+    /**
+     * Get Properties of clustor
+     * @param applicationName
+     * @param clusterId
+     * @return
+     * @throws RegistryException
+     */
+    @Override
     public List<NewProperty> getPropertiesOfCluster(String applicationName, String
clusterId) throws RegistryException {
         Registry tempRegistry = getGovernanceUserRegistry();
         String resourcePath = mainResource + applicationName + "/" + clusterId;
-        if(!tempRegistry.resourceExists(resourcePath)){
+        if (!tempRegistry.resourceExists(resourcePath)) {
             return null;
             //throw new RegistryException("Cluster does not exist at " + resourcePath);
         }
@@ -93,10 +176,9 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
 
         Properties props = regResource.getProperties();
         Enumeration<?> x = props.propertyNames();
-        while(x.hasMoreElements())
-        {
+        while (x.hasMoreElements()) {
             String key = (String) x.nextElement();
-            List<String>  values = regResource.getPropertyValues(key);
+            List<String> values = regResource.getPropertyValues(key);
             NewProperty property = new NewProperty();
             property.setKey(key);
             String[] valueArr = new String[values.size()];
@@ -108,6 +190,14 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
         return newProperties;
     }
 
+    /**
+     * Add property to cluster
+     * @param applicationId
+     * @param clusterId
+     * @param property
+     * @throws RegistryException
+     */
+    @Override
     public void addPropertyToCluster(String applicationId, String clusterId, NewProperty
property) throws RegistryException {
         Registry tempRegistry = getGovernanceUserRegistry();
         String resourcePath = mainResource + applicationId + "/" + clusterId;
@@ -119,6 +209,13 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
 
     }
 
+    /**
+     * Add properties to clustor
+     * @param applicationName
+     * @param clusterId
+     * @param properties
+     * @throws RegistryException
+     */
     @Override
     public void addPropertiesToCluster(String applicationName, String clusterId, NewProperty[]
properties) throws RegistryException {
         Registry tempRegistry = getGovernanceUserRegistry();
@@ -126,7 +223,7 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
         Resource regResource;
         regResource = createOrGetResourceforCluster(tempRegistry, resourcePath);
 
-        for(NewProperty property : properties){
+        for (NewProperty property : properties) {
             regResource.setProperty(property.getKey(), (Arrays.asList(property.getValues())));
 
         }
@@ -134,31 +231,44 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
         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
+     * @throws RegistryException
+     */
     private Resource createOrGetResourceforApplication(Registry tempRegistry, String resourcePath)
throws RegistryException {
         Resource regResource;
-        if(tempRegistry.resourceExists(resourcePath)) {
+        if (tempRegistry.resourceExists(resourcePath)) {
             regResource = tempRegistry.get(resourcePath);
-        }else{
+        } else {
             regResource = tempRegistry.newCollection();
-            if(log.isDebugEnabled()){
+            if (log.isDebugEnabled()) {
                 log.debug("Registry resource is create at path " + regResource.getPath()
+ " for application");
             }
         }
         return regResource;
     }
 
+    /**
+     * Create and get resources for Clustor
+     * @param tempRegistry
+     * @param resourcePath
+     * @return
+     * @throws RegistryException
+     */
     private Resource createOrGetResourceforCluster(Registry tempRegistry, String resourcePath)
throws RegistryException {
 
         int index = resourcePath.lastIndexOf('/');
-        String applicationResourcePath = resourcePath.substring(0,index);
+        String applicationResourcePath = resourcePath.substring(0, index);
         createOrGetResourceforApplication(tempRegistry, applicationResourcePath);
         Resource regResource;
-        if(tempRegistry.resourceExists(resourcePath)) {
+        if (tempRegistry.resourceExists(resourcePath)) {
             regResource = tempRegistry.get(resourcePath);
-        }else{
+        } else {
             regResource = tempRegistry.newResource();
-            if(log.isDebugEnabled()){
+            if (log.isDebugEnabled()) {
                 log.debug("Registry resource is create at path for cluster" + regResource.getPath()
+ " for cluster");
             }
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
index e1b1218..ea905a0 100644
--- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
+++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
@@ -18,6 +18,8 @@
  */
 package org.apache.stratos.metadataservice.registry;
 
+
+import org.apache.stratos.metadataservice.definition.CartridgeMetaData;
 import org.apache.stratos.metadataservice.definition.NewProperty;
 import org.wso2.carbon.registry.api.RegistryException;
 
@@ -28,6 +30,12 @@ import java.util.List;
  */
 public interface DataStore {
 
+	public void addCartridgeMetaDataDetails(String applicationName, String cartridgeType,
+	                                          CartridgeMetaData cartridgeMetaData) throws Exception;
+
+	public String getCartridgeMetaDataDetails(String applicationName, String cartridgeType)
+	                                                                                       throws
Exception;
+
     public boolean removeCartridgeMetaDataDetails(String applicationName, String cartridgeType)
 	                                                                                       
   throws Exception;
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
index 1726d10..2be8d27 100644
--- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
+++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
@@ -18,91 +18,199 @@
  */
 package org.apache.stratos.metadataservice.registry;
 
-import java.io.File;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Context;
-
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.stratos.metadataservice.definition.CartridgeMetaData;
 import org.apache.stratos.metadataservice.definition.NewProperty;
 import org.apache.stratos.metadataservice.util.ConfUtil;
 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.registry.core.Comment;
 import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import java.io.File;
+import java.util.List;
+
 /**
- * 
  * Governance registry implementation for the registry factory
- * 
  */
 public class GRegRegistry implements DataStore {
 
-	private static Log log = LogFactory.getLog(GRegRegistry.class);
-	@Context
-	HttpServletRequest httpServletRequest;
-
-	private static ConfigurationContext configContext = null;
-
-	private static String defaultAxis2Repo = "repository/deployment/client";
-	private static String defaultAxis2Conf = "repository/conf/axis2/axis2_client.xml";
-
-	private static final String defaultUsername = "admin@org.com";
-	private static final String defaultPassword = "admin123";
-	private static final String serverURL = "https://localhost:9445/services/";
-	private static final String mainResource = "/startos/";
-	private static final int defaultRank = 3;
-
-	/*
-	 * Registry initiation
-	 */
-	private static WSRegistryServiceClient setRegistry() throws Exception {
-
-		XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
-
-		String gregUsername = conf.getString("metadataservice.username", defaultUsername);
-		String gregPassword = conf.getString("metadataservice.password", defaultPassword);
-		String gregServerURL = conf.getString("metadataservice.serverurl", serverURL);
-		String axis2Repo = conf.getString("metadataservice.axis2Repo", defaultAxis2Repo);
-		String axis2Conf = conf.getString("metadataservice.axis2Conf", defaultAxis2Conf);
-		String defaultTrustStore =
-		                           "repository" + File.separator + "resources" + File.separator
+
-		                                   "security" + File.separator + "wso2carbon.jks";
-		String trustStorePath = conf.getString("metadataservice.trustStore", defaultTrustStore);
-		String trustStorePassword =
-		                            conf.getString("metadataservice.trustStorePassword",
-		                                           "wso2carbon");
-		String trustStoreType = conf.getString("metadataservice.trustStoreType", "JKS");
-
-		System.setProperty("javax.net.ssl.trustStore", trustStorePath);
-		System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);// "wso2carbon"
-		System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);// "JKS"
-		System.setProperty("carbon.repo.write.mode", "true");
-		configContext =
-		                ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2Repo,
-		                                                                                     axis2Conf);
-		return new WSRegistryServiceClient(gregServerURL, gregUsername, gregPassword, configContext);
-	}
+
+    private static Log log = LogFactory.getLog(GRegRegistry.class);
+    @Context
+    HttpServletRequest httpServletRequest;
+
+    private static ConfigurationContext configContext;
+
+    static {
+        configContext = null;
+    }
+
+    private static final String defaultUsername = "admin@org.com";
+    private static final String defaultPassword = "admin123";
+    private static final String serverURL = "https://localhost:9445/services/";
+    private static final String mainResource = "/startos/";
+    private static final int defaultRank = 3;
 
     /*
-     *
-     * Remove the meta data from the registry
-     *
-     * @see org.apache.stratos.metadataservice.registry.DataStore#
-     * removeCartridgeMetaDataDetails(java.lang.String, java.lang.String)
+     * Registry initiation
      */
-	@Override
-	public boolean removeCartridgeMetaDataDetails(String applicationName, String cartridgeType)
-	                                                                                       
   throws Exception {
-		Registry registry = setRegistry();
-		String resourcePath = mainResource + applicationName + "/" + cartridgeType;
-		registry.delete(resourcePath);
-		return false;
-	}
+    private static WSRegistryServiceClient setRegistry() throws Exception {
+
+        XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+
+        String gregUsername = conf.getString("metadataservice.username", defaultUsername);
+        String gregPassword = conf.getString("metadataservice.password", defaultPassword);
+        String gregServerURL = conf.getString("metadataservice.serverurl", serverURL);
+        String defaultAxis2Repo = "repository/deployment/client";
+        String axis2Repo = conf.getString("metadataservice.axis2Repo", defaultAxis2Repo);
+        String defaultAxis2Conf = "repository/conf/axis2/axis2_client.xml";
+        String axis2Conf = conf.getString("metadataservice.axis2Conf", defaultAxis2Conf);
+        String defaultTrustStore =
+                "repository" + File.separator + "resources" + File.separator +
+                        "security" + File.separator + "wso2carbon.jks";
+        String trustStorePath = conf.getString("metadataservice.trustStore", defaultTrustStore);
+        String trustStorePassword =
+                conf.getString("metadataservice.trustStorePassword",
+                        "wso2carbon");
+        String trustStoreType = conf.getString("metadataservice.trustStoreType", "JKS");
+
+        System.setProperty("javax.net.ssl.trustStore", trustStorePath);
+        System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);// "wso2carbon"
+        System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);// "JKS"
+        System.setProperty("carbon.repo.write.mode", "true");
+        configContext =
+                ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2Repo,
+                        axis2Conf);
+        return new WSRegistryServiceClient(gregServerURL, gregUsername, gregPassword, configContext);
+    }
+
+
+
+    /**
+     * Add the meta data to governance registry
+     * @param applicationName
+     * @param cartridgeType
+     * @param cartridgeMetaData
+     * @throws Exception
+     */
+    @Override
+    public void addCartridgeMetaDataDetails(String applicationName, String cartridgeType,
+                                            CartridgeMetaData cartridgeMetaData) throws Exception
{
+
+        Registry registry = setRegistry();
+        try {
+
+            Resource resource = registry.newResource();
+
+            String type = cartridgeMetaData.type;
+
+            resource.setContent("Application description :: " + type);
+
+            String resourcePath = mainResource + applicationName + "/" + cartridgeType;
+
+            resource.addProperty("Application Name", cartridgeMetaData.applicationName);
+            resource.addProperty("Display Name", cartridgeMetaData.displayName);
+            resource.addProperty("Description", cartridgeMetaData.description);
+            resource.addProperty("Cartidge Type", cartridgeMetaData.type);
+            resource.addProperty("provider", cartridgeMetaData.provider);
+            resource.addProperty("Version", cartridgeMetaData.version);
+            resource.addProperty("Host", cartridgeMetaData.host);
+            resource.addProperty("Properties", cartridgeMetaData.properties);
+            registry.put(resourcePath, resource);
+
+            registry.rateResource(resourcePath, defaultRank);
+
+            Comment comment = new Comment();
+            comment.setText("Added the " + applicationName + " " + type + " cartridge");
+            registry.addComment(resourcePath, comment);
+
+        } catch (Exception e) {
+
+            if (log.isErrorEnabled()) {
+                log.error("addCartridgeMetaDataDetails", e);
+            }
+        } finally {
+            // Close the session
+            ((WSRegistryServiceClient) registry).logut();
+        }
+
+
+    }
+
+    /**
+     * Get the meta data from the registry
+     * @param applicationName
+     * @param cartridgeType
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public String getCartridgeMetaDataDetails(String applicationName, String cartridgeType)
+            throws Exception {
+        Registry registry = setRegistry();
+        CartridgeMetaData cartridgeMetaData = new CartridgeMetaData();
+        try {
+
+            String resourcePath = mainResource + applicationName + "/" + cartridgeType;
+            if (registry.resourceExists(resourcePath)) {
+
+                Resource getResource = registry.get(resourcePath);
+                if (log.isDebugEnabled()) {
+                    log.debug("Resource retrived");
+                    log.debug("Printing retrieved resource content: " +
+                            new String((byte[]) getResource.getContent()));
+                }
+
+                cartridgeMetaData.type = getResource.getProperty("Cartidge Type");
+                cartridgeMetaData.applicationName = getResource.getProperty("Application
Name");
+                cartridgeMetaData.description = getResource.getProperty("Description");
+                cartridgeMetaData.displayName = getResource.getProperty("Display Name");
+                cartridgeMetaData.host = getResource.getProperty("Host");
+                cartridgeMetaData.provider = getResource.getProperty("provider");
+                cartridgeMetaData.version = getResource.getProperty("Version");
+                cartridgeMetaData.properties = getResource.getProperty("Properties");
+
+
+
+            }
+
+        } catch (Exception e) {
+
+            if (log.isErrorEnabled()) {
+                log.error("getCartridgeMetaDataDetails", e);
+            }
+        } finally {
+            // Close the session
+            ((WSRegistryServiceClient) registry).logut();
+        }
+        return cartridgeMetaData.toString();
+    }
+
+    /**
+     * Remove catridge meta data details from the registry
+     * @param applicationName
+     * @param cartridgeType
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public boolean removeCartridgeMetaDataDetails(String applicationName, String cartridgeType)
+            throws Exception {
+        Registry registry = setRegistry();
+        String resourcePath = mainResource + applicationName + "/" + cartridgeType;
+        registry.delete(resourcePath);
+        return false;
+    }
+
 
     public void addPropertiesToCluster(String applicationName, String clusterId, NewProperty[]
properties) throws RegistryException {
 
@@ -113,7 +221,7 @@ public class GRegRegistry implements DataStore {
     }
 
     public void addPropertyToCluster(String applicationId, String clusterId, NewProperty
property) throws RegistryException {
-        
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/products/stratos/modules/distribution/src/main/conf/metadataservice.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/metadataservice.xml b/products/stratos/modules/distribution/src/main/conf/metadataservice.xml
index d871bc0..5e8bb1d 100644
--- a/products/stratos/modules/distribution/src/main/conf/metadataservice.xml
+++ b/products/stratos/modules/distribution/src/main/conf/metadataservice.xml
@@ -19,7 +19,7 @@
 -->
 <configuration>
 	<metadataservice>
-	    <govenanceregistrytype>OWN</govenanceregistrytype>
+	    <govenanceregistrytype>carbon</govenanceregistrytype>
 	    <serverurl>https://localhost:9445/services/</serverurl>
 		<username>admin</username>
 		<password>admin</password>

http://git-wip-us.apache.org/repos/asf/stratos/blob/86dbc56e/tools/stratos-installer/config/all/repository/conf/metadataservice.xml
----------------------------------------------------------------------
diff --git a/tools/stratos-installer/config/all/repository/conf/metadataservice.xml b/tools/stratos-installer/config/all/repository/conf/metadataservice.xml
index 690e056..5e8bb1d 100644
--- a/tools/stratos-installer/config/all/repository/conf/metadataservice.xml
+++ b/tools/stratos-installer/config/all/repository/conf/metadataservice.xml
@@ -19,7 +19,7 @@
 -->
 <configuration>
 	<metadataservice>
-	    <govenanceregistrytype>GREG</govenanceregistrytype>
+	    <govenanceregistrytype>carbon</govenanceregistrytype>
 	    <serverurl>https://localhost:9445/services/</serverurl>
 		<username>admin</username>
 		<password>admin</password>


Mime
View raw message