Package org.globus.gram

Examples of org.globus.gram.GramJob


        try {
            GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(jobExecutionContext);
            String rsl = jobAttr.toRSL();

            log.debug("RSL = " + rsl);
            GramJob job = new GramJob(rsl);
            return job;
        } catch (ToolsException te) {
            throw new GFacProviderException(te.getMessage(), te, jobExecutionContext);
        }
    }
View Full Code Here


      contact = context.getExecutionModel().getHost();
    } else {
      contact = gatekeeper.getEndPointReference();
    }
    log.info("Using Globus GateKeeper " + contact);
    GramJob job = null;
    boolean jobSucsseful = false;

    String rsl = "";
    int errCode = 0;

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

      log.info("Host desc = " + context.getExecutionModel().getHostDesc().xmlText());

      GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(context);
      rsl = jobAttr.toRSL();
      job = new GramJob(rsl);
      job.setCredentials(gssCred);

      log.info("RSL = " + rsl);

      NotificationService notifier = context.getNotificationService();
      DurationObj compObj = notifier.computationStarted();
      StringBuffer buf = new StringBuffer();

      JobSubmissionListener listener = new JobSubmissionListener(job, context);
      job.addListener(listener);
      log.info("Request to contact:" + contact);
      // The first boolean is to specify the job is a batch job - use true
      // for interactive and false for batch.
      // the second boolean is to specify to use the full proxy and not
      // delegate a limited proxy.
      job.request(contact, false, false);

      log.info("JobID = " + job.getIDAsString());

      // Gram.request(contact, job, false, false);

      buf.append("Finished launching job, Host = ").append(context.getExecutionModel().getHost()).append(" RSL = ").append(job.getRSL()).append("working directory =").append(context.getExecutionModel().getWorkingDir()).append("tempDirectory =").append(context.getExecutionModel().getTmpDir())
          .append("Globus GateKeeper cantact = ").append(contact);
      context.getNotificationService().info(buf.toString());
      String gramJobid = job.getIDAsString();
      context.getNotificationService().info("JobID=" + gramJobid);
      log.info(buf.toString());
      // Send Audit Notifications
      notifier.appAudit(invocationContext.getServiceName(), new URI(job.getIDAsString()), contact, null, null, gssCred.getName().toString(), null, job.getRSL());

      listener.waitFor();
      job.removeListener(listener);

      int jobStatus = listener.getStatus();
      if (jobStatus == GramJob.STATUS_FAILED) {
        errCode = listener.getError();
        // Adding retry for error code to properties files as
        // gfac.retryonJobErrorCodes with comma separated
        if (context.getServiceContext().getGlobalConfiguration().getRetryonErrorCodes().contains(Integer.toString(errCode))) {
          try {
            log.info("Job Failed with Error code " + errCode + " and job id: " + gramJobid);
            log.info("Retry job sumttion one more time for error code" + errCode);
            job = new GramJob(rsl);
            job.setCredentials(gssCred);
            listener = new JobSubmissionListener(job, context);
            job.addListener(listener);
            job.request(contact, false, false);
            String newGramJobid = job.getIDAsString();
            String jobStatusMessage = GfacUtils.formatJobStatus(newGramJobid, "RETRY");
            context.getNotificationService().info(jobStatusMessage);
            context.getNotificationService().info("JobID=" + newGramJobid);
            notifier.appAudit(context.getServiceContext().getService().getService().getServiceName().getStringValue(), new URI(job.getIDAsString()), contact, null, null, gssCred.getName().toString(), null, job.getRSL());
            listener.waitFor();
            job.removeListener(listener);
            int jobStatus1 = listener.getStatus();
            if (jobStatus1 == GramJob.STATUS_FAILED) {
              int errCode1 = listener.getError();
              String errorMsg = "Job " + job.getID() + " on host " + context.getExecutionModel().getHost() + " Error Code = " + errCode1;
              String localHost = context.getServiceContext().getGlobalConfiguration().getLocalHost();
              throw new JobSubmissionFault(new Exception(errorMsg), localHost, "", "", CurrentProviders.Gram);
            }
          } catch (Exception e) {
            String localHost = context.getServiceContext().getGlobalConfiguration().getLocalHost();
            throw new JobSubmissionFault(e, localHost, "", "", CurrentProviders.Gram);
          }
        } else {
          String errorMsg = "Job " + job.getID() + " on host " + context.getExecutionModel().getHost() + " Error Code = " + errCode;
          String localHost = context.getServiceContext().getGlobalConfiguration().getLocalHost();
          GfacException error = new JobSubmissionFault(new Exception(errorMsg), localHost, contact, rsl, CurrentProviders.Gram);
          if (errCode == 8) {
            error.setFaultCode(ErrorCodes.JOB_CANCELED);
          } else {
            error.setFaultCode(ErrorCodes.JOB_FAILED);
          }
          // error.addProperty(ErrorCodes.JOB_TYPE,
          // ErrorCodes.JobType.Gram.toString());
          // error.addProperty(ErrorCodes.CONTACT, contact);
          throw error;
        }
      }
      notifier.computationFinished(compObj);     

      /*
       * Stdout and Stderror
       */
      GridFtp ftp = new GridFtp();

      // get Hostname
      String hostgridFTP = null;

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

      URI stdoutURI = GfacUtils.createGsiftpURI(hostgridFTP, invocationContext.getExecutionContext().getExecutionModel().getStdOut());
      URI stderrURI = GfacUtils.createGsiftpURI(hostgridFTP, invocationContext.getExecutionContext().getExecutionModel().getStderr());
     
      System.out.println(stdoutURI);
      System.out.println(stderrURI);
     
      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");
     
      String stdout = ftp.readRemoteFile(stdoutURI, gssCred, localStdOutFile);
      String stderr = ftp.readRemoteFile(stderrURI, gssCred, localStdErrFile);
     
      //set to context
      OutputUtils.fillOutputFromStdout(invocationContext.getMessageContext("output"), stdout, stderr);
     
     
      jobSucsseful = true;     
    } catch (GramException e) {
      String localHost = "xxxx";
      GfacException error = new JobSubmissionFault(e, localHost, contact, rsl, CurrentProviders.Gram);
      if (errCode == 8) {
        error.setFaultCode(ErrorCodes.JOB_CANCELED);
      } else {
        error.setFaultCode(ErrorCodes.JOB_FAILED);
      }
      // error.addProperty(ErrorCodes.JOB_TYPE,
      // ErrorCodes.JobType.Gram.toString());
      // error.addProperty(ErrorCodes.CONTACT, contact);
      throw error;
    } catch (GSSException e) {
      String localHost = context.getServiceContext().getGlobalConfiguration().getLocalHost();
      throw new JobSubmissionFault(e, localHost, contact, rsl, CurrentProviders.Gram);
    } catch (URISyntaxException e) {
      throw new GfacException(e, FaultCode.ErrorAtDependentService);
    } catch (InterruptedException e) {
      throw new GfacException(e, FaultCode.ErrorAtDependentService);
    } finally {
      if (job != null && !jobSucsseful) {
        try {
          job.cancel();
        } catch (Exception e) {
        }
      }
    }

View Full Code Here

  }

  public void abort(InvocationContext invocationContext) throws GfacException {
    try {
      ExecutionContext context = invocationContext.getExecutionContext();
      GramJob job = new GramJob("");
      job.setID(context.getExecutionModel().getJobID());
      job.setCredentials(((GSISecurityContext) context.getSecurityContext()).getGssCredentails());
      job.cancel();
    } catch (MalformedURLException e) {
      throw new GfacException(e, FaultCode.ErrorAtDependentService);
    } catch (GramException e) {
      throw new GfacException(e, FaultCode.ErrorAtDependentService);
    } catch (GSSException e) {
View Full Code Here

  public static void syncFileSystem(String host, GSSCredential gssCred) {
    try {
      GramAttributes gramAttr = new GramAttributes();
      gramAttr.setExecutable("/bin/sync");
      GramJob job = new GramJob(gramAttr.toRSL());
      job.setCredentials(gssCred);
      log.info("RSL = " + job.getRSL());
      try {
        Gram.request(host, job, false, false);
      } catch (Exception e) {
        String error = "Cannot launch GRAM job to sync filesystem. " + e.getMessage();
        log.error(error, e);
        throw new Exception(e);
      }

      int twoMin = 1000 * 60 * 2;
      long start = System.currentTimeMillis();

      while ((System.currentTimeMillis() - start) < twoMin) {
        int jobStatus = job.getStatus();

        // job finished successfully
        if (jobStatus == GRAMConstants.STATUS_DONE) {
          log.info("Filesystem sync succeeded");
          return;
        } else if (jobStatus == GRAMConstants.STATUS_FAILED) {
          String error = "Filesystem sync failed";
          log.info(error);
          throw new Exception(error);
        }
        try {
          Thread.sleep(2000);
        } catch (InterruptedException ie) {
          log.error("Thread " + Thread.currentThread().getName() + " interrupted", ie);
          try {
            job.cancel();
          } catch (Exception e) {
            log.error("Exception cancelling job", e);
          }
        }
      }
View Full Code Here

    public static void syncFileSystem(String host, GSSCredential gssCred)  {
        try {
            GramAttributes gramAttr = new GramAttributes();
            gramAttr.setExecutable("/bin/sync");
            GramJob job = new GramJob(gramAttr.toRSL());
            job.setCredentials(gssCred);
            logger.info("RSL = " + job.getRSL());
            try {
                Gram.request(host, job, false, false);
            } catch (Exception e) {
                String error = "Cannot launch GRAM job to sync filesystem. " + e.getMessage();
                logger.severe(error);
                throw new Exception(e);
            }

            int twoMin = 1000 * 60 * 2;
            long start = System.currentTimeMillis();

            while ((System.currentTimeMillis() - start) < twoMin) {
                int jobStatus = job.getStatus();

                // job finished successfully
                if (jobStatus == GRAMConstants.STATUS_DONE) {
                    logger.info("Filesystem sync succeeded");
                    return;
                } else if (jobStatus == GRAMConstants.STATUS_FAILED) {
                    String error = "Filesystem sync failed";
                    logger.info(error);
                    throw new Exception(error);
                }
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException ie) {
                    logger.severe("Thread " + Thread.currentThread().getName() + " interrupted");
                    try {
                        job.cancel();
                    } catch (Exception e) {
                        logger.severe("Exception cancelling job: " + e.getLocalizedMessage());
                    }
                }
            }
View Full Code Here

            GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(invocationContext);
            String rsl = jobAttr.toRSL();

            log.debug("RSL = " + rsl);

            job = new GramJob(rsl);
            listener = new JobSubmissionListener(job, invocationContext);
            job.addListener(listener);

        } catch (ToolsException te) {
            throw new ProviderException(te.getMessage(), te, invocationContext);
View Full Code Here

            GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(invocationContext);
            String rsl = jobAttr.toRSL();

            log.info("RSL = " + rsl);

            job = new GramJob(rsl);
            listener = new JobSubmissionListener(job, invocationContext);
            job.addListener(listener);

        } catch (ToolsException te) {
            throw new ProviderException(te.getMessage(), te, invocationContext);
View Full Code Here

            if (enableTwoPhase) {
                rsl = rsl + "(twoPhase=yes)";
            }

            log.debug("RSL = " + rsl);
            GramJob job = new GramJob(rsl);
            return job;
        } catch (ToolsException te) {
            throw new GFacProviderException(te.getMessage(), te, jobExecutionContext);
        }
    }
View Full Code Here

    private void cancelSingleJob(String jobId, JobExecutionContext context) throws GFacException {
        // First check whether job id is in the cache
        if (currentlyExecutingJobCache.containsKey(jobId)) {

            synchronized (this) {
                GramJob gramJob = currentlyExecutingJobCache.get(jobId);

                // Even though we check using containsKey, at this point job could be null
                if (gramJob != null && (gramJob.getStatus() != GRAMConstants.STATUS_DONE ||
                        gramJob.getStatus() != GRAMConstants.STATUS_FAILED)) {
                    cancelJob(gramJob, context);
                }
            }

        } else {

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

            GramJob gramJob = new GramJob(null);
            try {
                gramJob.setID(jobId);
            } catch (MalformedURLException e) {
                throw new GFacException("Invalid job id - " + jobId, e);
            }
            gramJob.setCredentials(gssCred);

            synchronized (this) {
                if (gramJob.getStatus() != GRAMConstants.STATUS_DONE ||
                        gramJob.getStatus() != GRAMConstants.STATUS_FAILED) {
                    cancelJob(gramJob, context);
                }
            }
        }
    }
View Full Code Here

            GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(invocationContext);
            String rsl = jobAttr.toRSL();

            log.info("RSL = " + rsl);

            job = new GramJob(rsl);
            listener = new JobSubmissionListener(job, invocationContext);
            job.addListener(listener);

        } catch (ToolsException te) {
            throw new ProviderException(te.getMessage(), te, invocationContext);
View Full Code Here

TOP

Related Classes of org.globus.gram.GramJob

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.