Search in sources :

Example 1 with UntypedItemXml

use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.

the class FederatedPlatformLayerClient method putItemByTag.

@Override
public UntypedItem putItemByTag(PlatformLayerKey key, Tag uniqueTag, String data, Format format) throws PlatformLayerClientException {
    MappedPlatformLayerKey mapped = mapToChildForPut(key);
    UntypedItemXml post = UntypedItemXml.build(data);
    post.setPlatformLayerKey(mapped.key);
    UntypedItem item = mapped.child.client.putItemByTag(mapped.key, uniqueTag, post.serialize(), format);
    return mapped.child.setHost(item);
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) UntypedItemXml(org.platformlayer.UntypedItemXml)

Example 2 with UntypedItemXml

use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.

the class SshAddressFinder method visit.

public void visit(UntypedItem item) throws PlatformLayerClientException {
    UntypedItemXml untypedItem = (UntypedItemXml) item;
    ElementInfo rootElementInfo = untypedItem.getRootElementInfo();
    boolean consider = true;
    switch(untypedItem.getState()) {
        case DELETED:
        case DELETE_REQUESTED:
            consider = false;
            break;
    }
    Set<String> instanceTypes = Sets.newHashSet();
    instanceTypes.add("directInstance");
    instanceTypes.add("googleCloudInstance");
    if (!instanceTypes.contains(rootElementInfo.elementName)) {
        consider = false;
    }
    if (consider) {
        Tags itemTags = untypedItem.getTags();
        for (InetAddress address : Tag.NETWORK_ADDRESS.find(itemTags)) {
            found.add(address);
        }
    }
    boolean includeDeleted = false;
    for (UntypedItem child : client.listChildren(untypedItem.getKey(), includeDeleted).getItems()) {
        visit(child);
    }
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) ElementInfo(org.platformlayer.xml.XmlHelper.ElementInfo) UntypedItemXml(org.platformlayer.UntypedItemXml) InetAddress(java.net.InetAddress) Tags(org.platformlayer.core.model.Tags)

Example 3 with UntypedItemXml

use of org.platformlayer.UntypedItemXml 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 4 with UntypedItemXml

use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.

the class PutLink method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey resolved = path.resolve(getContext());
    UntypedItemXml item = (UntypedItemXml) client.getItemUntyped(resolved, Format.XML);
    Links links = item.getLinks();
    Link link = new Link();
    link.name = name;
    link.target = target.resolve(getContext());
    Link existing = links.findLink(name);
    List<Link> linkList = links.getLinks();
    if (existing != null) {
        linkList.remove(existing);
    }
    linkList.add(link);
    item.setLinks(links);
    String xml = item.serialize();
    UntypedItemXml updated = (UntypedItemXml) client.putItem(resolved, xml, Format.XML);
    return updated.getLinks().getLinks();
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) UntypedItemXml(org.platformlayer.UntypedItemXml) Links(org.platformlayer.core.model.Links) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Link(org.platformlayer.core.model.Link)

Example 5 with UntypedItemXml

use of org.platformlayer.UntypedItemXml in project platformlayer by platformlayer.

the class ItemMutatorCommand method runCommand.

protected UntypedItemXml runCommand(ItemPath path) throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey resolved = path.resolve(getContext());
    UntypedItemXml item = (UntypedItemXml) client.getItemUntyped(resolved, Format.XML);
    changeItem(item);
    String xml = item.serialize();
    UntypedItemXml updated = (UntypedItemXml) client.putItem(resolved, xml, Format.XML);
    return updated;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) UntypedItemXml(org.platformlayer.UntypedItemXml) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Aggregations

UntypedItemXml (org.platformlayer.UntypedItemXml)9 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)4 PlatformLayerClient (org.platformlayer.PlatformLayerClient)3 UntypedItem (org.platformlayer.common.UntypedItem)3 Ansi (com.fathomdb.cli.commands.Ansi)2 Link (org.platformlayer.core.model.Link)2 Links (org.platformlayer.core.model.Links)2 Tags (org.platformlayer.core.model.Tags)2 InetAddress (java.net.InetAddress)1 Source (javax.xml.transform.Source)1 DOMSource (javax.xml.transform.dom.DOMSource)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 UntypedItemJson (org.platformlayer.UntypedItemJson)1 PlatformLayerCliContext (org.platformlayer.client.cli.PlatformLayerCliContext)1 ElementInfo (org.platformlayer.xml.XmlHelper.ElementInfo)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1