Search in sources :

Example 16 with PlatformLayerKey

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;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) ClientAction(com.fathomdb.cli.output.ClientAction) UntypedItem(org.platformlayer.common.UntypedItem) CliException(com.fathomdb.cli.CliException) ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) InetAddress(java.net.InetAddress) File(java.io.File)

Example 17 with PlatformLayerKey

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);
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo) ServiceType(org.platformlayer.ids.ServiceType) ItemType(org.platformlayer.ids.ItemType) ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) FederationKey(org.platformlayer.ids.FederationKey)

Example 18 with PlatformLayerKey

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;
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) JaxbHelper(org.platformlayer.xml.JaxbHelper) UntypedItemCollection(org.platformlayer.common.UntypedItemCollection) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 19 with PlatformLayerKey

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);
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) JaxbHelper(org.platformlayer.xml.JaxbHelper) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 20 with PlatformLayerKey

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;
}
Also used : JaxbHelper(org.platformlayer.xml.JaxbHelper) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Aggregations

PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)86 PlatformLayerClient (org.platformlayer.PlatformLayerClient)21 OpsException (org.platformlayer.ops.OpsException)16 ItemBase (org.platformlayer.core.model.ItemBase)14 ManagedItemId (org.platformlayer.ids.ManagedItemId)13 UntypedItem (org.platformlayer.common.UntypedItem)10 ProjectId (org.platformlayer.ids.ProjectId)10 Tag (org.platformlayer.core.model.Tag)8 RepositoryException (org.platformlayer.RepositoryException)7 ServiceType (org.platformlayer.ids.ServiceType)7 JobData (org.platformlayer.jobs.model.JobData)7 InstanceBase (org.platformlayer.core.model.InstanceBase)6 ItemType (org.platformlayer.ids.ItemType)6 OpsTarget (org.platformlayer.ops.OpsTarget)6 JaxbHelper (org.platformlayer.xml.JaxbHelper)6 Handler (org.platformlayer.ops.Handler)5 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)4 UntypedItemXml (org.platformlayer.UntypedItemXml)4 FederationKey (org.platformlayer.ids.FederationKey)4 Machine (org.platformlayer.ops.Machine)4