use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class RMRest method defineNodeSource.
@Override
@POST
@Path("nodesource")
@Produces("application/json")
public NSState defineNodeSource(@HeaderParam("sessionid") String sessionId, @FormParam("nodeSourceName") String nodeSourceName, @FormParam("infrastructureType") String infrastructureType, @FormParam("infrastructureParameters") String[] infrastructureParameters, @FormParam("infrastructureFileParameters") String[] infrastructureFileParameters, @FormParam("policyType") String policyType, @FormParam("policyParameters") String[] policyParameters, @FormParam("policyFileParameters") String[] policyFileParameters, @FormParam("nodesRecoverable") String nodesRecoverable) throws NotConnectedException {
ResourceManager rm = checkAccess(sessionId);
NSState nsState = new NSState();
Object[] infraParams = this.getAllInfrastructureParameters(infrastructureType, infrastructureParameters, infrastructureFileParameters, rm);
Object[] policyParams = this.getAllPolicyParameters(policyType, policyParameters, policyFileParameters, rm);
try {
nsState.setResult(rm.defineNodeSource(nodeSourceName, infrastructureType, infraParams, policyType, policyParams, Boolean.parseBoolean(nodesRecoverable)).getBooleanValue());
} catch (RuntimeException ex) {
nsState.setResult(false);
nsState.setErrorMessage(cleanDisplayedErrorMessage(ex.getMessage()));
nsState.setStackTrace(StringEscapeUtils.escapeJson(getStackTrace(ex)));
}
return nsState;
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class AddNodeCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpPost request = new HttpPost(currentContext.getResourceUrl("node"));
QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
queryStringBuilder.add("nodeurl", nodeUrl);
if (currentContext.getProperty(SET_NODE_SOURCE, String.class) != null) {
nodeSource = currentContext.getProperty(SET_NODE_SOURCE, String.class);
}
if (nodeSource != null) {
queryStringBuilder.add("nodesource", nodeSource);
}
request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
boolean successful = readValue(response, Boolean.TYPE, currentContext);
currentContext.resultStack().push(successful);
if (successful) {
writeLine(currentContext, "Node('%s') added successfully.", nodeUrl);
} else {
writeLine(currentContext, "Cannot add node('%s').", nodeUrl);
}
} else {
handleError("An error occurred while adding the node:", response, currentContext);
}
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class CreateNodeSourceCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
QueryStringBuilder infrastructure = currentContext.getProperty(SET_INFRASTRUCTURE, QueryStringBuilder.class);
QueryStringBuilder policy = currentContext.getProperty(SET_POLICY, QueryStringBuilder.class);
if (infrastructure == null) {
throw new CLIException(REASON_INVALID_ARGUMENTS, "Infrastructure not specified");
}
if (policy == null) {
throw new CLIException(REASON_INVALID_ARGUMENTS, "Policy not specified");
}
if (currentContext.getProperty(SET_NODE_SOURCE, String.class) != null) {
nodeSource = currentContext.getProperty(SET_NODE_SOURCE, String.class);
}
HttpPost request = new HttpPost(currentContext.getResourceUrl("nodesource/create/recovery"));
QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
queryStringBuilder.add("nodeSourceName", nodeSource).addAll(infrastructure).addAll(policy).add("nodesRecoverable", nodesRecoverable);
request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
NSStateView nsState = readValue(response, NSStateView.class, currentContext);
boolean success = nsState.isResult();
resultStack(currentContext).push(success);
if (success) {
writeLine(currentContext, "Node source successfully created.");
} else {
writeLine(currentContext, "%s %s", "Cannot create node source:", nodeSource);
}
} else {
handleError("An error occurred while creating node source:", response, currentContext);
}
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class RemoveNodeSourceCommand method execute.
public void execute(ApplicationContext currentContext) throws CLIException {
if (currentContext.isForced()) {
preempt = true;
}
HttpPost request = new HttpPost(currentContext.getResourceUrl("nodesource/remove"));
QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
queryStringBuilder.add("name", nodeSource).add("preempt", Boolean.toString(preempt));
request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(response) == statusCode(OK)) {
boolean success = readValue(response, Boolean.TYPE, currentContext);
resultStack(currentContext).push(success);
if (success) {
writeLine(currentContext, "Node source '%s' deleted successfully.", nodeSource);
} else {
writeLine(currentContext, "Cannot delete node source: %s.", nodeSource);
}
} else {
handleError(String.format("An error occurred while deleting node source: %s", nodeSource), response, currentContext);
}
}
use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.
the class NodeSourceTest method testSetNodeAvailableKnownNode.
@Test
public void testSetNodeAvailableKnownNode() throws RMException {
Node node = createNode(PROACTIVE_PROGRAMMING_NODE_URL);
RMNode rmNode = new RMNodeImpl(node, nodeSource, client, mock(Permission.class));
nodeSource.internalAddNode(node);
nodeSource.detectedPingedDownNode(node.getNodeInformation().getName(), node.getNodeInformation().getURL());
assertThat(nodeSource.getDownNodes()).hasSize(1);
boolean result = nodeSource.setNodeAvailable(rmNode);
assertThat(result).isTrue();
assertThat(nodeSource.getDownNodes()).hasSize(0);
}
Aggregations