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