Search in sources :

Example 11 with ConfigurationWriter

use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.

the class ContainerResourceTest method testGetGlobalConfig.

@Test
public void testGetGlobalConfig() {
    RestResponse response = join(adminCacheManagerClient.globalConfiguration());
    ResponseAssertion.assertThat(response).isOk();
    String json = response.getBody();
    EmbeddedCacheManager embeddedCacheManager = cacheManagers.get(0);
    GlobalConfiguration globalConfiguration = embeddedCacheManager.withSubject(ADMIN).getCacheManagerConfiguration();
    StringBuilderWriter sw = new StringBuilderWriter();
    try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
        new ParserRegistry().serialize(w, globalConfiguration, Collections.emptyMap());
    }
    assertEquals(sw.toString(), json);
}
Also used : StringBuilderWriter(org.infinispan.commons.io.StringBuilderWriter) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) RestResponse(org.infinispan.client.rest.RestResponse) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Test(org.testng.annotations.Test)

Example 12 with ConfigurationWriter

use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.

the class CacheResourceV2 method getDetailResponse.

private RestResponse getDetailResponse(Cache<?, ?> cache) {
    Configuration configuration = SecurityActions.getCacheConfiguration(cache.getAdvancedCache());
    EmbeddedCacheManager cacheManager = invocationHelper.getRestCacheManager().getInstance();
    GlobalConfiguration globalConfiguration = SecurityActions.getCacheManagerConfiguration(cacheManager);
    PersistenceManager persistenceManager = SecurityActions.getPersistenceManager(cacheManager, cache.getName());
    Stats stats = null;
    Boolean rehashInProgress = null;
    Boolean indexingInProgress = null;
    Boolean queryable = null;
    try {
        // TODO Shouldn't we return the clustered stats, like Hot Rod does?
        stats = cache.getAdvancedCache().getStats();
        DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager();
        rehashInProgress = distributionManager != null && distributionManager.isRehashInProgress();
    } catch (SecurityException ex) {
    // Admin is needed
    }
    Boolean rebalancingEnabled = null;
    try {
        LocalTopologyManager localTopologyManager = SecurityActions.getComponentRegistry(cache.getAdvancedCache()).getComponent(LocalTopologyManager.class);
        if (localTopologyManager != null) {
            rebalancingEnabled = localTopologyManager.isCacheRebalancingEnabled(cache.getName());
        }
    } catch (Exception ex) {
    // Getting rebalancing status might raise an exception
    }
    Integer size = null;
    if (globalConfiguration.metrics().accurateSize()) {
        try {
            size = cache.size();
        } catch (SecurityException ex) {
        // Bulk Read is needed
        }
    }
    SearchStatistics searchStatistics = Search.getSearchStatistics(cache);
    IndexStatistics indexStatistics = searchStatistics.getIndexStatistics();
    indexingInProgress = indexStatistics.reindexing();
    queryable = invocationHelper.getRestCacheManager().isCacheQueryable(cache);
    boolean statistics = configuration.statistics().enabled();
    boolean indexed = configuration.indexing().enabled();
    CacheFullDetail fullDetail = new CacheFullDetail();
    fullDetail.stats = stats;
    StringBuilderWriter sw = new StringBuilderWriter();
    try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
        invocationHelper.getParserRegistry().serialize(w, cache.getName(), configuration);
    }
    fullDetail.configuration = sw.toString();
    fullDetail.size = size;
    fullDetail.rehashInProgress = rehashInProgress;
    fullDetail.indexingInProgress = indexingInProgress;
    fullDetail.persistent = persistenceManager.isEnabled();
    fullDetail.bounded = configuration.memory().whenFull().isEnabled();
    fullDetail.indexed = indexed;
    fullDetail.hasRemoteBackup = configuration.sites().hasBackups();
    fullDetail.secured = configuration.security().authorization().enabled();
    fullDetail.transactional = configuration.transaction().transactionMode().isTransactional();
    fullDetail.statistics = statistics;
    fullDetail.queryable = queryable;
    fullDetail.rebalancingEnabled = rebalancingEnabled;
    fullDetail.keyStorage = cache.getAdvancedCache().getKeyDataConversion().getStorageMediaType();
    fullDetail.valueStorage = cache.getAdvancedCache().getValueDataConversion().getStorageMediaType();
    return addEntityAsJson(fullDetail.toJson(), new NettyRestResponse.Builder()).build();
}
Also used : StringBuilderWriter(org.infinispan.commons.io.StringBuilderWriter) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) SearchStatistics(org.infinispan.query.core.stats.SearchStatistics) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RestResponseException(org.infinispan.rest.RestResponseException) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) Stats(org.infinispan.stats.Stats) DistributionManager(org.infinispan.distribution.DistributionManager) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager)

Example 13 with ConfigurationWriter

use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.

the class ServerResource method config.

private CompletionStage<RestResponse> config(RestRequest request) {
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    MediaType accept = negotiateMediaType(request, APPLICATION_JSON, APPLICATION_XML, APPLICATION_YAML);
    responseBuilder.contentType(accept);
    StringBuilderWriter sw = new StringBuilderWriter();
    try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(accept).prettyPrint(false).build()) {
        invocationHelper.getServer().serializeConfiguration(w);
    }
    responseBuilder.entity(sw.toString());
    return CompletableFuture.completedFuture(responseBuilder.build());
}
Also used : StringBuilderWriter(org.infinispan.commons.io.StringBuilderWriter) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) MediaType(org.infinispan.commons.dataconversion.MediaType) MediaTypeUtils.negotiateMediaType(org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Example 14 with ConfigurationWriter

use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.

the class ContainerResource method getNamedCacheConfiguration.

private NamedCacheConfiguration getNamedCacheConfiguration(EmbeddedCacheManager subjectCacheManager, String n) {
    Configuration config = SecurityActions.getCacheConfigurationFromManager(subjectCacheManager, n);
    StringBuilderWriter sw = new StringBuilderWriter();
    try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
        invocationHelper.getParserRegistry().serialize(w, n, config);
    }
    return new NamedCacheConfiguration(n, sw.toString());
}
Also used : StringBuilderWriter(org.infinispan.commons.io.StringBuilderWriter) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) Configuration(org.infinispan.configuration.cache.Configuration)

Example 15 with ConfigurationWriter

use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.

the class CounterResource method getConfig.

private CompletionStage<RestResponse> getConfig(RestRequest request) {
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    String counterName = request.variables().get("counterName");
    return invocationHelper.getCounterManager().getConfigurationAsync(counterName).thenApply(cfg -> {
        if (cfg == null)
            return responseBuilder.status(NOT_FOUND).build();
        AbstractCounterConfiguration parsedConfig = ConvertUtil.configToParsedConfig(counterName, cfg);
        CounterConfigurationSerializer ccs = new CounterConfigurationSerializer();
        StringBuilderWriter sw = new StringBuilderWriter();
        try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
            ccs.serializeConfiguration(w, parsedConfig);
        }
        return responseBuilder.entity(sw.toString()).contentType(APPLICATION_JSON).build();
    });
}
Also used : CounterConfigurationSerializer(org.infinispan.counter.configuration.CounterConfigurationSerializer) StringBuilderWriter(org.infinispan.commons.io.StringBuilderWriter) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Aggregations

ConfigurationWriter (org.infinispan.commons.configuration.io.ConfigurationWriter)16 StringBuilderWriter (org.infinispan.commons.io.StringBuilderWriter)9 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)9 Configuration (org.infinispan.configuration.cache.Configuration)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)8 NettyRestResponse (org.infinispan.rest.NettyRestResponse)6 Map (java.util.Map)5 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HashMap (java.util.HashMap)4 ParserRegistry (org.infinispan.configuration.parsing.ParserRegistry)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 IOException (java.io.IOException)3 MediaType (org.infinispan.commons.dataconversion.MediaType)3 RemoteStoreConfiguration (org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration)3 MediaTypeUtils.negotiateMediaType (org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 URL (java.net.URL)2