Search in sources :

Example 1 with WanReplicationConfig

use of com.hazelcast.config.WanReplicationConfig in project hazelcast by hazelcast.

the class HttpPostCommandProcessor method handleAddWanConfig.

private void handleAddWanConfig(HttpPostCommand command) throws UnsupportedEncodingException {
    String res;
    byte[] data = command.getData();
    String[] strList = bytesToString(data).split("&");
    String wanConfigJson = URLDecoder.decode(strList[0], "UTF-8");
    try {
        OperationService opService = textCommandService.getNode().getNodeEngine().getOperationService();
        final Set<Member> members = textCommandService.getNode().getClusterService().getMembers();
        WanReplicationConfig wanReplicationConfig = new WanReplicationConfig();
        WanReplicationConfigDTO dto = new WanReplicationConfigDTO(wanReplicationConfig);
        dto.fromJson(Json.parse(wanConfigJson).asObject());
        List<InternalCompletableFuture> futureList = new ArrayList<InternalCompletableFuture>(members.size());
        for (Member member : members) {
            InternalCompletableFuture<Object> future = opService.invokeOnTarget(WanReplicationService.SERVICE_NAME, new AddWanConfigOperation(dto.getConfig()), member.getAddress());
            futureList.add(future);
        }
        for (InternalCompletableFuture future : futureList) {
            future.get();
        }
        res = response(ResponseType.SUCCESS, "message", "WAN configuration added.");
    } catch (Exception ex) {
        logger.warning("Error occurred while adding WAN config", ex);
        res = exceptionResponse(ex);
    }
    command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) WanReplicationConfigDTO(com.hazelcast.internal.management.dto.WanReplicationConfigDTO) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AddWanConfigOperation(com.hazelcast.internal.management.operation.AddWanConfigOperation) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member)

Example 2 with WanReplicationConfig

use of com.hazelcast.config.WanReplicationConfig in project hazelcast by hazelcast.

the class WanReplicationServiceImpl method getWanReplicationPublisher.

@Override
@SuppressWarnings("SynchronizeOnThis")
public WanReplicationPublisher getWanReplicationPublisher(String name) {
    WanReplicationPublisherDelegate wr = wanReplications.get(name);
    if (wr != null) {
        return wr;
    }
    synchronized (this) {
        wr = wanReplications.get(name);
        if (wr != null) {
            return wr;
        }
        WanReplicationConfig wanReplicationConfig = node.getConfig().getWanReplicationConfig(name);
        if (wanReplicationConfig == null) {
            return null;
        }
        List<WanPublisherConfig> publisherConfigs = wanReplicationConfig.getWanPublisherConfigs();
        WanReplicationEndpoint[] targetEndpoints = new WanReplicationEndpoint[publisherConfigs.size()];
        int count = 0;
        for (WanPublisherConfig publisherConfig : publisherConfigs) {
            WanReplicationEndpoint target;
            try {
                if (publisherConfig.getImplementation() != null) {
                    target = (WanReplicationEndpoint) publisherConfig.getImplementation();
                } else {
                    target = ClassLoaderUtil.newInstance(node.getConfigClassLoader(), publisherConfig.getClassName());
                }
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
            target.init(node, wanReplicationConfig, publisherConfig);
            targetEndpoints[count++] = target;
        }
        wr = new WanReplicationPublisherDelegate(name, targetEndpoints);
        wanReplications.put(name, wr);
        return wr;
    }
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) WanReplicationEndpoint(com.hazelcast.wan.WanReplicationEndpoint) WanPublisherConfig(com.hazelcast.config.WanPublisherConfig) WanReplicationEndpoint(com.hazelcast.wan.WanReplicationEndpoint)

Example 3 with WanReplicationConfig

use of com.hazelcast.config.WanReplicationConfig in project hazelcast by hazelcast.

the class WanReplicationTest method getConfig.

@Override
protected Config getConfig() {
    Config config = new Config();
    WanReplicationConfig wanConfig = new WanReplicationConfig();
    wanConfig.setName("dummyWan");
    wanConfig.addWanPublisherConfig(getPublisherConfig());
    WanReplicationRef wanRef = new WanReplicationRef();
    wanRef.setName("dummyWan");
    wanRef.setMergePolicy(PassThroughMergePolicy.class.getName());
    config.addWanReplicationConfig(wanConfig);
    config.getMapConfig("default").setWanReplicationRef(wanRef);
    return config;
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) PassThroughMergePolicy(com.hazelcast.map.merge.PassThroughMergePolicy) WanReplicationRef(com.hazelcast.config.WanReplicationRef) WanPublisherConfig(com.hazelcast.config.WanPublisherConfig) Config(com.hazelcast.config.Config) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig)

Example 4 with WanReplicationConfig

use of com.hazelcast.config.WanReplicationConfig in project hazelcast by hazelcast.

the class WanReplicationConfigDTOTest method testSerialization.

@Test
public void testSerialization() {
    Map<String, Comparable> properties = new HashMap<String, Comparable>();
    properties.put("key1", "value1");
    properties.put("key2", "value2");
    WanPublisherConfig wanPublisherConfig = new WanPublisherConfig().setGroupName("myGroupName").setQueueCapacity(23).setClassName("myClassName").setQueueFullBehavior(WANQueueFullBehavior.THROW_EXCEPTION).setProperties(properties);
    WanReplicationConfig expectedConfig = new WanReplicationConfig().setName("myName").addWanPublisherConfig(wanPublisherConfig);
    WanReplicationConfigDTO dto = new WanReplicationConfigDTO(expectedConfig);
    JsonObject json = dto.toJson();
    WanReplicationConfigDTO deserialized = new WanReplicationConfigDTO(null);
    deserialized.fromJson(json);
    WanReplicationConfig actualConfig = deserialized.getConfig();
    assertEquals(expectedConfig.getName(), actualConfig.getName());
    List<WanPublisherConfig> wanPublisherConfigs = actualConfig.getWanPublisherConfigs();
    assertEquals(1, wanPublisherConfigs.size());
    WanPublisherConfig actualWanPublisherConfig = wanPublisherConfigs.get(0);
    assertEquals(wanPublisherConfig.getGroupName(), actualWanPublisherConfig.getGroupName());
    assertEquals(wanPublisherConfig.getQueueCapacity(), actualWanPublisherConfig.getQueueCapacity());
    assertEquals(wanPublisherConfig.getClassName(), actualWanPublisherConfig.getClassName());
    assertEquals(wanPublisherConfig.getQueueFullBehavior(), actualWanPublisherConfig.getQueueFullBehavior());
    assertEquals(wanPublisherConfig.getProperties(), actualWanPublisherConfig.getProperties());
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) HashMap(java.util.HashMap) JsonObject(com.eclipsesource.json.JsonObject) WanPublisherConfig(com.hazelcast.config.WanPublisherConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with WanReplicationConfig

use of com.hazelcast.config.WanReplicationConfig in project hazelcast by hazelcast.

the class ClientMapWANExceptionTest method getConfig.

@Override
protected Config getConfig() {
    Config config = new Config();
    WanReplicationConfig wanConfig = new WanReplicationConfig();
    wanConfig.setName("dummyWan");
    wanConfig.addWanPublisherConfig(getWanPublisherConfig());
    WanReplicationRef wanRef = new WanReplicationRef();
    wanRef.setName("dummyWan");
    wanRef.setMergePolicy(PassThroughMergePolicy.class.getName());
    config.addWanReplicationConfig(wanConfig);
    config.getMapConfig("default").setWanReplicationRef(wanRef);
    return config;
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) PassThroughMergePolicy(com.hazelcast.map.merge.PassThroughMergePolicy) WanReplicationRef(com.hazelcast.config.WanReplicationRef) Config(com.hazelcast.config.Config) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) WanPublisherConfig(com.hazelcast.config.WanPublisherConfig)

Aggregations

WanReplicationConfig (com.hazelcast.config.WanReplicationConfig)9 WanPublisherConfig (com.hazelcast.config.WanPublisherConfig)6 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 Config (com.hazelcast.config.Config)2 WanReplicationRef (com.hazelcast.config.WanReplicationRef)2 WanReplicationConfigDTO (com.hazelcast.internal.management.dto.WanReplicationConfigDTO)2 PassThroughMergePolicy (com.hazelcast.map.merge.PassThroughMergePolicy)2 JsonArray (com.eclipsesource.json.JsonArray)1 JsonObject (com.eclipsesource.json.JsonObject)1 WanConsumerConfig (com.hazelcast.config.WanConsumerConfig)1 Member (com.hazelcast.core.Member)1 AddWanConfigOperation (com.hazelcast.internal.management.operation.AddWanConfigOperation)1 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)1 OperationService (com.hazelcast.spi.OperationService)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)1 WanReplicationEndpoint (com.hazelcast.wan.WanReplicationEndpoint)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1