Search in sources :

Example 6 with PlatformLayerClientException

use of org.platformlayer.PlatformLayerClientException in project platformlayer by platformlayer.

the class ImageFactory method getOrCreateImage.

public DiskImage getOrCreateImage(DiskImage template) throws OpsException {
    DiskImage best = null;
    try {
        for (DiskImage candidate : platformLayer.listItems(DiskImage.class)) {
            if (isMatch(candidate, template)) {
                best = candidate;
                break;
            }
        }
        if (best == null) {
            // We should be owned by the recipe
            PlatformLayerKey recipeKey = template.getRecipeId();
            if (recipeKey != null) {
                template.getTags().add(Tag.buildParentTag(recipeKey));
            }
            best = platformLayer.putItem(template);
        }
    } catch (PlatformLayerClientException e) {
        throw new OpsException("Error fetching or building image", e);
    }
    return best;
}
Also used : PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) OpsException(org.platformlayer.ops.OpsException) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) DiskImage(org.platformlayer.images.model.DiskImage)

Aggregations

PlatformLayerClientException (org.platformlayer.PlatformLayerClientException)6 OpsException (org.platformlayer.ops.OpsException)3 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 Tag (org.platformlayer.core.model.Tag)2 Handler (org.platformlayer.ops.Handler)2 HttpPlatformLayerClient (org.platformlayer.HttpPlatformLayerClient)1 PlatformLayerClient (org.platformlayer.PlatformLayerClient)1 PlatformLayerEndpointInfo (org.platformlayer.PlatformLayerEndpointInfo)1 RepositoryException (org.platformlayer.RepositoryException)1 EndpointInfo (org.platformlayer.core.model.EndpointInfo)1 ItemBase (org.platformlayer.core.model.ItemBase)1 PublicEndpointBase (org.platformlayer.core.model.PublicEndpointBase)1 DnsRecord (org.platformlayer.dns.model.DnsRecord)1 DiskImage (org.platformlayer.images.model.DiskImage)1 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)1