Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Admin client works with real comm, fake backend

Using json serialization because type marshaling with RMI was getting freaky.
  • Loading branch information...
commit 7da4536be300259d19ad1025955643902ed84cc0 1 parent 7dcc262
@labisso labisso authored
View
1  .idea/libraries/workspace_service_libs.xml
@@ -19,6 +19,7 @@
<root url="jar://$PROJECT_DIR$/lib/services/junixsocket-1.3.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/services/junixsocket-rmi-1.3.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/services/commons-cli-2.0.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/services/gson-1.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
View
17 service/service/java/source/src/org/globus/workspace/remoting/admin/RemoteNodePool.java
@@ -15,9 +15,20 @@
*/
package org.globus.workspace.remoting.admin;
-import org.globus.workspace.scheduler.NodePool;
-
+import java.io.IOException;
import java.rmi.Remote;
-public interface RemoteNodePool extends NodePool, Remote {
+public interface RemoteNodePool extends Remote {
+ //Create
+ public void addNodes(String nodeJson) throws IOException;
+
+ //Read
+ public String listNodes() throws IOException;
+ public String getNode(String hostname) throws IOException;
+
+ //Update
+ public void updateNodes(String nodeJson) throws IOException;
+
+ //Delete
+ public void removeNodes(String[] hostnames) throws IOException;
}
View
108 service/service/java/source/src/org/globus/workspace/remoting/admin/client/AdminClient.java
@@ -15,14 +15,16 @@
*/
package org.globus.workspace.remoting.admin.client;
+import com.google.gson.Gson;
import org.apache.commons.cli.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.*;
import org.globus.workspace.remoting.RemotingClient;
-import org.globus.workspace.scheduler.NodePool;
+import org.globus.workspace.remoting.admin.RemoteNodePool;
import org.globus.workspace.scheduler.VmmNode;
import org.globus.workspace.scheduler.defaults.DefaultVmmNode;
+import org.nimbustools.api.brain.NimbusHomePathResolver;
import java.io.File;
import java.io.FileInputStream;
@@ -39,6 +41,7 @@
private static final Log logger =
LogFactory.getLog(AdminClient.class.getName());
+
public static final int EXIT_OK = 0;
public static final int EXIT_PARAMETER_PROBLEM = 1;
public static final int EXIT_EXECUTION_PROBLEM = 2;
@@ -50,6 +53,7 @@
private static final String PROP_DEFAULT_NETWORKS = "node.networks.default";
private static final String PROP_DEFAULT_POOL = "node.pool.default";
+ private final Gson gson = new Gson();
private AdminAction action;
private List<String> hosts;
@@ -62,7 +66,7 @@
private File socketDirectory;
private RemotingClient remotingClient;
private String nodePoolBindingName;
- private NodePool vmmNodePool;
+ private RemoteNodePool remoteNodePool;
public static void main(String args[]) {
@@ -77,7 +81,14 @@ public static void main(String args[]) {
}
if (isDebug) {
- BasicConfigurator.configure();
+ System.out.println("sandwiches");
+
+ //TODO uggggh something is configuring log4j first
+ BasicConfigurator.resetConfiguration();
+
+ final PatternLayout layout = new PatternLayout("%C{1}:%L - %m%n");
+ BasicConfigurator.configure(new ConsoleAppender(layout));
+
logger.info("Debug mode enabled");
}
@@ -154,7 +165,7 @@ public void run(String[] args)
}
- private void run_addNodes() throws ParameterProblem {
+ private void run_addNodes() throws ParameterProblem, ExecutionProblem {
if (!this.nodeMemoryConfigured) {
throw new ParameterProblem(
"Node max memory must be specified as an argument ("+
@@ -178,20 +189,76 @@ private void run_addNodes() throws ParameterProblem {
nodes.add(new DefaultVmmNode(hostname, this.nodePool,
this.nodeMemory, this.nodeNetworks, true));
}
- this.vmmNodePool.addNodes(nodes);
+ try {
+ this.remoteNodePool.addNodes(gson.toJson(nodes));
+ } catch (IOException e) {
+ handleRemoteException(e);
+ }
+
+ reportNodes(nodes.toArray(new VmmNode[nodes.size()]));
}
+ private void run_listNodes() throws ExecutionProblem {
+ try {
+ final String nodesJson = this.remoteNodePool.listNodes();
+ final VmmNode[] nodes = this.gson.fromJson(nodesJson, DefaultVmmNode[].class);
+ this.reportNodes(nodes);
+ } catch (IOException e) {
+ handleRemoteException(e);
+ }
+ }
- private void run_listNodes() {
- //TODO
+ private void run_removeNodes() throws ExecutionProblem {
+ try {
+ final String[] hostnames = this.hosts.toArray(new String[this.hosts.size()]);
+ this.remoteNodePool.removeNodes(hostnames);
+ } catch (IOException e) {
+ handleRemoteException(e);
+ }
}
- private void run_removeNodes() {
+ private void run_updateNodes() throws ExecutionProblem {
+
//TODO
+
+ final List<VmmNode> nodes = new ArrayList<VmmNode>(this.hosts.size());
+ for (String hostname : this.hosts) {
+ nodes.add(new DefaultVmmNode(hostname, this.nodePool,
+ this.nodeMemory, this.nodeNetworks, true));
+ }
+ try {
+ this.remoteNodePool.updateNodes(gson.toJson(nodes));
+ } catch (IOException e) {
+ handleRemoteException(e);
+ }
}
- private void run_updateNodes() {
- //TODO
+ private void handleRemoteException(Throwable t) throws ExecutionProblem {
+ throw new ExecutionProblem("Failed to communicate with Nimbus service. "+
+ "Is it running? Error: " + t.getMessage(), t);
+ }
+
+ private void reportNodes(VmmNode[] nodes) {
+ StringBuilder sb = new StringBuilder();
+ for (VmmNode node : nodes) {
+ for (String network : node.getNetworkAssociations()) {
+ if (sb.length() > 0) {
+ sb.append(", ");
+ }
+ sb.append(network);
+ }
+ if (sb.length() == 0) {
+ sb.append("*");
+ }
+
+ System.out.println("Host:\t" + node.getHostname());
+ System.out.println("Pool:\t" + node.getPoolName());
+ System.out.println("Memory:\t" + node.getMemory());
+ System.out.println("Networks:\t" + sb.toString());
+ System.out.println();
+
+ sb.delete(0, sb.length());
+ }
}
private void setupRemoting() throws ExecutionProblem {
@@ -207,7 +274,7 @@ private void setupRemoting() throws ExecutionProblem {
this.remotingClient = client;
try {
- this.vmmNodePool = (NodePool) client.lookup(this.nodePoolBindingName);
+ this.remoteNodePool = (RemoteNodePool) client.lookup(this.nodePoolBindingName);
} catch (RemoteException e) {
handleRemoteException(e);
} catch (NotBoundException e) {
@@ -259,7 +326,9 @@ private void loadConfig(String configPath)
throw new ExecutionProblem("Configuration file is missing "+
PROP_SOCKET_DIR + " entry: " + configFile.getAbsolutePath());
}
- this.socketDirectory = new File(sockDir);
+
+ final NimbusHomePathResolver resolver = new NimbusHomePathResolver();
+ this.socketDirectory = new File(resolver.resolvePath(sockDir));
final String nodePoolBinding = props.getProperty(PROP_RMI_BINDING_NODEPOOL_DIR);
if (nodePoolBinding == null) {
@@ -291,6 +360,8 @@ private void loadConfig(String configPath)
}
private void loadArgs(String[] args) throws ParameterProblem {
+
+ logger.debug("Parsing command line arguments");
final CommandLineParser parser = new PosixParser();
final Opts opts = new Opts();
@@ -318,6 +389,7 @@ private void loadArgs(String[] args) throws ParameterProblem {
}
this.action = theAction;
+ logger.debug("Action: " + theAction);
// short circuit for --help arg
@@ -440,11 +512,11 @@ private static void printHelp() {
enum AdminAction {
- AddNodes(Opts.ADD_NODES_LONG),
- ListNodes(Opts.LIST_NODES_LONG),
- RemoveNodes(Opts.REMOVE_NODES_LONG),
- UpdateNodes(Opts.UPDATE_NODES_LONG),
- Help(Opts.HELP_LONG);
+ AddNodes(Opts.ADD_NODES),
+ ListNodes(Opts.LIST_NODES),
+ RemoveNodes(Opts.REMOVE_NODES),
+ UpdateNodes(Opts.UPDATE_NODES),
+ Help(Opts.HELP);
private final String option;
View
45 ...vice/java/source/src/org/globus/workspace/remoting/admin/defaults/FakeRemoteNodePool.java
@@ -15,43 +15,58 @@
*/
package org.globus.workspace.remoting.admin.defaults;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import org.globus.workspace.remoting.admin.RemoteNodePool;
import org.globus.workspace.scheduler.VmmNode;
+import org.globus.workspace.scheduler.defaults.DefaultVmmNode;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class FakeRemoteNodePool implements RemoteNodePool {
+ private final Gson gson;
+ private final TypeToken<Collection<DefaultVmmNode>> vmmNodeCollectionTypeToken;
- private List<VmmNode> nodeList = new ArrayList<VmmNode>();
-
- public void addNode(VmmNode node) {
- nodeList.add(node);
+ public FakeRemoteNodePool() {
+ this.gson = new Gson();
+ this.vmmNodeCollectionTypeToken = new TypeToken<Collection<DefaultVmmNode>>(){};
}
- public void addNodes(Collection<VmmNode> nodes) {
- nodeList.addAll(nodes);
+ private List<VmmNode> nodeList = new ArrayList<VmmNode>();
+
+ public void addNodes(String nodeJson) throws IOException {
+ Collection<VmmNode> nodes = gson.fromJson(nodeJson,
+ vmmNodeCollectionTypeToken.getType());
+ for (VmmNode node : nodes) {
+ this.nodeList.add(node);
+ }
}
- public List<VmmNode> listNodes() {
- return new ArrayList<VmmNode>(nodeList);
+ public String listNodes() {
+ return gson.toJson(nodeList);
}
- public VmmNode getNode(String hostname) {
+ public String getNode(String hostname) {
for (VmmNode node : nodeList) {
if (node.getHostname().equals(hostname)) {
- return node;
+ return gson.toJson(node);
}
}
return null;
}
- public void updateNode(VmmNode node) {
+ public void updateNodes(String nodeJson) {
+ final Collection<VmmNode> nodes = gson.fromJson(nodeJson,
+ this.vmmNodeCollectionTypeToken.getType());
+ for (VmmNode node : nodes) {
final String hostname = node.getHostname();
- for (int i = 0; i < this.nodeList.size(); i++) {
- if (nodeList.get(i).getHostname().equals(hostname)) {
- nodeList.set(i, node);
+ for (int i = 0; i < this.nodeList.size(); i++) {
+ if (nodeList.get(i).getHostname().equals(hostname)) {
+ nodeList.set(i, node);
+ }
}
}
}
@@ -64,7 +79,7 @@ public void removeNode(String hostname) {
}
}
- public void removeNodes(Collection<String> hostnames) {
+ public void removeNodes(String[] hostnames) {
for (String hostname : hostnames) {
this.removeNode(hostname);
}
View
3  service/service/java/source/src/org/globus/workspace/scheduler/defaults/DefaultVmmNode.java
@@ -21,6 +21,9 @@
public class DefaultVmmNode implements VmmNode {
+ @SuppressWarnings({"UnusedDeclaration"}) // used by GSON deserialization
+ DefaultVmmNode() {}
+
public DefaultVmmNode(String hostname, String poolName,
int memory, Collection<String> networkAssociations,
boolean vacant) {

0 comments on commit 7da4536

Please sign in to comment.
Something went wrong with that request. Please try again.