use of io.mycat.config.MycatRouterConfig in project Mycat2 by MyCATApache.
the class MigrateUtil method read.
@SneakyThrows
public static Flowable<Object[]> read(MigrateUtil.MigrateJdbcInput migrateJdbcInput, Partition backend) {
MycatRouterConfig routerConfig = MetaClusterCurrent.wrapper(MycatRouterConfig.class);
ReplicaSelectorManager replicaSelectorRuntime = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class);
String targetName = backend.getTargetName();
String tableName = backend.getTable();
String schemaName = backend.getSchema();
String datasourceName = replicaSelectorRuntime.getDatasourceNameByReplicaName(targetName, true, null);
List<DatasourceConfig> datasources = routerConfig.getDatasources();
DatasourceConfig datasourceConfig = datasources.stream().filter(i -> i.getName().equals(datasourceName)).findFirst().orElseThrow((Supplier<Throwable>) () -> {
MycatException mycatException = new MycatException("can not found datasource " + datasourceName);
LOGGER.error("", mycatException);
return mycatException;
});
return read(migrateJdbcInput, tableName, schemaName, datasourceConfig.getUrl(), datasourceConfig.getUser(), datasourceConfig.getPassword());
}
use of io.mycat.config.MycatRouterConfig in project Mycat2 by MyCATApache.
the class RWEntry method snapshot.
public static RWEntryMap snapshot() {
if ((!MetaClusterCurrent.exist(ReplicaSelectorManager.class)) || (!MetaClusterCurrent.exist(MycatRouterConfig.class))) {
return new RWEntryMap();
}
ReplicaSelectorManager replicaSelectorManager = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class);
MycatRouterConfig routerConfig = MetaClusterCurrent.wrapper(MycatRouterConfig.class);
Map<String, ClusterConfig> clusterConfigMap = routerConfig.getClusters().stream().collect(Collectors.toMap(k -> k.getName(), v -> v));
Map<String, ReplicaSelector> replicaMap = replicaSelectorManager.getReplicaMap();
Map<String, RWEntry> rwEntryMap = new HashMap<>();
for (Map.Entry<String, Entry> entry : map.entrySet()) {
String name = entry.getKey();
Entry value = entry.getValue();
// //////////////////////////////////////////////////////////////
boolean status = false;
ReplicaSelector replicaSelector = replicaMap.get(name);
if (replicaSelector != null) {
ClusterConfig clusterConfig = clusterConfigMap.get(replicaSelector.getName());
List<String> dsNames = (List) ImmutableList.builder().addAll(clusterConfig.getMasters()).addAll(clusterConfig.getReplicas()).build().stream().distinct().collect(Collectors.toList());
int i = 0;
for (; i < dsNames.size(); i++) {
String dsName = dsNames.get(i);
PhysicsInstance physicsInstance = replicaSelector.getRawDataSourceMap().get(dsName);
if (physicsInstance == null) {
break;
} else {
if (!physicsInstance.isAlive()) {
break;
}
}
}
status = i == dsNames.size();
} else {
status = false;
}
rwEntryMap.put(name, new RWEntry(value.MASTER.get(), value.SLAVE.get(), status));
}
RWEntryMap res = new RWEntryMap();
res.rwMap = rwEntryMap;
return res;
}
Aggregations