Repository: airavata Updated Branches: refs/heads/master 18ee7cd24 -> 832a7151f
throw exception from AiravataClientFactory when unable to create a client + refactor integration tests Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/832a7151 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/832a7151 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/832a7151 Branch: refs/heads/master Commit: 832a7151f2f3427dc56a75207fbb7d4a1d7aa5c1 Parents: 18ee7cd Author: Saminda Wijeratne <[email protected]> Authored: Fri Apr 18 18:57:10 2014 -0700 Committer: Saminda Wijeratne <[email protected]> Committed: Fri Apr 18 18:57:10 2014 -0700 ---------------------------------------------------------------------- .../api/client/AiravataClientFactory.java | 6 +- .../error/AiravataClientConnectException.java | 32 +++++++++ .../airavata/integration/SimpleEchoIT.java | 12 ++-- .../SingleAppIntegrationTestBase.java | 75 ++++++++------------ .../WorkflowIntegrationTestBase.java | 29 ++++---- 5 files changed, 88 insertions(+), 66 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/832a7151/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/client/AiravataClientFactory.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/client/AiravataClientFactory.java b/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/client/AiravataClientFactory.java index ec5b45d..c4274d9 100644 --- a/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/client/AiravataClientFactory.java +++ b/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/client/AiravataClientFactory.java @@ -22,6 +22,7 @@ package org.apache.airavata.api.client; import org.apache.airavata.api.Airavata; +import org.apache.airavata.api.error.AiravataClientConnectException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; @@ -34,15 +35,14 @@ public class AiravataClientFactory { private final static Logger logger = LoggerFactory.getLogger(AiravataClientFactory.class); - public static Airavata.Client createAiravataClient(String serverHost, int serverPort){ + public static Airavata.Client createAiravataClient(String serverHost, int serverPort) throws AiravataClientConnectException{ try { TTransport transport = new TSocket(serverHost, serverPort); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); return new Airavata.Client(protocol); } catch (TTransportException e) { - logger.error("Unable to connect to the server at "+serverHost+":"+serverPort); + throw new AiravataClientConnectException("Unable to connect to the server at "+serverHost+":"+serverPort); } - return null; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/832a7151/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/error/AiravataClientConnectException.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/error/AiravataClientConnectException.java b/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/error/AiravataClientConnectException.java new file mode 100644 index 0000000..8c68641 --- /dev/null +++ b/airavata-api/airavata-api-stubs/src/main/java/org/apache/airavata/api/error/AiravataClientConnectException.java @@ -0,0 +1,32 @@ +/* + * + * 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.api.error; + +public class AiravataClientConnectException extends Exception { + + private static final long serialVersionUID = 430165455326177755L; + + public AiravataClientConnectException(String message) { + super(message); + } + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/832a7151/modules/integration-tests/src/test/java/org/apache/airavata/integration/SimpleEchoIT.java ---------------------------------------------------------------------- diff --git a/modules/integration-tests/src/test/java/org/apache/airavata/integration/SimpleEchoIT.java b/modules/integration-tests/src/test/java/org/apache/airavata/integration/SimpleEchoIT.java index 2360c70..1414dfe 100644 --- a/modules/integration-tests/src/test/java/org/apache/airavata/integration/SimpleEchoIT.java +++ b/modules/integration-tests/src/test/java/org/apache/airavata/integration/SimpleEchoIT.java @@ -51,7 +51,9 @@ public class SimpleEchoIT extends SingleAppIntegrationTestBase { @Test public void testSimpleLocalhostEchoService() throws Exception { - log.info("Running job in localhost..."); + log.info("Running job in localhost"); + log.info("========================\n"); + log.info("Adding applications..."); DocumentCreator documentCreator = new DocumentCreator(airavataAPI); documentCreator.createLocalHostDocs(); @@ -81,16 +83,16 @@ public class SimpleEchoIT extends SingleAppIntegrationTestBase { userConfigurationData.setComputationalResourceScheduling(scheduling); simpleExperiment.setUserConfigurationData(userConfigurationData); + log.info("Creating experiment..."); final String expId = createExperiment(simpleExperiment); - System.out.println("Experiment Id returned : " + expId); - log.info("Experiment Id returned : " + expId); launchExperiment(expId); - System.out.println("Launched successfully"); - + log.info("Experiment launched successfully\n"); + log.info("Monitoring job in localhost"); + log.info("===========================\n"); monitorJob(expId); } http://git-wip-us.apache.org/repos/asf/airavata/blob/832a7151/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java ---------------------------------------------------------------------- diff --git a/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java b/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java index 6592bf8..41e4dd8 100644 --- a/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java +++ b/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java @@ -21,8 +21,7 @@ package org.apache.airavata.integration; import java.io.IOException; -import java.util.Map; -import java.util.Set; +import java.util.Date; import org.apache.airavata.api.Airavata; import org.apache.airavata.api.client.AiravataClientFactory; @@ -33,12 +32,10 @@ import org.apache.airavata.api.error.InvalidRequestException; 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.utils.AiravataUtils; -import org.apache.airavata.common.utils.ApplicationSettings; import org.apache.airavata.common.utils.ClientSettings; import org.apache.airavata.model.workspace.experiment.Experiment; -import org.apache.airavata.model.workspace.experiment.JobState; -import org.apache.airavata.model.workspace.experiment.JobStatus; +import org.apache.airavata.model.workspace.experiment.ExperimentState; +import org.apache.airavata.model.workspace.experiment.ExperimentStatus; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,31 +87,19 @@ public class SingleAppIntegrationTestBase { * */ protected void initClient() throws Exception { int tries = 0; - - while (true) { - - if (tries == TRIES) { - log("Server not responding. Cannot continue with integration tests ..."); - throw new Exception("Server not responding !"); - } - - log("Checking if the server has started, try - " + tries); - + while (client==null) { + log.info("Waiting till server initializes ........[try "+ (++tries) + " of "+TRIES+"]"); try { - this.client = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT); - } catch (Exception e) { - - } - if (this.client == null) { - log.info("Waiting till server initializes ........"); - Thread.sleep(TIME_OUT); - } else { - break; + client = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT); + } catch (Exception e) { + if (tries == TRIES) { + log("Server not responding. Cannot continue with integration tests ..."); + throw e; + } else { + Thread.sleep(TIME_OUT); + } } - - ++tries; } - } protected String createExperiment(Experiment experiment) throws AiravataSystemException, InvalidRequestException, AiravataClientException, TException { @@ -133,26 +118,24 @@ public class SingleAppIntegrationTestBase { protected void monitorJob(final String expId) { Thread monitor = (new Thread() { public void run() { - Map<String, JobStatus> jobStatuses = null; + long previousUpdateTime=-1; while (true) { try { - System.out.println("*********Experiment status*** : "+client.getExperimentStatus(expId)); - jobStatuses = client.getJobStatuses(expId); - Set<String> strings = jobStatuses.keySet(); - for (String key : strings) { - JobStatus jobStatus = jobStatuses.get(key); - if (jobStatus == null) { - return; - } else { - if (JobState.COMPLETE.equals(jobStatus.getJobState())) { - log.info("Job completed Job ID: " + key); - return; - } else { - log.info("Job ID:" + key + " Job Status : " + jobStatuses.get(key).getJobState().toString()); - } - } - } - Thread.sleep(5000); + ExperimentStatus experimentStatus = client.getExperimentStatus(expId); + if (previousUpdateTime!=experimentStatus.getTimeOfStateChange()) { + previousUpdateTime=experimentStatus.getTimeOfStateChange(); + log.info("Experiment ID:" + + expId + + " Status : " + + experimentStatus.getExperimentState() + .toString() + + "["+new Date(previousUpdateTime).toString()+"]"); + + } + if (experimentStatus.getExperimentState()==ExperimentState.COMPLETED){ + break; + } + Thread.sleep(2000); } catch (Exception e) { log.error("Thread interrupted", e.getMessage()); } http://git-wip-us.apache.org/repos/asf/airavata/blob/832a7151/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java ---------------------------------------------------------------------- diff --git a/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java b/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java index 6885cbc..f288a54 100644 --- a/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java +++ b/modules/integration-tests/src/test/java/org/apache/airavata/integration/WorkflowIntegrationTestBase.java @@ -21,8 +21,17 @@ package org.apache.airavata.integration; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.List; + import junit.framework.Assert; + +import org.apache.airavata.api.Airavata; import org.apache.airavata.api.client.AiravataClientFactory; +import org.apache.airavata.api.error.AiravataClientConnectException; import org.apache.airavata.api.error.AiravataClientException; import org.apache.airavata.api.error.AiravataSystemException; import org.apache.airavata.api.error.ExperimentNotFoundException; @@ -38,10 +47,13 @@ import org.apache.airavata.common.utils.StringUtil; 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.api.Airavata; import org.apache.airavata.model.workspace.experiment.Experiment; import org.apache.airavata.registry.api.impl.WorkflowExecutionDataImpl; -import org.apache.airavata.registry.api.workflow.*; +import org.apache.airavata.registry.api.workflow.ExperimentData; +import org.apache.airavata.registry.api.workflow.InputData; +import org.apache.airavata.registry.api.workflow.NodeExecutionData; +import org.apache.airavata.registry.api.workflow.OutputData; +import org.apache.airavata.registry.api.workflow.WorkflowNodeType; import org.apache.airavata.workflow.model.component.ComponentException; import org.apache.airavata.workflow.model.graph.GraphException; import org.apache.airavata.workflow.model.wf.Workflow; @@ -50,13 +62,6 @@ import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.net.URI; -import java.util.List; - /** * Since most of the workflow integration tests have common functionality to register, start and monitor workflows, this * class will act as the aggregation of those methods. @@ -89,7 +94,7 @@ public abstract class WorkflowIntegrationTestBase { log.info(message); } - public Airavata.Client getClient() { + public Airavata.Client getClient() throws AiravataClientConnectException { if (client == null){ client = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT); } @@ -218,11 +223,11 @@ public abstract class WorkflowIntegrationTestBase { // // } - protected String createExperiment (Experiment experiment) throws AiravataSystemException, InvalidRequestException, AiravataClientException, TException { + protected String createExperiment (Experiment experiment) throws AiravataSystemException, InvalidRequestException, AiravataClientException, TException, AiravataClientConnectException { return getClient().createExperiment(experiment); } - protected void launchExperiment (String expId) throws ExperimentNotFoundException, AiravataSystemException, InvalidRequestException, AiravataClientException, TException { + protected void launchExperiment (String expId) throws ExperimentNotFoundException, AiravataSystemException, InvalidRequestException, AiravataClientException, TException, AiravataClientConnectException { getClient().launchExperiment(expId, "testToken"); }
