Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/coral/testing-librar…
Browse files Browse the repository at this point in the history
…y/jest-dom-6.1.4
  • Loading branch information
programmiri authored Nov 20, 2023
2 parents 8a64341 + 1b2bc6a commit 93afd25
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
16 changes: 9 additions & 7 deletions core/src/main/java/io/aiven/klaw/helpers/KlawResourceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import io.aiven.klaw.dao.Env;
import io.aiven.klaw.model.response.EnvIdInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class KlawResourceUtils {

private static final LinkedHashSet<String> EMPTY_LINKED_HASH_SET = new LinkedHashSet<>(0);

public static List<EnvIdInfo> getConvertedEnvs(
List<Env> allEnvs, Collection<String> selectedEnvs) {
List<EnvIdInfo> newEnvList = new ArrayList<>();
Expand All @@ -25,12 +29,10 @@ public static List<EnvIdInfo> getConvertedEnvs(
return newEnvList;
}

public static List<String> getOrderedEnvsList(String orderOfEnvs) {
List<String> orderOfEnvsArrayList = new ArrayList<>();
if (orderOfEnvs != null && !orderOfEnvs.equals("")) {
String[] orderOfEnvsList = orderOfEnvs.split(",");
orderOfEnvsArrayList = Arrays.asList(orderOfEnvsList);
public static LinkedHashSet<String> getOrderedEnvsSet(String orderOfEnvs) {
if (orderOfEnvs == null || orderOfEnvs.isEmpty()) {
return EMPTY_LINKED_HASH_SET;
}
return orderOfEnvsArrayList;
return Stream.of(orderOfEnvs.split(",")).collect(Collectors.toCollection(LinkedHashSet::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ private ConnectorOverview filterByEnvironment(
List<KwKafkaConnector> connectors, String envId, int tenantId) {
ConnectorOverview overview = new ConnectorOverview();
String orderOfEnvs = commonUtilsService.getEnvProperty(tenantId, ORDER_OF_KAFKA_CONNECT_ENVS);
List<String> orderOfEnvsArrayList = KlawResourceUtils.getOrderedEnvsList(orderOfEnvs);
Set<String> orderOfEnvsSet = KlawResourceUtils.getOrderedEnvsSet(orderOfEnvs);
List<EnvIdInfo> availableEnvs = new ArrayList<>();
List<EnvIdInfo> availableEnvsNotInPromotionOrder = new ArrayList<>();
connectors.forEach(
Expand All @@ -1238,7 +1238,7 @@ private ConnectorOverview filterByEnvironment(
.map(Env::getName)
.findFirst()
.orElse("ENV_NOT_FOUND"));
if (orderOfEnvsArrayList.contains(envIdInfo.getId())) {
if (orderOfEnvsSet.contains(envIdInfo.getId())) {
availableEnvs.add(envIdInfo);
} else {
availableEnvsNotInPromotionOrder.add(envIdInfo);
Expand Down
28 changes: 23 additions & 5 deletions core/src/main/java/io/aiven/klaw/service/TopicOverviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.aiven.klaw.model.response.TopicOverview;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -125,7 +126,7 @@ private Pair<String, List<Topic>> filterByEnvIdParameter(
List<EnvIdInfo> availableEnvs = new ArrayList<>();
List<EnvIdInfo> availableEnvsNotInPromotionOrder = new ArrayList<>();
String orderOfEnvs = commonUtilsService.getEnvProperty(tenantId, ORDER_OF_TOPIC_ENVS);
List<String> orderOfEnvsArrayList = KlawResourceUtils.getOrderedEnvsList(orderOfEnvs);
Set<String> orderOfEnvsSet = KlawResourceUtils.getOrderedEnvsSet(orderOfEnvs);
topics.forEach(
topic -> {
EnvIdInfo envIdInfo = new EnvIdInfo();
Expand All @@ -136,7 +137,7 @@ private Pair<String, List<Topic>> filterByEnvIdParameter(
.map(Env::getName)
.findFirst()
.orElse("ENV_NOT_FOUND"));
if (orderOfEnvsArrayList.contains(envIdInfo.getId())) {
if (orderOfEnvsSet.contains(envIdInfo.getId())) {
availableEnvs.add(envIdInfo);
} else {
availableEnvsNotInPromotionOrder.add(envIdInfo);
Expand Down Expand Up @@ -418,6 +419,22 @@ private boolean isSchemaRequestOpen(String topicName, String envId, int tenantId
.isPresent();
}

private <T> boolean checkIfElementsAreNeighbors(
LinkedHashSet<T> tLinkedHashSet, T element1, T element2) {
boolean foundFirst = false;
for (T elem : tLinkedHashSet) {
if (foundFirst && elem.equals(element2)) {
return true;
} else {
foundFirst = false;
}
if (elem.equals(element1)) {
foundFirst = true;
}
}
return false;
}

private PromotionStatus getTopicPromotionEnv(
String topicSearch, List<Topic> topics, int tenantId, String environmentId) {
PromotionStatus promotionStatus = new PromotionStatus();
Expand All @@ -427,7 +444,7 @@ private PromotionStatus getTopicPromotionEnv(
}
promotionStatus.setTopicName(topicSearch);
String orderEnvs = commonUtilsService.getEnvProperty(tenantId, ORDER_OF_TOPIC_ENVS);
List<String> envOrderList = KlawResourceUtils.getOrderedEnvsList(orderEnvs);
LinkedHashSet<String> orderedEnvsSet = KlawResourceUtils.getOrderedEnvsSet(orderEnvs);

if (topics != null && topics.size() > 0) {
List<String> envList =
Expand All @@ -438,8 +455,9 @@ private PromotionStatus getTopicPromotionEnv(
// T env
if (promotionStatus.getTargetEnvId() != null) {
String targetEnvId = promotionStatus.getTargetEnvId();
if (!((envOrderList.indexOf(targetEnvId) - envOrderList.indexOf(environmentId)) == 1)
|| !envOrderList.contains(environmentId)) {
if (!orderedEnvsSet.contains(environmentId)
|| !orderedEnvsSet.contains(targetEnvId)
|| !checkIfElementsAreNeighbors(orderedEnvsSet, environmentId, targetEnvId)) {
promotionStatus.setStatus(PromotionStatusType.NO_PROMOTION);
} else if (isTopicPromoteRequestOpen(
topicSearch, promotionStatus.getTargetEnvId(), tenantId)) {
Expand Down

0 comments on commit 93afd25

Please sign in to comment.