Search in sources :

Example 16 with ServiceProvider

use of org.platformlayer.xaas.services.ServiceProvider in project platformlayer by platformlayer.

the class ServiceProviderHelpers method getModelSubclasses.

public <T extends ItemBase> List<ModelClass<? extends T>> getModelSubclasses(Class<T> parent) {
    List<ModelClass<? extends T>> modelClasses = Lists.newArrayList();
    for (ServiceInfo serviceInfo : serviceProviderDictionary.getAllServices()) {
        ServiceType serviceType = new ServiceType(serviceInfo.serviceType);
        ServiceProvider serviceProvider = serviceProviderDictionary.getServiceProvider(serviceType);
        for (ModelClass<?> modelClass : serviceProvider.getModels().all()) {
            Class<?> javaClass = modelClass.getJavaClass();
            if (parent.isAssignableFrom(javaClass)) {
                modelClasses.add((ModelClass<? extends T>) modelClass);
            }
        }
    }
    return modelClasses;
}
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 17 with ServiceProvider

use of org.platformlayer.xaas.services.ServiceProvider in project platformlayer by platformlayer.

the class MetricsResource method getMetrics.

@POST
@Produces({ XML, JSON })
public MetricDataSource getMetrics(final MetricQuery query) throws RepositoryException, OpsException {
    final ItemBase managedItem = getManagedItem();
    final ServiceProvider serviceProvider = getServiceProvider();
    OpsContextBuilder opsContextBuilder = objectInjector.getInstance(OpsContextBuilder.class);
    final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(getServiceType(), getProjectAuthorization());
    return OpsContext.runInContext(opsContext, new CheckedCallable<MetricDataSource, Exception>() {

        @Override
        public MetricDataSource call() throws Exception {
            BindingScope bindingScope = BindingScope.push(managedItem, managedItem);
            try {
                MetricDataSource metrics = serviceProvider.getMetricValues(managedItem, query);
                return metrics;
            } finally {
                bindingScope.pop();
            }
        }
    });
}
Also used : MetricDataSource(org.platformlayer.metrics.model.MetricDataSource) ItemBase(org.platformlayer.core.model.ItemBase) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider) OpsContext(org.platformlayer.ops.OpsContext) RepositoryException(org.platformlayer.RepositoryException) OpsException(org.platformlayer.ops.OpsException) OpsContextBuilder(org.platformlayer.ops.tasks.OpsContextBuilder) BindingScope(org.platformlayer.ops.BindingScope) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 18 with ServiceProvider

use of org.platformlayer.xaas.services.ServiceProvider in project platformlayer by platformlayer.

the class ServiceResource method getExtensionsResource.

@Path("extensions")
public Object getExtensionsResource() throws Exception {
    final ServiceProvider serviceProvider = getServiceProvider();
    OpsContextBuilder opsContextBuilder = objectInjector.getInstance(OpsContextBuilder.class);
    final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(getServiceType(), getProjectAuthorization());
    Object extensionResource = OpsContext.runInContext(opsContext, new CheckedCallable<Object, Exception>() {

        @Override
        public Object call() throws Exception {
            return serviceProvider.getExtensionResource();
        }
    });
    if (extensionResource == null) {
        raiseNotFound();
    }
    return extensionResource;
}
Also used : ServiceProvider(org.platformlayer.xaas.services.ServiceProvider) OpsContext(org.platformlayer.ops.OpsContext) RepositoryException(org.platformlayer.RepositoryException) OpsException(org.platformlayer.ops.OpsException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) WebApplicationException(javax.ws.rs.WebApplicationException) OpsContextBuilder(org.platformlayer.ops.tasks.OpsContextBuilder) Path(javax.ws.rs.Path)

Example 19 with ServiceProvider

use of org.platformlayer.xaas.services.ServiceProvider in project platformlayer by platformlayer.

the class XaasResourceBase method getModelClass.

protected ModelClass<?> getModelClass() {
    ServiceProvider serviceProvider = getServiceProvider();
    if (serviceProvider == null) {
        log.warn("Unknown service");
        raiseNotFound();
    }
    ModelClass<?> modelClass = serviceProvider.getModels().find(getItemType());
    if (modelClass == null) {
        log.warn("Unknown itemtype: " + getItemType());
        raiseNotFound();
    }
    return modelClass;
}
Also used : ServiceProvider(org.platformlayer.xaas.services.ServiceProvider)

Aggregations

ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)19 RepositoryException (org.platformlayer.RepositoryException)9 OpsContext (org.platformlayer.ops.OpsContext)9 OpsException (org.platformlayer.ops.OpsException)8 ServiceType (org.platformlayer.ids.ServiceType)7 ItemBase (org.platformlayer.core.model.ItemBase)6 Produces (javax.ws.rs.Produces)5 JAXBException (javax.xml.bind.JAXBException)5 OpsContextBuilder (org.platformlayer.ops.tasks.OpsContextBuilder)5 ModelClass (org.platformlayer.xaas.services.ModelClass)5 Path (javax.ws.rs.Path)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 IOException (java.io.IOException)3 GET (javax.ws.rs.GET)3 ServiceInfo (org.platformlayer.core.model.ServiceInfo)3 BindingScope (org.platformlayer.ops.BindingScope)3 List (java.util.List)2 POST (javax.ws.rs.POST)2 SecretProvider (org.platformlayer.auth.crypto.SecretProvider)2 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2