Search in sources :

Example 1 with RemoteStoreConfiguration

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();
    }
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) Configuration(org.infinispan.configuration.cache.Configuration) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration)

Example 2 with RemoteStoreConfiguration

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());
}
Also used : RollingUpgradeManager(org.infinispan.upgrade.RollingUpgradeManager) ContentSource(org.infinispan.rest.framework.ContentSource) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ResourceUtil.addEntityAsJson(org.infinispan.rest.resources.ResourceUtil.addEntityAsJson) Json(org.infinispan.commons.dataconversion.internal.Json) NettyRestResponse(org.infinispan.rest.NettyRestResponse) RestResponseException(org.infinispan.rest.RestResponseException)

Example 3 with RemoteStoreConfiguration

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());
}
Also used : PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ArrayList(java.util.ArrayList) NettyRestResponse(org.infinispan.rest.NettyRestResponse) RemoteStore(org.infinispan.persistence.remote.RemoteStore)

Example 4 with RemoteStoreConfiguration

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());
}
Also used : RemoteServerConfiguration(org.infinispan.persistence.remote.configuration.RemoteServerConfiguration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Aggregations

RemoteStoreConfiguration (org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 NettyRestResponse (org.infinispan.rest.NettyRestResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 RestCacheClient (org.infinispan.client.rest.RestCacheClient)1 RestEntity (org.infinispan.client.rest.RestEntity)1 RestResponse (org.infinispan.client.rest.RestResponse)1 Json (org.infinispan.commons.dataconversion.internal.Json)1 Configuration (org.infinispan.configuration.cache.Configuration)1 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)1 PersistenceManager (org.infinispan.persistence.manager.PersistenceManager)1 RemoteStore (org.infinispan.persistence.remote.RemoteStore)1 RemoteServerConfiguration (org.infinispan.persistence.remote.configuration.RemoteServerConfiguration)1 RestResponseException (org.infinispan.rest.RestResponseException)1 ContentSource (org.infinispan.rest.framework.ContentSource)1 ResourceUtil.addEntityAsJson (org.infinispan.rest.resources.ResourceUtil.addEntityAsJson)1 RollingUpgradeManager (org.infinispan.upgrade.RollingUpgradeManager)1