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