use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class RmStatsCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
StringBuilder url = new StringBuilder();
url.append("info/ProActiveResourceManager:name=RuntimeData?");
QueryStringBuilder builder = new QueryStringBuilder();
for (String attr : RUNTIME_DATA_ATTR) {
builder.add("attr", attr);
}
url.append(builder.buildString());
HttpGet request = new HttpGet(currentContext.getResourceUrl(url.toString()));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
List<MBeanInfoView> infoList = readValue(response, new TypeReference<List<MBeanInfoView>>() {
}, currentContext);
MBeanInfoView[] stats = infoList.toArray(new MBeanInfoView[infoList.size()]);
resultStack(currentContext).push(stats);
if (!currentContext.isSilent()) {
writeLine(currentContext, "%s", StringUtility.mBeanInfoAsString(stats));
}
} else {
handleError("An error occurred while retrieving stats:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class SetInfrastructureCommand 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);
for (PluginView pluginView : pluginViewList) {
infrastructures.put(pluginView.getPluginName(), pluginView);
}
currentContext.setInfrastructures(infrastructures);
} else {
handleError("Unable to retrieve known infrastructure types:", response, currentContext);
}
}
if (infrastructures != null) {
PluginView pluginView = infrastructures.get(infrastructureType);
if (pluginView == null) {
throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("Unknown infrastructure type: %s", infrastructureType));
}
ConfigurableFieldView[] configurableFields = pluginView.getConfigurableFields();
if (configurableFields.length != infrastructureArgs.length) {
throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("Invalid number of arguments specified for '%s' type.", infrastructureType));
}
QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
queryStringBuilder.add("infrastructureType", infrastructureType);
for (int index = 0; index < configurableFields.length; index++) {
ConfigurableFieldView cf = configurableFields[index];
Type ft = cf.getMeta().type();
if (FILEBROWSER.equals(ft) || CREDENTIAL.equals(ft)) {
if ("".equals(infrastructureArgs[index])) {
String contents = "";
queryStringBuilder.add("infrastructureFileParameters", contents);
} else {
String contents = FileUtility.readFileToString(new File(infrastructureArgs[index]));
queryStringBuilder.add("infrastructureFileParameters", contents);
}
} else {
queryStringBuilder.add("infrastructureParameters", infrastructureArgs[index]);
}
}
currentContext.setProperty(SET_INFRASTRUCTURE, queryStringBuilder);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class ShutdownCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
HttpGet request = new HttpGet(currentContext.getResourceUrl("shutdown"));
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
boolean success = readValue(response, Boolean.TYPE, currentContext);
resultStack(currentContext).push(success);
if (success) {
writeLine(currentContext, "%s", "Resource manager shutdown successfully.");
} else {
writeLine(currentContext, "%s", "Cannot shutdown resource manager.");
}
} else {
handleError("An error occurred while shutting down:", response, currentContext);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.
the class UndeployNodeSourceCommand 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", this.nodeSourceName).add("preempt", Boolean.toString(this.preempt));
request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
HttpResponseWrapper response = this.execute(request, currentContext);
if (this.statusCode(OK) == this.statusCode(response)) {
NSStateView nsState = this.readValue(response, NSStateView.class, currentContext);
boolean success = nsState.isResult();
this.resultStack(currentContext).push(success);
if (success) {
writeLine(currentContext, "Node source successfully undeployed.");
} else {
writeLine(currentContext, "%s %s", "Cannot undeploy node source:", this.nodeSourceName);
}
} else {
this.handleError("An error occurred while undeploying node source:", response, currentContext);
}
}
Aggregations