You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by he...@apache.org on 2012/03/09 19:16:33 UTC

svn commit: r1298954 - in /incubator/airavata/trunk/modules: distribution/src/main/resources/bin/ registry-migrator/src/main/java/org/apache/airavata/migrator/registry/

Author: heshan
Date: Fri Mar  9 18:16:32 2012
New Revision: 1298954

URL: http://svn.apache.org/viewvc?rev=1298954&view=rev
Log:
Refactored the xregistry-migrator module.

Modified:
    incubator/airavata/trunk/modules/distribution/src/main/resources/bin/xregistry-migrator.sh
    incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/MigrationUtil.java
    incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/XRegistryMigrationManager.java

Modified: incubator/airavata/trunk/modules/distribution/src/main/resources/bin/xregistry-migrator.sh
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/distribution/src/main/resources/bin/xregistry-migrator.sh?rev=1298954&r1=1298953&r2=1298954&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/distribution/src/main/resources/bin/xregistry-migrator.sh (original)
+++ incubator/airavata/trunk/modules/distribution/src/main/resources/bin/xregistry-migrator.sh Fri Mar  9 18:16:32 2012
@@ -27,7 +27,7 @@ for f in ../standalone-server/lib/*.jar
 do
   TOOL_CLASSPATH="$TOOL_CLASSPATH":$f
 done
-echo "classpath : $TOOL_CLASSPATH"
+#echo "classpath : $TOOL_CLASSPATH"
 
 java -cp "$TOOL_CLASSPATH" org.apache.airavata.migrator.registry.XRegistryMigrationManager $1
 

Modified: incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/MigrationUtil.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/MigrationUtil.java?rev=1298954&r1=1298953&r2=1298954&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/MigrationUtil.java (original)
+++ incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/MigrationUtil.java Fri Mar  9 18:16:32 2012
@@ -70,8 +70,8 @@ public class MigrationUtil {
      * @return ServiceDescription
      */
     public static ServiceDescription createServiceDescription(ServiceBean serviceBean) {
-        ServiceDescription serv = new ServiceDescription();
-        serv.getType().setName(serviceBean.getServiceName());
+        ServiceDescription serviceDescription = new ServiceDescription();
+        serviceDescription.getType().setName(serviceBean.getServiceName());
 
         ArrayList<ParamObject> inputParameterTypes = serviceBean.getMethodBean().getInputParms();
         List<InputParameterType> inputList = new ArrayList<InputParameterType>();
@@ -96,7 +96,7 @@ public class MigrationUtil {
             }
             InputParameterType[] inputParamList =
                     inputList.toArray(new InputParameterType[inputList.size()]);
-            serv.getType().setInputParametersArray(inputParamList);
+            serviceDescription.getType().setInputParametersArray(inputParamList);
         }
 
         ArrayList<ParamObject> outputParameterTypes = serviceBean.getMethodBean().getOutputParms();
@@ -122,10 +122,10 @@ public class MigrationUtil {
             }
             OutputParameterType[] outputParamList =
                     outputList.toArray(new OutputParameterType[outputList.size()]);
-            serv.getType().setOutputParametersArray(outputParamList);
+            serviceDescription.getType().setOutputParametersArray(outputParamList);
         }
 
-        return serv;
+        return serviceDescription;
     }
 
     /**
@@ -137,8 +137,8 @@ public class MigrationUtil {
      */
     public static ServiceDescription createServiceDescription(String serviceName,
                                                               ServiceBean serviceBean) {
-        ServiceDescription serv = new ServiceDescription();
-        serv.getType().setName(serviceName);
+        ServiceDescription serviceDescription = new ServiceDescription();
+        serviceDescription.getType().setName(serviceName);
         log.debug("\nSERVICE : " + serviceName);
 
         ArrayList<ParamObject> inputParameterTypes = serviceBean.getMethodBean().getInputParms();
@@ -164,7 +164,7 @@ public class MigrationUtil {
             }
             InputParameterType[] inputParamList =
                     inputList.toArray(new InputParameterType[inputList.size()]);
-            serv.getType().setInputParametersArray(inputParamList);
+            serviceDescription.getType().setInputParametersArray(inputParamList);
         }
 
         ArrayList<ParamObject> outputParameterTypes = serviceBean.getMethodBean().getOutputParms();
@@ -190,10 +190,10 @@ public class MigrationUtil {
             }
             OutputParameterType[] outputParamList =
                     outputList.toArray(new OutputParameterType[outputList.size()]);
-            serv.getType().setOutputParametersArray(outputParamList);
+            serviceDescription.getType().setOutputParametersArray(outputParamList);
         }
 
-        return serv;
+        return serviceDescription;
     }
 
     /**
@@ -216,7 +216,6 @@ public class MigrationUtil {
             gram.setApplicationName(name);
             gram.setExecutableLocation(appBean.getExecutable());
             gram.setScratchWorkingDirectory(appBean.getTmpDir());
-            //TODO: add to documentation --> ask user to check the hostcount
             gram.setMaxWallTime(appBean.getMaxWallTime());
             if (appBean.getPcount() != null) {
                 gram.setCpuCount(appBean.getPcount());
@@ -226,7 +225,6 @@ public class MigrationUtil {
             }
 
             gram.setJobType(getJobTypeEnum(appBean.getJobType()));
-            // TODO : verify the following
             ProjectAccountType projectAccount;
             if(gram.getProjectAccount() != null) {
                 projectAccount = gram.getProjectAccount();
@@ -280,7 +278,6 @@ public class MigrationUtil {
             gram.setApplicationName(name);
             gram.setExecutableLocation(appBean.getExecutable());
             gram.setScratchWorkingDirectory(appBean.getTmpDir());
-            //TODO: add to documentation --> ask user to check the hostcount
             gram.setMaxWallTime(appBean.getMaxWallTime());
             if (appBean.getPcount() != null) {
                 gram.setCpuCount(appBean.getPcount());
@@ -290,7 +287,6 @@ public class MigrationUtil {
             }
 
             gram.setJobType(getJobTypeEnum(appBean.getJobType()));
-            // TODO : verify the following
             ProjectAccountType projectAccount;
             if(gram.getProjectAccount() != null) {
                 projectAccount = gram.getProjectAccount();
@@ -322,9 +318,9 @@ public class MigrationUtil {
     }
 
     private static JobTypeType.Enum getJobTypeEnum(String jobTypeString){
-        for (JobTypeType.Enum jtype : getJobTypes()) {
-            if (jtype.toString().equalsIgnoreCase(jobTypeString)){
-                return jtype;
+        for (JobTypeType.Enum jobTypeEnum : getJobTypes()) {
+            if (jobTypeEnum.toString().equalsIgnoreCase(jobTypeString)){
+                return jobTypeEnum;
             }
         }
         return null;

Modified: incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/XRegistryMigrationManager.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/XRegistryMigrationManager.java?rev=1298954&r1=1298953&r2=1298954&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/XRegistryMigrationManager.java (original)
+++ incubator/airavata/trunk/modules/registry-migrator/src/main/java/org/apache/airavata/migrator/registry/XRegistryMigrationManager.java Fri Mar  9 18:16:32 2012
@@ -96,8 +96,6 @@ public class XRegistryMigrationManager {
         }
 
         XRegistryClient client;
-
-
         try {
             client = XRegistryClientUtil.CreateGSISecureRegistryInstance(migrationPropertiesFile);
         } catch (XRegistryClientException e) {
@@ -126,7 +124,7 @@ public class XRegistryMigrationManager {
             try {
                 properties.load(fileInputStream);
             } catch (IOException e) {
-                throw new XRegistryMigrationException("Issue occured while loading the migration " +
+                throw new XRegistryMigrationException("Issue occurred while loading the migration " +
                         "properties from file " + e.getMessage(), e);
             }
         } else {
@@ -151,16 +149,16 @@ public class XRegistryMigrationManager {
      */
     private static void saveAllHostDescriptions(XRegistryClient client)
             throws XRegistryMigrationException {
-        HostDescription host = null;
-        HostDescData[] hostDescs;
+        HostDescription host;
+        HostDescData[] hostDescData;
         try {
-            hostDescs = client.findHosts("");
+            hostDescData = client.findHosts("");
         } catch (XRegistryClientException e) {
             throw new XRegistryMigrationException("Issue searching hosts in XRegistry instance " +
                     e.getMessage(), e);
         }
         Map<QName, HostDescData> val = new HashMap<QName, HostDescData>();
-        for (HostDescData hostDesc : hostDescs) {
+        for (HostDescData hostDesc : hostDescData) {
             val.put(hostDesc.getName(), hostDesc);
             String hostDescStr;
             try {
@@ -182,9 +180,7 @@ public class XRegistryMigrationManager {
                         e.getMessage(), e);
             }
 
-            if(hostBean != null){
-                host = MigrationUtil.createHostDescription(hostBean);
-            }
+            host = MigrationUtil.createHostDescription(hostBean);
 
             try {
                 jcrRegistry.saveHostDescription(host);
@@ -208,16 +204,16 @@ public class XRegistryMigrationManager {
     private static void saveAllServiceDescriptions(XRegistryClient client)
             throws XRegistryMigrationException {
         ServiceDescription service;
-        ServiceDescData[] serviceDescDatas;
+        ServiceDescData[] serviceDescData;
         try {
-            serviceDescDatas = client.findServiceDesc("");
+            serviceDescData = client.findServiceDesc("");
         } catch (XRegistryClientException e) {
             throw new XRegistryMigrationException("Issue accessing XRegistry " + e.getMessage(), e);
         }
         Map<QName, ServiceDescData> val3 = new HashMap<QName, ServiceDescData>();
         int count = 0;
 
-        for (ServiceDescData serviceDesc : serviceDescDatas) {
+        for (ServiceDescData serviceDesc : serviceDescData) {
             val3.put(serviceDesc.getName(), serviceDesc);
             String serviceDescStr;
             try {
@@ -243,42 +239,38 @@ public class XRegistryMigrationManager {
                         "Bean " + e.getMessage(), e);
             }
 
-            if(serviceBean != null) {
-                try {
-                    String serviceName = serviceBean.getServiceName();
-                    ServiceDescription serviceDescription = jcrRegistry.getServiceDesc(serviceName);
-                    if(serviceDescription == null) {
-                        service = MigrationUtil.createServiceDescription(serviceBean);
-                        jcrRegistry.saveServiceDescription(service);
-                        ApplicationBean appBean =
-                                saveApplicationDescriptionWithName(client, applicationName, service);
-                        // TODO : should look into this
-                        if (appBean != null){
-                            jcrRegistry.deployServiceOnHost(service.getType().
-                                    getName(), appBean.getHostName());
-                        }
-                    } else {
-                        serviceName = serviceName + "_" + count++;
-                        service = MigrationUtil.createServiceDescription(serviceName,serviceBean);
-                        log.info("Service Description named " +
-                                service.getType().getName() +
-                                " exists in the registry. Therefore, saving it as " +
-                                serviceName + " in the registry.");
-
-                        jcrRegistry.saveServiceDescription(service);
-                        ApplicationBean appBean = saveApplicationDescriptionWithName(client,
-                                applicationName, service);
-                        // TODO : should look into this
-                        if (appBean != null){
-                            jcrRegistry.deployServiceOnHost(service.getType().getName(),
-                                    appBean.getHostName());
-                        }
-
+            try {
+                String serviceName = serviceBean.getServiceName();
+                ServiceDescription serviceDescription = jcrRegistry.getServiceDesc(serviceName);
+                if(serviceDescription == null) {
+                    service = MigrationUtil.createServiceDescription(serviceBean);
+                    jcrRegistry.saveServiceDescription(service);
+                    ApplicationBean appBean =
+                            saveApplicationDescriptionWithName(client, applicationName, service);
+                    if (appBean != null){
+                        jcrRegistry.deployServiceOnHost(service.getType().
+                                getName(), appBean.getHostName());
+                    }
+                } else {
+                    serviceName = serviceName + "_" + count++;
+                    service = MigrationUtil.createServiceDescription(serviceName,serviceBean);
+                    log.info("Service Description named " +
+                            service.getType().getName() +
+                            " exists in the registry. Therefore, saving it as " +
+                            serviceName + " in the registry.");
+
+                    jcrRegistry.saveServiceDescription(service);
+                    ApplicationBean appBean = saveApplicationDescriptionWithName(client,
+                            applicationName, service);
+                    if (appBean != null){
+                        jcrRegistry.deployServiceOnHost(service.getType().getName(),
+                                appBean.getHostName());
                     }
-                } catch (RegistryException e) {
-                    throw new XRegistryMigrationException("Issue accessing the JCR Registry " +
-                            e.getMessage(), e);
+
                 }
+            } catch (RegistryException e) {
+                throw new XRegistryMigrationException("Issue accessing the JCR Registry " +
+                        e.getMessage(), e);
             }
 
         }
@@ -292,16 +284,15 @@ public class XRegistryMigrationManager {
      * @param applicationName name of the application to be saved
      * @param service service name
      * @return ApplicationBean
-     * @throws XRegistryClientException XRegistryClientException
      * @throws XRegistryMigrationException XRegistryMigrationException
      */
     private static ApplicationBean saveApplicationDescriptionWithName(XRegistryClient client,
                                                                       String applicationName,
                                                                       ServiceDescription service)
             throws XRegistryMigrationException {
-        FindAppDescResponseDocument.FindAppDescResponse.AppData[] appDatas;
+        FindAppDescResponseDocument.FindAppDescResponse.AppData[] appData;
         try {
-            appDatas = client.findAppDesc(applicationName);
+            appData = client.findAppDesc(applicationName);
         } catch (XRegistryClientException e) {
             throw new XRegistryMigrationException("Issue accessing XRegistry " + e.getMessage(), e);
         }
@@ -309,7 +300,7 @@ public class XRegistryMigrationManager {
                 new HashMap<QName, FindAppDescResponseDocument.FindAppDescResponse.AppData>();
         ApplicationBean appBean = null;
         int count = 0;
-        for (FindAppDescResponseDocument.FindAppDescResponse.AppData appDesc : appDatas) {
+        for (FindAppDescResponseDocument.FindAppDescResponse.AppData appDesc : appData) {
             val2.put(appDesc.getName(), appDesc);
             String appDescStr;
             try {
@@ -329,40 +320,38 @@ public class XRegistryMigrationManager {
                         "Application Bean " + e.getMessage(), e);
             }
 
-            if(appBean != null){
-                try {
-                    String name = service.getType().getName();
-                    String hostName = appBean.getHostName();
-                    Thread.sleep(500);
-                    ApplicationDeploymentDescription appDepDesc =
-                            jcrRegistry.getDeploymentDescription(name, hostName);
-                    if(appDepDesc == null) {
-                        if(log.isDebugEnabled()) {
-                            log.debug("name : " + name);
-                            log.debug("hostName: " + hostName);
-                        }
-                        jcrRegistry.saveDeploymentDescription(name, hostName,
-                                MigrationUtil.createAppDeploymentDescription(appBean));
-                    } else {
-                        //Creating a new name for the the duplicated item
-                        name = name + "_" + count++;
-                        if(log.isDebugEnabled()) {
-                            log.debug("DEBUG name : " + name);
-                            log.debug("hostName: " + hostName);
-                        }
-                        log.info("Application Deployment Description named " +
-                                service.getType().getName() + " with host " + hostName +
-                                " exists in the registry. Therefore, saving it as " +
-                                name + " in the registry.");
-                        jcrRegistry.saveDeploymentDescription(name, hostName,
-                                MigrationUtil.createAppDeploymentDescription(name,appBean));
+            try {
+                String name = service.getType().getName();
+                String hostName = appBean.getHostName();
+                Thread.sleep(500);
+                ApplicationDeploymentDescription appDepDesc =
+                        jcrRegistry.getDeploymentDescription(name, hostName);
+                if(appDepDesc == null) {
+                    if(log.isDebugEnabled()) {
+                        log.debug("name    : " + name);
+                        log.debug("hostName: " + hostName);
                     }
-                } catch (RegistryException e) {
-                    throw new XRegistryMigrationException("Issue using the Airavata Registry API " +
-                            e.getMessage(), e);
-                } catch (InterruptedException e) {
-                    throw new XRegistryMigrationException(e.getMessage(), e);
+                    jcrRegistry.saveDeploymentDescription(name, hostName,
+                            MigrationUtil.createAppDeploymentDescription(appBean));
+                } else {
+                    //Creating a new name for the the duplicated item
+                    name = name + "_" + count++;
+                    if(log.isDebugEnabled()) {
+                        log.debug("name    : " + name);
+                        log.debug("hostName: " + hostName);
+                    }
+                    log.info("Application Deployment Description named " +
+                            service.getType().getName() + " with host " + hostName +
+                            " exists in the registry. Therefore, saving it as " +
+                            name + " in the registry.");
+                    jcrRegistry.saveDeploymentDescription(name, hostName,
+                            MigrationUtil.createAppDeploymentDescription(name,appBean));
                 }
+            } catch (RegistryException e) {
+                throw new XRegistryMigrationException("Issue using the Airavata Registry API " +
+                        e.getMessage(), e);
+            } catch (InterruptedException e) {
+                throw new XRegistryMigrationException(e.getMessage(), e);
             }