Package net.schmizz.sshj.connection.channel.direct

Examples of net.schmizz.sshj.connection.channel.direct.Session


      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
        OutputUtils.fillOutputFromStdout(invocationContext.getMessageContext("output"), context.getExecutionModel().getStdoutStr(), context.getExecutionModel().getStderrStr());
       
      } catch (Exception e) {
        throw e;
      } finally {
        try {
          session.close();
        } catch (Exception e) {
        }
      }
    } catch (Exception e) {
      throw new GfacException(e.getMessage(), e);
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);
        } catch (TransportException e) {
            throw new ProviderException(e.getMessage(), e, context);
View Full Code Here

    }

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

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

            /*
             * Going to working Directory
             */
            session.exec("cd " + app.getStaticWorkingDirectory());

            // 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);
                }
            }
            // extra env's
            nv.put(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
            nv.put(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());

            /*
             * Set environment
             */
            log.debug("Command = " + command);
            for (Entry<String, String> entry : nv.entrySet()) {
                log.debug("Env[" + entry.getKey() + "] = " + entry.getValue());
                session.setEnvVar(entry.getKey(), entry.getValue());
            }

            /*
             * Execute
             */
            Command cmd = session.exec(command);
            log.debug("stdout=" + GfacUtils.readFromStream(session.getInputStream()));
            cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);

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

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

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

      /*
       * check return value. usually not very helpful to draw conclusions
       * based on return values so don't bother. just provide warning in
View Full Code Here

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

      /*
       * check return value. usually not very helpful to draw conclusions
       * based on return values so don't bother. just provide warning in
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);
        } catch (TransportException e) {
            throw new ProviderException(e.getMessage(), e, context);
View Full Code Here

    }

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

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

            /*
             * Going to working Directory
             */
            session.exec("cd " + app.getStaticWorkingDirectory());

            // 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);
                }
            }
            // extra env's
            nv.put(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
            nv.put(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());

            /*
             * Set environment
             */
            log.info("Command = " + command);
            for (Entry<String, String> entry : nv.entrySet()) {
                log.info("Env[" + entry.getKey() + "] = " + entry.getValue());
                session.setEnvVar(entry.getKey(), entry.getValue());
            }

            /*
             * Execute
             */
            Command cmd = session.exec(command);
            log.info("stdout=" + GfacUtils.readFromStream(session.getInputStream()));
            cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);

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

    }

    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);
        } catch (TransportException e) {
            throw new ProviderException(e.getMessage(), e);
View Full Code Here

    }

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

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

            /*
             * Going to working Directory
             */
            session.exec("cd " + app.getStaticWorkingDirectory());

            // 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);
                }
            }
            // extra env's
            nv.put(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
            nv.put(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());

            /*
             * Set environment
             */
            log.info("Command = " + command);
            for (Entry<String, String> entry : nv.entrySet()) {
                log.info("Env[" + entry.getKey() + "] = " + entry.getValue());
                session.setEnvVar(entry.getKey(), entry.getValue());
            }

            /*
             * Execute
             */
            Command cmd = session.exec(command);
            log.info("stdout=" + GfacUtils.readFromStream(session.getInputStream()));
            cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);

            /*
             * 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 net.schmizz.sshj.connection.channel.direct.Session

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.