You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by pa...@apache.org on 2011/10/24 19:48:53 UTC
svn commit: r1188257 - in
/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api:
./ exception/ impl/
Author: patanachai
Date: Mon Oct 24 17:48:53 2011
New Revision: 1188257
URL: http://svn.apache.org/viewvc?rev=1188257&view=rev
Log:
AIRAVATA-170 change throw out exception and implementation to XMLBean object
Added:
incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/RegistryException.java
Modified:
incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Axis2Registry.java
incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/DataRegistry.java
incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Registry.java
incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/DeploymentDescriptionRetrieveException.java
incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/HostDescriptionRetrieveException.java
incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/ServiceDescriptionRetrieveException.java
incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/JCRRegistry.java
Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Axis2Registry.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Axis2Registry.java?rev=1188257&r1=1188256&r2=1188257&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Axis2Registry.java (original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Axis2Registry.java Mon Oct 24 17:48:53 2011
@@ -21,7 +21,7 @@
package org.apache.airavata.registry.api;
-import org.apache.airavata.commons.gfac.type.ServiceDescription;
+import org.apache.airavata.schemas.gfac.ServiceDescription;
public interface Axis2Registry extends Registry {
Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/DataRegistry.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/DataRegistry.java?rev=1188257&r1=1188256&r2=1188257&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/DataRegistry.java (original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/DataRegistry.java Mon Oct 24 17:48:53 2011
@@ -23,7 +23,7 @@ package org.apache.airavata.registry.api
import java.util.List;
-import org.apache.airavata.commons.gfac.type.parameter.AbstractParameter;
+import org.apache.airavata.schemas.gfac.Parameter;
public interface DataRegistry {
@@ -34,7 +34,7 @@ public interface DataRegistry {
* @param parameters
* @return
*/
- public String saveOutput(String workflowId, List<AbstractParameter> parameters);
+ public String saveOutput(String workflowId, List<Parameter> parameters);
/**
* Load output from workflow execution.
@@ -42,6 +42,6 @@ public interface DataRegistry {
* @param workflowId
* @return List of parameters
*/
- public List<AbstractParameter> loadOutput(String workflowId);
+ public List<Parameter> loadOutput(String workflowId);
}
Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Registry.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Registry.java?rev=1188257&r1=1188256&r2=1188257&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Registry.java (original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/Registry.java Mon Oct 24 17:48:53 2011
@@ -25,16 +25,12 @@ import java.net.URI;
import java.util.List;
import java.util.Map;
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
import javax.xml.namespace.QName;
-import org.apache.airavata.commons.gfac.type.ApplicationDeploymentDescription;
-import org.apache.airavata.commons.gfac.type.HostDescription;
-import org.apache.airavata.commons.gfac.type.ServiceDescription;
-import org.apache.airavata.registry.api.exception.DeploymentDescriptionRetrieveException;
-import org.apache.airavata.registry.api.exception.HostDescriptionRetrieveException;
-import org.apache.airavata.registry.api.exception.ServiceDescriptionRetrieveException;
+import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescription;
+import org.apache.airavata.schemas.gfac.HostDescription;
+import org.apache.airavata.schemas.gfac.ServiceDescription;
public interface Registry {
/**
@@ -50,11 +46,9 @@ public interface Registry {
*
* @param serviceId
* @return a service description or null if a description is not found
- * @throws PathNotFoundException
* @throws ServiceDescriptionRetrieveException
*/
- public ServiceDescription getServiceDescription(String serviceId) throws ServiceDescriptionRetrieveException,
- PathNotFoundException;
+ public ServiceDescription getServiceDescription(String serviceId) throws RegistryException;
/**
* Retrieve a deployment description for a service from the specific host
@@ -62,11 +56,10 @@ public interface Registry {
* @param serviceId
* @param hostId
* @return a deployment description or null if a description is not found
- * @throws PathNotFoundException
* @throws DeploymentDescriptionRetrieveException
*/
public ApplicationDeploymentDescription getDeploymentDescription(String serviceId, String hostId)
- throws DeploymentDescriptionRetrieveException, PathNotFoundException;
+ throws RegistryException;
/**
* Retrieve a host description
@@ -74,8 +67,7 @@ public interface Registry {
* @param hostId
* @return a host description or null if a description is not found
*/
- public HostDescription getHostDescription(String hostId) throws HostDescriptionRetrieveException,
- PathNotFoundException;
+ public HostDescription getHostDescription(String hostId) throws RegistryException;
/**
* Save a host description with the specific name.
@@ -122,8 +114,7 @@ public interface Registry {
* @throws HostDescriptionRetrieveException
* @throws PathNotFoundException
*/
- public List<HostDescription> searchHostDescription(String name) throws HostDescriptionRetrieveException,
- PathNotFoundException;
+ public List<HostDescription> searchHostDescription(String name) throws RegistryException;
/**
* Search service description with name
@@ -133,8 +124,7 @@ public interface Registry {
* @throws PathNotFoundException
* @throws ServiceDescriptionRetrieveException
*/
- public List<ServiceDescription> searchServiceDescription(String name) throws ServiceDescriptionRetrieveException,
- PathNotFoundException;
+ public List<ServiceDescription> searchServiceDescription(String name) throws RegistryException;
/**
* Search deployment description from a service and/or a hostname
@@ -146,7 +136,7 @@ public interface Registry {
* @throws DeploymentDescriptionRetrieveException
*/
public List<ApplicationDeploymentDescription> searchDeploymentDescription(String serviceName, String hostName)
- throws DeploymentDescriptionRetrieveException, PathNotFoundException;
+ throws RegistryException;
/**
* Search deployment description from a service and/or a hostname
@@ -159,7 +149,7 @@ public interface Registry {
* @throws DeploymentDescriptionRetrieveException
*/
public List<ApplicationDeploymentDescription> searchDeploymentDescription(String serviceName, String hostName,
- String applicationName) throws PathNotFoundException, DeploymentDescriptionRetrieveException;
+ String applicationName) throws RegistryException;
/**
* Return all deployment descriptions
@@ -169,8 +159,7 @@ public interface Registry {
* @throws PathNotFoundException
* @throws DeploymentDescriptionRetrieveException
*/
- public Map<ApplicationDeploymentDescription, String> searchDeploymentDescription() throws PathNotFoundException,
- DeploymentDescriptionRetrieveException;
+ public Map<ApplicationDeploymentDescription, String> searchDeploymentDescription() throws RegistryException;
/**
* This method can be used to save the gfacURL in to registry
@@ -199,13 +188,12 @@ public interface Registry {
public boolean deleteWorkflow(QName resourceID, String userName);
- public void deleteServiceDescription(String serviceId) throws ServiceDescriptionRetrieveException,
- PathNotFoundException;
+ public void deleteServiceDescription(String serviceId) throws RegistryException;
public void deleteDeploymentDescription(String serviceName, String hostName, String applicationName)
- throws PathNotFoundException, DeploymentDescriptionRetrieveException;
+ throws RegistryException;
- public void deleteHostDescription(String hostId) throws HostDescriptionRetrieveException, PathNotFoundException;
+ public void deleteHostDescription(String hostId) throws RegistryException;
/**
* Returns the default username that is specified to connect to the repository
Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/DeploymentDescriptionRetrieveException.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/DeploymentDescriptionRetrieveException.java?rev=1188257&r1=1188256&r2=1188257&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/DeploymentDescriptionRetrieveException.java (original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/DeploymentDescriptionRetrieveException.java Mon Oct 24 17:48:53 2011
@@ -1,6 +1,27 @@
+/*
+ *
+ * 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.registry.api.exception;
-public class DeploymentDescriptionRetrieveException extends Exception {
+public class DeploymentDescriptionRetrieveException extends RegistryException {
private final static String ERROR_MESSAGE = "Error occured while attempting to retrieve existing deployment descriptions";
/**
*
@@ -8,7 +29,7 @@ public class DeploymentDescriptionRetrie
private static final long serialVersionUID = -2849422320139467602L;
public DeploymentDescriptionRetrieveException(Exception e) {
- super(ERROR_MESSAGE, e);
+ super(e);
}
}
Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/HostDescriptionRetrieveException.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/HostDescriptionRetrieveException.java?rev=1188257&r1=1188256&r2=1188257&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/HostDescriptionRetrieveException.java (original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/HostDescriptionRetrieveException.java Mon Oct 24 17:48:53 2011
@@ -1,10 +1,29 @@
+/*
+ *
+ * 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.registry.api.exception;
-public class HostDescriptionRetrieveException extends Exception {
+public class HostDescriptionRetrieveException extends RegistryException {
private final static String ERROR_MESSAGE = "Error occured while attempting to retrieve existing hosts";
- /**
- *
- */
+
private static final long serialVersionUID = -2849422320139467602L;
public HostDescriptionRetrieveException(Exception e) {
Added: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/RegistryException.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/RegistryException.java?rev=1188257&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/RegistryException.java (added)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/RegistryException.java Mon Oct 24 17:48:53 2011
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.registry.api.exception;
+
+public class RegistryException extends Exception {
+
+ private final static String ERROR_MESSAGE = "Error occured while attempting to retrieve existing deployment descriptions";
+
+ private static final long serialVersionUID = -2849422320139467602L;
+
+ public RegistryException(Exception e) {
+ super(ERROR_MESSAGE, e);
+ }
+
+ protected RegistryException(String message, Exception e) {
+ super(message, e);
+ }
+}
Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/ServiceDescriptionRetrieveException.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/ServiceDescriptionRetrieveException.java?rev=1188257&r1=1188256&r2=1188257&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/ServiceDescriptionRetrieveException.java (original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/exception/ServiceDescriptionRetrieveException.java Mon Oct 24 17:48:53 2011
@@ -1,6 +1,27 @@
+/*
+ *
+ * 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.registry.api.exception;
-public class ServiceDescriptionRetrieveException extends Exception {
+public class ServiceDescriptionRetrieveException extends RegistryException {
private final static String ERROR_MESSAGE = "Error occured while attempting to retrieve existing service descriptions";
/**
*
Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/JCRRegistry.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/JCRRegistry.java?rev=1188257&r1=1188256&r2=1188257&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/JCRRegistry.java (original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/JCRRegistry.java Mon Oct 24 17:48:53 2011
@@ -23,7 +23,6 @@ package org.apache.airavata.registry.api
import java.lang.reflect.Constructor;
import java.net.URI;
-import java.net.URL;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
@@ -45,825 +44,838 @@ import javax.jcr.RepositoryFactory;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
import javax.xml.namespace.QName;
-import org.apache.airavata.commons.gfac.type.ApplicationDeploymentDescription;
-import org.apache.airavata.commons.gfac.type.HostDescription;
-import org.apache.airavata.commons.gfac.type.ServiceDescription;
-import org.apache.airavata.commons.gfac.type.parameter.AbstractParameter;
-import org.apache.airavata.commons.gfac.util.SchemaUtil;
import org.apache.airavata.registry.api.Axis2Registry;
import org.apache.airavata.registry.api.DataRegistry;
import org.apache.airavata.registry.api.exception.DeploymentDescriptionRetrieveException;
import org.apache.airavata.registry.api.exception.HostDescriptionRetrieveException;
+import org.apache.airavata.registry.api.exception.RegistryException;
import org.apache.airavata.registry.api.exception.ServiceDescriptionRetrieveException;
import org.apache.airavata.registry.api.user.UserManager;
-import org.apache.airavata.registry.api.user.UserManagerFactory;
import org.apache.airavata.registry.api.util.WebServiceUtil;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescription;
+import org.apache.airavata.schemas.gfac.HostDescription;
+import org.apache.airavata.schemas.gfac.Parameter;
+import org.apache.airavata.schemas.gfac.ServiceDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class JCRRegistry extends Observable implements Axis2Registry, DataRegistry {
+public class JCRRegistry extends Observable implements Axis2Registry,
+ DataRegistry {
- private static final String OUTPUT_NODE_NAME = "OUTPUTS";
- private static final String SERVICE_NODE_NAME = "SERVICE_HOST";
- private static final String GFAC_INSTANCE_DATA = "GFAC_INSTANCE_DATA";
- 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 static final String WSDL_PROPERTY_NAME = "WSDL";
- private static final String GFAC_URL_PROPERTY_NAME = "GFAC_URL_LIST";
- private static final String LINK_NAME = "LINK";
- public static final String WORKFLOWS = "WORKFLOWS";
- public static final String PUBLIC = "PUBLIC";
- public static final String REGISTRY_TYPE_WORKFLOW = "workflow";
- public static final int GFAC_URL_UPDATE_INTERVAL = 1000 * 60 * 60 * 3;
- public static final String WORKFLOW_DATA = "WorkflowData";
-
-
- private Repository repository;
- private Credentials credentials;
- private UserManager userManager;
- private String username;
- private URI repositoryURI;
-
- private static Logger log = LoggerFactory.getLogger(JCRRegistry.class);
-
- public JCRRegistry(URI repositoryURI, String className, String user, String pass, Map<String, String> map)
- throws RepositoryException {
- 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();
- setRepositoryURI(repositoryURI);
- repository = repositoryFactory.getRepository(map);
- setUsername(user);
- credentials = new SimpleCredentials(getUsername(), 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);
- throw e;
- } catch (Exception e) {
- log.error("Error init", e);
- }
- }
-
- public JCRRegistry(Repository repo, Credentials credentials) {
- this.repository = repo;
- this.credentials = credentials;
- }
-
- public Session getSession() throws RepositoryException {
- return repository.login(credentials);
- }
-
- private Node getServiceNode(Session session) throws RepositoryException {
- return getOrAddNode(session.getRootNode(), SERVICE_NODE_NAME);
- }
-
- private Node getDeploymentNode(Session session) throws RepositoryException {
- return getOrAddNode(session.getRootNode(), DEPLOY_NODE_NAME);
- }
-
- private Node getHostNode(Session session) throws RepositoryException {
- return getOrAddNode(session.getRootNode(), HOST_NODE_NAME);
- }
-
- 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;
- }
-
- private void closeSession(Session session) {
- if (session != null && session.isLive()) {
- session.logout();
- }
- }
-
- public List<HostDescription> getServiceLocation(String serviceId) {
- Session session = null;
- ArrayList<HostDescription> result = new ArrayList<HostDescription>();
- try {
- session = getSession();
- Node node = getServiceNode(session);
- Node serviceNode = node.getNode(serviceId);
- if (serviceNode.hasProperty(LINK_NAME)) {
- Property prop = serviceNode.getProperty(LINK_NAME);
- Value[] vals = prop.getValues();
- for (Value val : vals) {
- Node host = session.getNodeByIdentifier(val.getString());
- Property hostProp = host.getProperty(XML_PROPERTY_NAME);
- result.add((HostDescription) SchemaUtil.parseFromXML(hostProp.getString()));
- }
- }
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public void deleteServiceDescription(String serviceId) throws ServiceDescriptionRetrieveException,
- PathNotFoundException {
- Session session = null;
- try {
- session = getSession();
- Node serviceNode = getServiceNode(session);
- Node node = serviceNode.getNode(serviceId);
- if (node != null) {
- node.remove();
- session.save();
- }
- } catch (PathNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw new ServiceDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- }
-
- public ServiceDescription getServiceDescription(String serviceId) throws ServiceDescriptionRetrieveException,
- PathNotFoundException {
- Session session = null;
- ServiceDescription result = null;
- try {
- session = getSession();
- Node serviceNode = getServiceNode(session);
- Node node = serviceNode.getNode(serviceId);
- Property prop = node.getProperty(XML_PROPERTY_NAME);
- result = (ServiceDescription) SchemaUtil.parseFromXML(prop.getString());
- } catch (PathNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw new ServiceDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public ApplicationDeploymentDescription getDeploymentDescription(String serviceId, String hostId)
- throws DeploymentDescriptionRetrieveException, PathNotFoundException {
- Session session = null;
- ApplicationDeploymentDescription result = null;
- try {
- session = getSession();
- Node deploymentNode = getDeploymentNode(session);
- Node serviceNode = deploymentNode.getNode(serviceId);
- Node hostNode = serviceNode.getNode(hostId);
- 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 {
- closeSession(session);
- }
- return result;
- }
-
- public void deleteHostDescription(String hostId) throws HostDescriptionRetrieveException, PathNotFoundException {
- Session session = null;
- try {
- session = getSession();
- Node hostNode = getHostNode(session);
- Node node = hostNode.getNode(hostId);
- if (node != null) {
- node.remove();
- session.save();
- }
- } catch (PathNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw new HostDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- }
-
- public HostDescription getHostDescription(String hostId) throws HostDescriptionRetrieveException,
- PathNotFoundException {
- Session session = null;
- HostDescription result = null;
- try {
- session = getSession();
- Node hostNode = getHostNode(session);
- Node node = hostNode.getNode(hostId);
- if (node != null) {
- result = getHostDescriptor(node);
- }
- } catch (PathNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw new HostDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- private HostDescription getHostDescriptor(Node node) throws PathNotFoundException, RepositoryException,
- ValueFormatException {
- HostDescription result;
- Property prop = node.getProperty(XML_PROPERTY_NAME);
- result = (HostDescription) SchemaUtil.parseFromXML(prop.getString());
- return result;
- }
-
- public String saveHostDescription(HostDescription host) {
- Session session = null;
- String result = null;
- try {
- session = getSession();
- Node hostNode = getHostNode(session);
- Node node = getOrAddNode(hostNode, host.getId());
- node.setProperty(XML_PROPERTY_NAME, SchemaUtil.toXML(host));
- session.save();
-
- result = node.getIdentifier();
- triggerObservers(this);
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public String saveServiceDescription(ServiceDescription service) {
- Session session = null;
- String result = null;
- try {
- session = getSession();
- Node serviceNode = getServiceNode(session);
- Node node = getOrAddNode(serviceNode, service.getId());
- node.setProperty(XML_PROPERTY_NAME, SchemaUtil.toXML(service));
- session.save();
-
- result = node.getIdentifier();
- triggerObservers(this);
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public String saveDeploymentDescription(String serviceId, String hostId, ApplicationDeploymentDescription app) {
- Session session = null;
- String result = null;
- try {
- session = getSession();
- Node deployNode = getDeploymentNode(session);
- Node serviceNode = getOrAddNode(deployNode, serviceId);
- Node hostNode = getOrAddNode(serviceNode, hostId);
- Node appName = getOrAddNode(hostNode, app.getId());
- appName.setProperty(XML_PROPERTY_NAME, SchemaUtil.toXML(app));
- session.save();
-
- result = appName.getIdentifier();
- triggerObservers(this);
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public boolean deployServiceOnHost(String serviceId, String hostId) {
- Session session = null;
- try {
- session = getSession();
- Node serviceRoot = getServiceNode(session);
- Node hostRoot = getHostNode(session);
-
- Node serviceNode = serviceRoot.getNode(serviceId);
- Node hostNode = hostRoot.getNode(hostId);
-
- if (!serviceNode.hasProperty(LINK_NAME)) {
- serviceNode.setProperty(LINK_NAME, new String[] { hostNode.getIdentifier() });
- } else {
- Property prop = serviceNode.getProperty(LINK_NAME);
- Value[] vals = prop.getValues();
- ArrayList<String> s = new ArrayList<String>();
- for (Value val : vals) {
- s.add(val.getString());
- }
-
- if (s.contains(hostNode.getIdentifier())) {
- return false;
- }
-
- s.add(hostNode.getIdentifier());
- serviceNode.setProperty(LINK_NAME, s.toArray(new String[0]));
- }
-
- session.save();
- return true;
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return false;
- }
-
- public List<ServiceDescription> searchServiceDescription(String name) throws ServiceDescriptionRetrieveException,
- PathNotFoundException {
- Session session = null;
- ArrayList<ServiceDescription> result = new ArrayList<ServiceDescription>();
- try {
- session = getSession();
- Node node = getServiceNode(session);
- NodeIterator nodes = node.getNodes();
- for (; nodes.hasNext();) {
- Node service = nodes.nextNode();
- Property prop = service.getProperty(XML_PROPERTY_NAME);
- result.add((ServiceDescription) SchemaUtil.parseFromXML(prop.getString()));
- }
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public List<HostDescription> searchHostDescription(String nameRegEx) throws HostDescriptionRetrieveException,
- PathNotFoundException {
- Session session = null;
- List<HostDescription> result = new ArrayList<HostDescription>();
- try {
- session = getSession();
- Node node = getHostNode(session);
- NodeIterator nodes = node.getNodes();
- for (; nodes.hasNext();) {
- Node host = nodes.nextNode();
- if (host != null && host.getName().matches(nameRegEx)) {
- HostDescription hostDescriptor = getHostDescriptor(host);
- result.add(hostDescriptor);
- }
- }
- } catch (PathNotFoundException e) {
- System.out.println(e);
- e.printStackTrace();
- throw e;
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- throw new HostDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public Map<ApplicationDeploymentDescription, String> searchDeploymentDescription() throws PathNotFoundException,
- DeploymentDescriptionRetrieveException {
- Session session = null;
- Map<ApplicationDeploymentDescription, String> result = new HashMap<ApplicationDeploymentDescription, String>();
- try {
- session = getSession();
- Node deploymentNode = getDeploymentNode(session);
- NodeIterator serviceNodes = deploymentNode.getNodes();
-
- for (; serviceNodes.hasNext();) {
- Node serviceNode = serviceNodes.nextNode();
- NodeIterator hostNodes = serviceNode.getNodes();
-
- for (; hostNodes.hasNext();) {
- Node hostNode = hostNodes.nextNode();
- NodeIterator nodes = hostNode.getNodes();
- for (; nodes.hasNext();) {
- Node app = nodes.nextNode();
- Property prop = app.getProperty(XML_PROPERTY_NAME);
- result.put((ApplicationDeploymentDescription) SchemaUtil.parseFromXML(prop.getString()),
- serviceNode.getName() + "$" + hostNode.getName());
- }
- }
- }
- } catch (PathNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw new DeploymentDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public void deleteDeploymentDescription(String serviceName, String hostName, String applicationName)
- throws PathNotFoundException, DeploymentDescriptionRetrieveException {
- Session session = null;
- try {
- session = getSession();
- Node deploymentNode = getDeploymentNode(session);
- Node serviceNode = deploymentNode.getNode(serviceName);
- Node hostNode = serviceNode.getNode(hostName);
- NodeIterator nodes = hostNode.getNodes();
- for (; nodes.hasNext();) {
- Node app = nodes.nextNode();
- Property prop = app.getProperty(XML_PROPERTY_NAME);
- ApplicationDeploymentDescription appDesc = (ApplicationDeploymentDescription) SchemaUtil
- .parseFromXML(prop.getString());
- if (appDesc.getId().matches(applicationName)) {
- app.remove();
- }
- }
- session.save();
- } catch (PathNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw new DeploymentDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- }
-
- public List<ApplicationDeploymentDescription> searchDeploymentDescription(String serviceName, String hostName,
- String applicationName) throws PathNotFoundException, DeploymentDescriptionRetrieveException {
- Session session = null;
- List<ApplicationDeploymentDescription> result = new ArrayList<ApplicationDeploymentDescription>();
- try {
- session = getSession();
- Node deploymentNode = getDeploymentNode(session);
- Node serviceNode = deploymentNode.getNode(serviceName);
- Node hostNode = serviceNode.getNode(hostName);
- NodeIterator nodes = hostNode.getNodes();
- for (; nodes.hasNext();) {
- Node app = nodes.nextNode();
- Property prop = app.getProperty(XML_PROPERTY_NAME);
- ApplicationDeploymentDescription appDesc = (ApplicationDeploymentDescription) SchemaUtil
- .parseFromXML(prop.getString());
- if (appDesc.getId().matches(applicationName)) {
- result.add(appDesc);
- }
- }
- } catch (PathNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw new DeploymentDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public List<ApplicationDeploymentDescription> searchDeploymentDescription(String serviceName, String hostName)
- throws PathNotFoundException, DeploymentDescriptionRetrieveException {
- Session session = null;
- List<ApplicationDeploymentDescription> result = new ArrayList<ApplicationDeploymentDescription>();
- try {
- session = getSession();
- Node deploymentNode = getDeploymentNode(session);
- Node serviceNode = deploymentNode.getNode(serviceName);
- Node hostNode = serviceNode.getNode(hostName);
- NodeIterator nodes = hostNode.getNodes();
- for (; nodes.hasNext();) {
- Node app = nodes.nextNode();
- Property prop = app.getProperty(XML_PROPERTY_NAME);
- result.add((ApplicationDeploymentDescription) SchemaUtil.parseFromXML(prop.getString()));
- }
- } catch (PathNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw new DeploymentDescriptionRetrieveException(e);
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public String saveWSDL(ServiceDescription service, String WSDL) {
- Session session = null;
- String result = null;
- try {
- session = getSession();
- Node serviceNode = getServiceNode(session);
- Node node = getOrAddNode(serviceNode, service.getId());
- node.setProperty(WSDL_PROPERTY_NAME, WSDL);
- session.save();
-
- result = node.getIdentifier();
- triggerObservers(this);
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public String saveWSDL(ServiceDescription service) {
- return saveWSDL(service, WebServiceUtil.generateWSDL(service));
- }
-
- public String getWSDL(String serviceName) {
- Session session = null;
- String result = null;
- try {
- session = getSession();
- Node serviceNode = getServiceNode(session);
- Node node = serviceNode.getNode(serviceName);
- Property prop = node.getProperty(WSDL_PROPERTY_NAME);
- result = prop.getString();
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public boolean saveGFacDescriptor(String gfacURL) {
- java.util.Date today = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
- Timestamp timestamp = new Timestamp(today.getTime());
- Session session = null;
- try {
- URI uri = new URI(gfacURL);
- String propertyName = uri.getHost() + "-" + uri.getPort();
- session = getSession();
- Node gfacDataNode = getOrAddNode(session.getRootNode(), GFAC_INSTANCE_DATA);
- try {
- Property prop = gfacDataNode.getProperty(propertyName);
- prop.setValue(gfacURL + ";" + timestamp.getTime());
- session.save();
- } catch (PathNotFoundException e) {
- gfacDataNode.setProperty(propertyName, gfacURL + ";" + timestamp.getTime());
- session.save();
- }
- triggerObservers(this);
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- return false;
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return true;
- }
-
- public boolean deleteGFacDescriptor(String gfacURL) {
- Session session = null;
- try {
- URI uri = new URI(gfacURL);
- String propertyName = uri.getHost() + "-" + uri.getPort();
- session = getSession();
- Node gfacDataNode = getOrAddNode(session.getRootNode(), GFAC_INSTANCE_DATA);
- Property prop = gfacDataNode.getProperty(propertyName);
- prop.setValue((String) null);
- session.save();
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- return false;
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return true;
- }
-
- public List<String> getGFacDescriptorList() {
- Session session = null;
- List<String> urlList = new ArrayList<String>();
- java.util.Date today = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
- Timestamp timestamp = new Timestamp(today.getTime());
- try {
- session = getSession();
- Node gfacNode = getOrAddNode(session.getRootNode(), GFAC_INSTANCE_DATA);
- PropertyIterator propertyIterator = gfacNode.getProperties();
- while (propertyIterator.hasNext()) {
- Property property = propertyIterator.nextProperty();
- if (!"nt:unstructured".equals(property.getString())) {
- String x = property.getString();
- Timestamp setTime = new Timestamp(new Long(property.getString().split(";")[1]));
- if (GFAC_URL_UPDATE_INTERVAL > (timestamp.getTime() - setTime.getTime())) {
- urlList.add(property.getString().split(";")[0]);
- }
- }
- }
- } catch (RepositoryException e) {
- e.printStackTrace();
- }
- return urlList;
- }
-
- public UserManager getUserManager() {
- return userManager;
- }
-
- public void setUserManager(UserManager userManager) {
- this.userManager = userManager;
- }
-
- public String saveOutput(String workflowId, List<AbstractParameter> parameters) {
- Session session = null;
- String result = null;
- try {
- session = getSession();
- Node outputNode = getOrAddNode(session.getRootNode(), OUTPUT_NODE_NAME);
- Node node = getOrAddNode(outputNode, workflowId);
- for (int i = 0; i < parameters.size(); i++) {
- node.setProperty(String.valueOf(i), SchemaUtil.toXML(parameters.get(i)));
- }
-
- session.save();
-
- result = node.getIdentifier();
- triggerObservers(this);
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public List<AbstractParameter> loadOutput(String workflowId) {
- Session session = null;
- ArrayList<AbstractParameter> result = new ArrayList<AbstractParameter>();
- try {
- session = getSession();
- Node outputNode = getOrAddNode(session.getRootNode(), OUTPUT_NODE_NAME);
- Node node = outputNode.getNode(workflowId);
-
- PropertyIterator it = node.getProperties();
- while (it.hasNext()) {
- Property prop = (Property) it.next();
- result.add((AbstractParameter) SchemaUtil.parseFromXML(prop.getString()));
- }
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- // TODO propagate
- } finally {
- closeSession(session);
- }
- return result;
- }
-
- public Map<QName, Node> getWorkflows(String userName) {
- Session session = null;
- Map<QName, Node> workflowList = new HashMap<QName, Node>();
- try {
- session = getSession();
- Node workflowListNode = getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOWS), PUBLIC);
- NodeIterator iterator = workflowListNode.getNodes();
- while (iterator.hasNext()) {
- Node nextNode = iterator.nextNode();
- workflowList.put(new QName(nextNode.getName()), nextNode);
- }
- workflowListNode = getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOWS), userName);
- iterator = workflowListNode.getNodes();
- while (iterator.hasNext()) {
- Node nextNode = iterator.nextNode();
- workflowList.put(new QName(nextNode.getName()), nextNode);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- return workflowList;
- }
-
- public Node getWorkflow(QName templateID, String userName) {
- Session session = null;
- Node result = null;
- try {
- session = getSession();
- Node workflowListNode = getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOWS), userName);
- result = getOrAddNode(workflowListNode, templateID.getLocalPart());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
-
- public boolean saveWorkflow(QName ResourceID, String workflowName, String resourceDesc, String workflowAsaString,
- String owner, boolean isMakePublic) {
- Session session = null;
- try {
- session = getSession();
- Node workflowListNode = getOrAddNode(session.getRootNode(), WORKFLOWS);
- Node workflowNode = null;
- if (isMakePublic) {
- workflowNode = getOrAddNode(getOrAddNode(workflowListNode, PUBLIC), workflowName);
- } else {
- workflowNode = getOrAddNode(getOrAddNode(workflowListNode, owner), workflowName);
- }
- workflowNode.setProperty("workflow", workflowAsaString);
- workflowNode.setProperty("Prefix", ResourceID.getPrefix());
- workflowNode.setProperty("LocalPart", ResourceID.getLocalPart());
- workflowNode.setProperty("NamespaceURI", ResourceID.getNamespaceURI());
- workflowNode.setProperty("public", isMakePublic);
- workflowNode.setProperty("Description", resourceDesc);
- workflowNode.setProperty("Type", REGISTRY_TYPE_WORKFLOW);
- session.save();
- triggerObservers(this);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- closeSession(session);
- return true;
- }
- }
-
- public boolean deleteWorkflow(QName resourceID, String userName) {
- Session session = null;
- try {
- session = getSession();
- Node workflowListNode = getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOWS), userName);
- Node result = getOrAddNode(workflowListNode, resourceID.getLocalPart());
- result.remove();
- session.save();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- closeSession(session);
- }
- return false;
- }
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public URI getRepositoryURI() {
- return repositoryURI;
- }
-
- private void setRepositoryURI(URI repositoryURI) {
- this.repositoryURI = repositoryURI;
- }
-
- protected void triggerObservers(Object o) {
- setChanged();
- notifyObservers(o);
- }
-
- public String getName() {
- return repository.getDescriptor(Repository.REP_NAME_DESC);
- }
-
- public boolean saveWorkflowData(String data, String experimentId,String nodeId) {
- Session session = null;
- try {
- session = getSession();
- Node workflowDataNode = getOrAddNode(getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOW_DATA),experimentId),nodeId);
- workflowDataNode.setProperty("content",data);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- closeSession(session);
- return true;
- }
+ private static final String OUTPUT_NODE_NAME = "OUTPUTS";
+ private static final String SERVICE_NODE_NAME = "SERVICE_HOST";
+ private static final String GFAC_INSTANCE_DATA = "GFAC_INSTANCE_DATA";
+ 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 static final String WSDL_PROPERTY_NAME = "WSDL";
+ private static final String GFAC_URL_PROPERTY_NAME = "GFAC_URL_LIST";
+ private static final String LINK_NAME = "LINK";
+ public static final String WORKFLOWS = "WORKFLOWS";
+ public static final String PUBLIC = "PUBLIC";
+ public static final String REGISTRY_TYPE_WORKFLOW = "workflow";
+ public static final int GFAC_URL_UPDATE_INTERVAL = 1000 * 60 * 60 * 3;
+ public static final String WORKFLOW_DATA = "WorkflowData";
+
+ private Repository repository;
+ private Credentials credentials;
+ private UserManager userManager;
+ private String username;
+ private URI repositoryURI;
+
+ private static Logger log = LoggerFactory.getLogger(JCRRegistry.class);
+
+ public JCRRegistry(URI repositoryURI, String className, String user,
+ String pass, Map<String, String> map) throws RepositoryException {
+ 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();
+ setRepositoryURI(repositoryURI);
+ repository = repositoryFactory.getRepository(map);
+ setUsername(user);
+ credentials = new SimpleCredentials(getUsername(),
+ 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);
+ throw e;
+ } catch (Exception e) {
+ log.error("Error init", e);
+ }
+ }
+
+ public JCRRegistry(Repository repo, Credentials credentials) {
+ this.repository = repo;
+ this.credentials = credentials;
+ }
+
+ public Session getSession() throws RepositoryException {
+ return repository.login(credentials);
+ }
+
+ private Node getServiceNode(Session session) throws RepositoryException {
+ return getOrAddNode(session.getRootNode(), SERVICE_NODE_NAME);
+ }
+
+ private Node getDeploymentNode(Session session) throws RepositoryException {
+ return getOrAddNode(session.getRootNode(), DEPLOY_NODE_NAME);
+ }
+
+ private Node getHostNode(Session session) throws RepositoryException {
+ return getOrAddNode(session.getRootNode(), HOST_NODE_NAME);
+ }
+
+ 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;
+ }
+
+ private void closeSession(Session session) {
+ if (session != null && session.isLive()) {
+ session.logout();
+ }
+ }
+
+ public List<HostDescription> getServiceLocation(String serviceId) {
+ Session session = null;
+ ArrayList<HostDescription> result = new ArrayList<HostDescription>();
+ try {
+ session = getSession();
+ Node node = getServiceNode(session);
+ Node serviceNode = node.getNode(serviceId);
+ if (serviceNode.hasProperty(LINK_NAME)) {
+ Property prop = serviceNode.getProperty(LINK_NAME);
+ Value[] vals = prop.getValues();
+ for (Value val : vals) {
+ Node host = session.getNodeByIdentifier(val.getString());
+ Property hostProp = host.getProperty(XML_PROPERTY_NAME);
+ result.add(HostDescription.Factory.parse(hostProp
+ .getString()));
+ }
+ }
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public void deleteServiceDescription(String serviceId)
+ throws ServiceDescriptionRetrieveException {
+ Session session = null;
+ try {
+ session = getSession();
+ Node serviceNode = getServiceNode(session);
+ Node node = serviceNode.getNode(serviceId);
+ if (node != null) {
+ node.remove();
+ session.save();
+ }
+ } catch (Exception e) {
+ throw new ServiceDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ }
+
+ public ServiceDescription getServiceDescription(String serviceId)
+ throws ServiceDescriptionRetrieveException {
+ Session session = null;
+ ServiceDescription result = null;
+ try {
+ session = getSession();
+ Node serviceNode = getServiceNode(session);
+ Node node = serviceNode.getNode(serviceId);
+ Property prop = node.getProperty(XML_PROPERTY_NAME);
+ result = ServiceDescription.Factory.parse(prop.getString());
+ } catch (Exception e) {
+ throw new ServiceDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public ApplicationDeploymentDescription getDeploymentDescription(
+ String serviceId, String hostId) throws RegistryException {
+ Session session = null;
+ ApplicationDeploymentDescription result = null;
+ try {
+ session = getSession();
+ Node deploymentNode = getDeploymentNode(session);
+ Node serviceNode = deploymentNode.getNode(serviceId);
+ Node hostNode = serviceNode.getNode(hostId);
+ NodeIterator nodes = hostNode.getNodes();
+ for (; nodes.hasNext();) {
+ Node app = nodes.nextNode();
+ Property prop = app.getProperty(XML_PROPERTY_NAME);
+ result = ApplicationDeploymentDescription.Factory.parse(prop
+ .getString());
+ }
+ } catch (Exception e) {
+ log.error("Cannot get Deployment Description", e);
+ throw new DeploymentDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public void deleteHostDescription(String hostId) throws RegistryException {
+ Session session = null;
+ try {
+ session = getSession();
+ Node hostNode = getHostNode(session);
+ Node node = hostNode.getNode(hostId);
+ if (node != null) {
+ node.remove();
+ session.save();
+ }
+ } catch (Exception e) {
+ throw new HostDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ }
+
+ public HostDescription getHostDescription(String hostId)
+ throws RegistryException {
+ Session session = null;
+ HostDescription result = null;
+ try {
+ session = getSession();
+ Node hostNode = getHostNode(session);
+ Node node = hostNode.getNode(hostId);
+ if (node != null) {
+ result = getHostDescriptor(node);
+ }
+ } catch (Exception e) {
+ throw new HostDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ private HostDescription getHostDescriptor(Node node)
+ throws RegistryException {
+ HostDescription result;
+ try {
+ Property prop = node.getProperty(XML_PROPERTY_NAME);
+ result = HostDescription.Factory.parse(prop.getString());
+ } catch (Exception e) {
+ throw new HostDescriptionRetrieveException(e);
+ }
+ return result;
+ }
+
+ public String saveHostDescription(HostDescription host) {
+ Session session = null;
+ String result = null;
+ try {
+ session = getSession();
+ Node hostNode = getHostNode(session);
+ Node node = getOrAddNode(hostNode, host.getName());
+ node.setProperty(XML_PROPERTY_NAME, host.xmlText());
+ session.save();
+
+ result = node.getIdentifier();
+ triggerObservers(this);
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public String saveServiceDescription(ServiceDescription service) {
+ Session session = null;
+ String result = null;
+ try {
+ session = getSession();
+ Node serviceNode = getServiceNode(session);
+ Node node = getOrAddNode(serviceNode, service.getName());
+ node.setProperty(XML_PROPERTY_NAME, service.xmlText());
+ session.save();
+
+ result = node.getIdentifier();
+ triggerObservers(this);
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public String saveDeploymentDescription(String serviceId, String hostId,
+ ApplicationDeploymentDescription app) {
+ Session session = null;
+ String result = null;
+ try {
+ session = getSession();
+ Node deployNode = getDeploymentNode(session);
+ Node serviceNode = getOrAddNode(deployNode, serviceId);
+ Node hostNode = getOrAddNode(serviceNode, hostId);
+ Node appName = getOrAddNode(hostNode, app.getName());
+ appName.setProperty(XML_PROPERTY_NAME, app.xmlText());
+ session.save();
+
+ result = appName.getIdentifier();
+ triggerObservers(this);
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public boolean deployServiceOnHost(String serviceId, String hostId) {
+ Session session = null;
+ try {
+ session = getSession();
+ Node serviceRoot = getServiceNode(session);
+ Node hostRoot = getHostNode(session);
+
+ Node serviceNode = serviceRoot.getNode(serviceId);
+ Node hostNode = hostRoot.getNode(hostId);
+
+ if (!serviceNode.hasProperty(LINK_NAME)) {
+ serviceNode.setProperty(LINK_NAME,
+ new String[] { hostNode.getIdentifier() });
+ } else {
+ Property prop = serviceNode.getProperty(LINK_NAME);
+ Value[] vals = prop.getValues();
+ ArrayList<String> s = new ArrayList<String>();
+ for (Value val : vals) {
+ s.add(val.getString());
+ }
+
+ if (s.contains(hostNode.getIdentifier())) {
+ return false;
+ }
+
+ s.add(hostNode.getIdentifier());
+ serviceNode.setProperty(LINK_NAME, s.toArray(new String[0]));
+ }
+
+ session.save();
+ return true;
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return false;
+ }
+
+ public List<ServiceDescription> searchServiceDescription(String name)
+ throws RegistryException {
+ Session session = null;
+ ArrayList<ServiceDescription> result = new ArrayList<ServiceDescription>();
+ try {
+ session = getSession();
+ Node node = getServiceNode(session);
+ NodeIterator nodes = node.getNodes();
+ for (; nodes.hasNext();) {
+ Node service = nodes.nextNode();
+ Property prop = service.getProperty(XML_PROPERTY_NAME);
+ result.add(ServiceDescription.Factory.parse(prop.getString()));
+ }
+ } catch (Exception e) {
+ new ServiceDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public List<HostDescription> searchHostDescription(String nameRegEx)
+ throws RegistryException {
+ Session session = null;
+ List<HostDescription> result = new ArrayList<HostDescription>();
+ try {
+ session = getSession();
+ Node node = getHostNode(session);
+ NodeIterator nodes = node.getNodes();
+ for (; nodes.hasNext();) {
+ Node host = nodes.nextNode();
+ if (host != null && host.getName().matches(nameRegEx)) {
+ HostDescription hostDescriptor = getHostDescriptor(host);
+ result.add(hostDescriptor);
+ }
+ }
+ } catch (Exception e) {
+ throw new HostDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public Map<ApplicationDeploymentDescription, String> searchDeploymentDescription()
+ throws RegistryException {
+ Session session = null;
+ Map<ApplicationDeploymentDescription, String> result = new HashMap<ApplicationDeploymentDescription, String>();
+ try {
+ session = getSession();
+ Node deploymentNode = getDeploymentNode(session);
+ NodeIterator serviceNodes = deploymentNode.getNodes();
+
+ for (; serviceNodes.hasNext();) {
+ Node serviceNode = serviceNodes.nextNode();
+ NodeIterator hostNodes = serviceNode.getNodes();
+
+ for (; hostNodes.hasNext();) {
+ Node hostNode = hostNodes.nextNode();
+ NodeIterator nodes = hostNode.getNodes();
+ for (; nodes.hasNext();) {
+ Node app = nodes.nextNode();
+ Property prop = app.getProperty(XML_PROPERTY_NAME);
+ result.put(ApplicationDeploymentDescription.Factory
+ .parse(prop.getString()), serviceNode.getName()
+ + "$" + hostNode.getName());
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new DeploymentDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public void deleteDeploymentDescription(String serviceName,
+ String hostName, String applicationName)
+ throws RegistryException {
+ Session session = null;
+ try {
+ session = getSession();
+ Node deploymentNode = getDeploymentNode(session);
+ Node serviceNode = deploymentNode.getNode(serviceName);
+ Node hostNode = serviceNode.getNode(hostName);
+ NodeIterator nodes = hostNode.getNodes();
+ for (; nodes.hasNext();) {
+ Node app = nodes.nextNode();
+ Property prop = app.getProperty(XML_PROPERTY_NAME);
+ ApplicationDeploymentDescription appDesc = ApplicationDeploymentDescription.Factory
+ .parse(prop.getString());
+ if (appDesc.getName().matches(applicationName)) {
+ app.remove();
+ }
+ }
+ session.save();
+ } catch (Exception e) {
+ throw new DeploymentDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ }
+
+ public List<ApplicationDeploymentDescription> searchDeploymentDescription(
+ String serviceName, String hostName, String applicationName)
+ throws RegistryException {
+ Session session = null;
+ List<ApplicationDeploymentDescription> result = new ArrayList<ApplicationDeploymentDescription>();
+ try {
+ session = getSession();
+ Node deploymentNode = getDeploymentNode(session);
+ Node serviceNode = deploymentNode.getNode(serviceName);
+ Node hostNode = serviceNode.getNode(hostName);
+ NodeIterator nodes = hostNode.getNodes();
+ for (; nodes.hasNext();) {
+ Node app = nodes.nextNode();
+ Property prop = app.getProperty(XML_PROPERTY_NAME);
+ ApplicationDeploymentDescription appDesc = ApplicationDeploymentDescription.Factory
+ .parse(prop.getString());
+ if (appDesc.getName().matches(applicationName)) {
+ result.add(appDesc);
+ }
+ }
+ } catch (Exception e) {
+ throw new DeploymentDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public List<ApplicationDeploymentDescription> searchDeploymentDescription(
+ String serviceName, String hostName) throws RegistryException {
+ Session session = null;
+ List<ApplicationDeploymentDescription> result = new ArrayList<ApplicationDeploymentDescription>();
+ try {
+ session = getSession();
+ Node deploymentNode = getDeploymentNode(session);
+ Node serviceNode = deploymentNode.getNode(serviceName);
+ Node hostNode = serviceNode.getNode(hostName);
+ NodeIterator nodes = hostNode.getNodes();
+ for (; nodes.hasNext();) {
+ Node app = nodes.nextNode();
+ Property prop = app.getProperty(XML_PROPERTY_NAME);
+ result.add(ApplicationDeploymentDescription.Factory.parse(prop
+ .getString()));
+ }
+ } catch (Exception e) {
+ throw new DeploymentDescriptionRetrieveException(e);
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public String saveWSDL(ServiceDescription service, String WSDL) {
+ Session session = null;
+ String result = null;
+ try {
+ session = getSession();
+ Node serviceNode = getServiceNode(session);
+ Node node = getOrAddNode(serviceNode, service.getName());
+ node.setProperty(WSDL_PROPERTY_NAME, WSDL);
+ session.save();
+
+ result = node.getIdentifier();
+ triggerObservers(this);
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public String saveWSDL(ServiceDescription service) {
+ return saveWSDL(service, WebServiceUtil.generateWSDL(service));
+ }
+
+ public String getWSDL(String serviceName) {
+ Session session = null;
+ String result = null;
+ try {
+ session = getSession();
+ Node serviceNode = getServiceNode(session);
+ Node node = serviceNode.getNode(serviceName);
+ Property prop = node.getProperty(WSDL_PROPERTY_NAME);
+ result = prop.getString();
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public boolean saveGFacDescriptor(String gfacURL) {
+ java.util.Date today = Calendar
+ .getInstance(TimeZone.getTimeZone("GMT")).getTime();
+ Timestamp timestamp = new Timestamp(today.getTime());
+ Session session = null;
+ try {
+ URI uri = new URI(gfacURL);
+ String propertyName = uri.getHost() + "-" + uri.getPort();
+ session = getSession();
+ Node gfacDataNode = getOrAddNode(session.getRootNode(),
+ GFAC_INSTANCE_DATA);
+ try {
+ Property prop = gfacDataNode.getProperty(propertyName);
+ prop.setValue(gfacURL + ";" + timestamp.getTime());
+ session.save();
+ } catch (PathNotFoundException e) {
+ gfacDataNode.setProperty(propertyName, gfacURL + ";"
+ + timestamp.getTime());
+ session.save();
+ }
+ triggerObservers(this);
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ return false;
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return true;
+ }
+
+ public boolean deleteGFacDescriptor(String gfacURL) {
+ Session session = null;
+ try {
+ URI uri = new URI(gfacURL);
+ String propertyName = uri.getHost() + "-" + uri.getPort();
+ session = getSession();
+ Node gfacDataNode = getOrAddNode(session.getRootNode(),
+ GFAC_INSTANCE_DATA);
+ Property prop = gfacDataNode.getProperty(propertyName);
+ prop.setValue((String) null);
+ session.save();
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ return false;
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return true;
+ }
+
+ public List<String> getGFacDescriptorList() {
+ Session session = null;
+ List<String> urlList = new ArrayList<String>();
+ java.util.Date today = Calendar
+ .getInstance(TimeZone.getTimeZone("GMT")).getTime();
+ Timestamp timestamp = new Timestamp(today.getTime());
+ try {
+ session = getSession();
+ Node gfacNode = getOrAddNode(session.getRootNode(),
+ GFAC_INSTANCE_DATA);
+ PropertyIterator propertyIterator = gfacNode.getProperties();
+ while (propertyIterator.hasNext()) {
+ Property property = propertyIterator.nextProperty();
+ if (!"nt:unstructured".equals(property.getString())) {
+ String x = property.getString();
+ Timestamp setTime = new Timestamp(new Long(property
+ .getString().split(";")[1]));
+ if (GFAC_URL_UPDATE_INTERVAL > (timestamp.getTime() - setTime
+ .getTime())) {
+ urlList.add(property.getString().split(";")[0]);
+ }
+ }
+ }
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ }
+ return urlList;
+ }
+
+ public UserManager getUserManager() {
+ return userManager;
+ }
+
+ public void setUserManager(UserManager userManager) {
+ this.userManager = userManager;
+ }
+
+ public String saveOutput(String workflowId, List<Parameter> parameters) {
+ Session session = null;
+ String result = null;
+ try {
+ session = getSession();
+ Node outputNode = getOrAddNode(session.getRootNode(),
+ OUTPUT_NODE_NAME);
+ Node node = getOrAddNode(outputNode, workflowId);
+ for (int i = 0; i < parameters.size(); i++) {
+ node.setProperty(String.valueOf(i), parameters.get(i).xmlText());
+ }
+
+ session.save();
+
+ result = node.getIdentifier();
+ triggerObservers(this);
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public List<Parameter> loadOutput(String workflowId) {
+ Session session = null;
+ ArrayList<Parameter> result = new ArrayList<Parameter>();
+ try {
+ session = getSession();
+ Node outputNode = getOrAddNode(session.getRootNode(),
+ OUTPUT_NODE_NAME);
+ Node node = outputNode.getNode(workflowId);
+
+ PropertyIterator it = node.getProperties();
+ while (it.hasNext()) {
+ Property prop = (Property) it.next();
+ result.add(Parameter.Factory.parse(prop.getString()));
+ }
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ // TODO propagate
+ } finally {
+ closeSession(session);
+ }
+ return result;
+ }
+
+ public Map<QName, Node> getWorkflows(String userName) {
+ Session session = null;
+ Map<QName, Node> workflowList = new HashMap<QName, Node>();
+ try {
+ session = getSession();
+ Node workflowListNode = getOrAddNode(
+ getOrAddNode(session.getRootNode(), WORKFLOWS), PUBLIC);
+ NodeIterator iterator = workflowListNode.getNodes();
+ while (iterator.hasNext()) {
+ Node nextNode = iterator.nextNode();
+ workflowList.put(new QName(nextNode.getName()), nextNode);
+ }
+ workflowListNode = getOrAddNode(
+ getOrAddNode(session.getRootNode(), WORKFLOWS), userName);
+ iterator = workflowListNode.getNodes();
+ while (iterator.hasNext()) {
+ Node nextNode = iterator.nextNode();
+ workflowList.put(new QName(nextNode.getName()), nextNode);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return workflowList;
+ }
+
+ public Node getWorkflow(QName templateID, String userName) {
+ Session session = null;
+ Node result = null;
+ try {
+ session = getSession();
+ Node workflowListNode = getOrAddNode(
+ getOrAddNode(session.getRootNode(), WORKFLOWS), userName);
+ result = getOrAddNode(workflowListNode, templateID.getLocalPart());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ public boolean saveWorkflow(QName ResourceID, String workflowName,
+ String resourceDesc, String workflowAsaString, String owner,
+ boolean isMakePublic) {
+ Session session = null;
+ try {
+ session = getSession();
+ Node workflowListNode = getOrAddNode(session.getRootNode(),
+ WORKFLOWS);
+ Node workflowNode = null;
+ if (isMakePublic) {
+ workflowNode = getOrAddNode(
+ getOrAddNode(workflowListNode, PUBLIC), workflowName);
+ } else {
+ workflowNode = getOrAddNode(
+ getOrAddNode(workflowListNode, owner), workflowName);
+ }
+ workflowNode.setProperty("workflow", workflowAsaString);
+ workflowNode.setProperty("Prefix", ResourceID.getPrefix());
+ workflowNode.setProperty("LocalPart", ResourceID.getLocalPart());
+ workflowNode.setProperty("NamespaceURI",
+ ResourceID.getNamespaceURI());
+ workflowNode.setProperty("public", isMakePublic);
+ workflowNode.setProperty("Description", resourceDesc);
+ workflowNode.setProperty("Type", REGISTRY_TYPE_WORKFLOW);
+ session.save();
+ triggerObservers(this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ closeSession(session);
+ return true;
+ }
+ }
+
+ public boolean deleteWorkflow(QName resourceID, String userName) {
+ Session session = null;
+ try {
+ session = getSession();
+ Node workflowListNode = getOrAddNode(
+ getOrAddNode(session.getRootNode(), WORKFLOWS), userName);
+ Node result = getOrAddNode(workflowListNode,
+ resourceID.getLocalPart());
+ result.remove();
+ session.save();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ closeSession(session);
+ }
+ return false;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public URI getRepositoryURI() {
+ return repositoryURI;
+ }
+
+ private void setRepositoryURI(URI repositoryURI) {
+ this.repositoryURI = repositoryURI;
+ }
+
+ protected void triggerObservers(Object o) {
+ setChanged();
+ notifyObservers(o);
+ }
+
+ public String getName() {
+ return repository.getDescriptor(Repository.REP_NAME_DESC);
+ }
+
+ public boolean saveWorkflowData(String data, String experimentId,
+ String nodeId) {
+ Session session = null;
+ try {
+ session = getSession();
+ Node workflowDataNode = getOrAddNode(
+ getOrAddNode(
+ getOrAddNode(session.getRootNode(), WORKFLOW_DATA),
+ experimentId), nodeId);
+ workflowDataNode.setProperty("content", data);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ closeSession(session);
+ return true;
+ }
- }
+ }
}