Search in sources :

Example 1 with PlatformLayerClientException

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

the class SchedulerImpl method toRunnable.

private Runnable toRunnable(final ActionTask task) {
    final PlatformLayerKey target = task.target;
    final PlatformLayerEndpointInfo endpoint = rehydrateEndpoint(task.endpoint);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                PlatformLayerClient platformLayer = HttpPlatformLayerClient.build(httpStrategy, endpoint.getPlatformlayerBaseUrl(), endpoint.getAuthenticator(), endpoint.getProjectId(), endpoint.getTrustKeys());
                platformLayer.doAction(target, task.action);
            // TODO: Wait for task completion??
            // TODO: Link job id??
            } catch (PlatformLayerClientException e) {
                log.warn("Error running action", e);
            }
        }

        @Override
        public String toString() {
            return task.action + " on " + task.target;
        }
    };
    return runnable;
}
Also used : HttpPlatformLayerClient(org.platformlayer.HttpPlatformLayerClient) PlatformLayerClient(org.platformlayer.PlatformLayerClient) PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) PlatformLayerEndpointInfo(org.platformlayer.PlatformLayerEndpointInfo) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 2 with PlatformLayerClientException

use of org.platformlayer.PlatformLayerClientException 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 3 with PlatformLayerClientException

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

the class DirectPlatformLayerClient method getModelClass.

protected ModelClass<?> getModelClass(ServiceType serviceType, ItemType itemType) throws PlatformLayerClientException {
    ServiceProvider serviceProvider = getServiceProvider(serviceType);
    if (serviceProvider == null) {
        log.warn("Unknown serviceType: " + serviceType);
        throw new PlatformLayerClientException("Service type not recognized: " + serviceType.getKey());
    }
    ModelClass<?> modelClass = serviceProvider.getModels().find(itemType);
    if (modelClass == null) {
        log.warn("Unknown itemtype: " + itemType);
        throw new PlatformLayerClientException("Item type not recognized: " + itemType.getKey());
    }
    return modelClass;
}
Also used : PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider)

Example 4 with PlatformLayerClientException

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

the class OwnedItem method handler.

@Handler
public void handler() throws OpsException {
    T itemTemplate = buildItemTemplate();
    Tag uniqueTag = getUniqueTag(itemTemplate);
    if (OpsContext.isConfigure()) {
        try {
            item = platformLayer.putItemByTag(itemTemplate, uniqueTag);
        } catch (PlatformLayerClientException e) {
            throw new OpsException("Error creating owned item", e);
        }
    }
    if (OpsContext.isDelete()) {
        List<? extends ItemBase> items = platformLayer.listItems(itemTemplate.getClass(), TagFilter.byTag(uniqueTag));
        if (items.size() != 0) {
            if (items.size() != 1) {
                throw new OpsException("Found multiple items with unique tag: " + uniqueTag);
            }
            item = (T) items.get(0);
            platformLayer.ensureDeleted(item);
        }
    }
}
Also used : PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) OpsException(org.platformlayer.ops.OpsException) Tag(org.platformlayer.core.model.Tag) Handler(org.platformlayer.ops.Handler)

Example 5 with PlatformLayerClientException

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

the class EndpointDnsRecord method handler.

@Handler
public void handler() throws OpsException {
    PublicEndpointBase endpoint = endpointProvider.get();
    if (OpsContext.isConfigure()) {
        // Create a DNS record
        Tag parentTag = Tag.buildParentTag(endpoint.getKey());
        List<EndpointInfo> endpoints = EndpointInfo.findEndpoints(endpoint.getTags(), destinationPort);
        if (endpoints.isEmpty()) {
            throw new OpsException("Cannot find endpoint for port: " + destinationPort);
        }
        DnsRecord record = new DnsRecord();
        record.setDnsName(dnsName);
        for (EndpointInfo endpointInfo : endpoints) {
            record.getAddress().add(endpointInfo.publicIp);
        }
        record.getTags().add(parentTag);
        record.setKey(PlatformLayerKey.fromId(dnsName));
        try {
            platformLayerClient.putItemByTag((ItemBase) record, parentTag);
        } catch (PlatformLayerClientException e) {
            throw new OpsException("Error registering persistent instance", e);
        }
    }
}
Also used : PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) EndpointInfo(org.platformlayer.core.model.EndpointInfo) OpsException(org.platformlayer.ops.OpsException) Tag(org.platformlayer.core.model.Tag) PublicEndpointBase(org.platformlayer.core.model.PublicEndpointBase) DnsRecord(org.platformlayer.dns.model.DnsRecord) Handler(org.platformlayer.ops.Handler)

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