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