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

Commit

Permalink
Added nimbus-admin node update support
Browse files Browse the repository at this point in the history
  • Loading branch information
labisso committed Oct 14, 2010
1 parent ecc57e6 commit 2300242
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 113 deletions.
Expand Up @@ -150,7 +150,7 @@ public Hashtable currentAssociations(boolean cachedIsFine)

throws WorkspaceDatabaseException;

public void replaceResourcepoolEntry(ResourcepoolEntry entry)
public void updateResourcepoolEntryAvailableMemory(String hostname, int newAvailMemory)

throws WorkspaceDatabaseException;

Expand Down Expand Up @@ -196,6 +196,12 @@ public void updateCursorPosition(long currentPosition)

public List<ResourcepoolEntry> getAvailableEntriesSortedByFreeMemoryPercentage(int requestedMem)

throws WorkspaceDatabaseException;
throws WorkspaceDatabaseException;

boolean updateResourcepoolEntry(String hostname,
String pool,
String networks,
Integer memory,
Boolean active)
throws WorkspaceDatabaseException;
}
Expand Up @@ -163,7 +163,11 @@ public interface PersistenceAdapterConstants {

public static final String SQL_UPDATE_RESOURCE_POOL_ENTRY_MEMORY =
"UPDATE resourcepool_entries SET available_memory=? " +
"WHERE resourcepool=? AND hostname=?";
"WHERE hostname=?";

// not a prepared statement, the skeleton for custom update queries
public static final String SQL_UPDATE_RESOURCE_POOL_ENTRY_SKELETAL =
"UPDATE resourcepool_entries SET %s WHERE hostname=?";

public static final String SQL_DELETE_RESOURCE_POOL_ENTRY =
"DELETE FROM resourcepool_entries WHERE hostname = ?";
Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.globus.workspace.network.Association;
import org.globus.workspace.network.AssociationEntry;
import org.globus.workspace.persistence.impls.AssociationPersistenceUtil;
import org.globus.workspace.persistence.impls.ResourcepoolPersistenceUtil;
import org.globus.workspace.persistence.impls.VMPersistence;
import org.globus.workspace.persistence.impls.VirtualMachinePersistenceUtil;
import org.globus.workspace.scheduler.defaults.ResourcepoolEntry;
Expand Down Expand Up @@ -1798,24 +1797,32 @@ public synchronized Hashtable currentAssociations(boolean cachedIsFine)

}


/**
* For now, only available_memory is replaceable.
* @param entry pool entry
*/
public void replaceResourcepoolEntry(ResourcepoolEntry entry)
public void updateResourcepoolEntryAvailableMemory(String hostname, int newAvailMemory)
throws WorkspaceDatabaseException {

if (this.dbTrace) {
logger.trace("replaceResourcepoolEntry()");
logger.trace("updateResourcepoolEntryAvailableMemory()");
}

if (hostname == null) {
throw new IllegalArgumentException("hostname may not be null");
}

if (newAvailMemory < 0) {
throw new IllegalArgumentException("newAvailMemory must be non-negative");
}

Connection c = null;
PreparedStatement pstmt = null;
try {
c = getConnection();
pstmt = ResourcepoolPersistenceUtil.
updateAvailableMemory(entry.getResourcePool(), entry, c);

pstmt =
c.prepareStatement(SQL_UPDATE_RESOURCE_POOL_ENTRY_MEMORY);

pstmt.setInt(1, newAvailMemory);
pstmt.setString(2, hostname);

final int updated = pstmt.executeUpdate();
if (updated != 1) {
throw new WorkspaceDatabaseException("expected row update");
Expand All @@ -1838,6 +1845,91 @@ public void replaceResourcepoolEntry(ResourcepoolEntry entry)

}

public boolean updateResourcepoolEntry(String hostname,
String pool,
String networks,
Integer memory,
Boolean active)
throws WorkspaceDatabaseException {

if (this.dbTrace) {
logger.trace("updateResourcepoolEntry()");
}
if (hostname == null) {
throw new IllegalArgumentException("hostname may not be null");
}

final StringBuilder sb = new StringBuilder();
final List<Object> params = new ArrayList<Object>(4);
if (pool != null) {
appendUpdatePair(sb, "resourcepool");
params.add(pool);
}
if (networks != null) {
appendUpdatePair(sb, "associations");
params.add(networks);
}
if (memory != null) {
appendUpdatePair(sb, "maximum_memory");
params.add(memory);
}
if (active != null) {
appendUpdatePair(sb, "active");
params.add(active);
}
if (params.isEmpty()) {
throw new IllegalArgumentException(
"at least one updated field must be specified");
}

Connection c = null;
PreparedStatement pstmt = null;
try {
c = getConnection();

final String q = String.format(
SQL_UPDATE_RESOURCE_POOL_ENTRY_SKELETAL, sb.toString());
if (this.dbTrace) {
logger.trace("resourcepool_entry update query: "+ q);
}
pstmt = c.prepareStatement(q);

int paramIndex = 1;
for (Object p : params) {
pstmt.setObject(paramIndex, p);
paramIndex++;
}

// add on the hostname param
pstmt.setString(paramIndex, hostname);

final int updated = pstmt.executeUpdate();
return updated >= 1;

} catch(SQLException e) {
logger.error("",e);
throw new WorkspaceDatabaseException(e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
if (c != null) {
returnConnection(c);
}
} catch (SQLException sql) {
logger.error("SQLException in finally cleanup", sql);
}
}
}

private void appendUpdatePair(StringBuilder stringBuilder, String columnName) {
if (stringBuilder.length() != 0) {
stringBuilder.append(",");
}
stringBuilder.append(columnName).append("=?");
}

// one can only use result of this safely during service initialization
public int memoryUsedOnPoolnode(String poolnode)

Expand Down

This file was deleted.

Expand Up @@ -27,7 +27,17 @@ public interface RemoteNodeManagement extends Remote {
public String getNode(String hostname) throws RemoteException;

//Update
public String updateNodes(String nodeJson) throws RemoteException;

// this rather sucks. null values mean no update of that field.
// but all fields need to be part of signature, so this won't
// scale to well. also it is not parallel with how howNodes()
// works
public String updateNodes(String[] hostnames,
Boolean active,
String pool,
Integer memory,
String networks)
throws RemoteException;

//Delete
public String removeNodes(String[] hostnames) throws RemoteException;
Expand Down
Expand Up @@ -264,15 +264,17 @@ private void run_removeNodes() throws ExecutionProblem {

private void run_updateNodes() throws ExecutionProblem {

final List<VmmNode> nodes = new ArrayList<VmmNode>(this.hosts.size());
//TODO
// for (String hostname : this.hosts) {
// nodes.add(new VmmNode(hostname, this.nodePool,
// this.nodeMemory, this.nodeNetworks, true));
// }
final String[] hostnames = this.hosts.toArray(new String[this.hosts.size()]);
final Boolean active = this.nodeActiveConfigured ? this.nodeActive : null;
final String resourcepool = this.nodePool;
final Integer memory = this.nodeMemoryConfigured ? this.nodeMemory : null;
final String networks = this.nodeNetworks;


NodeReport[] reports = null;
try {
final String reportJson = this.remoteNodeManagement.updateNodes(gson.toJson(nodes));
final String reportJson = this.remoteNodeManagement.updateNodes(
hostnames, active, resourcepool, memory, networks);
reports = gson.fromJson(reportJson, NodeReport[].class);
} catch (RemoteException e) {
handleRemoteException(e);
Expand Down Expand Up @@ -621,7 +623,7 @@ private static String getHelpText() {
bis = new BufferedInputStream(is);
StringBuilder sb = new StringBuilder();
byte[] chars = new byte[1024];
int bytesRead = 0;
int bytesRead;
while( (bytesRead = bis.read(chars)) > -1){
sb.append(new String(chars, 0, bytesRead));
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.globus.workspace.scheduler.NodeExistsException;
import org.globus.workspace.scheduler.NodeInUseException;
import org.globus.workspace.scheduler.NodeManagement;
import org.globus.workspace.scheduler.NodeNotFoundException;
import org.globus.workspace.scheduler.defaults.ResourcepoolEntry;

import java.rmi.RemoteException;
Expand Down Expand Up @@ -124,36 +125,50 @@ public String getNode(String hostname) {
return gson.toJson(translateResourcepoolEntry(entry));
}

public String updateNodes(String nodeJson) {
if (nodeJson == null) {
throw new IllegalArgumentException("nodeJson may not be null");
public String updateNodes(String[] hostnames,
Boolean active,
String pool,
Integer memory,
String networks) {
if (hostnames == null) {
throw new IllegalArgumentException("hostnames may not be null");
}
final Collection<VmmNode> nodes = gson.fromJson(nodeJson,
this.vmmNodeCollectionTypeToken.getType());

if (nodes.isEmpty()) {
if (hostnames.length == 0) {
throw new IllegalArgumentException(
"You must specify at least one VMM node to update");
}

List<NodeReport> reports = new ArrayList<NodeReport>(nodes.size());
for (VmmNode node : nodes) {
if (node == null) {
throw new IllegalArgumentException("update request has null node");
if (active == null && pool == null && memory == null && networks == null) {
throw new IllegalArgumentException(
"You must specify at least one node parameter to update");
}

final List<NodeReport> reports = new ArrayList<NodeReport>(hostnames.length);

for (String hostname : hostnames) {
if (hostname == null) {
throw new IllegalArgumentException("update request has null node hostname");
}
final String hostname = node.getHostname();

logger.info("Updating VMM node: " + node.toString());
logger.info("Updating VMM node: " + hostname);

try {
nodeManagement.updateNode(translateVmmNode(node));
final ResourcepoolEntry entry = nodeManagement.updateNode(
hostname, pool, networks, memory, active);

final VmmNode node = translateResourcepoolEntry(entry);
reports.add(new NodeReport(hostname, NodeReport.STATE_UPDATED,
node));
} catch (NodeInUseException e) {
logger.info("VMM node was in use, failed to update: " + hostname);
reports.add(
new NodeReport(hostname,
NodeReport.STATE_NODE_IN_USE, null));
} catch (NodeNotFoundException e) {
logger.info("VMM node not found, failed to update: " + hostname);
reports.add(
new NodeReport(hostname,
NodeReport.STATE_NODE_NOT_FOUND, null));
}

}
Expand Down Expand Up @@ -216,13 +231,4 @@ private static VmmNode translateResourcepoolEntry(ResourcepoolEntry entry) {
entry.getResourcePool(), entry.getMemMax(),
entry.getSupportedAssociations(), entry.isVacant());
}

private static ResourcepoolEntry translateVmmNode(VmmNode node) {
if (node == null) {
return null;
}
return new ResourcepoolEntry(node.getPoolName(), node.getHostname(),
node.getMemory(), node.getMemory(),
node.getNetworkAssociations(), node.isActive());
}
}
Expand Up @@ -63,20 +63,15 @@ public String getNode(String hostname) {
return null;
}

public String updateNodes(String nodeJson) {
final Collection<VmmNode> nodes = gson.fromJson(nodeJson,
this.vmmNodeCollectionTypeToken.getType());
List<NodeReport> reports = new ArrayList<NodeReport>(nodes.size());
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);
}
reports.add(new NodeReport(hostname, "UPDATED", node));
}
}
return gson.toJson(reports);
public String updateNodes(String[] hostnames,
Boolean active,
String pool,
Integer memory,
String networks)
throws RemoteException {

//not implemented
return null;
}

public String removeNode(String hostname) {
Expand Down

0 comments on commit 2300242

Please sign in to comment.