http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/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 deleted file mode 100644 index 6bfb40e..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/FileTransferRequestDao.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * 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.db.dao; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.mongodb.*; -import com.mongodb.util.JSON; -import org.apache.airavata.file.manager.core.db.conversion.ModelConversionHelper; -import org.apache.airavata.file.manager.core.db.utils.MongoUtils; -import org.apache.airavata.model.file.transfer.FileTransferRequestModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.UUID; - -public class FileTransferRequestDao { - private final static Logger logger = LoggerFactory.getLogger(FileTransferRequestDao.class); - - private static final String FILE_TRANSFER_REQUESTS_COLLECTION_NAME = "file-transfer-requests"; - private DBCollection collection; - private ModelConversionHelper modelConversionHelper; - - private static final String TRANSFER_ID = "transfer_id"; - - public FileTransferRequestDao() throws IOException { - collection = MongoUtils.getFileManagerRegistry().getCollection(FILE_TRANSFER_REQUESTS_COLLECTION_NAME); - modelConversionHelper = new ModelConversionHelper(); - collection.dropIndexes(); - initIndexes(); - } - - /** - * If indexes are already defined this will simply ignore them - */ - private void initIndexes() { - collection.createIndex(new BasicDBObject(TRANSFER_ID, 1), new BasicDBObject("unique", true)); - } - - public String createFileTransferRequest(FileTransferRequestModel fileTransferRequestModel) throws JsonProcessingException { - fileTransferRequestModel.setTransferId(UUID.randomUUID().toString()); - WriteResult result = collection.insert((DBObject) JSON.parse( - modelConversionHelper.serializeObject(fileTransferRequestModel))); - logger.debug("No of inserted results " + result.getN()); - return fileTransferRequestModel.getTransferId(); - } - - public void updateFileTransferRequest(FileTransferRequestModel fileTransferRequestModel) throws JsonProcessingException { - DBObject query = BasicDBObjectBuilder.start().add( - TRANSFER_ID, fileTransferRequestModel.getTransferId()).get(); - WriteResult result = collection.update(query, (DBObject) JSON.parse( - modelConversionHelper.serializeObject(fileTransferRequestModel))); - logger.debug("No of updated results " + result.getN()); - } - - public void deleteFileTransferRequest(String trasnferId){ - DBObject query = BasicDBObjectBuilder.start().add( - TRANSFER_ID, trasnferId).get(); - WriteResult result = collection.remove(query); - logger.debug("No of removed file transfer requests " + result.getN()); - } - - public FileTransferRequestModel getFileTransferRequest(String transferId) throws IOException { - - DBObject criteria = new BasicDBObject(TRANSFER_ID, transferId); - DBObject doc = collection.findOne(criteria); - if (doc != null) { - String json = doc.toString(); - return (FileTransferRequestModel) modelConversionHelper.deserializeObject( - FileTransferRequestModel.class, json); - } - return null; - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/MetadataDao.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/MetadataDao.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/MetadataDao.java deleted file mode 100644 index 9f9d494..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/dao/MetadataDao.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * 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.db.dao; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.mongodb.*; -import com.mongodb.util.JSON; -import org.apache.airavata.file.manager.core.db.conversion.ModelConversionHelper; -import org.apache.airavata.file.manager.core.db.utils.MongoUtils; -import org.apache.airavata.file.manager.cpi.FileManagerConstants; -import org.apache.airavata.model.file.metadata.MetadataModel; -import org.apache.airavata.model.file.replica.FileModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.UUID; - -public class MetadataDao { - private final static Logger logger = LoggerFactory.getLogger(MetadataDao.class); - - private static final String METADATA_COLLECTION_NAME = "metadata-models"; - private DBCollection collection; - private ModelConversionHelper modelConversionHelper; - - private static final String METADATA_ID = "metadata_id"; - - public MetadataDao() throws IOException { - collection = MongoUtils.getFileManagerRegistry().getCollection(METADATA_COLLECTION_NAME); - modelConversionHelper = new ModelConversionHelper(); - collection.dropIndexes(); - initIndexes(); - } - - /** - * If indexes are already defined this will simply ignore them - */ - private void initIndexes() { - collection.createIndex(new BasicDBObject(METADATA_ID, 1), new BasicDBObject("unique", true)); - } - - public String createMetadata(MetadataModel metadataModel) throws JsonProcessingException { - metadataModel.setMetadataId(FileManagerConstants.AIRAVATA_METADATA_ID_PREFIX + UUID.randomUUID().toString()); - WriteResult result = collection.insert((DBObject) JSON.parse( - modelConversionHelper.serializeObject(metadataModel))); - logger.debug("No of inserted results " + result.getN()); - return metadataModel.getMetadataId(); - } - - public void updateMetadata(MetadataModel metadataModel) throws JsonProcessingException { - DBObject query = BasicDBObjectBuilder.start().add( - METADATA_ID, metadataModel.getMetadataId()).get(); - WriteResult result = collection.update(query, (DBObject) JSON.parse( - modelConversionHelper.serializeObject(metadataModel))); - logger.debug("No of updated results " + result.getN()); - } - - public void deleteMetadata(String metadataId){ - DBObject query = BasicDBObjectBuilder.start().add( - METADATA_ID,metadataId).get(); - WriteResult result = collection.remove(query); - logger.debug("No of removed metadata model requests " + result.getN()); - } - - public MetadataModel getMetadata(String metadataId) throws IOException { - - DBObject criteria = new BasicDBObject(METADATA_ID, metadataId); - DBObject doc = collection.findOne(criteria); - if (doc != null) { - String json = doc.toString(); - return (MetadataModel) modelConversionHelper.deserializeObject( - MetadataModel.class, json); - } - return null; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/utils/MongoUtils.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/utils/MongoUtils.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/utils/MongoUtils.java deleted file mode 100644 index 5148dd3..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/db/utils/MongoUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * 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.db.utils; - -import org.apache.airavata.file.manager.core.utils.FileManagerConstants; -import org.apache.airavata.file.manager.core.utils.FileManagerProperties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.mongodb.DB; -import com.mongodb.MongoClient; - -import java.io.IOException; - -public class MongoUtils { - private final static Logger logger = LoggerFactory.getLogger(MongoUtils.class); - - private static int port; - private static String host; - private static MongoClient mongoClient = null; - private static DB fileManagerRegistry; - private static String FILE_MANAGER_REGISTRY_NAME; - - public static MongoClient getMongoClient() throws IOException { - if (mongoClient == null) { - FileManagerProperties fileManagerProperties = FileManagerProperties.getInstance(); - host = fileManagerProperties.getProperty(FileManagerConstants.MONGODB_HOST, "localhost"); - port = Integer.parseInt(fileManagerProperties.getProperty(FileManagerConstants.MONGODB_PORT, "27017")); - FILE_MANAGER_REGISTRY_NAME = fileManagerProperties.getProperty(FileManagerConstants.MONGODB_DB_NAME, - "file-manager-db"); - mongoClient = new MongoClient(host, port); - logger.debug("New Mongo Client created with [" + host + "] and [" - + port + "]"); - - } - return mongoClient; - } - - public static DB getFileManagerRegistry() throws IOException { - if (fileManagerRegistry == null) { - fileManagerRegistry = getMongoClient().getDB(FILE_MANAGER_REGISTRY_NAME); - } - return fileManagerRegistry; - } - - public static void dropFileManagerRegistry() throws IOException { - getMongoClient().dropDatabase(FILE_MANAGER_REGISTRY_NAME); - logger.debug("Dropped File Manager Registry"); - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/RemoteStorageClient.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/RemoteStorageClient.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/RemoteStorageClient.java deleted file mode 100644 index a9e743c..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/RemoteStorageClient.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * - * 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; - -import org.apache.airavata.model.file.transfer.LSEntryModel; - -import java.io.File; -import java.util.List; - -public interface RemoteStorageClient { - - /** - * Reads a remote file, write it to local temporary directory and returns a file pointer to it - * @param filePath - * @return - * @throws Exception - */ - File readFile(String filePath) throws Exception; - - /** - * Writes the source file in the local storage to specified path in the remote storage - * @param sourceFile - * @return - * @throws Exception - */ - void writeFile(File sourceFile, String filePath) throws Exception; - - /** - * Returns a directory listing of the specified directory - * @param directoryPath - * @return - * @throws Exception - */ - List<LSEntryModel> getDirectoryListing(String directoryPath) throws Exception; - - /** - * Move the specified file from source to destination within the same storage resource - * @param currentPath - * @param newPath - * @throws Exception - */ - void moveFile(String currentPath, String newPath) throws Exception; - - /** - * - * @param sourcePath - * @param destinationPath - * @throws Exception - */ - void copyFile(String sourcePath, String destinationPath) throws Exception; - - /** - * Rename file with the given name - * @param filePath - * @param newFileName - * @throws Exception - */ - void renameFile(String filePath, String newFileName) throws Exception; - - /** - * Delete the specified file - * @param filePath - * @throws Exception - */ - void deleteFile(String filePath) throws Exception; - - /** - * Create new directory in the specified file - * @param newDirPath - * @throws Exception - */ - void mkdir(String newDirPath) throws Exception; - - /** - * Checks whether specified file exists in the remote storage system - * @param filePath - * @return - * @throws Exception - */ - boolean checkFileExists(String filePath) throws Exception; - - /** - * Checks whether the given path is a directory - * @param filePath - * @return - * @throws Exception - */ - boolean checkIsDirectory(String filePath) throws Exception; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/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 deleted file mode 100644 index 37da5f9..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/ExecutionContext.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * - * 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/1ad9ae5d/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 deleted file mode 100644 index 89bfba3..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTP.java +++ /dev/null @@ -1,430 +0,0 @@ -/* - * - * 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/1ad9ae5d/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 deleted file mode 100644 index 5e00df0..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * 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/1ad9ae5d/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 deleted file mode 100644 index 060f015..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/GridFTPContactInfo.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * 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/1ad9ae5d/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 deleted file mode 100644 index 00d9343..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/CertificateManager.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * 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/1ad9ae5d/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 deleted file mode 100644 index 23dfd5e..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/MyProxyCredentials.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * - * 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/1ad9ae5d/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 deleted file mode 100644 index eb1a541..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/gridftp/myproxy/SecurityContext.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * - * 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/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/http/HTTPStorageClient.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/http/HTTPStorageClient.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/http/HTTPStorageClient.java deleted file mode 100644 index e829c3b..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/http/HTTPStorageClient.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * - * 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.http; - -import org.apache.airavata.file.manager.core.remote.client.RemoteStorageClient; -import org.apache.airavata.model.file.transfer.LSEntryModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import java.io.File; -import java.io.FileOutputStream; -import java.net.URL; -import java.net.URLConnection; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.util.List; -import java.util.UUID; - -public class HTTPStorageClient implements RemoteStorageClient { - private final static Logger logger = LoggerFactory.getLogger(HTTPStorageClient.class); - - public static enum Protocol { - HTTP, HTTPS - } - - private String host; - private int port; - private Protocol protocol; - - public HTTPStorageClient(Protocol protocol, String host, int port) throws KeyManagementException, NoSuchAlgorithmException { - this.protocol = protocol; - this.host = host; - this.port = port; - - // Create a new trust manager that trust all certificates - TrustManager[] trustAllCerts = new TrustManager[]{ - new X509TrustManager() { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted( - java.security.cert.X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted( - java.security.cert.X509Certificate[] certs, String authType) { - } - } - }; - - // Activate the new trust manager - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, new java.security.SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - } - - /** - * Reads a remote file, write it to local temporary directory and returns a file pointer to it - * - * @param filePath - * @return - * @throws Exception - */ - @Override - public File readFile(String filePath) throws Exception { - String url = ""; - if (protocol == Protocol.HTTP) - url += "http://"; - else - url += "https://"; - url += host + ":" + port; - if (!filePath.startsWith("/")) - filePath += "/" + filePath; - url += filePath; - - URL fileUrl = new URL(url); - URLConnection urlConnection = fileUrl.openConnection(); - ReadableByteChannel rbc = Channels.newChannel(urlConnection.getInputStream()); - String localFilePath = System.getProperty("java.io.tmpdir") + File.separator + UUID.randomUUID().toString(); - FileOutputStream fos = new FileOutputStream(localFilePath); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - - return new File(localFilePath); - } - - /** - * Writes the source file in the local storage to specified path in the remote storage - * - * @param sourceFile - * @param filePath - * @return - * @throws Exception - */ - @Override - public void writeFile(File sourceFile, String filePath) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Returns a directory listing of the specified directory - * - * @param directoryPath - * @return - * @throws Exception - */ - @Override - public List<LSEntryModel> getDirectoryListing(String directoryPath) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Move the specified file from source to destination within the same storage resource - * - * @param currentPath - * @param newPath - * @throws Exception - */ - @Override - public void moveFile(String currentPath, String newPath) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * @param sourcePath - * @param destinationPath - * @throws Exception - */ - @Override - public void copyFile(String sourcePath, String destinationPath) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Rename file with the given name - * - * @param filePath - * @param newFileName - * @throws Exception - */ - @Override - public void renameFile(String filePath, String newFileName) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Delete the specified file - * - * @param filePath - * @throws Exception - */ - @Override - public void deleteFile(String filePath) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Create new directory in the specified file - * - * @param newDirPath - * @throws Exception - */ - @Override - public void mkdir(String newDirPath) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Checks whether specified file exists in the remote storage system - * - * @param filePath - * @return - * @throws Exception - */ - @Override - public boolean checkFileExists(String filePath) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Checks whether the given path is a directory - * - * @param filePath - * @return - * @throws Exception - */ - @Override - public boolean checkIsDirectory(String filePath) throws Exception { - return false; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/CommandOutput.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/CommandOutput.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/CommandOutput.java deleted file mode 100644 index 5fd2b52..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/CommandOutput.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * 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.scp; - -import com.jcraft.jsch.Channel; -import java.io.OutputStream; - -public interface CommandOutput { - void onOutput(Channel var1); - - OutputStream getStandardError(); - - void exitCode(int var1); - - int getExitCode(); -} http://git-wip-us.apache.org/repos/asf/airavata/blob/1ad9ae5d/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPApiException.java ---------------------------------------------------------------------- diff --git a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPApiException.java b/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPApiException.java deleted file mode 100644 index 0f07707..0000000 --- a/modules/file-manager/file-manager-core/src/main/java/org/apache/airavata/file/manager/core/remote/client/scp/SCPApiException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * 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.scp; - -public class SCPApiException extends Exception { - - public SCPApiException(String message) { - super(message); - } - - public SCPApiException(String message, Exception e) { - super(message, e); - } - -}
