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);
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations