Search in sources :

Example 1 with UntypedItem

use of org.platformlayer.common.UntypedItem 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 UntypedItem

use of org.platformlayer.common.UntypedItem 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 UntypedItem

use of org.platformlayer.common.UntypedItem in project platformlayer by platformlayer.

the class PlatformLayerClientBase method putItemByTag.

@Override
public <T extends ItemBase> T putItemByTag(T item, Tag uniqueTag) throws OpsException {
    JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(item);
    String xml = PlatformLayerClientBase.serialize(jaxbHelper, item);
    PlatformLayerKey key = PlatformLayerClientBase.toKey(jaxbHelper, item, listServices(true));
    UntypedItem ret = putItemByTag(key, uniqueTag, xml, Format.XML);
    Class<T> itemClass = (Class<T>) item.getClass();
    return promoteToTyped(ret, itemClass);
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) JaxbHelper(org.platformlayer.xml.JaxbHelper) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 4 with UntypedItem

use of org.platformlayer.common.UntypedItem in project platformlayer by platformlayer.

the class PlatformLayerClientBase method listItems.

@Override
public <T> List<T> listItems(Class<T> clazz) throws OpsException {
    JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(clazz, ManagedItemCollection.class);
    PlatformLayerKey path = PlatformLayerClientBase.toKey(jaxbHelper, null, listServices(true));
    UntypedItemCollection untypedItems = listItemsUntyped(path);
    List<T> items = Lists.newArrayList();
    for (UntypedItem untypedItem : untypedItems.getItems()) {
        T item = promoteToTyped(untypedItem, clazz);
        items.add(item);
    }
    return items;
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) JaxbHelper(org.platformlayer.xml.JaxbHelper) UntypedItemCollection(org.platformlayer.common.UntypedItemCollection) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 5 with UntypedItem

use of org.platformlayer.common.UntypedItem in project platformlayer by platformlayer.

the class OpenItem method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey key = path.resolve(getContext());
    UntypedItem untypedItem = client.getItemUntyped(key, getFormat());
    List<EndpointInfo> endpointList = EndpointInfo.getEndpoints(untypedItem.getTags());
    Set<EndpointInfo> endpoints = Sets.newHashSet(endpointList);
    EndpointInfo bestEndpoint = null;
    for (EndpointInfo candidate : endpoints) {
        if (bestEndpoint == null) {
            bestEndpoint = candidate;
        } else {
            throw new IllegalArgumentException("Cannot choose between: " + bestEndpoint + " and " + candidate);
        }
    }
    ClientAction action = null;
    if (bestEndpoint != null) {
        // TODO: How do we want to do this? A new tag??
        String id = key.getServiceType().getKey() + ":" + key.getItemType().getKey();
        if (id.equals("jenkins:jenkinsService")) {
            action = new ClientAction(ClientAction.ClientActionType.BROWSER, "http://" + bestEndpoint.publicIp + ":" + bestEndpoint.publicIp);
        }
    }
    return action;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) ClientAction(com.fathomdb.cli.output.ClientAction) UntypedItem(org.platformlayer.common.UntypedItem) EndpointInfo(org.platformlayer.core.model.EndpointInfo) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Aggregations

UntypedItem (org.platformlayer.common.UntypedItem)22 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)10 PlatformLayerClient (org.platformlayer.PlatformLayerClient)7 Ansi (com.fathomdb.cli.commands.Ansi)3 UntypedItemXml (org.platformlayer.UntypedItemXml)3 JaxbHelper (org.platformlayer.xml.JaxbHelper)3 CliException (com.fathomdb.cli.CliException)2 ClientAction (com.fathomdb.cli.output.ClientAction)2 InetAddress (java.net.InetAddress)2 EndpointInfo (org.platformlayer.core.model.EndpointInfo)2 Tag (org.platformlayer.core.model.Tag)2 Tags (org.platformlayer.core.model.Tags)2 NoCloseInputStream (com.fathomdb.io.NoCloseInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 UntypedItemCollection (org.platformlayer.common.UntypedItemCollection)1 ItemBase (org.platformlayer.core.model.ItemBase)1