-
-
Couldn't load subscription status.
- Fork 195
BE: KC: Added connect cluster info #1247
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
643d432
BE: Fixes #445 Added connect cluster info
germanosin 206f543
Added missed code
germanosin ca860d0
removed unused imports
germanosin f3f58f0
Fixed checkstyle
germanosin c3f98b0
Fixed checkstyle
germanosin d874a37
renamed field to camelCase
germanosin 52566a3
Merge branch 'main' into issues/445-clusterinfo
germanosin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
api/src/test/java/io/kafbat/ui/mapper/KafkaConnectMapperTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| package io.kafbat.ui.mapper; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import io.kafbat.ui.config.ClustersProperties; | ||
| import io.kafbat.ui.connect.model.ClusterInfo; | ||
| import io.kafbat.ui.model.ConnectDTO; | ||
| import io.kafbat.ui.model.ConnectorDTO; | ||
| import io.kafbat.ui.model.ConnectorStateDTO; | ||
| import io.kafbat.ui.model.ConnectorStatusDTO; | ||
| import io.kafbat.ui.model.ConnectorTaskStatusDTO; | ||
| import io.kafbat.ui.model.TaskDTO; | ||
| import io.kafbat.ui.model.TaskIdDTO; | ||
| import io.kafbat.ui.model.TaskStatusDTO; | ||
| import io.kafbat.ui.model.connect.InternalConnectorInfo; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openapitools.jackson.nullable.JsonNullable; | ||
|
|
||
| class KafkaConnectMapperTest { | ||
|
|
||
| @Test | ||
| void toKafkaConnect() { | ||
| ThreadLocalRandom random = ThreadLocalRandom.current(); | ||
|
|
||
| List<InternalConnectorInfo> connectors = new ArrayList<>(); | ||
| int failedConnectors = 0; | ||
| int failedTasks = 0; | ||
| int tasksPerConnector = random.nextInt(1, 10); | ||
|
|
||
| for (int i = 0; i < 10; i++) { | ||
| ConnectorStateDTO connectorState; | ||
| if (random.nextBoolean()) { | ||
| connectorState = ConnectorStateDTO.FAILED; | ||
| failedConnectors++; | ||
| } else { | ||
| connectorState = ConnectorStateDTO.RUNNING; | ||
| } | ||
|
|
||
| ConnectorDTO connectorDto = new ConnectorDTO(); | ||
| connectorDto.setName(UUID.randomUUID().toString()); | ||
| connectorDto.setStatus( | ||
| new ConnectorStatusDTO(connectorState, UUID.randomUUID().toString()) | ||
| ); | ||
|
|
||
| List<TaskDTO> tasks = new ArrayList<>(); | ||
| List<TaskIdDTO> taskIds = new ArrayList<>(); | ||
|
|
||
| for (int j = 0; j < tasksPerConnector; j++) { | ||
| TaskDTO task = new TaskDTO(); | ||
| TaskIdDTO taskId = new TaskIdDTO(UUID.randomUUID().toString(), j); | ||
| task.setId(taskId); | ||
|
|
||
| ConnectorTaskStatusDTO state; | ||
| if (random.nextBoolean()) { | ||
| state = ConnectorTaskStatusDTO.FAILED; | ||
| failedTasks++; | ||
| } else { | ||
| state = ConnectorTaskStatusDTO.RUNNING; | ||
| } | ||
|
|
||
| TaskStatusDTO status = new TaskStatusDTO(); | ||
| status.setState(state); | ||
| task.setStatus(status); | ||
| tasks.add(task); | ||
| taskIds.add(taskId); | ||
| } | ||
|
|
||
| connectorDto.setTasks(taskIds); | ||
| InternalConnectorInfo connector = InternalConnectorInfo.builder() | ||
| .connector(connectorDto) | ||
| .tasks(tasks) | ||
| .build(); | ||
|
|
||
| connectors.add(connector); | ||
| } | ||
|
|
||
| ClusterInfo clusterInfo = new ClusterInfo(); | ||
| clusterInfo.setVersion(UUID.randomUUID().toString()); | ||
| clusterInfo.setCommit(UUID.randomUUID().toString()); | ||
| clusterInfo.setKafkaClusterId(UUID.randomUUID().toString()); | ||
|
|
||
| ClustersProperties.ConnectCluster connectCluster = ClustersProperties.ConnectCluster.builder() | ||
| .name(UUID.randomUUID().toString()) | ||
| .address("http://localhost:" + random.nextInt(1000, 5000)) | ||
| .username(UUID.randomUUID().toString()) | ||
| .password(UUID.randomUUID().toString()).build(); | ||
|
|
||
| ConnectDTO connectDto = new ConnectDTO(); | ||
| connectDto.setName(connectCluster.getName()); | ||
| connectDto.setAddress(connectCluster.getAddress()); | ||
| connectDto.setVersion(JsonNullable.of(clusterInfo.getVersion())); | ||
| connectDto.setCommit(JsonNullable.of(clusterInfo.getCommit())); | ||
| connectDto.setClusterId(JsonNullable.of(clusterInfo.getKafkaClusterId())); | ||
| connectDto.setConnectorsCount(JsonNullable.of(connectors.size())); | ||
| connectDto.setFailedConnectorsCount(JsonNullable.of(failedConnectors)); | ||
| connectDto.setTasksCount(JsonNullable.of(connectors.size() * tasksPerConnector)); | ||
| connectDto.setFailedTasksCount(JsonNullable.of(failedTasks)); | ||
|
|
||
| KafkaConnectMapper mapper = new KafkaConnectMapperImpl(); | ||
| ConnectDTO kafkaConnect = mapper.toKafkaConnect( | ||
| connectCluster, | ||
| connectors, | ||
| clusterInfo, | ||
| true | ||
| ); | ||
|
|
||
| assertThat(kafkaConnect).isNotNull(); | ||
| assertThat(kafkaConnect).isEqualTo(connectDto); | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.