airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject [5/7] moving common monitoring classes to gfac-core
Date Mon, 05 May 2014 16:00:13 GMT
http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/notification/listeners/WorkflowTrackingListener.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/notification/listeners/WorkflowTrackingListener.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/notification/listeners/WorkflowTrackingListener.java
new file mode 100644
index 0000000..4f1dd9e
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/notification/listeners/WorkflowTrackingListener.java
@@ -0,0 +1,133 @@
+/*
+ *
+ * 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.notification.listeners;
+
+import com.google.common.eventbus.Subscribe;
+import org.apache.airavata.gfac.core.notification.events.*;
+import org.apache.airavata.workflow.tracking.Notifier;
+import org.apache.airavata.workflow.tracking.NotifierFactory;
+import org.apache.airavata.workflow.tracking.common.DurationObj;
+import org.apache.airavata.workflow.tracking.common.InvocationEntity;
+import org.apache.airavata.workflow.tracking.common.WorkflowTrackingContext;
+
+import java.net.URI;
+import java.util.Properties;
+
+public class WorkflowTrackingListener {
+
+    private Notifier notifier;
+
+    private String topic;
+
+    private URI workflowID;
+
+    private WorkflowTrackingContext context;
+
+    private InvocationEntity initiator;
+
+    private InvocationEntity receiver;
+
+    private DurationObj duration;
+
+    private org.apache.airavata.workflow.tracking.common.InvocationContext invocationContext;
+
+    public WorkflowTrackingListener(String workflowID, String workflowNodeID, String brokerURL, String topic){
+        this.topic = topic;
+        this.workflowID = URI.create(this.topic);
+        this.notifier = NotifierFactory.createNotifier();
+        URI initiatorWorkflowID = URI.create(workflowID);
+        URI initiatorServiceID = URI.create(topic);
+        String initiatorWorkflowNodeID = workflowNodeID;
+        Integer initiatorWorkflowTimeStep = null;
+        this.context = this.notifier.createTrackingContext(new Properties(), brokerURL, initiatorWorkflowID, initiatorServiceID,
+                initiatorWorkflowNodeID, initiatorWorkflowTimeStep);
+        this.context.setTopic(topic);
+        this.initiator = this.notifier.createEntity(initiatorWorkflowID, initiatorServiceID, initiatorWorkflowNodeID,
+                initiatorWorkflowTimeStep);
+
+        URI receiverWorkflowID = this.workflowID;
+        URI receiverServiceID = this.workflowID;
+        String receiverWorkflowNodeID = null;
+        Integer receiverWorkflowTimeStep = null;
+
+        setReceiver(this.notifier.createEntity(receiverWorkflowID, receiverServiceID, receiverWorkflowNodeID,
+                receiverWorkflowTimeStep));
+        // send start workflow
+        this.invocationContext = this.notifier.workflowInvoked(this.context, this.initiator);
+    }
+
+
+
+    @Subscribe
+    public void startExecution(StartExecutionEvent e) {
+        this.duration = this.notifier.computationStarted();
+    }
+
+    @Subscribe
+    public void finishExecution(FinishExecutionEvent e) {
+        this.duration = this.notifier.computationFinished(this.context, this.duration);
+    }
+
+    @Subscribe
+    public void statusChanged(StatusChangeEvent event) {
+        this.notifier.info(this.context, event.getStatusMessage());
+    }
+
+    @Subscribe
+    public void startSchedule(StartScheduleEvent e){
+        this.notifier.info(this.context,e.getEventType());
+    }
+
+    @Subscribe
+    public void executionFail(ExecutionFailEvent e) {
+        this.notifier.sendingFault(this.context, this.invocationContext, e.getCauseForFailure().getMessage());
+    }
+
+
+    @Subscribe
+    public void info(String... data) {
+        this.notifier.info(this.context, data);
+    }
+
+    @Subscribe
+    public void warning(String... data) {
+    }
+
+    @Subscribe
+    public void exception(String... data) {
+    }
+
+    @Subscribe
+    public void finishSchedule(FinishScheduleEvent e){
+        this.notifier.info(this.context,e.getEventType());
+    }
+
+
+    public InvocationEntity getReceiver() {
+        return receiver;
+    }
+
+    public void setReceiver(InvocationEntity receiver) {
+        this.receiver = receiver;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/persistence/JobData.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/persistence/JobData.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/persistence/JobData.java
new file mode 100644
index 0000000..10be472
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/persistence/JobData.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.
+ *
+ */
+
+package org.apache.airavata.gfac.core.persistence;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 2:34 PM
+ */
+
+public class JobData {
+
+    private String jobId;
+    private int state;
+
+    public JobData(String id, int state) {
+        this.jobId = id;
+        this.state = state;
+    }
+
+    public String getJobId() {
+        return jobId;
+    }
+
+    public void setJobId(String jobId) {
+        this.jobId = jobId;
+    }
+
+    public int getState() {
+        return state;
+    }
+
+    public void setState(int state) {
+        this.state = state;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/persistence/JobPersistenceManager.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/persistence/JobPersistenceManager.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/persistence/JobPersistenceManager.java
new file mode 100644
index 0000000..0f7c848
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/persistence/JobPersistenceManager.java
@@ -0,0 +1,76 @@
+/*
+ *
+ * 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.persistence;
+
+
+import org.apache.airavata.gfac.GFacException;
+
+import java.util.List;
+
+/**
+ * User: AmilaJ (amilaj@apache.org)
+ * Date: 6/18/13
+ * Time: 2:23 PM
+ */
+
+/**
+ * Responsible persisting job data. This data is useful during a restart.
+ * When restarting Airavata can resume monitoring currently executing jobs.
+ */
+public interface JobPersistenceManager {
+
+    /**
+     * Updates the job state in the persisting storage.
+     * @param jobData Job data to update.
+     * @throws GFacException If an error occurred while updating job data.
+     */
+    void updateJobStatus (JobData jobData) throws GFacException;
+
+    /**
+     * Get all running jobs.
+     * @return Job ids which are not failed nor completed.
+     * @throws GFacException If an error occurred while querying job data.
+     */
+    List<JobData> getRunningJobs() throws GFacException;
+
+    /**
+     * Get all failed job ids.
+     * @return Failed job ids.
+     * @throws GFacException If an error occurred while querying job data.
+     */
+    List<JobData> getFailedJobs() throws GFacException;
+
+    /**
+     * Get all un-submitted job ids.
+     * @return Un-submitted job ids.
+     * @throws GFacException If an error occurred while querying job data.
+     */
+    List<JobData> getUnSubmittedJobs() throws GFacException;
+
+    /**
+     * Get all successfully completed job ids.
+     * @return Successfully completed job ids.
+     * @throws GFacException If an error occurred while querying job data.
+     */
+    List<JobData> getSuccessfullyCompletedJobs() throws GFacException;
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java
new file mode 100644
index 0000000..4d28d72
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/AbstractProvider.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.provider;
+
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.core.context.JobExecutionContext;
+import org.apache.airavata.model.workspace.experiment.JobDetails;
+import org.apache.airavata.model.workspace.experiment.JobStatus;
+import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
+import org.apache.airavata.registry.cpi.Registry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractProvider implements GFacProvider{
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    protected Registry registry = null;
+	protected JobDetails details;     //todo we need to remove this and add methods to fill Job details, this is not a property of a provider
+	protected JobStatus status;   //todo we need to remove this and add methods to fill Job details, this is not a property of a provider
+	protected JobExecutionContext jobExecutionContext;
+
+	public void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException {
+        log.debug("Initializing " + this.getClass().getName());
+		registry = RegistryFactory.getDefaultRegistry();
+		details = new JobDetails();
+		status = new JobStatus();
+		this.jobExecutionContext=jobExecutionContext;
+	}
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProvider.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProvider.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProvider.java
new file mode 100644
index 0000000..7c17cf2
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProvider.java
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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.provider;
+
+import java.util.Map;
+
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.core.context.JobExecutionContext;
+
+public interface GFacProvider{
+
+    void initProperties(Map<String,String> properties) throws GFacProviderException,GFacException;
+    /**
+     * Initialize environment required for invoking the execute method of the provider. If environment setup is
+     * done during the in handler execution, validation of environment will go here.
+     * @param jobExecutionContext containing job execution related information.
+     * @throws GFacProviderException in case of a error initializing the environment.
+     */
+    void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException,GFacException;
+
+    /**
+     * Invoke the providers intended functionality using information and data in job execution context.
+     * @param jobExecutionContext containing job execution related information.
+     * @throws GFacProviderException in case of a error executing the job.
+     */
+    void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException;
+
+    /**
+     * Cleans up the acquired resources during initialization and execution of the job.
+     * @param jobExecutionContext containing job execution related information.
+     * @throws GFacProviderException in case of a error cleaning resources.
+     */
+    void dispose(JobExecutionContext jobExecutionContext) throws GFacProviderException,GFacException;
+
+    /**
+     * Cancels all jobs relevant to an experiment.
+     * @param jobId The experiment id
+     * @param jobExecutionContext The job execution context, contains runtime information.
+     * @throws GFacException If an error occurred while cancelling the job.
+     */
+    public void cancelJob(String jobId, JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException;
+
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProviderConfig.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProviderConfig.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProviderConfig.java
new file mode 100644
index 0000000..8a85dc4
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProviderConfig.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.provider;
+
+import java.util.Map;
+
+public class GFacProviderConfig {
+
+    public GFacProviderConfig(Map<String, String> properties, String className) {
+        this.properties = properties;
+        this.className = className;
+    }
+
+    private Map<String, String> properties;
+
+    private String className;
+
+    public void setProperties(Map<String, String> properties) {
+        this.properties = properties;
+    }
+
+    public void setClassName(String className) {
+        this.className = className;
+    }
+
+    public Map<String, String> getProperties() {
+        return properties;
+    }
+
+    public String getClassName() {
+        return className;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProviderException.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProviderException.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProviderException.java
new file mode 100644
index 0000000..30f9530
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/GFacProviderException.java
@@ -0,0 +1,50 @@
+/*
+ *
+ * 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.provider;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GFacProviderException extends Exception {
+    private static final Logger log = LoggerFactory.getLogger(GFacProviderException.class);
+
+    private String aditionalInfo[] = null;
+
+    public GFacProviderException(String message) {
+        super(message);
+        log.error(message);
+    }
+
+
+    public GFacProviderException(String message, Throwable cause) {
+        super(message, cause);
+        log.error(message,cause);
+    }
+
+
+    public GFacProviderException(String message, Exception e, String... additionExceptiondata) {
+        super(message);
+        this.aditionalInfo = additionExceptiondata;
+        log.error(message,e);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/DataIDType.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/DataIDType.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/DataIDType.java
new file mode 100644
index 0000000..5028502
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/DataIDType.java
@@ -0,0 +1,95 @@
+/*
+ *
+ * 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.provider.utils;
+
+import org.apache.airavata.gfac.core.provider.GFacProviderException;
+import org.xmlpull.v1.builder.XmlElement;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+
+/**
+ * Represents a DataID (A schema with real names), currently it only sends a one
+ * location value.
+ */
+public class DataIDType {
+    public static final String LOCATION_ATTRIBUTE = "location";
+
+    private URI dataID;
+
+    private ArrayList<URI> dataLocations = new ArrayList<URI>();
+
+    public URI getRealLocation() {
+        if (dataLocations.size() > 0) {
+            return dataLocations.get(0);
+        } else {
+            return null;
+        }
+    }
+
+    public DataIDType(XmlElement ele) throws GFacProviderException {
+        try {
+            String value = ele.requiredTextContent();
+            if (value != null) {
+                this.dataID = new URI(value);
+            } else {
+                throw new GFacProviderException(
+                        "Illegal InputMessage, No value content found for the parameter "
+                                + ele.getName() + "/value. Invalid Local Argument");
+            }
+            String location = ele.getAttributeValue(null, DataIDType.LOCATION_ATTRIBUTE);
+            if (location != null) {
+                addDataLocation(new URI(location));
+            }
+        } catch (URISyntaxException e) {
+            throw new GFacProviderException("Invalid Local Argument", e);
+        }
+    }
+
+    public DataIDType(URI dataID) {
+        super();
+        this.dataID = dataID;
+    }
+
+    public void addDataLocation(URI dataLocation) {
+        dataLocations.add(dataLocation);
+    }
+
+    public ArrayList<URI> getDataLocations() {
+        return dataLocations;
+    }
+
+    public URI getDataID() {
+        return dataID;
+    }
+
+    public void fillData(XmlElement ele) {
+        ele.addChild(dataID.toString());
+        URI location = getRealLocation();
+        if (location != null) {
+            ele.addAttribute(DataIDType.LOCATION_ATTRIBUTE, location.toString());
+        }
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/ProviderUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/ProviderUtils.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/ProviderUtils.java
new file mode 100644
index 0000000..c98da92
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/ProviderUtils.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.provider.utils;
+
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.MappingFactory;
+import org.apache.airavata.gfac.core.context.JobExecutionContext;
+import org.apache.airavata.gfac.core.context.MessageContext;
+import org.apache.airavata.gfac.core.provider.GFacProviderException;
+import org.apache.airavata.schemas.gfac.InputParameterType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ProviderUtils {
+
+    public static List<String> getInputParameters(JobExecutionContext jobExecutionContext) throws GFacProviderException {
+        List<String> parameters = new ArrayList<String>();
+        MessageContext inMessageContext = jobExecutionContext.getInMessageContext();
+        InputParameterType[] inputParamDefinitionArray = jobExecutionContext.getApplicationContext().
+                getServiceDescription().getType().getInputParametersArray();
+        for (InputParameterType inputParam : inputParamDefinitionArray) {
+            String parameterName = inputParam.getParameterName();
+            ActualParameter parameter = (ActualParameter)inMessageContext.getParameter(parameterName);
+            if(parameter == null){
+                throw new GFacProviderException("Cannot find required input parameter " + parameterName + ".");
+            }
+
+            parameters.add(MappingFactory.toString(parameter));
+        }
+
+        return parameters;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/ResourceRequirement.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/ResourceRequirement.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/ResourceRequirement.java
new file mode 100644
index 0000000..2e824b3
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/provider/utils/ResourceRequirement.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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.provider.utils;
+
+public interface ResourceRequirement extends Cloneable {
+	
+	/**
+	 * States whether this resource requirement is active
+	 * and should be written into the job description.
+	 * @return
+	 */
+	public boolean isEnabled();
+	
+	public void setEnabled(boolean enabled);
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/scheduler/HostScheduler.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/scheduler/HostScheduler.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/scheduler/HostScheduler.java
new file mode 100644
index 0000000..1971a7d
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/scheduler/HostScheduler.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.scheduler;
+
+import org.apache.airavata.commons.gfac.type.HostDescription;
+
+import java.util.List;
+
+public  interface HostScheduler {
+    /**
+     * This method will pick a host among set of hosts based on the algorithm users wants to implement, For a single instance
+     * of Airavata users can pick one Scheduler.
+     * @param registeredHosts
+     * @return
+     */
+     public HostDescription schedule(List<HostDescription> registeredHosts);
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/scheduler/impl/SimpleHostScheduler.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/scheduler/impl/SimpleHostScheduler.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/scheduler/impl/SimpleHostScheduler.java
new file mode 100644
index 0000000..c74b6b3
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/scheduler/impl/SimpleHostScheduler.java
@@ -0,0 +1,33 @@
+/*
+ *
+ * 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.scheduler.impl;
+
+import org.apache.airavata.commons.gfac.type.HostDescription;
+import org.apache.airavata.gfac.core.scheduler.HostScheduler;
+
+import java.util.List;
+
+public class SimpleHostScheduler implements HostScheduler {
+    public HostDescription schedule(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/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/utils/GFacUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/utils/GFacUtils.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/utils/GFacUtils.java
new file mode 100644
index 0000000..e13fa3f
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/utils/GFacUtils.java
@@ -0,0 +1,662 @@
+/*
+ *
+ * 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.utils;
+
+import java.io.BufferedReader;
+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.util.*;
+
+import org.apache.airavata.client.api.AiravataAPI;
+import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
+import org.apache.airavata.common.utils.StringUtil;
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+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.model.workspace.experiment.*;
+import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
+import org.apache.airavata.registry.api.workflow.ApplicationJob;
+import org.apache.airavata.registry.api.workflow.ApplicationJob.ApplicationJobStatus;
+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.schemas.gfac.*;
+import org.apache.axiom.om.OMElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GFacUtils {
+    private final static Logger log = LoggerFactory.getLogger(GFacUtils.class);
+
+    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 createUniqueNameForService(String serviceName) {
+        String date = new Date().toString();
+        date = date.replaceAll(" ", "_");
+        date = date.replaceAll(":", "_");
+        return serviceName + "_" + date + "_" + UUID.randomUUID();
+    }
+
+
+
+
+
+    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 ActualParameter getInputActualParameter(Parameter parameter, DataObjectType element) {
+        ActualParameter actualParameter = new ActualParameter();
+        if ("String".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(StringParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((StringParameterType) actualParameter.getType()).setValue(element.getValue());
+            }  else {
+                ((StringParameterType) actualParameter.getType()).setValue("");
+            }
+        } else if ("Double".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(DoubleParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((DoubleParameterType) actualParameter.getType()).setValue(new Double(element.getValue()));
+            }
+        } else if ("Integer".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(IntegerParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((IntegerParameterType) actualParameter.getType()).setValue(new Integer(element.getValue()));
+            }
+        } else if ("Float".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FloatParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((FloatParameterType) actualParameter.getType()).setValue(new Float(element.getValue()));
+            }
+        } else if ("Boolean".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(BooleanParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((BooleanParameterType) actualParameter.getType()).setValue(new Boolean(element.getValue()));
+            }
+        } else if ("File".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FileParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((FileParameterType) actualParameter.getType()).setValue(element.getValue());
+            }
+        } else if ("URI".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(URIParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((URIParameterType) actualParameter.getType()).setValue(element.getValue());
+            } else {
+                ((URIParameterType) actualParameter.getType()).setValue("");
+            }
+
+        } else if ("StdOut".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(StdOutParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((StdOutParameterType) actualParameter.getType()).setValue(element.getValue());
+            } else {
+                ((StdOutParameterType) actualParameter.getType()).setValue("");
+            }
+
+        }
+        else if ("StdErr".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(StdErrParameterType.type);
+            if (!"".equals(element.getValue())) {
+                ((StdErrParameterType) actualParameter.getType()).setValue(element.getValue());
+            } else {
+                ((StdErrParameterType) actualParameter.getType()).setValue("");
+            }
+
+        }
+        return actualParameter;
+    }
+    public static ActualParameter getInputActualParameter(Parameter parameter, OMElement element) {
+        OMElement innerelement = null;
+        ActualParameter actualParameter = new ActualParameter();
+        if ("String".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(StringParameterType.type);
+            if (!"".equals(element.getText())) {
+                ((StringParameterType) actualParameter.getType()).setValue(element.getText());
+            } else if (element.getChildrenWithLocalName("value").hasNext()) {
+                innerelement = (OMElement) element.getChildrenWithLocalName("value").next();
+                ((StringParameterType) actualParameter.getType()).setValue(innerelement.getText());
+            } else {
+                ((StringParameterType) actualParameter.getType()).setValue("");
+            }
+        } else if ("Double".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(DoubleParameterType.type);
+            if (!"".equals(element.getText())) {
+                ((DoubleParameterType) actualParameter.getType()).setValue(new Double(innerelement.getText()));
+            } else {
+                innerelement = (OMElement) element.getChildrenWithLocalName("value").next();
+                ((DoubleParameterType) actualParameter.getType()).setValue(new Double(innerelement.getText()));
+            }
+        } else if ("Integer".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(IntegerParameterType.type);
+            if (!"".equals(element.getText())) {
+                ((IntegerParameterType) actualParameter.getType()).setValue(new Integer(element.getText()));
+            } else {
+                innerelement = (OMElement) element.getChildrenWithLocalName("value").next();
+                ((IntegerParameterType) actualParameter.getType()).setValue(new Integer(innerelement.getText()));
+            }
+        } else if ("Float".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FloatParameterType.type);
+            if (!"".equals(element.getText())) {
+                ((FloatParameterType) actualParameter.getType()).setValue(new Float(element.getText()));
+            } else {
+                innerelement = (OMElement) element.getChildrenWithLocalName("value").next();
+                ((FloatParameterType) actualParameter.getType()).setValue(new Float(innerelement.getText()));
+            }
+        } else if ("Boolean".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(BooleanParameterType.type);
+            if (!"".equals(element.getText())) {
+                ((BooleanParameterType) actualParameter.getType()).setValue(new Boolean(element.getText()));
+            } else {
+                innerelement = (OMElement) element.getChildrenWithLocalName("value").next();
+                ((BooleanParameterType) actualParameter.getType()).setValue(Boolean.parseBoolean(innerelement.getText()));
+            }
+        } else if ("File".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FileParameterType.type);
+            if (!"".equals(element.getText())) {
+                ((FileParameterType) actualParameter.getType()).setValue(element.getText());
+            } else {
+                innerelement = (OMElement) element.getChildrenWithLocalName("value").next();
+                ((FileParameterType) actualParameter.getType()).setValue(innerelement.getText());
+            }
+        } else if ("URI".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(URIParameterType.type);
+            if (!"".equals(element.getText())) {
+                ((URIParameterType) actualParameter.getType()).setValue(element.getText());
+            } else if (element.getChildrenWithLocalName("value").hasNext()) {
+                innerelement = (OMElement) element.getChildrenWithLocalName("value").next();
+                System.out.println(actualParameter.getType().toString());
+                log.debug(actualParameter.getType().toString());
+                ((URIParameterType) actualParameter.getType()).setValue(innerelement.getText());
+            } else {
+                ((URIParameterType) actualParameter.getType()).setValue("");
+            }
+        } else if ("StringArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(StringArrayType.type);
+            Iterator value = element.getChildrenWithLocalName("value");
+            int i = 0;
+            if (!"".equals(element.getText())) {
+                String[] list = StringUtil.getElementsFromString(element.getText());
+                for (String arrayValue : list) {
+                    ((StringArrayType) actualParameter.getType()).insertValue(i++, arrayValue);
+                }
+            } else {
+                while (value.hasNext()) {
+                    innerelement = (OMElement) value.next();
+                    ((StringArrayType) actualParameter.getType()).insertValue(i++, innerelement.getText());
+                }
+            }
+        } else if ("DoubleArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(DoubleArrayType.type);
+            Iterator value = element.getChildrenWithLocalName("value");
+            int i = 0;
+            if (!"".equals(element.getText())) {
+                String[] list = StringUtil.getElementsFromString(element.getText());
+                for (String arrayValue : list) {
+                    ((DoubleArrayType) actualParameter.getType()).insertValue(i++, new Double(arrayValue));
+                }
+            } else {
+                while (value.hasNext()) {
+                    innerelement = (OMElement) value.next();
+                    ((DoubleArrayType) actualParameter.getType()).insertValue(i++, new Double(innerelement.getText()));
+                }
+            }
+
+        } else if ("IntegerArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(IntegerArrayType.type);
+            Iterator value = element.getChildrenWithLocalName("value");
+            int i = 0;
+            if (!"".equals(element.getText())) {
+                String[] list = StringUtil.getElementsFromString(element.getText());
+                for (String arrayValue : list) {
+                    ((IntegerArrayType) actualParameter.getType()).insertValue(i++, new Integer(arrayValue));
+                }
+            } else {
+                while (value.hasNext()) {
+                    innerelement = (OMElement) value.next();
+                    ((IntegerArrayType) actualParameter.getType()).insertValue(i++, new Integer(innerelement.getText()));
+                }
+            }
+        } else if ("FloatArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FloatArrayType.type);
+            Iterator value = element.getChildrenWithLocalName("value");
+            int i = 0;
+            if (!"".equals(element.getText())) {
+                String[] list = StringUtil.getElementsFromString(element.getText());
+                for (String arrayValue : list) {
+                    ((FloatArrayType) actualParameter.getType()).insertValue(i++, new Float(arrayValue));
+                }
+            } else {
+
+                while (value.hasNext()) {
+                    innerelement = (OMElement) value.next();
+                    ((FloatArrayType) actualParameter.getType()).insertValue(i++, new Float(innerelement.getText()));
+                }
+            }
+        } else if ("BooleanArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(BooleanArrayType.type);
+            Iterator value = element.getChildrenWithLocalName("value");
+            int i = 0;
+            if (!"".equals(element.getText())) {
+                String[] list = StringUtil.getElementsFromString(element.getText());
+                for (String arrayValue : list) {
+                    ((BooleanArrayType) actualParameter.getType()).insertValue(i++, new Boolean(arrayValue));
+                }
+            } else {
+
+                while (value.hasNext()) {
+                    innerelement = (OMElement) value.next();
+                    ((BooleanArrayType) actualParameter.getType()).insertValue(i++, new Boolean(innerelement.getText()));
+                }
+            }
+        } else if ("FileArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FileArrayType.type);
+            Iterator value = element.getChildrenWithLocalName("value");
+            int i = 0;
+            if (!"".equals(element.getText())) {
+                String[] list = StringUtil.getElementsFromString(element.getText());
+                for (String arrayValue : list) {
+                    ((FileArrayType) actualParameter.getType()).insertValue(i++, arrayValue);
+                }
+            } else {
+
+                while (value.hasNext()) {
+                    innerelement = (OMElement) value.next();
+                    ((FileArrayType) actualParameter.getType()).insertValue(i++, innerelement.getText());
+                }
+            }
+        } else if ("URIArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(URIArrayType.type);
+            Iterator value = element.getChildrenWithLocalName("value");
+            int i = 0;
+            if (!"".equals(element.getText())) {
+                String[] list = StringUtil.getElementsFromString(element.getText());
+                for (String arrayValue : list) {
+                    ((URIArrayType) actualParameter.getType()).insertValue(i++, arrayValue);
+                }
+            } else {
+
+                while (value.hasNext()) {
+                    innerelement = (OMElement) value.next();
+                    ((URIArrayType) actualParameter.getType()).insertValue(i++, innerelement.getText());
+                }
+            }
+        }
+        return actualParameter;
+    }
+
+    public static ActualParameter getInputActualParameter(Parameter parameter, String inputVal) throws GFacException{
+        OMElement innerelement = null;
+        ActualParameter actualParameter = new ActualParameter();
+        if ("String".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(StringParameterType.type);
+            ((StringParameterType) actualParameter.getType()).setValue(inputVal);
+        } else if ("Double".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(DoubleParameterType.type);
+            ((DoubleParameterType) actualParameter.getType()).setValue(new Double(inputVal));
+        } else if ("Integer".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(IntegerParameterType.type);
+            ((IntegerParameterType) actualParameter.getType()).setValue(new Integer(inputVal));
+        } else if ("Float".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FloatParameterType.type);
+            ((FloatParameterType) actualParameter.getType()).setValue(new Float(inputVal));
+        } else if ("Boolean".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(BooleanParameterType.type);
+            ((BooleanParameterType) actualParameter.getType()).setValue(new Boolean(inputVal));
+        } else if ("File".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FileParameterType.type);
+            ((FileParameterType) actualParameter.getType()).setValue(inputVal);
+        } else if ("URI".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(URIParameterType.type);
+            ((URIParameterType) actualParameter.getType()).setValue(inputVal);
+        } else if ("StringArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(StringArrayType.type);
+            Iterator iterator = Arrays.asList(StringUtil.getElementsFromString(inputVal)).iterator();
+            int i = 0;
+            while (iterator.hasNext()) {
+                innerelement = (OMElement) iterator.next();
+                ((StringArrayType) actualParameter.getType()).insertValue(i++, innerelement.getText());
+            }
+        } else if ("DoubleArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(DoubleArrayType.type);
+            Iterator value = Arrays.asList(StringUtil.getElementsFromString(inputVal)).iterator();
+            int i = 0;
+            while (value.hasNext()) {
+                innerelement = (OMElement) value.next();
+                ((DoubleArrayType) actualParameter.getType()).insertValue(i++, new Double(innerelement.getText()));
+            }
+        } else if ("IntegerArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(IntegerArrayType.type);
+            Iterator value = Arrays.asList(StringUtil.getElementsFromString(inputVal)).iterator();
+            int i = 0;
+            while (value.hasNext()) {
+                innerelement = (OMElement) value.next();
+                ((IntegerArrayType) actualParameter.getType()).insertValue(i++, new Integer(innerelement.getText()));
+            }
+        } else if ("FloatArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FloatArrayType.type);
+            Iterator value = Arrays.asList(StringUtil.getElementsFromString(inputVal)).iterator();
+            int i = 0;
+            while (value.hasNext()) {
+                innerelement = (OMElement) value.next();
+                ((FloatArrayType) actualParameter.getType()).insertValue(i++, new Float(innerelement.getText()));
+            }
+        } else if ("BooleanArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(BooleanArrayType.type);
+            Iterator value = Arrays.asList(StringUtil.getElementsFromString(inputVal)).iterator();
+            int i = 0;
+            while (value.hasNext()) {
+                innerelement = (OMElement) value.next();
+                ((BooleanArrayType) actualParameter.getType()).insertValue(i++, new Boolean(innerelement.getText()));
+            }
+        } else if ("FileArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(FileArrayType.type);
+            Iterator value = Arrays.asList(StringUtil.getElementsFromString(inputVal)).iterator();
+            int i = 0;
+            while (value.hasNext()) {
+                innerelement = (OMElement) value.next();
+                ((FileArrayType) actualParameter.getType()).insertValue(i++, innerelement.getText());
+            }
+        } else if ("URIArray".equals(parameter.getParameterType().getName())) {
+            actualParameter = new ActualParameter(URIArrayType.type);
+            Iterator value = Arrays.asList(StringUtil.getElementsFromString(inputVal)).iterator();
+            int i = 0;
+            while (value.hasNext()) {
+                innerelement = (OMElement) value.next();
+                ((URIArrayType) actualParameter.getType()).insertValue(i++, innerelement.getText());
+            }
+        } else{
+            throw new GFacException("Input parameters are not configured properly ");
+        }
+        return actualParameter;
+    }
+
+
+    public static ApplicationJob createApplicationJob(
+            JobExecutionContext jobExecutionContext) {
+        ApplicationJob appJob = new ApplicationJob();
+        appJob.setExperimentId((String) jobExecutionContext.getProperty(Constants.PROP_TOPIC));
+        appJob.setWorkflowExecutionId(appJob.getExperimentId());
+        appJob.setNodeId((String) jobExecutionContext.getProperty(Constants.PROP_WORKFLOW_NODE_ID));
+        appJob.setServiceDescriptionId(jobExecutionContext.getApplicationContext().getServiceDescription().getType().getName());
+        appJob.setHostDescriptionId(jobExecutionContext.getApplicationContext().getHostDescription().getType().getHostName());
+        appJob.setApplicationDescriptionId(jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType().getApplicationName().getStringValue());
+        return appJob;
+    }
+
+    public static void updateApplicationJobStatusUpdateTime(JobExecutionContext context, String jobId, Date statusUpdateTime) {
+        AiravataAPI airavataAPI = context.getGFacConfiguration().getAiravataAPI();
+        try {
+            airavataAPI.getProvenanceManager().updateApplicationJobStatusUpdateTime(jobId, statusUpdateTime);
+        } catch (AiravataAPIInvocationException e) {
+            log.error("Error in updating application job status time " + statusUpdateTime.toString() + " for job Id " + jobId + "!!!", e);
+        }
+    }
+
+    public static void updateApplicationJobStatus(JobExecutionContext context, String jobId, ApplicationJobStatus status, Date statusUpdateTime) {
+        AiravataAPI airavataAPI = context.getGFacConfiguration().getAiravataAPI();
+        try {
+            airavataAPI.getProvenanceManager().updateApplicationJobStatus(jobId, status, statusUpdateTime);
+        } catch (AiravataAPIInvocationException e) {
+            log.error("Error in updating application job status " + status.toString() + " for job Id " + jobId + "!!!", e);
+        }
+    }
+
+    /**
+     * Gets the job ids given experiment id.
+     *
+     * @param context      The job execution context.
+     * @param experimentId The experiment id.
+     * @return List of job ids relevant to given experiment id.
+     */
+    public static List<ApplicationJob> getJobIds(JobExecutionContext context, String experimentId) {
+
+        AiravataAPI airavataAPI = context.getGFacConfiguration().getAiravataAPI();
+        try {
+            return airavataAPI.getProvenanceManager().getApplicationJobs(experimentId, null, null);
+        } catch (AiravataAPIInvocationException e) {
+            log.error("Error retrieving application jobs for experiment id " + experimentId, e);
+        }
+
+        return new ArrayList<ApplicationJob>(0);
+    }
+
+    /**
+     * Gets the job ids given experiment id and workflow id.
+     *
+     * @param context      The job execution context.
+     * @param experimentId The experiment id.
+     * @param workflowId   The workflow id
+     * @return List of job ids relevant to given experiment id and workflow id.
+     */
+    public static List<ApplicationJob> getJobIds(JobExecutionContext context, String experimentId, String workflowId) {
+
+        AiravataAPI airavataAPI = context.getGFacConfiguration().getAiravataAPI();
+        try {
+            return airavataAPI.getProvenanceManager().getApplicationJobs(experimentId, workflowId, null);
+        } catch (AiravataAPIInvocationException e) {
+            log.error("Error retrieving application jobs for experiment id " + experimentId, " workflow id " +
+                    workflowId, e);
+        }
+
+        return new ArrayList<ApplicationJob>(0);
+    }
+
+    /**
+     * Gets the job ids given experiment id and workflow id.
+     *
+     * @param context      The job execution context.
+     * @param experimentId The experiment id.
+     * @param workflowId   The workflow id
+     * @return List of job ids relevant to given experiment id and workflow id.
+     */
+    public static List<ApplicationJob> getJobIds(JobExecutionContext context, String experimentId,
+                                                 String workflowId, String nodeId) {
+
+        AiravataAPI airavataAPI = context.getGFacConfiguration().getAiravataAPI();
+        try {
+            return airavataAPI.getProvenanceManager().getApplicationJobs(experimentId, workflowId, nodeId);
+        } catch (AiravataAPIInvocationException e) {
+            log.error("Error retrieving application jobs for experiment id " + experimentId, " workflow id " +
+                    workflowId, e);
+        }
+
+        return new ArrayList<ApplicationJob>(0);
+    }
+
+    /*public static RequestData getRequestData(Properties configurationProperties) {
+
+        RequestData requestData = new RequestData();
+
+        requestData.setMyProxyServerUrl(configurationProperties.getProperty(Constants.MYPROXY_SERVER));
+        requestData.setMyProxyUserName(configurationProperties.getProperty(Constants.MYPROXY_USER));
+        requestData.setMyProxyPassword(configurationProperties.getProperty(Constants.MYPROXY_PASS));
+
+        int lifeTime;
+        String sLife = configurationProperties.getProperty(Constants.MYPROXY_LIFE);
+        if (sLife != null) {
+            lifeTime = Integer.parseInt(sLife);
+            requestData.setMyProxyLifeTime(lifeTime);
+        } else {
+            log.info("The configuration does not specify a default life time");
+        }
+
+
+
+    }
+*/
+
+
+    public static void recordApplicationJob(JobExecutionContext context, ApplicationJob job) {
+        AiravataAPI airavataAPI = context.getGFacConfiguration().getAiravataAPI();
+        try {
+            airavataAPI.getProvenanceManager().addApplicationJob(job);
+        } catch (AiravataAPIInvocationException e) {
+            log.error("Error in persisting application job data for application job " + job.getJobId() + "!!!", e);
+        }
+    }
+    public static void saveJobStatus(JobExecutionContext jobExecutionContext, JobDetails details, JobState state) throws GFacException {
+		try {
+			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()));
+		} 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.DataType.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 = RegistryFactory.getDefaultRegistry();
+		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> getMessageContext(List<DataObjectType> experimentData,
+                                                        Parameter[] parameters) throws GFacException {
+        HashMap<String, Object> stringObjectHashMap = new HashMap<String, Object>();
+        Map<String,DataObjectType> map = new HashMap<String,DataObjectType>();
+        for(DataObjectType objectType : experimentData){
+        	map.put(objectType.getKey(), objectType);
+        }
+        for (int i = 0; i < parameters.length; i++) {
+        	DataObjectType input = map.get(parameters[i].getParameterName());
+            if (input != null) {
+                stringObjectHashMap.put(parameters[i].getParameterName(), GFacUtils.getInputActualParameter(parameters[i], input));
+            } else {
+                throw new GFacException("Error finding the parameter: parameter Name" + parameters[i].getParameterName());
+            }
+        }
+        return stringObjectHashMap;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/utils/OutputUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/utils/OutputUtils.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/utils/OutputUtils.java
new file mode 100644
index 0000000..cff1367
--- /dev/null
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/utils/OutputUtils.java
@@ -0,0 +1,105 @@
+/*
+ *
+ * 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.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.airavata.common.utils.StringUtil;
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.MappingFactory;
+import org.apache.airavata.gfac.core.handler.GFacHandlerException;
+import org.apache.airavata.schemas.gfac.StdErrParameterType;
+import org.apache.airavata.schemas.gfac.StdOutParameterType;
+
+public class OutputUtils {
+    private static String regexPattern = "\\s*=\\s*(.*)\\r?\\n";
+
+    public static Map<String, ActualParameter> fillOutputFromStdout(Map<String, Object> output, String stdout, String stderr) throws Exception {
+
+        if (stdout == null || stdout.equals("")){
+            throw new GFacHandlerException("Standard output is empty.");
+        }
+
+        Map<String, ActualParameter> result = new HashMap<String, ActualParameter>();
+        Set<String> keys = output.keySet();
+        for (String paramName : keys) {
+        	ActualParameter actual = (ActualParameter) output.get(paramName);
+            // if parameter value is not already set, we let it go
+            
+            if (actual == null) {
+                continue;
+            }
+            if ("StdOut".equals(actual.getType().getType().toString())) {
+                ((StdOutParameterType) actual.getType()).setValue(stdout);
+                result.put(paramName, actual);
+            } else if ("StdErr".equals(actual.getType().getType().toString())) {
+                ((StdErrParameterType) actual.getType()).setValue(stderr);
+                result.put(paramName, actual);
+            }else if("URI".equals(actual.getType().getType().toString())){
+            	continue;
+            } 
+            else {
+                String parseStdout = parseStdout(stdout, paramName);
+                if (parseStdout != null) {
+                    MappingFactory.fromString(actual, parseStdout);
+                    result.put(paramName, actual);
+                }
+            }
+        }
+
+        return result;
+    }
+
+    private static String parseStdout(String stdout, String outParam) throws Exception {
+        String regex = Pattern.quote(outParam) + regexPattern;
+        String match = null;
+        Pattern pattern = Pattern.compile(regex);
+        Matcher matcher = pattern.matcher(stdout);
+        while (matcher.find()) {
+            match = matcher.group(1);
+        }
+        if (match != null) {
+            match = match.trim();
+            return match;
+        } else {
+            throw new Exception("Data for the output parameter '" + outParam + "' was not found");
+        }
+    }
+
+    public static String[] parseStdoutArray(String stdout, String outParam) throws Exception {
+        String regex = Pattern.quote(outParam) + regexPattern;
+        StringBuffer match = new StringBuffer();
+        Pattern pattern = Pattern.compile(regex);
+        Matcher matcher = pattern.matcher(stdout);
+        while (matcher.find()) {
+            match.append(matcher.group(1) + StringUtil.DELIMETER);
+        }
+        if (match != null) {
+        	return StringUtil.getElementsFromString(match.toString());
+        } else {
+            throw new Exception("Data for the output parameter '" + outParam + "' was not found");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/39370c52/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/cpi/GFac.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/cpi/GFac.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/cpi/GFac.java
deleted file mode 100644
index fc5fd19..0000000
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/cpi/GFac.java
+++ /dev/null
@@ -1,49 +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.cpi;
-
-import org.apache.airavata.gfac.GFacException;
-import org.apache.airavata.gfac.context.JobExecutionContext;
-
-/**
- * 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 {
-
-    /**
-     * 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
-     * @throws org.apache.airavata.gfac.GFacException
-     */
-    public JobExecutionContext submitJob(String experimentID,String taskID) throws GFacException;
-
-    /**
-     *  This method has to be invoked after submitting the job and have to make sure job is properly finished
-     * @param jobExecutionContext
-     * @throws GFacException
-     */
-    public void invokeOutFlowHandlers(JobExecutionContext jobExecutionContext) throws GFacException;
-
-}


Mime
View raw message