You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2012/12/20 17:12:59 UTC

svn commit: r1424559 - in /airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac: context/ external/ phoebus/ phoebus/impl/ utils/

Author: samindaw
Date: Thu Dec 20 16:12:58 2012
New Revision: 1424559

URL: http://svn.apache.org/viewvc?rev=1424559&view=rev
Log:
enabling phoebus in Airavata backend

Added:
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridConfigurationHandler.java   (with props)
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/phoebus/
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/phoebus/impl/
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/phoebus/impl/PhoebusGridConfigurationHandler.java   (with props)
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/PhoebusUtils.java   (with props)
Modified:
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java?rev=1424559&r1=1424558&r2=1424559&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java Thu Dec 20 16:12:58 2012
@@ -20,9 +20,17 @@
 */
 package org.apache.airavata.core.gfac.context;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.airavata.client.api.AiravataAPI;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.core.gfac.external.GridConfigurationHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class GFacConfiguration {
+    public static final Logger log = LoggerFactory.getLogger(GFacConfiguration.class);
 
     private String myProxyServer;
 
@@ -36,6 +44,29 @@ public class GFacConfiguration {
     private AiravataAPI airavataAPI;
 
     private String trustedCertLocation;
+    
+    private static List<GridConfigurationHandler> gridConfigurationHandlers;
+    private static String GRID_HANDLERS="airavata.grid.handlers";
+    
+    static{
+    	gridConfigurationHandlers=new ArrayList<GridConfigurationHandler>();
+    	String handlerString = ServerSettings.getSetting(GRID_HANDLERS, null);
+    	String[] handlers = handlerString.split(",");
+    	for (String handlerClass : handlers) {
+    		try {
+				@SuppressWarnings("unchecked")
+				Class<GridConfigurationHandler> classInstance = (Class<GridConfigurationHandler>) GFacConfiguration.class
+						.getClassLoader().loadClass(handlerClass);
+				gridConfigurationHandlers.add(classInstance.newInstance());
+			} catch (Exception e) {
+				log.error("Error while loading Grid Configuration Handler class "+handlerClass, e);
+			}
+		}
+    }
+    
+    public static GridConfigurationHandler[] getGridConfigurationHandlers(){
+    	return gridConfigurationHandlers.toArray(new GridConfigurationHandler[]{});
+    }
 
     public GFacConfiguration(String myProxyServer,
                              String myProxyUser,

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridConfigurationHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridConfigurationHandler.java?rev=1424559&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridConfigurationHandler.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridConfigurationHandler.java Thu Dec 20 16:12:58 2012
@@ -0,0 +1,41 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.core.gfac.external;
+
+import org.globus.ftp.GridFTPClient;
+
+public interface GridConfigurationHandler {
+	
+	/**
+	 * Do the configurations required for the source GridFTPClient object
+	 * @param client
+	 * @throws Exception
+	 */
+	public void handleSourceFTPClient(GridFTPClient client) throws Exception;
+	
+	/**
+	 * Do the configurations required for the destination GridFTPClient object
+	 * @param client
+	 * @throws Exception
+	 */
+	public void handleDestinationFTPClient(GridFTPClient client) throws Exception;
+}

Propchange: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridConfigurationHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java?rev=1424559&r1=1424558&r2=1424559&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java Thu Dec 20 16:12:58 2012
@@ -36,6 +36,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.Vector;
 
+import org.apache.airavata.core.gfac.context.GFacConfiguration;
 import org.apache.airavata.core.gfac.exception.GfacException;
 import org.apache.airavata.core.gfac.exception.ToolsException;
 import org.apache.airavata.core.gfac.utils.GFacConstants;
@@ -91,6 +92,7 @@ public class GridFtp {
                     destClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
                     destClient.authenticate(gssCred);
                     destClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+                    makeExternalConfigurations(destClient, false);
 
                     if (!destClient.exists(destPath)) {
                         destClient.makeDir(destPath);
@@ -150,6 +152,7 @@ public class GridFtp {
             ftpClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
             ftpClient.authenticate(gsCredential);
             ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+            makeExternalConfigurations(ftpClient, false);
 
             log.debug("Uploading file");
             if (checkBinaryExtensions(remoteFile)) {
@@ -194,14 +197,14 @@ public class GridFtp {
             srcClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
             srcClient.authenticate(gsCredential);
             srcClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
-
+            makeExternalConfigurations(srcClient, true);
+            
             GridFTPClient destClient = new GridFTPClient(destContactInfo.hostName, destContactInfo.port);
             destClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
             destClient.authenticate(gsCredential);
             destClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
-
-
-           log.debug("Uploading file");
+            makeExternalConfigurations(destClient, false);
+		log.debug("Uploading file");
             if (checkBinaryExtensions(remoteFile)) {
                 log.info("Transfer mode is set to Binary for a file upload");
                 srcClient.setType(Session.TYPE_IMAGE);
@@ -252,6 +255,7 @@ public class GridFtp {
             ftpClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
             ftpClient.authenticate(gsCredential);
             ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+            makeExternalConfigurations(ftpClient, false);
 
             log.debug("Uploading file");
             if (checkBinaryExtensions(remoteFile)) {
@@ -304,6 +308,7 @@ public class GridFtp {
             ftpClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
             ftpClient.authenticate(gsCredential);
             ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+            makeExternalConfigurations(ftpClient, true);
 
             log.debug("Downloading file");
             if (checkBinaryExtensions(remoteFile)) {
@@ -401,6 +406,8 @@ public class GridFtp {
             destClient = new GridFTPClient(desthost.getHost(), desthost.getPort());
             destClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
             destClient.authenticate(gssCred);
+            makeExternalConfigurations(destClient, false);
+
             if (checkBinaryExtensions(desthost.getPath())) {
                 log.info("Transfer mode is set to Binary");
                 destClient.setType(Session.TYPE_IMAGE);
@@ -409,6 +416,8 @@ public class GridFtp {
             srcClient = new GridFTPClient(srchost.getHost(), srchost.getPort());
             srcClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
             srcClient.authenticate(gssCred);
+            makeExternalConfigurations(srcClient, true);
+
             if (checkBinaryExtensions(srchost.getPath())) {
                 log.info("Transfer mode is set to Binary");
                 srcClient.setType(Session.TYPE_IMAGE);
@@ -483,6 +492,7 @@ public class GridFtp {
 				srcClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
 				srcClient.setType(Session.TYPE_ASCII);
 				srcClient.changeDir(dirURI.getPath());
+	            makeExternalConfigurations(srcClient, true);
 
 				Vector<Object> fileInfo = null;
 				try {
@@ -542,4 +552,30 @@ public class GridFtp {
         }
 
     }
+    
+    /**
+     * This function will call the external configuration handlers to configure the GridFTPClient
+     * object.
+     * @param client
+     * @param source
+     */
+	private void makeExternalConfigurations(GridFTPClient client, boolean source) {
+		GridConfigurationHandler[] handlers = GFacConfiguration.getGridConfigurationHandlers();
+		for(GridConfigurationHandler handler:handlers){
+			try {
+				if (source) {
+					handler.handleSourceFTPClient(client);
+				}else{
+					handler.handleDestinationFTPClient(client);
+				}
+			} catch (Exception e) {
+				//TODO Right now we are just catching & ignoring the exception. But later on we need 
+				//to throw this exception to notify the user of configuration errors of their 
+				//custom configuration handlers.
+				log.error("Error while configuring GridFTPClient for "
+								+ client.getHost(), e);
+			}
+		}
+		
+	}
 }

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/phoebus/impl/PhoebusGridConfigurationHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/phoebus/impl/PhoebusGridConfigurationHandler.java?rev=1424559&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/phoebus/impl/PhoebusGridConfigurationHandler.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/phoebus/impl/PhoebusGridConfigurationHandler.java Thu Dec 20 16:12:58 2012
@@ -0,0 +1,44 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.core.gfac.phoebus.impl;
+
+import org.apache.airavata.core.gfac.external.GridConfigurationHandler;
+import org.apache.airavata.core.gfac.utils.PhoebusUtils;
+import org.globus.ftp.GridFTPClient;
+
+public class PhoebusGridConfigurationHandler implements
+		GridConfigurationHandler {
+
+	@Override
+	public void handleSourceFTPClient(GridFTPClient client) throws Exception {
+		if (PhoebusUtils.isPhoebusDefined(client.getHost())) {
+			client.site("SITE SETNETSTACK " + PhoebusUtils.getPhoebusDataChannelXIODriver(client.getHost()));
+		}
+	}
+
+	@Override
+	public void handleDestinationFTPClient(GridFTPClient client)
+			throws Exception {
+
+	}
+
+}

Propchange: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/phoebus/impl/PhoebusGridConfigurationHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/PhoebusUtils.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/PhoebusUtils.java?rev=1424559&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/PhoebusUtils.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/PhoebusUtils.java Thu Dec 20 16:12:58 2012
@@ -0,0 +1,54 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.core.gfac.utils;
+
+import org.apache.airavata.common.exception.UnspecifiedServerSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+
+public class PhoebusUtils {
+	
+	private static String PHOEBUS_DC_XIO_DRIVERS="phoebus.dc.xio_drivers";
+	
+	public static boolean isPhoebusDefined(String hostAddress) throws Exception{
+		try {
+			return getPhoebusDataChannelXIODriver(hostAddress)!=null;
+		} catch (UnspecifiedServerSettingsException e) {
+			return false;
+		}
+	}
+	
+	public static String getPhoebusDataChannelXIODriver(String hostAddress) throws Exception{
+		String driverString = ServerSettings.getSetting(PHOEBUS_DC_XIO_DRIVERS);
+		String[] hostList = driverString.split(",");
+		for (String hostString : hostList) {
+			String[] driverData = hostString.split("=");
+			if (driverData.length!=2){
+				throw new Exception("Invalid Phoebus XIO drivers settings!!!");
+			}
+			if (hostAddress.equalsIgnoreCase(driverData[0])){
+				return driverData[1];
+			}
+		}
+		throw new Exception("Phoebus XIO drivers not defined for "+hostAddress);
+	}
+
+}

Propchange: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/utils/PhoebusUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain