You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2011/08/10 21:10:47 UTC

svn commit: r1156318 - in /incubator/airavata/trunk/modules/commons/gfac-schema: ./ src/main/java/org/apache/airavata/core/gfac/api/ src/main/java/org/apache/airavata/core/gfac/api/impl/ src/main/java/org/apache/airavata/core/gfac/type/util/

Author: smarru
Date: Wed Aug 10 19:10:46 2011
New Revision: 1156318

URL: http://svn.apache.org/viewvc?rev=1156318&view=rev
Log:
accepting patanachai contribution of JCR implementation to address AIRAVATA-73

Added:
    incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/
    incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/Registry.java
    incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/impl/
    incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/impl/JCRRegistry.java
    incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/type/util/
    incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/type/util/SchemaUtil.java
Modified:
    incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml

Modified: incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml?rev=1156318&r1=1156317&r2=1156318&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml (original)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml Wed Aug 10 19:10:46 2011
@@ -32,6 +32,16 @@
 	</repositories>
 	<dependencies>
 		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+			<version>1.1.1</version>
+		</dependency>	
+		<dependency>
+			<groupId>javax.jcr</groupId>
+			<artifactId>jcr</artifactId>
+			<version>2.0</version>
+		</dependency>	
+		<dependency>
 			<groupId>xmlbeans</groupId>
 			<artifactId>xbean</artifactId>
 			<version>2.5.0</version>
@@ -62,6 +72,26 @@
 			<version>1.5.2</version>
 			<type>jar</type>
 		</dependency>
+		
+		<!-- Testing -->
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-core</artifactId>
+			<version>2.2.7</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-simple</artifactId>
+			<version>1.5.11</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jackrabbit</groupId>
+			<artifactId>jackrabbit-jcr-rmi</artifactId>
+			<version>2.2.7</version>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 	<build>
 		<pluginManagement>

Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/Registry.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/Registry.java?rev=1156318&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/Registry.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/Registry.java Wed Aug 10 19:10:46 2011
@@ -0,0 +1,116 @@
+/*
+ *
+ * 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.airavata.core.gfac.api;
+
+import java.util.List;
+
+import org.apache.airavata.core.gfac.type.ApplicationDeploymentDescription;
+import org.apache.airavata.core.gfac.type.HostDescription;
+import org.apache.airavata.core.gfac.type.ServiceDescription;
+
+public interface Registry {
+	/**
+	 * Find locations where the service is deployed
+	 * 
+	 * @param serviceName
+	 * @return List of HostDescription having the service
+	 */
+	public List<HostDescription> getServiceLocation(String serviceName);
+	
+	/**
+	 * Retrieve a service description i.e. name, description, parameters 
+	 * 
+	 * @param serviceName
+	 * @return a service description or null if a description is not found
+	 */
+	public ServiceDescription getServiceDescription(String serviceName);
+	
+	/**
+	 * Retrieve a deployment description for a service from the specific host
+	 * 
+	 * @param serviceName
+	 * @param hostName
+	 * @return a deployment description or null if a description is not found
+	 */
+	public ApplicationDeploymentDescription getDeploymentDescription(String serviceName, String hostName);
+	
+	/**
+	 * Retrieve a host description
+	 * 
+	 * @param name
+	 * @return a host description or null if a description is not found
+	 */
+	public HostDescription getHostDescription(String name);
+	
+	/**
+	 * Save a host description with the specific name.
+	 * 
+	 * @param name
+	 * @param host
+	 * @return identifier
+	 */
+	public String saveHostDescription(String name, HostDescription host);
+	
+	/**
+	 * Save a service description with the specific name.
+	 * 
+	 * @param service
+	 * @param host
+	 * @return identifier
+	 */
+	public String saveServiceDescription(String name, ServiceDescription service);
+	
+	/**
+	 * Save a deployment description according to the service and host
+	 * 
+	 * @param service
+	 * @param host
+	 * @param app
+	 * @return identifier
+	 */
+	public String saveDeploymentDescription(String service, String host, ApplicationDeploymentDescription app);
+		
+	/**
+	 * Search host description with name
+	 * 
+	 * @param name
+	 * @return the host descriptions with matched name
+	 */
+	public List<HostDescription> searchHostDescription(String name);
+	
+	/**
+	 * Search service description with name
+	 * 
+	 * @param name
+	 * @return the service descriptions with matched name
+	 */
+	public List<ServiceDescription> searchServiceDescription(String name);
+	
+	/**
+	 * Search deployment description from a service and/or a hostname
+	 *
+	 * @param serviceName 
+	 * @param hostName
+	 * @return the deployment descriptions with matched names
+	 */
+	public List<ApplicationDeploymentDescription> searchDeploymentDescription(String serviceName, String hostName);	
+}

Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/impl/JCRRegistry.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/impl/JCRRegistry.java?rev=1156318&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/impl/JCRRegistry.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/api/impl/JCRRegistry.java Wed Aug 10 19:10:46 2011
@@ -0,0 +1,306 @@
+/*
+ *
+ * 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.airavata.core.gfac.api.impl;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Credentials;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.airavata.core.gfac.api.Registry;
+import org.apache.airavata.core.gfac.type.ApplicationDeploymentDescription;
+import org.apache.airavata.core.gfac.type.HostDescription;
+import org.apache.airavata.core.gfac.type.ServiceDescription;
+import org.apache.airavata.core.gfac.type.util.SchemaUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class JCRRegistry implements Registry {
+
+	private static final String SERVICE_NODE_NAME = "SERVICE_HOST";
+	private static final String DEPLOY_NODE_NAME = "APP_HOST";
+	private static final String HOST_NODE_NAME = "GFAC_HOST";
+	private static final String XML_PROPERTY_NAME = "XML";	
+
+	private Repository repository;
+	private Credentials credentials;
+
+	private Node serviceNode;
+	private Node appNode;
+	private Node hostNode;
+
+	private static Log log = LogFactory.getLog(JCRRegistry.class);
+
+	public JCRRegistry(String className, String user, String pass,
+			Map<String, String> map) {
+		try {
+			/*
+			 * Load the configuration from properties file at this level and
+			 * create the object
+			 */
+			Class registryRepositoryFactory = Class.forName(className);
+			Constructor c = registryRepositoryFactory.getConstructor();
+			RepositoryFactory repositoryFactory = (RepositoryFactory) c
+					.newInstance();
+
+			repository = repositoryFactory.getRepository(map);
+			if (repository == null)
+				System.exit(1);
+			credentials = new SimpleCredentials(user,
+					new String(pass).toCharArray());
+
+		} catch (ClassNotFoundException e) {
+			log.error("Error class path settting", e);
+		} catch (RepositoryException e) {
+			log.error("Error connecting Remote Registry instance", e);
+		} catch (Exception e) {
+			log.error("Error init", e);
+		}
+	}
+
+	private Session getSession() throws RepositoryException {
+		return repository.login(credentials);
+	}
+
+	private Node getServiceNode(Session session) throws RepositoryException {
+		if (this.serviceNode == null) {
+			this.serviceNode = getOrAddNode(session.getRootNode(),
+					SERVICE_NODE_NAME);
+		}
+		return this.serviceNode;
+	}
+
+	private Node getDeploymentNode(Session session) throws RepositoryException {
+		if (this.appNode == null) {
+			this.appNode = getOrAddNode(session.getRootNode(), DEPLOY_NODE_NAME);
+		}
+		return this.appNode;
+	}
+
+	private Node getHostNode(Session session) throws RepositoryException {
+		if (this.hostNode == null) {
+			this.hostNode = getOrAddNode(session.getRootNode(), HOST_NODE_NAME);
+		}
+		return this.hostNode;
+	}
+
+	private Node getOrAddNode(Node node, String name)
+			throws RepositoryException {
+		Node node1 = null;
+		try {
+			node1 = node.getNode(name);
+		}catch(PathNotFoundException pnfe){
+			node1 = node.addNode(name);
+		} catch (RepositoryException e) {
+			String msg = "failed to resolve the path of the given node ";
+			log.debug(msg);
+			throw new RepositoryException(msg, e);
+		}
+		return node1;
+	}
+
+	public List<HostDescription> getServiceLocation(String serviceName) {
+		Session session = null;
+		ArrayList<HostDescription> result = new ArrayList<HostDescription>();
+		try {
+			session = getSession();
+			Node node = getServiceNode(session);
+			NodeIterator nodes = node.getNodes();
+			for (; nodes.hasNext();) {
+				Node host = nodes.nextNode();
+				Property prop = host.getProperty(XML_PROPERTY_NAME);
+				result.add((HostDescription) SchemaUtil.parseFromXML(prop
+						.getString()));
+			}
+		} catch (Exception e) {
+			System.out.println(e);
+			e.printStackTrace();
+			// TODO propagate
+		} finally {
+			if (session != null) {
+				session.logout();
+			}
+		}
+		return result;
+	}
+
+	public ServiceDescription getServiceDescription(String serviceName) {
+		Session session = null;
+		ServiceDescription result = null;
+		try {
+			session = getSession();
+			Node serviceNode = getServiceNode(session);
+			Node node = serviceNode.getNode(serviceName);
+			Property prop = node.getProperty(XML_PROPERTY_NAME);
+			result = (ServiceDescription) SchemaUtil.parseFromXML(prop
+					.getString());
+		} catch (Exception e) {
+			System.out.println(e);
+			e.printStackTrace();
+			// TODO propagate
+		} finally {
+			if (session != null) {
+				session.logout();
+			}
+		}
+		return result;
+	}
+
+	public ApplicationDeploymentDescription getDeploymentDescription(
+			String serviceName, String host) {
+		Session session = null;
+		ApplicationDeploymentDescription result = null;
+		try {
+			session = getSession();
+			Node deploymentNode = getDeploymentNode(session);
+			Node serviceNode = deploymentNode.getNode(serviceName);
+			Node hostNode = serviceNode.getNode(host);
+			NodeIterator nodes = hostNode.getNodes();
+			for (; nodes.hasNext();) {
+				Node app = nodes.nextNode();
+				Property prop = app.getProperty(XML_PROPERTY_NAME);
+				result = (ApplicationDeploymentDescription) SchemaUtil
+						.parseFromXML(prop.getString());
+			}
+		} catch (Exception e) {
+			System.out.println(e);
+			e.printStackTrace();
+			// TODO propagate
+		} finally {
+			if (session != null) {
+				session.logout();
+			}
+		}
+		return result;
+	}
+
+	public HostDescription getHostDescription(String name) {
+		Session session = null;
+		HostDescription result = null;
+		try {
+			session = getSession();
+			Node hostNode = getHostNode(session);
+			Node node = hostNode.getNode(name);
+			Property prop = node.getProperty(XML_PROPERTY_NAME);
+			result = (HostDescription) SchemaUtil
+					.parseFromXML(prop.getString());
+		} catch (Exception e) {
+			System.out.println(e);
+			e.printStackTrace();
+			// TODO propagate
+		} finally {
+			if (session != null) {
+				session.logout();
+			}
+		}
+		return result;
+	}
+
+	public String saveHostDescription(String name, HostDescription host) {
+		Session session = null;
+		String result = null;
+		try {
+			session = getSession();
+			Node hostNode = getHostNode(session);
+			Node node = getOrAddNode(hostNode, name);
+			Property prop = node.setProperty(XML_PROPERTY_NAME,
+					SchemaUtil.toXML(host));
+			session.save();
+
+			result = node.getIdentifier();
+		} catch (Exception e) {
+			System.out.println(e);
+			e.printStackTrace();
+			// TODO propagate
+		}
+		return result;
+	}
+
+	public String saveServiceDescription(String name, ServiceDescription service) {
+		Session session = null;
+		String result = null;
+		try {
+			session = getSession();
+			Node serviceNode = getServiceNode(session);
+			Node node = getOrAddNode(serviceNode, name);
+			Property prop = node.setProperty(XML_PROPERTY_NAME,
+					SchemaUtil.toXML(service));
+			session.save();
+
+			result = node.getIdentifier();
+		} catch (Exception e) {
+			System.out.println(e);
+			e.printStackTrace();
+			// TODO propagate
+		}
+		return result;
+	}
+
+	public String saveDeploymentDescription(String service, String host,
+			ApplicationDeploymentDescription app) {
+		Session session = null;
+		String result = null;
+		try {
+			session = getSession();
+			Node deployNode = getDeploymentNode(session);
+			Node serviceNode = getOrAddNode(deployNode, service);
+			Node hostNode = getOrAddNode(serviceNode, host);
+			Node appName = getOrAddNode(hostNode, app.getName());
+			Property prop = appName.setProperty(XML_PROPERTY_NAME,
+					SchemaUtil.toXML(app));
+			session.save();
+
+			result = appName.getIdentifier();
+		} catch (Exception e) {
+			System.out.println(e);
+			e.printStackTrace();
+			// TODO propagate
+		}
+		return result;
+	}
+
+	public List<HostDescription> searchHostDescription(String name) {
+		// TODO implementation
+		return null;
+	}
+
+	public List<ServiceDescription> searchServiceDescription(String name) {
+		// TODO implementation
+		return null;
+	}
+
+	public List<ApplicationDeploymentDescription> searchDeploymentDescription(String serviceName, String hostName) {
+		// TODO implementation
+		return null;
+	}
+}

Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/type/util/SchemaUtil.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/type/util/SchemaUtil.java?rev=1156318&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/type/util/SchemaUtil.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/core/gfac/type/util/SchemaUtil.java Wed Aug 10 19:10:46 2011
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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.airavata.core.gfac.type.util;
+
+import java.beans.XMLDecoder;
+import java.beans.XMLEncoder;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.airavata.core.gfac.type.Type;
+
+public class SchemaUtil {
+	public static Type parseFromXML(String xml) {
+		ByteArrayInputStream bs = new ByteArrayInputStream(xml.getBytes());
+		XMLDecoder d = new XMLDecoder(bs);
+		Object result = d.readObject();
+		d.close();
+		return (Type) result;
+	}
+
+	public static String toXML(Type type) {
+		ByteArrayOutputStream x = new ByteArrayOutputStream();
+		XMLEncoder e = new XMLEncoder(x);
+		e.writeObject(type);
+		e.close();
+		return x.toString();
+	}
+}