Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CA7C2105D6 for ; Mon, 8 Jul 2013 19:41:24 +0000 (UTC) Received: (qmail 9617 invoked by uid 500); 8 Jul 2013 19:41:24 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 9578 invoked by uid 500); 8 Jul 2013 19:41:24 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 9571 invoked by uid 99); 8 Jul 2013 19:41:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jul 2013 19:41:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,NORMAL_HTTP_TO_IP X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jul 2013 19:41:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 656A9238888A; Mon, 8 Jul 2013 19:41:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1500905 [1/2] - in /airavata/trunk/modules: airavata-client/ airavata-client/src/main/java/org/apache/airavata/client/ airavata-client/src/main/resources/ airavata-client/src/test/java/org/apache/airavata/client/airavata/ commons/utils/src... Date: Mon, 08 Jul 2013 19:40:59 -0000 To: commits@airavata.apache.org From: amilaj@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130708194100.656A9238888A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: amilaj Date: Mon Jul 8 19:40:59 2013 New Revision: 1500905 URL: http://svn.apache.org/r1500905 Log: Fixing issue AIRAVATA-879 Added: airavata/trunk/modules/commons/utils/src/test/java/org/apache/airavata/common/utils/ApplicationSettingsTest.java airavata/trunk/modules/commons/utils/src/test/resources/airavata-server.properties (with props) airavata/trunk/modules/integration-tests/src/test/resources/airavata-client.properties Modified: airavata/trunk/modules/airavata-client/pom.xml airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java airavata/trunk/modules/airavata-client/src/main/resources/RegistryService.wsdl airavata/trunk/modules/airavata-client/src/test/java/org/apache/airavata/client/airavata/AiravataClientTest.java airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataUtils.java airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java airavata/trunk/modules/distribution/airavata-client/src/main/resources/conf/airavata-client.properties airavata/trunk/modules/distribution/airavata-server/src/main/resources/conf/airavata-server.properties airavata/trunk/modules/integration-tests/pom.xml airavata/trunk/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/RegistryService.java airavata/trunk/modules/rest/webapp/src/main/resources/airavata-server.properties airavata/trunk/modules/xbaya-gui/src/main/resources/airavata-client.properties Modified: airavata/trunk/modules/airavata-client/pom.xml URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/pom.xml?rev=1500905&r1=1500904&r2=1500905&view=diff ============================================================================== --- airavata/trunk/modules/airavata-client/pom.xml (original) +++ airavata/trunk/modules/airavata-client/pom.xml Mon Jul 8 19:40:59 2013 @@ -60,4 +60,38 @@ + + + + org.apache.axis2 + axis2-wsdl2code-maven-plugin + ${axis2.version} + + false + false + true + target/generated/wsdl2code + org.apache.airavata.registry.stub + ${pom.basedir}/src/main/resources/RegistryService.wsdl + xmlbeans + + + + + wsdl2code + + + + + + + + ${pom.basedir}/target/generated/wsdl2code/resources + + **/** + + + + + Modified: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java?rev=1500905&r1=1500904&r2=1500905&view=diff ============================================================================== --- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java (original) +++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java Mon Jul 8 19:40:59 2013 @@ -47,6 +47,9 @@ import org.apache.airavata.client.impl.P import org.apache.airavata.client.impl.UserManagerImpl; import org.apache.airavata.client.impl.WorkflowManagerImpl; import org.apache.airavata.common.exception.AiravataConfigurationException; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.common.utils.ApplicationSettings; import org.apache.airavata.common.utils.Version; import org.apache.airavata.common.workflow.execution.context.WorkflowContextHeaderBuilder; import org.apache.airavata.registry.api.AiravataRegistry2; @@ -55,7 +58,6 @@ import org.apache.airavata.registry.api. import org.apache.airavata.registry.api.Gateway; import org.apache.airavata.registry.api.PasswordCallback; import org.apache.airavata.registry.api.exception.RegistryException; -import org.apache.airavata.ws.monitor.MonitorConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -95,6 +97,11 @@ public class AiravataClient extends Obse private String gateway; private boolean configCreated = false; + private static volatile boolean registryServiceStarted = false; + + private static int WAIT_TIME_PERIOD = 3 * 1000; + private static int WAIT_ITERATIONS = 19; + private static final Version API_VERSION = new Version("Airavata", 0, 8, null, null, null); @@ -139,7 +146,10 @@ public class AiravataClient extends Obse @Override public void initialize() throws AiravataAPIInvocationException { - try { + + waitTillRegistryServiceStarts(); + + try { if (!configCreated) { configuration = createConfig(getRegitryURI(), getCurrentUser(), getPassword()); @@ -165,6 +175,94 @@ public class AiravataClient extends Obse } } + private void waitTillRegistryServiceStarts() throws AiravataAPIInvocationException{ + + synchronized (API_VERSION) { + if (!registryServiceStarted) { + waitForRegistryServiceToStart(getRegistryWebServiceWSDLUrl()); + registryServiceStarted = true; + } + } + } + + private String getRegistryWebServiceWSDLUrl() throws AiravataAPIInvocationException { + String registryUrl = null; + try { + registryUrl = ApplicationSettings.getAbsoluteSetting("registry.service.wsdl"); + } catch (ApplicationSettingsException e) { + String msg = "Configuration registry.service.wsdl is not specified in the configuration file"; + log.warn(msg); + log.debug(msg, e); + } + + if (registryUrl == null) { + String hostName = getRegitryURI().getHost(); + int port = getRegitryURI().getPort(); + String protocol = null; + try { + protocol = getRegitryURI().toURL().getProtocol(); + } catch (MalformedURLException e) { + String msg = "Error retrieving protocol from registry URI - " + + getRegitryURI().toString(); + log.error(msg, e); + throw new AiravataAPIInvocationException(msg, e); + } + + StringBuilder registryServiceUrlString = new StringBuilder(protocol); + registryServiceUrlString.append("://").append(hostName).append(":").append(port); + registryServiceUrlString.append("/axis2/services/RegistryService?wsdl"); + + registryUrl = registryServiceUrlString.toString(); + } + + return registryUrl; + } + + private void waitForRegistryServiceToStart(String url) throws AiravataAPIInvocationException { + + log.info("Registry service URL - " + url); + + int iterations = 0; + Exception exception = null; + + while (!registryServiceStarted) { + try { + org.apache.airavata.registry.stub.RegistryServiceStub stub = + new org.apache.airavata.registry.stub.RegistryServiceStub(url); + registryServiceStarted = stub.isRegistryServiceStarted().getIsRegistryServiceStartedResponse(). + getReturn(); + } catch (Exception e) { + exception = e; + } + + if (!registryServiceStarted) { + try { + if (iterations == WAIT_ITERATIONS) { + if (exception != null) { + throw new AiravataAPIInvocationException("Unable to connect to RegistryService. " + + "RegistryService may not have started", exception); + } else { + throw new AiravataAPIInvocationException("Unable to connect to RegistryService. " + + "RegistryService may not have started"); + } + + } else { + Thread.sleep(WAIT_TIME_PERIOD); + } + } catch (InterruptedException e1) { + log.info("Received an interrupted exception."); + } + + log.info("Attempting to contact registry service, iteration - " + iterations); + + ++iterations; + } + + } + + + } + private void updateClientConfiguration(Map configuration) throws MalformedURLException { AiravataClientConfiguration clientConfiguration = getClientConfiguration(); Modified: airavata/trunk/modules/airavata-client/src/main/resources/RegistryService.wsdl URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/resources/RegistryService.wsdl?rev=1500905&r1=1500904&r2=1500905&view=diff ============================================================================== --- airavata/trunk/modules/airavata-client/src/main/resources/RegistryService.wsdl (original) +++ airavata/trunk/modules/airavata-client/src/main/resources/RegistryService.wsdl Mon Jul 8 19:40:59 2013 @@ -1,951 +1,45 @@ - - - - RegistryService - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + Provide Simple Service for Testing Purpose including addition, subtraction, multiplication, array-generator + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + - + - - + + + + + @@ -954,368 +48,26 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - + - + - + - + Modified: airavata/trunk/modules/airavata-client/src/test/java/org/apache/airavata/client/airavata/AiravataClientTest.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/test/java/org/apache/airavata/client/airavata/AiravataClientTest.java?rev=1500905&r1=1500904&r2=1500905&view=diff ============================================================================== --- airavata/trunk/modules/airavata-client/src/test/java/org/apache/airavata/client/airavata/AiravataClientTest.java (original) +++ airavata/trunk/modules/airavata-client/src/test/java/org/apache/airavata/client/airavata/AiravataClientTest.java Mon Jul 8 19:40:59 2013 @@ -92,6 +92,16 @@ public class AiravataClientTest { // } } + //@Test + public void testRegistryServiceInvocation() throws Exception { + org.apache.airavata.registry.stub.RegistryServiceStub stub = + new org.apache.airavata.registry.stub.RegistryServiceStub("http://localhost:8080/axis2/services/RegistryService?wsdl"); + boolean registryServiceStarted = stub.isRegistryServiceStarted().getIsRegistryServiceStartedResponse(). + getReturn(); + + System.out.println(registryServiceStarted); + } + } Modified: airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataUtils.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataUtils.java?rev=1500905&r1=1500904&r2=1500905&view=diff ============================================================================== --- airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataUtils.java (original) +++ airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataUtils.java Mon Jul 8 19:40:59 2013 @@ -22,7 +22,7 @@ package org.apache.airavata.common.utils; public class AiravataUtils { - private static final String EXECUTION_MODE="application.execution.mode"; + public static final String EXECUTION_MODE="application.execution.mode"; public static void setExecutionMode(ExecutionMode mode){ System.setProperty(EXECUTION_MODE, mode.name()); } Modified: airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java?rev=1500905&r1=1500904&r2=1500905&view=diff ============================================================================== --- airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java (original) +++ airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java Mon Jul 8 19:40:59 2013 @@ -23,8 +23,12 @@ package org.apache.airavata.common.utils import java.io.FileOutputStream; import java.net.URL; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.exception.ApplicationSettingsLoadException; @@ -43,6 +47,8 @@ public abstract class ApplicationSetting protected static final String TRUST_STORE_PATH="trust.store"; protected static final String TRUST_STORE_PASSWORD="trust.store.password"; + private static final String REGULAR_EXPRESSION = "\\$\\{[a-zA-Z]*\\}"; + private final static Logger logger = LoggerFactory.getLogger(ApplicationSettings.class); static{ @@ -94,6 +100,51 @@ public abstract class ApplicationSetting } throw new UnspecifiedApplicationSettingsException(key); } + + /** + * Returns the configuration value relevant for the given key. + * If configuration value contains references to other configuration values they will also + * be replaced. E.g :- If configuration key reads http://${ip}:${port}/axis2/services/RegistryService?wsdl, + * the variables ip and port will get replaced by their appropriated values in the configuration. + * @param key The configuration key to read value of + * @return The configuration value. For above example caller will get a value like + * http://192.2.33.12:8080/axis2/services/RegistryService?wsdl + * @throws ApplicationSettingsException If an error occurred while reading configurations. + */ + public static String getAbsoluteSetting(String key) throws ApplicationSettingsException { + + String configurationValueWithVariables = ApplicationSettings.getSetting(key); + + List variableList + = getAllMatches(configurationValueWithVariables, REGULAR_EXPRESSION); + + if (variableList == null || variableList.isEmpty()) { + return configurationValueWithVariables; + } + + for(String variableIdentifier : variableList) { + String variableName = getVariableNameOnly(variableIdentifier); + String value = getAbsoluteSetting(variableName); + + configurationValueWithVariables = configurationValueWithVariables.replace(variableIdentifier, value); + } + + return configurationValueWithVariables; + + } + + private static String getVariableNameOnly(String variableWithIdentifiers) { + return variableWithIdentifiers.substring(2, (variableWithIdentifiers.length() - 1)); + } + + private static List getAllMatches(String text, String regex) { + List matches = new ArrayList(); + Matcher m = Pattern.compile("(?=(" + regex + "))").matcher(text); + while(m.find()) { + matches.add(m.group(1)); + } + return matches; + } public static String getSetting(String key, String defaultValue){ try { Added: airavata/trunk/modules/commons/utils/src/test/java/org/apache/airavata/common/utils/ApplicationSettingsTest.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/utils/src/test/java/org/apache/airavata/common/utils/ApplicationSettingsTest.java?rev=1500905&view=auto ============================================================================== --- airavata/trunk/modules/commons/utils/src/test/java/org/apache/airavata/common/utils/ApplicationSettingsTest.java (added) +++ airavata/trunk/modules/commons/utils/src/test/java/org/apache/airavata/common/utils/ApplicationSettingsTest.java Mon Jul 8 19:40:59 2013 @@ -0,0 +1,49 @@ +/* + * + * 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.common.utils; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.airavata.common.exception.ApplicationSettingsException; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * User: AmilaJ (amilaj@apache.org) + * Date: 7/5/13 + * Time: 4:39 PM + */ + +public class ApplicationSettingsTest extends TestCase { + public void testGetAbsoluteSetting() throws Exception { + + System.setProperty(AiravataUtils.EXECUTION_MODE, "SERVER"); + String url = ApplicationSettings.getAbsoluteSetting("registry.service.wsdl"); + Assert.assertEquals("http://192.2.33.12:8080/axis2/services/RegistryService?wsdl", url); + + } + + +}