use of org.ow2.proactive_grid_cloud_portal.cli.json.NodeEventView in project scheduling by ow2-proactive.
the class StringUtility method string.
public static String string(NodeEventView[] nodeEvents) {
ObjectArrayFormatter formatter = new ObjectArrayFormatter();
formatter.setMaxColumnLength(300);
formatter.setSpace(4);
List<String> titles = new ArrayList<>(7);
titles.add("SOURCE_NAME");
titles.add("HOST_NAME");
titles.add("STATE");
titles.add("SINCE");
titles.add("LOCKED");
titles.add("LOCKED_BY");
titles.add("LOCK_TIME");
titles.add("URL");
titles.add("PROVIDER");
titles.add("USED_BY");
formatter.setTitle(titles);
formatter.addEmptyLine();
if (nodeEvents != null) {
for (NodeEventView nodeEvent : nodeEvents) {
List<String> line = new ArrayList<>(10);
line.add(nodeEvent.getNodeSource());
line.add(nodeEvent.getHostName());
line.add(nodeEvent.getNodeState());
line.add(getStateChangeTime(nodeEvent));
line.add(nodeEvent.isLocked());
line.add(toStringNullable(nodeEvent.getNodeLocker()));
line.add(getLockTime(nodeEvent));
line.add(nodeEvent.getNodeUrl());
line.add(toStringNullable(nodeEvent.getNodeProvider()));
line.add(toStringNullable(nodeEvent.getNodeOwner()));
formatter.addLine(line);
}
}
return Tools.getStringAsArray(formatter);
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.NodeEventView 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.json.NodeEventView 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);
}
}
Aggregations