Search in sources :

Example 6 with ServiceType

use of org.platformlayer.ids.ServiceType 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 7 with ServiceType

use of org.platformlayer.ids.ServiceType in project platformlayer by platformlayer.

the class PlatformLayerCommandRunnerBase method pathToKey.

public static PlatformLayerKey pathToKey(PlatformLayerClient client, String path) throws PlatformLayerClientException {
    String serviceType;
    String itemType;
    if (path.contains("/")) {
        String[] components = path.split("/");
        if (components.length != 2) {
            throw new IllegalArgumentException("Cannot parse path: " + path);
        }
        serviceType = components[0];
        itemType = components[1];
    } else {
        itemType = path;
        serviceType = getServiceTypeFromItemType(client, itemType);
    }
    FederationKey host = null;
    ProjectId project = client.getProject();
    return new PlatformLayerKey(host, project, new ServiceType(serviceType), new ItemType(itemType), null);
}
Also used : 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 8 with ServiceType

use of org.platformlayer.ids.ServiceType in project platformlayer by platformlayer.

the class ProviderHelper method findModelsProviding.

private List<ModelClass<?>> findModelsProviding(Class<?> serviceClass) throws OpsException {
    List<ModelClass<?>> models = Lists.newArrayList();
    for (ServiceInfo service : serviceProviderDictionary.getAllServices()) {
        ServiceType serviceType = new ServiceType(service.getServiceType());
        ServiceProvider serviceProvider = serviceProviderDictionary.getServiceProvider(serviceType);
        for (ModelClass<?> model : serviceProvider.getModels().all()) {
            Class<?> controllerClass = serviceProvider.getControllerClass(model.getJavaClass());
            if (serviceClass.isAssignableFrom(controllerClass)) {
                models.add(model);
            }
        }
    }
    return models;
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo) ModelClass(org.platformlayer.xaas.services.ModelClass) ServiceType(org.platformlayer.ids.ServiceType) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider)

Example 9 with ServiceType

use of org.platformlayer.ids.ServiceType in project platformlayer by platformlayer.

the class ImageStoreController method getImageStore.

@Override
public org.platformlayer.ops.images.ImageStore getImageStore() throws OpsException {
    String endpoint = model.getTags().findUnique("endpoint");
    if (endpoint == null) {
        log.warn("ImageStore not yet active: " + model);
        return null;
    }
    URI url;
    try {
        url = new URI(endpoint);
    } catch (URISyntaxException e) {
        throw new OpsException("Cannot parse endpoint: " + endpoint, e);
    }
    if (url.getScheme().equals("ssh")) {
        String myAddress = url.getHost();
        Machine machine = new OpaqueMachine(NetworkPoint.forPublicHostname(myAddress));
        // This is nasty; we're in the context of another service here...
        SshKey sshKey = sshKeys.findOtherServiceKey(new ServiceType("imagestore"));
        OpsTarget target = machine.getTarget("imagestore", sshKey.getKeyPair());
        DirectImageStore directImageStore = OpsContext.get().getInjector().getInstance(DirectImageStore.class);
        directImageStore.connect(target);
        return directImageStore;
    } else {
        throw new OpsException("Unknown protocol for endpoint: " + endpoint);
    }
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsException(org.platformlayer.ops.OpsException) OpsTarget(org.platformlayer.ops.OpsTarget) ServiceType(org.platformlayer.ids.ServiceType) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Machine(org.platformlayer.ops.Machine) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) DirectImageStore(org.platformlayer.ops.images.direct.DirectImageStore)

Example 10 with ServiceType

use of org.platformlayer.ids.ServiceType in project platformlayer by platformlayer.

the class JdbcManagedItemRepository method getManagedItem.

@Override
@JdbcTransaction
public ItemBase getManagedItem(PlatformLayerKey key, boolean fetchTags, SecretProvider secretProvider) throws RepositoryException {
    DbHelper db = new DbHelper(key);
    try {
        ServiceProvider serviceProvider = serviceProviderDirectory.getServiceProvider(key.getServiceType());
        if (serviceProvider == null) {
            throw new IllegalStateException();
        }
        ModelClass<?> modelClass = serviceProvider.getModelClass(key.getItemType());
        ServiceType serviceType = key.getServiceType();
        ItemType itemType = key.getItemType();
        ProjectId project = key.getProject();
        ManagedItemId itemId = key.getItemId();
        return fetchItem(db, serviceType, itemType, project, itemId, modelClass.getJavaClass(), secretProvider, fetchTags);
    } catch (SQLException e) {
        throw new RepositoryException("Error running query", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) ServiceType(org.platformlayer.ids.ServiceType) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider) ItemType(org.platformlayer.ids.ItemType) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) ManagedItemId(org.platformlayer.ids.ManagedItemId) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Aggregations

ServiceType (org.platformlayer.ids.ServiceType)24 ItemType (org.platformlayer.ids.ItemType)10 ProjectId (org.platformlayer.ids.ProjectId)7 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)7 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)6 ServiceInfo (org.platformlayer.core.model.ServiceInfo)6 FederationKey (org.platformlayer.ids.FederationKey)6 ManagedItemId (org.platformlayer.ids.ManagedItemId)5 RepositoryException (org.platformlayer.RepositoryException)4 OpsException (org.platformlayer.ops.OpsException)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 OpsContext (org.platformlayer.ops.OpsContext)3 ServiceAuthorization (org.platformlayer.xaas.model.ServiceAuthorization)3 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 SQLException (java.sql.SQLException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JAXBException (javax.xml.bind.JAXBException)2