Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.client.impl.management;
import com.hazelcast.client.impl.ClientDelegatingFuture;
import com.hazelcast.client.impl.clientside.ClientMessageDecoder;
import com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl;
import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.codec.MCAddWanBatchPublisherConfigCodec;
import com.hazelcast.client.impl.protocol.codec.MCApplyMCConfigCodec;
import com.hazelcast.client.impl.protocol.codec.MCChangeClusterStateCodec;
import com.hazelcast.client.impl.protocol.codec.MCChangeClusterVersionCodec;
import com.hazelcast.client.impl.protocol.codec.MCChangeWanReplicationStateCodec;
import com.hazelcast.client.impl.protocol.codec.MCCheckWanConsistencyCodec;
import com.hazelcast.client.impl.protocol.codec.MCClearWanQueuesCodec;
import com.hazelcast.client.impl.protocol.codec.MCGetCPMembersCodec;
import com.hazelcast.client.impl.protocol.codec.MCGetClusterMetadataCodec;
import com.hazelcast.client.impl.protocol.codec.MCGetMapConfigCodec;
import com.hazelcast.client.impl.protocol.codec.MCGetMemberConfigCodec;
import com.hazelcast.client.impl.protocol.codec.MCGetSystemPropertiesCodec;
import com.hazelcast.client.impl.protocol.codec.MCGetThreadDumpCodec;
import com.hazelcast.client.impl.protocol.codec.MCGetTimedMemberStateCodec;
import com.hazelcast.client.impl.protocol.codec.MCInterruptHotRestartBackupCodec;
import com.hazelcast.client.impl.protocol.codec.MCMatchMCConfigCodec;
import com.hazelcast.client.impl.protocol.codec.MCPollMCEventsCodec;
import com.hazelcast.client.impl.protocol.codec.MCPromoteLiteMemberCodec;
import com.hazelcast.client.impl.protocol.codec.MCPromoteToCPMemberCodec;
import com.hazelcast.client.impl.protocol.codec.MCReadMetricsCodec;
import com.hazelcast.client.impl.protocol.codec.MCRemoveCPMemberCodec;
import com.hazelcast.client.impl.protocol.codec.MCResetCPSubsystemCodec;
import com.hazelcast.client.impl.protocol.codec.MCRunConsoleCommandCodec;
import com.hazelcast.client.impl.protocol.codec.MCRunGcCodec;
import com.hazelcast.client.impl.protocol.codec.MCRunScriptCodec;
import com.hazelcast.client.impl.protocol.codec.MCShutdownClusterCodec;
import com.hazelcast.client.impl.protocol.codec.MCShutdownMemberCodec;
import com.hazelcast.client.impl.protocol.codec.MCTriggerForceStartCodec;
import com.hazelcast.client.impl.protocol.codec.MCTriggerHotRestartBackupCodec;
import com.hazelcast.client.impl.protocol.codec.MCTriggerPartialStartCodec;
import com.hazelcast.client.impl.protocol.codec.MCUpdateMapConfigCodec;
import com.hazelcast.client.impl.protocol.codec.MCWanSyncMapCodec;
import com.hazelcast.client.impl.spi.impl.ClientInvocation;
import com.hazelcast.cluster.ClusterState;
import com.hazelcast.cluster.Member;
import com.hazelcast.cp.CPSubsystemManagementService;
import com.hazelcast.internal.management.TimedMemberState;
import com.hazelcast.internal.management.dto.CPMemberDTO;
import com.hazelcast.internal.management.dto.ClientBwListDTO;
import com.hazelcast.internal.management.dto.MCEventDTO;
import com.hazelcast.internal.metrics.managementcenter.MetricsResultSet;
import com.hazelcast.internal.nio.ConnectionType;
import com.hazelcast.internal.serialization.InternalSerializationService;
import com.hazelcast.internal.util.MapUtil;
import com.hazelcast.spi.properties.HazelcastProperty;
import com.hazelcast.version.Version;
import com.hazelcast.wan.WanPublisherState;
import com.hazelcast.wan.impl.AddWanConfigResult;
import com.hazelcast.wan.impl.WanSyncType;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import static com.hazelcast.internal.util.Preconditions.checkNotNull;
import static com.hazelcast.wan.impl.WanSyncType.ALL_MAPS;
import static com.hazelcast.wan.impl.WanSyncType.SINGLE_MAP;
/**
* Only works for smart clients, i.e. doesn't work for unisocket clients.
*/
@SuppressWarnings({"checkstyle:methodcount"})
public class ManagementCenterService {
/**
* Internal property for enabling MC client mode ({@link ConnectionType#MC_JAVA_CLIENT}).
*/
public static final HazelcastProperty MC_CLIENT_MODE_PROP
= new HazelcastProperty("hazelcast.client.internal.mc.mode", false);
private final HazelcastClientInstanceImpl client;
private final InternalSerializationService serializationService;
public ManagementCenterService(HazelcastClientInstanceImpl client,
InternalSerializationService serializationService) {
this.client = client;
this.serializationService = serializationService;
}
/**
* Reads the metrics journal for a given number starting from a specific sequence.
*/
@Nonnull
public CompletableFuture readMetricsAsync(Member member, long startSequence) {
ClientMessage request = MCReadMetricsCodec.encodeRequest(member.getUuid(), startSequence);
ClientInvocation invocation = new ClientInvocation(client, request, null, member.getUuid());
invocation.disallowRetryOnRandom();
ClientMessageDecoder decoder = (clientMessage) -> {
MCReadMetricsCodec.ResponseParameters response = MCReadMetricsCodec.decodeResponse(clientMessage);
return new MetricsResultSet(response.nextSequence, response.elements);
};
return new ClientDelegatingFuture<>(invocation.invoke(), serializationService, decoder, false);
}
/**
* Changes the cluster's state.
*/
@Nonnull
public CompletableFuture changeClusterState(ClusterState newState) {
checkNotNull(newState);
ClientInvocation invocation = new ClientInvocation(
client,
MCChangeClusterStateCodec.encodeRequest(newState.getId()),
null
);
return new ClientDelegatingFuture<>(
invocation.invoke(),
serializationService,
clientMessage -> null
);
}
/**
* Gets the config ƒor a given map from a random member.
*/
@Nonnull
public CompletableFuture getMapConfig(String map) {
checkNotNull(map);
return doGetMapConfig(null, map);
}
/**
* Gets the config ƒor a given map from a specific member.
*/
@Nonnull
public CompletableFuture getMapConfig(Member member, String map) {
checkNotNull(member);
checkNotNull(map);
return doGetMapConfig(member, map);
}
private CompletableFuture doGetMapConfig(Member member, String map) {
ClientInvocation invocation;
if (member == null) {
invocation = new ClientInvocation(
client,
MCGetMapConfigCodec.encodeRequest(map),
map
);
} else {
invocation = new ClientInvocation(
client,
MCGetMapConfigCodec.encodeRequest(map),
map,
member.getUuid()
);
invocation.disallowRetryOnRandom();
}
return new ClientDelegatingFuture<>(
invocation.invoke(),
serializationService,
clientMessage -> {
MCGetMapConfigCodec.ResponseParameters response =
MCGetMapConfigCodec.decodeResponse(clientMessage);
return MCMapConfig.fromResponse(response);
},
true
);
}
/**
* Updates the config of a given map on a given member.
*/
@Nonnull
public CompletableFuture updateMapConfig(Member member,
UpdateMapConfigParameters parameters) {
checkNotNull(member);
checkNotNull(parameters);
checkNotNull(parameters.getEvictionPolicy());
checkNotNull(parameters.getMaxSizePolicy());
ClientInvocation invocation = new ClientInvocation(
client,
MCUpdateMapConfigCodec.encodeRequest(
parameters.getMap(),
parameters.getTimeToLiveSeconds(),
parameters.getMaxIdleSeconds(),
parameters.getEvictionPolicy().getId(),
parameters.isReadBackupData(),
parameters.getMaxSize(),
parameters.getMaxSizePolicy().getId()),
parameters.getMap(),
member.getUuid()
);
invocation.disallowRetryOnRandom();
return new ClientDelegatingFuture<>(
invocation.invoke(),
serializationService,
clientMessage -> null
);
}
/**
* Gets the config of a given member rendered as XML.
*/
@Nonnull
public CompletableFuture getMemberConfig(Member member) {
checkNotNull(member);
ClientInvocation invocation = new ClientInvocation(
client,
MCGetMemberConfigCodec.encodeRequest(),
null,
member.getUuid()
);
invocation.disallowRetryOnRandom();
return new ClientDelegatingFuture<>(
invocation.invoke(),
serializationService,
clientMessage -> MCGetMemberConfigCodec.decodeResponse(clientMessage).configXml
);
}
/**
* Runs GC on a given member.
*/
@Nonnull
public CompletableFuture runGc(Member member) {
checkNotNull(member);
ClientInvocation invocation = new ClientInvocation(
client,
MCRunGcCodec.encodeRequest(),
null,
member.getUuid()
);
invocation.disallowRetryOnRandom();
return new ClientDelegatingFuture<>(
invocation.invoke(),
serializationService,
clientMessage -> null
);
}
/**
* Gets thread dump of a given member.
*
* @param member {@link Member} to get the thread dump of
* @param dumpDeadLocks whether only dead-locked threads or all threads should be dumped.
*/
@Nonnull
public CompletableFuture getThreadDump(Member member, boolean dumpDeadLocks) {
checkNotNull(member);
ClientInvocation invocation = new ClientInvocation(
client,
MCGetThreadDumpCodec.encodeRequest(dumpDeadLocks),
null,
member.getUuid()
);
invocation.disallowRetryOnRandom();
return new ClientDelegatingFuture<>(
invocation.invoke(),
serializationService,
clientMessage -> MCGetThreadDumpCodec.decodeResponse(clientMessage).threadDump
);
}
/**
* Shuts down a given member.
*
* @param member {@link Member} to shut down
*/
public void shutdownMember(Member member) {
checkNotNull(member);
ClientInvocation invocation = new ClientInvocation(
client,
MCShutdownMemberCodec.encodeRequest(),
null,
member.getUuid()
);
invocation.disallowRetryOnRandom();
invocation.invoke();
}
/**
* Promotes a lite member to a data member.
*
* @param member {@link Member} to promote
*/
@Nonnull
public CompletableFuture promoteLiteMember(Member member) {
checkNotNull(member);
ClientInvocation invocation = new ClientInvocation(
client,
MCPromoteLiteMemberCodec.encodeRequest(),
null,
member.getUuid()
);
invocation.disallowRetryOnRandom();
return new ClientDelegatingFuture<>(
invocation.invoke(),
serializationService,
clientMessage -> null
);
}
/**
* Gets system properties of a given member.
*
* @param member {@link Member} to get system properties of
*/
@Nonnull
public CompletableFuture