You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ch...@apache.org on 2014/05/30 21:54:06 UTC

[11/11] git commit: adding proper entity manager closing and exception handling - AIRAVATA-1285

adding proper entity manager closing and exception handling - AIRAVATA-1285


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

Branch: refs/heads/master
Commit: bf5f8c3c53f9aa8e1c86fc1238c6707fcbfbe091
Parents: 0fadb08
Author: Chathuri Wimalasena <ka...@gmail.com>
Authored: Fri May 30 15:53:04 2014 -0400
Committer: Chathuri Wimalasena <ka...@gmail.com>
Committed: Fri May 30 15:53:04 2014 -0400

----------------------------------------------------------------------
 .../server/handler/AiravataServerHandler.java   |  102 +-
 .../handler/ApplicationCatalogHandler.java      |    4 +-
 .../samples/TestCreateLaunchExperiment.java     |    6 +-
 .../apache/airavata/client/AiravataClient.java  |    8 +-
 .../client/api/CredentialStoreManager.java      |    9 +-
 .../airavata/client/api/ProvenanceManager.java  |    5 +-
 .../client/impl/ApplicationManagerImpl.java     |   26 +-
 .../client/impl/ProvenanceManagerImpl.java      |    4 +-
 .../client/impl/WorkflowManagerImpl.java        |   10 +-
 .../airavata/gfac/server/GfacServerHandler.java |    9 +-
 .../gfac/client/GfacClientFactoryTest.java      |    2 +-
 .../airavata/gfac/client/util/Initialize.java   |    3 +
 .../gfac/core/handler/AbstractHandler.java      |    7 +-
 .../gfac/core/provider/AbstractProvider.java    |    7 +-
 .../server/OrchestratorServerHandler.java       |    2 +
 .../client/OrchestratorClientFactoryTest.java   |    2 +-
 .../orchestrator/client/util/Initialize.java    |    3 +
 .../client/sample/OrchestratorClientSample.java |    3 +
 .../core/utils/OrchestratorUtils.java           |    4 +-
 .../validator/impl/SimpleAppDataValidator.java  |    7 +-
 .../cpi/impl/AbstractOrchestrator.java          |   11 +-
 .../orchestrator/core/util/Initialize.java      |    3 +
 .../persistance/registry/jpa/Resource.java      |   14 +-
 .../persistance/registry/jpa/ResourceUtils.java |  279 ++--
 .../registry/jpa/impl/AiravataJPARegistry.java  | 1435 ++++++++++--------
 .../registry/jpa/impl/ExperimentRegistry.java   |  421 ++---
 .../registry/jpa/impl/GatewayRegistry.java      |    5 +-
 .../registry/jpa/impl/ProjectRegistry.java      |   35 +-
 .../registry/jpa/impl/RegistryFactory.java      |   26 +-
 .../registry/jpa/impl/RegistryImpl.java         |    4 +-
 .../persistance/registry/jpa/impl/UserReg.java  |   11 +-
 .../jpa/resources/AbstractResource.java         |    5 +-
 .../AdvanceInputDataHandlingResource.java       |   80 +-
 .../AdvancedOutputDataHandlingResource.java     |   78 +-
 ...avataRegistryConnectionDataProviderImpl.java |    5 -
 .../ApplicationDescriptorResource.java          |   50 +-
 .../jpa/resources/ApplicationInputResource.java |   85 +-
 .../resources/ApplicationOutputResource.java    |   87 +-
 .../ComputationSchedulingResource.java          |   88 +-
 .../jpa/resources/ConfigDataResource.java       |   79 +-
 .../jpa/resources/ConfigurationResource.java    |   46 +-
 .../resources/DataTransferDetailResource.java   |  231 +--
 .../jpa/resources/ErrorDetailResource.java      |   84 +-
 .../jpa/resources/ExperimentInputResource.java  |   74 +-
 .../jpa/resources/ExperimentOutputResource.java |   33 +-
 .../jpa/resources/ExperimentResource.java       |  651 ++++----
 .../registry/jpa/resources/GatewayResource.java |  799 +++++-----
 .../jpa/resources/HostDescriptorResource.java   |   89 +-
 .../jpa/resources/JobDetailResource.java        |  293 ++--
 .../jpa/resources/NodeInputResource.java        |   85 +-
 .../jpa/resources/NodeOutputResource.java       |   86 +-
 .../registry/jpa/resources/ProjectResource.java |  280 ++--
 .../jpa/resources/ProjectUserResource.java      |   80 +-
 .../jpa/resources/PublishWorkflowResource.java  |  105 +-
 .../jpa/resources/QosParamResource.java         |   64 +-
 .../resources/ServiceDescriptorResource.java    |  121 +-
 .../registry/jpa/resources/StatusResource.java  |   99 +-
 .../jpa/resources/TaskDetailResource.java       |  660 ++++----
 .../registry/jpa/resources/UserResource.java    |   74 +-
 .../jpa/resources/UserWorkflowResource.java     |  111 +-
 .../registry/jpa/resources/WorkerResource.java  |  499 +++---
 .../resources/WorkflowNodeDetailResource.java   |  452 +++---
 .../jpa/utils/ThriftDataModelConversion.java    |   25 +-
 .../registry/jpa/util/Initialize.java           |    3 +
 .../registry/api/AiravataRegistry2.java         |    6 +-
 .../AiravataRegistryConnectionDataProvider.java |    1 -
 .../registry/api/AiravataRegistryFactory.java   |   54 +-
 .../registry/api/ConfigurationRegistry.java     |   50 +-
 .../registry/api/CredentialRegistry.java        |   18 +-
 .../airavata/registry/api/DataRegistry.java     |   10 +-
 .../registry/api/DescriptorRegistry.java        |   52 +-
 .../registry/api/OrchestratorRegistry.java      |   38 +-
 .../airavata/registry/api/ProjectsRegistry.java |   26 +-
 .../registry/api/ProvenanceRegistry.java        |  244 +--
 .../registry/api/PublishedWorkflowRegistry.java |   18 +-
 .../airavata/registry/api/UserRegistry.java     |    6 +-
 .../registry/api/UserWorkflowRegistry.java      |   16 +-
 .../airavata/registry/api/WorkspaceProject.java |    8 +-
 .../AiravataRegUninitializedException.java      |   32 +
 .../AiravataRegistryUninitializedException.java |   32 -
 .../DeploymentDescriptionRetrieveException.java |    2 +-
 .../GatewayNotRegisteredException.java          |    2 +-
 .../HostDescriptionRetrieveException.java       |    2 +-
 .../RegAPIVersionIncompatibleException.java     |   39 +
 .../RegAccessorInstantiateException.java        |   32 +
 .../exception/RegAccessorInvalidException.java  |   32 +
 .../exception/RegAccessorNotFoundException.java |   32 +
 .../RegAccessorUndefinedException.java          |   40 +
 .../registry/api/exception/RegException.java    |   39 +
 ...RegistryAPIVersionIncompatibleException.java |   41 -
 .../RegistryAccessorInstantiateException.java   |   32 -
 .../RegistryAccessorInvalidException.java       |   32 -
 .../RegistryAccessorNotFoundException.java      |   32 -
 .../RegistryAccessorUndefinedException.java     |   40 -
 .../api/exception/RegistryException.java        |   39 -
 .../ServiceDescriptionRetrieveException.java    |    2 +-
 .../UnimplementedRegOperationException.java     |   32 +
 ...UnimplementedRegistryOperationException.java |   32 -
 .../UnknownRegConnectionDataException.java      |   36 +
 .../UnknownRegistryConnectionDataException.java |   36 -
 .../DescriptorAlreadyExistsException.java       |    4 +-
 .../DescriptorDoesNotExistsException.java       |    4 +-
 .../gateway/InsufficientDataException.java      |    4 +-
 .../gateway/MalformedDescriptorException.java   |    4 +-
 ...PublishedWorkflowAlreadyExistsException.java |    4 +-
 ...PublishedWorkflowDoesNotExistsException.java |    4 +-
 .../ApplicationJobAlreadyExistsException.java   |    4 +-
 .../ApplicationJobDoesNotExistsException.java   |    4 +-
 .../ExperimentAlreadyExistsException.java       |    4 +-
 .../ExperimentDoesNotExistsException.java       |    4 +-
 .../InvalidApplicationJobIDException.java       |    4 +-
 .../UserWorkflowAlreadyExistsException.java     |    4 +-
 .../UserWorkflowDoesNotExistsException.java     |    4 +-
 .../WorkflowInstanceAlreadyExistsException.java |    4 +-
 .../WorkflowInstanceDoesNotExistsException.java |    4 +-
 ...kflowInstanceNodeAlreadyExistsException.java |    4 +-
 ...kflowInstanceNodeDoesNotExistsException.java |    4 +-
 .../WorkspaceProjectAlreadyExistsException.java |    4 +-
 .../WorkspaceProjectDoesNotExistsException.java |    4 +-
 .../registry/api/util/RegistryUtils.java        |   29 +-
 120 files changed, 5066 insertions(+), 4292 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
index 8615480..c808713 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
@@ -162,15 +162,15 @@ public class AiravataServerHandler implements Airavata.Iface {
             exception.setMessage("Username cannot be empty. Please provide a valid user..");
             throw exception;
         }
-        if (!ResourceUtils.isUserExist(userName)){
-            logger.error("User does not exist in the system. Please provide a valid user..");
-            AiravataSystemException exception = new AiravataSystemException();
-            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
-            exception.setMessage("User does not exist in the system. Please provide a valid user..");
-            throw exception;
-        }
         List<Project> projects = new ArrayList<Project>();
         try {
+            if (!ResourceUtils.isUserExist(userName)){
+                logger.error("User does not exist in the system. Please provide a valid user..");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("User does not exist in the system. Please provide a valid user..");
+                throw exception;
+            }
             registry = RegistryFactory.getDefaultRegistry();
             List<Object> list = registry.get(RegistryModelType.PROJECT, Constants.FieldConstants.ProjectConstants.OWNER, userName);
             if (list != null && !list.isEmpty()){
@@ -199,14 +199,14 @@ public class AiravataServerHandler implements Airavata.Iface {
             exception.setMessage("Username cannot be empty. Please provide a valid user..");
             throw exception;
         }
-        if (!ResourceUtils.isUserExist(userName)){
-            logger.error("User does not exist in the system. Please provide a valid user..");
-            AiravataSystemException exception = new AiravataSystemException();
-            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
-            exception.setMessage("User does not exist in the system. Please provide a valid user..");
-            throw exception;
-        }
         try {
+            if (!ResourceUtils.isUserExist(userName)){
+                logger.error("User does not exist in the system. Please provide a valid user..");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("User does not exist in the system. Please provide a valid user..");
+                throw exception;
+            }
             List<Project> projects = new ArrayList<Project>();
             registry = RegistryFactory.getDefaultRegistry();
             Map<String, String> filters = new HashMap<String, String>();
@@ -237,14 +237,14 @@ public class AiravataServerHandler implements Airavata.Iface {
             exception.setMessage("Username cannot be empty. Please provide a valid user..");
             throw exception;
         }
-        if (!ResourceUtils.isUserExist(userName)){
-            logger.error("User does not exist in the system. Please provide a valid user..");
-            AiravataSystemException exception = new AiravataSystemException();
-            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
-            exception.setMessage("User does not exist in the system. Please provide a valid user..");
-            throw exception;
-        }
         try {
+            if (!ResourceUtils.isUserExist(userName)){
+                logger.error("User does not exist in the system. Please provide a valid user..");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("User does not exist in the system. Please provide a valid user..");
+                throw exception;
+            }
             List<Project> projects = new ArrayList<Project>();
             registry = RegistryFactory.getDefaultRegistry();
             Map<String, String> filters = new HashMap<String, String>();
@@ -275,14 +275,14 @@ public class AiravataServerHandler implements Airavata.Iface {
             exception.setMessage("Username cannot be empty. Please provide a valid user..");
             throw exception;
         }
-        if (!ResourceUtils.isUserExist(userName)){
-            logger.error("User does not exist in the system. Please provide a valid user..");
-            AiravataSystemException exception = new AiravataSystemException();
-            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
-            exception.setMessage("User does not exist in the system. Please provide a valid user..");
-            throw exception;
-        }
         try {
+            if (!ResourceUtils.isUserExist(userName)){
+                logger.error("User does not exist in the system. Please provide a valid user..");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("User does not exist in the system. Please provide a valid user..");
+                throw exception;
+            }
             List<ExperimentSummary> summaries = new ArrayList<ExperimentSummary>();
             registry = RegistryFactory.getDefaultRegistry();
             Map<String, String> filters = new HashMap<String, String>();
@@ -313,14 +313,14 @@ public class AiravataServerHandler implements Airavata.Iface {
             exception.setMessage("Username cannot be empty. Please provide a valid user..");
             throw exception;
         }
-        if (!ResourceUtils.isUserExist(userName)){
-            logger.error("User does not exist in the system. Please provide a valid user..");
-            AiravataSystemException exception = new AiravataSystemException();
-            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
-            exception.setMessage("User does not exist in the system. Please provide a valid user..");
-            throw exception;
-        }
         try {
+            if (!ResourceUtils.isUserExist(userName)){
+                logger.error("User does not exist in the system. Please provide a valid user..");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("User does not exist in the system. Please provide a valid user..");
+                throw exception;
+            }
             List<ExperimentSummary> summaries = new ArrayList<ExperimentSummary>();
             registry = RegistryFactory.getDefaultRegistry();
             Map<String, String> filters = new HashMap<String, String>();
@@ -348,14 +348,14 @@ public class AiravataServerHandler implements Airavata.Iface {
             exception.setMessage("Username cannot be empty. Please provide a valid user..");
             throw exception;
         }
-        if (!ResourceUtils.isUserExist(userName)){
-            logger.error("User does not exist in the system. Please provide a valid user..");
-            AiravataSystemException exception = new AiravataSystemException();
-            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
-            exception.setMessage("User does not exist in the system. Please provide a valid user..");
-            throw exception;
-        }
         try {
+            if (!ResourceUtils.isUserExist(userName)){
+                logger.error("User does not exist in the system. Please provide a valid user..");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("User does not exist in the system. Please provide a valid user..");
+                throw exception;
+            }
             List<ExperimentSummary> summaries = new ArrayList<ExperimentSummary>();
             registry = RegistryFactory.getDefaultRegistry();
             Map<String, String> filters = new HashMap<String, String>();
@@ -431,14 +431,14 @@ public class AiravataServerHandler implements Airavata.Iface {
             exception.setMessage("Username cannot be empty. Please provide a valid user..");
             throw exception;
         }
-        if (!ResourceUtils.isUserExist(userName)){
-            logger.error("User does not exist in the system. Please provide a valid user..");
-            AiravataSystemException exception = new AiravataSystemException();
-            exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
-            exception.setMessage("User does not exist in the system. Please provide a valid user..");
-            throw exception;
-        }
         try {
+            if (!ResourceUtils.isUserExist(userName)){
+                logger.error("User does not exist in the system. Please provide a valid user..");
+                AiravataSystemException exception = new AiravataSystemException();
+                exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
+                exception.setMessage("User does not exist in the system. Please provide a valid user..");
+                throw exception;
+            }
             List<Experiment> experiments = new ArrayList<Experiment>();
             registry = RegistryFactory.getDefaultRegistry();
             List<Object> list = registry.get(RegistryModelType.EXPERIMENT, Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
@@ -717,8 +717,8 @@ public class AiravataServerHandler implements Airavata.Iface {
      */
     @Override
     public boolean validateExperiment(String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, TException {
-    	 registry = RegistryFactory.getDefaultRegistry();
      	try {
+            registry = RegistryFactory.getDefaultRegistry();
  			if (!registry.isExist(RegistryModelType.EXPERIMENT, airavataExperimentId)){
  			    throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system..");
  			}
@@ -871,8 +871,8 @@ public class AiravataServerHandler implements Airavata.Iface {
      */
     @Override
     public void launchExperiment(String airavataExperimentId, String airavataCredStoreToken) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, LaunchValidationException, TException {
-    	 registry = RegistryFactory.getDefaultRegistry();
     	try {
+            registry = RegistryFactory.getDefaultRegistry();
 			if (!registry.isExist(RegistryModelType.EXPERIMENT, airavataExperimentId)){
 			    throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system..");
 			}

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/ApplicationCatalogHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/ApplicationCatalogHandler.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/ApplicationCatalogHandler.java
index 85357de..b3ce8fb 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/ApplicationCatalogHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/ApplicationCatalogHandler.java
@@ -54,7 +54,7 @@ import org.apache.airavata.registry.api.AiravataRegistry2;
 import org.apache.airavata.registry.api.AiravataRegistryFactory;
 import org.apache.airavata.registry.api.AiravataUser;
 import org.apache.airavata.registry.api.Gateway;
-import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.exception.RegException;
 import org.apache.airavata.schemas.gfac.ExportProperties;
 import org.apache.airavata.schemas.gfac.GlobusHostType;
 import org.apache.airavata.schemas.gfac.GsisshHostType;
@@ -67,7 +67,7 @@ public class ApplicationCatalogHandler implements Iface {
     private static final Logger logger = LoggerFactory.getLogger(AiravataServerHandler.class);
 
 	AiravataRegistry2 registry;
-	private AiravataRegistry2 getRegistry() throws RegistryException, AiravataConfigurationException{
+	private AiravataRegistry2 getRegistry() throws RegException, AiravataConfigurationException{
 		 if (registry==null){
 			 registry = AiravataRegistryFactory.getRegistry(new Gateway("default"), new AiravataUser("admin"));
 		 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java
index 8dc907b..666e140 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/TestCreateLaunchExperiment.java
@@ -110,10 +110,12 @@ public class TestCreateLaunchExperiment {
 //                }
 //            }
 
-            for (int i = 0; i < 100 ; i++){
+            for (int i = 0; i < 500 ; i++){
                 long time = System.currentTimeMillis();
                 List<Experiment> experiments = getExperimentsForUser(airavata, "admin");
-                System.out.println("Experiment count : " + experiments.size());
+                int count = i+1;
+//                System.out.println("Experiment count : " + experiments.size());
+                System.out.println("iteration : " + String.valueOf(count));
                 System.out.println(System.currentTimeMillis() - time);
             }
 //            List<Experiment> experiments = getExperimentsForUser(airavata, "admin");

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java
----------------------------------------------------------------------
diff --git a/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java b/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java
index 235c6e4..d516918 100644
--- a/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java
+++ b/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java
@@ -58,7 +58,7 @@ import org.apache.airavata.registry.api.AiravataRegistryFactory;
 import org.apache.airavata.registry.api.AiravataUser;
 import org.apache.airavata.registry.api.Gateway;
 import org.apache.airavata.registry.api.PasswordCallback;
-import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.exception.RegException;
 import org.apache.airavata.workflow.model.wf.WorkflowInput;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -107,7 +107,7 @@ public class AiravataClient extends Observable implements AiravataAPI {
 
 	private static HashMap<String, String> createConfig(URI registryUrl, String gateway,
 			String username, String password) throws RepositoryException,
-			RegistryException, AiravataConfigurationException {
+            RegException, AiravataConfigurationException {
 		HashMap<String, String> config = new HashMap<String, String>();
 		if (registryUrl != null) {
 			config.put(AiravataClient.REGISTRY, registryUrl.toString());
@@ -291,7 +291,7 @@ public class AiravataClient extends Observable implements AiravataAPI {
 	}
 
 	public AiravataRegistry2 getRegistryClient()
-			throws AiravataConfigurationException, RegistryException {
+			throws AiravataConfigurationException, RegException {
 		if (registry == null) {
 			registry = getRegistry(getRegitryURI(), getGateway(),
 					getCurrentUser(), getCallBack());
@@ -301,7 +301,7 @@ public class AiravataClient extends Observable implements AiravataAPI {
 
 	public static AiravataRegistry2 getRegistry(URI registryURI,
 			String gateway, String username, PasswordCallback callback)
-			throws RegistryException, AiravataConfigurationException {
+			throws RegException, AiravataConfigurationException {
 		return AiravataRegistryFactory.getRegistry(registryURI, new Gateway(
 				gateway), new AiravataUser(username), callback);
 	}

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java b/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java
index b110abd..418c944 100644
--- a/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java
+++ b/modules/airavata-client/src/main/java/org/apache/airavata/client/api/CredentialStoreManager.java
@@ -22,7 +22,6 @@
 package org.apache.airavata.client.api;
 
 import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
-import org.apache.airavata.registry.api.exception.RegistryException;
 
 public interface CredentialStoreManager {
 
@@ -31,7 +30,7 @@ public interface CredentialStoreManager {
 	 * @param String gatewayId
 	 * @param String tokenId
 	 * @return a boolean (true is credential exists, false if not)
-	 * @throws RegistryException
+	 * @throws org.apache.airavata.registry.api.exception.RegException
 	 */
 	public boolean isCredentialExist(String gatewayId, String tokenId) throws AiravataAPIInvocationException;
 	
@@ -40,7 +39,7 @@ public interface CredentialStoreManager {
 	 * @param String gatewayId
 	 * @param String tokenId
 	 * @return String The public key of the credential
-	 * @throws RegistryException
+	 * @throws org.apache.airavata.registry.api.exception.RegException
 	 */
 	public String getCredentialPublicKey(String gatewayId, String tokenId) throws AiravataAPIInvocationException;
 	
@@ -50,7 +49,7 @@ public interface CredentialStoreManager {
 	 * @param String gatewayId
 	 * @param String tokenId
 	 * @return String The public key of the credential
-	 * @throws RegistryException
+	 * @throws org.apache.airavata.registry.api.exception.RegException
 	 */
 	public String createCredential(String gatewayId, String tokenId) throws AiravataAPIInvocationException;
 	
@@ -61,7 +60,7 @@ public interface CredentialStoreManager {
 	 * @param String tokenId
 	 * @param String username
 	 * @return String The public key of the credential
-	 * @throws RegistryException
+	 * @throws org.apache.airavata.registry.api.exception.RegException
 	 */
 	public String createCredential(String gatewayId, String tokenId, String username) throws AiravataAPIInvocationException;
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/airavata-client/src/main/java/org/apache/airavata/client/api/ProvenanceManager.java
----------------------------------------------------------------------
diff --git a/modules/airavata-client/src/main/java/org/apache/airavata/client/api/ProvenanceManager.java b/modules/airavata-client/src/main/java/org/apache/airavata/client/api/ProvenanceManager.java
index d1d4c38..3c0d5ec 100644
--- a/modules/airavata-client/src/main/java/org/apache/airavata/client/api/ProvenanceManager.java
+++ b/modules/airavata-client/src/main/java/org/apache/airavata/client/api/ProvenanceManager.java
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
-import org.apache.airavata.registry.api.exception.RegistryException;
 import org.apache.airavata.registry.api.workflow.ApplicationJobStatusData;
 import org.apache.airavata.registry.api.workflow.ExperimentData;
 import org.apache.airavata.registry.api.workflow.ExperimentMetadata;
@@ -372,7 +371,7 @@ public interface ProvenanceManager {
       * Returns <code>true</code> if a Application job data is existing in Airavata
       * @param jobId
       * @return
-      * @throws RegistryException
+      * @throws org.apache.airavata.registry.api.exception.RegException
       */
      public boolean isApplicationJobExists(String jobId) throws AiravataAPIInvocationException;
      
@@ -403,7 +402,7 @@ public interface ProvenanceManager {
 	 * Update the status of the job for the current server time
 	 * @param jobId
 	 * @param status
-	 * @throws RegistryException
+	 * @throws org.apache.airavata.registry.api.exception.RegException
 	 */
      public void updateApplicationJobStatus(String jobId, ApplicationJobStatus status) throws AiravataAPIInvocationException;
      

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ApplicationManagerImpl.java
----------------------------------------------------------------------
diff --git a/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ApplicationManagerImpl.java b/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ApplicationManagerImpl.java
index 1fea53d..804ca40 100644
--- a/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ApplicationManagerImpl.java
+++ b/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ApplicationManagerImpl.java
@@ -34,8 +34,8 @@ import org.apache.airavata.common.exception.AiravataConfigurationException;
 import org.apache.airavata.commons.gfac.type.ApplicationDescription;
 import org.apache.airavata.commons.gfac.type.HostDescription;
 import org.apache.airavata.commons.gfac.type.ServiceDescription;
-import org.apache.airavata.registry.api.exception.RegistryException;
-import org.apache.airavata.registry.api.exception.UnimplementedRegistryOperationException;
+import org.apache.airavata.registry.api.exception.RegException;
+import org.apache.airavata.registry.api.exception.UnimplementedRegOperationException;
 
 public class ApplicationManagerImpl implements ApplicationManager {
 	private AiravataClient client;
@@ -93,7 +93,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
             throw new DescriptorAlreadyExistsException("Service descriptor "
                     + serviceDescription.getType().getName()
                     + " already exists.", e);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new AiravataAPIInvocationException("An internal error occurred while trying to add service descriptor"
                     + serviceDescription.getType().getName(),
                     e);
@@ -108,7 +108,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
     public void updateServiceDescription(ServiceDescription serviceDescription) throws AiravataAPIInvocationException {
         try {
             getClient().getRegistryClient().updateServiceDescriptor(serviceDescription);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new AiravataAPIInvocationException("An internal error occurred while trying to add service descriptor"
                     + serviceDescription.getType().getName(),
                     e);
@@ -134,7 +134,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
 	@Override
 	public List<ServiceDescription> searchServiceDescription(String nameRegEx)
 			throws AiravataAPIInvocationException {
-		throw new AiravataAPIInvocationException(new UnimplementedRegistryOperationException());
+		throw new AiravataAPIInvocationException(new UnimplementedRegOperationException());
 	}
 
 	@Override
@@ -178,7 +178,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
                     applicationDeploymentDescription.getType().getApplicationName().getStringValue()
                     + " already associated to host " + hostDescription.getType().getHostName()
                     + " and service " + serviceDescription.getType().getName(), e);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
 
             throw new AiravataAPIInvocationException("An internal error occurred while trying to add " +
                     "application descriptor " +
@@ -204,7 +204,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
         try {
             getClient().getRegistryClient().updateApplicationDescriptor(serviceDescription.getType().getName(),
                     hostDescription.getType().getHostName(), applicationDeploymentDescription);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
 
             throw new AiravataAPIInvocationException("An internal error occurred while trying to add " +
                     "application descriptor " +
@@ -227,7 +227,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
 	public List<ApplicationDescription> searchApplicationDescription(
             String serviceName, String hostName)
 			throws AiravataAPIInvocationException {
-		throw new AiravataAPIInvocationException(new UnimplementedRegistryOperationException());
+		throw new AiravataAPIInvocationException(new UnimplementedRegOperationException());
 	}
 
 	@Override
@@ -244,7 +244,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
 	public List<ApplicationDescription> searchApplicationDescription(
             String serviceName, String hostName, String applicationName)
 			throws AiravataAPIInvocationException {
-		throw new AiravataAPIInvocationException(new UnimplementedRegistryOperationException());
+		throw new AiravataAPIInvocationException(new UnimplementedRegOperationException());
 	}
 
 	@Override
@@ -319,7 +319,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
         } catch (org.apache.airavata.registry.api.exception.gateway.DescriptorAlreadyExistsException e) {
             throw new DescriptorAlreadyExistsException("Host descriptor " + host.getType().getHostName()
                     + " already exists.", e);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new AiravataAPIInvocationException("An internal error occurred while trying to add host descriptor"
                     + host.getType().getHostName(),
                     e);
@@ -335,7 +335,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
     public void updateHostDescription(HostDescription host) throws AiravataAPIInvocationException {
         try {
             getClient().getRegistryClient().updateHostDescriptor(host);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new AiravataAPIInvocationException("An internal error occurred while trying to add host descriptor"
                     + host.getType().getHostName(),
                     e);
@@ -350,7 +350,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
     @Override
 	public List<HostDescription> searchHostDescription(String regExName)
 			throws AiravataAPIInvocationException {
-		throw new AiravataAPIInvocationException(new UnimplementedRegistryOperationException());
+		throw new AiravataAPIInvocationException(new UnimplementedRegOperationException());
 	}
 
 	@Override
@@ -366,7 +366,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
 	@Override
 	public boolean deployServiceOnHost(String serviceName, String hostName)
 			throws AiravataAPIInvocationException {
-		throw new AiravataAPIInvocationException(new UnimplementedRegistryOperationException());
+		throw new AiravataAPIInvocationException(new UnimplementedRegOperationException());
 	}
 
     @Override

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ProvenanceManagerImpl.java
----------------------------------------------------------------------
diff --git a/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ProvenanceManagerImpl.java b/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ProvenanceManagerImpl.java
index 293bca8..d311fbf 100644
--- a/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ProvenanceManagerImpl.java
+++ b/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/ProvenanceManagerImpl.java
@@ -32,7 +32,7 @@ import org.apache.airavata.client.api.ProvenanceManager;
 import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
 import org.apache.airavata.common.exception.AiravataConfigurationException;
 import org.apache.airavata.registry.api.AiravataExperiment;
-import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.exception.RegException;
 import org.apache.airavata.registry.api.workflow.ApplicationJob;
 import org.apache.airavata.registry.api.workflow.ApplicationJob.ApplicationJobStatus;
 import org.apache.airavata.registry.api.workflow.ApplicationJobStatusData;
@@ -498,7 +498,7 @@ public class ProvenanceManagerImpl implements ProvenanceManager {
     public void updateWorkflowNodeGramData(WorkflowNodeGramData data) throws AiravataAPIInvocationException {
         try {
             client.getRegistryClient().updateWorkflowNodeGramData(data);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new AiravataAPIInvocationException(e);
         } catch (AiravataConfigurationException e) {
             throw new AiravataAPIInvocationException(e);

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/WorkflowManagerImpl.java
----------------------------------------------------------------------
diff --git a/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/WorkflowManagerImpl.java b/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/WorkflowManagerImpl.java
index 608db5a..484fd57 100644
--- a/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/WorkflowManagerImpl.java
+++ b/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/WorkflowManagerImpl.java
@@ -33,7 +33,7 @@ import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
 import org.apache.airavata.client.api.exception.WorkflowAlreadyExistsException;
 import org.apache.airavata.common.exception.AiravataConfigurationException;
 import org.apache.airavata.common.utils.XMLUtil;
-import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.exception.RegException;
 import org.apache.airavata.registry.api.exception.worker.UserWorkflowAlreadyExistsException;
 import org.apache.airavata.workflow.model.wf.Workflow;
 import org.apache.airavata.workflow.model.wf.WorkflowData;
@@ -111,7 +111,7 @@ public class WorkflowManagerImpl implements WorkflowManager {
             throw new WorkflowAlreadyExistsException("Workflow " +
                     workflow.getName()
                     + " already exists in the system.", e);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new AiravataAPIInvocationException("An internal error occurred while adding workflow " +
                     workflow.getName(), e);
         } catch (AiravataConfigurationException e) {
@@ -122,7 +122,7 @@ public class WorkflowManagerImpl implements WorkflowManager {
         if (owner == null) {
             try {
                 getClient().getRegistryClient().publishWorkflow(workflow.getName());
-            } catch (RegistryException e) {
+            } catch (RegException e) {
                 throw new AiravataAPIInvocationException("An internal error occurred while adding workflow " +
                         workflow.getName(), e);
             } catch (AiravataConfigurationException e) {
@@ -136,7 +136,7 @@ public class WorkflowManagerImpl implements WorkflowManager {
             throws AiravataAPIInvocationException {
         try {
             getClient().getRegistryClient().updateWorkflow(workflow.getName(), workflowAsString);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new AiravataAPIInvocationException("An internal error occurred while adding workflow " +
                     workflow.getName(), e);
         } catch (AiravataConfigurationException e) {
@@ -147,7 +147,7 @@ public class WorkflowManagerImpl implements WorkflowManager {
         if (owner == null) {
             try {
                 getClient().getRegistryClient().publishWorkflow(workflow.getName());
-            } catch (RegistryException e) {
+            } catch (RegException e) {
                 throw new AiravataAPIInvocationException("An internal error occurred while adding workflow " +
                         workflow.getName(), e);
             } catch (AiravataConfigurationException e) {

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java
----------------------------------------------------------------------
diff --git a/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java b/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java
index 923163b..1b8d1e8 100644
--- a/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java
+++ b/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java
@@ -32,10 +32,7 @@ import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.registry.api.AiravataRegistryFactory;
 import org.apache.airavata.registry.api.AiravataUser;
 import org.apache.airavata.registry.api.Gateway;
-import org.apache.airavata.registry.api.exception.RegistryAccessorInstantiateException;
-import org.apache.airavata.registry.api.exception.RegistryAccessorInvalidException;
-import org.apache.airavata.registry.api.exception.RegistryAccessorUndefinedException;
-import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.exception.RegException;
 import org.apache.airavata.registry.cpi.Registry;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
@@ -52,8 +49,8 @@ public class GfacServerHandler implements GfacService.Iface {
     private String airavataUserName;
 
     public GfacServerHandler() {
-        registry = RegistryFactory.getDefaultRegistry();
         try {
+            registry = RegistryFactory.getDefaultRegistry();
             setGatewayProperties();
         }catch (Exception e){
            logger.error("Error initialising GFAC",e);
@@ -120,7 +117,7 @@ public class GfacServerHandler implements GfacService.Iface {
             return new GFacImpl(registry, null,
                                 AiravataRegistryFactory.getRegistry(new Gateway(getGatewayName()),
                                         new AiravataUser(getAiravataUserName())));
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new TException("Error initializing gfac instance",e);
         } catch (AiravataConfigurationException e) {
             throw new TException("Error initializing gfac instance",e);

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
----------------------------------------------------------------------
diff --git a/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java b/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
index 4207f05..8d64046 100644
--- a/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
+++ b/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
@@ -50,10 +50,10 @@ public class GfacClientFactoryTest {
         try {
             service = (new GfacServer());
             service.start();
+            registry = RegistryFactory.getDefaultRegistry();
         } catch (Exception e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
         }
-        registry = RegistryFactory.getDefaultRegistry();
         AiravataUtils.setExecutionAsServer();
         documentCreator = new DocumentCreator(getAiravataAPI());
         documentCreator.createLocalHostDocs();

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java
----------------------------------------------------------------------
diff --git a/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java b/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java
index 6e0e7e6..0046204 100644
--- a/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java
+++ b/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java
@@ -25,6 +25,7 @@ import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.resources.*;
 import org.apache.airavata.registry.api.exception.RegistrySettingsException;
 import org.apache.airavata.registry.api.util.RegistrySettings;
+import org.apache.airavata.registry.cpi.RegistryException;
 import org.apache.derby.drda.NetworkServerControl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -158,6 +159,8 @@ public class Initialize {
 
         } catch (RegistrySettingsException e) {
             logger.error("Unable to read properties", e);
+        } catch (RegistryException e) {
+            logger.error("Error while saving data to registry", e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/handler/AbstractHandler.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/handler/AbstractHandler.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/handler/AbstractHandler.java
index 0049c3c..81d2072 100644
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/handler/AbstractHandler.java
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/handler/AbstractHandler.java
@@ -25,6 +25,7 @@ import org.apache.airavata.gfac.core.cpi.GFacImpl;
 import org.apache.airavata.gfac.core.notification.MonitorPublisher;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.registry.cpi.Registry;
+import org.apache.airavata.registry.cpi.RegistryException;
 
 public abstract class AbstractHandler implements GFacHandler {
 	protected Registry registry = null;
@@ -38,7 +39,11 @@ public abstract class AbstractHandler implements GFacHandler {
     public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
 		registry = jobExecutionContext.getRegistry();
         if(registry == null){
-            registry = RegistryFactory.getDefaultRegistry();
+            try {
+                registry = RegistryFactory.getDefaultRegistry();
+            } catch (RegistryException e) {
+                throw new GFacHandlerException("unable to create registry instance", e);
+            }
         }
 	}
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java
index afc1894..7b24eb9 100644
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java
@@ -30,6 +30,7 @@ import org.apache.airavata.model.workspace.experiment.JobDetails;
 import org.apache.airavata.model.workspace.experiment.JobStatus;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.registry.cpi.Registry;
+import org.apache.airavata.registry.cpi.RegistryException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,7 +51,11 @@ public abstract class AbstractProvider implements GFacProvider{
     public void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException {
         log.debug("Initializing " + this.getClass().getName());
         if(jobExecutionContext.getRegistry() == null) {
-            registry = RegistryFactory.getDefaultRegistry();
+            try {
+                registry = RegistryFactory.getDefaultRegistry();
+            } catch (RegistryException e) {
+                throw new GFacException("Unable to create registry instance", e);
+            }
         }else{
             registry = jobExecutionContext.getRegistry();
         }

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
index 3dd0625..2c66293 100644
--- a/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
+++ b/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
@@ -64,6 +64,8 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface {
             orchestrator.initialize();
         }catch (OrchestratorException e) {
             e.printStackTrace();
+        } catch (RegistryException e) {
+            e.printStackTrace();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java b/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
index f625489..67b72f2 100644
--- a/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
+++ b/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
@@ -50,10 +50,10 @@ public class OrchestratorClientFactoryTest {
         try {
             service = (new OrchestratorServer());
             service.start();
+            registry = RegistryFactory.getDefaultRegistry();
         } catch (Exception e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
         }
-        registry = RegistryFactory.getDefaultRegistry();
         AiravataUtils.setExecutionAsServer();
         documentCreator = new DocumentCreator(getAiravataAPI());
         documentCreator.createLocalHostDocs();

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java b/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java
index 16d10f9..8301ac7 100644
--- a/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java
+++ b/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java
@@ -25,6 +25,7 @@ import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.resources.*;
 import org.apache.airavata.registry.api.exception.RegistrySettingsException;
 import org.apache.airavata.registry.api.util.RegistrySettings;
+import org.apache.airavata.registry.cpi.RegistryException;
 import org.apache.derby.drda.NetworkServerControl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -158,6 +159,8 @@ public class Initialize {
 
         } catch (RegistrySettingsException e) {
             logger.error("Unable to read properties", e);
+        } catch (RegistryException e) {
+            logger.error("Error while saving data to registry", e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java b/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
index e7c5a13..ec026d4 100644
--- a/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
+++ b/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
@@ -35,6 +35,7 @@ import org.apache.airavata.orchestrator.cpi.OrchestratorService;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.registry.cpi.ParentDataType;
 import org.apache.airavata.registry.cpi.Registry;
+import org.apache.airavata.registry.cpi.RegistryException;
 import org.apache.thrift.TException;
 
 import java.util.ArrayList;
@@ -67,6 +68,8 @@ public class OrchestratorClientSample {
             storeExperimentDetail();
         } catch (ApplicationSettingsException e) {
             e.printStackTrace();
+        } catch (RegistryException e) {
+            e.printStackTrace();
         }
 
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java
index 624ced7..2a8b27b 100644
--- a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java
+++ b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java
@@ -35,7 +35,7 @@ import org.apache.airavata.orchestrator.core.job.JobSubmitter;
 import org.apache.airavata.orchestrator.cpi.Orchestrator;
 import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl;
 import org.apache.airavata.registry.api.AiravataRegistry2;
-import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.exception.RegException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,7 +66,7 @@ public class OrchestratorUtils {
         String resourceHostId = taskScheduling.getResourceHostId();
         try {
             return registry.getHostDescriptor(resourceHostId);
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             throw new OrchestratorException(e);
         }
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/validator/impl/SimpleAppDataValidator.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/validator/impl/SimpleAppDataValidator.java b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/validator/impl/SimpleAppDataValidator.java
index f5916d5..8847500 100644
--- a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/validator/impl/SimpleAppDataValidator.java
+++ b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/validator/impl/SimpleAppDataValidator.java
@@ -28,6 +28,7 @@ import org.apache.airavata.orchestrator.core.exception.OrchestratorException;
 import org.apache.airavata.orchestrator.core.validator.JobMetadataValidator;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.registry.cpi.Registry;
+import org.apache.airavata.registry.cpi.RegistryException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,7 +38,11 @@ public class SimpleAppDataValidator implements JobMetadataValidator {
     private Registry registry;
 
     public SimpleAppDataValidator() {
-        this.registry = RegistryFactory.getDefaultRegistry();
+        try {
+            this.registry = RegistryFactory.getDefaultRegistry();
+        } catch (RegistryException e) {
+            logger.error("Unable to initialize registry", e);
+        }
     }
 
     public ValidatorResult validate(Experiment experiment, WorkflowNodeDetails workflowNodeDetail, TaskDetails taskID) {

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java
index 7147ef9..5bbe4e6 100644
--- a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java
+++ b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java
@@ -46,7 +46,8 @@ import org.apache.airavata.registry.api.AiravataRegistry2;
 import org.apache.airavata.registry.api.AiravataRegistryFactory;
 import org.apache.airavata.registry.api.AiravataUser;
 import org.apache.airavata.registry.api.Gateway;
-import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.api.exception.RegException;
+import org.apache.airavata.registry.cpi.RegistryException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -116,7 +117,7 @@ public abstract class AbstractOrchestrator implements Orchestrator {
 
             /* initializing registry cpi */
             orchestratorContext.setNewRegistry(new RegistryImpl());
-        } catch (RegistryException e) {
+        } catch (RegException e) {
             logger.error("Failed to initializing Orchestrator");
             OrchestratorException orchestratorException = new OrchestratorException(e);
             throw orchestratorException;
@@ -130,7 +131,11 @@ public abstract class AbstractOrchestrator implements Orchestrator {
             throw orchestratorException;
 		} catch (ApplicationSettingsException e) {
 			throw new OrchestratorException(e);
-		}
+		} catch (RegistryException e) {
+            logger.error("Failed to initializing Orchestrator - Error initializing registry");
+            OrchestratorException orchestratorException = new OrchestratorException(e);
+            throw orchestratorException;
+        }
     }
 	
 	//get the registry URL and the credentials from the property file

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java b/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java
index ba68259..fe71df5 100644
--- a/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java
+++ b/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java
@@ -25,6 +25,7 @@ import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.resources.*;
 import org.apache.airavata.registry.api.exception.RegistrySettingsException;
 import org.apache.airavata.registry.api.util.RegistrySettings;
+import org.apache.airavata.registry.cpi.RegistryException;
 import org.apache.derby.drda.NetworkServerControl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -158,6 +159,8 @@ public class Initialize {
 
         } catch (RegistrySettingsException e) {
             logger.error("Unable to read properties", e);
+        } catch (RegistryException e) {
+            logger.error("Error while saving data to registry", e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java
index 3897d2a..26b7371 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java
@@ -20,6 +20,8 @@
 */
 package org.apache.airavata.persistance.registry.jpa;
 
+import org.apache.airavata.registry.cpi.RegistryException;
+
 import java.util.List;
 
 public interface Resource {
@@ -28,14 +30,14 @@ public interface Resource {
      * @param type child resource type
      * @return associate child resource
      */
-    Resource create(ResourceType type);
+    Resource create(ResourceType type) throws RegistryException, RegistryException;
 
     /**
      * This method will remove the given child resource from the database
      * @param type child resource type
      * @param name child resource name
      */
-    void remove(ResourceType type, Object name);
+    void remove(ResourceType type, Object name) throws RegistryException;
 
     /**
      *  This method will return the given child resource from the database
@@ -43,19 +45,19 @@ public interface Resource {
      * @param name child resource name
      * @return associate child resource
      */
-    Resource get(ResourceType type, Object name);
+    Resource get(ResourceType type, Object name) throws RegistryException;
 
     /**
      * This method will list all the child resources for the given resource type
      * @param type child resource type
      * @return list of child resources of the given child resource type
      */
-    List<Resource> get(ResourceType type);
+    List<Resource> get(ResourceType type) throws RegistryException;
 
     /**
      * This method will save the resource to the database.
      */
-    void save();
+    void save() throws RegistryException;
 
     /**
      * This method will check whether an entry from the given resource type and resource name
@@ -64,6 +66,6 @@ public interface Resource {
      * @param name child resource name
      * @return whether the entry exists in the database or not
      */
-    boolean isExists(ResourceType type, Object name);
+    boolean isExists(ResourceType type, Object name) throws RegistryException;
 
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf5f8c3c/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
index 9670c33..410a393 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
@@ -29,15 +29,13 @@ import java.util.concurrent.locks.ReentrantLock;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityNotFoundException;
 import javax.persistence.Persistence;
 import javax.persistence.Query;
 
 import org.apache.airavata.persistance.registry.jpa.model.*;
 import org.apache.airavata.persistance.registry.jpa.resources.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
-import org.apache.airavata.registry.api.exception.AiravataRegistryUninitializedException;
-import org.apache.airavata.registry.api.exception.RegistryException;
+import org.apache.airavata.registry.cpi.RegistryException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,8 +61,8 @@ public class ResourceUtils {
             properties.put("openjpa.ConnectionProperties", connectionProperties);
             properties.put("openjpa.DynamicEnhancementAgent", "true");
             properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
-            properties.put("openjpa.DataCache","true(CacheSize=5000)");
-            properties.put("openjpa.QueryCache","true(CacheSize=5000)");
+            properties.put("openjpa.DataCache","true(CacheSize=5000, SoftReferenceSize=0)");
+            properties.put("openjpa.QueryCache","true(CacheSize=5000, SoftReferenceSize=0)");
             properties.put("openjpa.RemoteCommitProvider","sjvm");
             properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
             properties.put("openjpa.ReadLockLevel", "none");
@@ -83,7 +81,7 @@ public class ResourceUtils {
      * @param gatewayName
      * @return
      */
-    public static Resource createGateway(String gatewayName){
+    public static Resource createGateway(String gatewayName) throws RegistryException {
         if (!isGatewayExist(gatewayName)) {
             GatewayResource gatewayResource = new GatewayResource();
             gatewayResource.setGatewayName(gatewayName);
@@ -93,7 +91,7 @@ public class ResourceUtils {
         }
     }
 
-    public static UserResource createUser(String username, String password){
+    public static UserResource createUser(String username, String password) throws RegistryException {
         if (!isUserExist(username)) {
             UserResource userResource = new UserResource();
             userResource.setUserName(username);
@@ -105,54 +103,97 @@ public class ResourceUtils {
 
     }
 
-    public static Resource getGateway(String gatewayName){
-        if (isGatewayExist(gatewayName)) {
-            EntityManager em = getEntityManager();
-            Gateway gateway = em.find(Gateway.class, gatewayName);
-            GatewayResource gatewayResource = (GatewayResource)Utils.getResource(ResourceType.GATEWAY, gateway);
-            em.close();
-            return gatewayResource;
+    public static Resource getGateway(String gatewayName) throws RegistryException{
+        EntityManager em = null;
+        try {
+            if (isGatewayExist(gatewayName)) {
+                em = getEntityManager();
+                Gateway gateway = em.find(Gateway.class, gatewayName);
+                GatewayResource gatewayResource = (GatewayResource)Utils.getResource(ResourceType.GATEWAY, gateway);
+                em.close();
+                return gatewayResource;
+            }
+        }catch (Exception e){
+            logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
         }
         return null;
-
     }
 
-    public static void addUser (String userName, String password){
+    public static void addUser (String userName, String password) throws RegistryException{
         UserResource resource = new UserResource();
         resource.setUserName(userName);
         resource.setPassword(password);
         resource.save();
     }
 
-    public static boolean isUserExist (String username){
-        EntityManager em = getEntityManager();
-        em.getTransaction().begin();
-        QueryGenerator generator = new QueryGenerator(AbstractResource.USERS);
-        generator.setParameter(AbstractResource.UserConstants.USERNAME, username);
-        Query q = generator.selectQuery(em);
-        int size = q.getResultList().size();
-        em.getTransaction().commit();
-        em.close();
-        return size>0;
-    }
-    public static Resource getUser(String userName){
-        if (isUserExist(userName)) {
-            EntityManager em = getEntityManager();
-            Users user =  em.find(Users.class, userName);
-            UserResource userResource = (UserResource)Utils.getResource(ResourceType.USER, user);
+    public static boolean isUserExist (String username) throws RegistryException{
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            QueryGenerator generator = new QueryGenerator(AbstractResource.USERS);
+            generator.setParameter(AbstractResource.UserConstants.USERNAME, username);
+            Query q = generator.selectQuery(em);
+            int size = q.getResultList().size();
+            em.getTransaction().commit();
             em.close();
-            return userResource;
+            return size>0;
+        } catch (Exception e){
+            logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
+        }
+    }
+
+
+    public static Resource getUser(String userName) throws RegistryException{
+        EntityManager em = null;
+        try {
+            if (isUserExist(userName)) {
+                em = getEntityManager();
+                Users user =  em.find(Users.class, userName);
+                UserResource userResource = (UserResource)Utils.getResource(ResourceType.USER, user);
+                em.close();
+                return userResource;
+            }
+        }catch (Exception e){
+            logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
         }
         return null;
 
     }
 
-    public static Resource getWorker(String gatewayName, String userName) {
-        EntityManager em = getEntityManager();
-        Gateway_Worker gatewayWorker = em.find(Gateway_Worker.class, new Gateway_Worker_PK(gatewayName, userName));
-        WorkerResource workerResource = (WorkerResource) Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
-        em.close();
-        return workerResource;
+    public static Resource getWorker(String gatewayName, String userName) throws RegistryException{
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            Gateway_Worker gatewayWorker = em.find(Gateway_Worker.class, new Gateway_Worker_PK(gatewayName, userName));
+            WorkerResource workerResource = (WorkerResource) Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
+            em.close();
+            return workerResource;
+        }catch (Exception e){
+            logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
+        }
+
+
     }
 
 
@@ -160,17 +201,27 @@ public class ResourceUtils {
      * @param gatewayName
      * @return
      */
-    public static boolean isGatewayExist(String gatewayName){
-
-        EntityManager em = getEntityManager();
-        em.getTransaction().begin();
-        QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
-        generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_NAME, gatewayName);
-        Query q = generator.selectQuery(em);
-        int size = q.getResultList().size();
-        em.getTransaction().commit();
-        em.close();
-		return size>0;
+    public static boolean isGatewayExist(String gatewayName) throws RegistryException{
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
+            generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_NAME, gatewayName);
+            Query q = generator.selectQuery(em);
+            int size = q.getResultList().size();
+            em.getTransaction().commit();
+            em.close();
+            return size>0;
+        }catch (Exception e){
+            logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
+        }
+
     }
 
     /**
@@ -178,8 +229,9 @@ public class ResourceUtils {
      * @return
      */
     public static boolean removeGateway(String gatewayName) {
+        EntityManager em = null;
         try {
-            EntityManager em = getEntityManager();
+            em = getEntityManager();
             em.getTransaction().begin();
             QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
             generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_NAME, gatewayName);
@@ -191,18 +243,21 @@ public class ResourceUtils {
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
             return false;
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
         }
-
-
     }
 
     /**
      * @param gatewayResource
      * @param userResource
      */
-    public static WorkerResource addGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
+    public static WorkerResource addGatewayWorker(GatewayResource gatewayResource, UserResource userResource) throws RegistryException{
+        EntityManager em = null;
         try {
-            EntityManager em = getEntityManager();
+            em = getEntityManager();
             em.getTransaction().begin();
             if (!isGatewayExist(gatewayResource.getGatewayName())){
                 gatewayResource.save();
@@ -218,12 +273,15 @@ public class ResourceUtils {
             em.persist(gatewayWorker);
             em.getTransaction().commit();
             em.close();
-            WorkerResource resource = (WorkerResource)Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
-            return resource;
-        } catch (Exception e) {
+            return (WorkerResource)Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
+        } catch (Exception e){
             logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
         }
-        return null;
     }
 
     /**
@@ -232,8 +290,9 @@ public class ResourceUtils {
      * @return
      */
     public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
+        EntityManager em = null;
         try {
-            EntityManager em = getEntityManager();
+            em = getEntityManager();
             em.getTransaction().begin();
             QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY_WORKER);
             generator.setParameter(AbstractResource.GatewayWorkerConstants.GATEWAY_NAME,
@@ -247,6 +306,10 @@ public class ResourceUtils {
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
             return false;
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
         }
 
     }
@@ -257,20 +320,29 @@ public class ResourceUtils {
      */
     public static List<ConfigurationResource> getConfigurations(String configKey){
         List<ConfigurationResource> list = new ArrayList<ConfigurationResource>();
-        EntityManager em = getEntityManager();
-        em.getTransaction().begin();
-        QueryGenerator generator = new QueryGenerator(AbstractResource.CONFIGURATION);
-        generator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configKey);
-        Query q = generator.selectQuery(em);
-        List<?> resultList = q.getResultList();
-        if (resultList.size() != 0) {
-            for (Object result : resultList) {
-                ConfigurationResource configurationResource = createConfigurationResourceObject(result);
-                list.add(configurationResource);
+        EntityManager em = null;
+        try {
+            em = getEntityManager();
+            em.getTransaction().begin();
+            QueryGenerator generator = new QueryGenerator(AbstractResource.CONFIGURATION);
+            generator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configKey);
+            Query q = generator.selectQuery(em);
+            List<?> resultList = q.getResultList();
+            if (resultList.size() != 0) {
+                for (Object result : resultList) {
+                    ConfigurationResource configurationResource = createConfigurationResourceObject(result);
+                    list.add(configurationResource);
+                }
+            }
+            em.getTransaction().commit();
+            em.close();
+        }catch (Exception e) {
+            logger.error(e.getMessage(), e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
             }
         }
-        em.getTransaction().commit();
-        em.close();
         return list;
     }
 
@@ -318,46 +390,71 @@ public class ResourceUtils {
      * @param configkey
      * @param configValue
      */
-    public static void removeConfiguration(String configkey, String configValue){
+    public static void removeConfiguration(String configkey, String configValue) throws RegistryException{
         QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
         queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
         queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_VAL, configValue);
-        if(isConfigurationExists(configkey, configValue)){
-            EntityManager em = getEntityManager();
-            em.getTransaction().begin();
-            Query q = queryGenerator.deleteQuery(em);
-            q.executeUpdate();
-            em.getTransaction().commit();
-            em.close();
+        EntityManager em = null;
+        try {
+            if(isConfigurationExists(configkey, configValue)){
+                em = getEntityManager();
+                em.getTransaction().begin();
+                Query q = queryGenerator.deleteQuery(em);
+                q.executeUpdate();
+                em.getTransaction().commit();
+                em.close();
+            }
+        }catch (Exception e){
+            logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
         }
     }
 
     /**
      * @param configkey
      */
-    public static void removeConfiguration(String configkey){
+    public static void removeConfiguration(String configkey) throws RegistryException{
         QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
         queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
-        if(isConfigurationExist(configkey)){
-            EntityManager em = getEntityManager();
-            em.getTransaction().begin();
-            Query q = queryGenerator.deleteQuery(em);
-            q.executeUpdate();
-            em.getTransaction().commit();
-            em.close();
+        EntityManager em = null;
+        try {
+            if(isConfigurationExist(configkey)){
+                em = getEntityManager();
+                em.getTransaction().begin();
+                Query q = queryGenerator.deleteQuery(em);
+                q.executeUpdate();
+                em.getTransaction().commit();
+                em.close();
+            }
+        }catch (Exception e){
+            logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
         }
     }
 
-    public static boolean isConfigurationExists(String configKey, String configVal){
+    public static boolean isConfigurationExists(String configKey, String configVal) throws RegistryException{
+        EntityManager em = null;
         try{
             //Currently categoryID is hardcoded value
-            EntityManager em = ResourceUtils.getEntityManager();
+            em = ResourceUtils.getEntityManager();
             Configuration existing = em.find(Configuration.class, new Configuration_PK(configKey, configVal, AbstractResource.ConfigurationConstants.CATEGORY_ID_DEFAULT_VALUE));
             em.close();
             return existing!= null;
         } catch (Exception e){
             logger.error(e.getMessage(), e);
-            throw new EntityNotFoundException();
+            throw new RegistryException(e);
+        }finally {
+            if (em != null && em.isOpen()){
+                em.close();
+            }
         }
     }