use of org.platformlayer.core.model.Tag in project platformlayer by platformlayer.
the class ManagedItemResource method listChildren.
@GET
@Produces({ XML, JSON })
@Path("children")
public ManagedItemCollection<ItemBase> listChildren(@QueryParam("deleted") boolean includeDeleted) throws OpsException, RepositoryException {
boolean fetchTags = true;
ItemBase item = getManagedItem(fetchTags);
Tag parentTag = Tag.buildParentTag(item.getKey());
Filter filter = TagFilter.byTag(parentTag);
if (!includeDeleted) {
filter = StateFilter.excludeDeleted(filter);
}
List<ItemBase> roots = itemService.listAll(getProjectAuthorization(), filter);
ManagedItemCollection<ItemBase> collection = new ManagedItemCollection<ItemBase>();
collection.items = roots;
return cleanup(collection);
}
use of org.platformlayer.core.model.Tag in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method listAll.
@Override
@JdbcTransaction
public List<ItemBase> listAll(ProjectId project, Filter filter, SecretProvider secretProvider) throws RepositoryException {
DbHelper db = new DbHelper(project);
try {
log.debug("listAll with filter: {}", filter);
// TODO: Use this logic for item selection as well
List<Tag> requiredTags = filter.getRequiredTags();
JoinedQueryResult result;
if (!requiredTags.isEmpty()) {
Tag requiredTag = requiredTags.get(0);
int projectId = db.mapToValue(project);
result = db.queries.listAllItemsWithTag(projectId, projectId, requiredTag.getKey(), requiredTag.getValue());
} else {
log.warn("Unable to optimize filter; selecting all items. Filter={}", filter);
result = db.listAllItems();
}
List<ItemBase> items = mapItemsAndTags(project, secretProvider, db, result);
return applyFilter(items, filter);
} catch (SQLException e) {
throw new RepositoryException("Error fetching items", e);
} finally {
db.close();
}
}
use of org.platformlayer.core.model.Tag in project platformlayer by platformlayer.
the class AddTag method runCommand.
@Override
public Object runCommand() throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
PlatformLayerKey resolved = path.resolve(getContext());
TagChanges tagChanges = new TagChanges();
Tag tag = Tag.build(tagKey, tagValue);
tagChanges.addTags.add(tag);
return client.changeTags(resolved, tagChanges, null);
}
use of org.platformlayer.core.model.Tag in project platformlayer by platformlayer.
the class DeleteTag method runCommand.
@Override
public Object runCommand() throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
PlatformLayerKey key = path.resolve(getContext());
UntypedItem ret = client.getItemUntyped(key, Format.XML);
TagChanges tagChanges = new TagChanges();
for (Tag tag : ret.getTags()) {
if (!tagKey.equals(tag.getKey())) {
continue;
}
if (tagValue != null && !tagValue.equals(tag.getValue())) {
continue;
}
tagChanges.removeTags.add(tag);
}
Tags newTags = client.changeTags(key, tagChanges, null);
return newTags;
}
use of org.platformlayer.core.model.Tag in project platformlayer by platformlayer.
the class InstanceBuilder method doOperation.
@Handler
public void doOperation() throws OpsException, IOException {
ItemBase item = ops.getInstance(ItemBase.class);
Tag parentTag = Tag.buildParentTag(item.getKey());
PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();
persistentInstanceTemplate.getTags().add(parentTag);
// Set during doOperation
Machine machine = null;
PersistentInstance persistentInstance = null;
InstanceBase instance = null;
OpsTarget target = null;
persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);
if (persistentInstance != null) {
// We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
// TODO: Should we always use the instance id??
instance = instances.findInstance(persistentInstance);
if (instance == null && !OpsContext.isDelete()) {
// A machine has not (yet) been assigned
throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
}
}
if (instance != null) {
machine = cloudHelpers.toMachine(instance);
}
if (addTagToManaged && !OpsContext.isDelete()) {
// Add tag with instance id to persistent instance (very helpful for
// DNS service!)
PlatformLayerKey machineKey = machine.getKey();
platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
}
SshKey sshKey = service.getSshKey();
if (machine != null) {
if (OpsContext.isDelete()) {
target = null;
machine = null;
} else {
target = machine.getTarget(sshKey);
}
}
RecursionState recursion = getRecursionState();
if (OpsContext.isDelete() && machine == null) {
// Don't recurse into no machine :-)
recursion.setPreventRecursion(true);
}
recursion.pushChildScope(Machine.class, machine);
recursion.pushChildScope(PersistentInstance.class, persistentInstance);
recursion.pushChildScope(InstanceBase.class, instance);
recursion.pushChildScope(OpsTarget.class, target);
}
Aggregations