Search in sources :

Example 6 with StringBuilderWriter

use of org.infinispan.commons.io.StringBuilderWriter 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 7 with StringBuilderWriter

use of org.infinispan.commons.io.StringBuilderWriter 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 8 with StringBuilderWriter

use of org.infinispan.commons.io.StringBuilderWriter 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 9 with StringBuilderWriter

use of org.infinispan.commons.io.StringBuilderWriter 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)9 StringBuilderWriter (org.infinispan.commons.io.StringBuilderWriter)9 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)5 Configuration (org.infinispan.configuration.cache.Configuration)4 NettyRestResponse (org.infinispan.rest.NettyRestResponse)4 Map (java.util.Map)3 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)3 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)3 ParserRegistry (org.infinispan.configuration.parsing.ParserRegistry)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 PrivilegedActionException (java.security.PrivilegedActionException)1