Package org.apache.airavata.gfac.context.security

Examples of org.apache.airavata.gfac.context.security.SSHSecurityContext


    log.info("Setup SSH job directorties");
    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);
    } catch (TransportException e) {
      throw new GFacHandlerException(e.getMessage(), e, context);
    } catch (IOException e) {
      throw new GFacHandlerException(e.getMessage(), e, context);
    } finally {
      securityContext.closeSession(session);
    }
  }
View Full Code Here


          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

      if (this.configuration.getAmazonSecurityContext() != null) {
        jobExecutionContext.addSecurityContext(AmazonSecurityContext.AMAZON_SECURITY_CONTEXT,
            this.configuration.getAmazonSecurityContext());
      }
    } else if (registeredHost.getType() instanceof SSHHostType) {
      SSHSecurityContext context = new SSHSecurityContext();
      context.setUsername(configurationProperties.getProperty(Constants.SSH_USER_NAME));
      context.setPrivateKeyLoc(configurationProperties.getProperty(Constants.SSH_PRIVATE_KEY));
      context.setKeyPass(configurationProperties.getProperty(Constants.SSH_PRIVATE_KEY_PASS));
      jobExecutionContext.addSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT, context);

    }
  }
View Full Code Here

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

        jobExecutionContext.setOutMessageContext(outMessage);

    }

  private SSHSecurityContext getSecurityContext() {
    SSHSecurityContext context = new SSHSecurityContext();
        context.setUsername("*****");
        context.setPrivateKeyLoc("~/.ssh/id_dsa");
        context.setKeyPass("*****");
    return context;
  }
View Full Code Here

          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

    log.info("Setup SSH job directorties");
    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);
    } catch (TransportException e) {
      throw new GFacHandlerException(e.getMessage(), e, context);
    } catch (IOException e) {
      throw new GFacHandlerException(e.getMessage(), e, context);
    } finally {
      securityContext.closeSession(session);
    }
  }
View Full Code Here

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

            String sshUserName = configurationProperties.getProperty(Constants.SSH_USER_NAME);
            String sshPrivateKey = configurationProperties.getProperty(Constants.SSH_PRIVATE_KEY);
            String sshPrivateKeyPass = configurationProperties.getProperty(Constants.SSH_PRIVATE_KEY_PASS);
            String sshPassword = configurationProperties.getProperty(Constants.SSH_PASSWORD);
            String sshPublicKey = configurationProperties.getProperty(Constants.SSH_PUBLIC_KEY);
            SSHSecurityContext sshSecurityContext = new SSHSecurityContext();
            if (((SSHHostType) registeredHost.getType()).getHpcResource()) {
                AuthenticationInfo authenticationInfo = null;
                // we give higher preference to the password over keypair ssh authentication
                if (sshPassword != null) {
                    authenticationInfo = new DefaultPasswordAuthenticationInfo(sshPassword);
                } else {
                    authenticationInfo = new DefaultPublicKeyFileAuthentication(sshPublicKey, sshPrivateKey, sshPrivateKeyPass);
                }
                ServerInfo serverInfo = new ServerInfo(sshUserName, registeredHost.getType().getHostAddress());

                Cluster pbsCluster = null;
                try {
                    pbsCluster = new PBSCluster(serverInfo, authenticationInfo,
                            (((HpcApplicationDeploymentType) jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType()).getInstalledParentPath()));
                } catch (SSHApiException e) {
                    e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
                }
                sshSecurityContext.setPbsCluster(pbsCluster);
                sshSecurityContext.setUsername(sshUserName);
            } else {
                sshSecurityContext = new SSHSecurityContext();
                sshSecurityContext.setUsername(sshUserName);
                sshSecurityContext.setPrivateKeyLoc(sshPrivateKey);
                sshSecurityContext.setKeyPass(sshPrivateKeyPass);
            }
            jobExecutionContext.addSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT, sshSecurityContext);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.airavata.gfac.context.security.SSHSecurityContext

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.