Search in sources :

Example 1 with ServiceInfo

use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.

the class FederatedPlatformLayerClient method listServices.

@Override
public Collection<ServiceInfo> listServices(boolean allowCache) throws PlatformLayerClientException {
    Collection<ServiceInfo> returnValue = servicesCache;
    if (!allowCache || returnValue == null) {
        Map<String, ServiceInfo> services = Maps.newHashMap();
        // TODO: Do we need to be smarter about how we dedup?
        for (ServiceInfo service : doListConcatenation(getChildClients(), new ListServices(allowCache))) {
            services.put(service.namespace, service);
        }
        returnValue = services.values();
        servicesCache = Lists.newArrayList(returnValue);
    }
    return returnValue;
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo)

Example 2 with ServiceInfo

use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.

the class ServiceProviderBase method getServiceInfo.

@Override
public ServiceInfo getServiceInfo() {
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.serviceType = getServiceType().getKey();
    serviceInfo.description = description;
    for (ModelClass<?> modelClass : getModels().all()) {
        ItemType itemType = modelClass.getItemType();
        if (serviceInfo.getNamespace() == null) {
            serviceInfo.namespace = modelClass.getPrimaryNamespace();
        }
        if (serviceInfo.itemTypes == null) {
            serviceInfo.itemTypes = Lists.newArrayList();
        }
        serviceInfo.itemTypes.add(itemType.getKey());
    }
    return serviceInfo;
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo) ItemType(org.platformlayer.ids.ItemType)

Example 3 with ServiceInfo

use of org.platformlayer.core.model.ServiceInfo 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 4 with ServiceInfo

use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.

the class PlatformLayerCliContext method listItemTypes.

public Multimap<String, ServiceInfo> listItemTypes() throws PlatformLayerClientException {
    Iterable<ServiceInfo> allServices = getAllServiceInfos();
    Multimap<String, ServiceInfo> items = HashMultimap.create();
    for (ServiceInfo service : allServices) {
        for (String itemType : service.getItemTypes()) {
            items.put(itemType, service);
        }
    }
    return items;
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo)

Example 5 with ServiceInfo

use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.

the class PlatformLayerCliContext method pathToItem.

public PlatformLayerKey pathToItem(ProjectId project, String path) throws PlatformLayerClientException {
    String serviceType = null;
    String itemType = null;
    String itemId = null;
    if (path.contains("://")) {
        return PlatformLayerKey.parse(path);
    }
    List<String> components = Lists.newArrayList(path.split("/"));
    if (components.size() <= 1) {
        throw new IllegalArgumentException("Cannot resolve path: " + path);
    }
    String head = components.get(0);
    {
        Map<String, ServiceInfo> services = listServices();
        if (services.containsKey(head)) {
            serviceType = services.get(head).serviceType;
            components.remove(0);
            if (components.size() <= 1) {
                throw new IllegalArgumentException("Cannot resolve path: " + path);
            }
            head = components.get(0);
        }
    }
    Multimap<String, ServiceInfo> items = listItemTypes();
    if (items.containsKey(head)) {
        Collection<ServiceInfo> services = items.get(head);
        if (services.size() > 1) {
            throw new IllegalArgumentException("Cannot resolve path (ambiguous item type): " + path);
        }
        ServiceInfo serviceInfo = Iterables.getOnlyElement(services);
        itemType = head;
        if (serviceType != null) {
            if (!Objects.equal(serviceType, serviceInfo.serviceType)) {
                throw new IllegalArgumentException("Cannot resolve path (service/item type mismatch): " + path);
            }
        } else {
            serviceType = serviceInfo.serviceType;
        }
        components.remove(0);
    } else {
        throw new IllegalArgumentException("Cannot resolve path (unknown item type): " + path);
    }
    itemId = Joiner.on('/').join(components);
    if (serviceType == null) {
        throw new IllegalArgumentException("Cannot resolve path (service type not resolved): " + path);
    }
    if (itemType == null) {
        throw new IllegalArgumentException("Cannot resolve path (item type not resolved): " + path);
    }
    if (Strings.isNullOrEmpty(itemId)) {
        throw new IllegalArgumentException("Cannot resolve path (item id not resolved): " + path);
    }
    FederationKey host = null;
    return new PlatformLayerKey(host, project, new ServiceType(serviceType), new ItemType(itemType), new ManagedItemId(itemId));
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo) ServiceType(org.platformlayer.ids.ServiceType) ItemType(org.platformlayer.ids.ItemType) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Map(java.util.Map) ManagedItemId(org.platformlayer.ids.ManagedItemId) FederationKey(org.platformlayer.ids.FederationKey)

Aggregations

ServiceInfo (org.platformlayer.core.model.ServiceInfo)13 ServiceType (org.platformlayer.ids.ServiceType)6 ItemType (org.platformlayer.ids.ItemType)3 ModelClass (org.platformlayer.xaas.services.ModelClass)3 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)3 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 FederationKey (org.platformlayer.ids.FederationKey)2 Map (java.util.Map)1 JAXBException (javax.xml.bind.JAXBException)1 PlatformLayerClient (org.platformlayer.PlatformLayerClient)1 ServiceInfoCollection (org.platformlayer.core.model.ServiceInfoCollection)1 ManagedItemId (org.platformlayer.ids.ManagedItemId)1 ProjectId (org.platformlayer.ids.ProjectId)1