Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ComputeNodeInstance.getCurrentInstanceId() #31291

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public Map<String, InstanceMetaData> getAllClusterInstances(final InstanceType i
* @return compute node instance
*/
public Optional<ComputeNodeInstance> getComputeNodeInstanceById(final String instanceId) {
return allClusterInstances.stream().filter(each -> instanceId.equals(each.getCurrentInstanceId())).findFirst();
return allClusterInstances.stream().filter(each -> instanceId.equals(each.getMetaData().getId())).findFirst();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ private void registerOnline(final EventBusContext eventBusContext, final Instanc
final ClusterPersistRepository repository, final ContextManagerBuilderParameter param, final ContextManager contextManager) {
ComputeNodeStatusService computeNodeStatusService = new ComputeNodeStatusService(repository);
computeNodeStatusService.registerOnline(instanceContext.getInstance().getMetaData());
computeNodeStatusService.persistInstanceLabels(instanceContext.getInstance().getCurrentInstanceId(), instanceContext.getInstance().getLabels());
computeNodeStatusService.persistInstanceState(instanceContext.getInstance().getCurrentInstanceId(), instanceContext.getInstance().getState());
computeNodeStatusService.persistInstanceLabels(instanceContext.getInstance().getMetaData().getId(), instanceContext.getInstance().getLabels());
computeNodeStatusService.persistInstanceState(instanceContext.getInstance().getMetaData().getId(), instanceContext.getInstance().getState());
new GovernanceWatcherFactory(repository,
eventBusContext, param.getInstanceMetaData() instanceof JDBCInstanceMetaData ? param.getDatabaseConfigs().keySet() : Collections.emptyList()).watchListeners();
contextManager.getInstanceContext().getInstance().setLabels(param.getLabels());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void stateChanged(final CuratorFramework client, final ConnectionState co
do {
isReconnectFailed = !reconnect(client);
} while (isReconnectFailed);
log.info("Instance reconnect success, instance ID: {}", instanceContext.getInstance().getCurrentInstanceId());
log.info("Instance reconnect success, instance ID: {}", instanceContext.getInstance().getMetaData().getId());
}

private boolean reconnect(final CuratorFramework client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public Collection<LocalDataQueryResultRow> getRows(final ExportMetaDataStatement
if (sqlStatement.getFilePath().isPresent()) {
String filePath = sqlStatement.getFilePath().get();
ExportUtils.exportToFile(filePath, exportedData);
return Collections.singleton(new LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getCurrentInstanceId(), LocalDateTime.now(),
return Collections.singleton(new LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getMetaData().getId(), LocalDateTime.now(),
String.format("Successfully exported to:'%s'", filePath)));
}
return Collections.singleton(new LocalDataQueryResultRow(
contextManager.getInstanceContext().getInstance().getCurrentInstanceId(), LocalDateTime.now(), Base64.encodeBase64String(exportedData.getBytes())));
contextManager.getInstanceContext().getInstance().getMetaData().getId(), LocalDateTime.now(), Base64.encodeBase64String(exportedData.getBytes())));
}

private String generateExportData(final ShardingSphereMetaData metaData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public Collection<LocalDataQueryResultRow> getRows(final ExportStorageNodesState
if (sqlStatement.getFilePath().isPresent()) {
String filePath = sqlStatement.getFilePath().get();
ExportUtils.exportToFile(filePath, exportedData);
return Collections.singleton(new LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getCurrentInstanceId(), LocalDateTime.now(),
return Collections.singleton(new LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getMetaData().getId(), LocalDateTime.now(),
String.format("Successfully exported to:'%s'", filePath)));
}
return Collections.singleton(
new LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getCurrentInstanceId(), LocalDateTime.now(), exportedData));
new LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getMetaData().getId(), LocalDateTime.now(), exportedData));
}

private void checkSQLStatement(final ShardingSphereMetaData metaData, final ExportStorageNodesStatement sqlStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void checkEnablingIsValid(final ContextManager contextManager, final Str
}

private void checkDisablingIsValid(final ContextManager contextManager, final String instanceId) {
ShardingSpherePreconditions.checkState(!contextManager.getInstanceContext().getInstance().getCurrentInstanceId().equals(instanceId),
ShardingSpherePreconditions.checkState(!contextManager.getInstanceContext().getInstance().getMetaData().getId().equals(instanceId),
() -> new UnsupportedSQLOperationException(String.format("`%s` is the currently in use instance and cannot be disabled", instanceId)));
ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().getComputeNodeInstanceById(instanceId).isPresent(),
() -> new UnsupportedSQLOperationException(String.format("`%s` does not exist", instanceId)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ void assertExecuteUpdateWithNotExistsInstanceID() {
@Test
void assertExecuteUpdateWithCurrentUsingInstance() {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getInstanceContext().getInstance().getCurrentInstanceId()).thenReturn("instanceID");
when(contextManager.getInstanceContext().getInstance().getMetaData().getId()).thenReturn("instanceID");
assertThrows(UnsupportedSQLOperationException.class, () -> executor.executeUpdate(new SetInstanceStatusStatement("DISABLE", "instanceID"), contextManager));
}

@Test
void assertExecuteUpdateWithAlreadyDisableInstance() {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getInstanceContext().getInstance().getCurrentInstanceId()).thenReturn("currentInstance");
when(contextManager.getInstanceContext().getInstance().getMetaData().getId()).thenReturn("currentInstance");
when(contextManager.getInstanceContext().getComputeNodeInstanceById("instanceID").isPresent()).thenReturn(true);
when(contextManager.getInstanceContext().getComputeNodeInstanceById("instanceID").get().getState().getCurrentState()).thenReturn(InstanceState.CIRCUIT_BREAK);
assertThrows(UnsupportedSQLOperationException.class, () -> executor.executeUpdate(new SetInstanceStatusStatement("DISABLE", "instanceID"), contextManager));
Expand Down
Loading