Search in sources :

Example 16 with ItemBase

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

the class DirectPlatformLayerClient method findItem.

@Override
public <T> T findItem(PlatformLayerKey key) throws PlatformLayerClientException {
    key = resolveKey(key);
    boolean fetchTags = true;
    ItemBase managedItem;
    try {
        managedItem = itemRepository.getManagedItem(key, fetchTags, getSecretProvider());
    } catch (RepositoryException e) {
        throw new PlatformLayerClientException("Error fetching item", e);
    }
    return (T) managedItem;
}
Also used : PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) ItemBase(org.platformlayer.core.model.ItemBase) RepositoryException(org.platformlayer.RepositoryException)

Example 17 with ItemBase

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

the class DirectPlatformLayerClient method listChildrenTyped.

@Override
public List<ItemBase> listChildrenTyped(PlatformLayerKey parentKey, boolean includeDeleted) throws OpsException {
    parentKey = resolveKey(parentKey);
    Tag parentTag = Tag.buildParentTag(parentKey);
    Filter filter = TagFilter.byTag(parentTag);
    if (!includeDeleted) {
        filter = StateFilter.excludeDeleted(filter);
    }
    List<ItemBase> items = itemService.listAll(auth, filter);
    return items;
}
Also used : StateFilter(org.platformlayer.StateFilter) TagFilter(org.platformlayer.TagFilter) Filter(org.platformlayer.Filter) ItemBase(org.platformlayer.core.model.ItemBase) Tag(org.platformlayer.core.model.Tag)

Example 18 with ItemBase

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

the class UntypedItemXml method setLinks.

public void setLinks(Links links) {
    ItemBase item = new ItemBase();
    item.links = links;
    Document document;
    JaxbHelper helper = JaxbHelper.get(ItemBase.class);
    try {
        document = helper.marshalToDom(item);
    } catch (JAXBException e) {
        throw new IllegalStateException("Error serializing data", e);
    }
    replaceNode("links", XmlHelper.findUniqueChild(document.getDocumentElement(), "links", false));
    // To avoid any possible state problems, we set to null rather than copying
    this.links = null;
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) JAXBException(javax.xml.bind.JAXBException) JaxbHelper(org.platformlayer.xml.JaxbHelper) Document(org.w3c.dom.Document)

Example 19 with ItemBase

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

the class PlatformlayerBackedPool method release.

@Override
public void release(PlatformLayerKey owner, T item) throws OpsException {
    for (int i = 0; i < 10; i++) {
        ItemBase resource = platformLayer.getItem(resourceKey);
        List<Assignment> assignments = findAssignments(resource);
        String key = adapter.toKey(item);
        Assignment assigned = Assignment.find(assignments, key, subkey);
        if (assigned == null) {
            throw new OpsException("Resource not assigned");
        }
        if (!assigned.item.equals(owner.getUrl())) {
            throw new OpsException("Resource not held");
        }
        Tag assignmentTag = assigned.asTag();
        TagChanges tagChanges = new TagChanges();
        tagChanges.removeTags.add(assignmentTag);
        if (null != platformLayer.changeTags(resourceKey, tagChanges, resource.getVersion())) {
            return;
        }
        if (!TimeSpan.ONE_SECOND.doSafeSleep()) {
            break;
        }
    }
// List<PlatformLayerKey> assignedTo = Tag.POOL_ASSIGNMENT.build(t) Tag.ASSIGNED_TO.find(item);
// if (!assignedTo.contains(holder)) {
// throw new OpsException("Resource not owned");
// }
//
// platformLayer.deleteItem(item.getKey());
}
Also used : OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) Tag(org.platformlayer.core.model.Tag) TagChanges(org.platformlayer.core.model.TagChanges)

Example 20 with ItemBase

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

the class StandardTemplateData method getAdditionalKeys.

public void getAdditionalKeys(Map<String, ManagedSecretKey> keys) throws OpsException {
    for (Link link : getLinks()) {
        ItemBase item = platformLayer.getItem(link.getTarget());
        LinkTarget linkTarget = providers.toInterface(item, LinkTarget.class);
        PlatformLayerKey caPath = linkTarget.getCaForClientKey();
        if (caPath != null) {
            String alias = links.buildKeyName(link);
            keys.put(alias, findCaSignedKey(caPath, alias));
        }
    }
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) LinkTarget(org.platformlayer.ops.uses.LinkTarget) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Link(org.platformlayer.core.model.Link)

Aggregations

ItemBase (org.platformlayer.core.model.ItemBase)56 OpsException (org.platformlayer.ops.OpsException)20 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)14 RepositoryException (org.platformlayer.RepositoryException)11 OpsContext (org.platformlayer.ops.OpsContext)11 Tag (org.platformlayer.core.model.Tag)8 BindingScope (org.platformlayer.ops.BindingScope)7 Machine (org.platformlayer.ops.Machine)7 DatabaseServer (org.platformlayer.ops.databases.DatabaseServer)6 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)6 Produces (javax.ws.rs.Produces)5 List (java.util.List)4 GET (javax.ws.rs.GET)4 TagChanges (org.platformlayer.core.model.TagChanges)4 OpsTarget (org.platformlayer.ops.OpsTarget)4 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)4 JAXBException (javax.xml.bind.JAXBException)3 Filter (org.platformlayer.Filter)3 InetAddressChooser (org.platformlayer.InetAddressChooser)3 StateFilter (org.platformlayer.StateFilter)3