Search in sources :

Example 36 with OpsException

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();
            }
        }
    });
}
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 37 with OpsException

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);
}
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 38 with OpsException

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException)

Example 39 with OpsException

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException)

Example 40 with OpsException

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException)

Aggregations

OpsException (org.platformlayer.ops.OpsException)142 IOException (java.io.IOException)39 File (java.io.File)19 ItemBase (org.platformlayer.core.model.ItemBase)19 RepositoryException (org.platformlayer.RepositoryException)18 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)17 Handler (org.platformlayer.ops.Handler)17 Tag (org.platformlayer.core.model.Tag)16 Command (org.platformlayer.ops.Command)16 Machine (org.platformlayer.ops.Machine)13 TagChanges (org.platformlayer.core.model.TagChanges)11 OpsTarget (org.platformlayer.ops.OpsTarget)11 TimeoutException (java.util.concurrent.TimeoutException)10 OpenstackException (org.openstack.client.OpenstackException)10 OpsContext (org.platformlayer.ops.OpsContext)10 X509Certificate (java.security.cert.X509Certificate)9 InetAddress (java.net.InetAddress)8 ProjectId (org.platformlayer.ids.ProjectId)8 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)8 List (java.util.List)7