Package org.apache.airavata.schemas.gfac

Examples of org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType


                command = "sh" + " " + type.getExecutable();
            }
            command = setCmdParams(jobExecutionContext, command);

        } else {
            ApplicationDeploymentDescriptionType type = appDesc.getType();
            command = "sh" + " " + type.getExecutableLocation();
            command = setCmdParams(jobExecutionContext, command);
        }

        return command + '\n';
    }
View Full Code Here


  }

    private static String stageInputFiles(JobExecutionContext context, String paramValue) throws IOException, GFacException {
        SSHSecurityContext securityContext = (SSHSecurityContext)context.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);
        Cluster pbsCluster = securityContext.getPbsCluster();
        ApplicationDeploymentDescriptionType app = context.getApplicationContext().getApplicationDeploymentDescription().getType();
        int i = paramValue.lastIndexOf(File.separator);
        String substring = paramValue.substring(i + 1);
        try {
            String targetFile = app.getInputDataDirectory()+ File.separator + substring;
            pbsCluster.scpTo(targetFile, paramValue);
            return targetFile;
        } catch (SSHApiException e) {
            throw new GFacHandlerException("Error while input File Staging", e, e.getLocalizedMessage());
        }
View Full Code Here

    private static final Logger log = LoggerFactory.getLogger(GridFTPOutputHandler.class);

    public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
        log.info("Invoking GridFTPOutputHandler ...");

       ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();

      HostDescriptionType hostType = jobExecutionContext.getApplicationContext().getHostDescription().getType();
      String[] gridFTPEndpointArray = null;
      String hostName = null;
       if(jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof GlobusHostType){
          gridFTPEndpointArray = ((GlobusHostType) hostType).getGridFTPEndPointArray();
          hostName = ((GlobusHostType) hostType).getHostName();
       }
       else if (jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof UnicoreHostType){
          gridFTPEndpointArray = ((UnicoreHostType) hostType).getGridFTPEndPointArray();
          hostName = ((UnicoreHostType) hostType).getHostName();
       }
       else {
          //TODO
       }

       GridFtp ftp = new GridFtp();
       File localStdErrFile = null;
       Map<String, ActualParameter> stringMap = new HashMap<String, ActualParameter>();
       try {
          GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentials();
          String[] hostgridFTP = gridFTPEndpointArray;
            if (hostgridFTP == null || hostgridFTP.length == 0) {
                hostgridFTP = new String[]{hostName};
            }
            for (String endpoint : gridFTPEndpointArray) {
                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(jobExecutionContext
                            .getServiceName());
                    File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout");
                    localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr");


                    String stdout = null;
                    String stderr = null;

                    // TODO: what if job is failed
                    // and this handler is not able to find std* files?
                    try {
                     stdout = ftp.readRemoteFile(stdoutURI, gssCred, localStdOutFile);
                     stderr = ftp.readRemoteFile(stderrURI, gssCred, localStdErrFile);
                     //TODO: do we also need to set them as output parameters for another job
                     ApplicationDescription application = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription();
                     ApplicationDeploymentDescriptionType appDesc = application.getType();
                     appDesc.setStandardOutput(stdout);
                     appDesc.setStandardError(stderr);
                     jobExecutionContext.getApplicationContext().setApplicationDeploymentDescription(application);
                    }
                    catch(ToolsException e) {
                        log.error("Cannot download stdout/err files. One reason could be the job is not successfully finished:  "+e.getMessage());
                    }
View Full Code Here

        return serv;
    }

    private ApplicationDeploymentDescription createAppDeploymentDescription() {
        ApplicationDeploymentDescription appDesc = new ApplicationDeploymentDescription();
        ApplicationDeploymentDescriptionType app = appDesc.getType();
        ApplicationDeploymentDescriptionType.ApplicationName name = ApplicationDeploymentDescriptionType.ApplicationName.Factory
                .newInstance();
        name.setStringValue("EchoLocal");
        app.setApplicationName(name);
        app.setExecutableLocation("/bin/echo");
        app.setScratchWorkingDirectory("/tmp");
        app.setStaticWorkingDirectory("/tmp");
        app.setInputDataDirectory("/tmp/input");
        app.setOutputDataDirectory("/tmp/output");
        app.setStandardOutput("/tmp/echo.stdout");
        app.setStandardError("/tmp/echo.stdout");
        return appDesc;
    }
View Full Code Here

    /*
     * App
     */
    ApplicationDeploymentDescription appDesc = new ApplicationDeploymentDescription();
    ApplicationDeploymentDescriptionType app = appDesc.getType();
    ApplicationDeploymentDescriptionType.ApplicationName name = ApplicationDeploymentDescriptionType.ApplicationName.Factory.newInstance();
    name.setStringValue("EchoLocal");
    app.setApplicationName(name);
    app.setExecutableLocation("/bin/echo");
    app.setScratchWorkingDirectory("/tmp");
    app.setStaticWorkingDirectory("/tmp");
    app.setInputDataDirectory("/tmp/input");
    app.setOutputDataDirectory("/tmp/output");
    app.setStandardOutput("/tmp/echo.stdout");
    app.setStandardError("/tmp/echo.stdout");



    /*
     * Service
 
View Full Code Here

            throw new ProviderException("Cannot make directory "+dir, invocationContext);
        }
    }

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

        log.info("working diectroy = " + app.getStaticWorkingDirectory());
        log.info("temp directory = " + app.getScratchWorkingDirectory());

        makeFileSystemDir(app.getStaticWorkingDirectory(),invocationContext);
        makeFileSystemDir(app.getScratchWorkingDirectory(),invocationContext);
        makeFileSystemDir(app.getInputDataDirectory(),invocationContext);
        makeFileSystemDir(app.getOutputDataDirectory(),invocationContext);
    }
View Full Code Here

    public boolean execute(InvocationContext context) throws ExtensionException {

        ServiceDescription serviceDesc = context.getExecutionDescription().getService();
        HostDescription hostDesc = context.getExecutionDescription().getHost();
        ApplicationDeploymentDescriptionType appDesc = context.getExecutionDescription().getApp().getType();
        if (serviceDesc != null && hostDesc != null && appDesc != null) {
            /*
             * if there is no setting in deployment description, use from host
             */
            if (appDesc.getScratchWorkingDirectory() == null) {
                appDesc.setScratchWorkingDirectory("/tmp");
            }

            /*
             * Working dir
             */
            if (appDesc.getStaticWorkingDirectory() == null || "null".equals(appDesc.getStaticWorkingDirectory())) {
                String date = new Date().toString();
                date = date.replaceAll(" ", "_");
                date = date.replaceAll(":", "_");

                String tmpDir = appDesc.getScratchWorkingDirectory() + File.separator
                        + appDesc.getApplicationName().getStringValue() + "_" + date + "_" + UUID.randomUUID();

                appDesc.setStaticWorkingDirectory(tmpDir);
            }

            /*
             * Input and Output Directory
             */
            if (appDesc.getInputDataDirectory() == null || "".equals(appDesc.getInputDataDirectory()) ) {
                appDesc.setInputDataDirectory(appDesc.getStaticWorkingDirectory() + File.separator + "inputData");
            }
            if (appDesc.getOutputDataDirectory() == null || "".equals(appDesc.getOutputDataDirectory())) {
                appDesc.setOutputDataDirectory(appDesc.getStaticWorkingDirectory() + File.separator + "outputData");
            }

            /*
             * Stdout and Stderr for Shell
             */
            if (appDesc.getStandardOutput() == null || "".equals(appDesc.getStandardOutput())) {
                appDesc.setStandardOutput(appDesc.getStaticWorkingDirectory() + File.separator
                        + appDesc.getApplicationName().getStringValue() + ".stdout");
            }
            if (appDesc.getStandardError() == null || "".equals(appDesc.getStandardError())) {
                appDesc.setStandardError(appDesc.getStaticWorkingDirectory() + File.separator
                        + appDesc.getApplicationName().getStringValue() + ".stderr");
            }

        } else {
            throw new ExtensionException("Service Map for " + context.getServiceName()
                    + " does not found on resource Catalog " + context.getExecutionContext().getRegistryService());
View Full Code Here

        makeFileSystemDir(app.getInputDataDirectory(),invocationContext);
        makeFileSystemDir(app.getOutputDataDirectory(),invocationContext);
    }

    public void setupEnvironment(InvocationContext context) throws ProviderException {
        ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType();

        // input parameter
        ArrayList<String> tmp = new ArrayList<String>();
        for (Iterator<String> iterator = context.getInput().getNames(); iterator.hasNext(); ) {
            String key = iterator.next();
            tmp.add(context.getInput().getStringValue(key));
        }

        cmdList = new ArrayList<String>();

        /*
         * Builder Command
         */
        cmdList.add(app.getExecutableLocation());
        cmdList.addAll(tmp);

        // create process builder from command
        this.builder = new ProcessBuilder(cmdList);

        // get the env of the host and the application
        NameValuePairType[] env = app.getApplicationEnvironmentArray();

        if (env != null) {
            Map<String, String> nv = new HashMap<String, String>();
            for (int i = 0; i < env.length; i++) {
                String key = env[i].getName();
                String value = env[i].getValue();
                nv.put(key, value);
            }

            if ((app.getApplicationEnvironmentArray() != null) && (app.getApplicationEnvironmentArray().length != 0)
                    && nv.size() > 0) {
                builder.environment().putAll(nv);
            }
        }

        // extra env's
        builder.environment().put(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
        builder.environment().put(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());

        // working directory
        builder.directory(new File(app.getStaticWorkingDirectory()));

        // log info
        log.info("Command = " + InputUtils.buildCommand(cmdList));
        log.info("Working dir = " + builder.directory());
        for (String key : builder.environment().keySet()) {
View Full Code Here

            log.info("Env[" + key + "] = " + builder.environment().get(key));
        }
    }

    public void executeApplication(InvocationContext context) throws ProviderException {
        ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType();

        try {
            // running cmd
            Process process = builder.start();

            Thread t1 = new InputStreamToFileWriter(process.getInputStream(), app.getStandardOutput());
            Thread t2 = new InputStreamToFileWriter(process.getErrorStream(), app.getStandardError());

            // start output threads
            t1.setDaemon(true);
            t2.setDaemon(true);
            t1.start();
            t2.start();

            // wait for the process (application) to finish executing
            int returnValue = process.waitFor();

            // make sure other two threads are done
            t1.join();
            t2.join();

            /*
             * check return value. usually not very helpful to draw conclusions based on return values so don't bother.
             * just provide warning in the log messages
             */
            if (returnValue != 0) {
                log.error("Process finished with non zero return value. Process may have failed");
            } else {
                log.info("Process finished with return value of zero.");
            }

            StringBuffer buf = new StringBuffer();
            buf.append("Executed ").append(InputUtils.buildCommand(cmdList))
                    .append(" on the localHost, working directory = ").append(app.getStaticWorkingDirectory())
                    .append(" tempDirectory = ").append(app.getScratchWorkingDirectory()).append(" With the status ")
                    .append(String.valueOf(returnValue));

            log.info(buf.toString());

        } catch (IOException io) {
View Full Code Here

        }
    }

    public Map<String, ?> processOutput(InvocationContext context) throws ProviderException {

        ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType();

        try {
            String stdOutStr = GfacUtils.readFileToString(app.getStandardOutput());
            String stdErrStr = GfacUtils.readFileToString(app.getStandardError());

            // set to context
            return OutputUtils.fillOutputFromStdout(context.<ActualParameter>getOutput(), stdOutStr, stdErrStr);
        } catch (XmlException e) {
            throw new ProviderException("Cannot read output:" + e.getMessage(), e, context);
View Full Code Here

TOP

Related Classes of org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType

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.