airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1330575 - in /incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac: external/GridFtp.java provider/impl/GramProvider.java
Date Wed, 25 Apr 2012 21:53:10 GMT
Author: lahiru
Date: Wed Apr 25 21:53:09 2012
New Revision: 1330575

URL: http://svn.apache.org/viewvc?rev=1330575&view=rev
Log:
fixing https://issues.apache.org/jira/browse/AIRAVATA-381.

Modified:
    incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java
    incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java

Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java?rev=1330575&r1=1330574&r2=1330575&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java
(original)
+++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/external/GridFtp.java
Wed Apr 25 21:53:09 2012
@@ -167,38 +167,39 @@ public class GridFtp {
     }
 
     public void uploadFile(URI srcURI,  URI destURI, GSSCredential gsCredential) throws ToolsException
{
-        GridFTPClient ftpClient = null;
-        GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
-
+        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("host"));
+            srcClient.authenticate(gsCredential);
+            srcClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
 
-            ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
-            ftpClient.setAuthorization(new HostAuthorization("host"));
-            ftpClient.authenticate(gsCredential);
-            ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+            GridFTPClient destClient = new GridFTPClient(srcContactInfo.hostName, srcContactInfo.port);
+            destClient.setAuthorization(new HostAuthorization("host"));
+            destClient.authenticate(gsCredential);
+            destClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
 
-            log.debug("Uploading file");
 
-//            ftpClient.put(remoteFile, new DataSourceStream(io), new MarkerListener() {
-//                public void markerArrived(Marker marker) {
-//                }
-//            });
+            log.debug("Uploading file");
+            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:" + contactInfo.toString(),
e);
+            throw new ToolsException("Cannot upload file to GridFTP:" + destContactInfo.toString(),
e);
         } catch (IOException e) {
-            throw new ToolsException("Cannot upload file to GridFTP:" + contactInfo.toString(),
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 (ftpClient != null) {
+            if (srcClient != null) {
                 try {
-                    ftpClient.close();
+                    srcClient.close();
                 } catch (Exception e) {
                     log.warn("Cannot close GridFTP client connection");
                 }

Modified: incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java?rev=1330575&r1=1330574&r2=1330575&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java
(original)
+++ incubator/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/provider/impl/GramProvider.java
Wed Apr 25 21:53:09 2012
@@ -21,8 +21,8 @@
 
 package org.apache.airavata.core.gfac.provider.impl;
 
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Iterator;
@@ -317,7 +317,6 @@ public class GramProvider extends Abstra
 					.getValue(paramName);
 			//TODO: Review this with type
 			if ("URI".equals(actualParameter.getType().getType().toString())) {
-				if(paramValue.startsWith("gsiftp") || paramValue.startsWith("http")){
 					URI gridftpURL;
 					try {
                         gridftpURL = new URI(paramValue);
@@ -328,19 +327,36 @@ public class GramProvider extends Abstra
                         GSSCredential gssCred = gssContext.getGssCredentails();
                         for (String endpoint : host.getGridFTPEndPointArray()) {
                             URI inputURI = GfacUtils.createGsiftpURI(endpoint, app.getInputDataDirectory());
-                            ftp.uploadFile(gridftpURL, GfacUtils.createGsiftpURI(endpoint,
inputURI.getPath() + gridftpURL.getPath()), gssCred);
+                            String fileName = new File(gridftpURL.getPath()).getName();
+                            String s = inputURI.getPath() + File.separator + fileName;
+                            URI destURI = GfacUtils.createGsiftpURI(endpoint, s);
+                            //if user give a url just to refer an endpoint, not a web resource
we are not doing any transfer
+                            if (fileName != null && !"".equals(fileName)) {
+                                if (paramValue.startsWith("gsiftp")) {
+                                    ftp.uploadFile(gridftpURL, destURI, gssCred);
+                                    ((URIParameterType) actualParameter.getType()).setValue(destURI.getPath());
+                                } else if (paramValue.startsWith("http")) {
+                                    ftp.uploadFile(destURI,
+                                            gssCred, (gridftpURL.toURL().openStream()));
+                                    ((URIParameterType) actualParameter.getType()).setValue(destURI.getPath());
+                                }else {
+                                    //todo throw exception telling unsupported protocol
+//                                    new
+                                }
+                            }
                         }
-                        ((URIParameterType) actualParameter.getType()).setValue(gridftpURL.getPath());
-                        log.info("File: " + paramValue + " moved to " + gridftpURL.getPath());
                     } catch (URISyntaxException e) {
                         throw new ProviderException(e.getMessage(), e);
                     } catch (ToolsException e) {
                         throw new ProviderException(e.getMessage(), e);
                     } catch (SecurityException e) {
                         throw new ProviderException(e.getMessage(), e);
+                    } catch (MalformedURLException e) {
+                        e.printStackTrace();  //To change body of catch statement use File
| Settings | File Templates.
+                    } catch (IOException e) {
+                        e.printStackTrace();  //To change body of catch statement use File
| Settings | File Templates.
                     }
 
-                }
             }
 			inputNew.add(paramName, actualParameter);
 		}



Mime
View raw message