Refactored gfac core module classes
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/2f3da010 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/2f3da010 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/2f3da010 Branch: refs/heads/master Commit: 2f3da0104f4c3d468b4a251a43249c39bce18c29 Parents: 4045c09 Author: Shameera Rathanyaka <[email protected]> Authored: Fri Jun 5 12:30:59 2015 -0400 Committer: Shameera Rathanyaka <[email protected]> Committed: Fri Jun 5 12:30:59 2015 -0400 ---------------------------------------------------------------------- .../gfac/bes/handlers/AbstractSMSHandler.java | 2 +- .../gfac/bes/provider/impl/BESProvider.java | 2 +- .../bes/security/UNICORESecurityContext.java | 4 +- .../gfac/bes/security/X509SecurityContext.java | 12 +- .../gfac/bes/utils/DataTransferrer.java | 4 +- .../airavata/gfac/bes/utils/SecurityUtils.java | 4 +- .../airavata/gfac/AbstractSecurityContext.java | 58 ---- .../org/apache/airavata/gfac/Constants.java | 82 ------ .../org/apache/airavata/gfac/ExecutionMode.java | 39 --- .../apache/airavata/gfac/GFacConfiguration.java | 289 ------------------- .../org/apache/airavata/gfac/GFacException.java | 48 --- .../airavata/gfac/JobSubmissionFault.java | 98 ------- .../org/apache/airavata/gfac/RequestData.java | 150 ---------- .../org/apache/airavata/gfac/Scheduler.java | 231 --------------- .../apache/airavata/gfac/SecurityContext.java | 26 -- .../apache/airavata/gfac/ToolsException.java | 35 --- .../gfac/core/AbstractSecurityContext.java | 57 ++++ .../apache/airavata/gfac/core/Constants.java | 82 ++++++ .../airavata/gfac/core/ExecutionMode.java | 39 +++ .../org/apache/airavata/gfac/core/GFac.java | 3 +- .../airavata/gfac/core/GFacConfiguration.java | 289 +++++++++++++++++++ .../airavata/gfac/core/GFacException.java | 48 +++ .../apache/airavata/gfac/core/GFacUtils.java | 4 - .../airavata/gfac/core/JobSubmissionFault.java | 98 +++++++ .../apache/airavata/gfac/core/RequestData.java | 151 ++++++++++ .../apache/airavata/gfac/core/Scheduler.java | 230 +++++++++++++++ .../airavata/gfac/core/SecurityContext.java | 26 ++ .../airavata/gfac/core/ToolsException.java | 35 +++ .../gfac/core/context/JobExecutionContext.java | 6 +- .../gfac/core/handler/GFacHandlerException.java | 2 +- .../gfac/core/provider/AbstractProvider.java | 2 +- .../gfac/core/provider/GFacProvider.java | 2 +- .../apache/airavata/job/GFacConfigXmlTest.java | 2 +- .../org/apache/airavata/job/TestProvider.java | 2 +- .../handler/GSISSHDirectorySetupHandler.java | 2 +- .../gfac/gsissh/handler/GSISSHInputHandler.java | 2 +- .../gsissh/handler/GSISSHOutputHandler.java | 2 +- .../gsissh/handler/NewGSISSHOutputHandler.java | 2 +- .../gsissh/provider/impl/GSISSHProvider.java | 2 +- .../gsissh/security/GSISecurityContext.java | 4 +- .../security/TokenizedMyProxyAuthInfo.java | 14 +- .../gfac/gsissh/util/GFACGSISSHUtils.java | 4 +- .../airavata/gfac/impl/BetterGfacImpl.java | 8 +- .../airavata/gfac/impl/OutHandlerWorker.java | 2 +- .../gfac/local/provider/impl/LocalProvider.java | 4 +- .../airavata/gfac/monitor/HPCMonitorID.java | 4 +- .../impl/pull/qstat/ResourceConnection.java | 4 +- .../airavata/gfac/monitor/util/CommonUtils.java | 2 +- .../ssh/handler/AdvancedSCPInputHandler.java | 2 +- .../ssh/handler/AdvancedSCPOutputHandler.java | 2 +- .../gfac/ssh/handler/NewSSHOutputHandler.java | 2 +- .../ssh/handler/SSHDirectorySetupHandler.java | 2 +- .../gfac/ssh/handler/SSHInputHandler.java | 2 +- .../gfac/ssh/handler/SSHOutputHandler.java | 4 +- .../gfac/ssh/provider/impl/SSHProvider.java | 4 +- .../gfac/ssh/security/SSHSecurityContext.java | 2 +- .../gfac/ssh/security/TokenizedSSHAuthInfo.java | 8 +- .../airavata/gfac/ssh/util/GFACSSHUtils.java | 6 +- .../services/impl/BigRed2TestWithSSHAuth.java | 6 +- .../gfac/services/impl/CredentialStoreTest.java | 4 +- .../impl/GSISSHProviderTestWithMyProxyAuth.java | 6 +- .../gfac/services/impl/LocalProviderTest.java | 4 +- .../impl/SSHProviderTestWithSSHAuth.java | 4 +- .../GSISecurityContextTestWithMyProxyAuth.java | 4 +- .../airavata/gfac/server/GfacServerHandler.java | 4 +- 65 files changed, 1137 insertions(+), 1147 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/handlers/AbstractSMSHandler.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/handlers/AbstractSMSHandler.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/handlers/AbstractSMSHandler.java index 34a00e3..2aec909 100644 --- a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/handlers/AbstractSMSHandler.java +++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/handlers/AbstractSMSHandler.java @@ -26,7 +26,7 @@ import java.io.StringWriter; import java.util.Properties; import org.apache.airavata.registry.cpi.AppCatalogException; -import org.apache.airavata.gfac.GFacException; +import org.apache.airavata.gfac.core.GFacException; import org.apache.airavata.gfac.bes.security.UNICORESecurityContext; import org.apache.airavata.gfac.bes.security.X509SecurityContext; import org.apache.airavata.gfac.bes.utils.BESConstants; http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/provider/impl/BESProvider.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/provider/impl/BESProvider.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/provider/impl/BESProvider.java index 19f4e3b..b166593 100644 --- a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/provider/impl/BESProvider.java +++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/provider/impl/BESProvider.java @@ -25,7 +25,7 @@ import java.util.Map; import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.gfac.GFacException; +import org.apache.airavata.gfac.core.GFacException; import org.apache.airavata.gfac.bes.security.UNICORESecurityContext; import org.apache.airavata.gfac.bes.security.X509SecurityContext; import org.apache.airavata.gfac.bes.utils.BESConstants; http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/UNICORESecurityContext.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/UNICORESecurityContext.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/UNICORESecurityContext.java index f2ec94e..1593e41 100644 --- a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/UNICORESecurityContext.java +++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/UNICORESecurityContext.java @@ -29,8 +29,8 @@ import java.util.Set; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.credential.store.store.CredentialReader; -import org.apache.airavata.gfac.GFacException; -import org.apache.airavata.gfac.RequestData; +import org.apache.airavata.gfac.core.GFacException; +import org.apache.airavata.gfac.core.RequestData; import org.apache.airavata.gfac.bes.utils.BESConstants; import org.apache.airavata.gfac.bes.utils.SecurityUtils; import org.apache.airavata.gfac.core.provider.GFacProviderException; http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/X509SecurityContext.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/X509SecurityContext.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/X509SecurityContext.java index 3707ff1..7d9c754 100644 --- a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/X509SecurityContext.java +++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/security/X509SecurityContext.java @@ -26,10 +26,10 @@ import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.credential.store.credential.Credential; import org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential; import org.apache.airavata.credential.store.store.CredentialReader; -import org.apache.airavata.gfac.AbstractSecurityContext; -import org.apache.airavata.gfac.Constants; -import org.apache.airavata.gfac.GFacException; -import org.apache.airavata.gfac.RequestData; +import org.apache.airavata.gfac.core.AbstractSecurityContext; +import org.apache.airavata.gfac.core.Constants; +import org.apache.airavata.gfac.core.GFacException; +import org.apache.airavata.gfac.core.RequestData; import org.apache.airavata.gfac.bes.utils.MyProxyLogon; import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.x500.X500Name; @@ -137,7 +137,7 @@ public class X509SecurityContext extends AbstractSecurityContext { * 1. Try creating credentials using certificates stored in the credential store * 2. If 1 fails use user name and password to create credentials * @return x509credentials (from CANL security API) - * @throws org.apache.airavata.gfac.GFacException If an error occurred while creating credentials. + * @throws GFacException If an error occurred while creating credentials. * @throws org.apache.airavata.common.exception.ApplicationSettingsException */ public X509Credential getX509Credentials() throws GFacException, ApplicationSettingsException { @@ -234,7 +234,7 @@ public class X509SecurityContext extends AbstractSecurityContext { /** * Gets the default proxy certificate. * @return Default my proxy credentials. - * @throws org.apache.airavata.gfac.GFacException If an error occurred while retrieving credentials. + * @throws GFacException If an error occurred while retrieving credentials. * @throws org.apache.airavata.common.exception.ApplicationSettingsException */ public X509Credential getDefaultCredentials() throws GFacException, ApplicationSettingsException{ http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/DataTransferrer.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/DataTransferrer.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/DataTransferrer.java index d70e4b1..623a0b6 100644 --- a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/DataTransferrer.java +++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/DataTransferrer.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.airavata.gfac.Constants; +import org.apache.airavata.gfac.core.Constants; import org.apache.airavata.gfac.core.context.JobExecutionContext; import org.apache.airavata.gfac.core.provider.GFacProviderException; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; @@ -39,8 +39,6 @@ import org.apache.airavata.model.appcatalog.appinterface.DataType; import org.apache.airavata.model.appcatalog.appinterface.InputDataObjectType; import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType; import org.apache.airavata.model.workspace.experiment.TaskDetails; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SecurityUtils.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SecurityUtils.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SecurityUtils.java index ede44d4..aba485c 100644 --- a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SecurityUtils.java +++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SecurityUtils.java @@ -38,8 +38,8 @@ import javax.security.auth.x500.X500Principal; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.credential.store.store.CredentialReader; -import org.apache.airavata.gfac.GFacException; -import org.apache.airavata.gfac.RequestData; +import org.apache.airavata.gfac.core.GFacException; +import org.apache.airavata.gfac.core.RequestData; import org.apache.airavata.gfac.bes.security.UNICORESecurityContext; import org.apache.airavata.gfac.bes.security.X509SecurityContext; import org.apache.airavata.gfac.core.context.JobExecutionContext; http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/AbstractSecurityContext.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/AbstractSecurityContext.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/AbstractSecurityContext.java deleted file mode 100644 index 36d7296..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/AbstractSecurityContext.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * 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.gfac; - -/** - * User: AmilaJ ([email protected]) - * Date: 6/26/13 - * Time: 4:33 PM - */ - -import java.io.Serializable; - -import org.apache.airavata.credential.store.store.CredentialReader; -import org.apache.airavata.gfac.SecurityContext; - -/** - * Abstract implementation of the security context. - */ -public abstract class AbstractSecurityContext implements SecurityContext, Serializable { - - private CredentialReader credentialReader; - private RequestData requestData; - - public AbstractSecurityContext(CredentialReader credentialReader, RequestData requestData) { - this.credentialReader = credentialReader; - this.requestData = requestData; - } - public AbstractSecurityContext() { - - } - - public CredentialReader getCredentialReader() { - return credentialReader; - } - - public RequestData getRequestData() { - return requestData; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java deleted file mode 100644 index 73ff677..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/Constants.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * 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.gfac; - -public class Constants { - public static final String XPATH_EXPR_GLOBAL_INFLOW_HANDLERS = "/GFac/GlobalHandlers/InHandlers/Handler"; - public static final String XPATH_EXPR_GLOBAL_OUTFLOW_HANDLERS = "/GFac/GlobalHandlers/OutHandlers/Handler"; - public static final String XPATH_EXPR_DAEMON_HANDLERS = "/GFac/DaemonHandlers/Handler"; - - public static final String XPATH_EXPR_APPLICATION_HANDLERS_START = "/GFac/Application[@name='"; - public static final String XPATH_EXPR_APPLICATION_INFLOW_HANDLERS_END = "']/InHandlers/Handler"; - public static final String XPATH_EXPR_APPLICATION_OUTFLOW_HANDLERS_END = "']/OutHandlers/Handler"; - public static final String XPATH_EXPR_APPLICATION_PROVIDER = "']/OutHandlers/Handler"; - - - public static final String XPATH_EXPR_PROVIDER_HANDLERS_START = "/GFac/Provider[@class='"; - public static final String XPATH_EXPR_PROVIDER_ON_HOST = "/GFac/Provider[@host='"; - public static final String XPATH_EXPR_PROVIDER_ON_SUBMISSION = "/GFac/Provider[@submission='"; - public static final String XPATH_EXPR_PROVIDER_INFLOW_HANDLERS_END = "']/InHandlers/Handler"; - public static final String XPATH_EXPR_PROVIDER_OUTFLOW_HANDLERS_END = "']/OutHandlers/Handler"; - - public static final String GFAC_CONFIG_CLASS_ATTRIBUTE = "class"; - public static final String GFAC_CONFIG_SECURITY_ATTRIBUTE = "security"; - public static final String GFAC_CONFIG_SUBMISSION_ATTRIBUTE = "submission"; - public static final String GFAC_CONFIG_EXECUTION_MODE_ATTRIBUTE = "executionMode"; - public static final String GFAC_CONFIG_APPLICATION_NAME_ATTRIBUTE = "class"; - public static final String NEWLINE = System.getProperty("line.separator"); - public static final String INPUT_DATA_DIR_VAR_NAME = "input"; - public static final String OUTPUT_DATA_DIR_VAR_NAME = "output"; - public static final int DEFAULT_GSI_FTP_PORT = 2811; - public static final String _127_0_0_1 = "127.0.0.1"; - public static final String LOCALHOST = "localhost"; - - public static final String PROP_WORKFLOW_INSTANCE_ID = "workflow.instance.id"; - public static final String PROP_WORKFLOW_NODE_ID = "workflow.node.id"; - public static final String PROP_BROKER_URL = "broker.url"; - public static final String PROP_TOPIC = "topic"; - public static final String SPACE = " "; - public static final int COMMAND_EXECUTION_TIMEOUT = 5; - public static final String EXECUTABLE_NAME = "run.sh"; - - public static final String TRUSTED_CERT_LOCATION = "trusted.cert.location"; - public static final String TRUSTED_CERTIFICATE_SYSTEM_PROPERTY = "X509_CERT_DIR"; - public static final String MYPROXY_SERVER = "myproxy.server"; - public static final String MYPROXY_SERVER_PORT = "myproxy.port"; - public static final String MYPROXY_USER = "myproxy.username"; - public static final String MYPROXY_PASS = "myproxy.password"; - public static final String MYPROXY_LIFE = "myproxy.life"; - /* - * SSH properties - */ - public static final String SSH_PRIVATE_KEY = "private.ssh.key"; - public static final String SSH_PUBLIC_KEY = "public.ssh.key"; - public static final String SSH_PRIVATE_KEY_PASS = "ssh.keypass"; - public static final String SSH_USER_NAME = "ssh.username"; - public static final String SSH_PASSWORD = "ssh.password"; - public static final String PROPERTY = "property"; - public static final String NAME = "name"; - public static final String VALUE = "value"; - public static final String OUTPUT_DATA_DIR = "output.location"; - - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/ExecutionMode.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/ExecutionMode.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/ExecutionMode.java deleted file mode 100644 index 63f2523..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/ExecutionMode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * 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.gfac; - - -/** - * These are the different modes of execution chains in gfac - * if the mode is SYNCHRONOUS then gfac will waits until the provider invoke mthod returns and then - * invoke the out handlers explicitly, otherwise gfac will not invoke out hanlders, implementation - * has to handler when to invoke out handlers, and default execution mode is synchronous. - */ -public enum ExecutionMode { - SYNCHRONOUS,ASYNCHRONOUS; - - public static ExecutionMode fromString(String mode){ - if("async".equals(mode) || "asynchronous".equals(mode)){ - return ExecutionMode.ASYNCHRONOUS; - } - return ExecutionMode.SYNCHRONOUS; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java deleted file mode 100644 index 60e9c71..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/GFacConfiguration.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * - * 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.gfac; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.*; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.apache.airavata.gfac.core.handler.GFacHandlerConfig; -import org.apache.airavata.gfac.core.provider.GFacProviderConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.*; -import org.xml.sax.SAXException; - -public class GFacConfiguration { - public static final Logger log = LoggerFactory.getLogger(GFacConfiguration.class); - - -// private AiravataAPI airavataAPI; - - private static Document handlerDoc; - // Keep list of full qualified class names of GFac handlers which should invoked before - // the provider - private List<GFacHandlerConfig> inHandlers = new ArrayList<GFacHandlerConfig>(); - - // Keep list of full qualified class names of GFac handlers which should invoked after - // the provider - private List<GFacHandlerConfig> outHandlers = new ArrayList<GFacHandlerConfig>(); - - public ExecutionMode executionMode = ExecutionMode.SYNCHRONOUS; // default execution mode is SYNCHRONOUS - - public GFacConfiguration() { - } - -// public AiravataAPI getAiravataAPI() { -// return airavataAPI; -// } - - - public static File getConfigFile() { - URL resource = GFacConfiguration.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML); - File gfacConfigFile = null; - if (resource != null) { - gfacConfigFile = new File(resource.getPath()); - } - return gfacConfigFile; - } - public List<GFacHandlerConfig> getInHandlers() { - //This will avoid the misconfiguration done by user in gfac-config.xml - return removeDuplicateWithOrder(inHandlers); - } - - public List<GFacHandlerConfig> getOutHandlers() { - //This will avoid the misconfiguration done by user in gfac-config.xml - return removeDuplicateWithOrder(outHandlers); - } - public void setInHandlers(List<GFacHandlerConfig> inHandlers) { - this.inHandlers = inHandlers; - } - - public void setOutHandlers(List<GFacHandlerConfig> outHandlers) { - this.outHandlers = outHandlers; - } - - public void setInHandlers(String providerName, String applicationName) { - try { - this.inHandlers = getHandlerConfig(handlerDoc, Constants.XPATH_EXPR_GLOBAL_INFLOW_HANDLERS, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); - if (applicationName != null) { - String xPath = Constants.XPATH_EXPR_APPLICATION_HANDLERS_START + applicationName + Constants.XPATH_EXPR_APPLICATION_INFLOW_HANDLERS_END; - List<GFacHandlerConfig> handlers = getHandlerConfig(handlerDoc, xPath, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); - this.inHandlers.addAll(handlers); - } - if (providerName != null) { - String xPath = Constants.XPATH_EXPR_PROVIDER_HANDLERS_START + providerName + Constants.XPATH_EXPR_PROVIDER_INFLOW_HANDLERS_END; - List<GFacHandlerConfig> handlers = getHandlerConfig(handlerDoc, xPath, Constants.GFAC_CONFIG_APPLICATION_NAME_ATTRIBUTE); - this.inHandlers.addAll(handlers); - } - } catch (XPathExpressionException e) { - new GFacException("Error parsing Handler Configuration", e); - } - } - - public void setOutHandlers(String providerName, String applicationName) { - try { - this.outHandlers = getHandlerConfig(handlerDoc, Constants.XPATH_EXPR_GLOBAL_OUTFLOW_HANDLERS, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); - if (applicationName != null) { - String xPath = Constants.XPATH_EXPR_APPLICATION_HANDLERS_START + applicationName + Constants.XPATH_EXPR_APPLICATION_OUTFLOW_HANDLERS_END; - List<GFacHandlerConfig> handlers = getHandlerConfig(handlerDoc, xPath, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); - this.outHandlers.addAll(handlers); - } - if(providerName != null) { - String xPath = Constants.XPATH_EXPR_PROVIDER_HANDLERS_START + providerName + Constants.XPATH_EXPR_PROVIDER_OUTFLOW_HANDLERS_END; - List<GFacHandlerConfig> handlers = getHandlerConfig(handlerDoc, xPath, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); - this.outHandlers.addAll(handlers); - } - } catch (XPathExpressionException e) { - new GFacException("Error parsing Handler Configuration", e); - } - } - - /** - * Parse GFac configuration file and populate GFacConfiguration object. XML configuration - * file for GFac will look like below. - * <p/> - * <GFac> - * <GlobalHandlers> - * <InHandlers> - * <Handler class="org.apache.airavata.gfac.GlobalHandler1"> - * </InHandler> - * <OutHandlers> - * <Handler class="org.apache.airavata.gfac.GlabalHandler2"> - * </OutHandlers> - * </GlobalHandlers> - * <Provider class="org.apache.airavata.gfac.providers.LocalProvider" host="LocalHost"> - * <InHandlers> - * <Handler class="org.apache.airavata.gfac.handlers.LocalEvenSetupHandler"> - * </InHandlers> - * <OutHandlers> - * <Handler>org.apache.airavata.LocalOutHandler1</Handler> - * </OutHandlers> - * </Provider> - * <Application name="UltraScan"> - * <InHandlers> - * <Handler class="org.apache.airavata.gfac.handlers.LocalEvenSetupHandler"> - * </InHandlers> - * <OutHandlers> - * <Handler class="org.apache.airavata.gfac.LocalOutHandler1"> - * </OutHandlers> - * </Application> - * </GFac> - * - * @param configFile configuration file - * @return GFacConfiguration object. - */ - //FIXME - public static GFacConfiguration create(File configFile, Properties configurationProperties) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); - handlerDoc = docBuilder.parse(configFile); - return new GFacConfiguration(); - } - - private static String xpathGetText(Document doc, String expression) throws XPathExpressionException { - XPathFactory xPathFactory = XPathFactory.newInstance(); - XPath xPath = xPathFactory.newXPath(); - XPathExpression expr = xPath.compile(expression); - - return (String) expr.evaluate(doc, XPathConstants.STRING); - } - - /** - * Select matching node set and extract specified attribute value. - * - * @param doc XML document - * @param expression expression to match node set - * @param attribute name of the attribute to extract - * @return list of attribute values. - * @throws XPathExpressionException - */ - public static List<GFacHandlerConfig> getHandlerConfig(Document doc, String expression, String attribute) throws XPathExpressionException { - XPathFactory xPathFactory = XPathFactory.newInstance(); - XPath xPath = xPathFactory.newXPath(); - XPathExpression expr = xPath.compile(expression); - - NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); - List<GFacHandlerConfig> gFacHandlerConfigs = new ArrayList<GFacHandlerConfig>(); - Properties properties = new Properties(); - String className = ""; - for (int i = 0; i < nl.getLength(); i++) { - className = ((Element) nl.item(i)).getAttribute(attribute); - NodeList childNodes = (nl.item(i)).getChildNodes(); - for(int j = 0;j < childNodes.getLength();j++){ - if(Constants.PROPERTY.equals(childNodes.item(j).getNodeName())) { - String name = ((Element) childNodes.item(j)).getAttribute(Constants.NAME); - String value = ((Element) childNodes.item(j)).getAttribute(Constants.VALUE); - properties.put(name, value); - } - } - GFacHandlerConfig gFacHandlerConfig = new GFacHandlerConfig(properties,className); - gFacHandlerConfigs.add(gFacHandlerConfig); - } - return gFacHandlerConfigs; - } - - public static List<GFacProviderConfig> getProviderConfig(Document doc, String expression, String attribute) throws XPathExpressionException { - XPathFactory xPathFactory = XPathFactory.newInstance(); - XPath xPath = xPathFactory.newXPath(); - XPathExpression expr = xPath.compile(expression); - - NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); - List<GFacProviderConfig> gFacProviderConfigs = new ArrayList<GFacProviderConfig>(); - Map<String, String> properties = new HashMap<String, String>(); - String className = ""; - for (int i = 0; i < nl.getLength(); i++) { - className = ((Element) nl.item(i)).getAttribute(attribute); - if (className != null && !className.equals("")) { - NodeList childNodes = (nl.item(i)).getChildNodes(); - for (int j = 0; j < childNodes.getLength(); j++) { - if (Constants.PROPERTY.equals(childNodes.item(j).getNodeName())) { - String name = ((Element) childNodes.item(j)).getAttribute(Constants.NAME); - String value = ((Element) childNodes.item(j)).getAttribute(Constants.VALUE); - properties.put(name, value); - } - } - GFacProviderConfig gFacProviderConfig = new GFacProviderConfig(properties,className); - gFacProviderConfigs.add(gFacProviderConfig); - } - } - return gFacProviderConfigs; - } - - public static String getAttributeValue(Document doc, String expression, String attribute) throws XPathExpressionException { - XPathFactory xPathFactory = XPathFactory.newInstance(); - XPath xPath = xPathFactory.newXPath(); - XPathExpression expr = xPath.compile(expression); - - NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); - String className = null; - for (int i = 0; i < nl.getLength(); i++) { - className = ((Element) nl.item(i)).getAttribute(attribute); - break; - } - return className; - } - - public static GFacConfiguration create(Properties configProps) { - return null; - } - - private static List removeDuplicateWithOrder(List arlList) { - Set set = new HashSet(); - List newList = new ArrayList(); - for (Iterator iter = arlList.iterator(); iter.hasNext(); ) { - Object element = iter.next(); - if (set.add(element)) - newList.add(element); - } - arlList.clear(); - arlList.addAll(newList); - return arlList; - } - public static List<GFacHandlerConfig> getDaemonHandlers(File configFile)throws ParserConfigurationException, IOException, SAXException, XPathExpressionException{ - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); - handlerDoc = docBuilder.parse(configFile); - return getHandlerConfig(handlerDoc, Constants.XPATH_EXPR_DAEMON_HANDLERS, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); - } - public static Document getHandlerDoc() { - return handlerDoc; - } - - public ExecutionMode getExecutionMode() { - return executionMode; - } - - public void setExecutionMode(ExecutionMode executionMode) { - this.executionMode = executionMode; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java deleted file mode 100644 index ce11e8d..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/GFacException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * 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.gfac; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GFacException extends Exception { - private static final Logger log = LoggerFactory.getLogger(GFacException.class); - - /** - * - */ - private static final long serialVersionUID = 1L; - - public GFacException(String s) { - super(s); - } - - public GFacException(Exception e) { - super(e); - log.error(e.getMessage(),e); - } - - public GFacException(String s, Throwable throwable) { - super(s, throwable); - log.error(s,throwable); - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/JobSubmissionFault.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/JobSubmissionFault.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/JobSubmissionFault.java deleted file mode 100644 index b211e2f..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/JobSubmissionFault.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * - * 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.gfac; - -import org.apache.airavata.gfac.core.context.JobExecutionContext; -import org.apache.airavata.gfac.core.provider.GFacProviderException; - -// TODO review this class - Not sure some of the attributes are actually -// needed -public class JobSubmissionFault extends GFacProviderException { - - // TODO why we need following ? - //public static final String JOB_CANCEL = "JOB_CANCEL"; - - //public static final String JOB_FAILED = "JOB_FAILED"; - - private String reason; - private String contact; - private int gramErrorCode; - private String rsl; - private String host; - - public JobSubmissionFault(Throwable cause, String submitHost, String contact, String rsl, - JobExecutionContext jobExecutionContext, String reason, int errorCode) { - super(cause.getMessage(), cause); - - this.host = submitHost; - this.contact = contact; - this.rsl = rsl; - this.reason = reason; - this.gramErrorCode = errorCode; - } - - public void setReason(String reason) { - this.reason = reason; - } - - // TODO why we need this ? - public void sendFaultNotification(String message, - JobExecutionContext jobExecutionContext, Exception e, - String... additionalExceptiondata) { - - } - - public String getReason() { - return reason; - } - - public String getContact() { - return contact; - } - - public void setContact(String contact) { - this.contact = contact; - } - - public int getGramErrorCode() { - return gramErrorCode; - } - - public void setGramErrorCode(int gramErrorCode) { - this.gramErrorCode = gramErrorCode; - } - - public String getRsl() { - return rsl; - } - - public void setRsl(String rsl) { - this.rsl = rsl; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/RequestData.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/RequestData.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/RequestData.java deleted file mode 100644 index 000ea7d..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/RequestData.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * - * 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.gfac; - -/** - * User: AmilaJ ([email protected]) - * Date: 6/28/13 - * Time: 3:28 PM - */ - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.ServerSettings; - -/** - * Encapsulates GFac specific data that are coming in the request. - */ -public class RequestData { - - private static final int DEFAULT_LIFE_TIME = 3600; - private static final int DEFAULT_MY_PROXY_PORT = 7512; - - private String tokenId; - private String requestUser; - private String gatewayId; - - private String myProxyServerUrl = null; - private int myProxyPort = 0; - private String myProxyUserName = null; - private String myProxyPassword = null; - private int myProxyLifeTime = DEFAULT_LIFE_TIME; - - - - - public RequestData() { - } - - public RequestData(String gatewayId) { - this.gatewayId = gatewayId; - } - - public RequestData(String tokenId, String requestUser, String gatewayId) { - this.tokenId = tokenId; - this.requestUser = requestUser; - this.gatewayId = gatewayId; - } - - public String getTokenId() { - return tokenId; - } - - public void setTokenId(String tokenId) { - this.tokenId = tokenId; - } - - public String getRequestUser() { - return requestUser; - } - - public void setRequestUser(String requestUser) { - this.requestUser = requestUser; - } - - public String getGatewayId() { - return gatewayId; - } - - public void setGatewayId(String gatewayId) { - this.gatewayId = gatewayId; - } - - public String getMyProxyServerUrl() throws ApplicationSettingsException { - if (myProxyServerUrl == null) { - myProxyServerUrl = ServerSettings.getSetting(Constants.MYPROXY_SERVER); - } - return myProxyServerUrl; - } - - public void setMyProxyServerUrl(String myProxyServerUrl) { - this.myProxyServerUrl = myProxyServerUrl; - } - - public int getMyProxyPort() { - - if (myProxyPort == 0) { - String sPort = ServerSettings.getSetting(Constants.MYPROXY_SERVER_PORT, Integer.toString(DEFAULT_MY_PROXY_PORT)); - myProxyPort = Integer.parseInt(sPort); - } - - return myProxyPort; - } - - public void setMyProxyPort(int myProxyPort) { - this.myProxyPort = myProxyPort; - } - - public String getMyProxyUserName() throws ApplicationSettingsException { - if (myProxyUserName == null) { - myProxyUserName = ServerSettings.getSetting(Constants.MYPROXY_USER); - } - - return myProxyUserName; - } - - public void setMyProxyUserName(String myProxyUserName) { - this.myProxyUserName = myProxyUserName; - } - - public String getMyProxyPassword() throws ApplicationSettingsException { - - if (myProxyPassword == null) { - myProxyPassword = ServerSettings.getSetting(Constants.MYPROXY_PASS); - } - - return myProxyPassword; - } - - public int getMyProxyLifeTime() { - String life = ServerSettings.getSetting(Constants.MYPROXY_LIFE,Integer.toString(myProxyLifeTime)); - myProxyLifeTime = Integer.parseInt(life); - return myProxyLifeTime; - } - - public void setMyProxyLifeTime(int myProxyLifeTime) { - this.myProxyLifeTime = myProxyLifeTime; - } - - public void setMyProxyPassword(String myProxyPassword) { - this.myProxyPassword = myProxyPassword; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java deleted file mode 100644 index c9a1ce0..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/Scheduler.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * - * 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.gfac; - -import org.apache.airavata.registry.cpi.AppCatalog; -import org.apache.airavata.registry.cpi.AppCatalogException; -import org.apache.airavata.gfac.core.context.JobExecutionContext; -import org.apache.airavata.gfac.core.provider.GFacProvider; -import org.apache.airavata.gfac.core.provider.GFacProviderConfig; -import org.apache.airavata.gfac.core.provider.GFacProviderException; -import org.apache.airavata.gfac.core.GFacUtils; -import org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface; -import org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol; -import org.apache.airavata.model.appcatalog.computeresource.LOCALSubmission; -import org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission; -import org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.List; - - -/** - * Scheduler decides the execution order of handlers based on application description. In addition - * to that scheduler decides which provider to invoke at the end. Scheduler will set - * provider instance and in/out handler chains in JobExecutionContext. - */ -public class Scheduler { - private static Logger log = LoggerFactory.getLogger(Scheduler.class); - - /** - * Decide which provider to use and execution sequence of handlers based on job request and - * job configuration. - * @param jobExecutionContext containing job request as well as all the configurations. - */ - public static void schedule(JobExecutionContext jobExecutionContext) throws GFacException{ - // Current implementation only support static handler sequence. - jobExecutionContext.setProvider(getProvider(jobExecutionContext)); - // TODO: Selecting the provider based on application description. - jobExecutionContext.getGFacConfiguration().setInHandlers(jobExecutionContext.getProvider().getClass().getName(), - jobExecutionContext.getApplicationName()); - jobExecutionContext.getGFacConfiguration().setOutHandlers(jobExecutionContext.getProvider().getClass().getName(), - jobExecutionContext.getApplicationName()); - jobExecutionContext.getGFacConfiguration().setExecutionMode(getExecutionMode(jobExecutionContext)); - } - - /** - * Figure out which provider to use based on application configuration. - * @param jobExecutionContext containing all the required configurations. - * @return GFacProvider instance. - */ - private static GFacProvider getProvider(JobExecutionContext jobExecutionContext) throws GFacException { - String applicationName = jobExecutionContext.getApplicationName(); - - URL resource = Scheduler.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML); - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = null; - Document handlerDoc = null; - try { - docBuilder = docBuilderFactory.newDocumentBuilder(); - handlerDoc = docBuilder.parse(new File(resource.getPath())); - } catch (ParserConfigurationException e) { - throw new GFacException(e); - } catch (SAXException e) { - throw new GFacException(e); - } catch (IOException e) { - throw new GFacException(e); - } - GFacProviderConfig s = null; - GFacProvider provider = null; - List<GFacProviderConfig> aClass = null; - String providerClassName = null; - try { - aClass = GFacConfiguration.getProviderConfig(handlerDoc, - Constants.XPATH_EXPR_APPLICATION_HANDLERS_START + applicationName + "']", Constants.GFAC_CONFIG_APPLICATION_NAME_ATTRIBUTE); - // This should be have a single element only. - if (aClass != null && !aClass.isEmpty()) { - s = aClass.get(0); - Class<? extends GFacProvider> aClass1 = Class.forName(s.getClassName()).asSubclass(GFacProvider.class); - provider = aClass1.newInstance(); - //loading the provider properties - if(!aClass.isEmpty()){ - provider.initProperties(aClass.get(0).getProperties()); - } - } - // We give higher preference to applications specific provider if configured - if (provider == null) { - - List<JobSubmissionInterface> jobSubmissionInterfaces = jobExecutionContext.getApplicationContext().getComputeResourceDescription().getJobSubmissionInterfaces(); - JobSubmissionProtocol jobSubmissionProtocol = jobExecutionContext.getPreferredJobSubmissionProtocol(); - SSHJobSubmission sshJobSubmission; - LOCALSubmission localSubmission; - UnicoreJobSubmission unicoreSubmission; - String securityProtocol = null; - try { - AppCatalog appCatalog = jobExecutionContext.getAppCatalog(); - if (jobSubmissionProtocol == JobSubmissionProtocol.SSH) { - sshJobSubmission = appCatalog.getComputeResource().getSSHJobSubmission( - jobExecutionContext.getPreferredJobSubmissionInterface().getJobSubmissionInterfaceId()); - if (sshJobSubmission != null) { - securityProtocol = sshJobSubmission.getSecurityProtocol().toString(); - } - }else if (jobSubmissionProtocol == JobSubmissionProtocol.LOCAL) { - localSubmission = appCatalog.getComputeResource().getLocalJobSubmission(jobExecutionContext.getPreferredJobSubmissionInterface().getJobSubmissionInterfaceId()); - } - else if (jobSubmissionProtocol == JobSubmissionProtocol.UNICORE) { - unicoreSubmission = appCatalog.getComputeResource().getUNICOREJobSubmission(jobExecutionContext.getPreferredJobSubmissionInterface().getJobSubmissionInterfaceId()); - securityProtocol = unicoreSubmission.getSecurityProtocol().toString(); - } - List<Element> elements = GFacUtils.getElementList(GFacConfiguration.getHandlerDoc(), Constants.XPATH_EXPR_PROVIDER_ON_SUBMISSION + jobSubmissionProtocol + "']"); - for (Element element : elements) { - String security = element.getAttribute(Constants.GFAC_CONFIG_SECURITY_ATTRIBUTE); - if (security.equals("")) { - providerClassName = element.getAttribute(Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); - }else if (securityProtocol != null && securityProtocol.equals(security)) { - providerClassName = element.getAttribute(Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); - } - } - if (providerClassName == null) { - throw new GFacException("Couldn't find provider class"); - } - - Class<? extends GFacProvider> aClass1 = Class.forName(providerClassName).asSubclass(GFacProvider.class); - provider = aClass1.newInstance(); - //loading the provider properties - aClass = GFacConfiguration.getProviderConfig(GFacConfiguration.getHandlerDoc(), Constants.XPATH_EXPR_PROVIDER_HANDLERS_START + - providerClassName + "']", Constants.GFAC_CONFIG_APPLICATION_NAME_ATTRIBUTE); - if (!aClass.isEmpty()) { - provider.initProperties(aClass.get(0).getProperties()); - } - } catch (AppCatalogException e) { - throw new GFacException("Couldn't retrieve job submission protocol from app catalog "); - } - } - } catch (XPathExpressionException e) { - log.error("Error evaluating XPath expression"); //To change body of catch statement use File | Settings | File Templates. - throw new GFacException("Error evaluating XPath expression", e); - } catch (GFacProviderException e) { - log.error("Error During scheduling"); //To change body of catch statement use File | Settings | File Templates. - throw new GFacException("Error During scheduling", e); - }catch (ClassNotFoundException e) { - log.error("Application Provider class: " + s + "couldn't find"); - throw new GFacException("Error initializing application specific Handler: " +providerClassName , e); - } catch (InstantiationException e) { - log.error("Error initializing application specific Handler: " + providerClassName); - throw new GFacException("Error initializing Handler", e); - } catch (IllegalAccessException e) { - log.error("Error initializing application specific Handler: " + providerClassName); - throw new GFacException("Error initializing Handler", e); - } - return provider; - } - public static ExecutionMode getExecutionMode(JobExecutionContext jobExecutionContext)throws GFacException{ - String applicationName = jobExecutionContext.getApplicationContext().getApplicationInterfaceDescription().getApplicationName(); - URL resource = Scheduler.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML); - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = null; - Document handlerDoc = null; - String jobSubmissionProtocol = jobExecutionContext.getPreferredJobSubmissionProtocol().toString(); - try { - docBuilder = docBuilderFactory.newDocumentBuilder(); - handlerDoc = docBuilder.parse(new File(resource.getPath())); - } catch (ParserConfigurationException e) { - throw new GFacException(e); - } catch (SAXException e) { - throw new GFacException(e); - } catch (IOException e) { - throw new GFacException(e); - } - GFacProviderConfig s = null; - String executionMode = "sync"; - try { - executionMode = GFacConfiguration.getAttributeValue(handlerDoc, - Constants.XPATH_EXPR_APPLICATION_HANDLERS_START + applicationName + "']", Constants.GFAC_CONFIG_EXECUTION_MODE_ATTRIBUTE); - // This should be have a single element only. - - if (executionMode == null || "".equals(executionMode)) { - String hostClass = jobExecutionContext.getPreferredJobSubmissionProtocol().toString(); - executionMode = GFacConfiguration.getAttributeValue(GFacConfiguration.getHandlerDoc(), Constants.XPATH_EXPR_PROVIDER_ON_HOST + hostClass + "']", Constants.GFAC_CONFIG_EXECUTION_MODE_ATTRIBUTE); - } - - if (executionMode == null || "".equals(executionMode)) { - List<Element> elements = GFacUtils.getElementList(GFacConfiguration.getHandlerDoc(), Constants.XPATH_EXPR_PROVIDER_ON_SUBMISSION + jobSubmissionProtocol + "']"); - for (Element element : elements) { - executionMode = element.getAttribute(Constants.GFAC_CONFIG_EXECUTION_MODE_ATTRIBUTE); - } - } - - } catch (XPathExpressionException e) { - log.error("Error evaluating XPath expression"); //To change body of catch statement use File | Settings | File Templates. - throw new GFacException("Error evaluating XPath expression", e); - } - - return ExecutionMode.fromString(executionMode); - } - -// private static HostDescription scheduleHost(List<HostDescription> registeredHosts) { -// //todo implement an algorithm to pick a host among different hosts, ideally this could be configurable in an xml -// return registeredHosts.get(0); -// } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/SecurityContext.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/SecurityContext.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/SecurityContext.java deleted file mode 100644 index 71db1ad..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/SecurityContext.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * 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.gfac; - -public interface SecurityContext { - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java deleted file mode 100644 index 8a20fcc..0000000 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/ToolsException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * 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.gfac; - - -/** - * Exception for all utilities - */ -public class ToolsException extends GFacException { - - public ToolsException(String message){ - super(message,new Throwable(message)); - } - public ToolsException(String message, Throwable cause) { - super(message, cause); - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/AbstractSecurityContext.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/AbstractSecurityContext.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/AbstractSecurityContext.java new file mode 100644 index 0000000..bc9c21a --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/AbstractSecurityContext.java @@ -0,0 +1,57 @@ +/* + * + * 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.gfac.core; + +/** + * User: AmilaJ ([email protected]) + * Date: 6/26/13 + * Time: 4:33 PM + */ + +import java.io.Serializable; + +import org.apache.airavata.credential.store.store.CredentialReader; + +/** + * Abstract implementation of the security context. + */ +public abstract class AbstractSecurityContext implements SecurityContext, Serializable { + + private CredentialReader credentialReader; + private RequestData requestData; + + public AbstractSecurityContext(CredentialReader credentialReader, RequestData requestData) { + this.credentialReader = credentialReader; + this.requestData = requestData; + } + public AbstractSecurityContext() { + + } + + public CredentialReader getCredentialReader() { + return credentialReader; + } + + public RequestData getRequestData() { + return requestData; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/Constants.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/Constants.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/Constants.java new file mode 100644 index 0000000..9f89256 --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/Constants.java @@ -0,0 +1,82 @@ +/* + * + * 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.gfac.core; + +public class Constants { + public static final String XPATH_EXPR_GLOBAL_INFLOW_HANDLERS = "/GFac/GlobalHandlers/InHandlers/Handler"; + public static final String XPATH_EXPR_GLOBAL_OUTFLOW_HANDLERS = "/GFac/GlobalHandlers/OutHandlers/Handler"; + public static final String XPATH_EXPR_DAEMON_HANDLERS = "/GFac/DaemonHandlers/Handler"; + + public static final String XPATH_EXPR_APPLICATION_HANDLERS_START = "/GFac/Application[@name='"; + public static final String XPATH_EXPR_APPLICATION_INFLOW_HANDLERS_END = "']/InHandlers/Handler"; + public static final String XPATH_EXPR_APPLICATION_OUTFLOW_HANDLERS_END = "']/OutHandlers/Handler"; + public static final String XPATH_EXPR_APPLICATION_PROVIDER = "']/OutHandlers/Handler"; + + + public static final String XPATH_EXPR_PROVIDER_HANDLERS_START = "/GFac/Provider[@class='"; + public static final String XPATH_EXPR_PROVIDER_ON_HOST = "/GFac/Provider[@host='"; + public static final String XPATH_EXPR_PROVIDER_ON_SUBMISSION = "/GFac/Provider[@submission='"; + public static final String XPATH_EXPR_PROVIDER_INFLOW_HANDLERS_END = "']/InHandlers/Handler"; + public static final String XPATH_EXPR_PROVIDER_OUTFLOW_HANDLERS_END = "']/OutHandlers/Handler"; + + public static final String GFAC_CONFIG_CLASS_ATTRIBUTE = "class"; + public static final String GFAC_CONFIG_SECURITY_ATTRIBUTE = "security"; + public static final String GFAC_CONFIG_SUBMISSION_ATTRIBUTE = "submission"; + public static final String GFAC_CONFIG_EXECUTION_MODE_ATTRIBUTE = "executionMode"; + public static final String GFAC_CONFIG_APPLICATION_NAME_ATTRIBUTE = "class"; + public static final String NEWLINE = System.getProperty("line.separator"); + public static final String INPUT_DATA_DIR_VAR_NAME = "input"; + public static final String OUTPUT_DATA_DIR_VAR_NAME = "output"; + public static final int DEFAULT_GSI_FTP_PORT = 2811; + public static final String _127_0_0_1 = "127.0.0.1"; + public static final String LOCALHOST = "localhost"; + + public static final String PROP_WORKFLOW_INSTANCE_ID = "workflow.instance.id"; + public static final String PROP_WORKFLOW_NODE_ID = "workflow.node.id"; + public static final String PROP_BROKER_URL = "broker.url"; + public static final String PROP_TOPIC = "topic"; + public static final String SPACE = " "; + public static final int COMMAND_EXECUTION_TIMEOUT = 5; + public static final String EXECUTABLE_NAME = "run.sh"; + + public static final String TRUSTED_CERT_LOCATION = "trusted.cert.location"; + public static final String TRUSTED_CERTIFICATE_SYSTEM_PROPERTY = "X509_CERT_DIR"; + public static final String MYPROXY_SERVER = "myproxy.server"; + public static final String MYPROXY_SERVER_PORT = "myproxy.port"; + public static final String MYPROXY_USER = "myproxy.username"; + public static final String MYPROXY_PASS = "myproxy.password"; + public static final String MYPROXY_LIFE = "myproxy.life"; + /* + * SSH properties + */ + public static final String SSH_PRIVATE_KEY = "private.ssh.key"; + public static final String SSH_PUBLIC_KEY = "public.ssh.key"; + public static final String SSH_PRIVATE_KEY_PASS = "ssh.keypass"; + public static final String SSH_USER_NAME = "ssh.username"; + public static final String SSH_PASSWORD = "ssh.password"; + public static final String PROPERTY = "property"; + public static final String NAME = "name"; + public static final String VALUE = "value"; + public static final String OUTPUT_DATA_DIR = "output.location"; + + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/ExecutionMode.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/ExecutionMode.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/ExecutionMode.java new file mode 100644 index 0000000..ebaf6fc --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/ExecutionMode.java @@ -0,0 +1,39 @@ +/* + * + * 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.gfac.core; + + +/** + * These are the different modes of execution chains in gfac + * if the mode is SYNCHRONOUS then gfac will waits until the provider invoke mthod returns and then + * invoke the out handlers explicitly, otherwise gfac will not invoke out hanlders, implementation + * has to handler when to invoke out handlers, and default execution mode is synchronous. + */ +public enum ExecutionMode { + SYNCHRONOUS,ASYNCHRONOUS; + + public static ExecutionMode fromString(String mode){ + if("async".equals(mode) || "asynchronous".equals(mode)){ + return ExecutionMode.ASYNCHRONOUS; + } + return ExecutionMode.SYNCHRONOUS; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFac.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFac.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFac.java index 584a581..a8c0d58 100644 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFac.java +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFac.java @@ -22,7 +22,6 @@ package org.apache.airavata.gfac.core; import org.apache.airavata.registry.cpi.AppCatalog; import org.apache.airavata.common.utils.MonitorPublisher; -import org.apache.airavata.gfac.GFacException; import org.apache.airavata.gfac.core.context.JobExecutionContext; import org.apache.airavata.registry.cpi.ExperimentCatalog; import org.apache.curator.framework.CuratorFramework; @@ -49,7 +48,7 @@ public interface GFac { * * @param experimentID * @return boolean Successful acceptence of the jobExecution returns a true value - * @throws org.apache.airavata.gfac.GFacException + * @throws GFacException */ public boolean submitJob(String experimentID,String taskID, String gatewayID, String tokenId) throws GFacException; http://git-wip-us.apache.org/repos/asf/airavata/blob/2f3da010/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacConfiguration.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacConfiguration.java new file mode 100644 index 0000000..ae82a72 --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacConfiguration.java @@ -0,0 +1,289 @@ +/* + * + * 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.gfac.core; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.*; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.airavata.gfac.core.handler.GFacHandlerConfig; +import org.apache.airavata.gfac.core.provider.GFacProviderConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.*; +import org.xml.sax.SAXException; + +public class GFacConfiguration { + public static final Logger log = LoggerFactory.getLogger(GFacConfiguration.class); + + +// private AiravataAPI airavataAPI; + + private static Document handlerDoc; + // Keep list of full qualified class names of GFac handlers which should invoked before + // the provider + private List<GFacHandlerConfig> inHandlers = new ArrayList<GFacHandlerConfig>(); + + // Keep list of full qualified class names of GFac handlers which should invoked after + // the provider + private List<GFacHandlerConfig> outHandlers = new ArrayList<GFacHandlerConfig>(); + + public ExecutionMode executionMode = ExecutionMode.SYNCHRONOUS; // default execution mode is SYNCHRONOUS + + public GFacConfiguration() { + } + +// public AiravataAPI getAiravataAPI() { +// return airavataAPI; +// } + + + public static File getConfigFile() { + URL resource = GFacConfiguration.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML); + File gfacConfigFile = null; + if (resource != null) { + gfacConfigFile = new File(resource.getPath()); + } + return gfacConfigFile; + } + public List<GFacHandlerConfig> getInHandlers() { + //This will avoid the misconfiguration done by user in gfac-config.xml + return removeDuplicateWithOrder(inHandlers); + } + + public List<GFacHandlerConfig> getOutHandlers() { + //This will avoid the misconfiguration done by user in gfac-config.xml + return removeDuplicateWithOrder(outHandlers); + } + public void setInHandlers(List<GFacHandlerConfig> inHandlers) { + this.inHandlers = inHandlers; + } + + public void setOutHandlers(List<GFacHandlerConfig> outHandlers) { + this.outHandlers = outHandlers; + } + + public void setInHandlers(String providerName, String applicationName) { + try { + this.inHandlers = getHandlerConfig(handlerDoc, Constants.XPATH_EXPR_GLOBAL_INFLOW_HANDLERS, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); + if (applicationName != null) { + String xPath = Constants.XPATH_EXPR_APPLICATION_HANDLERS_START + applicationName + Constants.XPATH_EXPR_APPLICATION_INFLOW_HANDLERS_END; + List<GFacHandlerConfig> handlers = getHandlerConfig(handlerDoc, xPath, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); + this.inHandlers.addAll(handlers); + } + if (providerName != null) { + String xPath = Constants.XPATH_EXPR_PROVIDER_HANDLERS_START + providerName + Constants.XPATH_EXPR_PROVIDER_INFLOW_HANDLERS_END; + List<GFacHandlerConfig> handlers = getHandlerConfig(handlerDoc, xPath, Constants.GFAC_CONFIG_APPLICATION_NAME_ATTRIBUTE); + this.inHandlers.addAll(handlers); + } + } catch (XPathExpressionException e) { + new GFacException("Error parsing Handler Configuration", e); + } + } + + public void setOutHandlers(String providerName, String applicationName) { + try { + this.outHandlers = getHandlerConfig(handlerDoc, Constants.XPATH_EXPR_GLOBAL_OUTFLOW_HANDLERS, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); + if (applicationName != null) { + String xPath = Constants.XPATH_EXPR_APPLICATION_HANDLERS_START + applicationName + Constants.XPATH_EXPR_APPLICATION_OUTFLOW_HANDLERS_END; + List<GFacHandlerConfig> handlers = getHandlerConfig(handlerDoc, xPath, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); + this.outHandlers.addAll(handlers); + } + if(providerName != null) { + String xPath = Constants.XPATH_EXPR_PROVIDER_HANDLERS_START + providerName + Constants.XPATH_EXPR_PROVIDER_OUTFLOW_HANDLERS_END; + List<GFacHandlerConfig> handlers = getHandlerConfig(handlerDoc, xPath, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); + this.outHandlers.addAll(handlers); + } + } catch (XPathExpressionException e) { + new GFacException("Error parsing Handler Configuration", e); + } + } + + /** + * Parse GFac configuration file and populate GFacConfiguration object. XML configuration + * file for GFac will look like below. + * <p/> + * <GFac> + * <GlobalHandlers> + * <InHandlers> + * <Handler class="org.apache.airavata.gfac.GlobalHandler1"> + * </InHandler> + * <OutHandlers> + * <Handler class="org.apache.airavata.gfac.GlabalHandler2"> + * </OutHandlers> + * </GlobalHandlers> + * <Provider class="org.apache.airavata.gfac.providers.LocalProvider" host="LocalHost"> + * <InHandlers> + * <Handler class="org.apache.airavata.gfac.handlers.LocalEvenSetupHandler"> + * </InHandlers> + * <OutHandlers> + * <Handler>org.apache.airavata.LocalOutHandler1</Handler> + * </OutHandlers> + * </Provider> + * <Application name="UltraScan"> + * <InHandlers> + * <Handler class="org.apache.airavata.gfac.handlers.LocalEvenSetupHandler"> + * </InHandlers> + * <OutHandlers> + * <Handler class="org.apache.airavata.gfac.LocalOutHandler1"> + * </OutHandlers> + * </Application> + * </GFac> + * + * @param configFile configuration file + * @return GFacConfiguration object. + */ + //FIXME + public static GFacConfiguration create(File configFile, Properties configurationProperties) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); + handlerDoc = docBuilder.parse(configFile); + return new GFacConfiguration(); + } + + private static String xpathGetText(Document doc, String expression) throws XPathExpressionException { + XPathFactory xPathFactory = XPathFactory.newInstance(); + XPath xPath = xPathFactory.newXPath(); + XPathExpression expr = xPath.compile(expression); + + return (String) expr.evaluate(doc, XPathConstants.STRING); + } + + /** + * Select matching node set and extract specified attribute value. + * + * @param doc XML document + * @param expression expression to match node set + * @param attribute name of the attribute to extract + * @return list of attribute values. + * @throws XPathExpressionException + */ + public static List<GFacHandlerConfig> getHandlerConfig(Document doc, String expression, String attribute) throws XPathExpressionException { + XPathFactory xPathFactory = XPathFactory.newInstance(); + XPath xPath = xPathFactory.newXPath(); + XPathExpression expr = xPath.compile(expression); + + NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); + List<GFacHandlerConfig> gFacHandlerConfigs = new ArrayList<GFacHandlerConfig>(); + Properties properties = new Properties(); + String className = ""; + for (int i = 0; i < nl.getLength(); i++) { + className = ((Element) nl.item(i)).getAttribute(attribute); + NodeList childNodes = (nl.item(i)).getChildNodes(); + for(int j = 0;j < childNodes.getLength();j++){ + if(Constants.PROPERTY.equals(childNodes.item(j).getNodeName())) { + String name = ((Element) childNodes.item(j)).getAttribute(Constants.NAME); + String value = ((Element) childNodes.item(j)).getAttribute(Constants.VALUE); + properties.put(name, value); + } + } + GFacHandlerConfig gFacHandlerConfig = new GFacHandlerConfig(properties,className); + gFacHandlerConfigs.add(gFacHandlerConfig); + } + return gFacHandlerConfigs; + } + + public static List<GFacProviderConfig> getProviderConfig(Document doc, String expression, String attribute) throws XPathExpressionException { + XPathFactory xPathFactory = XPathFactory.newInstance(); + XPath xPath = xPathFactory.newXPath(); + XPathExpression expr = xPath.compile(expression); + + NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); + List<GFacProviderConfig> gFacProviderConfigs = new ArrayList<GFacProviderConfig>(); + Map<String, String> properties = new HashMap<String, String>(); + String className = ""; + for (int i = 0; i < nl.getLength(); i++) { + className = ((Element) nl.item(i)).getAttribute(attribute); + if (className != null && !className.equals("")) { + NodeList childNodes = (nl.item(i)).getChildNodes(); + for (int j = 0; j < childNodes.getLength(); j++) { + if (Constants.PROPERTY.equals(childNodes.item(j).getNodeName())) { + String name = ((Element) childNodes.item(j)).getAttribute(Constants.NAME); + String value = ((Element) childNodes.item(j)).getAttribute(Constants.VALUE); + properties.put(name, value); + } + } + GFacProviderConfig gFacProviderConfig = new GFacProviderConfig(properties,className); + gFacProviderConfigs.add(gFacProviderConfig); + } + } + return gFacProviderConfigs; + } + + public static String getAttributeValue(Document doc, String expression, String attribute) throws XPathExpressionException { + XPathFactory xPathFactory = XPathFactory.newInstance(); + XPath xPath = xPathFactory.newXPath(); + XPathExpression expr = xPath.compile(expression); + + NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); + String className = null; + for (int i = 0; i < nl.getLength(); i++) { + className = ((Element) nl.item(i)).getAttribute(attribute); + break; + } + return className; + } + + public static GFacConfiguration create(Properties configProps) { + return null; + } + + private static List removeDuplicateWithOrder(List arlList) { + Set set = new HashSet(); + List newList = new ArrayList(); + for (Iterator iter = arlList.iterator(); iter.hasNext(); ) { + Object element = iter.next(); + if (set.add(element)) + newList.add(element); + } + arlList.clear(); + arlList.addAll(newList); + return arlList; + } + public static List<GFacHandlerConfig> getDaemonHandlers(File configFile)throws ParserConfigurationException, IOException, SAXException, XPathExpressionException{ + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); + handlerDoc = docBuilder.parse(configFile); + return getHandlerConfig(handlerDoc, Constants.XPATH_EXPR_DAEMON_HANDLERS, Constants.GFAC_CONFIG_CLASS_ATTRIBUTE); + } + public static Document getHandlerDoc() { + return handlerDoc; + } + + public ExecutionMode getExecutionMode() { + return executionMode; + } + + public void setExecutionMode(ExecutionMode executionMode) { + this.executionMode = executionMode; + } +}
