Search in sources :

Example 1 with Tags

use of org.platformlayer.core.model.Tags in project platformlayer by platformlayer.

the class Tagger method handler.

@Handler
public void handler() throws OpsException {
    if (OpsContext.isDelete() || OpsContext.isConfigure()) {
        TagChanges tagChanges = tagChangesProvider.get();
        if (tagChanges != null) {
            log.info("Setting tags on " + platformLayerKey);
            if (OpsContext.isDelete()) {
                // Swap the tags for a removal
                Tags x = tagChanges.addTags;
                tagChanges.addTags = tagChanges.removeTags;
                tagChanges.removeTags = x;
            }
            platformLayer.changeTags(platformLayerKey, tagChanges, null);
        }
    }
}
Also used : TagChanges(org.platformlayer.core.model.TagChanges) Tags(org.platformlayer.core.model.Tags) Handler(org.platformlayer.ops.Handler)

Example 2 with Tags

use of org.platformlayer.core.model.Tags in project platformlayer by platformlayer.

the class PlatformLayerHelpers method getOrCreateUuid.

public UUID getOrCreateUuid(ItemBase model) throws PlatformLayerClientException {
    Tags tags = model.getTags();
    UUID uuid = Tag.UUID.findUnique(tags);
    if (uuid != null) {
        return uuid;
    }
    uuid = UUID.randomUUID();
    Tag uuidTag = Tag.UUID.build(uuid);
    tags.add(uuidTag);
    this.addTag(model.getKey(), uuidTag);
    return uuid;
}
Also used : Tag(org.platformlayer.core.model.Tag) UUID(java.util.UUID) Tags(org.platformlayer.core.model.Tags)

Example 3 with Tags

use of org.platformlayer.core.model.Tags 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 4 with Tags

use of org.platformlayer.core.model.Tags 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 5 with Tags

use of org.platformlayer.core.model.Tags in project platformlayer by platformlayer.

the class DirectImageStore method findImages.

@Override
public List<CloudImage> findImages(List<Tag> tags) throws OpsException {
    List<CloudImage> images = Lists.newArrayList();
    for (String imageId : fileStore.find(tags)) {
        Properties properties = fileStore.readProperties(imageId);
        Tags imageTags = fileStore.asTags(properties);
        images.add(new DirectCloudImage(this, imageId, imageTags));
    }
    return images;
}
Also used : CloudImage(org.platformlayer.ops.images.CloudImage) Properties(java.util.Properties) Tags(org.platformlayer.core.model.Tags)

Aggregations

Tags (org.platformlayer.core.model.Tags)20 Tag (org.platformlayer.core.model.Tag)8 MachineCreationRequest (org.platformlayer.ops.MachineCreationRequest)6 TagChanges (org.platformlayer.core.model.TagChanges)5 OpsException (org.platformlayer.ops.OpsException)5 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)3 Handler (org.platformlayer.ops.Handler)3 OpsTarget (org.platformlayer.ops.OpsTarget)3 SshKey (org.platformlayer.ops.helpers.SshKey)3 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)2 SQLException (java.sql.SQLException)2 Produces (javax.ws.rs.Produces)2 RepositoryException (org.platformlayer.RepositoryException)2 UntypedItemXml (org.platformlayer.UntypedItemXml)2 UntypedItem (org.platformlayer.common.UntypedItem)2 Machine (org.platformlayer.ops.Machine)2 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)1 CryptoKey (com.fathomdb.crypto.CryptoKey)1 Instance (com.google.api.services.compute.model.Instance)1 Operation (com.google.api.services.compute.model.Operation)1