Package org.apache.airavata.schemas.gfac

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


  @Override
  public void dispose(JobExecutionContext jobExecutionContext) throws GFacProviderException {
  }

  private File createShellScript(JobExecutionContext context) throws IOException {
    ApplicationDeploymentDescriptionType app = context.getApplicationContext()
        .getApplicationDeploymentDescription().getType();
    String uniqueDir = app.getApplicationName().getStringValue() + System.currentTimeMillis()
        + new Random().nextLong();

    File shellScript = File.createTempFile(uniqueDir, "sh");
    OutputStream out = new FileOutputStream(shellScript);

    out.write("#!/bin/bash\n".getBytes());
    out.write(("cd " + app.getStaticWorkingDirectory() + "\n").getBytes());
    out.write(("export " + Constants.INPUT_DATA_DIR_VAR_NAME + "=" + app.getInputDataDirectory() + "\n").getBytes());
    out.write(("export " + Constants.OUTPUT_DATA_DIR_VAR_NAME + "=" + app.getOutputDataDirectory() + "\n")
        .getBytes());
    // get the env of the host and the application
    NameValuePairType[] env = app.getApplicationEnvironmentArray();

    Map<String, String> nv = new HashMap<String, String>();
    if (env != null) {
      for (int i = 0; i < env.length; i++) {
        String key = env[i].getName();
        String value = env[i].getValue();
        nv.put(key, value);
      }
    }
    for (Entry<String, String> entry : nv.entrySet()) {
      log.debug("Env[" + entry.getKey() + "] = " + entry.getValue());
      out.write(("export " + entry.getKey() + "=" + entry.getValue() + "\n").getBytes());

    }

    // prepare the command
    final String SPACE = " ";
    StringBuffer cmd = new StringBuffer();
    cmd.append(app.getExecutableLocation());
    cmd.append(SPACE);

    MessageContext input = context.getInMessageContext();
    ;
    Map<String, Object> inputs = input.getParameters();
    Set<String> keys = inputs.keySet();
    for (String paramName : keys) {
      ActualParameter actualParameter = (ActualParameter) inputs.get(paramName);
      if ("URIArray".equals(actualParameter.getType().getType().toString())) {
        String[] values = ((URIArrayType) actualParameter.getType()).getValueArray();
        for (String value : values) {
          cmd.append(value);
          cmd.append(SPACE);
        }
      } else {
        String paramValue = MappingFactory.toString(actualParameter);
        cmd.append(paramValue);
        cmd.append(SPACE);
      }
    }
    // We redirect the error and stdout to remote files, they will be read
    // in later
    cmd.append(SPACE);
    cmd.append("1>");
    cmd.append(SPACE);
    cmd.append(app.getStandardOutput());
    cmd.append(SPACE);
    cmd.append("2>");
    cmd.append(SPACE);
    cmd.append(app.getStandardError());

    String cmdStr = cmd.toString();
    log.info("Command = " + cmdStr);
    out.write((cmdStr + "\n").getBytes());
    String message = "\"execuationSuceeded\"";
View Full Code Here


    private String gateKeeper;
    private JobSubmissionListener listener;

    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);
View Full Code Here

    }

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

        StringBuffer buf = new StringBuffer();
        try {

            /*
             * Set Security
             */
            GSSCredential gssCred = gssContext.getGssCredentails();
            job.setCredentials(gssCred);

            log.debug("Request to contact:" + gateKeeper);

            buf.append("Finished launching job, Host = ").append(host.getHostAddress()).append(" RSL = ")
                    .append(job.getRSL()).append(" working directory = ").append(app.getStaticWorkingDirectory())
                    .append(" temp directory = ").append(app.getScratchWorkingDirectory())
                    .append(" Globus GateKeeper Endpoint = ").append(gateKeeper);
            invocationContext.getExecutionContext().getNotifier().info(invocationContext, buf.toString());

            /*
             * The first boolean is to specify the job is a batch job - use true for interactive and false for batch.
View Full Code Here

    return error;
  }

    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);
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);
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.debug("working diectroy = " + app.getStaticWorkingDirectory());
        log.debug("temp directory = " + app.getScratchWorkingDirectory());

        makeFileSystemDir(app.getStaticWorkingDirectory(),invocationContext);
        makeFileSystemDir(app.getScratchWorkingDirectory(),invocationContext);
        makeFileSystemDir(app.getInputDataDirectory(),invocationContext);
        makeFileSystemDir(app.getOutputDataDirectory(),invocationContext);
    }
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.debug("Command = " + InputUtils.buildCommand(cmdList));
        log.debug("Working dir = " + builder.directory());
        for (String key : builder.environment().keySet()) {
View Full Code Here

            log.debug("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.debug("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.debug(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

            }
        }
    }

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

        Session session = null;
        try {
            session = getSession(context);

            StringBuilder commandString = new StringBuilder();

            commandString.append("mkdir -p ");
            commandString.append(app.getScratchWorkingDirectory());
            commandString.append(" ; ");
            commandString.append("mkdir -p ");
            commandString.append(app.getStaticWorkingDirectory());
            commandString.append(" ; ");
            commandString.append("mkdir -p ");
            commandString.append(app.getInputDataDirectory());
            commandString.append(" ; ");
            commandString.append("mkdir -p ");
            commandString.append(app.getOutputDataDirectory());

            Command cmd = session.exec(commandString.toString());
            cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
        } catch (ConnectionException e) {
            throw new ProviderException(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.