Package org.ogce.gfac.notification

Examples of org.ogce.gfac.notification.NotificationService


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


   
    try {
      /*
       * Notifier
       */
      NotificationService notifier = context.getNotificationService();
     
      /*
       * Builder Command
       */         
      cmdList.add(context.getExecutionModel().getExecutable());
      cmdList.addAll(context.getExecutionModel().getInputParameters());
     
      //create process builder from command
      ProcessBuilder builder = new  ProcessBuilder(cmdList);
     
     
      // get the env of the host and the application
      Map<String, String> nv = context.getExecutionModel().getEnv();     
      builder.environment().putAll(nv);
     
      // extra env's     
      builder.environment().put(GFacConstants.INPUT_DATA_DIR, context.getExecutionModel().getInputDataDir());
      builder.environment().put(GFacConstants.OUTPUT_DATA_DIR, context.getExecutionModel().getOutputDataDir());
     
      //working directory
      builder.directory(new File(context.getExecutionModel().getWorkingDir()));
           
     
      //log info
      log.info("Command = " + buildCommand(cmdList));
      log.info("Working dir = " + builder.directory());
      for (String key : builder.environment().keySet()) {
        log.info("Env[" + key + "] = " + builder.environment().get(key));
      }
     
      //notify start     
      DurationObj compObj = notifier.computationStarted();   
     
      //running cmd
      Process process = builder.start();               

      final BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
      final BufferedReader err = new BufferedReader(new InputStreamReader(process.getErrorStream()));
      final BufferedWriter stdoutWtiter = new BufferedWriter(new FileWriter(context.getExecutionModel().getStdOut()));
      final BufferedWriter stdErrWtiter =  new BufferedWriter(new FileWriter(context.getExecutionModel().getStderr()));

      Thread t1 = new Thread(new Runnable() {
       
        public void run() {
          try {
            String line=null;
                  while ( (line = in.readLine()) != null){
                    log.debug(line);
                    stdoutWtiter.write(line);
                    stdoutWtiter.newLine();       
                  }
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            if (in != null){
              try {
                in.close();
              } catch (Exception e) {
                e.printStackTrace();
              }             
            }
            if (stdoutWtiter != null) {
              try {
                stdoutWtiter.close();
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }
        }

      });

      Thread t2 = new Thread(new Runnable() {

        public void run() {
          try {
            String line=null;
            while ((line = err.readLine()) != null){
                    log.debug(line);
                    stdErrWtiter.write(line);
                    stdErrWtiter.newLine();       
                  }
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            if (err != null){
              try {
                err.close();
              } catch (Exception e) {
                e.printStackTrace();
              }             
            }
            if (stdErrWtiter != null) {
              try {
                stdErrWtiter.close();
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }

        }

      });
     
      //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();
     
      // notify end
      notifier.computationFinished(compObj);
     
      // make sure other two threads are done
      t1.join();
      t2.join();

View Full Code Here

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

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

TOP

Related Classes of org.ogce.gfac.notification.NotificationService

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.