You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/06/17 23:19:00 UTC

svn commit: r1137031 - in /oodt/branches/protocol/protocol-api/src/main: java/org/apache/oodt/cas/protocol/action/ java/org/apache/oodt/cas/protocol/verify/ resources/policy/

Author: bfoster
Date: Fri Jun 17 21:19:00 2011
New Revision: 1137031

URL: http://svn.apache.org/viewvc?rev=1137031&view=rev
Log:

- added ProtocolAction which allows the transferring of a file from one site to another site (using different Protocols if necessary

--------------
OODT-194

Added:
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/CrossProtocolTransferAction.java   (with props)
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifierFactory.java   (with props)
Modified:
    oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml
    oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml
    oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-config.xml

Added: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/CrossProtocolTransferAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/CrossProtocolTransferAction.java?rev=1137031&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/CrossProtocolTransferAction.java (added)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/CrossProtocolTransferAction.java Fri Jun 17 21:19:00 2011
@@ -0,0 +1,106 @@
+/*
+ * 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.oodt.cas.protocol.action;
+
+//JDK imports
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.UUID;
+
+//OODT imports
+import org.apache.oodt.cas.protocol.Protocol;
+import org.apache.oodt.cas.protocol.ProtocolFile;
+import org.apache.oodt.cas.protocol.auth.Authentication;
+import org.apache.oodt.cas.protocol.auth.BasicAuthentication;
+import org.apache.oodt.cas.protocol.auth.NoAuthentication;
+import org.apache.oodt.cas.protocol.system.ProtocolManager;
+import org.apache.oodt.cas.protocol.verify.ProtocolVerifier;
+import org.apache.oodt.cas.protocol.verify.ProtocolVerifierFactory;
+
+/**
+ * {@link ProtocolAction} for transferring a file from one host to another
+ *
+ * @author bfoster
+ */
+public class CrossProtocolTransferAction extends ProtocolAction {
+
+	private URI fromUri;
+	private URI toUri;
+	private ProtocolVerifierFactory verifierFactory;
+	
+	@Override
+	public void performAction(ProtocolManager protocolManager) throws Exception {
+		ProtocolVerifier verifier = null;
+		if (verifierFactory != null) {
+			verifier = verifierFactory.newInstance();
+		}
+		
+		File localFile = createTempDownloadFile();
+		if (localFile == null) {
+			throw new Exception("Failed to create tempory local file");
+		}
+		
+		Protocol fromProtocol = protocolManager.getProtocolBySite(fromUri, getAuthentication(fromUri), verifier);
+		if (fromProtocol == null) {
+			throw new Exception("Failed to get protocol for 'from' URI '" + fromUri + "'");
+		}
+		
+		Protocol toProtocol = protocolManager.getProtocolBySite(toUri, getAuthentication(toUri), verifier);
+		if (toProtocol == null) {
+			throw new Exception("Failed to get protocol for 'to' URI '" + toUri + "'");
+		}
+			
+		fromProtocol.get(new ProtocolFile(fromUri.getPath(), false), localFile);
+		toProtocol.put(localFile, new ProtocolFile(toUri.getPath(), false));
+	}
+
+	public void setFromUri(String fromUri) throws URISyntaxException {
+		this.fromUri = new URI(fromUri);
+	}
+	
+	public void setToUri(String toUri) throws URISyntaxException {
+		this.toUri = new URI(toUri);
+	}
+	
+	public void setVerifierFactory(ProtocolVerifierFactory verifierFactory) {
+		this.verifierFactory = verifierFactory;
+	}
+
+	private File createTempDownloadFile() {
+		File bogusFile = null;
+		try {
+			bogusFile = File.createTempFile("bogus", "bogus");
+			File tmpDir = new File(bogusFile.getParentFile(), "ProtocolTransfer/" + UUID.randomUUID().toString());
+			tmpDir.mkdirs();
+			return new File(tmpDir, "temp_file");
+		} catch (Exception e) {
+			return null;
+		} finally {
+			try { bogusFile.delete(); } catch (Exception e) {}
+		}
+	}
+	
+	private Authentication getAuthentication(URI uri) {
+		if (uri.getUserInfo() != null) {
+			String[] userInfo = uri.getUserInfo().split("\\:");
+			return new BasicAuthentication(userInfo[0], userInfo[1]);
+		} else {
+			return new NoAuthentication();
+		}
+	}
+}

Propchange: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/CrossProtocolTransferAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifierFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifierFactory.java?rev=1137031&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifierFactory.java (added)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifierFactory.java Fri Jun 17 21:19:00 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.oodt.cas.protocol.verify;
+
+//JDK imports
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+//OODT imports
+import org.apache.oodt.cas.protocol.ProtocolFile;
+
+/**
+ * {@link ProtocolVerifierFactory} which creates {@link BasicProtocolVerifier}.
+ *
+ * @author bfoster
+ */
+public class BasicProtocolVerifierFactory implements ProtocolVerifierFactory {
+
+	private Map<URI, ProtocolFile> testCdMap;
+	
+	public ProtocolVerifier newInstance() {
+		if (testCdMap != null) {
+			return new BasicProtocolVerifier(testCdMap);
+		} else {
+			return new BasicProtocolVerifier(new HashMap<URI, ProtocolFile>());
+		}
+	}
+
+	public void setTestCdMap(Map<URI, ProtocolFile> testCdMap) {
+		this.testCdMap = testCdMap;
+	}
+}

Propchange: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifierFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml?rev=1137031&r1=1137030&r2=1137031&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml (original)
+++ oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml Fri Jun 17 21:19:00 2011
@@ -13,6 +13,11 @@
 	<bean class="org.apache.oodt.commons.spring.postprocessor.SetIdBeanPostProcessor"/>
 
   <bean id="Download" class="org.apache.oodt.cas.protocol.action.DownloadAction"/>
-	<bean id="GetSupportedFactories" class="org.apache.oodt.cas.protocol.action.GetSupportedFactoriesAction"/>
+  <bean id="GetSupportedFactories" class="org.apache.oodt.cas.protocol.action.GetSupportedFactoriesAction"/>
+	<bean id="CrossProtocolTransfer" class="org.apache.oodt.cas.protocol.action.CrossProtocolTransferAction">
+	 <property name="verifierFactory" ref="BasicVerifier"/>
+	</bean>
+
+  <bean id="BasicVerifier" class="org.apache.oodt.cas.protocol.verify.BasicProtocolVerifierFactory"/>
 	
 </beans>
\ No newline at end of file

Modified: oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml?rev=1137031&r1=1137030&r2=1137031&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml (original)
+++ oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml Fri Jun 17 21:19:00 2011
@@ -1,78 +1,149 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-	
-	Author: bfoster
-	Description: ProtocolManager Configuration
-	
--->
+<!-- Author: bfoster Description: ProtocolManager Configuration -->
 <beans xmlns="http://www.springframework.org/schema/beans"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xmlns:p="http://www.springframework.org/schema/p"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
-	<bean class="org.apache.oodt.commons.spring.postprocessor.SetIdBeanPostProcessor"/>
+	<bean
+		class="org.apache.oodt.commons.spring.postprocessor.SetIdBeanPostProcessor" />
 
-	<bean id="action" lazy-init="true" class="org.apache.oodt.commons.option.CmdLineOption">
-		<property name="shortOption" value="a"/>
-		<property name="longOption" value="action"/>
-		<property name="description" value="The Action to perfrom"/>
-		<property name="hasArgs" value="true"/>
-		<property name="optionArgName" value="bean id"/>
-		<property name="required" value="true"/>
-	</bean>
-		
-	<bean id="user" lazy-init="true" class="org.apache.oodt.commons.option.CmdLineOption">
-		<property name="shortOption" value="u"/>
-		<property name="longOption" value="user"/>
-		<property name="description" value="Username for authentication"/>
-		<property name="hasArgs" value="true"/>
-		<property name="optionArgName" value="username"/>
-		<property name="required" value="false"/>		
+	<bean id="action" lazy-init="true"
+		class="org.apache.oodt.commons.option.CmdLineOption">
+		<property name="shortOption" value="a" />
+		<property name="longOption" value="action" />
+		<property name="description" value="The Action to perfrom" />
+		<property name="hasArgs" value="true" />
+		<property name="optionArgName" value="bean id" />
+		<property name="required" value="true" />
+	</bean>
+
+	<bean id="user" lazy-init="true"
+		class="org.apache.oodt.commons.option.CmdLineOption">
+		<property name="shortOption" value="u" />
+		<property name="longOption" value="user" />
+		<property name="description" value="Username for authentication" />
+		<property name="hasArgs" value="true" />
+		<property name="optionArgName" value="username" />
+		<property name="required" value="false" />
 		<property name="handler">
-			<bean class="org.apache.oodt.commons.option.handler.CmdLineOptionBeanHandler">
+			<bean
+				class="org.apache.oodt.commons.option.handler.CmdLineOptionBeanHandler">
 				<property name="applyToBeans">
 					<list>
-						<bean class="org.apache.oodt.commons.option.handler.BeanInfo" p:bean-ref="Download"/>		
+						<bean class="org.apache.oodt.commons.option.handler.BeanInfo"
+							p:bean-ref="Download" />
 					</list>
 				</property>
 			</bean>
 		</property>
 	</bean>
-	
-	<bean id="pass" lazy-init="true" class="org.apache.oodt.commons.option.CmdLineOption">
-		<property name="shortOption" value="p"/>
-		<property name="longOption" value="pass"/>
-		<property name="description" value="Password for authentication"/>
-		<property name="hasArgs" value="true"/>
-		<property name="optionArgName" value="password"/>
-		<property name="required" value="false"/>		
+
+	<bean id="pass" lazy-init="true"
+		class="org.apache.oodt.commons.option.CmdLineOption">
+		<property name="shortOption" value="p" />
+		<property name="longOption" value="pass" />
+		<property name="description" value="Password for authentication" />
+		<property name="hasArgs" value="true" />
+		<property name="optionArgName" value="password" />
+		<property name="required" value="false" />
 		<property name="handler">
-			<bean class="org.apache.oodt.commons.option.handler.CmdLineOptionBeanHandler">
+			<bean
+				class="org.apache.oodt.commons.option.handler.CmdLineOptionBeanHandler">
 				<property name="applyToBeans">
 					<list>
-						<bean class="org.apache.oodt.commons.option.handler.BeanInfo" p:bean-ref="Download"/>		
+						<bean class="org.apache.oodt.commons.option.handler.BeanInfo"
+							p:bean-ref="Download" />
 					</list>
 				</property>
 			</bean>
 		</property>
 	</bean>
-	
-	<bean id="url" lazy-init="true" class="org.apache.oodt.commons.option.CmdLineOption">
-		<property name="shortOption" value="url"/>
-		<property name="longOption" value="url"/>
-		<property name="description" value="URL to download"/>
-		<property name="hasArgs" value="true"/>
-		<property name="optionArgName" value="URL"/>
-		<property name="required" value="false"/>		
+
+	<bean id="url" lazy-init="true"
+		class="org.apache.oodt.commons.option.CmdLineOption">
+		<property name="shortOption" value="url" />
+		<property name="longOption" value="url" />
+		<property name="description" value="URL to download" />
+		<property name="hasArgs" value="true" />
+		<property name="optionArgName" value="URL" />
+		<property name="required" value="false" />
 		<property name="handler">
-			<bean class="org.apache.oodt.commons.option.handler.CmdLineOptionBeanHandler">
+			<bean
+				class="org.apache.oodt.commons.option.handler.CmdLineOptionBeanHandler">
+				<property name="applyToBeans">
+					<list>
+						<bean class="org.apache.oodt.commons.option.handler.BeanInfo"
+							p:bean-ref="Download" />
+					</list>
+				</property>
+			</bean>
+		</property>
+	</bean>
+
+	<bean id="fromUrl" lazy-init="true"
+		class="org.apache.oodt.commons.option.CmdLineOption">
+		<property name="shortOption" value="fu" />
+		<property name="longOption" value="fromUrl" />
+		<property name="description" value="URL to get file" />
+		<property name="hasArgs" value="true" />
+		<property name="optionArgName" value="URL" />
+    <property name="requiredOptions">
+      <list>
+        <bean class="org.apache.oodt.commons.option.required.RequiredOption">
+          <property name="optionLongName" value="action" />
+          <property name="requireAllValues" value="false" />
+          <property name="optionValues">
+            <list>
+              <value>CrossProtocolTransfer</value>
+            </list>
+          </property>
+        </bean>
+      </list>
+    </property>
+    <property name="handler">
+			<bean
+				class="org.apache.oodt.commons.option.handler.CmdLineOptionBeanHandler">
 				<property name="applyToBeans">
 					<list>
-						<bean class="org.apache.oodt.commons.option.handler.BeanInfo" p:bean-ref="Download"/>		
+						<bean class="org.apache.oodt.commons.option.handler.BeanInfo"
+							p:bean-ref="CrossProtocolTransfer" p:methodName="setFromUri" />
 					</list>
 				</property>
 			</bean>
 		</property>
 	</bean>
-	
+
+	<bean id="toUrl" lazy-init="true"
+		class="org.apache.oodt.commons.option.CmdLineOption">
+		<property name="shortOption" value="tu" />
+		<property name="longOption" value="toUrl" />
+		<property name="description" value="URL to send file" />
+		<property name="hasArgs" value="true" />
+		<property name="optionArgName" value="URL" />
+		<property name="requiredOptions">
+			<list>
+				<bean class="org.apache.oodt.commons.option.required.RequiredOption">
+					<property name="optionLongName" value="action" />
+					<property name="requireAllValues" value="false" />
+					<property name="optionValues">
+						<list>
+							<value>CrossProtocolTransfer</value>
+						</list>
+					</property>
+				</bean>
+			</list>
+		</property>
+		<property name="handler">
+			<bean
+				class="org.apache.oodt.commons.option.handler.CmdLineOptionBeanHandler">
+				<property name="applyToBeans">
+					<list>
+						<bean class="org.apache.oodt.commons.option.handler.BeanInfo"
+							p:bean-ref="CrossProtocolTransfer" p:methodName="setToUri" />
+					</list>
+				</property>
+			</bean>
+		</property>
+	</bean>
+
 </beans>
\ No newline at end of file

Modified: oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-config.xml
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-config.xml?rev=1137031&r1=1137030&r2=1137031&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-config.xml (original)
+++ oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-config.xml Fri Jun 17 21:19:00 2011
@@ -12,6 +12,6 @@
 
   <import resource="protocol-action-beans.xml"/>
   <import resource="protocol-cmd-line-beans.xml"/>
-	<import resource="classpath*:**/*-protocol-config.xml"/>
+	<import resource="classpath*:/org/apache/oodt/cas/protocol/**/*-protocol-config.xml"/>
 	
 </beans>
\ No newline at end of file