use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class SshItem method runCommand.
@Override
public Object runCommand() throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
PlatformLayerKey key = path.resolve(getContext());
UntypedItem untypedItem = client.getItemUntyped(key, Format.XML);
InetAddress sshAddress = findSshAddress(client, untypedItem);
ClientAction action = null;
if (sshAddress != null) {
String user = "root";
ProjectId project = key.getProject();
if (project == null) {
project = client.getProject();
}
if (project == null) {
throw new CliException("Cannot determine project");
}
String projectKey = project.getKey();
String serviceKey = "service-" + key.getServiceType().getKey();
File sshKey = IoUtils.resolve("~/.credentials/ssh/" + projectKey + "/" + serviceKey);
// Hmmm... user? key?
action = new ClientAction(ClientAction.ClientActionType.SSH, user + "@" + sshAddress.getHostAddress(), sshKey.getAbsolutePath());
}
return action;
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class PlatformLayerClientBase method toKey.
public static <T> PlatformLayerKey toKey(JaxbHelper jaxbHelper, ManagedItemId id, Class<T> itemClass, Collection<ServiceInfo> services) throws PlatformLayerClientException {
String namespaceURI = jaxbHelper.getPrimaryNamespace();
String nodeName = jaxbHelper.getXmlElementName();
if (namespaceURI == null) {
throw new IllegalArgumentException("Namespace could not be determined");
}
ServiceInfo service = getServiceInfo(services, namespaceURI);
if (service == null) {
throw new PlatformLayerClientException("Cannot find service for " + namespaceURI);
}
ServiceType serviceType = new ServiceType(service.getServiceType());
ItemType itemType = new ItemType(nodeName);
FederationKey host = null;
ProjectId project = null;
return new PlatformLayerKey(host, project, serviceType, itemType, id);
}
use of org.platformlayer.core.model.PlatformLayerKey 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.core.model.PlatformLayerKey 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.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class TypedPlatformLayerClient method toKey.
public <T> PlatformLayerKey toKey(Class<T> itemClass, String id) throws PlatformLayerClientException {
JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(itemClass, new Class[0]);
ManagedItemId itemId = new ManagedItemId(id);
PlatformLayerKey key = PlatformLayerClientBase.toKey(jaxbHelper, itemId, itemClass, platformLayerClient.listServices(true));
return key;
}
Aggregations