You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2011/06/05 07:16:09 UTC

svn commit: r1131734 - in /oodt/trunk: ./ resource/src/main/java/org/apache/oodt/cas/resource/system/ resource/src/test/org/apache/oodt/cas/resource/system/ resource/src/testdata/policy/

Author: mattmann
Date: Sun Jun  5 05:16:08 2011
New Revision: 1131734

URL: http://svn.apache.org/viewvc?rev=1131734&view=rev
Log:
- fix for OODT-198 Add test harness for XmlRpcResourceManager

Added:
    oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/system/
    oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java
    oodt/trunk/resource/src/testdata/policy/
    oodt/trunk/resource/src/testdata/policy/node-to-queue-mapping.xml
    oodt/trunk/resource/src/testdata/policy/nodes.xml
Modified:
    oodt/trunk/CHANGES.txt
    oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java

Modified: oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1131734&r1=1131733&r2=1131734&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Sun Jun  5 05:16:08 2011
@@ -4,6 +4,8 @@ Apache OODT Change Log
 Release 0.3-SNAPSHOT (in progress)
 --------------------------------------------
 
+* OODT-198 Add test harness for XmlRpcResourceManager (mattmann)
+
 * OODT-182 Add ability to change node capacity during execution (Gabe Resneck via mattmann)
 
 * OODT-162 Parametric Data Model File Manager Catalog (mattmann, ahart, cgoodale)

Modified: oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java
URL: http://svn.apache.org/viewvc/oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java?rev=1131734&r1=1131733&r2=1131734&view=diff
==============================================================================
--- oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java (original)
+++ oodt/trunk/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java Sun Jun  5 05:16:08 2011
@@ -314,6 +314,15 @@ public class XmlRpcResourceManager {
     	return new Vector<String>(this.scheduler.getQueueManager().getQueues(nodeId));
     }
     
+    public boolean shutdown(){
+      if (this.webServer != null) {
+        this.webServer.shutdown();
+        this.webServer = null;
+        return true;
+    } else
+        return false;      
+    }
+    
     public static void main(String[] args) throws Exception {
         int portNum = -1;
         String usage = "XmlRpcResourceManager --portNum <port number for xml rpc service>\n";

Added: oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java
URL: http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java?rev=1131734&view=auto
==============================================================================
--- oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java (added)
+++ oodt/trunk/resource/src/test/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java Sun Jun  5 05:16:08 2011
@@ -0,0 +1,176 @@
+/**
+ * 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.resource.system;
+
+//JDK imports
+import java.io.File;
+import java.io.FileFilter;
+import java.net.URL;
+import java.util.Properties;
+
+//Apache imports
+import org.apache.commons.io.FileUtils;
+
+//OODT imports
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ * 
+ * Test harness for the {@link XmlRpcResourceManager}.
+ * 
+ * @author mattmann
+ * @version $Revision$
+ * 
+ */
+public class TestXmlRpcResourceManager extends TestCase {
+
+  private File tmpPolicyDir;
+
+  private XmlRpcResourceManager rm;
+
+  private static final int RM_PORT = 50001;
+
+  /**
+   * @since OODT-182
+   */
+  public void testDynSetNodeCapacity() {
+    XmlRpcResourceManagerClient rmc = null;
+    try {
+      rmc = new XmlRpcResourceManagerClient(new URL("http://localhost:"
+          + RM_PORT));
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
+
+    assertNotNull(rmc);
+    try {
+      rmc.setNodeCapacity("localhost", 8);
+    } catch (MonitorException e) {
+      fail(e.getMessage());
+    }
+
+    int setCapacity = -1;
+    try {
+      setCapacity = rmc.getNodeById("localhost").getCapacity();
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
+    assertEquals(8, setCapacity);
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see junit.framework.TestCase#setUp()
+   */
+  @Override
+  protected void setUp() throws Exception {
+    generateTestConfiguration();
+    this.rm = new XmlRpcResourceManager(RM_PORT);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see junit.framework.TestCase#tearDown()
+   */
+  @Override
+  protected void tearDown() throws Exception {
+    this.rm.shutdown();
+    deleteAllFiles(this.tmpPolicyDir.getAbsolutePath());
+  }
+
+  private void deleteAllFiles(String startDir) {
+    File startDirFile = new File(startDir);
+    File[] delFiles = startDirFile.listFiles();
+
+    if (delFiles != null && delFiles.length > 0) {
+      for (int i = 0; i < delFiles.length; i++) {
+        delFiles[i].delete();
+      }
+    }
+
+    startDirFile.delete();
+
+  }
+
+  private void generateTestConfiguration() {
+    Properties config = new Properties();
+    config.setProperty("resource.batchmgr.factory",
+        "org.apache.oodt.cas.resource.batchmgr.XmlRpcBatchMgrFactory");
+    config.setProperty("resource.monitor.factory",
+        "org.apache.oodt.cas.resource.monitor.AssignmentMonitorFactory");
+    config.setProperty("resource.scheduler.factory",
+        "org.apache.oodt.cas.resource.scheduler.LRUSchedulerFactory");
+    config.setProperty("resource.jobqueue.factory",
+        "org.apache.oodt.cas.resource.jobqueue.JobStackJobQueueFactory");
+    config.setProperty("resource.jobrepo.factory",
+        "org.apache.oodt.cas.resource.jobrepo.MemoryJobRepositoryFactory");
+    config.setProperty("org.apache.oodt.cas.resource.nodes.repo.factory",
+        "org.apache.oodt.cas.resource.noderepo.XmlNodeRepositoryFactory");
+    config.setProperty("org.apache.oodt.cas.resource.queues.repo.factory",
+        "org.apache.oodt.cas.resource.queuerepo.XmlQueueRepositoryFactory");
+
+    config.setProperty(
+        "org.apache.oodt.cas.resource.jobqueue.jobstack.maxstacksize", "1000");
+    config.setProperty("org.apache.oodt.cas.resource.scheduler.wait.seconds",
+        "20");
+
+    config.setProperty(
+        "org.apache.oodt.cas.resource.system.xmlrpc.requestTimeout.minutes",
+        "20");
+    config.setProperty(
+        "org.apache.oodt.cas.resource.system.xmlrpc.connectionTimeout.minutes",
+        "60");
+
+    // stage policy
+    File tmpPolicyDir = null;
+    try {
+      tmpPolicyDir = File.createTempFile("test", "ignore").getParentFile();
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
+    for (File policyFile : new File("./src/testdata/policy")
+        .listFiles(new FileFilter() {
+
+          @Override
+          public boolean accept(File pathname) {
+            return pathname.isFile() && pathname.getName().endsWith(".xml");
+          }
+        })) {
+      try {
+        FileUtils.copyFileToDirectory(policyFile, tmpPolicyDir);
+      } catch (Exception e) {
+        fail(e.getMessage());
+      }
+    }
+
+    config.setProperty("org.apache.oodt.cas.resource.nodes.dirs", tmpPolicyDir
+        .toURI().toString());
+    config.setProperty("org.apache.oodt.cas.resource.nodetoqueues.dirs",
+        tmpPolicyDir.toURI().toString());
+
+    System.getProperties().putAll(config);
+    this.tmpPolicyDir = tmpPolicyDir;
+  }
+
+}

Added: oodt/trunk/resource/src/testdata/policy/node-to-queue-mapping.xml
URL: http://svn.apache.org/viewvc/oodt/trunk/resource/src/testdata/policy/node-to-queue-mapping.xml?rev=1131734&view=auto
==============================================================================
--- oodt/trunk/resource/src/testdata/policy/node-to-queue-mapping.xml (added)
+++ oodt/trunk/resource/src/testdata/policy/node-to-queue-mapping.xml Sun Jun  5 05:16:08 2011
@@ -0,0 +1,26 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more contributor
+license agreements.  See the NOTICE.txt 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.
+-->
+<cas:node-to-queue-mapping xmlns:cas="http://oodt.jpl.nasa.gov/1.0/cas">
+	<node id="localhost">
+		<queues>
+			<queue name="high"/>
+			<queue name="quick"/>
+			<queue name="long"/>
+		</queues>
+	</node>	
+</cas:node-to-queue-mapping>

Added: oodt/trunk/resource/src/testdata/policy/nodes.xml
URL: http://svn.apache.org/viewvc/oodt/trunk/resource/src/testdata/policy/nodes.xml?rev=1131734&view=auto
==============================================================================
--- oodt/trunk/resource/src/testdata/policy/nodes.xml (added)
+++ oodt/trunk/resource/src/testdata/policy/nodes.xml Sun Jun  5 05:16:08 2011
@@ -0,0 +1,23 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more contributor
+license agreements.  See the NOTICE.txt 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.
+-->
+<cas:resourcenodes xmlns:cas="http://oodt.jpl.nasa.gov/1.0/cas">
+	<node nodeId="localhost" ip="http://localhost:2001" capacity="8"/>
+	<!-- EnvReplace Example 
+	<node nodeId="somehost" ip="http://somehost:[BATCH_STUB_PORT]" capacity="8" envReplace="true"/>
+	-->
+</cas:resourcenodes>