use of org.platformlayer.common.UntypedItem in project platformlayer by platformlayer.
the class FederatedPlatformLayerClient method putItemByTag.
@Override
public UntypedItem putItemByTag(PlatformLayerKey key, Tag uniqueTag, String data, Format format) throws PlatformLayerClientException {
MappedPlatformLayerKey mapped = mapToChildForPut(key);
UntypedItemXml post = UntypedItemXml.build(data);
post.setPlatformLayerKey(mapped.key);
UntypedItem item = mapped.child.client.putItemByTag(mapped.key, uniqueTag, post.serialize(), format);
return mapped.child.setHost(item);
}
use of org.platformlayer.common.UntypedItem in project platformlayer by platformlayer.
the class SshAddressFinder method visit.
public void visit(UntypedItem item) throws PlatformLayerClientException {
UntypedItemXml untypedItem = (UntypedItemXml) item;
ElementInfo rootElementInfo = untypedItem.getRootElementInfo();
boolean consider = true;
switch(untypedItem.getState()) {
case DELETED:
case DELETE_REQUESTED:
consider = false;
break;
}
Set<String> instanceTypes = Sets.newHashSet();
instanceTypes.add("directInstance");
instanceTypes.add("googleCloudInstance");
if (!instanceTypes.contains(rootElementInfo.elementName)) {
consider = false;
}
if (consider) {
Tags itemTags = untypedItem.getTags();
for (InetAddress address : Tag.NETWORK_ADDRESS.find(itemTags)) {
found.add(address);
}
}
boolean includeDeleted = false;
for (UntypedItem child : client.listChildren(untypedItem.getKey(), includeDeleted).getItems()) {
visit(child);
}
}
use of org.platformlayer.common.UntypedItem in project platformlayer by platformlayer.
the class PlatformLayerClientBase method putItemByTag.
@Override
public <T extends ItemBase> T putItemByTag(T item, Tag uniqueTag) throws OpsException {
JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(item);
String xml = PlatformLayerClientBase.serialize(jaxbHelper, item);
PlatformLayerKey key = PlatformLayerClientBase.toKey(jaxbHelper, item, listServices(true));
UntypedItem ret = putItemByTag(key, uniqueTag, xml, Format.XML);
Class<T> itemClass = (Class<T>) item.getClass();
return promoteToTyped(ret, itemClass);
}
use of org.platformlayer.common.UntypedItem in project platformlayer by platformlayer.
the class PlatformLayerClientBase method listItems.
@Override
public <T> List<T> listItems(Class<T> clazz) throws OpsException {
JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(clazz, ManagedItemCollection.class);
PlatformLayerKey path = PlatformLayerClientBase.toKey(jaxbHelper, null, listServices(true));
UntypedItemCollection untypedItems = listItemsUntyped(path);
List<T> items = Lists.newArrayList();
for (UntypedItem untypedItem : untypedItems.getItems()) {
T item = promoteToTyped(untypedItem, clazz);
items.add(item);
}
return items;
}
use of org.platformlayer.common.UntypedItem in project platformlayer by platformlayer.
the class OpenItem method runCommand.
@Override
public Object runCommand() throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
PlatformLayerKey key = path.resolve(getContext());
UntypedItem untypedItem = client.getItemUntyped(key, getFormat());
List<EndpointInfo> endpointList = EndpointInfo.getEndpoints(untypedItem.getTags());
Set<EndpointInfo> endpoints = Sets.newHashSet(endpointList);
EndpointInfo bestEndpoint = null;
for (EndpointInfo candidate : endpoints) {
if (bestEndpoint == null) {
bestEndpoint = candidate;
} else {
throw new IllegalArgumentException("Cannot choose between: " + bestEndpoint + " and " + candidate);
}
}
ClientAction action = null;
if (bestEndpoint != null) {
// TODO: How do we want to do this? A new tag??
String id = key.getServiceType().getKey() + ":" + key.getItemType().getKey();
if (id.equals("jenkins:jenkinsService")) {
action = new ClientAction(ClientAction.ClientActionType.BROWSER, "http://" + bestEndpoint.publicIp + ":" + bestEndpoint.publicIp);
}
}
return action;
}
Aggregations