Search in sources :

Example 6 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)

Example 7 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 8 with ServiceInfo

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

the class PlatformLayerCliContext method listServices.

public Map<String, ServiceInfo> listServices() throws PlatformLayerClientException {
    Iterable<ServiceInfo> allServices = getAllServiceInfos();
    Map<String, ServiceInfo> services = Maps.newHashMap();
    for (ServiceInfo service : allServices) {
        services.put(service.getServiceType(), service);
    }
    return services;
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo)

Example 9 with ServiceInfo

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

the class PlatformLayerCliContext method getAllServiceInfos.

private Iterable<ServiceInfo> getAllServiceInfos() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    Iterable<ServiceInfo> allServices = client.listServices(true);
    return allServices;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) ServiceInfo(org.platformlayer.core.model.ServiceInfo)

Example 10 with ServiceInfo

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

the class JaxbContextHelper method getJaxbContext.

public synchronized JAXBContext getJaxbContext(Class<?> forClass) {
    if (jaxbContext == null) {
        List<Class<?>> javaClasses = Lists.newArrayList();
        javaClasses.add(Tags.class);
        javaClasses.add(Tag.class);
        javaClasses.add(ItemBase.class);
        javaClasses.add(ManagedItemCollection.class);
        javaClasses.add(JobSchedule.class);
        javaClasses.add(PlatformLayerKey.class);
        javaClasses.add(ConfigureAction.class);
        javaClasses.add(ValidateAction.class);
        javaClasses.add(DeleteAction.class);
        javaClasses.add(BackupAction.class);
        for (ServiceInfo serviceInfo : serviceProviderDictionary.getAllServices()) {
            ServiceType serviceType = new ServiceType(serviceInfo.serviceType);
            ServiceProvider serviceProvider = serviceProviderDictionary.getServiceProvider(serviceType);
            for (ModelClass<?> modelClass : serviceProvider.getModels().all()) {
                javaClasses.add(modelClass.getJavaClass());
            // String modelNamespace = modelClass.getJaxbHelper().getPrimaryNamespace();
            // if (namespace == null) {
            // namespace = modelNamespace;
            // } else if (!namespace.equals(modelNamespace)) {
            // throw new IllegalStateException();
            // }
            }
            for (Class<?> clazz : serviceProvider.getActions()) {
                javaClasses.add(clazz);
            }
        }
        try {
            jaxbContext = JAXBContext.newInstance(javaClasses.toArray(new Class<?>[javaClasses.size()]));
        } catch (JAXBException e) {
            throw new IllegalStateException("Unable to build JAXB context", e);
        }
    }
    return jaxbContext;
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo) ServiceType(org.platformlayer.ids.ServiceType) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider) JAXBException(javax.xml.bind.JAXBException) ModelClass(org.platformlayer.xaas.services.ModelClass)

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