Search in sources :

Example 1 with PlatformLayerCliContext

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;
}
Also used : PlatformLayerCliContext(org.platformlayer.client.cli.PlatformLayerCliContext) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 2 with PlatformLayerCliContext

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);
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) PlatformLayerCliContext(org.platformlayer.client.cli.PlatformLayerCliContext) UntypedItemXml(org.platformlayer.UntypedItemXml) Tags(org.platformlayer.core.model.Tags)

Example 3 with PlatformLayerCliContext

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);
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) JSONObject(org.codehaus.jettison.json.JSONObject) PlatformLayerCliContext(org.platformlayer.client.cli.PlatformLayerCliContext)

Example 4 with PlatformLayerCliContext

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;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) PlatformLayerCliContext(org.platformlayer.client.cli.PlatformLayerCliContext)

Example 5 with PlatformLayerCliContext

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);
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) JSONObject(org.codehaus.jettison.json.JSONObject) PlatformLayerCliContext(org.platformlayer.client.cli.PlatformLayerCliContext)

Aggregations

PlatformLayerCliContext (org.platformlayer.client.cli.PlatformLayerCliContext)6 PlatformLayerClient (org.platformlayer.PlatformLayerClient)4 JSONObject (org.codehaus.jettison.json.JSONObject)3 UntypedItemXml (org.platformlayer.UntypedItemXml)1 Tags (org.platformlayer.core.model.Tags)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1