Package org.apache.airavata.schemas.gfac

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


    job.setJobData(executableName);
    GFacUtils.recordApplicationJob(jobExecutionContext, job);
  }

  public void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException {
    ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
    Session session = null;
    try {
      session = securityContext.getSession(jobExecutionContext.getApplicationContext().getHostDescription().getType().getHostAddress());
      /*
       * Execute
       */
      String execuable = app.getStaticWorkingDirectory() + File.separatorChar + Constants.EXECUTABLE_NAME;
      GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobID, ApplicationJobStatus.SUBMITTED);
      Command cmd = session.exec("/bin/chmod 755 " + execuable + "; " + execuable);
      GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobID, ApplicationJobStatus.RESULTS_RETRIEVE);
      log.info("stdout=" + GFacUtils.readFromStream(session.getInputStream()));
      cmd.join(Constants.COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
View Full Code Here


  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

    public void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException{
        jobExecutionContext.getNotifier().publish(new StartExecutionEvent());
        GlobusHostType host = (GlobusHostType) jobExecutionContext.getApplicationContext().
                getHostDescription().getType();
        ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().
                getApplicationDeploymentDescription().getType();

        StringBuilder stringBuilder = new StringBuilder();
        try {

            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.
                    getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentials();
            job.setCredentials(gssCred);
            // We do not support multiple gatekeepers in XBaya GUI, so we simply pick the 0th element in the array
            String gateKeeper = host.getGlobusGateKeeperEndPointArray(0);
            log.info("Request to contact:" + gateKeeper);

            stringBuilder.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);

            log.info(stringBuilder.toString());

            submitJobs(gateKeeper, jobExecutionContext, host);
View Full Code Here

          //TODO
        }


        ApplicationDescription applicationDeploymentDescription = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription();
        ApplicationDeploymentDescriptionType app = applicationDeploymentDescription.getType();
        GridFtp ftp = new GridFtp();

        try {




            GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext.
                    getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentials();

            if (gridFTPEndpointArray == null || gridFTPEndpointArray.length == 0) {
              gridFTPEndpointArray = new String[]{hostType.getHostAddress()};
            }
            boolean success = false;
            GFacHandlerException pe = null;// = new ProviderException("");
            for (String endpoint : gridFTPEndpointArray) {
                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.info("Host FTP = " + gridFTPEndpointArray[0]);
                    log.info("temp directory = " + tmpdirURI);
                    log.info("Working directory = " + workingDirURI);
                    log.info("Input directory = " + inputURI);
View Full Code Here

    makeDirectory(jobExecutionContext);

  }
  private void makeDirectory(JobExecutionContext context) throws GFacHandlerException,GFacException {
    SSHSecurityContext securityContext = (SSHSecurityContext)context.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);
    ApplicationDeploymentDescriptionType app = context.getApplicationContext().getApplicationDeploymentDescription().getType();
    Session session = null;
    try {
      session = securityContext.getSession(context.getApplicationContext().getHostDescription().getType().getHostAddress());

      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(Constants.COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
    } catch (ConnectionException e) {
      throw new GFacHandlerException(e.getMessage(), e, context);
View Full Code Here

              throw new GFacHandlerException("Error while input File Staging", jobExecutionContext, e, e.getLocalizedMessage());
          }
          jobExecutionContext.setInMessageContext(inputNew);
  }
   private static String stageInputFiles(JobExecutionContext context,String paramValue) throws IOException,GFacException{
     ApplicationDeploymentDescriptionType app = context.getApplicationContext().getApplicationDeploymentDescription().getType();

     SSHSecurityContext securityContext = (SSHSecurityContext)context.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);
     SCPFileTransfer fileTransfer = securityContext.getSSHClient().newSCPFileTransfer();
     String remoteFile = app.getInputDataDirectory() + File.separatorChar + paramValue;

     File inputFile = new File(paramValue);
     fileTransfer.upload(inputFile.getAbsolutePath(), remoteFile);
     return remoteFile;
   }
View Full Code Here

public class SCPOutputHandler implements GFacHandler{


  public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
    ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext()
        .getApplicationDeploymentDescription().getType();
    try {
      SSHSecurityContext securityContext = (SSHSecurityContext) jobExecutionContext
          .getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);

      // Get the Stdouts and StdErrs
      String timeStampedServiceName = GFacUtils.createUniqueNameForService(jobExecutionContext.getServiceName());
      File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout");
      File localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr");

      SCPFileTransfer fileTransfer = securityContext.getSSHClient().newSCPFileTransfer();
      fileTransfer.download(app.getStandardOutput(), localStdOutFile.getAbsolutePath());
      fileTransfer.download(app.getStandardError(), localStdErrFile.getAbsolutePath());

      String stdOutStr = GFacUtils.readFileToString(localStdOutFile.getAbsolutePath());
      String stdErrStr = GFacUtils.readFileToString(localStdErrFile.getAbsolutePath());
      Map<String, ActualParameter> stringMap = new HashMap<String, ActualParameter>();
      Map<String, Object> output = jobExecutionContext.getOutMessageContext().getParameters();
View Full Code Here

    public LocalProvider(){
        cmdList = new ArrayList<String>();
    }

    public void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException {
        ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().
                getApplicationDeploymentDescription().getType();

        buildCommand(app.getExecutableLocation(), ProviderUtils.getInputParameters(jobExecutionContext));
        initProcessBuilder(app);

        // extra environment variables
        builder.environment().put(Constants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
        builder.environment().put(Constants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());

        // set 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

        }
    }

    public void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException {
        jobExecutionContext.getNotifier().publish(new StartExecutionEvent());
         ApplicationDeploymentDescriptionType app = jobExecutionContext.
                 getApplicationContext().getApplicationDeploymentDescription().getType();

        try {
            // running cmd
            Process process = builder.start();
            jobId="Local_"+Calendar.getInstance().getTimeInMillis();
            if(jobExecutionContext.getGFacConfiguration().getAiravataAPI() != null){
            saveApplicationJob(jobExecutionContext);
          }
            GFacUtils.updateApplicationJobStatus(jobExecutionContext,jobId, ApplicationJobStatus.INITIALIZE);
            Thread standardOutWriter = new InputStreamToFileWriter(process.getInputStream(), app.getStandardOutput());
            Thread standardErrorWriter = new InputStreamToFileWriter(process.getErrorStream(), app.getStandardError());

            // start output threads
            standardOutWriter.setDaemon(true);
            standardErrorWriter.setDaemon(true);
            standardOutWriter.start();
            standardErrorWriter.start();
            GFacUtils.updateApplicationJobStatus(jobExecutionContext,jobId, ApplicationJobStatus.EXECUTING);
            // wait for the process (application) to finish executing
            int returnValue = process.waitFor();
            GFacUtils.updateApplicationJobStatus(jobExecutionContext,jobId, ApplicationJobStatus.FINALIZE);

            // make sure other two threads are done
            standardOutWriter.join();
            standardErrorWriter.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) {
              GFacUtils.updateApplicationJobStatus(jobExecutionContext,jobId, ApplicationJobStatus.FAILED);
                log.error("Process finished with non zero return value. Process may have failed");
            } else {
              GFacUtils.updateApplicationJobStatus(jobExecutionContext,jobId, ApplicationJobStatus.FINISHED);
                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

        }
    }

  private void saveApplicationJob(JobExecutionContext jobExecutionContext)
      throws GFacProviderException {
    ApplicationDeploymentDescriptionType app = jobExecutionContext.
                getApplicationContext().getApplicationDeploymentDescription().getType();
    ApplicationJob appJob = GFacUtils.createApplicationJob(jobExecutionContext);
    appJob.setJobId(jobId);
    LocalProviderJobData data = new LocalProviderJobData();
    data.setApplicationName(app.getExecutableLocation());
    data.setInputDir(app.getInputDataDirectory());
    data.setOutputDir(app.getOutputDataDirectory());
    data.setWorkingDir(builder.directory().toString());
    data.setInputParameters(ProviderUtils.getInputParameters(jobExecutionContext));
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    JAXB.marshal(data, stream);
    appJob.setJobData(stream.toString());
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.