Package org.apache.airavata.schemas.gfac

Examples of org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType


            closeSession(session);
        }
    }

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

        // input parameter
        ArrayList<String> tmp = new ArrayList<String>();
        for (Iterator<String> iterator = context.getInput().getNames(); iterator.hasNext();) {
            String key = iterator.next();
            tmp.add(context.getInput().getStringValue(key));
        }

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

        /*
         * Builder Command
         */
        cmdList.add(app.getExecutableLocation());
        cmdList.addAll(tmp);

        // create process builder from command
        command = InputUtils.buildCommand(cmdList);

        // redirect StdOut and StdErr
        // TODO: Make 1> and 2> into static constants.
        // TODO: This only works for the BASH shell. CSH and TCSH will be
        // different.
        command += SPACE + "1>" + SPACE + app.getStandardOutput();
        command += SPACE + "2>" + SPACE + app.getStandardError();
    }
View Full Code Here


        command += SPACE + "1>" + SPACE + app.getStandardOutput();
        command += SPACE + "2>" + SPACE + app.getStandardError();
    }

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

            closeSession(session);
        }
    }

    public Map<String, ?> processOutput(InvocationContext context) throws ProviderException {
        ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType();
        try {

            // Get the Stdouts and StdErrs
            String timeStampedServiceName = GfacUtils.createUniqueNameForService(context.getServiceName());
            File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout");
            File localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr");

            SCPFileTransfer fileTransfer = ssh.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());

            return OutputUtils.fillOutputFromStdout(context.<ActualParameter> getOutput(), stdOutStr,stdErrStr);
View Full Code Here

    private String jobId;
    private GSISecurityContext gssContext;

    public void makeDirectory(InvocationContext invocationContext) throws ProviderException {
        GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
        ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();

        GridFtp ftp = new GridFtp();

        try {
            gssContext = (GSISecurityContext)invocationContext.getSecurityContext(MYPROXY_SECURITY_CONTEXT);
            GSSCredential gssCred = gssContext.getGssCredentails();
            String[] hostgridFTP = host.getGridFTPEndPointArray();
            if (hostgridFTP == null || hostgridFTP.length == 0) {
                hostgridFTP = new String[] { host.getHostAddress() };
            }

            boolean success = false;
            ProviderException pe = null;// = new ProviderException("");

            for (String endpoint : host.getGridFTPEndPointArray()) {
                try {

                    URI tmpdirURI = GfacUtils.createGsiftpURI(endpoint, app.getScratchWorkingDirectory());
                    URI workingDirURI = GfacUtils.createGsiftpURI(endpoint, app.getStaticWorkingDirectory());
                    URI inputURI = GfacUtils.createGsiftpURI(endpoint, app.getInputDataDirectory());
                    URI outputURI = GfacUtils.createGsiftpURI(endpoint, app.getOutputDataDirectory());

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

    }

    public void executeApplication(InvocationContext invocationContext) throws ProviderException {
        GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
        ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();
        StringBuffer buf = new StringBuffer();
            /*
             * Set Security
             */
            securityProperties = initSecurityProperties();
            String factoryUrl = job.getFactoryUrl();
            EndpointReferenceType eprt = EndpointReferenceType.Factory
                    .newInstance();
            eprt.addNewAddress().setStringValue(factoryUrl);
            System.out.println("========================================");
            System.out.println(String.format("Job Submitted to %s.\n", factoryUrl));
            FactoryClient factory = null;
            try {
                factory = new FactoryClient(eprt, securityProperties);
            } catch (Exception e) {
                e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
            }
            CreateActivityDocument cad = CreateActivityDocument.Factory
                    .newInstance();
            cad.addNewCreateActivity().addNewActivityDocument()
                    .setJobDefinition(job.getJobDoc().getJobDefinition());
            CreateActivityResponseDocument response = null;
            try {
                response = factory.createActivity(cad);
            } catch (NotAcceptingNewActivitiesFault notAcceptingNewActivitiesFault) {
                notAcceptingNewActivitiesFault.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
            } catch (InvalidRequestMessageFault invalidRequestMessageFault) {
                invalidRequestMessageFault.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
            } catch (UnsupportedFeatureFault unsupportedFeatureFault) {
                unsupportedFeatureFault.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
            }
            EndpointReferenceType activityEpr = response
                    .getCreateActivityResponse().getActivityIdentifier();
            //factory.waitWhileActivityIsDone(activityEpr, 1000);
            jobId = WSUtilities.extractResourceID(activityEpr);
            if (jobId == null) {
                jobId = new Long(Calendar.getInstance().getTimeInMillis())
                        .toString();
            }
            ActivityStateEnumeration.Enum state = factory.getActivityStatus(activityEpr);

            String status;

            status = String.format("Job %s is %s.\n", activityEpr.getAddress()
                    .getStringValue(), factory.getActivityStatus(activityEpr)
                    .toString()).toString();


            while ((factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.FINISHED) &&
                    (factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.FAILED)){
                status = String.format("Job %s is %s.\n", activityEpr.getAddress()
                        .getStringValue(), factory.getActivityStatus(activityEpr)
                        .toString()).toString();
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
                }
                continue;
            }

            status = String.format("Job %s is %s.\n", activityEpr.getAddress()
                    .getStringValue(), factory.getActivityStatus(activityEpr)
                    .toString()).toString();

            log.debug("Request to contact:" + unicoreHost);

            buf.append("Finished launching job, Host = ").append(host.getHostAddress()).append(" JSDL = ")
                    .append(job.getJobDoc().toString()).append(" working directory = ").append(app.getStaticWorkingDirectory())
                    .append(" temp directory = ").append(app.getScratchWorkingDirectory())
                    .append(" Unicore Endpoint = ").append(unicoreHost);
            invocationContext.getExecutionContext().getNotifier().info(invocationContext, buf.toString());
            invocationContext.getExecutionContext().getNotifier().info(invocationContext, "JobID=" + jobId);
            log.debug(buf.toString());
    }
View Full Code Here

    return serv;
  }

  private ApplicationDescription createAppDeploymentDescription() {
    ApplicationDescription appDesc = new ApplicationDescription();
    ApplicationDeploymentDescriptionType app = appDesc.getType();
    ApplicationDeploymentDescriptionType.ApplicationName name = ApplicationDeploymentDescriptionType.ApplicationName.Factory
        .newInstance();
    name.setStringValue("EchoLocal");
    app.setApplicationName(name);
    app.setExecutableLocation("/bin/echo");
    app.setScratchWorkingDirectory("/tmp");
    app.setStaticWorkingDirectory("/tmp");
    app.setInputDataDirectory("/tmp/input");
    app.setOutputDataDirectory("/tmp/output");
    app.setStandardOutput("/tmp/echo.stdout");
    app.setStandardError("/tmp/echo.stdout");
    return appDesc;
  }
View Full Code Here

                             * src complete URI
                             */
                            File file = new File(uri.getPath());
                            String srcFilePath = file.getName();

                            ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp()
                                    .getType();
                            srcFilePath = app.getOutputDataDirectory() + File.separator + srcFilePath;

                            HostDescriptionType hostDescription = context.getExecutionDescription().getHost().getType();
                            if (hostDescription instanceof GlobusHostType) {
                                gridFTPTransfer(context, uri, srcFilePath);
                            } else if (GfacUtils.isLocalHost(hostDescription.getHostAddress())) {
View Full Code Here

                             * Desctination complete URI
                             */
                            File file = new File(uri.getPath());
                            String destFilePath = file.getName();

                            ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType();
                            destFilePath = app.getInputDataDirectory() + File.separator + destFilePath;

                            HostDescriptionType hostDescription = context.getExecutionDescription().getHost().getType();
                            if (hostDescription instanceof GlobusHostType) {
                                uploadToGridFTPFromHttp(context, uri, destFilePath);
                            } else {
View Full Code Here

                             * Destination complete URI
                             */
                            File file = new File(uri.getPath());
                            String destFilePath = file.getName();

                            ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType();
                            destFilePath = app.getInputDataDirectory() + File.separator + destFilePath;

                            HostDescriptionType hostDescription = context.getExecutionDescription().getHost().getType();
                            if (hostDescription instanceof GlobusHostType) {
                                gridFTPTransfer(context, uri, destFilePath);
                            } else if (GfacUtils.isLocalHost(hostDescription.getHostAddress())) {
View Full Code Here

    public boolean execute(InvocationContext context) throws ExtensionException {

        ServiceDescription serviceDesc = context.getExecutionDescription().getService();
        HostDescription hostDesc = context.getExecutionDescription().getHost();
        ApplicationDeploymentDescriptionType appDesc = context.getExecutionDescription().getApp().getType();
        if (serviceDesc != null && hostDesc != null && appDesc != null) {
            /*
             * if there is no setting in deployment description, use from host
             */
            if (appDesc.getScratchWorkingDirectory() == null) {
                appDesc.setScratchWorkingDirectory("/tmp");
            }

            /*
             * Working dir
             */
            if (appDesc.getStaticWorkingDirectory() == null || "null".equals(appDesc.getStaticWorkingDirectory())) {
                String date = new Date().toString();
                date = date.replaceAll(" ", "_");
                date = date.replaceAll(":", "_");

                String tmpDir = appDesc.getScratchWorkingDirectory() + File.separator
                        + serviceDesc.getType().getName() + "_" + date + "_" + UUID.randomUUID();

                appDesc.setStaticWorkingDirectory(tmpDir);
            }

            /*
             * Input and Output Directory
             */
            if (appDesc.getInputDataDirectory() == null || "".equals(appDesc.getInputDataDirectory()) ) {
                appDesc.setInputDataDirectory(appDesc.getStaticWorkingDirectory() + File.separator + "inputData");
            }
            if (appDesc.getOutputDataDirectory() == null || "".equals(appDesc.getOutputDataDirectory())) {
                appDesc.setOutputDataDirectory(appDesc.getStaticWorkingDirectory() + File.separator + "outputData");
            }

            /*
             * Stdout and Stderr for Shell
             */
            if (appDesc.getStandardOutput() == null || "".equals(appDesc.getStandardOutput())) {
                appDesc.setStandardOutput(appDesc.getStaticWorkingDirectory() + File.separator
                        + appDesc.getApplicationName().getStringValue() + ".stdout");
            }
            if (appDesc.getStandardError() == null || "".equals(appDesc.getStandardError())) {
                appDesc.setStandardError(appDesc.getStaticWorkingDirectory() + File.separator
                        + appDesc.getApplicationName().getStringValue() + ".stderr");
            }

        } else {
            throw new ExtensionException("Service Map for " + context.getServiceName()
                    + " does not found on resource Catalog " + context.getExecutionContext().getRegistryService());
View Full Code Here

TOP

Related Classes of org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType

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.