Search in sources :

Example 26 with Tag

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

the class PlatformLayerHelpers method setCollection.

public void setCollection(PlatformLayerKey key, String tagKey, Collection<Tag> newTags) throws OpsException {
    Set<String> newValues = Sets.newHashSet();
    for (Tag newTag : newTags) {
        if (!tagKey.equals(newTag.getKey())) {
            throw new IllegalStateException();
        }
        newValues.add(newTag.getValue());
    }
    setCollectionValues(key, tagKey, newValues);
}
Also used : Tag(org.platformlayer.core.model.Tag)

Example 27 with Tag

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

the class PlatformLayerHelpers method setCollectionValues.

public void setCollectionValues(PlatformLayerKey key, String tagKey, Collection<String> newTagValues) throws OpsException {
    Set<String> newTagValuesSet = Sets.newHashSet(newTagValues);
    Tags existingTags = getItemTags(key);
    TagChanges tagChanges = new TagChanges();
    Set<String> foundValues = Sets.newHashSet();
    for (Tag existingTag : existingTags) {
        String existingTagKey = existingTag.getKey();
        if (!tagKey.equals(existingTagKey)) {
            continue;
        }
        String existingTagValue = existingTag.getValue();
        if (!newTagValuesSet.contains(existingTagValue)) {
            tagChanges.removeTags.add(existingTag);
        } else {
            foundValues.add(existingTagValue);
        }
    }
    for (String newTagValue : newTagValues) {
        if (foundValues.contains(newTagValue)) {
            continue;
        }
        tagChanges.addTags.add(Tag.build(tagKey, newTagValue));
    }
    if (!tagChanges.isEmpty()) {
        changeTags(key, tagChanges);
    }
}
Also used : Tag(org.platformlayer.core.model.Tag) TagChanges(org.platformlayer.core.model.TagChanges) Tags(org.platformlayer.core.model.Tags)

Example 28 with Tag

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

the class PlatformLayerHelpers method setUniqueTags.

public void setUniqueTags(PlatformLayerKey key, Iterable<Tag> uniqueTags) throws OpsException {
    Tags tags = getItemTags(key);
    TagChanges tagChanges = new TagChanges();
    for (Tag setTag : uniqueTags) {
        String tagKey = setTag.getKey();
        List<String> existing = tags.findAll(tagKey);
        if (existing == null || existing.isEmpty()) {
            tagChanges.addTags.add(setTag);
        } else if (existing.size() == 1) {
            String existingValue = existing.get(0);
            if (!Objects.equal(existingValue, setTag.value)) {
                tagChanges.addTags.add(setTag);
                tagChanges.removeTags.add(Tag.build(tagKey, existingValue));
            }
        } else {
            // We probably should replace existing tags...
            throw new OpsException("Found duplicate tag for: " + setTag.key);
        }
    }
    if (!tagChanges.isEmpty()) {
        changeTags(key, tagChanges);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) Tag(org.platformlayer.core.model.Tag) TagChanges(org.platformlayer.core.model.TagChanges) Tags(org.platformlayer.core.model.Tags)

Example 29 with Tag

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

the class ImageFactory method findBootstrapImage.

private CloudImage findBootstrapImage(ImageFormat format, ImageStore imageStore) throws OpsException {
    // Tag formatTag = buildImageFormatTag(format);
    // 
    // CloudImage image = imageStore.findImage(Lists.newArrayList(formatTag, BOOTSTRAP_IMAGE_TAG));
    // if (image != null) {
    // return image;
    // }
    Tag osDebian = Tag.build(Tag.IMAGE_OS_DISTRIBUTION, "debian.org");
    Tag osSqueeze = Tag.build(Tag.IMAGE_OS_VERSION, "6.0.4");
    Tag diskFormatTag;
    switch(format) {
        case DiskQcow2:
            diskFormatTag = format.toTag();
            break;
        default:
            log.warn("Unsupported format: " + format);
            return null;
    }
    List<CloudImage> images = imageStore.findImages(Arrays.asList(diskFormatTag, osDebian, osSqueeze));
    for (CloudImage candidate : images) {
        return candidate;
    }
    return null;
}
Also used : CloudImage(org.platformlayer.ops.images.CloudImage) Tag(org.platformlayer.core.model.Tag)

Example 30 with Tag

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

the class PropertiesFileStore method asTags.

public Tags asTags(Properties properties) {
    Tags tags = new Tags();
    for (Object keyObject : properties.keySet()) {
        String key = (String) keyObject;
        // if (key.startsWith(PROPERTY_PREFIX_TAG)) {
        // String tagName = key.substring(PROPERTY_PREFIX_TAG.length());
        String tagName = key;
        Tag tag = Tag.build(tagName, properties.getProperty(key));
        tags.add(tag);
    // }
    }
    return tags;
}
Also used : Tag(org.platformlayer.core.model.Tag) Tags(org.platformlayer.core.model.Tags)

Aggregations

Tag (org.platformlayer.core.model.Tag)41 OpsException (org.platformlayer.ops.OpsException)16 ItemBase (org.platformlayer.core.model.ItemBase)8 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)8 Tags (org.platformlayer.core.model.Tags)8 Handler (org.platformlayer.ops.Handler)8 TagChanges (org.platformlayer.core.model.TagChanges)6 JSONObject (org.json.JSONObject)4 OpenstackException (org.openstack.client.OpenstackException)4 RepositoryException (org.platformlayer.RepositoryException)4 Machine (org.platformlayer.ops.Machine)4 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)3 SQLException (java.sql.SQLException)3 OpenstackImageClient (org.openstack.client.common.OpenstackImageClient)3 Filter (org.platformlayer.Filter)3 PlatformLayerClient (org.platformlayer.PlatformLayerClient)3 StateFilter (org.platformlayer.StateFilter)3 OpsTarget (org.platformlayer.ops.OpsTarget)3 UniqueTag (org.platformlayer.ops.UniqueTag)3 SshKey (org.platformlayer.ops.helpers.SshKey)3