You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2013/01/30 22:31:37 UTC
svn commit: r1440680 - in
/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac:
./ context/ external/ notification/events/ phoebus/ utils/
Author: lahiru
Date: Wed Jan 30 21:31:37 2013
New Revision: 1440680
URL: http://svn.apache.org/viewvc?rev=1440680&view=rev
Log:
adding more changes to new gfac architecture.
Added:
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/external/
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/external/GridFtp.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/events/StatusChangeEvent.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/phoebus/
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/phoebus/PhoebusGridConfigurationHandler.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/MyProxyManager.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/PhoebusUtils.java
Modified:
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java
airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java
Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java?rev=1440680&r1=1440679&r2=1440680&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java Wed Jan 30 21:31:37 2013
@@ -1,6 +1,12 @@
package org.apache.airavata.gfac;
import org.apache.airavata.client.api.AiravataAPI;
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.exception.UnspecifiedApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.gfac.utils.GridConfigurationHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -17,7 +23,7 @@ import java.util.List;
import java.util.Properties;
public class GFacConfiguration {
-
+ public static final Logger log = LoggerFactory.getLogger(GFacConfiguration.class);
public static final String TRUSTED_CERT_LOCATION = "trusted.cert.location";
public static final String MYPROXY_SERVER = "myproxy.server";
public static final String MYPROXY_USER = "myproxy.user";
@@ -44,6 +50,35 @@ public class GFacConfiguration {
// the provider
private List<String> outHandlers = new ArrayList<String>();
+ private static List<GridConfigurationHandler> gridConfigurationHandlers;
+
+ private static String GRID_HANDLERS="airavata.grid.handlers";
+
+ static{
+ gridConfigurationHandlers=new ArrayList<GridConfigurationHandler>();
+ try {
+ String handlerString = ServerSettings.getSetting(GRID_HANDLERS);
+ 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);
+ }
+ }
+ } catch (UnspecifiedApplicationSettingsException e) {
+ //no handlers defined
+ } catch (ApplicationSettingsException e1) {
+ log.error("Error in reading Configuration handler data!!!",e1);
+ }
+ }
+
+ public static GridConfigurationHandler[] getGridConfigurationHandlers(){
+ return gridConfigurationHandlers.toArray(new GridConfigurationHandler[]{});
+ }
public GFacConfiguration(AiravataAPI airavataAPI, Properties configurationProperties) {
this.airavataAPI = airavataAPI;
if (configurationProperties != null) {
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.gfac;
+
+
+/**
+ * Exception for all utilities
+ */
+public class ToolsException extends GFacException {
+
+ public ToolsException(String message){
+ super(message,new Throwable(message));
+ }
+ public ToolsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/GSISecurityContext.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,115 @@
+/*
+ *
+ * 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.gfac.context;
+
+import org.apache.airavata.gfac.GFacConfiguration;
+import org.apache.airavata.gfac.utils.MyProxyManager;
+import org.globus.tools.MyProxy;
+import org.ietf.jgss.GSSCredential;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GSISecurityContext extends SecurityContext {
+ protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ private MyProxyManager proxyRenewer;
+
+ private String myproxyUserName;
+
+ private String myproxyPasswd;
+
+ private String myproxyServer;
+
+ private int myproxyLifetime;
+
+ private String trustedCertLoc;
+
+ private GSSCredential gssCredentails;
+
+
+ public GSISecurityContext(GFacConfiguration configuration) {
+ this.setMyproxyLifetime(configuration.getMyProxyLifeCycle());
+ this.setMyproxyPasswd(configuration.getMyProxyPassphrase());
+ this.setMyproxyServer(configuration.getMyProxyServer());
+ this.setMyproxyUserName(configuration.getMyProxyUser());
+ this.setTrustedCertLoc(configuration.getTrustedCertLocation());
+ }
+
+ public GSSCredential getGssCredentails() throws SecurityException {
+ try {
+
+ System.out.println(gssCredentails);
+ if (gssCredentails == null || gssCredentails.getRemainingLifetime() < 10 * 90) {
+ if (proxyRenewer != null) {
+ gssCredentails = proxyRenewer.renewProxy();
+ } else if (myproxyUserName != null && myproxyPasswd != null && myproxyServer != null) {
+ this.proxyRenewer = new MyProxyManager(myproxyUserName, myproxyPasswd, MyProxy.MYPROXY_SERVER_PORT,
+ myproxyLifetime, myproxyServer, trustedCertLoc);
+ log.debug("loaded credentails from Proxy server");
+ gssCredentails = this.proxyRenewer.renewProxy();
+ }
+ }
+ return gssCredentails;
+ } catch (Exception e) {
+ throw new SecurityException(e.getMessage(), e);
+ }
+ }
+
+ public String getTrustedCertLoc() {
+ return trustedCertLoc;
+ }
+
+ public void setTrustedCertLoc(String trustedCertLoc) {
+ this.trustedCertLoc = trustedCertLoc;
+ }
+
+ public String getMyproxyUserName() {
+ return myproxyUserName;
+ }
+
+ public void setMyproxyUserName(String myproxyUserName) {
+ this.myproxyUserName = myproxyUserName;
+ }
+
+ public String getMyproxyPasswd() {
+ return myproxyPasswd;
+ }
+
+ public void setMyproxyPasswd(String myproxyPasswd) {
+ this.myproxyPasswd = myproxyPasswd;
+ }
+
+ public String getMyproxyServer() {
+ return myproxyServer;
+ }
+
+ public void setMyproxyServer(String myproxyServer) {
+ this.myproxyServer = myproxyServer;
+ }
+
+ public int getMyproxyLifetime() {
+ return myproxyLifetime;
+ }
+
+ public void setMyproxyLifetime(int myproxyLifetime) {
+ this.myproxyLifetime = myproxyLifetime;
+ }
+}
Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java?rev=1440680&r1=1440679&r2=1440680&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/context/MessageContext.java Wed Jan 30 21:31:37 2013
@@ -21,8 +21,6 @@
package org.apache.airavata.gfac.context;
-import org.apache.airavata.commons.gfac.type.ActualParameter;
-
import java.util.HashMap;
import java.util.Map;
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/external/GridFtp.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/external/GridFtp.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/external/GridFtp.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/external/GridFtp.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,581 @@
+/*
+ *
+ * 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.gfac.external;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import org.apache.airavata.gfac.GFacConfiguration;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.ToolsException;
+import org.apache.airavata.gfac.Constants;
+import org.apache.airavata.gfac.utils.GFacUtils;
+import org.apache.airavata.gfac.utils.GridConfigurationHandler;
+import org.apache.airavata.gfac.utils.GridFTPContactInfo;
+import org.globus.ftp.DataChannelAuthentication;
+import org.globus.ftp.DataSourceStream;
+import org.globus.ftp.FileInfo;
+import org.globus.ftp.GridFTPClient;
+import org.globus.ftp.HostPort;
+import org.globus.ftp.Marker;
+import org.globus.ftp.MarkerListener;
+import org.globus.ftp.MlsxEntry;
+import org.globus.ftp.Session;
+import org.globus.ftp.exception.ClientException;
+import org.globus.ftp.exception.ServerException;
+import org.globus.gsi.gssapi.auth.HostAuthorization;
+import org.ietf.jgss.GSSCredential;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * GridFTP tools
+ */
+public class GridFtp {
+ public static final Logger log = LoggerFactory.getLogger(GridFtp.class);
+
+ public static final String GSIFTP_SCHEME = "gsiftp";
+ public static final String HOST = "host";
+
+ /**
+ * Make directory at remote location
+ *
+ * @param destURI
+ * @param gssCred
+ * @throws ServerException
+ * @throws IOException
+ */
+ public void makeDir(URI destURI, GSSCredential gssCred) throws ToolsException {
+ GridFTPClient destClient = null;
+ GridFTPContactInfo destHost = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+ try {
+
+ String destPath = destURI.getPath();
+ log.info(("Creating Directory = " + destHost + "=" + destPath));
+
+ destClient = new GridFTPClient(destHost.hostName, destHost.port);
+
+ int tryCount = 0;
+ while (true) {
+ try {
+ destClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
+ destClient.authenticate(gssCred);
+ destClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+ makeExternalConfigurations(destClient, false);
+
+ if (!destClient.exists(destPath)) {
+ destClient.makeDir(destPath);
+ }
+ break;
+ } catch (ServerException e) {
+ tryCount++;
+ if (tryCount >= 3) {
+ throw new ToolsException(e.getMessage(), e);
+ }
+ Thread.sleep(10000);
+ } catch (IOException e) {
+ tryCount++;
+ if (tryCount >= 3) {
+ throw new ToolsException(e.getMessage(), e);
+ }
+ Thread.sleep(10000);
+ }
+ }
+ } catch (ServerException e) {
+ throw new ToolsException("Cannot Create GridFTP Client to:" + destHost.toString(), e);
+ } catch (IOException e) {
+ throw new ToolsException("Cannot Create GridFTP Client to:" + destHost.toString(), e);
+ } catch (InterruptedException e) {
+ throw new ToolsException("Internal Error cannot sleep", e);
+ } finally {
+ if (destClient != null) {
+ try {
+ destClient.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection",e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Upload file from stream
+ *
+ * @param destURI
+ * @param gsCredential
+ * @param io
+ * @throws GFacException
+ */
+ public void uploadFile(URI destURI, GSSCredential gsCredential, InputStream io) throws ToolsException {
+ GridFTPClient ftpClient = null;
+ GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+
+ try {
+
+ String remoteFile = destURI.getPath();
+ log.info("The remote file is " + remoteFile);
+
+ log.debug("Setup GridFTP Client");
+
+ ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+ ftpClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
+ ftpClient.authenticate(gsCredential);
+ ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+ makeExternalConfigurations(ftpClient, false);
+
+ log.info("Uploading file");
+ if (checkBinaryExtensions(remoteFile)) {
+ log.debug("Transfer mode is set to Binary for a file upload");
+ ftpClient.setType(Session.TYPE_IMAGE);
+ }
+
+
+ ftpClient.put(remoteFile, new DataSourceStream(io), new MarkerListener() {
+ public void markerArrived(Marker marker) {
+ }
+ });
+
+ log.info("Upload file to:" + remoteFile + " is done");
+
+ } catch (ServerException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+ } catch (IOException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+ } catch (ClientException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+ } finally {
+ if (ftpClient != null) {
+ try {
+ ftpClient.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection",e);
+ }
+ }
+ }
+ }
+
+ public void uploadFile(URI srcURI, URI destURI, GSSCredential gsCredential) throws ToolsException {
+ GridFTPClient srcClient = null;
+ GridFTPContactInfo destContactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+ GridFTPContactInfo srcContactInfo = new GridFTPContactInfo(srcURI.getHost(),srcURI.getPort());
+ try {
+ String remoteFile = destURI.getPath();
+ log.info("The remote file is " + remoteFile);
+ log.debug("Setup GridFTP Client");
+ srcClient = new GridFTPClient(srcContactInfo.hostName, srcContactInfo.port);
+ 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);
+ makeExternalConfigurations(destClient, false);
+ log.debug("Uploading file");
+ if (checkBinaryExtensions(remoteFile)) {
+ log.debug("Transfer mode is set to Binary for a file upload");
+ srcClient.setType(Session.TYPE_IMAGE);
+ }
+
+ srcClient.transfer(srcURI.getPath(),destClient, remoteFile, false, null);
+
+ log.info("Upload file to:" + remoteFile + " is done");
+
+ } catch (ServerException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + destContactInfo.toString(), e);
+ } catch (IOException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + destContactInfo.toString(), e);
+ } catch (ClientException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + destContactInfo.toString(), e);
+ } finally {
+ if (srcClient != null) {
+ try {
+ srcClient.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection",e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Upload file to remote location
+ *
+ * @param destURI
+ * @param gsCredential
+ * @param localFile
+ * @throws GFacException
+ */
+ public void uploadFile(URI destURI, GSSCredential gsCredential, File localFile) throws ToolsException {
+ GridFTPClient ftpClient = null;
+ GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+ try {
+
+ String remoteFile = destURI.getPath();
+
+ log.info("The local temp file is " + localFile);
+ log.info("the remote file is " + remoteFile);
+
+ log.debug("Setup GridFTP Client");
+
+ ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+ ftpClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
+ ftpClient.authenticate(gsCredential);
+ ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+ makeExternalConfigurations(ftpClient, false);
+
+ log.debug("Uploading file");
+ if (checkBinaryExtensions(remoteFile)) {
+ log.debug("Transfer mode is set to Binary for a file upload");
+ ftpClient.setType(Session.TYPE_IMAGE);
+ }
+
+
+ ftpClient.put(localFile, remoteFile, false);
+
+ log.info("Upload file to:" + remoteFile + " is done");
+
+ } catch (ServerException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+ } catch (IOException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+ } catch (ClientException e) {
+ throw new ToolsException("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+ } finally {
+ if (ftpClient != null) {
+ try {
+ ftpClient.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection",e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Download File from remote location
+ *
+ * @param destURI
+ * @param gsCredential
+ * @param localFile
+ * @throws GFacException
+ */
+ public void downloadFile(URI destURI, GSSCredential gsCredential, File localFile) throws ToolsException {
+ GridFTPClient ftpClient = null;
+ GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+ try {
+ String remoteFile = destURI.getPath();
+
+ log.info("The local temp file is " + localFile);
+ log.info("the remote file is " + remoteFile);
+
+ log.debug("Setup GridFTP Client");
+
+ ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+ ftpClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
+ ftpClient.authenticate(gsCredential);
+ ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+ makeExternalConfigurations(ftpClient, true);
+
+ log.debug("Downloading file");
+ if (checkBinaryExtensions(remoteFile)) {
+ log.debug("Transfer mode is set to Binary to download a file");
+ ftpClient.setType(Session.TYPE_IMAGE);
+ }
+
+ ftpClient.get(remoteFile, localFile);
+
+ log.info("Download file to:" + localFile + " is done");
+
+ } catch (ServerException e) {
+ throw new ToolsException("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+ } catch (IOException e) {
+ throw new ToolsException("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+ } catch (ClientException e) {
+ throw new ToolsException("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+ } finally {
+ if (ftpClient != null) {
+ try {
+ ftpClient.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection",e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Stream remote file
+ *
+ * @param destURI
+ * @param gsCredential
+ * @param localFile
+ * @return
+ * @throws GFacException
+ */
+ public String readRemoteFile(URI destURI, GSSCredential gsCredential, File localFile) throws ToolsException {
+ BufferedReader instream = null;
+ File localTempfile = null;
+ try {
+
+ if (localFile == null) {
+ localTempfile = File.createTempFile("stderr", "err");
+ } else {
+ localTempfile = localFile;
+ }
+
+ log.info("Loca temporary file:" + localTempfile);
+
+ downloadFile(destURI, gsCredential, localTempfile);
+
+ instream = new BufferedReader(new FileReader(localTempfile));
+ StringBuffer buff = new StringBuffer();
+ String temp = null;
+ while ((temp = instream.readLine()) != null) {
+ buff.append(temp);
+ buff.append(Constants.NEWLINE);
+ }
+
+ log.info("finish read file:" + localTempfile);
+
+ return buff.toString();
+ } catch (FileNotFoundException e) {
+ throw new ToolsException("Cannot read localfile file:" + localTempfile, e);
+ } catch (IOException e) {
+ throw new ToolsException("Cannot read localfile file:" + localTempfile, e);
+ } finally {
+ if (instream != null) {
+ try {
+ instream.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection",e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Transfer data from one GridFTp Endpoint to another GridFTP Endpoint
+ *
+ * @param srchost
+ * @param desthost
+ * @param gssCred
+ * @param srcActive
+ * @throws ServerException
+ * @throws ClientException
+ * @throws IOException
+ */
+ public void transfer(URI srchost, URI desthost, GSSCredential gssCred, boolean srcActive) throws ToolsException {
+ GridFTPClient destClient = null;
+ GridFTPClient srcClient = null;
+
+ try {
+ destClient = new GridFTPClient(desthost.getHost(), desthost.getPort());
+ destClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
+ destClient.authenticate(gssCred);
+ makeExternalConfigurations(destClient, false);
+
+ if (checkBinaryExtensions(desthost.getPath())) {
+ log.debug("Transfer mode is set to Binary");
+ destClient.setType(Session.TYPE_IMAGE);
+ }
+
+ srcClient = new GridFTPClient(srchost.getHost(), srchost.getPort());
+ srcClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
+ srcClient.authenticate(gssCred);
+ makeExternalConfigurations(srcClient, true);
+
+ if (checkBinaryExtensions(srchost.getPath())) {
+ log.debug("Transfer mode is set to Binary");
+ srcClient.setType(Session.TYPE_IMAGE);
+ }
+
+ if (srcActive) {
+ log.debug("Set src active");
+ HostPort hp = destClient.setPassive();
+ srcClient.setActive(hp);
+ } else {
+ log.debug("Set dst active");
+ HostPort hp = srcClient.setPassive();
+ destClient.setActive(hp);
+ }
+
+ log.debug("Start transfer file from GridFTP:" + srchost.toString() + " to " + desthost.toString());
+
+ /**
+ * Transfer a file. The transfer() function blocks until the transfer is complete.
+ */
+ srcClient.transfer(srchost.getPath(), destClient, desthost.getPath(), false, null);
+ if (srcClient.getSize(srchost.getPath()) == destClient.getSize(desthost.getPath())) {
+ log.debug("CHECK SUM OK");
+ } else {
+ log.debug("****CHECK SUM FAILED****");
+ }
+
+ } catch (ServerException e) {
+ throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+ + desthost.toString(), e);
+ } catch (IOException e) {
+ throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+ + desthost.toString(), e);
+ } catch (ClientException e) {
+ throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+ + desthost.toString(), e);
+ } finally {
+ if (destClient != null) {
+ try {
+ destClient.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection at Desitnation:" + desthost.toString());
+ }
+ }
+ if (srcClient != null) {
+ try {
+ srcClient.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection at Source:" + srchost.toString(),e);
+ }
+ }
+ }
+ }
+
+ /**
+ * List files in a GridFTP directory
+ * @param dirURI
+ * @param gssCred
+ * @return
+ * @throws ToolsException
+ */
+ @SuppressWarnings("unchecked")
+ public List<String> listDir(URI dirURI, GSSCredential gssCred) throws ToolsException {
+ List<String> files = new ArrayList<String>();
+ GridFTPClient srcClient = null;
+ try {
+ GridFTPContactInfo contactInfo = new GridFTPContactInfo(dirURI.getHost(), dirURI.getPort());
+
+ srcClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+ srcClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
+ srcClient.authenticate(gssCred);
+ srcClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+ srcClient.setType(Session.TYPE_ASCII);
+ srcClient.changeDir(dirURI.getPath());
+ makeExternalConfigurations(srcClient, true);
+
+ Vector<Object> fileInfo = null;
+ try {
+ fileInfo = srcClient.mlsd();
+ } catch (Throwable e) {
+ fileInfo = srcClient.list();
+ }
+
+ if (!fileInfo.isEmpty()) {
+ for (int j = 0; j < fileInfo.size(); ++j) {
+ String name = null;
+ if (fileInfo.get(j) instanceof MlsxEntry) {
+ name = ((MlsxEntry) fileInfo.get(j)).getFileName();
+ } else if (fileInfo.get(j) instanceof FileInfo) {
+ name = ((FileInfo) fileInfo.get(j)).getName();
+ } else {
+ throw new ToolsException("Unsupported type returned by gridftp " + fileInfo.get(j));
+ }
+
+ if (!name.equals(".") && !name.equals("..")) {
+ URI uri = GFacUtils.createGsiftpURI(contactInfo.hostName, dirURI.getPath() + File.separator + name);
+ files.add(uri.getPath());
+ }
+ }
+ }
+ return files;
+ } catch (IOException e) {
+ throw new ToolsException("Could not list directory: " + dirURI.toString() ,e);
+ } catch (ServerException e) {
+ throw new ToolsException("Could not list directory: " + dirURI.toString() ,e);
+ } catch (ClientException e) {
+ throw new ToolsException("Could not list directory: " + dirURI.toString() ,e);
+ } catch (URISyntaxException e) {
+ throw new ToolsException("Error creating URL of listed files: " + dirURI.toString() ,e);
+ } finally {
+ if (srcClient != null) {
+ try {
+ srcClient.close();
+ } catch (Exception e) {
+ log.warn("Cannot close GridFTP client connection", e);
+ }
+ }
+ }
+ }
+ /**
+ * Method to check file extension as binary to set transfer type
+ * @param filePath
+ * @return
+ */
+ private static boolean checkBinaryExtensions(String filePath){
+ String extension = filePath.substring(filePath.lastIndexOf(".")+1,filePath.length());
+ Set<String> extensions = new HashSet<String>(Arrays.asList(new String[] {"tar","zip","gz","tgz"}));
+ if(extensions.contains(extension)){
+ return true;
+ }else{
+ return false;
+ }
+
+ }
+
+ /**
+ * 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/gfac/notification/events/StatusChangeEvent.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/events/StatusChangeEvent.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/events/StatusChangeEvent.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/notification/events/StatusChangeEvent.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.gfac.notification.events;
+
+public class StatusChangeEvent extends GFacEvent {
+
+ public StatusChangeEvent(){
+ this.eventType = StatusChangeEvent.class.getSimpleName();
+ }
+}
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/phoebus/PhoebusGridConfigurationHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/phoebus/PhoebusGridConfigurationHandler.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/phoebus/PhoebusGridConfigurationHandler.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/phoebus/PhoebusGridConfigurationHandler.java Wed Jan 30 21:31:37 2013
@@ -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.gfac.phoebus;
+
+import org.apache.airavata.gfac.utils.GridConfigurationHandler;
+import org.apache.airavata.gfac.utils.PhoebusUtils;
+import org.globus.ftp.DataChannelAuthentication;
+import org.globus.ftp.GridFTPClient;
+
+public class PhoebusGridConfigurationHandler implements GridConfigurationHandler{
+ @Override
+ public void handleSourceFTPClient(GridFTPClient client) throws Exception {
+ if (PhoebusUtils.isPhoebusDriverConfigurationsDefined(client.getHost())) {
+ client.setDataChannelAuthentication(DataChannelAuthentication.NONE);
+ client.site("SITE SETNETSTACK phoebus:" + PhoebusUtils.getPhoebusDataChannelXIODriverParameters(client.getHost()));
+ }
+ }
+ @Override
+ public void handleDestinationFTPClient(GridFTPClient client)
+ throws Exception {
+
+ }
+}
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,135 @@
+/*
+ *
+ * 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.gfac.utils;
+
+import org.apache.airavata.gfac.context.GSISecurityContext;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.notification.events.StatusChangeEvent;
+import org.globus.gram.GramException;
+import org.globus.gram.GramJob;
+import org.globus.gram.GramJobListener;
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GramJobSubmissionListener implements GramJobListener{
+ private final Logger log = LoggerFactory.getLogger(GramJobSubmissionListener.class);
+ public static final String MYPROXY_SECURITY_CONTEXT = "myproxy";
+ private static final int JOB_PROXY_REMAINING_TIME_LIMIT = 900;
+
+ private static final long JOB_FINISH_WAIT_TIME = 60 * 1000l;
+ private boolean finished;
+ private int error;
+ private int status;
+ private JobExecutionContext context;
+ private GramJob job;
+
+ public GramJobSubmissionListener(GramJob job, JobExecutionContext context) {
+ this.job = job;
+ this.context = context;
+ }
+
+ /**
+ * This method is used to block the process until the status of the job is DONE or FAILED
+ *
+ * @throws InterruptedException
+ * @throws GSSException
+ * @throws GramException
+ * @throws SecurityException
+ */
+ public void waitFor() throws InterruptedException, GSSException, GramException, SecurityException {
+ while (!isFinished()) {
+ int proxyExpTime = job.getCredentials().getRemainingLifetime();
+ if (proxyExpTime < JOB_PROXY_REMAINING_TIME_LIMIT) {
+ log.info("Job proxy expired. Trying to renew proxy");
+ GSSCredential gssCred = (new GSISecurityContext(context.getGFacConfiguration())).getGssCredentails();
+ job.renew(gssCred);
+ log.info("Myproxy renewed");
+ }
+
+ synchronized (this) {
+
+ /*
+ * job status is changed but method isn't invoked
+ */
+ if (status != 0) {
+ if (job.getStatus() != status) {
+ log.info("Change job status manually");
+ if (setStatus(job.getStatus(), job.getError())) {
+ break;
+ }
+ } else {
+ log.info("job " + job.getIDAsString() + " have same status: "
+ + GramJob.getStatusAsString(status));
+ }
+ } else {
+ log.info("Status is zero");
+ }
+
+ wait(JOB_FINISH_WAIT_TIME);
+ }
+ }
+ }
+
+ private synchronized boolean isFinished() {
+ return this.finished;
+ }
+
+ private synchronized boolean setStatus(int status, int error) {
+ this.status = status;
+ this.error = error;
+
+ switch (this.status) {
+ case GramJob.STATUS_FAILED:
+ log.info("Job Error Code: " + error);
+ case GramJob.STATUS_DONE:
+ this.finished = true;
+ }
+
+ return this.finished;
+ }
+
+ public void statusChanged(GramJob job) {
+ String jobStatusMessage = "Status of job " + job.getIDAsString() + "is " + job.getStatusAsString();
+ log.info(jobStatusMessage);
+
+ /*
+ * Notify status change
+ */
+ this.context.getNotifier().publish(new StatusChangeEvent());
+
+ /*
+ * Set new status if it is finished, notify all wait object
+ */
+ if (setStatus(job.getStatus(), job.getError())) {
+ notifyAll();
+ }
+ }
+
+ public synchronized int getError() {
+ return error;
+ }
+
+ public synchronized int getStatus() {
+ return status;
+ }
+}
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,24 @@
+/*
+ *
+ * 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.gfac.utils;
+
+public class GramProviderUtils {
+}
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.gfac.utils;
+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;
+}
+
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/MyProxyManager.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/MyProxyManager.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/MyProxyManager.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/MyProxyManager.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,118 @@
+/*
+ *
+ * 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.gfac.utils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.UUID;
+
+import org.globus.gsi.GlobusCredential;
+import org.globus.gsi.TrustedCertificates;
+import org.globus.gsi.gssapi.GlobusGSSCredentialImpl;
+import org.globus.myproxy.MyProxy;
+import org.globus.myproxy.MyProxyException;
+import org.ietf.jgss.GSSCredential;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MyProxyManager {
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ private final String username;
+ private final String password;
+ private final int port;
+ private final int lifetime;
+ private final String hostname;
+ private String trustedCertsLoc;
+
+ public MyProxyManager(final String username, final String password, final int port, final int lifetime,
+ final String hostname) {
+ this.username = username;
+ this.password = password;
+ this.port = port;
+ this.lifetime = lifetime;
+ this.hostname = hostname;
+ }
+
+ public MyProxyManager(final String username, final String password, final int port, final int lifetime,
+ final String hostname, String trustedCertsLoc) {
+ this.username = username;
+ this.password = password;
+ this.port = port;
+ this.lifetime = lifetime;
+ this.hostname = hostname;
+ this.trustedCertsLoc = trustedCertsLoc;
+ }
+
+ private void init() {
+ if (trustedCertsLoc != null) {
+ TrustedCertificates certificates = TrustedCertificates.load(trustedCertsLoc);
+ TrustedCertificates.setDefaultTrustedCertificates(certificates);
+ }
+ }
+
+ public GSSCredential renewProxy() throws MyProxyException, IOException {
+
+ init();
+ String proxyloc = null;
+ MyProxy myproxy = new MyProxy(hostname, port);
+ GSSCredential proxy = myproxy.get(username, password, lifetime);
+ GlobusCredential globusCred = null;
+ if (proxy instanceof GlobusGSSCredentialImpl) {
+ globusCred = ((GlobusGSSCredentialImpl) proxy).getGlobusCredential();
+ log.debug("got proxy from myproxy for " + username + " with " + lifetime + " lifetime.");
+ String uid = username;
+ // uid = XpolaUtil.getSysUserid();
+ log.debug("uid: " + uid);
+ proxyloc = "/tmp/x509up_u" + uid + UUID.randomUUID().toString();
+ log.debug("proxy location: " + proxyloc);
+ File proxyfile = new File(proxyloc);
+ if (!proxyfile.exists()) {
+ String dirpath = proxyloc.substring(0, proxyloc.lastIndexOf('/'));
+ File dir = new File(dirpath);
+ if (!dir.exists()) {
+ if (dir.mkdirs()) {
+ log.debug("new directory " + dirpath + " is created.");
+ } else {
+ log.error("error in creating directory " + dirpath);
+ }
+ }
+ proxyfile.createNewFile();
+ log.debug("new proxy file " + proxyloc + " is created.");
+ }
+ FileOutputStream fout = null;
+ try {
+ fout = new FileOutputStream(proxyfile);
+ globusCred.save(fout);
+ } finally {
+ if (fout != null) {
+ fout.close();
+ }
+ }
+ Runtime.getRuntime().exec("/bin/chmod 600 " + proxyloc);
+ log.info("Proxy file renewed to " + proxyloc + " for the user " + username + " with " + lifetime
+ + " lifetime.");
+
+ }
+ return proxy;
+ }
+}
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/PhoebusUtils.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/PhoebusUtils.java?rev=1440680&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/PhoebusUtils.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/PhoebusUtils.java Wed Jan 30 21:31:37 2013
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.gfac.utils;
+
+import org.apache.airavata.common.exception.UnspecifiedApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+
+public class PhoebusUtils {
+ private static String PHOEBUS_DC_XIO_DRIVERS="dc.phoebus.xio_driver_configurations";
+
+ public static boolean isPhoebusDriverConfigurationsDefined(String hostAddress) throws Exception{
+ try {
+ return getPhoebusDataChannelXIODriverParameters(hostAddress)!=null;
+ } catch (UnspecifiedApplicationSettingsException e) {
+ return false;
+ }
+ }
+
+ public static String getPhoebusDataChannelXIODriverParameters(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);
+ }
+
+}