use of org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration in project infinispan by infinispan.
the class SerializationUtils method fromJson.
public static RemoteStoreConfiguration fromJson(String json) throws IOException {
ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder();
holder.newConfigurationBuilder(PLACEHOLDER);
try (ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes(UTF_8))) {
ConfigurationBuilderHolder parsedHolder = parserRegistry.parse(bais, holder, null, APPLICATION_JSON);
Configuration parsedConfig = parsedHolder.getNamedConfigurationBuilders().get(PLACEHOLDER).build();
return (RemoteStoreConfiguration) parsedConfig.persistence().stores().iterator().next();
}
}
use of org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration in project infinispan by infinispan.
the class CacheResourceV2 method addSourceConnection.
private CompletionStage<RestResponse> addSourceConnection(RestRequest request) {
final NettyRestResponse.Builder builder = new NettyRestResponse.Builder();
builder.status(NO_CONTENT);
String cacheName = request.variables().get("cacheName");
ContentSource contents = request.contents();
byte[] config = contents.rawContent();
Cache<?, ?> cache = invocationHelper.getRestCacheManager().getCache(cacheName, request);
if (cache == null) {
return notFoundResponseFuture();
}
if (config == null || config.length == 0) {
return badRequestResponseFuture("A remote-store config must be provided");
}
String storeConfig = new String(config, UTF_8);
Json read = Json.read(storeConfig);
if (!read.isObject() || read.at("remote-store") == null || read.asMap().size() != 1) {
return badRequestResponseFuture("Invalid remote-store JSON description: a single remote-store element must be provided");
}
return CompletableFuture.supplyAsync(() -> {
RollingUpgradeManager upgradeManager = cache.getAdvancedCache().getComponentRegistry().getComponent(RollingUpgradeManager.class);
try {
RemoteStoreConfiguration storeConfiguration = SerializationUtils.fromJson(read.toString());
if (!upgradeManager.isConnected(MIGRATOR_NAME)) {
upgradeManager.connectSource(MIGRATOR_NAME, storeConfiguration);
} else {
builder.status(HttpResponseStatus.NOT_MODIFIED);
}
} catch (Exception e) {
Throwable rootCause = Util.getRootCause(e);
builder.status(HttpResponseStatus.INTERNAL_SERVER_ERROR).entity(rootCause.getMessage());
}
return builder.build();
}, invocationHelper.getExecutor());
}
use of org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration in project infinispan by infinispan.
the class CacheResourceV2 method getSourceConnection.
@SuppressWarnings("rawtypes")
private CompletionStage<RestResponse> getSourceConnection(RestRequest request) {
NettyRestResponse.Builder builder = new NettyRestResponse.Builder();
String cacheName = request.variables().get("cacheName");
Cache<?, ?> cache = invocationHelper.getRestCacheManager().getCache(cacheName, request);
PersistenceManager persistenceManager = SecurityActions.getPersistenceManager(invocationHelper.getRestCacheManager().getInstance(), cache.getName());
List<RemoteStore> remoteStores = new ArrayList<>(persistenceManager.getStores(RemoteStore.class));
if (remoteStores.isEmpty()) {
builder.status(NOT_FOUND);
return completedFuture(builder.build());
}
if (remoteStores.size() != 1) {
builder.status(INTERNAL_SERVER_ERROR);
builder.entity("More than one remote store detected, rolling upgrades aren't supported");
return completedFuture(builder.build());
}
RemoteStoreConfiguration storeConfiguration = remoteStores.get(0).getConfiguration();
builder.entity(SerializationUtils.toJson(storeConfiguration));
return completedFuture(builder.build());
}
use of org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration in project infinispan by infinispan.
the class RollingUpgradeDynamicStoreIT method connectTargetCluster.
protected void connectTargetCluster() throws IOException {
RestCacheClient client = target.getClient().cache(CACHE_NAME);
ConfigurationBuilder builder = new ConfigurationBuilder();
addRemoteStore(builder);
RemoteStoreConfiguration remoteStore = (RemoteStoreConfiguration) builder.build().persistence().stores().iterator().next();
RestEntity restEntity = RestEntity.create(MediaType.APPLICATION_JSON, SerializationUtils.toJson(remoteStore));
RestResponse response = join(client.connectSource(restEntity));
assertEquals(response.getBody(), 204, response.getStatus());
response = join(client.sourceConnection());
RemoteStoreConfiguration remoteStoreConfiguration = SerializationUtils.fromJson(response.getBody());
List<RemoteServerConfiguration> servers = remoteStoreConfiguration.servers();
assertEquals(1, servers.size());
RemoteServerConfiguration initialConfig = remoteStore.servers().iterator().next();
assertEquals(initialConfig.host(), servers.get(0).host());
assertEquals(initialConfig.port(), servers.get(0).port());
}
Aggregations