http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-client/src/main/java/org/apache/airavata/gfac/cpi/gfac_cpi_serviceConstants.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-client/src/main/java/org/apache/airavata/gfac/cpi/gfac_cpi_serviceConstants.java b/modules/gfac/gfac-client/src/main/java/org/apache/airavata/gfac/cpi/gfac_cpi_serviceConstants.java new file mode 100644 index 0000000..14fd7fe --- /dev/null +++ b/modules/gfac/gfac-client/src/main/java/org/apache/airavata/gfac/cpi/gfac_cpi_serviceConstants.java @@ -0,0 +1,55 @@ + /* + * 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. + */ +/** + * Autogenerated by Thrift Compiler (0.9.1) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.apache.airavata.gfac.cpi; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@SuppressWarnings("all") public class gfac_cpi_serviceConstants { + + public static final String GFAC_CPI_VERSION = "0.13.0"; + +}
http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/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 index 853ffc8..b9c17e7 100644 --- 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 @@ -27,7 +27,7 @@ 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.utils.GFacUtils; +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; http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/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 new file mode 100644 index 0000000..d3e1c70 --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFac.java @@ -0,0 +1,77 @@ +/* + * + * 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 org.airavata.appcatalog.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.Registry; +import org.apache.curator.framework.CuratorFramework; + +/** + * This is the GFac CPI interface which needs to be implemented by an internal class, this simply have a single method to submit a job to + * the resource, required data for the job has to be stored in registry prior to invoke this object. + */ +public interface GFac { + + /** + * Initialized method, this method must call one time before use any other method. + * @param registry + * @param appCatalog + * @param curatorClient + * @param publisher + * @return + */ + public boolean init(Registry registry, AppCatalog appCatalog, CuratorFramework curatorClient, MonitorPublisher publisher); + + /** + * This is the job launching method outsiders of GFac can use, this will invoke the GFac handler chain and providers + * And update the registry occordingly, so the users can query the database to retrieve status and output from Registry + * + * @param experimentID + * @return boolean Successful acceptence of the jobExecution returns a true value + * @throws org.apache.airavata.gfac.GFacException + */ + public boolean submitJob(String experimentID,String taskID, String gatewayID, String tokenId) throws GFacException; + + /** + * This method can be used in a handler to ivvoke outhandler asynchronously + * @param jobExecutionContext + * @throws GFacException + */ + public void invokeOutFlowHandlers(JobExecutionContext jobExecutionContext) throws GFacException; + + /** + * This method can be used to handle re-run case asynchronously + * @param jobExecutionContext + * @throws GFacException + */ + public void reInvokeOutFlowHandlers(JobExecutionContext jobExecutionContext) throws GFacException; + + /** + * This operation can be used to cancel an already running experiment + * @return Successful cancellation will return true + * @throws GFacException + */ + public boolean cancel(String experimentID, String taskID, String gatewayID, String tokenId)throws GFacException; + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacThreadPoolExecutor.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacThreadPoolExecutor.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacThreadPoolExecutor.java new file mode 100644 index 0000000..9ae8c99 --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacThreadPoolExecutor.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; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.logger.AiravataLogger; +import org.apache.airavata.common.logger.AiravataLoggerFactory; +import org.apache.airavata.common.utils.ServerSettings; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class GFacThreadPoolExecutor { + private final static AiravataLogger logger = AiravataLoggerFactory.getLogger(GFacThreadPoolExecutor.class); + public static final String GFAC_THREAD_POOL_SIZE = "gfac.thread.pool.size"; + + private static ExecutorService threadPool; + + public static ExecutorService getCachedThreadPool() { + if(threadPool ==null){ + threadPool = Executors.newCachedThreadPool(); + } + return threadPool; + } + + public static ExecutorService client() throws ApplicationSettingsException { + if(threadPool ==null){ + try { + threadPool = Executors.newFixedThreadPool(Integer.parseInt(ServerSettings.getSetting(GFAC_THREAD_POOL_SIZE))); + } catch (ApplicationSettingsException e) { + logger.error("Error reading " + GFAC_THREAD_POOL_SIZE+ " property"); + throw e; + } + } + return threadPool; + } + + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacUtils.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacUtils.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacUtils.java new file mode 100644 index 0000000..407db94 --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/GFacUtils.java @@ -0,0 +1,708 @@ +/* + * + * 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 org.airavata.appcatalog.cpi.AppCatalog; +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.impl.AppCatalogFactory; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.AiravataZKUtils; +import org.apache.airavata.common.utils.DBUtil; +import org.apache.airavata.common.utils.MonitorPublisher; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.credential.store.store.CredentialReader; +import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl; +import org.apache.airavata.gfac.Constants; +import org.apache.airavata.gfac.ExecutionMode; +import org.apache.airavata.gfac.GFacConfiguration; +import org.apache.airavata.gfac.GFacException; +import org.apache.airavata.gfac.core.context.JobExecutionContext; +import org.apache.airavata.gfac.core.handler.GFacHandlerException; +import org.apache.airavata.gfac.core.states.GfacExperimentState; +import org.apache.airavata.gfac.core.states.GfacHandlerState; +import org.apache.airavata.model.appcatalog.appinterface.InputDataObjectType; +import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType; +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.apache.airavata.model.messaging.event.JobIdentifier; +import org.apache.airavata.model.messaging.event.JobStatusChangeRequestEvent; +import org.apache.airavata.model.messaging.event.TaskIdentifier; +import org.apache.airavata.model.messaging.event.TaskStatusChangeRequestEvent; +import org.apache.airavata.model.workspace.experiment.ActionableGroup; +import org.apache.airavata.model.workspace.experiment.CorrectiveAction; +import org.apache.airavata.model.workspace.experiment.ErrorCategory; +import org.apache.airavata.model.workspace.experiment.ErrorDetails; +import org.apache.airavata.model.workspace.experiment.Experiment; +import org.apache.airavata.model.workspace.experiment.ExperimentState; +import org.apache.airavata.model.workspace.experiment.JobDetails; +import org.apache.airavata.model.workspace.experiment.JobState; +import org.apache.airavata.model.workspace.experiment.JobStatus; +import org.apache.airavata.model.workspace.experiment.TaskState; +import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory; +import org.apache.airavata.registry.cpi.ChildDataType; +import org.apache.airavata.registry.cpi.CompositeIdentifier; +import org.apache.airavata.registry.cpi.Registry; +import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.airavata.registry.cpi.RegistryModelType; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.utils.ZKPaths; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +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 java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.URISyntaxException; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +//import org.apache.airavata.commons.gfac.type.ActualParameter; + +public class GFacUtils { + private final static Logger log = LoggerFactory.getLogger(GFacUtils.class); + public static final ArrayList<ACL> OPEN_ACL_UNSAFE = ZooDefs.Ids.OPEN_ACL_UNSAFE; + + private GFacUtils() { + } + + /** + * Read data from inputStream and convert it to String. + * + * @param in + * @return String read from inputStream + * @throws java.io.IOException + */ + public static String readFromStream(InputStream in) throws IOException { + try { + StringBuffer wsdlStr = new StringBuffer(); + + int read; + + byte[] buf = new byte[1024]; + while ((read = in.read(buf)) > 0) { + wsdlStr.append(new String(buf, 0, read)); + } + return wsdlStr.toString(); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + log.warn("Cannot close InputStream: " + + in.getClass().getName(), e); + } + } + } + } + + /** + * this can be used to do framework opertaions specific to different modes + * + * @param jobExecutionContext + * @return + */ + public static boolean isSynchronousMode( + JobExecutionContext jobExecutionContext) { + GFacConfiguration gFacConfiguration = jobExecutionContext + .getGFacConfiguration(); + if (ExecutionMode.ASYNCHRONOUS.equals(gFacConfiguration + .getExecutionMode())) { + return false; + } + return true; + } + + public static String readFileToString(String file) + throws FileNotFoundException, IOException { + BufferedReader instream = null; + try { + + instream = new BufferedReader(new FileReader(file)); + StringBuffer buff = new StringBuffer(); + String temp = null; + while ((temp = instream.readLine()) != null) { + buff.append(temp); + buff.append(Constants.NEWLINE); + } + return buff.toString(); + } finally { + if (instream != null) { + try { + instream.close(); + } catch (IOException e) { + log.warn("Cannot close FileinputStream", e); + } + } + } + } + + public static boolean isLocalHost(String appHost) + throws UnknownHostException { + String localHost = InetAddress.getLocalHost().getCanonicalHostName(); + return (localHost.equals(appHost) + || Constants.LOCALHOST.equals(appHost) || Constants._127_0_0_1 + .equals(appHost)); + } + + public static String createUniqueNameWithDate(String name) { + String date = new Date().toString(); + date = date.replaceAll(" ", "_"); + date = date.replaceAll(":", "_"); + return name + "_" + date; + } + + public static List<Element> getElementList(Document doc, String expression) throws XPathExpressionException { + XPathFactory xPathFactory = XPathFactory.newInstance(); + XPath xPath = xPathFactory.newXPath(); + XPathExpression expr = xPath.compile(expression); + NodeList nodeList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); + List<Element> elementList = new ArrayList<Element>(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node item = nodeList.item(i); + if (item instanceof Element) { + elementList.add((Element) item); + } + } + return elementList; + } + + public static String createGsiftpURIAsString(String host, String localPath) + throws URISyntaxException { + StringBuffer buf = new StringBuffer(); + if (!host.startsWith("gsiftp://")) + buf.append("gsiftp://"); + buf.append(host); + if (!host.endsWith("/")) + buf.append("/"); + buf.append(localPath); + return buf.toString(); + } + + public static void saveJobStatus(JobExecutionContext jobExecutionContext, + JobDetails details, JobState state) throws GFacException { + try { + // first we save job details to the registry for sa and then save the job status. + Registry registry = jobExecutionContext.getRegistry(); + JobStatus status = new JobStatus(); + status.setJobState(state); + details.setJobStatus(status); + registry.add(ChildDataType.JOB_DETAIL, details, + new CompositeIdentifier(jobExecutionContext.getTaskData() + .getTaskID(), details.getJobID())); + JobIdentifier identifier = new JobIdentifier(details.getJobID(), jobExecutionContext.getTaskData().getTaskID(), + jobExecutionContext.getWorkflowNodeDetails().getNodeInstanceId(), jobExecutionContext.getExperimentID(), + jobExecutionContext.getGatewayID()); + JobStatusChangeRequestEvent jobStatusChangeRequestEvent = new JobStatusChangeRequestEvent(state, identifier); + jobExecutionContext.getMonitorPublisher().publish(jobStatusChangeRequestEvent); + } catch (Exception e) { + throw new GFacException("Error persisting job status" + + e.getLocalizedMessage(), e); + } + } + + public static void updateJobStatus(JobExecutionContext jobExecutionContext, + JobDetails details, JobState state) throws GFacException { + try { + Registry registry = jobExecutionContext.getRegistry(); + JobStatus status = new JobStatus(); + status.setJobState(state); + status.setTimeOfStateChange(Calendar.getInstance() + .getTimeInMillis()); + details.setJobStatus(status); + registry.update( + org.apache.airavata.registry.cpi.RegistryModelType.JOB_DETAIL, + details, details.getJobID()); + } catch (Exception e) { + throw new GFacException("Error persisting job status" + + e.getLocalizedMessage(), e); + } + } + + public static void saveErrorDetails( + JobExecutionContext jobExecutionContext, String errorMessage, + CorrectiveAction action, ErrorCategory errorCatogory) + throws GFacException { + try { + Registry registry = jobExecutionContext.getRegistry(); + ErrorDetails details = new ErrorDetails(); + details.setActualErrorMessage(errorMessage); + details.setCorrectiveAction(action); + details.setActionableGroup(ActionableGroup.GATEWAYS_ADMINS); + details.setCreationTime(Calendar.getInstance().getTimeInMillis()); + details.setErrorCategory(errorCatogory); + registry.add(ChildDataType.ERROR_DETAIL, details, + jobExecutionContext.getTaskData().getTaskID()); + } catch (Exception e) { + throw new GFacException("Error persisting job status" + + e.getLocalizedMessage(), e); + } + } + + public static Map<String, Object> getInputParamMap(List<InputDataObjectType> experimentData) throws GFacException { + Map<String, Object> map = new HashMap<String, Object>(); + for (InputDataObjectType objectType : experimentData) { + map.put(objectType.getName(), objectType); + } + return map; + } + + public static Map<String, Object> getOuputParamMap(List<OutputDataObjectType> experimentData) throws GFacException { + Map<String, Object> map = new HashMap<String, Object>(); + for (OutputDataObjectType objectType : experimentData) { + map.put(objectType.getName(), objectType); + } + return map; + } + + public static GfacExperimentState getZKExperimentState(CuratorFramework curatorClient, + JobExecutionContext jobExecutionContext) + throws Exception { + String expState = AiravataZKUtils.getExpState(curatorClient, jobExecutionContext + .getExperimentID()); + if (expState == null || expState.isEmpty()) { + return GfacExperimentState.UNKNOWN; + } + return GfacExperimentState.findByValue(Integer.valueOf(expState)); + } + + public static boolean createHandlerZnode(CuratorFramework curatorClient, + JobExecutionContext jobExecutionContext, String className) + throws Exception { + String expState = AiravataZKUtils.getExpZnodeHandlerPath( + jobExecutionContext.getExperimentID(), className); + Stat exists = curatorClient.checkExists().forPath(expState); + if (exists == null) { + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE).forPath(expState, new byte[0]); + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE, new byte[0]); + } else { + exists = curatorClient.checkExists().forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE); + if (exists == null) { + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE, new byte[0]); + } + } + + exists = curatorClient.checkExists().forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE); + if (exists != null) { + curatorClient.setData().withVersion(exists.getVersion()) + .forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE, + String.valueOf(GfacHandlerState.INVOKING.getValue()).getBytes()); + } + return true; + } + + public static boolean createHandlerZnode(CuratorFramework curatorClient, + JobExecutionContext jobExecutionContext, String className, + GfacHandlerState state) throws Exception { + String expState = AiravataZKUtils.getExpZnodeHandlerPath( + jobExecutionContext.getExperimentID(), className); + Stat exists = curatorClient.checkExists().forPath(expState); + if (exists == null) { + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(expState, new byte[0]); + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE, new byte[0]); + } else { + exists = curatorClient.checkExists().forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE); + if (exists == null) { + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE, new byte[0]); + } + } + + exists = curatorClient.checkExists().forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE); + if (exists != null) { + curatorClient.setData().withVersion(exists.getVersion()) + .forPath(expState + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE, + String.valueOf(state.getValue()).getBytes()); + } + return true; + } + + public static boolean updateHandlerState(CuratorFramework curatorClient, + JobExecutionContext jobExecutionContext, String className, + GfacHandlerState state) throws Exception { + String handlerPath = AiravataZKUtils.getExpZnodeHandlerPath( + jobExecutionContext.getExperimentID(), className); + Stat exists = curatorClient.checkExists().forPath(handlerPath + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE); + if (exists != null) { + curatorClient.setData().withVersion(exists.getVersion()) + .forPath(handlerPath + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE, String.valueOf(state.getValue()).getBytes()); + } else { + createHandlerZnode(curatorClient, jobExecutionContext, className, state); + } + return false; + } + + public static GfacHandlerState getHandlerState(CuratorFramework curatorClient, + JobExecutionContext jobExecutionContext, String className) { + try { + String handlerPath = AiravataZKUtils.getExpZnodeHandlerPath( jobExecutionContext.getExperimentID(), className); + Stat exists = curatorClient.checkExists().forPath(handlerPath + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE); + if (exists != null) { + String stateVal = new String(curatorClient.getData().storingStatIn(exists) + .forPath(handlerPath + File.separator + AiravataZKUtils.ZK_EXPERIMENT_STATE_NODE)); + return GfacHandlerState.findByValue(Integer.valueOf(stateVal)); + } + return GfacHandlerState.UNKNOWN; // if the node doesn't exist or any other error we + // return false + } catch (Exception e) { + log.error("Error occured while getting zk node status", e); + return null; + } + } + + // This method is dangerous because of moving the experiment data + public static boolean createExperimentEntryForPassive(String experimentID, + String taskID, CuratorFramework curatorClient, String experimentNode, + String pickedChild, String tokenId, long deliveryTag) throws Exception { + String experimentPath = experimentNode + File.separator + pickedChild; + String newExperimentPath = experimentPath + File.separator + experimentID; + Stat exists1 = curatorClient.checkExists().forPath(newExperimentPath); + String oldExperimentPath = GFacUtils.findExperimentEntry(experimentID, curatorClient); + if (oldExperimentPath == null) { // this means this is a very new experiment + // are going to create a new node + log.info("This is a new Job, so creating all the experiment docs from the scratch"); + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE).forPath(newExperimentPath, new byte[0]); + String stateNodePath = curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(newExperimentPath + File.separator + "state", + String .valueOf(GfacExperimentState.LAUNCHED.getValue()) .getBytes()); + + if(curatorClient.checkExists().forPath(stateNodePath)!=null) { + log.info("Created the node: " + stateNodePath + " successfully !"); + }else { + log.error("Error creating node: " + stateNodePath + " successfully !"); + } + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(newExperimentPath + AiravataZKUtils.DELIVERY_TAG_POSTFIX, longToBytes(deliveryTag)); + } else { + log.error("ExperimentID: " + experimentID + " taskID: " + taskID + " was running by some Gfac instance,but it failed"); + removeCancelDeliveryTagNode(oldExperimentPath, curatorClient); // remove previous cancel deliveryTagNode + if(newExperimentPath.equals(oldExperimentPath)){ + log.info("Re-launch experiment came to the same GFac instance"); + }else { + log.info("Re-launch experiment came to a new GFac instance so we are moving data to new gfac node"); + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE).forPath(newExperimentPath, + curatorClient.getData().storingStatIn(exists1).forPath(oldExperimentPath)); // recursively copy children + copyChildren(curatorClient, oldExperimentPath, newExperimentPath, 2); // we need to copy children up to depth 2 + String oldDeliveryTag = oldExperimentPath + AiravataZKUtils.DELIVERY_TAG_POSTFIX; + Stat exists = curatorClient.checkExists().forPath(oldDeliveryTag); + if(exists!=null) { + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(newExperimentPath + AiravataZKUtils.DELIVERY_TAG_POSTFIX, + curatorClient.getData().storingStatIn(exists).forPath(oldDeliveryTag)); + ZKPaths.deleteChildren(curatorClient.getZookeeperClient().getZooKeeper(), oldDeliveryTag, true); + } + // After all the files are successfully transfered we delete the // old experiment,otherwise we do + // not delete a single file + log.info("After a successful copying of experiment data for an old experiment we delete the old data"); + log.info("Deleting experiment data: " + oldExperimentPath); + ZKPaths.deleteChildren(curatorClient.getZookeeperClient().getZooKeeper(), oldExperimentPath, true); + } + } + return true; + } + + private static void removeCancelDeliveryTagNode(String experimentPath, CuratorFramework curatorClient) throws Exception { + Stat exists = curatorClient.checkExists().forPath(experimentPath + AiravataZKUtils.CANCEL_DELIVERY_TAG_POSTFIX); + if (exists != null) { + ZKPaths.deleteChildren(curatorClient.getZookeeperClient().getZooKeeper(), experimentPath + AiravataZKUtils.CANCEL_DELIVERY_TAG_POSTFIX, true); + } + } + + private static void copyChildren(CuratorFramework curatorClient, String oldPath, String newPath, int depth) throws Exception { + for (String childNode : curatorClient.getChildren().forPath(oldPath)) { + String oldChildPath = oldPath + File.separator + childNode; + Stat stat = curatorClient.checkExists().forPath(oldChildPath); // no need to check exists + String newChildPath = newPath + File.separator + childNode; + log.info("Creating new znode: " + newChildPath); + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(newChildPath, curatorClient.getData().storingStatIn(stat).forPath(oldChildPath)); + if (--depth > 0) { + copyChildren(curatorClient , oldChildPath, newChildPath, depth ); + } + } + } + + /** + * This will return a value if the server is down because we iterate through exisiting experiment nodes, not + * through gfac-server nodes + * + * @param experimentID + * @param curatorClient + * @return + * @throws KeeperException + * @throws InterruptedException + */ + public static String findExperimentEntry(String experimentID, CuratorFramework curatorClient) throws Exception { + String experimentNode = ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_GFAC_EXPERIMENT_NODE, "/gfac-experiments"); + List<String> children = curatorClient.getChildren().forPath(experimentNode); + for (String pickedChild : children) { + String experimentPath = experimentNode + File.separator + pickedChild; + String newExpNode = experimentPath + File.separator + experimentID; + Stat exists = curatorClient.checkExists().forPath(newExpNode); + if (exists == null) { + continue; + } else { + return newExpNode; + } + } + return null; + } + + public static boolean setExperimentCancel(String experimentId, CuratorFramework curatorClient, long deliveryTag) throws Exception { + String experimentEntry = GFacUtils.findExperimentEntry(experimentId, curatorClient); + if (experimentEntry == null) { + // This should be handle in validation request. Gfac shouldn't get any invalidate experiment. + log.error("Cannot find the experiment Entry, so cancel operation cannot be performed. " + + "This happen when experiment completed and already removed from the zookeeper"); + return false; + } else { + // check cancel operation is being processed for the same experiment. + Stat cancelState = curatorClient.checkExists().forPath(experimentEntry + AiravataZKUtils.CANCEL_DELIVERY_TAG_POSTFIX); + if (cancelState != null) { + // another cancel operation is being processed. only one cancel operation can exist for a given experiment. + return false; + } + + curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) + .forPath(experimentEntry + AiravataZKUtils.CANCEL_DELIVERY_TAG_POSTFIX, longToBytes(deliveryTag)); // save cancel delivery tag to be acknowledge at the end. + return true; + } + + } + public static boolean isCancelled(String experimentID, CuratorFramework curatorClient ) throws Exception { + String experimentEntry = GFacUtils.findExperimentEntry(experimentID, curatorClient); + if(experimentEntry == null){ + return false; + }else { + Stat exists = curatorClient.checkExists().forPath(experimentEntry); + if (exists != null) { + String operation = new String(curatorClient.getData().storingStatIn(exists).forPath(experimentEntry + File.separator + "operation")); + if ("cancel".equals(operation)) { + return true; + } + } + } + return false; + } + + public static void saveHandlerData(JobExecutionContext jobExecutionContext, + StringBuffer data, String className) throws GFacHandlerException { + try { + CuratorFramework curatorClient = jobExecutionContext.getCuratorClient(); + if (curatorClient != null) { + String expZnodeHandlerPath = AiravataZKUtils + .getExpZnodeHandlerPath( + jobExecutionContext.getExperimentID(), + className); + Stat exists = curatorClient.checkExists().forPath(expZnodeHandlerPath); + if (exists != null) { + curatorClient.setData().withVersion(exists.getVersion()).forPath(expZnodeHandlerPath, data.toString().getBytes()); + } else { + log.error("Saving Handler data failed, Stat is null"); + } + } + } catch (Exception e) { + throw new GFacHandlerException(e); + } + } + + public static String getHandlerData(JobExecutionContext jobExecutionContext, String className) throws Exception { + CuratorFramework curatorClient = jobExecutionContext.getCuratorClient(); + if (curatorClient != null) { + String expZnodeHandlerPath = AiravataZKUtils + .getExpZnodeHandlerPath( + jobExecutionContext.getExperimentID(), + className); + Stat exists = curatorClient.checkExists().forPath(expZnodeHandlerPath); + return new String(jobExecutionContext.getCuratorClient().getData().storingStatIn(exists).forPath(expZnodeHandlerPath)); + } + return null; + } + + public static CredentialReader getCredentialReader() + throws ApplicationSettingsException, IllegalAccessException, + InstantiationException { + try{ + String jdbcUrl = ServerSettings.getCredentialStoreDBURL(); + String jdbcUsr = ServerSettings.getCredentialStoreDBUser(); + String jdbcPass = ServerSettings.getCredentialStoreDBPassword(); + String driver = ServerSettings.getCredentialStoreDBDriver(); + return new CredentialReaderImpl(new DBUtil(jdbcUrl, jdbcUsr, jdbcPass, + driver)); + }catch(ClassNotFoundException e){ + log.error("Not able to find driver: " + e.getLocalizedMessage()); + return null; + } + } + + public static LOCALSubmission getLocalJobSubmission (String submissionId) throws AppCatalogException{ + try { + AppCatalog appCatalog = AppCatalogFactory.getAppCatalog(); + return appCatalog.getComputeResource().getLocalJobSubmission(submissionId); + }catch (Exception e){ + String errorMsg = "Error while retrieving local job submission with submission id : " + submissionId; + log.error(errorMsg, e); + throw new AppCatalogException(errorMsg, e); + } + } + + public static UnicoreJobSubmission getUnicoreJobSubmission (String submissionId) throws AppCatalogException{ + try { + AppCatalog appCatalog = AppCatalogFactory.getAppCatalog(); + return appCatalog.getComputeResource().getUNICOREJobSubmission(submissionId); + }catch (Exception e){ + String errorMsg = "Error while retrieving UNICORE job submission with submission id : " + submissionId; + log.error(errorMsg, e); + throw new AppCatalogException(errorMsg, e); + } + } + + public static SSHJobSubmission getSSHJobSubmission (String submissionId) throws AppCatalogException{ + try { + AppCatalog appCatalog = AppCatalogFactory.getAppCatalog(); + return appCatalog.getComputeResource().getSSHJobSubmission(submissionId); + }catch (Exception e){ + String errorMsg = "Error while retrieving SSH job submission with submission id : " + submissionId; + log.error(errorMsg, e); + throw new AppCatalogException(errorMsg, e); + } + } + + /** + * To convert list to separated value + * @param listOfStrings + * @param separator + * @return + */ + public static String listToCsv(List<String> listOfStrings, char separator) { + StringBuilder sb = new StringBuilder(); + + // all but last + for(int i = 0; i < listOfStrings.size() - 1 ; i++) { + sb.append(listOfStrings.get(i)); + sb.append(separator); + } + + // last string, no separator + if(listOfStrings.size() > 0){ + sb.append(listOfStrings.get(listOfStrings.size()-1)); + } + + return sb.toString(); + } + + public static byte[] longToBytes(long x) { + ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); + buffer.putLong(x); + return buffer.array(); + } + + public static long bytesToLong(byte[] bytes) { + ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); + buffer.put(bytes); + buffer.flip();//need flip + return buffer.getLong(); + } + + public static ExperimentState updateExperimentStatus(String experimentId, ExperimentState state) throws RegistryException { + Registry airavataRegistry = RegistryFactory.getDefaultRegistry(); + Experiment details = (Experiment) airavataRegistry.get(RegistryModelType.EXPERIMENT, experimentId); + if (details == null) { + details = new Experiment(); + details.setExperimentID(experimentId); + } + org.apache.airavata.model.workspace.experiment.ExperimentStatus status = new org.apache.airavata.model.workspace.experiment.ExperimentStatus(); + status.setExperimentState(state); + status.setTimeOfStateChange(Calendar.getInstance().getTimeInMillis()); + if (!ExperimentState.CANCELED.equals(details.getExperimentStatus().getExperimentState()) && + !ExperimentState.CANCELING.equals(details.getExperimentStatus().getExperimentState())) { + status.setExperimentState(state); + } else { + status.setExperimentState(details.getExperimentStatus().getExperimentState()); + } + details.setExperimentStatus(status); + log.info("Updating the experiment status of experiment: " + experimentId + " to " + status.getExperimentState().toString()); + airavataRegistry.update(RegistryModelType.EXPERIMENT_STATUS, status, experimentId); + return details.getExperimentStatus().getExperimentState(); + } + + public static boolean isFailedJob (JobExecutionContext jec) { + JobStatus jobStatus = jec.getJobDetails().getJobStatus(); + if (jobStatus.getJobState() == JobState.FAILED) { + return true; + } + return false; + } + + public static boolean ackCancelRequest(String experimentId, CuratorFramework curatorClient) throws Exception { + String experimentEntry = GFacUtils.findExperimentEntry(experimentId, curatorClient); + String cancelNodePath = experimentEntry + AiravataZKUtils.CANCEL_DELIVERY_TAG_POSTFIX; + if (experimentEntry == null) { + // This should be handle in validation request. Gfac shouldn't get any invalidate experiment. + log.error("Cannot find the experiment Entry, so cancel operation cannot be performed. " + + "This happen when experiment completed and already removed from the CuratorFramework"); + } else { + // check cancel operation is being processed for the same experiment. + Stat cancelState = curatorClient.checkExists().forPath(cancelNodePath); + if (cancelState != null) { + ZKPaths.deleteChildren(curatorClient.getZookeeperClient().getZooKeeper(), cancelNodePath, true); + return true; + } + } + return false; + } + + public static void publishTaskStatus (JobExecutionContext jobExecutionContext, MonitorPublisher publisher, TaskState state){ + TaskIdentifier taskIdentity = new TaskIdentifier(jobExecutionContext.getTaskData().getTaskID(), + jobExecutionContext.getWorkflowNodeDetails().getNodeInstanceId(), + jobExecutionContext.getExperimentID(), + jobExecutionContext.getGatewayID()); + publisher.publish(new TaskStatusChangeRequestEvent(state, taskIdentity)); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/AuthenticationInfo.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/AuthenticationInfo.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/AuthenticationInfo.java new file mode 100644 index 0000000..2a01e9d --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/AuthenticationInfo.java @@ -0,0 +1,32 @@ +package org.apache.airavata.gfac.core.authentication;/* + * + * 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. + * + */ + +/** + * User: AmilaJ ([email protected]) + * Date: 10/4/13 + * Time: 11:25 AM + */ + +/** + * An empty interface that represents authentication data to the API. + */ +public interface AuthenticationInfo { +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/GSIAuthenticationInfo.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/GSIAuthenticationInfo.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/GSIAuthenticationInfo.java new file mode 100644 index 0000000..91b3d83 --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/GSIAuthenticationInfo.java @@ -0,0 +1,43 @@ +package org.apache.airavata.gfac.core.authentication;/* + * + * 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. + * + */ + +import org.ietf.jgss.GSSCredential; + +import java.util.Properties; + +/** + * Authentication data. Could be MyProxy user name, password, could be GSSCredentials + * or could be SSH keys. + */ +public abstract class GSIAuthenticationInfo implements AuthenticationInfo { + + public Properties properties = new Properties(); + + public abstract GSSCredential getCredentials() throws SecurityException; + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java new file mode 100644 index 0000000..41b8c9e --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java @@ -0,0 +1,46 @@ +package org.apache.airavata.gfac.core.authentication;/* + * + * 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. + * + */ + +/** + * User: AmilaJ ([email protected]) + * Date: 10/4/13 + * Time: 2:39 PM + */ + +/** + * Abstracts out common methods for SSH key authentication. + */ +public interface SSHKeyAuthentication extends AuthenticationInfo { + + /** + * This is needed only if private key and public keys are encrypted. + * If they are not encrypted we can just return null. + * @return User should return pass phrase if keys are encrypted. If not null. + */ + String getPassPhrase(); + + /** + * Callback with the banner message. API user can get hold of banner message + * by implementing this method. + * @param message The banner message. + */ + void bannerMessage(String message); +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPasswordAuthentication.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPasswordAuthentication.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPasswordAuthentication.java new file mode 100644 index 0000000..e5b867b --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPasswordAuthentication.java @@ -0,0 +1,43 @@ +/* + * + * 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.authentication; + +/** + * User: AmilaJ ([email protected]) + * Date: 10/4/13 + * Time: 11:22 AM + */ + +/** + * Password authentication for vanilla SSH. + */ +public interface SSHPasswordAuthentication extends AuthenticationInfo { + + /** + * Gets the password for given host name and given user name. + * @param userName The connecting user name name. + * @param hostName The connecting host. + * @return Password for the given user. + */ + String getPassword(String userName, String hostName); + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPublicKeyAuthentication.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPublicKeyAuthentication.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPublicKeyAuthentication.java new file mode 100644 index 0000000..8824f5b --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPublicKeyAuthentication.java @@ -0,0 +1,54 @@ +/* + * + * 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.authentication; + +/** + * User: AmilaJ ([email protected]) + * Date: 10/4/13 + * Time: 9:48 AM + */ + + +/** + * Public key authentication for vanilla SSH. + * The public key and private key are returned as byte arrays. Useful when we store private key/public key + * in a secure storage such as credential store. API user should implement this. + */ +public interface SSHPublicKeyAuthentication extends SSHKeyAuthentication { + + /** + * Gets the public key as byte array. + * @param userName The user who is trying to SSH + * @param hostName The host which user wants to connect to. + * @return The public key as a byte array. + */ + byte[] getPrivateKey(String userName, String hostName); + + /** + * Gets the private key as byte array. + * @param userName The user who is trying to SSH + * @param hostName The host which user wants to connect to. + * @return The private key as a byte array. + */ + byte[] getPublicKey(String userName, String hostName); + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPublicKeyFileAuthentication.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPublicKeyFileAuthentication.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPublicKeyFileAuthentication.java new file mode 100644 index 0000000..f98e945 --- /dev/null +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHPublicKeyFileAuthentication.java @@ -0,0 +1,52 @@ +package org.apache.airavata.gfac.core.authentication;/* + * + * 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. + * + */ + + +/** + * User: AmilaJ ([email protected]) + * Date: 10/4/13 + * Time: 9:52 AM + */ + +/** + * Public key authentication for vanilla SSH. + * The public key and private key stored files are returned. API user should implement this. + */ +public interface SSHPublicKeyFileAuthentication extends SSHKeyAuthentication { + + /** + * The file which contains the public key. + * @param userName The user who is trying to SSH + * @param hostName The host which user wants to connect to. + * @return The name of the file which contains the public key. + */ + String getPublicKeyFile(String userName, String hostName); + + /** + * The file which contains the public key. + * @param userName The user who is trying to SSH + * @param hostName The host which user wants to connect to. + * @return The name of the file which contains the private key. + */ + String getPrivateKeyFile(String userName, String hostName); + + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/JobExecutionContext.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/JobExecutionContext.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/JobExecutionContext.java index 1baf792..67c80cf 100644 --- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/JobExecutionContext.java +++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/JobExecutionContext.java @@ -34,8 +34,7 @@ import org.apache.airavata.common.utils.MonitorPublisher; import org.apache.airavata.gfac.GFacConfiguration; import org.apache.airavata.gfac.GFacException; import org.apache.airavata.gfac.SecurityContext; -import org.apache.airavata.gfac.core.cpi.GFac; -import org.apache.airavata.gfac.core.notification.GFacNotifier; +import org.apache.airavata.gfac.core.GFac; import org.apache.airavata.gfac.core.provider.GFacProvider; import org.apache.airavata.model.appcatalog.computeresource.*; import org.apache.airavata.model.workspace.experiment.Experiment; @@ -54,7 +53,6 @@ public class JobExecutionContext extends AbstractContext implements Serializable private ApplicationContext applicationContext; private MessageContext inMessageContext; private MessageContext outMessageContext; - private GFacNotifier notifier; //FIXME : not needed for gfac private Experiment experiment; private TaskDetails taskData; @@ -166,7 +164,6 @@ public class JobExecutionContext extends AbstractContext implements Serializable public JobExecutionContext(GFacConfiguration gFacConfiguration,String applicationName){ this.gfacConfiguration = gFacConfiguration; - notifier = new GFacNotifier(); setApplicationName(applicationName); outputFileList = new ArrayList<String>(); } @@ -223,10 +220,6 @@ public class JobExecutionContext extends AbstractContext implements Serializable return gfacConfiguration; } - public GFacNotifier getNotificationService(){ - return notifier; - } - public GFacProvider getProvider() { return provider; } @@ -259,10 +252,6 @@ public class JobExecutionContext extends AbstractContext implements Serializable this.applicationName = applicationName; } - public GFacNotifier getNotifier() { - return notifier; - } - public boolean isInPath() { return inPath; }
