copying gridftp client code from sandbox
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/9fd6be25 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/9fd6be25 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/9fd6be25 Branch: refs/heads/develop Commit: 9fd6be25a69b9e6a6af8406da300ed02d21024f4 Parents: dceabc8 Author: scnakandala <[email protected]> Authored: Thu Dec 24 02:01:01 2015 -0500 Committer: scnakandala <[email protected]> Committed: Thu Dec 24 02:01:01 2015 -0500 ---------------------------------------------------------------------- .../lib/airavata/replica_models_types.cpp | 24 +- .../lib/airavata/replica_models_types.h | 14 +- .../lib/Airavata/Model/File/Replica/Types.php | 16 +- .../airavata/model/file/replica/ttypes.py | 18 +- .../airavata/model/file/replica/FileModel.java | 112 ++--- modules/file-manager/file-manager-core/pom.xml | 23 + .../core/db/dao/FileTransferRequestDao.java | 10 - .../remote/client/gridftp/ExecutionContext.java | 184 ++++++++ .../core/remote/client/gridftp/GridFTP.java | 430 +++++++++++++++++++ .../remote/client/gridftp/GridFTPConstants.java | 45 ++ .../client/gridftp/GridFTPContactInfo.java | 60 +++ .../gridftp/myproxy/CertificateManager.java | 87 ++++ .../gridftp/myproxy/MyProxyCredentials.java | 296 +++++++++++++ .../client/gridftp/myproxy/SecurityContext.java | 211 +++++++++ .../remote/client/scp/SCPStorageClient.java | 19 - .../main/resources/gridftp-client.properties | 30 ++ .../core/db/dao/FileTransferRequestDaoTest.java | 45 ++ .../remote/client/gridftp/CertFileReadTest.java | 126 ++++++ .../remote/client/gridftp/FileTransferTest.java | 168 ++++++++ .../remote/client/scp/SCPStorageClientTest.java | 55 +++ .../airavata-myproxy-client.properties | 28 ++ .../file-manager-core/src/test/resources/dummy | 0 .../file-manager-models/replica_models.thrift | 2 +- 23 files changed, 1881 insertions(+), 122 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.cpp ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.cpp b/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.cpp index cd2a8cf..b5c3027 100644 --- a/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.cpp +++ b/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.cpp @@ -403,9 +403,9 @@ void FileModel::__set_fileSize(const int32_t val) { __isset.fileSize = true; } -void FileModel::__set_nativeFormat(const std::string& val) { - this->nativeFormat = val; -__isset.nativeFormat = true; +void FileModel::__set_dataType(const std::string& val) { + this->dataType = val; +__isset.dataType = true; } void FileModel::__set_creationTime(const int64_t val) { @@ -540,8 +540,8 @@ uint32_t FileModel::read(::apache::thrift::protocol::TProtocol* iprot) { break; case 11: if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->nativeFormat); - this->__isset.nativeFormat = true; + xfer += iprot->readString(this->dataType); + this->__isset.dataType = true; } else { xfer += iprot->skip(ftype); } @@ -657,9 +657,9 @@ uint32_t FileModel::write(::apache::thrift::protocol::TProtocol* oprot) const { xfer += oprot->writeI32(this->fileSize); xfer += oprot->writeFieldEnd(); } - if (this->__isset.nativeFormat) { - xfer += oprot->writeFieldBegin("nativeFormat", ::apache::thrift::protocol::T_STRING, 11); - xfer += oprot->writeString(this->nativeFormat); + if (this->__isset.dataType) { + xfer += oprot->writeFieldBegin("dataType", ::apache::thrift::protocol::T_STRING, 11); + xfer += oprot->writeString(this->dataType); xfer += oprot->writeFieldEnd(); } if (this->__isset.creationTime) { @@ -702,7 +702,7 @@ void swap(FileModel &a, FileModel &b) { swap(a.sha256Checksum, b.sha256Checksum); swap(a.fileType, b.fileType); swap(a.fileSize, b.fileSize); - swap(a.nativeFormat, b.nativeFormat); + swap(a.dataType, b.dataType); swap(a.creationTime, b.creationTime); swap(a.lastModifiedTime, b.lastModifiedTime); swap(a.fileReplicas, b.fileReplicas); @@ -720,7 +720,7 @@ FileModel::FileModel(const FileModel& other27) { sha256Checksum = other27.sha256Checksum; fileType = other27.fileType; fileSize = other27.fileSize; - nativeFormat = other27.nativeFormat; + dataType = other27.dataType; creationTime = other27.creationTime; lastModifiedTime = other27.lastModifiedTime; fileReplicas = other27.fileReplicas; @@ -737,7 +737,7 @@ FileModel& FileModel::operator=(const FileModel& other28) { sha256Checksum = other28.sha256Checksum; fileType = other28.fileType; fileSize = other28.fileSize; - nativeFormat = other28.nativeFormat; + dataType = other28.dataType; creationTime = other28.creationTime; lastModifiedTime = other28.lastModifiedTime; fileReplicas = other28.fileReplicas; @@ -757,7 +757,7 @@ void FileModel::printTo(std::ostream& out) const { out << ", " << "sha256Checksum="; (__isset.sha256Checksum ? (out << to_string(sha256Checksum)) : (out << "<null>")); out << ", " << "fileType="; (__isset.fileType ? (out << to_string(fileType)) : (out << "<null>")); out << ", " << "fileSize="; (__isset.fileSize ? (out << to_string(fileSize)) : (out << "<null>")); - out << ", " << "nativeFormat="; (__isset.nativeFormat ? (out << to_string(nativeFormat)) : (out << "<null>")); + out << ", " << "dataType="; (__isset.dataType ? (out << to_string(dataType)) : (out << "<null>")); out << ", " << "creationTime="; (__isset.creationTime ? (out << to_string(creationTime)) : (out << "<null>")); out << ", " << "lastModifiedTime="; (__isset.lastModifiedTime ? (out << to_string(lastModifiedTime)) : (out << "<null>")); out << ", " << "fileReplicas="; (__isset.fileReplicas ? (out << to_string(fileReplicas)) : (out << "<null>")); http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.h ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.h b/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.h index f8136a4..73569cc 100644 --- a/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.h +++ b/airavata-api/airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/replica_models_types.h @@ -178,7 +178,7 @@ inline std::ostream& operator<<(std::ostream& out, const FileCollectionModel& ob } typedef struct _FileModel__isset { - _FileModel__isset() : fileId(false), gatewayId(false), username(false), sharedUsers(false), sharedPublic(false), fileName(false), fileDescription(false), sha256Checksum(false), fileType(false), fileSize(false), nativeFormat(false), creationTime(false), lastModifiedTime(false), fileReplicas(false) {} + _FileModel__isset() : fileId(false), gatewayId(false), username(false), sharedUsers(false), sharedPublic(false), fileName(false), fileDescription(false), sha256Checksum(false), fileType(false), fileSize(false), dataType(false), creationTime(false), lastModifiedTime(false), fileReplicas(false) {} bool fileId :1; bool gatewayId :1; bool username :1; @@ -189,7 +189,7 @@ typedef struct _FileModel__isset { bool sha256Checksum :1; bool fileType :1; bool fileSize :1; - bool nativeFormat :1; + bool dataType :1; bool creationTime :1; bool lastModifiedTime :1; bool fileReplicas :1; @@ -200,7 +200,7 @@ class FileModel { FileModel(const FileModel&); FileModel& operator=(const FileModel&); - FileModel() : fileId(), gatewayId(), username(), sharedPublic(0), fileName(), fileDescription(), sha256Checksum(), fileType((FileModelType::type)0), fileSize(0), nativeFormat(), creationTime(0), lastModifiedTime(0) { + FileModel() : fileId(), gatewayId(), username(), sharedPublic(0), fileName(), fileDescription(), sha256Checksum(), fileType((FileModelType::type)0), fileSize(0), dataType(), creationTime(0), lastModifiedTime(0) { } virtual ~FileModel() throw(); @@ -214,7 +214,7 @@ class FileModel { std::string sha256Checksum; FileModelType::type fileType; int32_t fileSize; - std::string nativeFormat; + std::string dataType; int64_t creationTime; int64_t lastModifiedTime; std::vector<FileReplicaModel> fileReplicas; @@ -241,7 +241,7 @@ class FileModel { void __set_fileSize(const int32_t val); - void __set_nativeFormat(const std::string& val); + void __set_dataType(const std::string& val); void __set_creationTime(const int64_t val); @@ -291,9 +291,9 @@ class FileModel { return false; else if (__isset.fileSize && !(fileSize == rhs.fileSize)) return false; - if (__isset.nativeFormat != rhs.__isset.nativeFormat) + if (__isset.dataType != rhs.__isset.dataType) return false; - else if (__isset.nativeFormat && !(nativeFormat == rhs.nativeFormat)) + else if (__isset.dataType && !(dataType == rhs.dataType)) return false; if (__isset.creationTime != rhs.__isset.creationTime) return false; http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Airavata/Model/File/Replica/Types.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Airavata/Model/File/Replica/Types.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Airavata/Model/File/Replica/Types.php index de67d7a..7ccf94c 100644 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Airavata/Model/File/Replica/Types.php +++ b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Airavata/Model/File/Replica/Types.php @@ -384,7 +384,7 @@ class FileModel { /** * @var string */ - public $nativeFormat = null; + public $dataType = null; /** * @var int */ @@ -446,7 +446,7 @@ class FileModel { 'type' => TType::I32, ), 11 => array( - 'var' => 'nativeFormat', + 'var' => 'dataType', 'type' => TType::STRING, ), 12 => array( @@ -499,8 +499,8 @@ class FileModel { if (isset($vals['fileSize'])) { $this->fileSize = $vals['fileSize']; } - if (isset($vals['nativeFormat'])) { - $this->nativeFormat = $vals['nativeFormat']; + if (isset($vals['dataType'])) { + $this->dataType = $vals['dataType']; } if (isset($vals['creationTime'])) { $this->creationTime = $vals['creationTime']; @@ -615,7 +615,7 @@ class FileModel { break; case 11: if ($ftype == TType::STRING) { - $xfer += $input->readString($this->nativeFormat); + $xfer += $input->readString($this->dataType); } else { $xfer += $input->skip($ftype); } @@ -727,9 +727,9 @@ class FileModel { $xfer += $output->writeI32($this->fileSize); $xfer += $output->writeFieldEnd(); } - if ($this->nativeFormat !== null) { - $xfer += $output->writeFieldBegin('nativeFormat', TType::STRING, 11); - $xfer += $output->writeString($this->nativeFormat); + if ($this->dataType !== null) { + $xfer += $output->writeFieldBegin('dataType', TType::STRING, 11); + $xfer += $output->writeString($this->dataType); $xfer += $output->writeFieldEnd(); } if ($this->creationTime !== null) { http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/replica/ttypes.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/replica/ttypes.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/replica/ttypes.py index 0abb029..df2ddf5 100644 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/replica/ttypes.py +++ b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/replica/ttypes.py @@ -255,7 +255,7 @@ class FileModel: - sha256Checksum - fileType - fileSize - - nativeFormat + - dataType - creationTime - lastModifiedTime - fileReplicas @@ -273,13 +273,13 @@ class FileModel: (8, TType.STRING, 'sha256Checksum', None, None, ), # 8 (9, TType.I32, 'fileType', None, None, ), # 9 (10, TType.I32, 'fileSize', None, None, ), # 10 - (11, TType.STRING, 'nativeFormat', None, None, ), # 11 + (11, TType.STRING, 'dataType', None, None, ), # 11 (12, TType.I64, 'creationTime', None, None, ), # 12 (13, TType.I64, 'lastModifiedTime', None, None, ), # 13 (14, TType.LIST, 'fileReplicas', (TType.STRUCT,(FileReplicaModel, FileReplicaModel.thrift_spec)), None, ), # 14 ) - def __init__(self, fileId=None, gatewayId=None, username=None, sharedUsers=None, sharedPublic=None, fileName=None, fileDescription=None, sha256Checksum=None, fileType=None, fileSize=None, nativeFormat=None, creationTime=None, lastModifiedTime=None, fileReplicas=None,): + def __init__(self, fileId=None, gatewayId=None, username=None, sharedUsers=None, sharedPublic=None, fileName=None, fileDescription=None, sha256Checksum=None, fileType=None, fileSize=None, dataType=None, creationTime=None, lastModifiedTime=None, fileReplicas=None,): self.fileId = fileId self.gatewayId = gatewayId self.username = username @@ -290,7 +290,7 @@ class FileModel: self.sha256Checksum = sha256Checksum self.fileType = fileType self.fileSize = fileSize - self.nativeFormat = nativeFormat + self.dataType = dataType self.creationTime = creationTime self.lastModifiedTime = lastModifiedTime self.fileReplicas = fileReplicas @@ -361,7 +361,7 @@ class FileModel: iprot.skip(ftype) elif fid == 11: if ftype == TType.STRING: - self.nativeFormat = iprot.readString() + self.dataType = iprot.readString() else: iprot.skip(ftype) elif fid == 12: @@ -438,9 +438,9 @@ class FileModel: oprot.writeFieldBegin('fileSize', TType.I32, 10) oprot.writeI32(self.fileSize) oprot.writeFieldEnd() - if self.nativeFormat is not None: - oprot.writeFieldBegin('nativeFormat', TType.STRING, 11) - oprot.writeString(self.nativeFormat) + if self.dataType is not None: + oprot.writeFieldBegin('dataType', TType.STRING, 11) + oprot.writeString(self.dataType) oprot.writeFieldEnd() if self.creationTime is not None: oprot.writeFieldBegin('creationTime', TType.I64, 12) @@ -476,7 +476,7 @@ class FileModel: value = (value * 31) ^ hash(self.sha256Checksum) value = (value * 31) ^ hash(self.fileType) value = (value * 31) ^ hash(self.fileSize) - value = (value * 31) ^ hash(self.nativeFormat) + value = (value * 31) ^ hash(self.dataType) value = (value * 31) ^ hash(self.creationTime) value = (value * 31) ^ hash(self.lastModifiedTime) value = (value * 31) ^ hash(self.fileReplicas) http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/airavata-api/airavata-data-models/src/main/java/org/apache/airavata/model/file/replica/FileModel.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-data-models/src/main/java/org/apache/airavata/model/file/replica/FileModel.java b/airavata-api/airavata-data-models/src/main/java/org/apache/airavata/model/file/replica/FileModel.java index f36825c..bd1d357 100644 --- a/airavata-api/airavata-data-models/src/main/java/org/apache/airavata/model/file/replica/FileModel.java +++ b/airavata-api/airavata-data-models/src/main/java/org/apache/airavata/model/file/replica/FileModel.java @@ -65,7 +65,7 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ private static final org.apache.thrift.protocol.TField SHA256_CHECKSUM_FIELD_DESC = new org.apache.thrift.protocol.TField("sha256Checksum", org.apache.thrift.protocol.TType.STRING, (short)8); private static final org.apache.thrift.protocol.TField FILE_TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("fileType", org.apache.thrift.protocol.TType.I32, (short)9); private static final org.apache.thrift.protocol.TField FILE_SIZE_FIELD_DESC = new org.apache.thrift.protocol.TField("fileSize", org.apache.thrift.protocol.TType.I32, (short)10); - private static final org.apache.thrift.protocol.TField NATIVE_FORMAT_FIELD_DESC = new org.apache.thrift.protocol.TField("nativeFormat", org.apache.thrift.protocol.TType.STRING, (short)11); + private static final org.apache.thrift.protocol.TField DATA_TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("dataType", org.apache.thrift.protocol.TType.STRING, (short)11); private static final org.apache.thrift.protocol.TField CREATION_TIME_FIELD_DESC = new org.apache.thrift.protocol.TField("creationTime", org.apache.thrift.protocol.TType.I64, (short)12); private static final org.apache.thrift.protocol.TField LAST_MODIFIED_TIME_FIELD_DESC = new org.apache.thrift.protocol.TField("lastModifiedTime", org.apache.thrift.protocol.TType.I64, (short)13); private static final org.apache.thrift.protocol.TField FILE_REPLICAS_FIELD_DESC = new org.apache.thrift.protocol.TField("fileReplicas", org.apache.thrift.protocol.TType.LIST, (short)14); @@ -86,7 +86,7 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ private String sha256Checksum; // optional private FileModelType fileType; // optional private int fileSize; // optional - private String nativeFormat; // optional + private String dataType; // optional private long creationTime; // optional private long lastModifiedTime; // optional private List<FileReplicaModel> fileReplicas; // optional @@ -107,7 +107,7 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ */ FILE_TYPE((short)9, "fileType"), FILE_SIZE((short)10, "fileSize"), - NATIVE_FORMAT((short)11, "nativeFormat"), + DATA_TYPE((short)11, "dataType"), CREATION_TIME((short)12, "creationTime"), LAST_MODIFIED_TIME((short)13, "lastModifiedTime"), FILE_REPLICAS((short)14, "fileReplicas"); @@ -145,8 +145,8 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ return FILE_TYPE; case 10: // FILE_SIZE return FILE_SIZE; - case 11: // NATIVE_FORMAT - return NATIVE_FORMAT; + case 11: // DATA_TYPE + return DATA_TYPE; case 12: // CREATION_TIME return CREATION_TIME; case 13: // LAST_MODIFIED_TIME @@ -198,7 +198,7 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ private static final int __CREATIONTIME_ISSET_ID = 2; private static final int __LASTMODIFIEDTIME_ISSET_ID = 3; private byte __isset_bitfield = 0; - private static final _Fields optionals[] = {_Fields.FILE_ID,_Fields.GATEWAY_ID,_Fields.USERNAME,_Fields.SHARED_USERS,_Fields.SHARED_PUBLIC,_Fields.FILE_NAME,_Fields.FILE_DESCRIPTION,_Fields.SHA256_CHECKSUM,_Fields.FILE_TYPE,_Fields.FILE_SIZE,_Fields.NATIVE_FORMAT,_Fields.CREATION_TIME,_Fields.LAST_MODIFIED_TIME,_Fields.FILE_REPLICAS}; + private static final _Fields optionals[] = {_Fields.FILE_ID,_Fields.GATEWAY_ID,_Fields.USERNAME,_Fields.SHARED_USERS,_Fields.SHARED_PUBLIC,_Fields.FILE_NAME,_Fields.FILE_DESCRIPTION,_Fields.SHA256_CHECKSUM,_Fields.FILE_TYPE,_Fields.FILE_SIZE,_Fields.DATA_TYPE,_Fields.CREATION_TIME,_Fields.LAST_MODIFIED_TIME,_Fields.FILE_REPLICAS}; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); @@ -223,7 +223,7 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, FileModelType.class))); tmpMap.put(_Fields.FILE_SIZE, new org.apache.thrift.meta_data.FieldMetaData("fileSize", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); - tmpMap.put(_Fields.NATIVE_FORMAT, new org.apache.thrift.meta_data.FieldMetaData("nativeFormat", org.apache.thrift.TFieldRequirementType.OPTIONAL, + tmpMap.put(_Fields.DATA_TYPE, new org.apache.thrift.meta_data.FieldMetaData("dataType", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); tmpMap.put(_Fields.CREATION_TIME, new org.apache.thrift.meta_data.FieldMetaData("creationTime", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); @@ -271,8 +271,8 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ this.fileType = other.fileType; } this.fileSize = other.fileSize; - if (other.isSetNativeFormat()) { - this.nativeFormat = other.nativeFormat; + if (other.isSetDataType()) { + this.dataType = other.dataType; } this.creationTime = other.creationTime; this.lastModifiedTime = other.lastModifiedTime; @@ -303,7 +303,7 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ this.fileType = null; setFileSizeIsSet(false); this.fileSize = 0; - this.nativeFormat = null; + this.dataType = null; setCreationTimeIsSet(false); this.creationTime = 0; setLastModifiedTimeIsSet(false); @@ -562,26 +562,26 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __FILESIZE_ISSET_ID, value); } - public String getNativeFormat() { - return this.nativeFormat; + public String getDataType() { + return this.dataType; } - public void setNativeFormat(String nativeFormat) { - this.nativeFormat = nativeFormat; + public void setDataType(String dataType) { + this.dataType = dataType; } - public void unsetNativeFormat() { - this.nativeFormat = null; + public void unsetDataType() { + this.dataType = null; } - /** Returns true if field nativeFormat is set (has been assigned a value) and false otherwise */ - public boolean isSetNativeFormat() { - return this.nativeFormat != null; + /** Returns true if field dataType is set (has been assigned a value) and false otherwise */ + public boolean isSetDataType() { + return this.dataType != null; } - public void setNativeFormatIsSet(boolean value) { + public void setDataTypeIsSet(boolean value) { if (!value) { - this.nativeFormat = null; + this.dataType = null; } } @@ -749,11 +749,11 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ } break; - case NATIVE_FORMAT: + case DATA_TYPE: if (value == null) { - unsetNativeFormat(); + unsetDataType(); } else { - setNativeFormat((String)value); + setDataType((String)value); } break; @@ -816,8 +816,8 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ case FILE_SIZE: return getFileSize(); - case NATIVE_FORMAT: - return getNativeFormat(); + case DATA_TYPE: + return getDataType(); case CREATION_TIME: return getCreationTime(); @@ -859,8 +859,8 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ return isSetFileType(); case FILE_SIZE: return isSetFileSize(); - case NATIVE_FORMAT: - return isSetNativeFormat(); + case DATA_TYPE: + return isSetDataType(); case CREATION_TIME: return isSetCreationTime(); case LAST_MODIFIED_TIME: @@ -974,12 +974,12 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ return false; } - boolean this_present_nativeFormat = true && this.isSetNativeFormat(); - boolean that_present_nativeFormat = true && that.isSetNativeFormat(); - if (this_present_nativeFormat || that_present_nativeFormat) { - if (!(this_present_nativeFormat && that_present_nativeFormat)) + boolean this_present_dataType = true && this.isSetDataType(); + boolean that_present_dataType = true && that.isSetDataType(); + if (this_present_dataType || that_present_dataType) { + if (!(this_present_dataType && that_present_dataType)) return false; - if (!this.nativeFormat.equals(that.nativeFormat)) + if (!this.dataType.equals(that.dataType)) return false; } @@ -1067,10 +1067,10 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ if (present_fileSize) list.add(fileSize); - boolean present_nativeFormat = true && (isSetNativeFormat()); - list.add(present_nativeFormat); - if (present_nativeFormat) - list.add(nativeFormat); + boolean present_dataType = true && (isSetDataType()); + list.add(present_dataType); + if (present_dataType) + list.add(dataType); boolean present_creationTime = true && (isSetCreationTime()); list.add(present_creationTime); @@ -1198,12 +1198,12 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ return lastComparison; } } - lastComparison = Boolean.valueOf(isSetNativeFormat()).compareTo(other.isSetNativeFormat()); + lastComparison = Boolean.valueOf(isSetDataType()).compareTo(other.isSetDataType()); if (lastComparison != 0) { return lastComparison; } - if (isSetNativeFormat()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.nativeFormat, other.nativeFormat); + if (isSetDataType()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.dataType, other.dataType); if (lastComparison != 0) { return lastComparison; } @@ -1349,13 +1349,13 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ sb.append(this.fileSize); first = false; } - if (isSetNativeFormat()) { + if (isSetDataType()) { if (!first) sb.append(", "); - sb.append("nativeFormat:"); - if (this.nativeFormat == null) { + sb.append("dataType:"); + if (this.dataType == null) { sb.append("null"); } else { - sb.append(this.nativeFormat); + sb.append(this.dataType); } first = false; } @@ -1516,10 +1516,10 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; - case 11: // NATIVE_FORMAT + case 11: // DATA_TYPE if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { - struct.nativeFormat = iprot.readString(); - struct.setNativeFormatIsSet(true); + struct.dataType = iprot.readString(); + struct.setDataTypeIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } @@ -1645,10 +1645,10 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ oprot.writeI32(struct.fileSize); oprot.writeFieldEnd(); } - if (struct.nativeFormat != null) { - if (struct.isSetNativeFormat()) { - oprot.writeFieldBegin(NATIVE_FORMAT_FIELD_DESC); - oprot.writeString(struct.nativeFormat); + if (struct.dataType != null) { + if (struct.isSetDataType()) { + oprot.writeFieldBegin(DATA_TYPE_FIELD_DESC); + oprot.writeString(struct.dataType); oprot.writeFieldEnd(); } } @@ -1724,7 +1724,7 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ if (struct.isSetFileSize()) { optionals.set(9); } - if (struct.isSetNativeFormat()) { + if (struct.isSetDataType()) { optionals.set(10); } if (struct.isSetCreationTime()) { @@ -1773,8 +1773,8 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ if (struct.isSetFileSize()) { oprot.writeI32(struct.fileSize); } - if (struct.isSetNativeFormat()) { - oprot.writeString(struct.nativeFormat); + if (struct.isSetDataType()) { + oprot.writeString(struct.dataType); } if (struct.isSetCreationTime()) { oprot.writeI64(struct.creationTime); @@ -1847,8 +1847,8 @@ public class FileModel implements org.apache.thrift.TBase<FileModel, FileModel._ struct.setFileSizeIsSet(true); } if (incoming.get(10)) { - struct.nativeFormat = iprot.readString(); - struct.setNativeFormatIsSet(true); + struct.dataType = iprot.readString(); + struct.setDataTypeIsSet(true); } if (incoming.get(11)) { struct.creationTime = iprot.readI64(); http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/pom.xml ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/pom.xml b/modules/file-manager/file-manager-core/pom.xml index affeea9..b8e98e2 100644 --- a/modules/file-manager/file-manager-core/pom.xml +++ b/modules/file-manager/file-manager-core/pom.xml @@ -59,6 +59,29 @@ </dependency> <dependency> + <groupId>org.jglobus</groupId> + <artifactId>gss</artifactId> + <version>${jglobus.version}</version> + </dependency> + <dependency> + <groupId>org.jglobus</groupId> + <artifactId>gridftp</artifactId> + <version>${jglobus.version}</version> + </dependency> + <dependency> + <groupId>org.jglobus</groupId> + <artifactId>myproxy</artifactId> + <version>2.1.0</version> + </dependency> + + <dependency> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-jdk16</artifactId> + <version>1.44</version> + </dependency> + + + <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.3</version> http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileTransferRequestDao.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileTransferRequestDao.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileTransferRequestDao.java index afae6d0..6bfb40e 100644 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileTransferRequestDao.java +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileTransferRequestDao.java @@ -89,14 +89,4 @@ public class FileTransferRequestDao { } return null; } - - public static void main(String[] args) throws IOException { - FileTransferRequestModel fileTransferRequestModel = new FileTransferRequestModel(); - fileTransferRequestModel.setSrcHostCredToken("djkalbsbdaslfbalsfbslf"); - fileTransferRequestModel.setSrcFilePath("test-file-path"); - FileTransferRequestDao fileTransferRequestDao = new FileTransferRequestDao(); - String transferId = fileTransferRequestDao.createFileTransferRequest(fileTransferRequestModel); - fileTransferRequestModel = fileTransferRequestDao.getFileTransferRequest(transferId); - System.out.println("Transfer Id:" + fileTransferRequestModel.getTransferId()); - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/ExecutionContext.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/ExecutionContext.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/ExecutionContext.java new file mode 100644 index 0000000..37da5f9 --- /dev/null +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/ExecutionContext.java @@ -0,0 +1,184 @@ +/* + * + * 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.file.manager.core.remote.client.gridftp; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Properties; + +@SuppressWarnings("UnusedDeclaration") +public class ExecutionContext { + + private String testingHost; + + private String loneStarGridFTP; + private String rangerGridFTP; + private String trestlesGridFTP; + + private String gridFTPServerSource; + private String sourceDataLocation; + private String gridFTPServerDestination; + private String destinationDataLocation; + private String uploadingFilePath; + + public static final String PROPERTY_FILE = "airavata-myproxy-client.properties"; + + public ExecutionContext() throws IOException { + loadConfigurations(); + } + + private void loadConfigurations() throws IOException { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + InputStream propertyStream = classLoader.getResourceAsStream(PROPERTY_FILE); + + Properties properties = new Properties(); + if (propertyStream != null) { + properties.load(propertyStream); + + String testingHost = properties.getProperty(GridFTPConstants.TESTINGHOST); + + String loneStarGridFtp = properties.getProperty(GridFTPConstants.LONESTARGRIDFTPEPR); + String rangerGridFtp = properties.getProperty(GridFTPConstants.RANGERGRIDFTPEPR); + String trestlesGridFtp = properties.getProperty(GridFTPConstants.TRESTLESGRIDFTPEPR); + + String gridFTPServerSource = properties.getProperty(GridFTPConstants.GRIDFTPSERVERSOURCE); + String gridFTPSourcePath = properties.getProperty(GridFTPConstants.GRIDFTPSOURCEPATH); + String gridFTPServerDestination = properties.getProperty(GridFTPConstants.GRIDFTPSERVERDEST); + String gridFTPDestinationPath = properties.getProperty(GridFTPConstants.GRIDFTPDESTPATH); + String gridFTPUploadingPath = properties.getProperty(GridFTPConstants.UPLOADING_FILE_PATH); + + if (testingHost != null) { + this.testingHost = testingHost; + } + + if (loneStarGridFtp != null) { + this.loneStarGridFTP = loneStarGridFtp; + } + if (rangerGridFtp != null) { + this.rangerGridFTP= rangerGridFtp; + } + if (trestlesGridFtp != null) { + this.trestlesGridFTP = trestlesGridFtp; + } + + if (gridFTPServerSource != null && !gridFTPServerSource.isEmpty()) { + this.gridFTPServerSource = gridFTPServerSource; + } + if (gridFTPSourcePath != null && !gridFTPSourcePath.isEmpty()) { + this.sourceDataLocation = gridFTPSourcePath; + } + if (gridFTPServerDestination != null && !gridFTPServerDestination.isEmpty()) { + this.gridFTPServerDestination = gridFTPServerDestination; + } + if (gridFTPDestinationPath != null && !gridFTPDestinationPath.isEmpty()) { + this.destinationDataLocation = gridFTPDestinationPath; + } + if (gridFTPUploadingPath != null && !gridFTPUploadingPath.isEmpty()) { + this.uploadingFilePath = gridFTPUploadingPath; + } + + } + } + + public String getTestingHost() { + return testingHost; + } + + public void setTestingHost(String testingHost) { + this.testingHost = testingHost; + } + + public String getLoneStarGridFTP() { + return loneStarGridFTP; + } + + public void setLoneStarGridFTP(String loneStarGridFTP) { + this.loneStarGridFTP = loneStarGridFTP; + } + + public String getRangerGridFTP() { + return rangerGridFTP; + } + + public void setRangerGridFTP(String rangerGridFTP) { + this.rangerGridFTP = rangerGridFTP; + } + + public String getTrestlesGridFTP() { + return trestlesGridFTP; + } + + public void setTrestlesGridFTP(String trestlesGridFTP) { + this.trestlesGridFTP = trestlesGridFTP; + } + + public String getGridFTPServerSource() { + return gridFTPServerSource; + } + + public void setGridFTPServerSource(String gridFTPServerSource) { + this.gridFTPServerSource = gridFTPServerSource; + } + + public URI getSourceDataFileUri() throws URISyntaxException { + String file = gridFTPServerSource + getSourceDataLocation(); + return new URI(file); + } + + public URI getUploadingFilePathUri() throws URISyntaxException { + String file = gridFTPServerSource + getUploadingFilePath(); + return new URI(file); + } + + public String getUploadingFilePath() { + return uploadingFilePath; + } + + public void setUploadingFilePath(String uploadingFilePath) { + this.uploadingFilePath = uploadingFilePath; + } + + public String getSourceDataLocation() { + return sourceDataLocation; + } + + public void setSourceDataLocation(String sourceDataLocation) { + this.sourceDataLocation = sourceDataLocation; + } + + public String getGridFTPServerDestination() { + return gridFTPServerDestination; + } + + public void setGridFTPServerDestination(String gridFTPServerDestination) { + this.gridFTPServerDestination = gridFTPServerDestination; + } + + public String getDestinationDataLocation() { + return destinationDataLocation; + } + + public void setDestinationDataLocation(String destinationDataLocation) { + this.destinationDataLocation = destinationDataLocation; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTP.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTP.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTP.java new file mode 100644 index 0000000..89bfba3 --- /dev/null +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTP.java @@ -0,0 +1,430 @@ +/* + * + * 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.file.manager.core.remote.client.gridftp; + + +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 org.apache.log4j.Logger; +import org.globus.ftp.DataChannelAuthentication; +import org.globus.ftp.DataSourceStream; +import org.globus.ftp.GridFTPClient; +import org.globus.ftp.HostPort; +import org.globus.ftp.Marker; +import org.globus.ftp.MarkerListener; +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; + +/** + * GridFTP tools + */ +public class GridFTP { + + public static final String GSIFTP_SCHEME = "gsiftp"; + private static final Logger log = Logger.getLogger(GridFTP.class); + + /** + * Make directory at remote location + * + * @param destURI Directory name and server location to create the directory. + * @param gssCred Credentials to authenticate with remote server. + * @throws ServerException If an error occurred while authenticating. + * @throws IOException If an error occurred while creating the directory. + */ + public void makeDir(URI destURI, GSSCredential gssCred) throws Exception { + 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("host")); + destClient.authenticate(gssCred); + destClient.setDataChannelAuthentication(DataChannelAuthentication.SELF); + + if (!destClient.exists(destPath)) { + destClient.makeDir(destPath); + } + break; + } catch (ServerException e) { + tryCount++; + if (tryCount >= 3) { + throw new Exception(e.getMessage(), e); + } + Thread.sleep(10000); + } catch (IOException e) { + tryCount++; + if (tryCount >= 3) { + throw new Exception(e.getMessage(), e); + } + Thread.sleep(10000); + } + } + } catch (ServerException e) { + throw new Exception("Cannot Create GridFTP Client to:" + destHost.toString(), e); + } catch (IOException e) { + throw new Exception("Cannot Create GridFTP Client to:" + destHost.toString(), e); + } catch (InterruptedException e) { + throw new Exception("Internal Error cannot sleep", e); + } finally { + if (destClient != null) { + try { + destClient.close(); + } catch (Exception e) { + log.info("Cannot close GridFTP client connection"); + } + } + } + } + + /** + * Upload file from stream + * + * @param destURI Name of the file to be uploaded. + * @param gsCredential Credentials to authenticate. + */ + public void updateFile(URI destURI, GSSCredential gsCredential, InputStream io) throws Exception { + GridFTPClient ftpClient = null; + GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort()); + + try { + + String remoteFile = destURI.getPath(); + log.info("The remote file is " + remoteFile); + + log.info("Setup GridFTP Client"); + + ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port); + ftpClient.setAuthorization(new HostAuthorization("host")); + ftpClient.authenticate(gsCredential); + ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF); + + log.info("Uploading file"); + + 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 Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e); + } catch (IOException e) { + throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e); + } catch (ClientException e) { + throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e); + } finally { + if (ftpClient != null) { + try { + ftpClient.close(); + } catch (Exception e) { + log.info("Cannot close GridFTP client connection"); + } + } + } + } + + /** + * Upload file to remote location + * + * @param destURI Name of the file to be uploaded. + * @param gsCredential Credentials used to upload the file. + * @param localFile Local file to be uploaded. + */ + public void updateFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception { + 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.info("Setup GridFTP Client"); + + ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port); + ftpClient.setAuthorization(new HostAuthorization("host")); + ftpClient.authenticate(gsCredential); + ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF); + + log.info("Uploading file"); + + ftpClient.put(localFile, remoteFile, false); + + + log.info("Upload file to:" + remoteFile + " is done"); + + } catch (ServerException e) { + throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e); + } catch (IOException e) { + throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e); + } catch (ClientException e) { + throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e); + } finally { + if (ftpClient != null) { + try { + ftpClient.close(); + } catch (Exception e) { + log.info("Cannot close GridFTP client connection"); + } + } + } + } + + /** + * Download File from remote location + * + * @param destURI File to be downloaded. + * @param gsCredential To authenticate user to remote machine. + * @param localFile The downloaded file name. + */ + public void downloadFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception { + 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.info("Setup GridFTP Client"); + + ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port); + ftpClient.setAuthorization(new HostAuthorization("host")); + ftpClient.authenticate(gsCredential); + ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF); + + log.info("Downloading file"); + + ftpClient.get(remoteFile, localFile); + + log.info("Download file to:" + remoteFile + " is done"); + + } catch (ServerException e) { + throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e); + } catch (IOException e) { + throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e); + } catch (ClientException e) { + throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e); + } finally { + if (ftpClient != null) { + try { + ftpClient.close(); + } catch (Exception e) { + log.info("Cannot close GridFTP client connection"); + } + } + } + } + + /** + * Checks whether files exists. + * + * @param destURI Name of the file to check existence. + * @param gsCredential Credentials to authenticate user. + */ + public boolean exists(URI destURI, GSSCredential gsCredential) throws Exception { + GridFTPClient ftpClient = null; + GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort()); + try { + String remoteFile = destURI.getPath(); + + log.info("the remote file is " + remoteFile); + + log.info("Setup GridFTP Client"); + + ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port); + ftpClient.setAuthorization(new HostAuthorization("host")); + ftpClient.authenticate(gsCredential); + ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF); + + log.info("Checking whether file exists"); + + return ftpClient.exists(destURI.getPath()); + + } catch (ServerException e) { + throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e); + } catch (IOException e) { + throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e); + } finally { + if (ftpClient != null) { + try { + ftpClient.close(); + } catch (Exception e) { + log.info("Cannot close GridFTP client connection"); + } + } + } + } + + /** + * Stream remote file + * + * @param destURI Remote file to be read. + * @param gsCredential Credentials to authenticate user. + * @param localFile Downloaded local file name. + * @return The content of the downloaded file. + */ + public String readRemoteFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception { + 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(System.getProperty("line.separator")); + } + + log.info("finish read file:" + localTempfile); + + return buff.toString(); + } catch (FileNotFoundException e) { + throw new Exception("Cannot read localfile file:" + localTempfile, e); + } catch (IOException e) { + throw new Exception("Cannot read localfile file:" + localTempfile, e); + } finally { + if (instream != null) { + try { + instream.close(); + } catch (Exception e) { + log.info("Cannot close GridFTP client connection"); + } + } + } + } + + /** + * Transfer data from one GridFTp Endpoint to another GridFTP Endpoint + * + * @param srchost Source file and host. + * @param desthost Destination file and host. + * @param gssCred Credentials to be authenticate user. + * @param srcActive Tells source to be active. i.e. asking src to connect destination. + * @throws ServerException If an error occurred while transferring data. + * @throws ClientException If an error occurred while transferring data. + * @throws IOException If an error occurred while transferring data. + */ + public void transfer(URI srchost, URI desthost, GSSCredential gssCred, boolean srcActive) throws Exception { + GridFTPClient destClient = null; + GridFTPClient srcClient = null; + + try { + destClient = new GridFTPClient(desthost.getHost(), desthost.getPort()); + destClient.setAuthorization(new HostAuthorization("host")); + destClient.authenticate(gssCred); + destClient.setType(Session.TYPE_IMAGE); + + srcClient = new GridFTPClient(srchost.getHost(), srchost.getPort()); + srcClient.setAuthorization(new HostAuthorization("host")); + srcClient.authenticate(gssCred); + srcClient.setType(Session.TYPE_IMAGE); + + if (srcActive) { + log.info("Set src active"); + HostPort hp = destClient.setPassive(); + srcClient.setActive(hp); + } else { + log.info("Set dst active"); + HostPort hp = srcClient.setPassive(); + destClient.setActive(hp); + } + + log.info("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.info("CHECK SUM OK"); + } else { + log.info("****CHECK SUM FAILED****"); + } + + } catch (ServerException e) { + throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to " + + desthost.toString(), e); + } catch (IOException e) { + throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to " + + desthost.toString(), e); + } catch (ClientException e) { + throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to " + + desthost.toString(), e); + } finally { + if (destClient != null) { + try { + destClient.close(); + } catch (Exception e) { + log.info("Cannot close GridFTP client connection at Desitnation:" + desthost.toString()); + } + } + if (srcClient != null) { + try { + srcClient.close(); + } catch (Exception e) { + log.info("Cannot close GridFTP client connection at Source:" + srchost.toString()); + } + } + } + } + + public static URI createGsiftpURI(String host, String localPath) throws URISyntaxException { + StringBuffer buf = new StringBuffer(); + if (!host.startsWith("gsiftp://")) + buf.append("gsiftp://"); + buf.append(host); + if (!host.endsWith("/")) + buf.append("/"); + buf.append(localPath); + return new URI(buf.toString()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPConstants.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPConstants.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPConstants.java new file mode 100644 index 0000000..5e00df0 --- /dev/null +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPConstants.java @@ -0,0 +1,45 @@ +/* + * + * 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.file.manager.core.remote.client.gridftp; + +public class GridFTPConstants { + + public static final String MYPROXY_SERVER = "myproxyServer"; + public static final String MYPROXY_PORT = "myproxyPort"; + public static final String MYPROXY_LIFETIME = "myproxy_lifetime"; + public static final String MYPROXY_USERNAME = "myproxyUserName"; + public static final String MYPROXY_PASSWD = "myproxyPasswd"; + public static final String TRUSTED_CERTS_FILE = "trustedCertsFile"; + public static final String HOSTCERTS_KEY_FILE = "hostcertsKeyFile"; + + public static final String TESTINGHOST = "testing.host"; + + public static final String LONESTARGRIDFTPEPR = "lonestar.gridftp.endpoint"; + public static final String RANGERGRIDFTPEPR = "ranger.gridftp.endpoint"; + public static final String TRESTLESGRIDFTPEPR = "trestles.gridftp.endpoint"; + + public static final String GRIDFTPSERVERSOURCE = "gridftpserverSource"; + public static final String GRIDFTPSOURCEPATH = "gridftpSourcePath"; + public static final String GRIDFTPSERVERDEST = "gridftpserverDest"; + public static final String GRIDFTPDESTPATH = "gridftpDestPath"; + public static final String UPLOADING_FILE_PATH = "gridftpUploadingFilePath"; + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPContactInfo.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPContactInfo.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPContactInfo.java new file mode 100644 index 0000000..060f015 --- /dev/null +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPContactInfo.java @@ -0,0 +1,60 @@ +/* + * + * 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.file.manager.core.remote.client.gridftp; + +/** +* Class represents GridFTP Endpoint +* +*/ +public class GridFTPContactInfo { + public static final int DEFAULT_GSI_FTP_PORT = 2811; + public String hostName; + public int port; + + public GridFTPContactInfo(String hostName, int port) { + if (port <= 0 || port == 80) { + port = DEFAULT_GSI_FTP_PORT; + } + this.hostName = hostName; + this.port = port; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof GridFTPContactInfo) { + return hostName.equals(((GridFTPContactInfo) obj).hostName) && port == ((GridFTPContactInfo) obj).port; + } else { + return false; + } + } + + @Override + public int hashCode() { + return hostName.hashCode(); + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append(hostName).append(":").append(port); + return buf.toString(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/CertificateManager.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/CertificateManager.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/CertificateManager.java new file mode 100644 index 0000000..00d9343 --- /dev/null +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/CertificateManager.java @@ -0,0 +1,87 @@ +/* + * + * 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.file.manager.core.remote.client.gridftp.myproxy; + +import java.io.InputStream; +import java.security.GeneralSecurityException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; + +import org.globus.gsi.util.CertificateLoadUtil; +import org.globus.util.ClassLoaderUtils; + +public class CertificateManager { + + private static X509Certificate[] trustedCertificates; + + /** + * Load CA certificates from a file included in the XBaya jar. + * + * @return The trusted certificates. + */ + public static X509Certificate[] getTrustedCertificate(String certificate) { + if (trustedCertificates != null) { + return trustedCertificates; + } + + List<X509Certificate> extremeTrustedCertificates = getTrustedCertificates(certificate); + + List<X509Certificate> allTrustedCertificates = new ArrayList<X509Certificate>(); + allTrustedCertificates.addAll(extremeTrustedCertificates); + + trustedCertificates = allTrustedCertificates.toArray(new X509Certificate[allTrustedCertificates.size()]); + return trustedCertificates; + } + + private static List<X509Certificate> getTrustedCertificates(String pass) { + // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); //** + // InputStream stream = classLoader.getResourceAsStream(pass); //** + InputStream stream = ClassLoaderUtils.getResourceAsStream(pass); // ** + if (stream == null) { + throw new RuntimeException("Failed to get InputStream to " + pass); + } + return readTrustedCertificates(stream); + } + + /** + * @param stream + * @return List of X509Certificate + */ + public static List<X509Certificate> readTrustedCertificates(InputStream stream) { + ArrayList<X509Certificate> certificates = new ArrayList<X509Certificate>(); + while (true) { + X509Certificate certificate; + try { + certificate = CertificateLoadUtil.loadCertificate(stream); + } catch (GeneralSecurityException e) { + String message = "Certificates are invalid"; + throw new RuntimeException(message, e); + } + if (certificate == null) { + break; + } + certificates.add(certificate); + } + return certificates; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/MyProxyCredentials.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/MyProxyCredentials.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/MyProxyCredentials.java new file mode 100644 index 0000000..23dfd5e --- /dev/null +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/MyProxyCredentials.java @@ -0,0 +1,296 @@ +/* + * + * 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.file.manager.core.remote.client.gridftp.myproxy; + +import java.io.*; +import java.security.PrivateKey; +import java.security.cert.X509Certificate; + +import org.apache.log4j.Logger; +import org.globus.gsi.X509Credential; +import org.globus.gsi.gssapi.GlobusGSSCredentialImpl; +import org.globus.myproxy.GetParams; +import org.globus.myproxy.MyProxy; +import org.ietf.jgss.GSSCredential; + +/** + * Class to manipulate my proxy credentials. Responsible for retrieving, creating + * my proxy credentials. + */ +public class MyProxyCredentials implements Serializable { + + private static final long serialVersionUID = -2471014486509046212L; + protected String myProxyHostname; + protected String myProxyUserName; + protected String myProxyPassword; + protected int myProxyPortNumber; + protected int myProxyLifeTime = 14400; + protected String trustedCertificatePath; + + private static final Logger log = Logger.getLogger(MyProxyCredentials.class); + + /** + * Default constructor. + */ + public MyProxyCredentials() { + } + + /** + * Constructor. + * @param myProxyServer Ip address of the my proxy server. + * @param myProxyPort Port which my proxy server is running. + * @param myProxyUsername User name to connect to my proxy server. + * @param myProxyPassPhrase Password for my proxy authentication. + * @param myProxyLifetime Lifetime of the retrieving credentials. + * @param trustedCerts Trusted certificate location for SSL communication. + */ + public MyProxyCredentials(String myProxyServer, int myProxyPort, String myProxyUsername, String myProxyPassPhrase, + int myProxyLifetime, String trustedCerts) { + + this.myProxyHostname = myProxyServer; + this.myProxyPortNumber = myProxyPort; + this.myProxyUserName = myProxyUsername; + this.myProxyPassword = myProxyPassPhrase; + this.myProxyLifeTime = myProxyLifetime; + this.trustedCertificatePath = trustedCerts; + + init(); + + } + + /** + * Gets the default proxy certificate. + * @return Default my proxy credentials. + * @throws Exception If an error occurred while retrieving credentials. + */ + public GSSCredential getDefaultCredentials() throws Exception { + MyProxy myproxy = new MyProxy(this.myProxyHostname, this.myProxyPortNumber); + return myproxy.get(this.myProxyUserName, this.myProxyPassword, this.myProxyLifeTime); + } + + /** + * Gets a new proxy certificate given current credentials. + * @param credential The new proxy credentials. + * @return The short lived GSSCredentials + * @throws Exception If an error is occurred while retrieving credentials. + */ + public GSSCredential getProxyCredentials(GSSCredential credential) throws Exception { + + MyProxy myproxy = new MyProxy(this.myProxyHostname, this.myProxyPortNumber); + return myproxy.get(credential, this.myProxyUserName, this.myProxyPassword, this.myProxyLifeTime); + } + + /** + * Renew GSSCredentials. + * @param credential Credentials to be renewed. + * @return Renewed credentials. + * @throws Exception If an error occurred while renewing credentials. + */ + public GSSCredential renewCredentials(GSSCredential credential) throws Exception { + MyProxy myproxy = new MyProxy(this.myProxyHostname, this.myProxyPortNumber); + + GetParams getParams = new GetParams(); + getParams.setAuthzCreds(credential); + getParams.setUserName(this.myProxyUserName); + getParams.setLifetime(this.getMyProxyLifeTime()); + + return myproxy.get(credential, getParams); + } + + public GSSCredential createCredentials(X509Certificate[] x509Certificates, PrivateKey privateKey) throws Exception { + X509Credential newCredential = new X509Credential(privateKey, + x509Certificates); + + return new GlobusGSSCredentialImpl(newCredential, + GSSCredential.INITIATE_AND_ACCEPT); + + } + + public GSSCredential createCredentials(X509Certificate x509Certificate, PrivateKey privateKey) throws Exception { + + X509Certificate[] x509Certificates = new X509Certificate[1]; + x509Certificates[0] = x509Certificate; + + return createCredentials(x509Certificates, privateKey); + + } + + public void init() { + validateTrustedCertificatePath(); + } + + private void validateTrustedCertificatePath() { + + File file = new File(this.trustedCertificatePath); + + if (!file.exists() || !file.canRead()) { + File f = new File("."); + System.out.println("Current directory " + f.getAbsolutePath()); + throw new RuntimeException("Cannot read trusted certificate path " + this.trustedCertificatePath); + } else { + System.setProperty("X509_CERT_DIR", file.getAbsolutePath()); + } + } + + + /** + * @return the myProxyHostname + */ + public String getMyProxyHostname() { + return myProxyHostname; + } + + /** + * @param myProxyHostname the myProxyHostname to set + */ + public void setMyProxyHostname(String myProxyHostname) { + this.myProxyHostname = myProxyHostname; + } + + /** + * @return the myProxyUserName + */ + public String getMyProxyUserName() { + return myProxyUserName; + } + + /** + * @param myProxyUserName the myProxyUserName to set + */ + public void setMyProxyUserName(String myProxyUserName) { + this.myProxyUserName = myProxyUserName; + } + + /** + * @return the myProxyPassword + */ + public String getMyProxyPassword() { + return myProxyPassword; + } + + /** + * @param myProxyPassword the myProxyPassword to set + */ + public void setMyProxyPassword(String myProxyPassword) { + this.myProxyPassword = myProxyPassword; + } + + /** + * @return the myProxyLifeTime + */ + public int getMyProxyLifeTime() { + return myProxyLifeTime; + } + + /** + * @param myProxyLifeTime the myProxyLifeTime to set + */ + public void setMyProxyLifeTime(int myProxyLifeTime) { + this.myProxyLifeTime = myProxyLifeTime; + } + + /** + * @return the myProxyPortNumber + */ + public int getMyProxyPortNumber() { + return myProxyPortNumber; + } + + /** + * @param myProxyPortNumber the myProxyPortNumber to set + */ + public void setMyProxyPortNumber(int myProxyPortNumber) { + this.myProxyPortNumber = myProxyPortNumber; + } + + public String getTrustedCertificatePath() { + return trustedCertificatePath; + } + + public void setTrustedCertificatePath(String trustedCertificatePath) { + this.trustedCertificatePath = trustedCertificatePath; + } + + /** + * @return the portalUserName + */ + /*public String getPortalUserName() { + return portalUserName; + }*/ + + /** + * @param portalUserName + * the portalUserName to set + */ + /*public void setPortalUserName(String portalUserName) { + this.portalUserName = portalUserName; + }*/ + + /** + * Returns the initialized. + * + * @return The initialized + */ + /*public boolean isInitialized() { + return this.initialized; + }*/ + + /** + * Sets initialized. + * + * @param initialized + * The initialized to set. + */ + /* public void setInitialized(boolean initialized) { + this.initialized = initialized; + }*/ + + /** + * @param hostcertsKeyFile + * the hostcertsKeyFile to set + */ + /*public void setHostcertsKeyFile(String hostcertsKeyFile) { + this.hostcertsKeyFile = hostcertsKeyFile; + }*/ + + /** + * @return the hostcertsKeyFile + */ + /*public String getHostcertsKeyFile() { + return hostcertsKeyFile; + }*/ + + /** + * @param trustedCertsFile + * the trustedCertsFile to set + */ + /*public void setTrustedCertsFile(String trustedCertsFile) { + this.trustedCertsFile = trustedCertsFile; + }*/ + + /** + * @return the trustedCertsFile + */ + /*public String getTrustedCertsFile() { + return trustedCertsFile; + }*/ + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/SecurityContext.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/SecurityContext.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/SecurityContext.java new file mode 100644 index 0000000..eb1a541 --- /dev/null +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/SecurityContext.java @@ -0,0 +1,211 @@ +/* + * + * 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.file.manager.core.remote.client.gridftp.myproxy; + +import java.io.File; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.airavata.file.manager.core.remote.client.gridftp.GridFTPConstants; +import org.apache.log4j.Logger; +import org.globus.myproxy.MyProxy; +import org.ietf.jgss.GSSCredential; + +public class SecurityContext { + + /** + * + */ + public static final String GRIDFTP_CLIENT_PROPERTY = "gridftp-client.properties"; + private Properties properties; + protected GSSCredential gssCredential; + + private MyProxyCredentials myProxyCredentials; + private static final Logger log = Logger.getLogger(SecurityContext.class); + + private String userName = null; + private String password = null; + + /** + * + * Constructs a ApplicationGlobalContext. + * + * @throws Exception + */ + + public SecurityContext() throws Exception { + log.setLevel(org.apache.log4j.Level.INFO); + loadConfiguration(); + + } + + public SecurityContext(String user, String pwd) throws Exception { + + this.userName = user; + this.password = pwd; + + log.setLevel(org.apache.log4j.Level.INFO); + loadConfiguration(); + + } + + /** + * + * @throws Exception + */ + public void login() throws Exception { + gssCredential = myProxyCredentials.getDefaultCredentials(); + } + + public GSSCredential getProxyCredentials(GSSCredential credential) throws Exception { + return myProxyCredentials.getProxyCredentials(credential); + } + + public GSSCredential renewCredentials(GSSCredential credential) throws Exception { + return myProxyCredentials.renewCredentials(credential); + } + + public static String getProperty(String name) { + try { + SecurityContext context = new SecurityContext(); + return context.getProperties().getProperty(name); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + + } + + /** + * Load the configration file + * + * @throws Exception + */ + private void loadConfiguration() throws Exception { + try { + + System.out.println("In the load configurations method ....."); + + if (properties == null) { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + + InputStream propertyStream = classLoader.getResourceAsStream(GRIDFTP_CLIENT_PROPERTY); + properties = new Properties(); + if (myProxyCredentials == null) { + this.myProxyCredentials = new MyProxyCredentials(); + } + if (propertyStream != null) { + properties.load(propertyStream); + String myproxyServerTmp = properties.getProperty(GridFTPConstants.MYPROXY_SERVER); + if (myproxyServerTmp != null) { + this.myProxyCredentials.setMyProxyHostname(myproxyServerTmp.trim()); + } + String myproxyPortTemp = properties.getProperty(GridFTPConstants.MYPROXY_PORT); + if (myproxyPortTemp != null && myproxyPortTemp.trim().length() > 0) { + this.myProxyCredentials.setMyProxyPortNumber(Integer.parseInt(myproxyPortTemp.trim())); + } else { + this.myProxyCredentials.setMyProxyPortNumber(MyProxy.DEFAULT_PORT); + } + + this.myProxyCredentials.setMyProxyUserName(userName); + this.myProxyCredentials.setMyProxyPassword(password); + + String myproxytime = properties.getProperty(GridFTPConstants.MYPROXY_LIFETIME); + if (myproxytime != null) { + this.myProxyCredentials.setMyProxyLifeTime(Integer.parseInt(myproxytime)); + } + + String currentDirectory = System.getProperty("projectDirectory"); + String certificatePath = currentDirectory + File.separatorChar + + properties.getProperty(GridFTPConstants.TRUSTED_CERTS_FILE); + + this.myProxyCredentials.setTrustedCertificatePath(certificatePath); + + System.out.println("Certificate path - " + certificatePath); + + this.myProxyCredentials.init(); + } + } + + } catch (Exception e) { + e.printStackTrace(); + log.error(e.getLocalizedMessage()); + throw new Exception(e); + } + + } + + /** + * @return the properties + */ + public Properties getProperties() { + return properties; + } + + /** + * @param properties + * the properties to set + */ + public void setProperties(Properties properties) { + this.properties = properties; + } + + /** + * Returns the raw gssCredential, without creating a proxy. + * + * @return The gssCredential + */ + public GSSCredential getRawCredential() throws Exception{ + + return gssCredential; + } + + /** + * Returns the gssCredential. + * + * @return The gssCredential + */ + public GSSCredential getGssCredential() throws Exception{ + + if (this.gssCredential == null) + return null; + + return renewCredentials(gssCredential); + } + + /** + * Sets gssCredential. + * + * @param gssCredential + * The gssCredential to set. + */ + public void setGssCredential(GSSCredential gssCredential) { + this.gssCredential = gssCredential; + } + + public MyProxyCredentials getMyProxyCredentials() { + return myProxyCredentials; + } + + public void setMyProxyCredentials(MyProxyCredentials myProxyCredentials) { + this.myProxyCredentials = myProxyCredentials; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPStorageClient.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPStorageClient.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPStorageClient.java index 559bdde..69f1206 100644 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPStorageClient.java +++ b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPStorageClient.java @@ -403,23 +403,4 @@ public class SCPStorageClient implements RemoteStorageClient { } return b; } - - public static void main(String[] args) throws Exception { - File privateKey = new File("/Users/supun/.ssh/id_rsa"); - byte[] privateKeyBytes = IOUtils.toByteArray(new FileInputStream(privateKey)); - - File publicKey = new File("/Users/supun/.ssh/id_rsa.pub"); - byte[] publicKeyBytes = IOUtils.toByteArray(new FileInputStream(publicKey)); - - String passPhrase = ""; - byte[] passPhraseBytes = passPhrase.getBytes(); - - SCPStorageClient scpStorageClient = new SCPStorageClient("gw75.iu.xsede.org", 22, "pga", privateKeyBytes, - publicKeyBytes, passPhraseBytes); - File file = scpStorageClient.readFile("/var/www/portals/gateway-user-data/testdrive/test.txt"); - System.out.println("File exists ? " + file.exists()); - scpStorageClient.writeFile(file, "/var/www/portals/gateway-user-data/testdrive/test2.txt"); - file.delete(); - System.out.println("File exists ? " + file.exists()); - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/9fd6be25/modules/file-manager/file-manager-core/src/main/resources/gridftp-client.properties ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/resources/gridftp-client.properties b/modules/file-manager/file-manager-core/src/main/resources/gridftp-client.properties new file mode 100644 index 0000000..7d8a757 --- /dev/null +++ b/modules/file-manager/file-manager-core/src/main/resources/gridftp-client.properties @@ -0,0 +1,30 @@ +trustedCertsFile=/Users/supun/Work/airavata-sandbox/grid-tools/certificates/ +myproxyServer=myproxy.teragrid.org +myproxy_lifetime=17280000 +myproxyUserName= +myproxyPasswd= +myproxyPort=7512 + + +testing.host=trestles +#testing.host=stampede +#testing.host=lonestar + +## TACC Lonestar +lonestar.gridftp.endpoint=gsiftp://gridftp1.ls4.tacc.utexas.edu:2811/ + +## TACC Stampede +stampede.gridftp.endpoint=gsiftp://gridftp.stampede.tacc.utexas.edu:2811/ + +## SDSC Trestles +trestles.gridftp.endpoint=gsiftp://trestles.sdsc.edu:2811/ + +gridftpserverSource=gsiftp://trestles-dm.sdsc.xsede.org:2811/ +gridftpSourcePath=/oasis/projects/nsf/sds128/ogce/file-transfer-tests/source/sample_wrfout.netcdf +gridftpUploadingFilePath = /oasis/projects/nsf/sds128/ogce/file-transfer-tests/source/dummy1 + +#gridftpserverDest=gsiftp://trestles-dm.sdsc.xsede.org:2811/ +#gridftpDestPath=/oasis/projects/nsf/sds128/ogce/file-transfer-tests/gf + +gridftpserverDest=gsiftp://gridftp.stampede.tacc.utexas.edu:2811/ +gridftpDestPath=/scratch/01437/ogce/file-transfer-tests/dest/xx \ No newline at end of file
