Search in sources :

Example 1 with OpsContextBuilder

use of org.platformlayer.ops.tasks.OpsContextBuilder in project platformlayer by platformlayer.

the class ManagedItemResource method getExtensionsResource.

@Path("extensions")
public Object getExtensionsResource() throws Exception {
    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 {
            boolean fetchTags = true;
            ItemBase managedItem = getManagedItem(fetchTags);
            ServiceProvider serviceProvider = getServiceProvider();
            Object resource = serviceProvider.getItemExtensionResource(managedItem);
            return resource;
        }
    });
    if (extensionResource == null) {
        raiseNotFound();
    }
    return extensionResource;
}
Also used : 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) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) OpsContextBuilder(org.platformlayer.ops.tasks.OpsContextBuilder) Path(javax.ws.rs.Path)

Example 2 with OpsContextBuilder

use of org.platformlayer.ops.tasks.OpsContextBuilder in project platformlayer by platformlayer.

the class MetricsResource method listMetrics.

@GET
@Produces({ XML, JSON })
public MetricInfoCollection listMetrics() throws OpsException, RepositoryException {
    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<MetricInfoCollection, Exception>() {

        @Override
        public MetricInfoCollection call() throws Exception {
            BindingScope bindingScope = BindingScope.push(managedItem, managedItem);
            try {
                Object controller = serviceProvider.getController(managedItem);
                MetricConfig metricConfig = opsContext.getMetricInfo(controller);
                return MetricCollector.toMetricInfo(metricConfig);
            } finally {
                bindingScope.pop();
            }
        }
    });
}
Also used : MetricConfig(org.platformlayer.ops.model.metrics.MetricConfig) ItemBase(org.platformlayer.core.model.ItemBase) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider) MetricInfoCollection(org.platformlayer.metrics.model.MetricInfoCollection) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with OpsContextBuilder

use of org.platformlayer.ops.tasks.OpsContextBuilder in project platformlayer by platformlayer.

the class ServiceResource method getSshPublicKey.

@GET
@Path("sshkey")
@Produces({ TEXT_PLAIN })
public String getSshPublicKey() throws RepositoryException, OpsException, IOException {
    final ServiceProvider serviceProvider = getServiceProvider();
    if (serviceProvider == null) {
        raiseNotFound();
    }
    OpsContextBuilder opsContextBuilder = opsContextBuilderFactory.get();
    final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(serviceProvider.getServiceType(), getProjectAuthorization());
    PublicKey publicKey = OpsContext.runInContext(opsContext, new CheckedCallable<PublicKey, Exception>() {

        @Override
        public PublicKey call() throws Exception {
            PublicKey publicKey = serviceProvider.getSshPublicKey();
            return publicKey;
        }
    });
    if (publicKey == null) {
        throw new WebApplicationException(404);
    }
    String description = "platformlayer://" + getProject().getKey() + "/" + serviceProvider.getServiceType().getKey();
    return OpenSshUtils.serialize(publicKey, description);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) PublicKey(java.security.PublicKey) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with OpsContextBuilder

use of org.platformlayer.ops.tasks.OpsContextBuilder 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 5 with OpsContextBuilder

use of org.platformlayer.ops.tasks.OpsContextBuilder 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)

Aggregations

RepositoryException (org.platformlayer.RepositoryException)5 OpsContext (org.platformlayer.ops.OpsContext)5 OpsException (org.platformlayer.ops.OpsException)5 OpsContextBuilder (org.platformlayer.ops.tasks.OpsContextBuilder)5 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)5 IOException (java.io.IOException)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 JAXBException (javax.xml.bind.JAXBException)3 ItemBase (org.platformlayer.core.model.ItemBase)3 GET (javax.ws.rs.GET)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 BindingScope (org.platformlayer.ops.BindingScope)2 PublicKey (java.security.PublicKey)1 POST (javax.ws.rs.POST)1 MetricDataSource (org.platformlayer.metrics.model.MetricDataSource)1 MetricInfoCollection (org.platformlayer.metrics.model.MetricInfoCollection)1 MetricConfig (org.platformlayer.ops.model.metrics.MetricConfig)1