Package org.apache.airavata.core.gfac.context.invocation.impl

Examples of org.apache.airavata.core.gfac.context.invocation.impl.DefaultInvocationContext


        try {
            URL url = this.getClass().getClassLoader().getResource(GRAM_PROPERTIES);
            Properties properties = new Properties();
            properties.load(url.openStream());

            DefaultInvocationContext ct = new DefaultInvocationContext();
            DefaultExecutionContext ec = new DefaultExecutionContext();
            ec.addNotifiable(new LoggingNotification());
            ec.setRegistryService(jcrRegistry);
            ct.setExecutionContext(ec);


            GSISecurityContext gsiSecurityContext = new GSISecurityContext();
            gsiSecurityContext.setMyproxyServer(properties.getProperty("myproxy.server"));
            gsiSecurityContext.setMyproxyUserName(properties.getProperty("myproxy.username"));
            gsiSecurityContext.setMyproxyPasswd(properties.getProperty("myproxy.password"));
            gsiSecurityContext.setMyproxyLifetime(14400);
            gsiSecurityContext.setTrustedCertLoc(properties.getProperty("ca.certificates.directory"));

            ct.addSecurityContext(MYPROXY, gsiSecurityContext);

            ct.setServiceName("MockPwscfMPIService");

            /* Input */
            ParameterContextImpl input = new ParameterContextImpl();
            ActualParameter echo_input = new ActualParameter();
            ((StringParameterType) echo_input.getType()).setValue("echo_mpi_output=hi");
            input.add("echo_mpi_input", echo_input);

            /* Output */
            ParameterContextImpl output = new ParameterContextImpl();
            ActualParameter echo_output = new ActualParameter();
            output.add("echo_mpi_output", echo_output);

            /* parameter */
            ct.setInput(input);
            ct.setOutput(output);

            PropertiesBasedServiceImpl service = new PropertiesBasedServiceImpl();
            service.init();
            service.execute(ct);

            System.out.println("output              : " + ct.getOutput().toString());
            System.out.println("output from service : " + ct.getOutput().getValue("echo_mpi_output"));

            Assert.assertNotNull(ct.getOutput());

        } catch (Exception e) {
            e.printStackTrace();
            fail("ERROR");
        }
View Full Code Here


        try {
            URL url = this.getClass().getClassLoader().getResource(GRAM_PROPERTIES);
            Properties properties = new Properties();
            properties.load(url.openStream());

            DefaultInvocationContext ct = new DefaultInvocationContext();
            DefaultExecutionContext ec = new DefaultExecutionContext();
            ec.addNotifiable(new LoggingNotification());
            ct.setExecutionContext(ec);


            GSISecurityContext gsiSecurityContext = new GSISecurityContext();
            gsiSecurityContext.setMyproxyServer(properties.getProperty("myproxy.server"));
            gsiSecurityContext.setMyproxyUserName(properties.getProperty("myproxy.username"));
            gsiSecurityContext.setMyproxyPasswd(properties.getProperty("myproxy.password"));
            gsiSecurityContext.setMyproxyLifetime(14400);
            gsiSecurityContext.setTrustedCertLoc(properties.getProperty("certificate.path"));

            ct.addSecurityContext(MYPROXY, gsiSecurityContext);

            ct.setServiceName("SimpleEcho");

            /*
            * Input
            */
            ParameterContextImpl input = new ParameterContextImpl();
            ActualParameter echo_input = new ActualParameter();
            ((StringParameterType) echo_input.getType()).setValue("echo_output=hello");
            input.add("echo_input", echo_input);

            /*
            * Output
            */
            ParameterContextImpl output = new ParameterContextImpl();
            ActualParameter echo_output = new ActualParameter();
            output.add("echo_output", echo_output);

            // parameter
            ct.setInput(input);
            ct.setOutput(output);

            PropertiesBasedServiceImpl service = new PropertiesBasedServiceImpl();
            service.init();
            service.execute(ct);

            Assert.assertNotNull(ct.getOutput());
            Assert.assertNotNull(ct.getOutput().getValue("echo_output"));
            Assert.assertEquals("hello", ((StringParameterType) ((ActualParameter) ct.getOutput().getValue("echo_output")).getType()).getValue());


        } catch (Exception e) {
            e.printStackTrace();
            fail("ERROR");
View Full Code Here

            /*
             * Add notifiable object
             */
            WorkflowTrackingNotification workflowNotification = new WorkflowTrackingNotification(brokerURL, topic);
            LoggingNotification loggingNotification = new LoggingNotification();
            DefaultInvocationContext invocationContext = new DefaultInvocationContext();
            invocationContext.setExecutionContext(new DefaultExecutionContext());
            invocationContext.setServiceName(serviceName);
            invocationContext.getExecutionContext().setRegistryService(getRegistry(context));
            invocationContext.getExecutionContext().setSecurityContextHeader(getHeader(messageContext));
            invocationContext.getExecutionContext().addNotifiable(workflowNotification);
            invocationContext.getExecutionContext().addNotifiable(loggingNotification);

            GSISecurityContext gssContext = new GSISecurityContext();
            SecurityContextDocument parse =
                    SecurityContextDocument.Factory.parse(getHeader(messageContext).getFirstChildWithName
                            (new QName("http://schemas.airavata.apache.org/workflow-execution-context", "security-context")).toStringWithConsume());
            SecurityContextDocument.SecurityContext.GridMyproxyRepository gridMyproxyRepository = parse.getSecurityContext().getGridMyproxyRepository();
            if (gridMyproxyRepository==null){
              gssContext.setMyproxyPasswd((String)messageContext.getConfigurationContext().getProperty(MYPROXY_PASS));
                gssContext.setMyproxyUserName((String)messageContext.getConfigurationContext().getProperty(MYPROXY_USER));
                gssContext.setMyproxyLifetime(Integer.parseInt(messageContext.getConfigurationContext().getProperty(MYPROXY_LIFE).toString()));
                gssContext.setMyproxyServer((String)messageContext.getConfigurationContext().getProperty(MYPROXY_SERVER))
            }else{
              gssContext.setMyproxyPasswd(gridMyproxyRepository.getPassword());
              gssContext.setMyproxyUserName(gridMyproxyRepository.getUsername());
              gssContext.setMyproxyLifetime(gridMyproxyRepository.getLifeTimeInhours());
              gssContext.setMyproxyServer(gridMyproxyRepository.getMyproxyServer());
            }
            gssContext.setTrustedCertLoc((String)messageContext.getConfigurationContext().getProperty(TRUSTED_CERT_LOCATION));
           
            invocationContext.addSecurityContext("myproxy",gssContext);

            /*
             * Add workflow context
             */
            WorkflowContextImpl workflowContext = new WorkflowContextImpl();
            workflowContext.setValue(WorkflowContextImpl.WORKFLOW_ID, URI.create(topic).toString());
            invocationContext.addMessageContext(WorkflowContextImpl.WORKFLOW_CONTEXT_NAME, workflowContext);

            /*
             * read from registry and set the correct parameters
             */
            ServiceDescription serviceDescription = getRegistry(context).getServiceDescription(serviceName);

            /*
             * Input
             */
            ParameterContextImpl inputParam = new ParameterContextImpl();
            ServiceDescriptionType serviceDescriptionType = serviceDescription.getType();

            for (Parameter parameter : serviceDescriptionType.getInputParametersArray()) {
                OMElement element = input.getFirstChildWithName(new QName(null,parameter.getParameterName()));
                if (element == null) {
                    throw new Exception("Parameter is not found in the message");
                }
                //todo this implementation doesn't work when there are n number of nodes connecting .. need to fix

//                String xmlContent = "";
//                if(!element.getChildElements().hasNext()){
//                    xmlContent = "<type:GFacParameter xsi:type=\"type:" + MappingFactory.getActualParameterType(parameter.getParameterType().getType())
//                        +"\" xmlns:type=\"http://schemas.airavata.apache.org/gfac/type\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + element.getText() + "</type:GFacParameter>";
//                }else{
//                    xmlContent = "<type:GFacParameter xsi:type=\"type:" + MappingFactory.getActualParameterType(parameter.getParameterType().getType())
//                            +"\" xmlns:type=\"http://schemas.airavata.apache.org/gfac/type\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + element.toStringWithConsume() + "</type:GFacParameter>";
//                }
//                System.out.println(xmlContent);
//                inputParam.add(parameter.getParameterName(),ActualParameter.fromXML(xmlContent));

                ActualParameter actualParameter = getInputActualParameter(parameter, element);
                inputParam.add(parameter.getParameterName(),actualParameter);
            }

            /*
             * Output
             */
            ParameterContextImpl outputParam = new ParameterContextImpl();


            // List<Parameter> outputs = serviceDescription.getOutputParameters();
            for (OutputParameterType parameter : serviceDescriptionType.getOutputParametersArray()) {
                ActualParameter actualParameter = new ActualParameter();
                if("String".equals(parameter.getParameterType().getName())){
                   actualParameter.getType().changeType(StringParameterType.type);
                }else if("Double".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(DoubleParameterType.type);
                }else if("Integer".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(IntegerParameterType.type);
                }else if("Float".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(FloatParameterType.type);
                }else if("Boolean".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(BooleanParameterType.type);
                }else if("File".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(FileParameterType.type);
                }else if("URI".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(URIParameterType.type);
                }else if("StringArray".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(StringArrayType.type);
                }else if("DoubleArray".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(DoubleArrayType.type);
                }else if("IntegerArray".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(IntegerArrayType.type);
                }else if("FloatArray".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(FloatArrayType.type);
                }else if("BooleanArray".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(BooleanArrayType.type);
                }else if("FileArray".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(FileArrayType.type);
                }else if("URIArray".equals(parameter.getParameterType().getName())){
                    actualParameter.getType().changeType(URIArrayType.type);
                }
                outputParam.add(parameter.getParameterName(), new ActualParameter());
            }

            invocationContext.setInput(inputParam);
            invocationContext.setOutput(outputParam);

            if (service == null) {
                service = new PropertyServiceFactory(GFacService.REPOSITORY_PROPERTIES).createService();
            }
            // invoke service
            service.execute(invocationContext);

            /*
             * Process Output
             */
            OMFactory fac = OMAbstractFactory.getOMFactory();
            OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2/xsd", "ns1");
            outputElement = fac.createOMElement("invokeResponse", omNs);

            ParameterContextImpl paramContext = (ParameterContextImpl) invocationContext
                    .<ActualParameter> getMessageContext("output");
            for (Iterator<String> iterator = paramContext.getNames(); iterator.hasNext();) {
                String name = iterator.next();
                String outputString = paramContext.getValue(name).toXML().replaceAll("GFacParameter", name);
                XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(outputString));
View Full Code Here

  @Test
  public void testExecute() {
    try {

      DefaultInvocationContext ct = new DefaultInvocationContext();
      DefaultExecutionContext ec = new DefaultExecutionContext();
      ec.addNotifiable(new LoggingNotification());
      ct.setExecutionContext(ec);

      ct.setServiceName("SimpleEcho");

      /*
       * Input
       */     
      ParameterContextImpl input = new ParameterContextImpl();
      ActualParameter echo_input = new ActualParameter();
      ((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
      input.add("echo_input", echo_input);

      /*
       * Output
       */
      ParameterContextImpl output = new ParameterContextImpl();
      ActualParameter echo_output = new ActualParameter();
      output.add("echo_output", echo_output);

      // parameter
      ct.setInput(input);
      ct.setOutput(output);

      PropertiesBasedServiceImpl service = new PropertiesBasedServiceImpl();
      service.init();
      service.execute(ct);

      Assert.assertNotNull(ct.getOutput());
      Assert.assertNotNull(ct.getOutput().getValue("echo_output"));
      Assert.assertEquals("hello", ((StringParameterType)((ActualParameter)ct.getOutput().getValue("echo_output")).getType()).getValue());

    } catch (Exception e) {
      e.printStackTrace();
      fail("ERROR");
    }
View Full Code Here

  @Test
  public void testExecute() {
    try {

      DefaultInvocationContext ct = new DefaultInvocationContext();
      DefaultExecutionContext ec = new DefaultExecutionContext();
      ec.addNotifiable(new LoggingNotification());
      ct.setExecutionContext(ec);

      ct.setServiceName("SimpleEcho");

      /*
       * Input
       */
      ParameterContextImpl input = new ParameterContextImpl();
      ActualParameter echo_input = new ActualParameter();
      ((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
      input.add("echo_input", echo_input);

      /*
       * Output
       */
      ParameterContextImpl output = new ParameterContextImpl();
      ActualParameter echo_output = new ActualParameter();
      output.add("echo_output", echo_output);

      // parameter
      ct.setInput(input);
      ct.setOutput(output);
            ct.getExecutionContext().setRegistryService(jcrRegistry);
            Scheduler scheduler = new SchedulerImpl();
            Provider provider = scheduler.schedule(ct);


              if(provider instanceof GramProvider){
View Full Code Here

        String workflowNodeId = WorkflowContextHeaderBuilder.getCurrentContextHeader().getWorkflowMonitoringContext().getWorkflowNodeId();
        String workflowInstanceId = WorkflowContextHeaderBuilder.getCurrentContextHeader().getWorkflowMonitoringContext().getWorkflowInstanceId();
        WorkflowTrackingNotification workflowNotification = new WorkflowTrackingNotification(jobContext.getBrokerURL(),
                jobContext.getTopic(),workflowNodeId,workflowInstanceId);
        LoggingNotification loggingNotification = new LoggingNotification();
        DefaultInvocationContext invocationContext = new DefaultInvocationContext();
        invocationContext.setExecutionContext(new DefaultExecutionContext());
        invocationContext.setServiceName(jobContext.getServiceName());
        invocationContext.getExecutionContext().setRegistryService(gfacConfig.getRegistry());
        invocationContext.getExecutionContext().addNotifiable(workflowNotification);
        invocationContext.getExecutionContext().addNotifiable(loggingNotification);

        GSISecurityContext gssContext = new GSISecurityContext();
//        if (gridMyproxyRepository == null) {
            gssContext.setMyproxyPasswd(gfacConfig.getMyProxyPassphrase());
            gssContext.setMyproxyUserName(gfacConfig.getMyProxyUser());
            gssContext.setMyproxyLifetime(gfacConfig.getMyProxyLifeCycle());
            gssContext.setMyproxyServer(gfacConfig.getMyProxyServer());
//        } else {
//            gssContext.setMyproxyPasswd(gridMyproxyRepository.getPassword());
//            gssContext.setMyproxyUserName(gridMyproxyRepository.getUsername());
//            gssContext.setMyproxyLifetime(gridMyproxyRepository.getLifeTimeInhours());
//            gssContext.setMyproxyServer(gridMyproxyRepository.getMyproxyServer());
//        }
        gssContext.setTrustedCertLoc(gfacConfig.getTrustedCertLocation());

        invocationContext.addSecurityContext("myproxy", gssContext);

        /*
    * Add workflow context
    */
        ServiceDescription serviceDescription = gfacConfig.getRegistry().getServiceDescription(jobContext.getServiceName());
        ServiceDescriptionType serviceDescriptionType = serviceDescription.getType();
        ParameterContextImpl inputParam = new ParameterContextImpl();
        WorkflowContextImpl workflowContext = new WorkflowContextImpl();
        workflowContext.setValue(WorkflowContextImpl.WORKFLOW_ID, URI.create(jobContext.getTopic()).toString());
        invocationContext.addMessageContext(WorkflowContextImpl.WORKFLOW_CONTEXT_NAME, workflowContext);
        for(Parameter parameter:jobContext.getParameters().keySet()){
            inputParam.add(parameter.getParameterName(), jobContext.getParameters().get(parameter));
        }

        /*
    * Output
    */
        ParameterContextImpl outputParam = new ParameterContextImpl();


        // List<Parameter> outputs = serviceDescription.getOutputParameters();
        for (OutputParameterType parameter : serviceDescriptionType.getOutputParametersArray()) {
            ActualParameter actualParameter = new ActualParameter();
            if ("String".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(StringParameterType.type);
            } else if ("Double".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(DoubleParameterType.type);
            } else if ("Integer".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(IntegerParameterType.type);
            } else if ("Float".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(FloatParameterType.type);
            } else if ("Boolean".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(BooleanParameterType.type);
            } else if ("File".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(FileParameterType.type);
            } else if ("URI".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(URIParameterType.type);
            } else if ("StringArray".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(StringArrayType.type);
            } else if ("DoubleArray".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(DoubleArrayType.type);
            } else if ("IntegerArray".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(IntegerArrayType.type);
            } else if ("FloatArray".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(FloatArrayType.type);
            } else if ("BooleanArray".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(BooleanArrayType.type);
            } else if ("FileArray".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(FileArrayType.type);
            } else if ("URIArray".equals(parameter.getParameterType().getName())) {
                actualParameter.getType().changeType(URIArrayType.type);
            }
            outputParam.add(parameter.getParameterName(), actualParameter);
        }

        invocationContext.setInput(inputParam);
        invocationContext.setOutput(outputParam);
        GenericService service = new PropertyServiceFactory(GfacAPI.REPOSITORY_PROPERTIES).createService();
        service.execute(invocationContext);
        return invocationContext;
    }
View Full Code Here

                throw new Exception("Parameter is not found in the message");
            }
            //todo this implementation doesn't work when there are n number of nodes connecting .. need to fix
            actualParameters.put(parameter, GfacUtils.getInputActualParameter(parameter, element));
        }
        DefaultInvocationContext invocationContext = null;
        JobContext jobContext = new JobContext(actualParameters,topic,serviceName,brokerURL);
        if(document.getContextHeader().getSecurityContext().getAmazonWebservices() != null){
//            invocationContext.getExecutionContext().setSecurityContextHeader(header);
            //todo if there's amazoneWebServices context we need to set that value, this will refer in EC2Provider
        }else{
            invocationContext = gfacAPI.gridJobSubmit(jobContext,(GFacConfiguration)context.getProperty(GFacService.GFAC_CONFIGURATION));
        }
        try {
            /*
             * Add notifiable object
             */

            ParameterContextImpl outputParamContext = (ParameterContextImpl) invocationContext
                    .<ActualParameter> getMessageContext("output");
            /*
             * Process Output
             */
            OMFactory fac = OMAbstractFactory.getOMFactory();
View Full Code Here

  @Test
  public void testExecute() {
    try {

      DefaultInvocationContext ct = new DefaultInvocationContext();
      DefaultExecutionContext ec = new DefaultExecutionContext();
      ec.addNotifiable(new LoggingNotification());
      ct.setExecutionContext(ec);
             Map<String,String> config = new HashMap<String,String>();
            config.put("org.apache.jackrabbit.repository.home","target");
        AiravataJCRRegistry jcrRegistry = new AiravataJCRRegistry(null,
        "org.apache.jackrabbit.core.RepositoryFactoryImpl", "admin",
        "admin", config);

            ec.setRegistryService(jcrRegistry);
      ct.setServiceName("SimpleEcho");

      /*
       * Input
       */     
      ParameterContextImpl input = new ParameterContextImpl();
      ActualParameter echo_input = new ActualParameter();
      ((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
      input.add("echo_input", echo_input);

      /*
       * Output
       */
      ParameterContextImpl output = new ParameterContextImpl();
      ActualParameter echo_output = new ActualParameter();
      output.add("echo_output", echo_output);

      // parameter
      ct.setInput(input);
      ct.setOutput(output);

      PropertiesBasedServiceImpl service = new PropertiesBasedServiceImpl();
      service.init();
      service.execute(ct);

      Assert.assertNotNull(ct.getOutput());
      Assert.assertNotNull(ct.getOutput().getValue("echo_output"));
      Assert.assertEquals("hello", ((StringParameterType)((ActualParameter)ct.getOutput().getValue("echo_output")).getType()).getValue());

    } catch (Exception e) {
      e.printStackTrace();
      fail("ERROR");
    }
View Full Code Here

  @Test
  public void testExecute() {
    try {

      DefaultInvocationContext ct = new DefaultInvocationContext();
      DefaultExecutionContext ec = new DefaultExecutionContext();
      ec.addNotifiable(new LoggingNotification());
      ct.setExecutionContext(ec);

      ct.setServiceName("SimpleEcho");

      /*
       * Input
       */
      ParameterContextImpl input = new ParameterContextImpl();
      ActualParameter echo_input = new ActualParameter();
      ((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
      input.add("echo_input", echo_input);

      /*
       * Output
       */
      ParameterContextImpl output = new ParameterContextImpl();
      ActualParameter echo_output = new ActualParameter();
      output.add("echo_output", echo_output);

      // parameter
      ct.setInput(input);
      ct.setOutput(output);
            ct.getExecutionContext().setRegistryService(jcrRegistry);
            Scheduler scheduler = new SchedulerImpl();
            Provider provider = scheduler.schedule(ct);


              if(provider instanceof GramProvider){
View Full Code Here

TOP

Related Classes of org.apache.airavata.core.gfac.context.invocation.impl.DefaultInvocationContext

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.