use of com.hazelcast.internal.management.dto.ClientEndPointDTO in project hazelcast by hazelcast.
the class TimedMemberStateFactory method createMemberState.
private void createMemberState(TimedMemberState timedMemberState, MemberStateImpl memberState, Collection<StatisticsAwareService> services) {
Node node = instance.node;
HashSet<ClientEndPointDTO> serializableClientEndPoints = new HashSet<ClientEndPointDTO>();
for (Client client : instance.node.clientEngine.getClients()) {
serializableClientEndPoints.add(new ClientEndPointDTO(client));
}
memberState.setClients(serializableClientEndPoints);
Address thisAddress = node.getThisAddress();
memberState.setAddress(thisAddress.getHost() + ":" + thisAddress.getPort());
TimedMemberStateFactoryHelper.registerJMXBeans(instance, memberState);
MemberPartitionStateImpl memberPartitionState = (MemberPartitionStateImpl) memberState.getMemberPartitionState();
InternalPartitionService partitionService = node.getPartitionService();
IPartition[] partitions = partitionService.getPartitions();
List<Integer> partitionList = memberPartitionState.getPartitions();
for (IPartition partition : partitions) {
if (partition.isLocal()) {
partitionList.add(partition.getPartitionId());
}
}
memberPartitionState.setMigrationQueueSize(partitionService.getMigrationQueueSize());
memberPartitionState.setMemberStateSafe(memberStateSafe);
memberState.setLocalMemoryStats(getMemoryStats());
memberState.setOperationStats(getOperationStats());
TimedMemberStateFactoryHelper.createRuntimeProps(memberState);
createMemState(timedMemberState, memberState, services);
createNodeState(memberState);
createHotRestartState(memberState);
createClusterHotRestartStatus(memberState);
createWanSyncState(memberState);
}
use of com.hazelcast.internal.management.dto.ClientEndPointDTO in project hazelcast by hazelcast.
the class MemberStateImplTest method testSerialization.
@Test
public void testSerialization() {
HazelcastInstance hazelcastInstance = createHazelcastInstance();
LocalReplicatedMapStatsImpl replicatedMapStats = new LocalReplicatedMapStatsImpl();
replicatedMapStats.incrementPuts(30);
CacheStatisticsImpl cacheStatistics = new CacheStatisticsImpl(Clock.currentTimeMillis());
cacheStatistics.increaseCacheHits(5);
Collection<ClientEndPointDTO> clients = new ArrayList<ClientEndPointDTO>();
ClientEndPointDTO client = new ClientEndPointDTO();
client.uuid = "abc123456";
client.address = "localhost";
client.clientType = "undefined";
clients.add(client);
Map<String, Long> runtimeProps = new HashMap<String, Long>();
runtimeProps.put("prop1", 598123L);
ClusterState clusterState = ClusterState.ACTIVE;
com.hazelcast.instance.NodeState nodeState = com.hazelcast.instance.NodeState.PASSIVE;
Version clusterVersion = Version.of("3.8.0");
MemberVersion memberVersion = MemberVersion.of("3.9.0");
NodeState state = new NodeStateImpl(clusterState, nodeState, clusterVersion, memberVersion);
final BackupTaskStatus backupTaskStatus = new BackupTaskStatus(BackupTaskState.IN_PROGRESS, 5, 10);
final HotRestartStateImpl hotRestartState = new HotRestartStateImpl(backupTaskStatus, false);
final WanSyncState wanSyncState = new WanSyncStateImpl(WanSyncStatus.IN_PROGRESS, 86, "atob", "B");
TimedMemberStateFactory factory = new TimedMemberStateFactory(getHazelcastInstanceImpl(hazelcastInstance));
TimedMemberState timedMemberState = factory.createTimedMemberState();
MemberStateImpl memberState = timedMemberState.getMemberState();
memberState.setAddress("memberStateAddress:Port");
memberState.putLocalMapStats("mapStats", new LocalMapStatsImpl());
memberState.putLocalMultiMapStats("multiMapStats", new LocalMultiMapStatsImpl());
memberState.putLocalQueueStats("queueStats", new LocalQueueStatsImpl());
memberState.putLocalTopicStats("topicStats", new LocalTopicStatsImpl());
memberState.putLocalExecutorStats("executorStats", new LocalExecutorStatsImpl());
memberState.putLocalReplicatedMapStats("replicatedMapStats", replicatedMapStats);
memberState.putLocalCacheStats("cacheStats", new LocalCacheStatsImpl(cacheStatistics));
memberState.setRuntimeProps(runtimeProps);
memberState.setLocalMemoryStats(new LocalMemoryStatsImpl());
memberState.setOperationStats(new LocalOperationStatsImpl());
memberState.setClients(clients);
memberState.setNodeState(state);
memberState.setHotRestartState(hotRestartState);
memberState.setWanSyncState(wanSyncState);
MemberStateImpl deserialized = new MemberStateImpl();
deserialized.fromJson(memberState.toJson());
assertEquals("memberStateAddress:Port", deserialized.getAddress());
assertNotNull(deserialized.getLocalMapStats("mapStats").toString());
assertNotNull(deserialized.getLocalMultiMapStats("multiMapStats").toString());
assertNotNull(deserialized.getLocalQueueStats("queueStats").toString());
assertNotNull(deserialized.getLocalTopicStats("topicStats").toString());
assertNotNull(deserialized.getLocalExecutorStats("executorStats").toString());
assertNotNull(deserialized.getLocalReplicatedMapStats("replicatedMapStats").toString());
assertEquals(1, deserialized.getLocalReplicatedMapStats("replicatedMapStats").getPutOperationCount());
assertNotNull(deserialized.getLocalCacheStats("cacheStats").toString());
assertEquals(5, deserialized.getLocalCacheStats("cacheStats").getCacheHits());
assertNotNull(deserialized.getRuntimeProps());
assertEquals(Long.valueOf(598123L), deserialized.getRuntimeProps().get("prop1"));
assertNotNull(deserialized.getLocalMemoryStats());
assertNotNull(deserialized.getOperationStats());
assertNotNull(deserialized.getMXBeans());
client = deserialized.getClients().iterator().next();
assertEquals("abc123456", client.uuid);
assertEquals("localhost", client.address);
assertEquals("undefined", client.clientType);
NodeState deserializedState = deserialized.getNodeState();
assertEquals(clusterState, deserializedState.getClusterState());
assertEquals(nodeState, deserializedState.getNodeState());
assertEquals(clusterVersion, deserializedState.getClusterVersion());
assertEquals(memberVersion, deserializedState.getMemberVersion());
final HotRestartState deserializedHotRestartState = deserialized.getHotRestartState();
assertEquals(backupTaskStatus, deserializedHotRestartState.getBackupTaskStatus());
final WanSyncState deserializedWanSyncState = deserialized.getWanSyncState();
assertEquals(WanSyncStatus.IN_PROGRESS, deserializedWanSyncState.getStatus());
assertEquals(86, deserializedWanSyncState.getSyncedPartitionCount());
assertEquals("atob", deserializedWanSyncState.getActiveWanConfigName());
assertEquals("B", deserializedWanSyncState.getActivePublisherName());
ClusterHotRestartStatusDTO clusterHotRestartStatus = deserialized.getClusterHotRestartStatus();
assertEquals(FULL_RECOVERY_ONLY, clusterHotRestartStatus.getDataRecoveryPolicy());
assertEquals(ClusterHotRestartStatusDTO.ClusterHotRestartStatus.UNKNOWN, clusterHotRestartStatus.getHotRestartStatus());
assertEquals(-1, clusterHotRestartStatus.getRemainingValidationTimeMillis());
assertEquals(-1, clusterHotRestartStatus.getRemainingDataLoadTimeMillis());
assertTrue(clusterHotRestartStatus.getMemberHotRestartStatusMap().isEmpty());
}
use of com.hazelcast.internal.management.dto.ClientEndPointDTO in project hazelcast by hazelcast.
the class MemberStateImpl method fromJson.
//CHECKSTYLE:OFF
@Override
public void fromJson(JsonObject json) {
address = getString(json, "address");
for (JsonObject.Member next : getObject(json, "mapStats")) {
LocalMapStatsImpl stats = new LocalMapStatsImpl();
stats.fromJson(next.getValue().asObject());
mapStats.put(next.getName(), stats);
}
for (JsonObject.Member next : getObject(json, "multiMapStats")) {
LocalMultiMapStatsImpl stats = new LocalMultiMapStatsImpl();
stats.fromJson(next.getValue().asObject());
multiMapStats.put(next.getName(), stats);
}
for (JsonObject.Member next : getObject(json, "replicatedMapStats", new JsonObject())) {
LocalReplicatedMapStats stats = new LocalReplicatedMapStatsImpl();
stats.fromJson(next.getValue().asObject());
replicatedMapStats.put(next.getName(), stats);
}
for (JsonObject.Member next : getObject(json, "queueStats")) {
LocalQueueStatsImpl stats = new LocalQueueStatsImpl();
stats.fromJson(next.getValue().asObject());
queueStats.put(next.getName(), stats);
}
for (JsonObject.Member next : getObject(json, "topicStats")) {
LocalTopicStatsImpl stats = new LocalTopicStatsImpl();
stats.fromJson(next.getValue().asObject());
topicStats.put(next.getName(), stats);
}
for (JsonObject.Member next : getObject(json, "executorStats")) {
LocalExecutorStatsImpl stats = new LocalExecutorStatsImpl();
stats.fromJson(next.getValue().asObject());
executorStats.put(next.getName(), stats);
}
for (JsonObject.Member next : getObject(json, "cacheStats", new JsonObject())) {
LocalCacheStats stats = new LocalCacheStatsImpl();
stats.fromJson(next.getValue().asObject());
cacheStats.put(next.getName(), stats);
}
for (JsonObject.Member next : getObject(json, "wanStats", new JsonObject())) {
LocalWanStats stats = new LocalWanStatsImpl();
stats.fromJson(next.getValue().asObject());
wanStats.put(next.getName(), stats);
}
for (JsonObject.Member next : getObject(json, "runtimeProps")) {
runtimeProps.put(next.getName(), next.getValue().asLong());
}
final JsonArray jsonClients = getArray(json, "clients");
for (JsonValue jsonClient : jsonClients) {
final ClientEndPointDTO client = new ClientEndPointDTO();
client.fromJson(jsonClient.asObject());
clients.add(client);
}
beans = new MXBeansDTO();
beans.fromJson(getObject(json, "beans"));
JsonObject jsonMemoryStats = getObject(json, "memoryStats", null);
if (jsonMemoryStats != null) {
memoryStats.fromJson(jsonMemoryStats);
}
JsonObject jsonOperationStats = getObject(json, "operationStats", null);
if (jsonOperationStats != null) {
operationStats.fromJson(jsonOperationStats);
}
JsonObject jsonMemberPartitionState = getObject(json, "memberPartitionState", null);
if (jsonMemberPartitionState != null) {
memberPartitionState = new MemberPartitionStateImpl();
memberPartitionState.fromJson(jsonMemberPartitionState);
}
JsonObject jsonNodeState = getObject(json, "nodeState", null);
if (jsonNodeState != null) {
nodeState = new NodeStateImpl();
nodeState.fromJson(jsonNodeState);
}
JsonObject jsonHotRestartState = getObject(json, "hotRestartState", null);
if (jsonHotRestartState != null) {
hotRestartState = new HotRestartStateImpl();
hotRestartState.fromJson(jsonHotRestartState);
}
JsonObject jsonClusterHotRestartStatus = getObject(json, "clusterHotRestartStatus", null);
if (jsonClusterHotRestartStatus != null) {
clusterHotRestartStatus = new ClusterHotRestartStatusDTO();
clusterHotRestartStatus.fromJson(jsonClusterHotRestartStatus);
}
JsonObject jsonWanSyncState = getObject(json, "wanSyncState", null);
if (jsonWanSyncState != null) {
wanSyncState = new WanSyncStateImpl();
wanSyncState.fromJson(jsonWanSyncState);
}
}
use of com.hazelcast.internal.management.dto.ClientEndPointDTO in project hazelcast by hazelcast.
the class MemberStateImpl method fromJson.
@Override
@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:methodlength" })
public void fromJson(JsonObject json) {
address = getString(json, "address");
String uuidString = getString(json, "uuid", null);
uuid = uuidString != null ? UUID.fromString(uuidString) : null;
String cpMemberUuidString = getString(json, "cpMemberUuid", null);
cpMemberUuid = cpMemberUuidString != null ? UUID.fromString(cpMemberUuidString) : null;
name = getString(json, "name", null);
JsonArray jsonEndpoints = getArray(json, "endpoints");
endpoints = new HashMap<>();
for (JsonValue obj : jsonEndpoints) {
JsonObject endpoint = obj.asObject();
String id = endpoint.getString("id", null);
ProtocolType type = ProtocolType.valueOf(endpoint.getString("protocol", "MEMBER"));
JsonValue addr = endpoint.get("address");
String host = addr.asObject().getString("host", "");
int port = addr.asObject().getInt("port", 0);
EndpointQualifier qualifier = EndpointQualifier.resolve(type, id);
Address address = null;
try {
address = new Address(host, port);
} catch (UnknownHostException e) {
// ignore
ignore(e);
}
endpoints.put(qualifier, address);
}
mapsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "mapStats")) {
mapsWithStats.add(next.getName());
}
multiMapsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "multiMapStats")) {
multiMapsWithStats.add(next.getName());
}
replicatedMapsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "replicatedMapStats")) {
replicatedMapsWithStats.add(next.getName());
}
queuesWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "queueStats")) {
queuesWithStats.add(next.getName());
}
topicsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "topicStats")) {
topicsWithStats.add(next.getName());
}
reliableTopicsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "reliableTopicStats")) {
reliableTopicsWithStats.add(next.getName());
}
pnCountersWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "pnCounterStats")) {
pnCountersWithStats.add(next.getName());
}
executorsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "executorStats")) {
executorsWithStats.add(next.getName());
}
scheduledExecutorsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "scheduledExecutorStats")) {
scheduledExecutorsWithStats.add(next.getName());
}
durableExecutorsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "durableExecutorStats")) {
durableExecutorsWithStats.add(next.getName());
}
cachesWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "cacheStats")) {
cachesWithStats.add(next.getName());
}
flakeIdGeneratorsWithStats = new HashSet<>();
for (JsonObject.Member next : getObject(json, "flakeIdStats")) {
flakeIdGeneratorsWithStats.add(next.getName());
}
for (JsonObject.Member next : getObject(json, "wanStats", new JsonObject())) {
putDeserializedIfSerializable(wanStats, next.getName(), next.getValue().asObject(), new LocalWanStatsImpl());
}
JsonArray jsonClients = getArray(json, "clients");
clients = new ArrayList<>();
for (JsonValue jsonClient : jsonClients) {
final ClientEndPointDTO client = new ClientEndPointDTO();
client.fromJson(jsonClient.asObject());
clients.add(client);
}
JsonObject jsonOperationStats = getObject(json, "operationStats", null);
if (jsonOperationStats != null) {
operationStats = readJsonIfDeserializable(jsonOperationStats, operationStats);
}
JsonObject jsonMemberPartitionState = getObject(json, "memberPartitionState", null);
if (jsonMemberPartitionState != null) {
memberPartitionState = new MemberPartitionStateImpl();
memberPartitionState.fromJson(jsonMemberPartitionState);
}
JsonObject jsonNodeState = getObject(json, "nodeState", null);
if (jsonNodeState != null) {
nodeState = new NodeStateImpl();
nodeState.fromJson(jsonNodeState);
}
JsonObject jsonHotRestartState = getObject(json, "hotRestartState", null);
if (jsonHotRestartState != null) {
hotRestartState = new HotRestartStateImpl();
hotRestartState.fromJson(jsonHotRestartState);
}
JsonObject jsonClusterHotRestartStatus = getObject(json, "clusterHotRestartStatus", null);
if (jsonClusterHotRestartStatus != null) {
clusterHotRestartStatus = new ClusterHotRestartStatusDTO();
clusterHotRestartStatus.fromJson(jsonClusterHotRestartStatus);
}
clientStats = new HashMap<>();
for (JsonObject.Member next : getObject(json, "clientStats")) {
clientStats.put(UUID.fromString(next.getName()), next.getValue().asString());
}
}
use of com.hazelcast.internal.management.dto.ClientEndPointDTO in project hazelcast by hazelcast.
the class MemberStateImplTest method testSerialization.
@Test
public void testSerialization() throws UnknownHostException {
HazelcastInstance hazelcastInstance = createHazelcastInstance();
LocalReplicatedMapStatsImpl replicatedMapStats = new LocalReplicatedMapStatsImpl();
replicatedMapStats.incrementPutsNanos(30);
CacheStatisticsImpl cacheStatistics = new CacheStatisticsImpl(Clock.currentTimeMillis());
cacheStatistics.increaseCacheHits(5);
UUID clientUuid = UUID.randomUUID();
Collection<ClientEndPointDTO> clients = new ArrayList<>();
ClientEndPointDTO client = new ClientEndPointDTO();
client.uuid = clientUuid;
client.address = "localhost";
client.clientType = "undefined";
client.name = "aClient";
client.labels = new HashSet<>(Collections.singletonList("label"));
client.ipAddress = "10.176.167.34";
client.canonicalHostName = "ip-10-176-167-34.ec2.internal";
clients.add(client);
ClusterState clusterState = ClusterState.ACTIVE;
com.hazelcast.instance.impl.NodeState nodeState = com.hazelcast.instance.impl.NodeState.PASSIVE;
Version clusterVersion = Version.of("3.9.0");
MemberVersion memberVersion = MemberVersion.of("3.8.0");
NodeState state = new NodeStateImpl(clusterState, nodeState, clusterVersion, memberVersion);
final BackupTaskStatus backupTaskStatus = new BackupTaskStatus(BackupTaskState.IN_PROGRESS, 5, 10);
final String backupDirectory = "/hot/backup/dir";
final HotRestartStateImpl hotRestartState = new HotRestartStateImpl(backupTaskStatus, true, backupDirectory);
Map<UUID, String> clientStats = new HashMap<>();
clientStats.put(clientUuid, "someStats");
Map<EndpointQualifier, Address> endpoints = new HashMap<>();
endpoints.put(EndpointQualifier.MEMBER, new Address("127.0.0.1", 5701));
endpoints.put(EndpointQualifier.resolve(ProtocolType.WAN, "MyWAN"), new Address("127.0.0.1", 5901));
TimedMemberStateFactory factory = new TimedMemberStateFactory(getHazelcastInstanceImpl(hazelcastInstance));
TimedMemberState timedMemberState = factory.createTimedMemberState();
MemberStateImpl memberState = timedMemberState.getMemberState();
memberState.setAddress("memberStateAddress:Port");
UUID uuid = UUID.randomUUID();
memberState.setUuid(uuid);
UUID cpMemberUuid = UUID.randomUUID();
memberState.setCpMemberUuid(cpMemberUuid);
memberState.setEndpoints(endpoints);
memberState.setMapsWithStats(singleton("map-1"));
memberState.setMultiMapsWithStats(singleton("multiMap-1"));
memberState.setReplicatedMapsWithStats(singleton("replicatedMap-1"));
memberState.setQueuesWithStats(singleton("queue-1"));
memberState.setTopicsWithStats(singleton("topic-1"));
memberState.setReliableTopicsWithStats(singleton("reliableTopic-1"));
memberState.setPNCountersWithStats(singleton("pnCounter-1"));
memberState.setExecutorsWithStats(singleton("executor-1"));
memberState.setCachesWithStats(singleton("cache-1"));
memberState.setFlakeIdGeneratorsWithStats(singleton("flakeIdGenerator-1"));
memberState.setOperationStats(new LocalOperationStatsImpl());
memberState.setClients(clients);
memberState.setNodeState(state);
memberState.setHotRestartState(hotRestartState);
memberState.setClientStats(clientStats);
MemberStateImpl deserialized = new MemberStateImpl();
deserialized.fromJson(memberState.toJson());
assertEquals("memberStateAddress:Port", deserialized.getAddress());
assertEquals(uuid, deserialized.getUuid());
assertEquals(cpMemberUuid, deserialized.getCpMemberUuid());
assertEquals(endpoints, deserialized.getEndpoints());
assertNotNull(deserialized.getName());
assertEquals(deserialized.getName(), memberState.getName());
assertEquals(singleton("map-1"), deserialized.getMapsWithStats());
assertEquals(singleton("multiMap-1"), deserialized.getMultiMapsWithStats());
assertEquals(singleton("replicatedMap-1"), deserialized.getReplicatedMapsWithStats());
assertEquals(singleton("queue-1"), deserialized.getQueuesWithStats());
assertEquals(singleton("topic-1"), deserialized.getTopicsWithStats());
assertEquals(singleton("reliableTopic-1"), deserialized.getReliableTopicsWithStats());
assertEquals(singleton("pnCounter-1"), deserialized.getPNCountersWithStats());
assertEquals(singleton("executor-1"), deserialized.getExecutorsWithStats());
assertEquals(singleton("cache-1"), deserialized.getCachesWithStats());
assertEquals(singleton("flakeIdGenerator-1"), deserialized.getFlakeIdGeneratorsWithStats());
assertNotNull(deserialized.getOperationStats());
client = deserialized.getClients().iterator().next();
assertEquals(clientUuid, client.uuid);
assertEquals("localhost", client.address);
assertEquals("undefined", client.clientType);
assertEquals("aClient", client.name);
assertContains(client.labels, "label");
assertEquals("10.176.167.34", client.ipAddress);
assertEquals("ip-10-176-167-34.ec2.internal", client.canonicalHostName);
NodeState deserializedState = deserialized.getNodeState();
assertEquals(clusterState, deserializedState.getClusterState());
assertEquals(nodeState, deserializedState.getNodeState());
assertEquals(clusterVersion, deserializedState.getClusterVersion());
assertEquals(memberVersion, deserializedState.getMemberVersion());
final HotRestartState deserializedHotRestartState = deserialized.getHotRestartState();
assertTrue(deserializedHotRestartState.isHotBackupEnabled());
assertEquals(backupTaskStatus, deserializedHotRestartState.getBackupTaskStatus());
assertEquals(backupDirectory, deserializedHotRestartState.getBackupDirectory());
ClusterHotRestartStatusDTO clusterHotRestartStatus = deserialized.getClusterHotRestartStatus();
assertEquals(FULL_RECOVERY_ONLY, clusterHotRestartStatus.getDataRecoveryPolicy());
assertEquals(ClusterHotRestartStatusDTO.ClusterHotRestartStatus.UNKNOWN, clusterHotRestartStatus.getHotRestartStatus());
assertEquals(-1, clusterHotRestartStatus.getRemainingValidationTimeMillis());
assertEquals(-1, clusterHotRestartStatus.getRemainingDataLoadTimeMillis());
assertTrue(clusterHotRestartStatus.getMemberHotRestartStatusMap().isEmpty());
Map<UUID, String> deserializedClientStats = deserialized.getClientStats();
assertEquals("someStats", deserializedClientStats.get(clientUuid));
}
Aggregations