use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class DefineNodeSourceCommand 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(RM_REST_ENDPOINT));
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 defined.");
} else {
writeLine(currentContext, "%s %s", "Cannot define node source:", nodeSource);
}
} else {
handleError("An error occurred while defining node source:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class GetTopologyCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpGet request = new HttpGet(currentContext.getResourceUrl("topology"));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
TopologyView topology = readValue(response, TopologyView.class, currentContext);
resultStack(currentContext).push(topology);
if (!currentContext.isSilent()) {
writeLine(currentContext, "%s", StringUtility.string(topology));
}
} else {
handleError("An error occurred while retrieving the topology:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class ListNodeCommand 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[] selectedNodeEvents = null;
if (nodeEvents != null) {
if (nodeSource == null) {
selectedNodeEvents = nodeEvents;
} else {
List<NodeEventView> selectedList = new ArrayList<>();
for (NodeEventView nodeEvent : nodeEvents) {
if (!nodeSource.equals(nodeEvent.getNodeSource())) {
// node source doesn't match
continue;
} else {
selectedList.add(nodeEvent);
}
}
selectedNodeEvents = selectedList.toArray(new NodeEventView[selectedList.size()]);
}
}
// filter out all node events that was removed
// so rm client does not display them
List<NodeEventView> filtered = new ArrayList<>();
for (NodeEventView nodeEvent : selectedNodeEvents) {
if (!nodeEvent.isRemoved()) {
filtered.add(nodeEvent);
}
}
NodeEventView[] result = new NodeEventView[filtered.size()];
result = filtered.toArray(result);
resultStack(currentContext).push(result);
writeLine(currentContext, "%s", StringUtility.string(result));
} else {
handleError("An error occurred while retrieving nodes:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class ListPolicyCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
Map<String, PluginView> knownPolicyMap = currentContext.getPolicies();
if (knownPolicyMap == null) {
HttpGet request = new HttpGet(currentContext.getResourceUrl("policies"));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
List<PluginView> pluginViewList = readValue(response, new TypeReference<List<PluginView>>() {
}, currentContext);
resultStack(currentContext).push(pluginViewList.toArray(new PluginView[pluginViewList.size()]));
knownPolicyMap = new HashMap<>();
for (PluginView pluginView : pluginViewList) {
knownPolicyMap.put(pluginView.getPluginName(), pluginView);
}
currentContext.setPolicies(knownPolicyMap);
} else {
handleError("An error occurred while retrieving supported policy types:", response, currentContext);
}
}
if (!currentContext.isSilent()) {
if (knownPolicyMap != null) {
writeLine(currentContext, "%n%s:%n", "Supported policy types");
for (PluginView policy : knownPolicyMap.values()) {
writeLine(currentContext, "%s%n", policy.toString());
}
}
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class LockNodeCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpPost request = new HttpPost(currentContext.getResourceUrl("node/lock"));
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 successful = readValue(response, Boolean.TYPE, currentContext);
resultStack(currentContext).push(successful);
if (successful) {
writeLine(currentContext, "Node(s) locked successfully.");
} else {
writeLine(currentContext, "Cannot lock node(s).");
}
} else {
handleError("An error occurred while locking nodes:", response, currentContext);
}
}
Aggregations