use of org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder in project scheduling by ow2-proactive.
the class UnlockNodeCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpPost request = new HttpPost(currentContext.getResourceUrl("node/unlock"));
QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
for (String nodeUrl : nodeUrls) {
queryStringBuilder.add("nodeurls", nodeUrl);
}
request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
boolean success = readValue(response, Boolean.TYPE, currentContext);
resultStack(currentContext).push(success);
if (success) {
writeLine(currentContext, "Node(s) unlocked successfully.");
} else {
writeLine(currentContext, "Cannot unlock node(s).");
}
} else {
handleError("An error occurred while unlocking nodes:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder 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_grid_cloud_portal.cli.utils.QueryStringBuilder 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_grid_cloud_portal.cli.utils.QueryStringBuilder in project scheduling by ow2-proactive.
the class DeployNodeSourceCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpPut request = new HttpPut(currentContext.getResourceUrl(RM_REST_ENDPOINT));
QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
queryStringBuilder.add("nodeSourceName", nodeSourceName);
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 deployed.");
} else {
writeLine(currentContext, "%s %s", "Cannot deploy node source:", nodeSourceName);
}
} else {
handleError("An error occurred while deploying node source:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder in project scheduling by ow2-proactive.
the class RemoveNodeCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpPost request = new HttpPost(currentContext.getResourceUrl("node/remove"));
QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
queryStringBuilder.add("url", nodeUrl);
if (currentContext.isForced()) {
preempt = true;
}
if (preempt) {
queryStringBuilder.add("preempt", TRUE.toString());
}
request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
boolean successful = readValue(response, Boolean.TYPE, currentContext);
resultStack(currentContext).push(successful);
if (successful) {
writeLine(currentContext, "Node('%s') successfully removed.", nodeUrl);
} else {
writeLine(currentContext, "Cannot remove node: '%s'", nodeUrl);
}
} else {
handleError("An error occurred while removing node:", response, currentContext);
}
}
Aggregations