use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper 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.HttpResponseWrapper in project scheduling by ow2-proactive.
the class GetNodeInfoCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpGet request = new HttpGet(currentContext.getResourceUrl("monitoring"));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
RmStateView state = readValue(response, RmStateView.class, currentContext);
NodeEventView[] nodeEvents = state.getNodesEvents();
NodeEventView target = null;
for (NodeEventView nodeEvent : nodeEvents) {
if (nodeUrl.equals(nodeEvent.getNodeUrl())) {
target = nodeEvent;
break;
}
}
if (target == null) {
writeLine(currentContext, "Cannot find node: '%s'", nodeUrl);
return;
}
resultStack(currentContext).push(target);
writeLine(currentContext, "%s", target.getNodeInfo());
} else {
handleError("An error occurred while retrieving node info.", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class ListInfrastructureCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
Map<String, PluginView> infrastructures = currentContext.getInfrastructures();
if (infrastructures == null) {
HttpGet request = new HttpGet(currentContext.getResourceUrl("infrastructures"));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
infrastructures = new HashMap<>();
List<PluginView> pluginViewList = readValue(response, new TypeReference<List<PluginView>>() {
}, currentContext);
resultStack(currentContext).push(pluginViewList);
for (PluginView pluginView : pluginViewList) {
infrastructures.put(pluginView.getPluginName(), pluginView);
}
currentContext.setInfrastructures(infrastructures);
} else {
handleError("An error occurred while retrieving supported infrastructure types:", response, currentContext);
}
}
if (infrastructures != null) {
writeLine(currentContext, "%n%s:%n", "Supported infrastructure types");
for (PluginView pluginView : infrastructures.values()) {
writeLine(currentContext, "%s%n", pluginView.toString());
}
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class ListNodeSourceCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpGet request = new HttpGet(currentContext.getResourceUrl("monitoring"));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
RmStateView state = readValue(response, RmStateView.class, currentContext);
NodeSourceView[] nodeSources = state.getNodeSource();
// filter out all node source events that was removed
// so rm client does not display them
List<NodeSourceView> filtered = new ArrayList<>(nodeSources.length);
for (NodeSourceView nodeSourceEvent : nodeSources) {
if (!nodeSourceEvent.isRemoved()) {
filtered.add(nodeSourceEvent);
}
}
NodeSourceView[] result = new NodeSourceView[filtered.size()];
result = filtered.toArray(result);
resultStack(currentContext).push(result);
if (!currentContext.isSilent()) {
writeLine(currentContext, "%s", StringUtility.string(result));
}
} else {
handleError("An error occurred while retrieving node sources:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper 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