use of org.platformlayer.client.cli.PlatformLayerCliContext in project platformlayer by platformlayer.
the class ScriptCommands method toPython.
// public static Object listMetrics(String serviceType, String itemType, String itemKey) throws Exception {
// return runCommand(new ListMetrics(serviceType, itemType, itemKey));
// }
// public static Object doAction(String serviceType, String itemType, String itemKey, String action) throws
// Exception {
// DoAction cmd = new DoAction();
// cmd.path = serviceType + "/" + itemType + "/" + itemKey;
// cmd.action = action;
// return runCommand(cmd);
// }
// public static Object getMetric(String serviceType, String itemType, String itemKey, String metricKey) throws
// Exception {
// return runCommand(new GetMetric(serviceType, itemType, itemKey, metricKey));
// }
public static Object toPython(Object in) {
if (in instanceof Iterable) {
Iterable<?> list = (Iterable<?>) in;
PlatformLayerCliContext context = PlatformLayerCliContext.get();
List<Object> pythonObjects = Lists.newArrayList();
for (Object item : list) {
pythonObjects.add(toPython(item));
}
return FormattedList.build(context, pythonObjects, true);
}
if (in == null) {
return null;
}
return in;
}
use of org.platformlayer.client.cli.PlatformLayerCliContext in project platformlayer by platformlayer.
the class UntypedItemFormatter method visit.
@Override
public void visit(CliContext contextGeneric, UntypedItem o, OutputSink sink) throws IOException {
PlatformLayerCliContext context = (PlatformLayerCliContext) contextGeneric;
LinkedHashMap<String, Object> values = Maps.newLinkedHashMap();
UntypedItemXml item = (UntypedItemXml) o;
Element dataElement = item.getDataElement();
// String xml = o.getModelData();
//
// Element documentElement;
//
// try {
// Document dom = XmlHelper.parseXmlDocument(xml, false);
// documentElement = dom.getDocumentElement();
// } catch (Exception e) {
// throw new IllegalArgumentException("Error parsing XML", e);
// }
values.put("key", Utils.formatUrl(context, item.getKey()));
values.put("state", item.getState());
Tags tags = item.getTags();
values.put("tags", tagsToString(context, tags));
NodeList childNodes = dataElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
String nodeName = node.getNodeName();
String localName = node.getLocalName();
String namespace = node.getNamespaceURI();
if (namespace.equals("http://platformlayer.org/core/v1.0")) {
if (localName.equals("tags")) {
continue;
}
if (localName.equals("key")) {
continue;
}
if (localName.equals("version")) {
continue;
}
if (localName.equals("state")) {
continue;
}
}
String text = formatCell(node);
text = Utils.reformatText(context, text);
values.put(nodeName, text);
}
sink.outputRow(values);
}
use of org.platformlayer.client.cli.PlatformLayerCliContext in project platformlayer by platformlayer.
the class ScriptCommands method activateService.
public static Object activateService(String serviceType, Object properties) throws PlatformLayerClientException, JSONException {
PlatformLayerCliContext context = PlatformLayerCliContext.get();
PlatformLayerClient client = context.getPlatformLayerClient();
String json = properties.toString();
String wrapper = "{ \"data\": \"" + json + "\" }";
String retvalJsonString = client.activateService(serviceType, wrapper, Format.JSON);
JSONObject retvalJsonObject = new JSONObject(retvalJsonString);
return toPython(retvalJsonObject);
}
use of org.platformlayer.client.cli.PlatformLayerCliContext in project platformlayer by platformlayer.
the class ScriptCommands method getSchema.
public static Object getSchema(String serviceType) throws PlatformLayerClientException, JSONException {
PlatformLayerCliContext context = PlatformLayerCliContext.get();
PlatformLayerClient client = context.getPlatformLayerClient();
String retval = client.getSchema(serviceType, Format.XML);
return retval;
}
use of org.platformlayer.client.cli.PlatformLayerCliContext in project platformlayer by platformlayer.
the class ScriptCommands method getActivation.
public static Object getActivation(String serviceType) throws PlatformLayerClientException, JSONException {
PlatformLayerCliContext context = PlatformLayerCliContext.get();
PlatformLayerClient client = context.getPlatformLayerClient();
String retvalJsonString = client.getActivation(serviceType, Format.JSON);
JSONObject retvalJsonObject = new JSONObject(retvalJsonString);
return toPython(retvalJsonObject);
}
Aggregations