Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Added --allocation option to nimbus-nodes which lists network pool in…
Browse files Browse the repository at this point in the history
…formation
  • Loading branch information
rrusnak1 authored and oldpatricka committed Oct 4, 2011
1 parent 1730e65 commit 363c957
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import java.rmi.RemoteException;

public interface RemoteNodeManagement extends Remote {

public static final int ALL_ENTRIES = 0;
public static final int FREE_ENTRIES = 1;
public static final int USED_ENTRIES = 2;

//Create
public String addNodes(String nodeJson) throws RemoteException;

Expand All @@ -42,4 +47,8 @@ public String updateNodes(String[] hostnames,

//Delete
public String removeNodes(String[] hostnames) throws RemoteException;

public String getAllNetworkPools(int inUse) throws RemoteException;

public String getNetworkPool(String pool, int inUse) throws RemoteException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@
<bean id="nimbus-remoting-nodemgmt"
class="org.globus.workspace.remoting.admin.defaults.DefaultRemoteNodeManagement">
<property name="nodeManagement" ref="nimbus-rm.scheduler.SlotManagement"/>
<property name="persistenceAdapter" ref="nimbus-rm.persistence.PersistenceAdapter"/>
</bean>

<bean id="nimbus-remoting-admintools"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class AssociationEntry {
private boolean inUse;
private boolean explicitMac;

public AssociationEntry() {}; //used for Gson

public AssociationEntry(String ipAddress,
String macAddress,
String hostname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.globus.workspace.remoting.admin.client;

import org.apache.commons.cli.*;
import org.globus.workspace.network.AssociationEntry;
import org.globus.workspace.remoting.admin.NodeReport;
import org.globus.workspace.remoting.admin.VmmNode;
import org.nimbustools.api.services.admin.RemoteNodeManagement;
Expand All @@ -40,6 +41,12 @@ public class AdminClient extends RMIConfig {
private static final String FIELD_IN_USE = "in_use";
private static final String FIELD_RESULT = "result";

private static final String FIELD_IP = "ip";
private static final String FIELD_MAC = "mac";
private static final String FIELD_BROADCAST = "broadcast";
private static final String FIELD_SUBNET_MASK = "subnet mask";
private static final String FIELD_GATEWAY = "gateway";
private static final String FIELD_EXPLICIT_MAC = "explicit mac";

final static String[] NODE_FIELDS = new String[] {
FIELD_HOSTNAME, FIELD_POOL, FIELD_MEMORY, FIELD_NETWORKS,
Expand All @@ -54,6 +61,11 @@ public class AdminClient extends RMIConfig {
final static String[] NODE_REPORT_FIELDS_SHORT = new String[] {
FIELD_HOSTNAME, FIELD_RESULT};

final static String[] NODE_ALLOCATION_FIELDS = new String[] {
FIELD_HOSTNAME, FIELD_IP, FIELD_MAC, FIELD_BROADCAST,
FIELD_SUBNET_MASK, FIELD_GATEWAY, FIELD_IN_USE, FIELD_EXPLICIT_MAC
};



private AdminAction action;
Expand All @@ -66,6 +78,7 @@ public class AdminClient extends RMIConfig {
private String nodePool;
private boolean nodeActive = true;
private boolean nodeActiveConfigured;
private int inUse = 0;

private RemoteNodeManagement remoteNodeManagement;

Expand Down Expand Up @@ -143,6 +156,9 @@ public void run(String[] args)
case UpdateNodes:
run_updateNodes();
break;
case PoolAvailability:
run_poolAvail();
break;
}
}

Expand Down Expand Up @@ -234,7 +250,7 @@ private void run_updateNodes() throws ExecutionProblem {
hostnames, active, resourcepool, memory, networks);
reports = gson.fromJson(reportJson, NodeReport[].class);
} catch (RemoteException e) {
handleRemoteException(e);
super.handleRemoteException(e);
}

try {
Expand All @@ -244,6 +260,38 @@ private void run_updateNodes() throws ExecutionProblem {
}
}

private void run_poolAvail() throws ExecutionProblem {
AssociationEntry[] entries = null;
try {
if(this.nodePool != null) {
final String entriesJson = this.remoteNodeManagement.getNetworkPool(this.nodePool, this.inUse);
if(entriesJson == null) {
System.err.println("No entries with pool name " + nodePool + " found");
return;
}
entries = gson.fromJson(entriesJson, AssociationEntry[].class);
}
else {
final String entriesJson = this.remoteNodeManagement.getAllNetworkPools(this.inUse);
if(entriesJson == null) {
System.err.println("No pool entries found");
return;
}
entries = gson.fromJson(entriesJson, AssociationEntry[].class);
}
}
catch(RemoteException e) {
System.err.println(e.getMessage());
}

try {
reporter.report(nodeAllocationToMaps(entries), this.outStream);
}
catch (IOException e) {
throw new ExecutionProblem("Problem writing output: " + e.getMessage(), e);
}
}


private void loadAdminClientConfig() throws ParameterProblem, ExecutionProblem {

Expand Down Expand Up @@ -357,6 +405,20 @@ private void loadArgs(String[] args) throws ParameterProblem {
if (hostArg != null) {
this.hosts = parseHosts(hostArg);
}
} else if (theAction == AdminAction.PoolAvailability) {
if(line.hasOption(Opts.POOL)) {
final String pool = line.getOptionValue(Opts.POOL);
if(pool == null || pool.trim().length() == 0) {
throw new ParameterProblem("Pool name value is empty");
}
this.nodePool = pool;
}
if(line.hasOption(Opts.FREE)) {
this.inUse = RemoteNodeManagement.FREE_ENTRIES;
}
if(line.hasOption(Opts.USED)) {
this.inUse = RemoteNodeManagement.USED_ENTRIES;
}
}

//finally everything else
Expand Down Expand Up @@ -540,13 +602,35 @@ private static Map<String,String> nodeReportToMap(NodeReport nodeReport) {
}
return map;
}

private static List<Map<String,String>> nodeAllocationToMaps(AssociationEntry[] entries) {
List<Map<String,String>> maps = new ArrayList<Map<String, String>>(entries.length);
for (AssociationEntry entry : entries) {
maps.add(nodeAllocationToMap(entry));
}
return maps;
}

private static Map<String,String> nodeAllocationToMap(AssociationEntry entry) {
final HashMap<String, String> map = new HashMap(8);
map.put(FIELD_HOSTNAME, entry.getHostname());
map.put(FIELD_IP, entry.getIpAddress());
map.put(FIELD_MAC, entry.getMac());
map.put(FIELD_BROADCAST, entry.getBroadcast());
map.put(FIELD_SUBNET_MASK, entry.getSubnetMask());
map.put(FIELD_GATEWAY, entry.getGateway());
map.put(FIELD_IN_USE, Boolean.toString(entry.isInUse()));
map.put(FIELD_EXPLICIT_MAC, Boolean.toString(entry.isExplicitMac()));
return map;
}
}

enum AdminAction implements AdminEnum {
AddNodes(Opts.ADD_NODES, AdminClient.NODE_REPORT_FIELDS),
ListNodes(Opts.LIST_NODES, AdminClient.NODE_FIELDS),
RemoveNodes(Opts.REMOVE_NODES, AdminClient.NODE_REPORT_FIELDS_SHORT),
UpdateNodes(Opts.UPDATE_NODES, AdminClient.NODE_REPORT_FIELDS),
PoolAvailability(Opts.POOL_AVAILABILITY, AdminClient.NODE_ALLOCATION_FIELDS),
Help(Opts.HELP, null);

private final String option;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public Options getOptions() {
public final Option UPDATE_NODES_OPT =
OptionBuilder.withLongOpt(UPDATE_NODES_LONG).hasArg().create(UPDATE_NODES);

public static final String POOL_AVAILABILITY = "N";
public static final String POOL_AVAILABILITY_LONG = "allocation";
public final Option POOL_AVAILABILITY_OPT =
OptionBuilder.withLongOpt(POOL_AVAILABILITY_LONG).hasOptionalArg().create(POOL_AVAILABILITY);


//*************************************************************************
// NODE SETTINGS
Expand Down Expand Up @@ -132,6 +137,16 @@ public Options getOptions() {
public final Option POOL_OPT =
OptionBuilder.withLongOpt(POOL_LONG).hasArg().create(POOL);

public static final String FREE = "F";
public static final String FREE_LONG = "free";
public final Option FREE_OPT =
OptionBuilder.withLongOpt(FREE_LONG).create(FREE);

public static final String USED = "U";
public static final String USED_LONG = "used";
public final Option USED_OPT =
OptionBuilder.withLongOpt(USED_LONG).create(USED);


//*************************************************************************
// NIMBUS-ADMIN
Expand Down Expand Up @@ -190,10 +205,10 @@ public Options getOptions() {
public final Option[] ALL_ENABLED_OPTIONS = {
HELP_OPT, DEBUG_OPT, CONFIG_OPT, BATCH_OPT, DELIMITER_OPT,
REPORT_OPT, JSON_OPT, OUTPUT_OPT, ADD_NODES_OPT, LIST_NODES_OPT,
REMOVE_NODES_OPT, UPDATE_NODES_OPT, NETWORKS_OPT, MEMORY_OPT, POOL_OPT,
REMOVE_NODES_OPT, UPDATE_NODES_OPT, POOL_AVAILABILITY_OPT, NETWORKS_OPT, MEMORY_OPT, POOL_OPT,
ACTIVE_OPT, INACTIVE_OPT, LIST_VMS_OPT, SHUTDOWN_VMS_OPT, USER_OPT, ID_OPT,
SECONDS_OPT, ALL_VMS_OPT, HOST_OPT, DN_OPT, GROUP_ID_OPT,
GROUP_NAME_OPT
GROUP_NAME_OPT, FREE_OPT, USED_OPT
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ Actions
--remove (-d) HOSTS Removes VMM nodes from the Nimbus resource pool.
Nodes that are in use cannot be removed.

--allocation (-N) Provides network pool allocation information.
Displays ip, MAC, and other pool entry info as well
as whether or not the ip is currently in use.

--pool (-p) --allocation option that provides info for specific
pool name (ie. public)

--free Optional --allocation argument that only lists
ips that are not in use
--used Optional --allocation argument that only lists
ips that are in use


-----------------------------------------------------------------------------
VMM Node Parameters Values used in adding/updating nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import com.google.gson.reflect.TypeToken;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.globus.workspace.network.Association;
import org.globus.workspace.network.AssociationEntry;
import org.globus.workspace.persistence.PersistenceAdapter;
import org.globus.workspace.persistence.WorkspaceDatabaseException;
import org.globus.workspace.remoting.admin.NodeReport;
import org.nimbustools.api.services.admin.RemoteNodeManagement;
Expand All @@ -29,11 +32,10 @@
import org.globus.workspace.scheduler.NodeManagementDisabled;
import org.globus.workspace.scheduler.NodeNotFoundException;
import org.globus.workspace.scheduler.defaults.ResourcepoolEntry;
import org.springframework.remoting.RemoteAccessException;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.*;

public class DefaultRemoteNodeManagement implements RemoteNodeManagement {

Expand All @@ -44,6 +46,7 @@ public class DefaultRemoteNodeManagement implements RemoteNodeManagement {
private final TypeToken<Collection<VmmNode>> vmmNodeCollectionTypeToken;

private NodeManagement nodeManagement = null;
private PersistenceAdapter persistenceAdapter;

public DefaultRemoteNodeManagement() {
this.gson = new Gson();
Expand Down Expand Up @@ -261,6 +264,85 @@ public String removeNodes(String[] hostnames) throws RemoteException {
return gson.toJson(reports);
}

public String getAllNetworkPools(int inUse) throws RemoteException {
try {
Hashtable cAssociations = persistenceAdapter.currentAssociations();
List<Association> assocs = new ArrayList<Association>();
Enumeration keys = cAssociations.keys();

while(keys.hasMoreElements()) {
Association a = (Association) cAssociations.get(keys.nextElement());
assocs.add(a);
}

if(assocs == null || assocs.size() == 0)
return null;

List<AssociationEntry> allEntries = new ArrayList<AssociationEntry>();
for(Association assoc: assocs) {
Iterator it = assoc.getEntries().iterator();
while(it.hasNext()) {
AssociationEntry next = (AssociationEntry) it.next();
if(inUse == ALL_ENTRIES) {
allEntries.add(next);
}
else if(inUse == FREE_ENTRIES) {
if(!next.isInUse())
allEntries.add(next);
}
else if(inUse == USED_ENTRIES) {
if(next.isInUse())
allEntries.add(next);
}
}
}

if(allEntries == null || allEntries.isEmpty())
return null;

return gson.toJson(allEntries);
}
catch(WorkspaceDatabaseException e) {
throw new RemoteException(e.getMessage());
}
}

public String getNetworkPool(String pool, int inUse) throws RemoteException {
try {
Hashtable cAssociations = persistenceAdapter.currentAssociations();

final Association assoc = (Association) cAssociations.get(pool);

if (assoc == null)
return null;

List<AssociationEntry> entries = new ArrayList<AssociationEntry>();
Iterator it = assoc.getEntries().iterator();
while(it.hasNext()) {
AssociationEntry next = (AssociationEntry) it.next();
if(inUse == ALL_ENTRIES) {
entries.add(next);
}
else if(inUse == FREE_ENTRIES) {
if(!next.isInUse())
entries.add(next);
}
else if(inUse == USED_ENTRIES) {
if(next.isInUse())
entries.add(next);
}
}

if (entries == null || entries.isEmpty())
return null;

return gson.toJson(entries);
}
catch (WorkspaceDatabaseException e) {
throw new RemoteException(e.getMessage());
}
}

public NodeManagement getNodeManagement() {
return nodeManagement;
}
Expand All @@ -269,6 +351,10 @@ public void setNodeManagement(NodeManagement nodeManagement) {
this.nodeManagement = nodeManagement;
}

public void setPersistenceAdapter(PersistenceAdapter persistenceAdapter) {
this.persistenceAdapter = persistenceAdapter;
}

private static VmmNode translateResourcepoolEntry(ResourcepoolEntry entry) {
if (entry == null) {
return null;
Expand Down
Loading

0 comments on commit 363c957

Please sign in to comment.