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();
}
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());
}
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());
}
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();
});
}
Aggregations