Package org.apache.airavata.core.gfac.external

Examples of org.apache.airavata.core.gfac.external.GridFtp


    public void makeDirectory(InvocationContext invocationContext) throws ProviderException {
        GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
        ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();

        GridFtp ftp = new GridFtp();

        try {
            gssContext = (GSISecurityContext)invocationContext.getSecurityContext(MYPROXY_SECURITY_CONTEXT);
            GSSCredential gssCred = gssContext.getGssCredentails();
            String[] hostgridFTP = host.getGridFTPEndPointArray();
            if (hostgridFTP == null || hostgridFTP.length == 0) {
                hostgridFTP = new String[] { host.getHostAddress() };
            }

            boolean success = false;
            ProviderException pe = null;// = new ProviderException("");

            for (String endpoint : host.getGridFTPEndPointArray()) {
                try {

                    URI tmpdirURI = GfacUtils.createGsiftpURI(endpoint, app.getScratchWorkingDirectory());
                    URI workingDirURI = GfacUtils.createGsiftpURI(endpoint, app.getStaticWorkingDirectory());
                    URI inputURI = GfacUtils.createGsiftpURI(endpoint, app.getInputDataDirectory());
                    URI outputURI = GfacUtils.createGsiftpURI(endpoint, app.getOutputDataDirectory());

                    log.debug("Host FTP = " + hostgridFTP);
                    log.debug("temp directory = " + tmpdirURI);
                    log.debug("Working directory = " + workingDirURI);
                    log.debug("Input directory = " + inputURI);
                    log.debug("Output directory = " + outputURI);

                    ftp.makeDir(tmpdirURI, gssCred);
                    ftp.makeDir(workingDirURI, gssCred);
                    ftp.makeDir(inputURI, gssCred);
                    ftp.makeDir(outputURI, gssCred);

                    success = true;
                    break;
                } catch (URISyntaxException e) {
                    pe = new ProviderException("URI is malformatted:" + e.getMessage(), e,invocationContext);
View Full Code Here


  }

    public Map<String, ?> processOutput(InvocationContext invocationContext) throws ProviderException {
        GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
        ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();
        GridFtp ftp = new GridFtp();
        File localStdErrFile = null;
        try {
            GSSCredential gssCred = gssContext.getGssCredentails();

            String[] hostgridFTP = host.getGridFTPEndPointArray();
            if (hostgridFTP == null || hostgridFTP.length == 0) {
                hostgridFTP = new String[] { host.getHostAddress() };
            }
            ProviderException pe = null;
            for (String endpoint : host.getGridFTPEndPointArray()) {
                try {
                    /*
                     *  Read Stdout and Stderror
                     */
                    URI stdoutURI = GfacUtils.createGsiftpURI(endpoint, app.getStandardOutput());
                    URI stderrURI = GfacUtils.createGsiftpURI(endpoint, app.getStandardError());

                    log.info("STDOUT:" + stdoutURI.toString());
                    log.info("STDERR:" + stderrURI.toString());

                    File logDir = new File("./service_logs");
                    if (!logDir.exists()) {
                        logDir.mkdir();
                    }

                    String timeStampedServiceName = GfacUtils.createUniqueNameForService(invocationContext
                            .getServiceName());
                    File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout");
                    localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr");

                    String stdout = ftp.readRemoteFile(stdoutURI, gssCred, localStdOutFile);
                    String stderr = ftp.readRemoteFile(stderrURI, gssCred, localStdErrFile);
                    Map<String,ActualParameter> stringMap = null;
                    MessageContext<Object> output = invocationContext.getOutput();
                    for (Iterator<String> iterator = output.getNames(); iterator.hasNext(); ) {
                        String paramName = iterator.next();
                        ActualParameter actualParameter = (ActualParameter) output.getValue(paramName);
            if ("URIArray".equals(actualParameter.getType().getType().toString())) {
              URI outputURI = GfacUtils.createGsiftpURI(endpoint,app.getOutputDataDirectory());
              List<String> outputList = ftp.listDir(outputURI,gssCred);
              String[] valueList = outputList.toArray(new String[outputList.size()]);
              ((URIArrayType) actualParameter.getType()).setValueArray(valueList);
              stringMap = new HashMap<String, ActualParameter>();
              stringMap.put(paramName, actualParameter);
              invocationContext.getExecutionContext().getNotifier().output(invocationContext, actualParameter.toString());
View Full Code Here

    private String stageInputFiles(InvocationContext invocationContext, String paramValue, ActualParameter actualParameter) throws URISyntaxException, SecurityException, ToolsException, IOException {
        URI gridftpURL;
        gridftpURL = new URI(paramValue);
        GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
        ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();
        GridFtp ftp = new GridFtp();
        URI destURI = null;
        gssContext = (GSISecurityContext) invocationContext.getSecurityContext(MYPROXY_SECURITY_CONTEXT);
        GSSCredential gssCred = gssContext.getGssCredentails();
        for (String endpoint : host.getGridFTPEndPointArray()) {
            URI inputURI = GfacUtils.createGsiftpURI(endpoint, app.getInputDataDirectory());
            String fileName = new File(gridftpURL.getPath()).getName();
            String s = inputURI.getPath() + File.separator + fileName;
            //if user give a url just to refer an endpoint, not a web resource we are not doing any transfer
            if (fileName != null && !"".equals(fileName)) {
                destURI = GfacUtils.createGsiftpURI(endpoint, s);
                if (paramValue.startsWith("gsiftp")) {
                    ftp.uploadFile(gridftpURL, destURI, gssCred);
                } else if (paramValue.startsWith("file")) {
                    String localFile = paramValue.substring(paramValue.indexOf(":")+1, paramValue.length());
                    ftp.uploadFile(destURI, gssCred, new FileInputStream(localFile));
                }else if (paramValue.startsWith("http")) {
                    ftp.uploadFile(destURI,
                            gssCred, (gridftpURL.toURL().openStream()));
                }else {
                    //todo throw exception telling unsupported protocol
                    return paramValue;
                }
View Full Code Here

            String paramValue = input.getStringValue(paramName);
            ActualParameter actualParameter = (ActualParameter) input
                    .getValue(paramName);
            //TODO: Review this with type
            GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
            GridFtp ftp = new GridFtp();
            gssContext = (GSISecurityContext) invocationContext.getSecurityContext(MYPROXY_SECURITY_CONTEXT);
            GSSCredential gssCred = null;
            try {
                gssCred = gssContext.getGssCredentails();
            } catch (SecurityException e) {
View Full Code Here

    public void makeDirectory(InvocationContext invocationContext) throws ProviderException {
        GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
        ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();

        GridFtp ftp = new GridFtp();

        try {
            gssContext = (GSISecurityContext)invocationContext.getSecurityContext(MYPROXY_SECURITY_CONTEXT);
            GSSCredential gssCred = gssContext.getGssCredentails();
            String[] hostgridFTP = host.getGridFTPEndPointArray();
            if (hostgridFTP == null || hostgridFTP.length == 0) {
                hostgridFTP = new String[] { host.getHostAddress() };
            }

            boolean success = false;
            ProviderException pe = null;// = new ProviderException("");

            for (String endpoint : host.getGridFTPEndPointArray()) {
                try {

                    URI tmpdirURI = GfacUtils.createGsiftpURI(endpoint, app.getScratchWorkingDirectory());
                    URI workingDirURI = GfacUtils.createGsiftpURI(endpoint, app.getStaticWorkingDirectory());
                    URI inputURI = GfacUtils.createGsiftpURI(endpoint, app.getInputDataDirectory());
                    URI outputURI = GfacUtils.createGsiftpURI(endpoint, app.getOutputDataDirectory());

                    log.debug("Host FTP = " + hostgridFTP);
                    log.debug("temp directory = " + tmpdirURI);
                    log.debug("Working directory = " + workingDirURI);
                    log.debug("Input directory = " + inputURI);
                    log.debug("Output directory = " + outputURI);

                    ftp.makeDir(tmpdirURI, gssCred);
                    ftp.makeDir(workingDirURI, gssCred);
                    ftp.makeDir(inputURI, gssCred);
                    ftp.makeDir(outputURI, gssCred);

                    success = true;
                    break;
                } catch (URISyntaxException e) {
                    pe = new ProviderException("URI is malformatted:" + e.getMessage(), e,invocationContext);
View Full Code Here

        return false;
    }

    private void gridFTPTransfer(InvocationContext context, URI dest, String remoteSrcFile) throws SecurityException,
            ToolsException, URISyntaxException {
        GridFtp ftp = new GridFtp();
        GSSCredential gssCred = ((GSISecurityContext) context.getSecurityContext(MYPROXY_SECURITY_CONTEXT))
                .getGssCredentails();
        GlobusHostType host = (GlobusHostType) context.getExecutionDescription().getHost().getType();

        for (String endpoint : host.getGridFTPEndPointArray()) {
            try {
                URI srcURI = GfacUtils.createGsiftpURI(endpoint, remoteSrcFile);
                ftp.transfer(srcURI, dest, gssCred, true);
                return;
            } catch (ToolsException e) {
                log.error(e.getMessage(), e);
            }
        }
View Full Code Here

    }

    private void uploadFile(InvocationContext context, URI dest, String localFile) throws SecurityException,
            ToolsException {
        GridFtp ftp = new GridFtp();
        GSSCredential gssCred = ((GSISecurityContext) context.getSecurityContext(MYPROXY_SECURITY_CONTEXT))
                .getGssCredentails();
        ftp.uploadFile(dest, gssCred, new File(localFile));
    }
View Full Code Here

        return false;
    }

    private void uploadToGridFTPFromHttp(InvocationContext context, URI src, String remoteLocation)
            throws SecurityException, ToolsException, URISyntaxException, IOException {
        GridFtp ftp = new GridFtp();
        GSSCredential gssCred = ((GSISecurityContext) context.getSecurityContext(MYPROXY_SECURITY_CONTEXT))
                .getGssCredentails();

        GlobusHostType host = (GlobusHostType) context.getExecutionDescription().getHost().getType();

        for (String endpoint : host.getGridFTPEndPointArray()) {
            try {
                URI destURI = GfacUtils.createGsiftpURI(endpoint, remoteLocation);
                InputStream in = null;
                try {
                    in = src.toURL().openStream();
                    ftp.uploadFile(destURI, gssCred, in);
                } finally {
                    try {
                        if (in != null) {
                            in.close();
                        }
View Full Code Here

        return false;
    }

    private void gridFTPTransfer(InvocationContext context, URI src, String remoteFile) throws SecurityException,
            ToolsException, URISyntaxException {
        GridFtp ftp = new GridFtp();
        GSSCredential gssCred = ((GSISecurityContext) context.getSecurityContext(MYPROXY_SECURITY_CONTEXT))
                .getGssCredentails();
        GlobusHostType host = (GlobusHostType) context.getExecutionDescription().getHost().getType();
       
        for (String endpoint : host.getGridFTPEndPointArray()) {
            try {
                URI inputURI = GfacUtils.createGsiftpURI(endpoint, remoteFile);
                ftp.transfer(src, inputURI, gssCred, true);
                return;
            } catch (ToolsException e) {
                log.error(e.getMessage(), e);
            }
        }       
View Full Code Here

        }       
    }

    private void downloadFile(InvocationContext context, URI src, String localFile) throws SecurityException,
            ToolsException {
        GridFtp ftp = new GridFtp();
        GSSCredential gssCred = ((GSISecurityContext) context.getSecurityContext(MYPROXY_SECURITY_CONTEXT))
                .getGssCredentails();
        ftp.downloadFile(src, gssCred, new File(localFile));
    }
View Full Code Here

TOP

Related Classes of org.apache.airavata.core.gfac.external.GridFtp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.