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;
}
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;
}
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;
}
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;
}
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));
}
Aggregations