use of org.platformlayer.ops.OpsException 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.OpsException 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.OpsException in project platformlayer by platformlayer.
the class ItemServiceImpl method findRoots.
@Override
public List<ItemBase> findRoots(ProjectAuthorization authentication) throws OpsException {
ProjectId project = getProjectId(authentication);
boolean fetchTags = true;
List<ItemBase> items;
try {
items = repository.findRoots(project, fetchTags, SecretProvider.from(authentication));
} catch (RepositoryException e) {
throw new OpsException("Error reading objects from database", e);
}
return items;
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class ItemServiceImpl method listAll.
@Override
public List<ItemBase> listAll(ProjectAuthorization authentication, Filter filter) throws OpsException {
ProjectId project = getProjectId(authentication);
List<ItemBase> items;
try {
items = repository.listAll(project, filter, SecretProvider.from(authentication));
} catch (RepositoryException e) {
throw new OpsException("Error reading objects from database", e);
}
return items;
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class ItemServiceImpl method findAll.
// @Override
// public List<ManagedItem<Object>> listItems(ModelKey modelKey) throws RepositoryException {
// boolean fetchTags = true;
// List<ManagedItem<Object>> items = repository.getByAccountId(modelKey, fetchTags);
// return items;
// // ManagedItemCollection<T> collection = new ManagedItemCollection<T>();
// // collection.items = items;
// // return collection;
// }
@Override
public <T extends ItemBase> List<T> findAll(ProjectAuthorization authentication, Class<T> itemClass) throws OpsException {
ModelClass<T> modelClass = serviceProviderDirectory.getModelClass(itemClass);
if (modelClass == null) {
throw new IllegalArgumentException();
}
// if (modelClass.isSystemObject()) {
// if (!isInRole(authentication, RoleId.ADMIN)) {
// throw new SecurityException();
// }
// }
// Class<T> javaClass = modelClass.getJavaClass();
ProjectId project = getProjectId(authentication);
// ModelKey modelKey = new ModelKey(modelClass.getServiceType(), modelClass.getItemType(), project, null);
// if (isSystemObject(modelKey)) {
// checkLoggedInAsAdmin();
// }
boolean fetchTags = true;
List<T> items;
try {
items = repository.findAll(modelClass, project, fetchTags, getSecretProvider(authentication), Filter.EMPTY);
} catch (RepositoryException e) {
throw new OpsException("Error reading objects from database", e);
}
return items;
//
// List<ManagedItem<Object>> listItems = itemService.listItems(modelKey);
//
// ServiceProvider serviceProvider = serviceProviderDictionary.getServiceProvider(serviceType);
// Class<?> javaClass = serviceProvider.getJavaClass(itemType);
//
// List<AptCacheService> typedItems = Lists.newArrayList();
// for (ManagedItem<Object> item : listItems) {
// ModelKey itemKey = new ModelKey(serviceType, itemType, project, new ManagedItemId(item.getKey()));
// TypedManagedItem<?> typedManagedItem = TypedManagedItem.build(javaClass, itemKey, item);
// typedItems.add((AptCacheService) typedManagedItem.getModel());
// }
//
// return typedItems;
}
Aggregations