Search in sources :

Example 1 with WanReplicationConfigDTO

use of com.hazelcast.internal.management.dto.WanReplicationConfigDTO 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 WanReplicationConfigDTO

use of com.hazelcast.internal.management.dto.WanReplicationConfigDTO in project hazelcast by hazelcast.

the class RestTest method addWanConfig.

@Test
public void addWanConfig() throws Exception {
    WanReplicationConfig wanConfig = new WanReplicationConfig();
    wanConfig.setName("test");
    WanReplicationConfigDTO dto = new WanReplicationConfigDTO(wanConfig);
    String result = communicator.addWanConfig(dto.toJson().toString());
    assertEquals("{\"status\":\"fail\",\"message\":\"java.lang.UnsupportedOperationException: Adding new WAN config is not supported.\"}", result);
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) WanReplicationConfigDTO(com.hazelcast.internal.management.dto.WanReplicationConfigDTO) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

WanReplicationConfig (com.hazelcast.config.WanReplicationConfig)2 WanReplicationConfigDTO (com.hazelcast.internal.management.dto.WanReplicationConfigDTO)2 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 QuickTest (com.hazelcast.test.annotation.QuickTest)1 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1