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 2018/03/12 04:35:39 UTC
[2/2] oodt git commit: Altered resource manager client CLI to use
avro resource manager client
Altered resource manager client CLI to use avro resource manager client
Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/9feacbb0
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/9feacbb0
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/9feacbb0
Branch: refs/heads/development
Commit: 9feacbb01b573c0eaf9f85972414ac9eaa784841
Parents: 1b921b5
Author: Imesha Sudasingha <im...@gmail.com>
Authored: Mon Mar 5 18:35:58 2018 +0530
Committer: Imesha Sudasingha <im...@gmail.com>
Committed: Mon Mar 5 18:35:58 2018 +0530
----------------------------------------------------------------------
resource/src/main/bin/resmgr-client | 2 +-
.../resource/cli/action/ResourceCliAction.java | 56 ++++++++--------
.../system/ResourceManagerClientMain.java | 28 ++++++++
.../resource/system/ResourceManagerMain.java | 14 ++--
.../system/rpc/ResourceManagerFactory.java | 67 ++++++++++++++++++++
5 files changed, 130 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/oodt/blob/9feacbb0/resource/src/main/bin/resmgr-client
----------------------------------------------------------------------
diff --git a/resource/src/main/bin/resmgr-client b/resource/src/main/bin/resmgr-client
index e7dbd3d..0376b66 100644
--- a/resource/src/main/bin/resmgr-client
+++ b/resource/src/main/bin/resmgr-client
@@ -31,4 +31,4 @@ $JAVA_HOME/bin/java \
-Djava.util.logging.config.file=../etc/logging.properties \
-Dorg.apache.oodt.cas.cli.action.spring.config=../policy/cmd-line-actions.xml \
-Dorg.apache.oodt.cas.cli.option.spring.config=../policy/cmd-line-options.xml \
- org.apache.oodt.cas.resource.system.XmlRpcResourceManagerClient $*
+ org.apache.oodt.cas.resource.system.ResourceManagerClientMain $*
http://git-wip-us.apache.org/repos/asf/oodt/blob/9feacbb0/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/ResourceCliAction.java
----------------------------------------------------------------------
diff --git a/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/ResourceCliAction.java b/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/ResourceCliAction.java
index 5cbb360..114be7f 100644
--- a/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/ResourceCliAction.java
+++ b/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/ResourceCliAction.java
@@ -16,16 +16,17 @@
*/
package org.apache.oodt.cas.resource.cli.action;
-//JDK imports
-import java.net.MalformedURLException;
-import java.net.URL;
//Apache imports
import org.apache.commons.lang.Validate;
-
-//OODT imports
import org.apache.oodt.cas.cli.action.CmdLineAction;
-import org.apache.oodt.cas.resource.system.XmlRpcResourceManagerClient;
+import org.apache.oodt.cas.resource.system.ResourceManagerClient;
+import org.apache.oodt.cas.resource.system.rpc.ResourceManagerFactory;
+
+//JDK imports
+import java.net.MalformedURLException;
+import java.net.URL;
+
/**
* Base {@link CmdLineAction} for Workflow Manager.
@@ -34,24 +35,27 @@ import org.apache.oodt.cas.resource.system.XmlRpcResourceManagerClient;
*/
public abstract class ResourceCliAction extends CmdLineAction {
- private XmlRpcResourceManagerClient client;
-
- public String getUrl() {
- return System.getProperty("org.apache.oodt.cas.resource.url");
- }
-
- protected XmlRpcResourceManagerClient getClient()
- throws MalformedURLException {
- Validate.notNull(getUrl());
-
- if (client != null) {
- return client;
- } else {
- return new XmlRpcResourceManagerClient(new URL(getUrl()));
- }
- }
-
- public void setClient(XmlRpcResourceManagerClient client) {
- this.client = client;
- }
+ private ResourceManagerClient client;
+
+ public String getUrl() {
+ return System.getProperty("org.apache.oodt.cas.resource.url");
+ }
+
+ protected ResourceManagerClient getClient() throws MalformedURLException {
+ Validate.notNull(getUrl());
+
+ if (client != null) {
+ return client;
+ } else {
+ try {
+ return ResourceManagerFactory.getResourceManagerClient(new URL(getUrl()));
+ } catch (Exception e) {
+ throw new IllegalStateException("Unable to create client", e);
+ }
+ }
+ }
+
+ public void setClient(ResourceManagerClient client) {
+ this.client = client;
+ }
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/9feacbb0/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerClientMain.java
----------------------------------------------------------------------
diff --git a/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerClientMain.java b/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerClientMain.java
new file mode 100644
index 0000000..c0750fe
--- /dev/null
+++ b/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerClientMain.java
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import org.apache.oodt.cas.cli.CmdLineUtility;
+
+public class ResourceManagerClientMain {
+
+ public static void main(String[] args) {
+ CmdLineUtility cmdLineUtility = new CmdLineUtility();
+ cmdLineUtility.run(args);
+ }
+}
http://git-wip-us.apache.org/repos/asf/oodt/blob/9feacbb0/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerMain.java
----------------------------------------------------------------------
diff --git a/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerMain.java b/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerMain.java
index 0880da1..162d64e 100644
--- a/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerMain.java
+++ b/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManagerMain.java
@@ -17,11 +17,10 @@
package org.apache.oodt.cas.resource.system;
+import org.apache.oodt.cas.resource.system.rpc.ResourceManagerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.lang.reflect.Constructor;
-
public class ResourceManagerMain {
private static final Logger logger = LoggerFactory.getLogger(ResourceManagerMain.class);
@@ -41,13 +40,7 @@ public class ResourceManagerMain {
System.exit(1);
}
- String resourceManagerClass = System.getProperty("resmgr.manager",
- "org.apache.oodt.cas.resource.system.AvroRpcResourceManager");
-
- logger.info("Starting resource manager {} at port: {}", resourceManagerClass, portNum);
-
- Constructor<?> constructor = Class.forName(resourceManagerClass).getConstructor(Integer.TYPE);
- final ResourceManager manager = (ResourceManager) constructor.newInstance(portNum);
+ final ResourceManager manager = ResourceManagerFactory.getResourceManager(portNum);
manager.startUp();
Runtime.getRuntime().addShutdownHook(new Thread() {
@@ -57,10 +50,11 @@ public class ResourceManagerMain {
}
});
- for (; ; )
+ for (; ; ) {
try {
Thread.currentThread().join();
} catch (InterruptedException ignore) {
}
+ }
}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/9feacbb0/resource/src/main/java/org/apache/oodt/cas/resource/system/rpc/ResourceManagerFactory.java
----------------------------------------------------------------------
diff --git a/resource/src/main/java/org/apache/oodt/cas/resource/system/rpc/ResourceManagerFactory.java b/resource/src/main/java/org/apache/oodt/cas/resource/system/rpc/ResourceManagerFactory.java
new file mode 100644
index 0000000..9287f6e
--- /dev/null
+++ b/resource/src/main/java/org/apache/oodt/cas/resource/system/rpc/ResourceManagerFactory.java
@@ -0,0 +1,67 @@
+/*
+ * 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.rpc;
+
+import org.apache.oodt.cas.resource.system.ResourceManager;
+import org.apache.oodt.cas.resource.system.ResourceManagerClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Constructor;
+import java.net.URL;
+
+public class ResourceManagerFactory {
+
+ private static final Logger logger = LoggerFactory.getLogger(ResourceManagerFactory.class);
+
+ public static ResourceManager getResourceManager(int port) throws Exception {
+ String resourceManagerClass = System.getProperty("resmgr.manager",
+ "org.apache.oodt.cas.resource.system.AvroRpcResourceManager");
+
+ logger.info("Creating resource manager {} at port: {}", resourceManagerClass, port);
+
+ ResourceManager manager;
+ try {
+ Constructor<?> constructor = Class.forName(resourceManagerClass).getConstructor(Integer.TYPE);
+ manager = (ResourceManager) constructor.newInstance(port);
+ } catch (Exception e) {
+ logger.error("Unable to create resource manager", e);
+ throw e;
+ }
+
+ return manager;
+ }
+
+ public static ResourceManagerClient getResourceManagerClient(URL url) throws Exception {
+ String resMgrClientClass = System.getProperty("resmgr.manager.client",
+ "org.apache.oodt.cas.resource.system.AvroRpcResourceManagerClient");
+
+ logger.info("Creating resource manager client {}", resMgrClientClass);
+
+ ResourceManagerClient client;
+ try {
+ Constructor<?> constructor = Class.forName(resMgrClientClass).getConstructor(URL.class);
+ client = (ResourceManagerClient) constructor.newInstance(url);
+ } catch (Exception e) {
+ logger.error("Unable to create resource manager", e);
+ throw e;
+ }
+
+ return client;
+ }
+}