Search in sources :

Example 1 with EmbeddedCacheManagerAdmin

use of org.infinispan.manager.EmbeddedCacheManagerAdmin in project infinispan by infinispan.

the class CacheResourceV2 method setCacheConfigMutableAttribute.

private CompletionStage<RestResponse> setCacheConfigMutableAttribute(RestRequest request) {
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    String attributeName = request.getParameter("attribute-name");
    String attributeValue = request.getParameter("attribute-value");
    String cacheName = request.variables().get("cacheName");
    Cache<?, ?> cache = invocationHelper.getRestCacheManager().getCache(cacheName, request);
    if (cache == null) {
        return notFoundResponseFuture();
    }
    Configuration configuration = new ConfigurationBuilder().read(SecurityActions.getCacheConfiguration(cache.getAdvancedCache())).build();
    Attribute<?> attribute = configuration.findAttribute(attributeName);
    invocationHelper.getRestCacheManager().getCacheManagerAdmin(request);
    EmbeddedCacheManagerAdmin administration = invocationHelper.getRestCacheManager().getCacheManagerAdmin(request).withFlags(AdminFlag.UPDATE);
    return CompletableFuture.supplyAsync(() -> {
        try {
            attribute.fromString(attributeValue);
            administration.getOrCreateCache(cacheName, configuration);
            responseBuilder.status(OK);
        } catch (Throwable t) {
            responseBuilder.status(BAD_REQUEST).entity(Util.getRootCause(t).getMessage());
        }
        return responseBuilder.build();
    }, invocationHelper.getExecutor());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) NettyRestResponse(org.infinispan.rest.NettyRestResponse) EmbeddedCacheManagerAdmin(org.infinispan.manager.EmbeddedCacheManagerAdmin)

Example 2 with EmbeddedCacheManagerAdmin

use of org.infinispan.manager.EmbeddedCacheManagerAdmin in project infinispan by infinispan.

the class XSiteResourceTest method defineCaches.

private void defineCaches(int siteIndex, Configuration configuration) {
    EmbeddedCacheManagerAdmin admin = manager(siteIndex, 0).administration().withFlags(VOLATILE);
    admin.getOrCreateCache(CACHE_1, configuration);
    admin.getOrCreateCache(CACHE_2, configuration);
}
Also used : EmbeddedCacheManagerAdmin(org.infinispan.manager.EmbeddedCacheManagerAdmin)

Example 3 with EmbeddedCacheManagerAdmin

use of org.infinispan.manager.EmbeddedCacheManagerAdmin in project vertx-infinispan by vert-x3.

the class InfinispanClusterManager method getAsyncMap.

@Override
public <K, V> void getAsyncMap(String name, Promise<AsyncMap<K, V>> promise) {
    vertx.executeBlocking(prom -> {
        EmbeddedCacheManagerAdmin administration = cacheManager.administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE);
        Cache<byte[], byte[]> cache = administration.getOrCreateCache(name, "__vertx.distributed.cache.configuration");
        prom.complete(new InfinispanAsyncMapImpl<>(vertx, cache));
    }, false, promise);
}
Also used : EmbeddedCacheManagerAdmin(org.infinispan.manager.EmbeddedCacheManagerAdmin)

Example 4 with EmbeddedCacheManagerAdmin

use of org.infinispan.manager.EmbeddedCacheManagerAdmin in project infinispan by infinispan.

the class CacheResourceV2 method createOrUpdate.

private CompletableFuture<RestResponse> createOrUpdate(RestRequest request) {
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    List<String> template = request.parameters().get("template");
    String cacheName = request.variables().get("cacheName");
    EnumSet<AdminFlag> adminFlags = request.getAdminFlags();
    if (request.method() == PUT) {
        if (adminFlags == null) {
            adminFlags = EnumSet.of(AdminFlag.UPDATE);
        } else {
            adminFlags.add(AdminFlag.UPDATE);
        }
    }
    EmbeddedCacheManagerAdmin initialAdmin = invocationHelper.getRestCacheManager().getCacheManagerAdmin(request);
    EmbeddedCacheManagerAdmin administration = adminFlags == null ? initialAdmin : initialAdmin.withFlags(adminFlags);
    if (template != null && !template.isEmpty()) {
        if (request.method() == PUT) {
            return CompletableFuture.completedFuture(responseBuilder.status(BAD_REQUEST).build());
        }
        String templateName = template.iterator().next();
        return CompletableFuture.supplyAsync(() -> {
            administration.createCache(cacheName, templateName);
            responseBuilder.status(OK);
            return responseBuilder.build();
        }, invocationHelper.getExecutor());
    }
    ContentSource contents = request.contents();
    byte[] bytes = contents.rawContent();
    if (bytes == null || bytes.length == 0) {
        if (request.method() == PUT) {
            return CompletableFuture.completedFuture(responseBuilder.status(BAD_REQUEST).build());
        }
        return CompletableFuture.supplyAsync(() -> {
            administration.createCache(cacheName, (String) null);
            responseBuilder.status(OK);
            return responseBuilder.build();
        }, invocationHelper.getExecutor());
    }
    MediaType sourceType = request.contentType() == null ? APPLICATION_JSON : request.contentType();
    if (!sourceType.match(APPLICATION_JSON) && !sourceType.match(APPLICATION_XML) && !sourceType.match(APPLICATION_YAML)) {
        responseBuilder.status(HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE);
        return CompletableFuture.completedFuture(responseBuilder.build());
    }
    return CompletableFuture.supplyAsync(() -> {
        try {
            ConfigurationBuilderHolder holder = invocationHelper.getParserRegistry().parse(new String(bytes, UTF_8), sourceType);
            ConfigurationBuilder cfgBuilder = holder.getCurrentConfigurationBuilder() != null ? holder.getCurrentConfigurationBuilder() : new ConfigurationBuilder();
            if (request.method() == PUT) {
                administration.getOrCreateCache(cacheName, cfgBuilder.build());
            } else {
                administration.createCache(cacheName, cfgBuilder.build());
            }
            responseBuilder.status(OK);
        } catch (Throwable t) {
            responseBuilder.status(BAD_REQUEST).entity(t.getMessage());
        }
        return responseBuilder.build();
    }, invocationHelper.getExecutor());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) AdminFlag(org.infinispan.commons.api.CacheContainerAdmin.AdminFlag) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) NettyRestResponse(org.infinispan.rest.NettyRestResponse) ContentSource(org.infinispan.rest.framework.ContentSource) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) MediaType(org.infinispan.commons.dataconversion.MediaType) MediaTypeUtils.negotiateMediaType(org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType) EmbeddedCacheManagerAdmin(org.infinispan.manager.EmbeddedCacheManagerAdmin)

Aggregations

EmbeddedCacheManagerAdmin (org.infinispan.manager.EmbeddedCacheManagerAdmin)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 NettyRestResponse (org.infinispan.rest.NettyRestResponse)2 AdminFlag (org.infinispan.commons.api.CacheContainerAdmin.AdminFlag)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 Configuration (org.infinispan.configuration.cache.Configuration)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)1 RemoteStoreConfiguration (org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration)1 ContentSource (org.infinispan.rest.framework.ContentSource)1 MediaTypeUtils.negotiateMediaType (org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType)1