Examples of ExecutionModel


Examples of org.ogce.gfac.model.ExecutionModel

  }

  @Override
  public void initialize(InvocationContext invocationContext) throws GfacException {
    ExecutionContext appExecContext = invocationContext.getExecutionContext();
    ExecutionModel model = appExecContext.getExecutionModel();
   
    AmazonSecurityContext amazonSecurityContext = ((AmazonSecurityContext) invocationContext.getSecurityContext(AMAZON_SECURITY_CONTEXT));
    String access_key = amazonSecurityContext.getAccessKey();
    String secret_key = amazonSecurityContext.getSecretKey();

    //TODO way to read value (header or xregistry)
    String ami_id = "";
    String ins_type = "";
    String ins_id = "";
   
    /*
     * Need to start EC2 instance before running it
     */
    AWSCredentials credential = new BasicAWSCredentials(access_key, secret_key);
    AmazonEC2Client ec2client = new AmazonEC2Client(credential);
       
    try {
      /*
       * Build key pair before start instance
       */
      buildKeyPair(ec2client);

      // right now, we can run it on one host
      if (ami_id != null)
        this.instance = startInstances(ec2client, ami_id, ins_type, invocationContext.getExecutionContext().getNotificationService()).get(0);
      else {

        // already running instance
        DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
        DescribeInstancesResult describeInstancesResult = ec2client.describeInstances(describeInstancesRequest.withInstanceIds(ins_id));

        if (describeInstancesResult.getReservations().size() == 0 || describeInstancesResult.getReservations().get(0).getInstances().size() == 0) {
          throw new GfacException("Instance not found:" + ins_id, FaultCode.InvalidRequest);
        }

        this.instance = describeInstancesResult.getReservations().get(0).getInstances().get(0);

        // check instance keypair
        if (this.instance.getKeyName() == null || !this.instance.getKeyName().equals(KEY_PAIR_NAME))
          throw new GfacException("Keypair for instance:" + ins_id + " is not valid", FaultCode.InvalidRequest);
      }
     
      //send out instance id
      invocationContext.getExecutionContext().getNotificationService().sendResourceMappingNotifications(this.instance.getPublicDnsName(), "EC2 Instance " + this.instance.getInstanceId() + " is running with public name " + this.instance.getPublicDnsName(), this.instance.getInstanceId());
     

      /*
       * Make sure port 22 is connectable
       */
      for (GroupIdentifier g : this.instance.getSecurityGroups()) {
        IpPermission ip = new IpPermission();
        ip.setIpProtocol("tcp");
        ip.setFromPort(22);
        ip.setToPort(22);
        AuthorizeSecurityGroupIngressRequest r = new AuthorizeSecurityGroupIngressRequest();
        r = r.withIpPermissions(ip.withIpRanges("0.0.0.0/0"));
        r.setGroupId(g.getGroupId());
        try {
          ec2client.authorizeSecurityGroupIngress(r);
        } catch (AmazonServiceException as) {
          /*
           * If exception is from duplicate room, ignore it.
           */
          if (!as.getErrorCode().equals("InvalidPermission.Duplicate"))
            throw as;
        }
      }   

    } catch (Exception e) {
      // TODO throw out
      e.printStackTrace();
      log.error(e.getMessage(), e);
      throw new GfacException(e, FaultCode.InvalidRequest);
    }   
       
    //set Host location
    model.setHost(this.instance.getPublicDnsName());
   
    /*
     * Make directory
     */
    SSHClient ssh = new SSHClient();
    try {
      ssh.loadKnownHosts();
      ssh.connect(this.instance.getPublicDnsName());

      ssh.authPublickey(privateKeyFilePath);
      final Session session = ssh.startSession();
      try {
        StringBuilder command = new StringBuilder();
        command.append("mkdir -p ");
        command.append(model.getTmpDir());
        command.append(" | ");
        command.append("mkdir -p ");
        command.append(model.getWorkingDir());
        command.append(" | ");
        command.append("mkdir -p ");
        command.append(model.getInputDataDir());
        command.append(" | ");
        command.append("mkdir -p ");
        command.append(model.getOutputDataDir());
        Command cmd = session.exec(command.toString());
        cmd.join(5, TimeUnit.SECONDS);
      } catch (Exception e) {
        throw e;
      } finally {
View Full Code Here

Examples of org.ogce.gfac.model.ExecutionModel

  }
 
  @Override
  public void execute(InvocationContext invocationContext) throws GfacException {
    ExecutionContext context = invocationContext.getExecutionContext();
    ExecutionModel model = context.getExecutionModel();

    List<String> cmdList = new ArrayList<String>();

    SSHClient ssh = new SSHClient();
    try {

      /*
       * Notifier
       */
      NotificationService notifier = context.getNotificationService();

      /*
       * Builder Command
       */
      cmdList.add(context.getExecutionModel().getExecutable());
      cmdList.addAll(context.getExecutionModel().getInputParameters());

      // create process builder from command
      String command = buildCommand(cmdList);
     
      //redirect StdOut and StdErr
      command += SPACE + "1>" + SPACE + model.getStdOut();
      command += SPACE + "2>" + SPACE + model.getStderr();     

      // get the env of the host and the application
      Map<String, String> nv = context.getExecutionModel().getEnv();     

      // extra env's
      nv.put(GFacConstants.INPUT_DATA_DIR, context.getExecutionModel().getInputDataDir());
      nv.put(GFacConstants.OUTPUT_DATA_DIR, context.getExecutionModel().getOutputDataDir());
     
      // log info
      log.info("Command = " + buildCommand(cmdList));     
      for (String key : nv.keySet()) {
        log.info("Env[" + key + "] = " + nv.get(key));
      }

      // notify start
      DurationObj compObj = notifier.computationStarted();

      /*
       * Create ssh connection
       */
      ssh.loadKnownHosts();
      ssh.connect(model.getHost());
      ssh.authPublickey(privateKeyFilePath);

      final Session session = ssh.startSession();
      try {
        /*
         * Build working Directory
         */
        log.info("WorkingDir = " + model.getWorkingDir());     
        session.exec("mkdir -p " + model.getWorkingDir());
        session.exec("cd " + model.getWorkingDir());
       
        /*
         * Set environment
         */
        for (String key : nv.keySet()) {
          session.setEnvVar(key, nv.get(key));
        }
       
        /*
         * Execute
         */
        Command cmd = session.exec(command);
        log.info("stdout=" + GfacUtils.readFromStream(session.getInputStream()));
        cmd.join(5, TimeUnit.SECONDS);
       
       
        // notify end
        notifier.computationFinished(compObj);
       
        /*
         * 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 (cmd.getExitStatus() != 0) {
          log.error("Process finished with non zero return value. Process may have failed");
        } else {
          log.info("Process finished with return value of zero.");
        }                       
       
        File logDir = new File("./service_logs");
        if (!logDir.exists()) {
          logDir.mkdir();
        }       
       
        // Get the Stdouts and StdErrs
        QName x = QName.valueOf(invocationContext.getServiceName());
        String timeStampedServiceName = GfacUtils.createServiceDirName(x);
        File localStdOutFile = new File(logDir, timeStampedServiceName + ".stdout");
        File localStdErrFile = new File(logDir, timeStampedServiceName + ".stderr");
       
        SCPFileTransfer fileTransfer = ssh.newSCPFileTransfer();
        fileTransfer.download(model.getStdOut(), localStdOutFile.getAbsolutePath());
        fileTransfer.download(model.getStderr(), localStdErrFile.getAbsolutePath());       
       
        context.getExecutionModel().setStdoutStr(GfacUtils.readFile(localStdOutFile.getAbsolutePath()));
        context.getExecutionModel().setStderrStr(GfacUtils.readFile(localStdErrFile.getAbsolutePath()));
       
        // set to context
View Full Code Here

Examples of org.ogce.gfac.model.ExecutionModel

  public static final String MYPROXY_SECURITY_CONTEXT = "myproxy";

  public void initialize(InvocationContext invocationContext) throws GfacException {
    ExecutionContext appExecContext = invocationContext.getExecutionContext();
    ExecutionModel model = appExecContext.getExecutionModel();

    GridFtp ftp = new GridFtp();

    try {
      GSSCredential gssCred = ((GSISecurityContext) invocationContext.getSecurityContext(MYPROXY_SECURITY_CONTEXT)).getGssCredentails();

      // get Hostname
      String hostgridFTP = null;

      if (model.getHostDesc().getHostConfiguration().getGridFTPArray() != null && model.getHostDesc().getHostConfiguration().getGridFTPArray().length > 0) {
        hostgridFTP = model.getHostDesc().getHostConfiguration().getGridFTPArray(0).getEndPointReference();
      } else {
        hostgridFTP = model.getHost();
      }

      URI tmpdirURI = GfacUtils.createGsiftpURI(hostgridFTP, model.getTmpDir());
      URI workingDirURI = GfacUtils.createGsiftpURI(hostgridFTP, model.getWorkingDir());
      URI inputURI = GfacUtils.createGsiftpURI(hostgridFTP, model.getInputDataDir());
      URI outputURI = GfacUtils.createGsiftpURI(hostgridFTP, model.getOutputDataDir());

      log.info("Host FTP = " + hostgridFTP);
      log.info("temp directory = " + tmpdirURI);
      log.info("Working directory = " + workingDirURI);
      log.info("Input directory = " + inputURI);
View Full Code Here

Examples of org.ogce.gfac.model.ExecutionModel

        String inputDataDir = tmpDir + File.separator + "inputData";
        String outputDataDir = tmpDir + File.separator + "outputData";

        GlobusGatekeeperType[] gatekeepers = hostDescType.getHostConfiguration().getGlobusGatekeeperArray();

        ExecutionModel model = new ExecutionModel();
        model.setHost(host);
        model.setExecutable(executable);
        model.setTmpDir(tmpDir);
        model.setWorkingDir(workingDir);
        model.setStdOut(stdOut);
        model.setStderr(stderr);
        model.setInputDataDir(inputDataDir);
        model.setOutputDataDir(outputDataDir);
        model.setEnv(envMap);
        model.setAplicationDesc(appDescType);
        model.setHostDesc(hostDescType);
        model.setGatekeeper(gatekeepers[0]);

        // input parameter
        ArrayList<String> tmp = new ArrayList<String>();
        for (Iterator<String> iterator = context.getMessageContext(INPUT_MESSAGE_CONTEXT).getParameterNames(); iterator.hasNext();) {
          String key = iterator.next();
          tmp.add(context.getMessageContext(INPUT_MESSAGE_CONTEXT).getStringParameterValue(key));
        }
        model.setInputParameters(tmp);

        context.getExecutionContext().setExectionModel(model);

        // output parameter
        //TODO type mapping
View Full Code Here

Examples of org.ogce.gfac.model.ExecutionModel

  }

  @Override
  public void initialize(InvocationContext invocationContext) throws GfacException {
    ExecutionContext appExecContext = invocationContext.getExecutionContext();
    ExecutionModel model = appExecContext.getExecutionModel();

    SSHClient ssh = new SSHClient();
    try {
      ssh.loadKnownHosts();
      ssh.connect(model.getHost());

      // TODO how to authenticate with system
      ssh.authPublickey(System.getProperty("user.name"));
      final Session session = ssh.startSession();
      try {
        StringBuilder command = new StringBuilder();
        command.append("mkdir -p ");
        command.append(model.getTmpDir());
        command.append(" | ");
        command.append("mkdir -p ");
        command.append(model.getWorkingDir());
        command.append(" | ");
        command.append("mkdir -p ");
        command.append(model.getInputDataDir());
        command.append(" | ");
        command.append("mkdir -p ");
        command.append(model.getOutputDataDir());
        Command cmd = session.exec(command.toString());
        cmd.join(5, TimeUnit.SECONDS);
      } catch (Exception e) {
        throw e;
      } finally {
View Full Code Here

Examples of org.ogce.gfac.model.ExecutionModel

  }

  @Override
  public void execute(InvocationContext invocationContext) throws GfacException {
    ExecutionContext context = invocationContext.getExecutionContext();
    ExecutionModel model = context.getExecutionModel();

    List<String> cmdList = new ArrayList<String>();

    SSHClient ssh = new SSHClient();
    try {

      /*
       * Notifier
       */
      NotificationService notifier = context.getNotificationService();

      /*
       * Builder Command
       */
      cmdList.add(context.getExecutionModel().getExecutable());
      cmdList.addAll(context.getExecutionModel().getInputParameters());

      // create process builder from command
      String command = buildCommand(cmdList);
     
      //redirect StdOut and StdErr
      command += SPACE + "1>" + SPACE + model.getStdOut();
      command += SPACE + "2>" + SPACE + model.getStderr();     

      // get the env of the host and the application
      Map<String, String> nv = context.getExecutionModel().getEnv();     

      // extra env's
      nv.put(GFacConstants.INPUT_DATA_DIR, context.getExecutionModel().getInputDataDir());
      nv.put(GFacConstants.OUTPUT_DATA_DIR, context.getExecutionModel().getOutputDataDir());
     
      // log info
      log.info("Command = " + buildCommand(cmdList));     
      for (String key : nv.keySet()) {
        log.info("Env[" + key + "] = " + nv.get(key));
      }

      // notify start
      DurationObj compObj = notifier.computationStarted();

      /*
       * Create ssh connection
       */
      ssh.loadKnownHosts();
      ssh.connect(model.getHost());

      // TODO how to authenticate with system
      ssh.authPublickey(System.getProperty("user.name"));

      final Session session = ssh.startSession();
      try {
        /*
         * Build working Directory
         */
        log.info("WorkingDir = " + model.getWorkingDir());     
        session.exec("mkdir -p " + model.getWorkingDir());
        session.exec("cd " + model.getWorkingDir());
       
        /*
         * Set environment
         */
        for (String key : nv.keySet()) {
          session.setEnvVar(key, nv.get(key));
        }
       
        /*
         * Execute
         */
        Command cmd = session.exec(command);
        log.info("stdout=" + GfacUtils.readFromStream(session.getInputStream()));
        cmd.join(5, TimeUnit.SECONDS);
       
       
        // notify end
        notifier.computationFinished(compObj);
       
        /*
         * 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 (cmd.getExitStatus() != 0) {
          log.error("Process finished with non zero return value. Process may have failed");
        } else {
          log.info("Process finished with return value of zero.");
        }                       
       
        File logDir = new File("./service_logs");
        if (!logDir.exists()) {
          logDir.mkdir();
        }       
       
        // Get the Stdouts and StdErrs
        QName x = QName.valueOf(invocationContext.getServiceName());
        String timeStampedServiceName = GfacUtils.createServiceDirName(x);
        File localStdOutFile = new File(logDir, timeStampedServiceName + ".stdout");
        File localStdErrFile = new File(logDir, timeStampedServiceName + ".stderr");
       
        SCPFileTransfer fileTransfer = ssh.newSCPFileTransfer();
        fileTransfer.download(model.getStdOut(), localStdOutFile.getAbsolutePath());
        fileTransfer.download(model.getStderr(), localStdErrFile.getAbsolutePath());       
       
        context.getExecutionModel().setStdoutStr(GfacUtils.readFile(localStdOutFile.getAbsolutePath()));
        context.getExecutionModel().setStderrStr(GfacUtils.readFile(localStdErrFile.getAbsolutePath()));
       
        // set to context
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.