use of org.ow2.proactive_grid_cloud_portal.cli.CLIException in project scheduling by ow2-proactive.
the class LoginCommand method login.
@Override
protected String login(ApplicationContext currentContext) throws CLIException {
String password = currentContext.getProperty(PASSWORD, String.class);
if (password == null) {
password = new String(readPassword(currentContext, "password:"));
}
HttpPost request = new HttpPost(currentContext.getResourceUrl("login"));
StringEntity entity = new StringEntity("username=" + username + "&password=" + password, APPLICATION_FORM_URLENCODED);
request.setEntity(entity);
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
return StringUtility.responseAsString(response).trim();
} else {
throw buildCLIException(REASON_OTHER, response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.CLIException in project scheduling by ow2-proactive.
the class LoginWithCredentialsCommand method login.
@Override
protected String login(ApplicationContext currentContext) throws CLIException {
File credentials = new File(pathname);
if (!credentials.exists()) {
throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("File does not exist: %s", credentials.getAbsolutePath()));
}
if (warn) {
writeLine(currentContext, "Using the default credentials file: %s", credentials.getAbsolutePath());
}
HttpPost request = new HttpPost(currentContext.getResourceUrl("login"));
MultipartEntity entity = new MultipartEntity();
entity.addPart("credential", new ByteArrayBody(FileUtility.byteArray(credentials), APPLICATION_OCTET_STREAM.getMimeType()));
request.setEntity(entity);
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
return StringUtility.responseAsString(response).trim();
} else {
handleError("An error occurred while logging: ", response, currentContext);
throw new CLIException(REASON_OTHER, "An error occurred while logging.");
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.CLIException 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.CLIException 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.CLIException 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