Skip to content

Commit

Permalink
fix: log in case policies are not consistent across VCPs
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Trieflinger <sven.trieflinger@de.bosch.com>
  • Loading branch information
strieflin committed Nov 13, 2024
1 parent 7bc1db2 commit ff1da62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
@NoArgsConstructor(force = true)

Check warning on line 19 in clients/java/src/main/java/io/carbynestack/thymus/client/PolicyResponse.java

View check run for this annotation

Codecov / codecov/patch

clients/java/src/main/java/io/carbynestack/thymus/client/PolicyResponse.java#L19

Added line #L19 was not covered by tests
public class PolicyResponse {

private static final Pattern POLICY_ID_PATTERN = Pattern.compile("stackable/bundles/([^/]+)/([^/]+)");
private static final Pattern POLICY_ID_PATTERN = Pattern.compile("([^/]+):([^/]+)");

String id;

Check warning on line 24 in clients/java/src/main/java/io/carbynestack/thymus/client/PolicyResponse.java

View check run for this annotation

Codecov / codecov/patch

clients/java/src/main/java/io/carbynestack/thymus/client/PolicyResponse.java#L24

Added line #L24 was not covered by tests

String raw;

Check warning on line 26 in clients/java/src/main/java/io/carbynestack/thymus/client/PolicyResponse.java

View check run for this annotation

Codecov / codecov/patch

clients/java/src/main/java/io/carbynestack/thymus/client/PolicyResponse.java#L26

Added line #L26 was not covered by tests

public PolicyResponse(Policy policy) {
this.id = "stackable/bundles/" + policy.getName().getNamespace() + "/" + policy.getName().getName();
this.id = policy.getName().getNamespace() + ":" + policy.getName().getName();
this.raw = policy.getSource();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ public Future<Either<ThymusError, Set<NamespacedName>>> getPolicies() {
return Future.sequence(invocations).map(results -> {
Set<ThymusError> errors = new HashSet<>();
Set<NamespacedName> commonPolicies = new HashSet<>();
Set<NamespacedName> allPolicies = new HashSet<>();
results.zipWithIndex().forEach(r -> {
val index = r._2;
val result = r._1;
if (result._2.isLeft()) {
// Collect all errors indexed by the endpoint
errors.add(result._2.getLeft());
} else {
allPolicies.addAll(result._2.get());

// Compute the intersection of all policies
if (index == 0) {
commonPolicies.addAll(result._2.get());
Expand All @@ -78,6 +81,10 @@ public Future<Either<ThymusError, Set<NamespacedName>>> getPolicies() {
}
}
});
if (commonPolicies.size() != allPolicies.size()) {
allPolicies.removeAll(commonPolicies);
log.debug("There are policies that are not common across all VCPs: {}", allPolicies);
}
if (!errors.isEmpty()) {
val me = new ThymusError.MultiError().setErrors(errors);
return Either.left(me);
Expand Down

0 comments on commit ff1da62

Please sign in to comment.