Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java?rev=1439743&view=auto ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java (added) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java Tue Jan 29 03:57:41 2013 @@ -0,0 +1,396 @@ +/* + * + * 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.utils; + +import org.apache.airavata.commons.gfac.type.ActualParameter; +import org.apache.airavata.gfac.Constants; +import org.apache.airavata.schemas.gfac.*; +import org.apache.axiom.om.OMElement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.net.InetAddress; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.UUID; + +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); + } + } + } + } + + 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 URI createGsiftpURI(GridFTPContactInfo host, String localPath) throws URISyntaxException { + StringBuffer buf = new StringBuffer(); + + if (!host.hostName.startsWith("gsiftp://")) + buf.append("gsiftp://"); + buf.append(host).append(":").append(host.port); + if (!host.hostName.endsWith("/")) + buf.append("/"); + buf.append(localPath); + return new URI(buf.toString()); + } + + public static URI createGsiftpURI(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 new URI(buf.toString()); + } + + 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 = element.getText().split(","); + 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 = element.getText().split(","); + 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 = element.getText().split(","); + 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 = element.getText().split(","); + 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 = element.getText().split(","); + 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 = element.getText().split(","); + 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 = element.getText().split(","); + 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) { + 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(inputVal.split(",")).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(inputVal.split(",")).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(inputVal.split(",")).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(inputVal.split(",")).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(inputVal.split(",")).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(inputVal.split(",")).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(inputVal.split(",")).iterator(); + int i = 0; + while (value.hasNext()) { + innerelement = (OMElement) value.next(); + ((URIArrayType) actualParameter.getType()).insertValue(i++, innerelement.getText()); + } + } + return actualParameter; + } +}
Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridFTPContactInfo.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridFTPContactInfo.java?rev=1439743&view=auto ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridFTPContactInfo.java (added) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridFTPContactInfo.java Tue Jan 29 03:57:41 2013 @@ -0,0 +1,61 @@ +/* + * + * 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.utils; + +import org.apache.airavata.gfac.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GridFTPContactInfo { + protected final static Logger log = LoggerFactory.getLogger(GridFTPContactInfo.class); + public String hostName; + public int port; + + public GridFTPContactInfo(String hostName, int port) { + if (port <= 0 || port == 80) { + log.debug(hostName + "port recived " + port + " setting it to " + Constants.DEFAULT_GSI_FTP_PORT); + port = Constants.DEFAULT_GSI_FTP_PORT; + } + this.hostName = hostName; + this.port = port; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof GridFTPContactInfo) { + return hostName.equals(((GridFTPContactInfo) obj).hostName) && port == ((GridFTPContactInfo) obj).port; + } else { + return false; + } + } + + @Override + public int hashCode() { + return hostName.hashCode(); + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append(hostName).append(":").append(port); + return buf.toString(); + } +} Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/InputStreamToFileWriter.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/InputStreamToFileWriter.java?rev=1439743&view=auto ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/InputStreamToFileWriter.java (added) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/InputStreamToFileWriter.java Tue Jan 29 03:57:41 2013 @@ -0,0 +1,68 @@ +/* + * + * 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.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; + +public class InputStreamToFileWriter extends Thread{ + protected final Logger log = LoggerFactory.getLogger(this.getClass()); + + private BufferedReader in; + private BufferedWriter out; + + public InputStreamToFileWriter(InputStream in, String out) throws IOException { + this.in = new BufferedReader(new InputStreamReader(in)); + this.out = new BufferedWriter(new FileWriter(out)); + } + + public void run() { + try { + String line = null; + while ((line = in.readLine()) != null) { + if (log.isDebugEnabled()) { + log.debug(line); + } + out.write(line); + out.newLine(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (in != null) { + try { + in.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (out != null) { + try { + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } +} Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/InputUtils.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/InputUtils.java?rev=1439743&view=auto ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/InputUtils.java (added) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/InputUtils.java Tue Jan 29 03:57:41 2013 @@ -0,0 +1,39 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ +package org.apache.airavata.gfac.utils; + +import java.util.List; + +public class InputUtils { + private static final String SPACE = " "; + + private InputUtils() { + } + + public static String buildCommand(List<String> cmdList) { + StringBuffer buff = new StringBuffer(); + for (String string : cmdList) { + buff.append(string); + buff.append(SPACE); + } + return buff.toString(); + } +} Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/LocalProviderUtil.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/LocalProviderUtil.java?rev=1439743&view=auto ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/LocalProviderUtil.java (added) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/LocalProviderUtil.java Tue Jan 29 03:57:41 2013 @@ -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.utils; + +import org.apache.airavata.gfac.context.JobExecutionContext; +import org.apache.airavata.gfac.provider.GFacProviderException; +import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; + +public class LocalProviderUtil { + private static final Logger log = LoggerFactory.getLogger(LocalProviderUtil.class); + + private void makeFileSystemDir(String dir, JobExecutionContext jobExecutionContext) throws GFacProviderException { + File f = new File(dir); + if (f.isDirectory() && f.exists()) { + return; + } else if (!new File(dir).mkdir()) { + throw new GFacProviderException("Cannot make directory " + dir, jobExecutionContext); + } + } + + public void makeDirectory(JobExecutionContext jobExecutionContext) throws GFacProviderException { + ApplicationDeploymentDescriptionType app = jobExecutionContext. + getApplicationContext().getApplicationDeploymentDescription().getType(); + log.info("working diectroy = " + app.getStaticWorkingDirectory()); + log.info("temp directory = " + app.getScratchWorkingDirectory()); + makeFileSystemDir(app.getStaticWorkingDirectory(), jobExecutionContext); + makeFileSystemDir(app.getScratchWorkingDirectory(), jobExecutionContext); + makeFileSystemDir(app.getInputDataDirectory(), jobExecutionContext); + makeFileSystemDir(app.getOutputDataDirectory(), jobExecutionContext); + } + +} Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/OutputUtils.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/OutputUtils.java?rev=1439743&view=auto ============================================================================== --- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/OutputUtils.java (added) +++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/OutputUtils.java Tue Jan 29 03:57:41 2013 @@ -0,0 +1,86 @@ +/* + * + * 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.utils; + +import org.apache.airavata.commons.gfac.type.ActualParameter; +import org.apache.airavata.commons.gfac.type.MappingFactory; +import org.apache.airavata.gfac.context.JobExecutionContext; +import org.apache.airavata.gfac.context.MessageContext; +import org.apache.airavata.schemas.gfac.OutputParameterType; +import org.apache.airavata.schemas.gfac.StdErrParameterType; +import org.apache.airavata.schemas.gfac.StdOutParameterType; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class OutputUtils { + private OutputUtils() { + } + + public static Map<String, ActualParameter> fillOutputFromStdout(JobExecutionContext context, String stdout, String stderr) throws Exception { + + Map<String, ActualParameter> result = new HashMap<String, ActualParameter>(); + OutputParameterType[] outputParametersArray = context.getApplicationContext(). + getServiceDescription().getType().getOutputParametersArray(); + MessageContext outMessageContext = context.getOutMessageContext(); + for (OutputParameterType outparamType : outputParametersArray) { + String parameterName = outparamType.getParameterName(); + ActualParameter actual = (ActualParameter)outMessageContext.getParameter(outparamType.getParameterName()); + // 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(parameterName, actual); + } else if ("StdErr".equals(actual.getType().getType().toString())) { + ((StdErrParameterType) actual.getType()).setValue(stderr); + result.put(parameterName, actual); + } else { + String parseStdout = parseStdout(stdout, parameterName); + if (parseStdout != null) { + MappingFactory.fromString(actual, parseStdout); + result.put(parameterName, actual); + } + } + } + return result; + } + + private static String parseStdout(String stdout, String outParam) throws Exception { + String regex = Pattern.quote(outParam) + "\\s*=\\s*([^\\[\\s'\"][^\\s]*|\"[^\"]*\"|'[^']*'|\\[[^\\[]*\\])"; + 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"); + } + } +}
