You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2014/01/14 21:58:18 UTC
svn commit: r1558188 - in
/airavata/trunk/modules/orchestrator/orchestrator-core/src:
main/java/org/apache/airavata/orchestrator/core/impl/
test/java/org/apache/airavata/orchestrator/core/
Author: lahiru
Date: Tue Jan 14 20:58:18 2014
New Revision: 1558188
URL: http://svn.apache.org/r1558188
Log:
adding another test case without sending descriptors along the request.
Added:
airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/SimpleOrchestratorTest.java
- copied, changed from r1558174, airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/PullBasedOrchestratorTest.java
airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/TestWithStoredDescriptors.java
Removed:
airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/PullBasedOrchestratorTest.java
Modified:
airavata/trunk/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/EmbeddedGFACJobSubmitter.java
Modified: airavata/trunk/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/EmbeddedGFACJobSubmitter.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/EmbeddedGFACJobSubmitter.java?rev=1558188&r1=1558187&r2=1558188&view=diff
==============================================================================
--- airavata/trunk/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/EmbeddedGFACJobSubmitter.java (original)
+++ airavata/trunk/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/EmbeddedGFACJobSubmitter.java Tue Jan 14 20:58:18 2014
@@ -22,6 +22,7 @@ package org.apache.airavata.orchestrator
import org.apache.airavata.client.api.AiravataAPI;
+import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
import org.apache.airavata.common.utils.AiravataJobState;
import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.commons.gfac.type.ApplicationDescription;
@@ -53,7 +54,9 @@ import javax.xml.xpath.XPathExpressionEx
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
/**
@@ -90,42 +93,75 @@ public class EmbeddedGFACJobSubmitter im
return true;
}
- private void launchGfacWithJobRequest(JobRequest jobRequest) throws RegistryException, ParserConfigurationException, IOException, SAXException, XPathExpressionException, GFacException {
- String serviceName = jobRequest.getServiceDescription().getType().getName();
+ private void launchGfacWithJobRequest(JobRequest jobRequest) throws OrchestratorException {
+ String serviceName = jobRequest.getServiceName();
+ if(serviceName == null){
+ serviceName = jobRequest.getServiceDescription().getType().getName();
+ }
+
+
//todo submit the jobs
//after successfully submitting the jobs set the status of the job to submitted
String experimentID = OrchestratorUtils.getUniqueID(jobRequest);
- orchestratorContext.getRegistry().changeStatus(experimentID, AiravataJobState.State.SUBMITTED);
- AiravataAPI airavataAPI = orchestratorContext.getOrchestratorConfiguration().getAiravataAPI();
- ServiceDescription serviceDescription = jobRequest.getServiceDescription();
-
- ApplicationDescription applicationDescription = jobRequest.getApplicationDescription();
-
- // When we run getInParameters we set the actualParameter object, this has to be fixed
- URL resource = EmbeddedGFACJobSubmitter.class.getClassLoader().getResource("gfac-config.xml");
- Properties configurationProperties = ServerSettings.getProperties();
- GFacConfiguration gFacConfiguration = GFacConfiguration.create(new File(resource.getPath()), airavataAPI, configurationProperties);
-
- JobExecutionContext jobExecutionContext = new JobExecutionContext(gFacConfiguration, serviceName);
- //Here we get only the contextheader information sent specific for this node
- //Add security context
-
-
- ApplicationContext applicationContext = new ApplicationContext();
- applicationContext.setApplicationDeploymentDescription(applicationDescription);
- applicationContext.setHostDescription(jobRequest.getHostDescription());
- applicationContext.setServiceDescription(serviceDescription);
+ AiravataAPI airavataAPI = null;
+ try {
- jobExecutionContext.setApplicationContext(applicationContext);
+ airavataAPI = orchestratorContext.getOrchestratorConfiguration().getAiravataAPI();
+ HostDescription hostDescription = jobRequest.getHostDescription();
+ if (hostDescription == null) {
+ List<HostDescription> registeredHosts = new ArrayList<HostDescription>();
+ Map<String, ApplicationDescription> applicationDescriptors = airavataAPI.getApplicationManager().getApplicationDescriptors(serviceName);
+ for (String hostDescName : applicationDescriptors.keySet()) {
+ registeredHosts.add(airavataAPI.getApplicationManager().getHostDescription(hostDescName));
+ }
+ Class<? extends HostScheduler> aClass = Class.forName(ServerSettings.getHostScheduler()).asSubclass(HostScheduler.class);
+ HostScheduler hostScheduler = aClass.newInstance();
+ hostDescription = hostScheduler.schedule(registeredHosts);
+ }
- jobExecutionContext.setOutMessageContext(new MessageContext(jobRequest.getOutputParameters()));
- jobExecutionContext.setInMessageContext(new MessageContext(jobRequest.getInputParameters()));
+ ServiceDescription serviceDescription = jobRequest.getServiceDescription();
+ if (serviceDescription == null) {
+ try {
+ serviceDescription = airavataAPI.getApplicationManager().getServiceDescription(jobRequest.getServiceName());
+ } catch (AiravataAPIInvocationException e) {
+ String error = "Error retrieving document from Registry: " + jobRequest.getServiceName();
+ throw new OrchestratorException(error, e);
+ }
+ }
- jobExecutionContext.setProperty(Constants.PROP_TOPIC, experimentID);
- jobExecutionContext.setExperimentID(experimentID);
- GFacAPI gfacAPI1 = new GFacAPI();
- gfacAPI1.submitJob(jobExecutionContext);
+ ApplicationDescription applicationDescription = jobRequest.getApplicationDescription();
+ if (applicationDescription == null) {
+ applicationDescription = airavataAPI.getApplicationManager().getApplicationDescription(serviceName, hostDescription.getType().getHostName());
+ }
+ // When we run getInParameters we set the actualParameter object, this has to be fixed
+ URL resource = EmbeddedGFACJobSubmitter.class.getClassLoader().getResource("gfac-config.xml");
+ Properties configurationProperties = ServerSettings.getProperties();
+ GFacConfiguration gFacConfiguration = GFacConfiguration.create(new File(resource.getPath()), airavataAPI, configurationProperties);
+
+ JobExecutionContext jobExecutionContext = new JobExecutionContext(gFacConfiguration, serviceName);
+ //Here we get only the contextheader information sent specific for this node
+ //Add security context
+
+
+ ApplicationContext applicationContext = new ApplicationContext();
+ applicationContext.setApplicationDeploymentDescription(applicationDescription);
+ applicationContext.setHostDescription(hostDescription);
+ applicationContext.setServiceDescription(serviceDescription);
+
+ jobExecutionContext.setApplicationContext(applicationContext);
+
+ jobExecutionContext.setOutMessageContext(new MessageContext(jobRequest.getOutputParameters()));
+ jobExecutionContext.setInMessageContext(new MessageContext(jobRequest.getInputParameters()));
+
+ jobExecutionContext.setProperty(Constants.PROP_TOPIC, experimentID);
+ jobExecutionContext.setExperimentID(experimentID);
+ GFacAPI gfacAPI1 = new GFacAPI();
+ gfacAPI1.submitJob(jobExecutionContext);
+ orchestratorContext.getRegistry().changeStatus(experimentID, AiravataJobState.State.SUBMITTED);
+ } catch (Exception e) {
+ throw new OrchestratorException("Error launching the Job", e);
+ }
}
public boolean directJobSubmit(JobRequest request) throws OrchestratorException {
Copied: airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/SimpleOrchestratorTest.java (from r1558174, airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/PullBasedOrchestratorTest.java)
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/SimpleOrchestratorTest.java?p2=airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/SimpleOrchestratorTest.java&p1=airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/PullBasedOrchestratorTest.java&r1=1558174&r2=1558188&rev=1558188&view=diff
==============================================================================
--- airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/PullBasedOrchestratorTest.java (original)
+++ airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/SimpleOrchestratorTest.java Tue Jan 14 20:58:18 2014
@@ -22,13 +22,13 @@ package org.apache.airavata.orchestrator
import junit.framework.Assert;
import org.apache.airavata.common.utils.AiravataUtils;
-import org.apache.airavata.common.utils.ExecutionMode;
import org.apache.airavata.commons.gfac.type.ActualParameter;
import org.apache.airavata.commons.gfac.type.ApplicationDescription;
import org.apache.airavata.commons.gfac.type.HostDescription;
import org.apache.airavata.commons.gfac.type.ServiceDescription;
import org.apache.airavata.registry.api.JobRequest;
import org.apache.airavata.schemas.gfac.*;
+import org.apache.tools.ant.taskdefs.Echo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeTest;
@@ -39,8 +39,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.UUID;
-public class PullBasedOrchestratorTest extends AbstractOrchestratorTest{
- private static final Logger log = LoggerFactory.getLogger(PullBasedOrchestratorTest.class);
+public class SimpleOrchestratorTest extends AbstractOrchestratorTest {
+ private static final Logger log = LoggerFactory.getLogger(SimpleOrchestratorTest.class);
private Orchestrator orchestrator;
@@ -60,14 +60,14 @@ public class PullBasedOrchestratorTest e
String systemExpID = orchestrator.createExperiment(experimentRequest);
- JobRequest jobRequest = createJobRequest(systemExpID);
+ JobRequest jobRequest = createJobRequestWithDocuments(systemExpID);
boolean b = orchestrator.launchExperiment(jobRequest);
- if(b){
+ if (b) {
// This means orchestrator successfully accepted the job
Assert.assertTrue(true);
- }else {
+ } else {
Assert.assertFalse(true);
}
}
@@ -80,18 +80,20 @@ public class PullBasedOrchestratorTest e
String systemExpID = orchestrator.createExperiment(experimentRequest);
- JobRequest jobRequest = createJobRequest(systemExpID);
+ JobRequest jobRequest = createJobRequestWithDocuments(systemExpID);
boolean b = orchestrator.launchExperiment(jobRequest);
- if(b){
+ if (b) {
// This means orchestrator successfully accepted the job
Assert.assertTrue(true);
- }else {
+ } else {
Assert.assertFalse(true);
}
}
- private JobRequest createJobRequest(String systemExpID) {
+
+
+ private JobRequest createJobRequestWithDocuments(String systemExpID) {
JobRequest jobRequest = new JobRequest();
// creating host description
@@ -154,6 +156,4 @@ public class PullBasedOrchestratorTest e
jobRequest.setOutputParameters(outputData);
return jobRequest;
}
-
-
}
Added: airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/TestWithStoredDescriptors.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/TestWithStoredDescriptors.java?rev=1558188&view=auto
==============================================================================
--- airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/TestWithStoredDescriptors.java (added)
+++ airavata/trunk/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/TestWithStoredDescriptors.java Tue Jan 14 20:58:18 2014
@@ -0,0 +1,177 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+package org.apache.airavata.orchestrator.core;
+
+import junit.framework.Assert;
+import org.apache.airavata.client.AiravataAPIFactory;
+import org.apache.airavata.client.api.AiravataAPI;
+import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.ApplicationDescription;
+import org.apache.airavata.commons.gfac.type.HostDescription;
+import org.apache.airavata.commons.gfac.type.ServiceDescription;
+import org.apache.airavata.registry.api.JobRequest;
+import org.apache.airavata.schemas.gfac.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
+
+public class TestWithStoredDescriptors extends AbstractOrchestratorTest {
+ private static final Logger log = LoggerFactory.getLogger(SimpleOrchestratorTest.class);
+
+ private Orchestrator orchestrator;
+
+ @BeforeTest
+ public void setUp() throws Exception {
+ AiravataUtils.setExecutionAsServer();
+ super.setUp();
+ orchestrator = new PullBasedOrchestrator();
+ orchestrator.initialize();
+ createJobRequestWithDocuments(getAiravataAPI());
+ }
+
+ private void createJobRequestWithDocuments(AiravataAPI airavataAPI) {
+ // creating host description
+ HostDescription descriptor = new HostDescription();
+ descriptor.getType().setHostName("localhost");
+ descriptor.getType().setHostAddress("127.0.0.1");
+ try {
+ airavataAPI.getApplicationManager().saveHostDescription(descriptor);
+ } catch (AiravataAPIInvocationException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+ ServiceDescription serviceDescription = new ServiceDescription();
+ List<InputParameterType> inputParameters = new ArrayList<InputParameterType>();
+ List<OutputParameterType> outputParameters = new ArrayList<OutputParameterType>();
+ serviceDescription.getType().setName("Echo");
+ serviceDescription.getType().setDescription("Echo service");
+ // Creating input parameters
+ InputParameterType parameter = InputParameterType.Factory.newInstance();
+ parameter.setParameterName("echo_input");
+ parameter.setParameterDescription("echo input");
+ ParameterType parameterType = parameter.addNewParameterType();
+ parameterType.setType(DataType.STRING);
+ parameterType.setName("String");
+ inputParameters.add(parameter);
+
+ // Creating output parameters
+ OutputParameterType outputParameter = OutputParameterType.Factory.newInstance();
+ outputParameter.setParameterName("echo_output");
+ outputParameter.setParameterDescription("Echo output");
+ ParameterType outputParaType = outputParameter.addNewParameterType();
+ outputParaType.setType(DataType.STRING);
+ outputParaType.setName("String");
+ outputParameters.add(outputParameter);
+
+ // Setting input and output parameters to serviceDescriptor
+ serviceDescription.getType().setInputParametersArray(inputParameters.toArray(new InputParameterType[]{}));
+ serviceDescription.getType().setOutputParametersArray(outputParameters.toArray(new OutputParameterType[]{}));
+
+ try {
+ airavataAPI.getApplicationManager().saveServiceDescription(serviceDescription);
+ } catch (AiravataAPIInvocationException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+ ApplicationDescription applicationDeploymentDescription = new ApplicationDescription();
+ ApplicationDeploymentDescriptionType applicationDeploymentDescriptionType = applicationDeploymentDescription
+ .getType();
+ applicationDeploymentDescriptionType.addNewApplicationName().setStringValue("EchoApplication");
+ applicationDeploymentDescriptionType.setExecutableLocation("/bin/echo");
+ applicationDeploymentDescriptionType.setScratchWorkingDirectory("/tmp");
+
+ try {
+ airavataAPI.getApplicationManager().saveApplicationDescription("Echo", "localhost", applicationDeploymentDescription);
+ } catch (AiravataAPIInvocationException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ @Test
+ public void noDescriptorTest() throws Exception {
+ ExperimentRequest experimentRequest = new ExperimentRequest();
+ experimentRequest.setUserExperimentID("test-" + UUID.randomUUID().toString());
+ experimentRequest.setUserName("orchestrator");
+
+ String systemExpID = orchestrator.createExperiment(experimentRequest);
+
+ JobRequest jobRequest = createJobRequestWithoutDocuments(systemExpID);
+
+
+ boolean b = orchestrator.launchExperiment(jobRequest);
+
+ if (b) {
+ // This means orchestrator successfully accepted the job
+ Assert.assertTrue(true);
+ } else {
+ Assert.assertFalse(true);
+ }
+ }
+
+
+ private JobRequest createJobRequestWithoutDocuments(String systemExpID) {
+ JobRequest jobRequest = new JobRequest();
+ jobRequest.setServiceName("Echo");
+
+ HashMap<String, Object> inputData = new HashMap<String, Object>();
+ ActualParameter echo_input = new ActualParameter();
+ ((StringParameterType) echo_input.getType()).setValue("echo_output=hello");
+ inputData.put("echo_input", echo_input);
+
+ HashMap<String, Object> outputData = new HashMap<String, Object>();
+
+
+ // setting all the parameters to jobRequest
+ jobRequest.setSystemExperimentID(systemExpID);
+ jobRequest.setInputParameters(inputData);
+ jobRequest.setOutputParameters(outputData);
+
+ return jobRequest;
+ }
+
+ private AiravataAPI getAiravataAPI() {
+ AiravataAPI airavataAPI = null;
+ if (airavataAPI == null) {
+ try {
+ String systemUserName = ServerSettings.getSystemUser();
+ String gateway = ServerSettings.getSystemUserGateway();
+ airavataAPI = AiravataAPIFactory.getAPI(gateway, systemUserName);
+ } catch (ApplicationSettingsException e) {
+ e.printStackTrace();
+ } catch (AiravataAPIInvocationException e) {
+ e.printStackTrace();
+ }
+ }
+ return airavataAPI;
+ }
+
+
+}