use of io.mycat.replica.ReplicaSwitchType in project Mycat2 by MyCATApache.
the class HintHandler method showClusters.
public static RowBaseIterator showClusters(String clusterName) {
MycatRouterConfig routerConfig = MetaClusterCurrent.wrapper(MycatRouterConfig.class);
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("NAME", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("SWITCH_TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MAX_REQUEST_COUNT", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("WRITE_DS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("READ_DS", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("WRITE_L", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("READ_L", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("AVAILABLE", JDBCType.VARCHAR);
Collection<ReplicaSelector> values = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class).getReplicaMap().values();
Map<String, ClusterConfig> clusterConfigMap = routerConfig.getClusters().stream().collect(Collectors.toMap(k -> k.getName(), v -> v));
for (ReplicaSelector value : values.stream().filter(v -> {
if (clusterName != null) {
return clusterName.equalsIgnoreCase(v.getName());
}
return true;
}).collect(Collectors.toList())) {
String NAME = value.getName();
Optional<ClusterConfig> e = Optional.ofNullable(clusterConfigMap.get(NAME));
ReplicaSwitchType SWITCH_TYPE = value.getSwitchType();
int MAX_REQUEST_COUNT = value.maxRequestCount();
String TYPE = value.getBalanceType().name();
String WRITE_DS = ((List<PhysicsInstance>) value.getWriteDataSourceByReplicaType()).stream().map(i -> i.getName()).collect(Collectors.joining(","));
String READ_DS = (value.getReadDataSourceByReplica()).stream().map(i -> i.getName()).collect(Collectors.joining(","));
String WL = Optional.ofNullable(value.getDefaultWriteLoadBalanceStrategy()).map(i -> i.getClass().getName()).orElse(null);
String RL = Optional.ofNullable(value.getDefaultReadLoadBalanceStrategy()).map(i -> i.getClass().getName()).orElse(null);
String AVAILABLE = Boolean.toString(((List<PhysicsInstance>) value.getWriteDataSourceByReplicaType()).stream().anyMatch(PhysicsInstance::isAlive));
resultSetBuilder.addObjectRowPayload(Arrays.asList(NAME, SWITCH_TYPE, MAX_REQUEST_COUNT, TYPE, WRITE_DS, READ_DS, WL, RL, AVAILABLE));
}
return resultSetBuilder.build();
}
Aggregations