use of org.ow2.proactive_grid_cloud_portal.cli.CLIException 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.CLIException 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.CLIException 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.CLIException 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);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.CLIException 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);
}
}
Aggregations