Skip to content

Commit

Permalink
Sidecar tags tests (#13502)
Browse files Browse the repository at this point in the history
* Only assign tagged configs that match the OS

* rename test

* add tests for SidecarService.updateTaggedConfigurationAssignments()

* add tests for SidecarService.applyManualAssignments()
  • Loading branch information
mpfz0r authored and gally47 committed Sep 29, 2022
1 parent c487933 commit 275c6b9
Show file tree
Hide file tree
Showing 5 changed files with 405 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ public Sidecar updateTaggedConfigurationAssignments(Sidecar sidecar) {
final Set<String> sidecarTags = sidecar.nodeDetails().tags();

// find all configurations that match the tags
// TODO only find configs that match the right collector os
final List<Configuration> taggedConfigs = configurationService.findByTags(sidecarTags);
final Set<String> matchingOsCollectorIds = collectorService.all().stream()
.filter(c -> c.nodeOperatingSystem().equalsIgnoreCase(sidecar.nodeDetails().operatingSystem()))
.map(Collector::id).collect(Collectors.toSet());

final List<ConfigurationAssignment> tagAssigned = taggedConfigs.stream().map(c -> {
final List<ConfigurationAssignment> tagAssigned = taggedConfigs.stream()
.filter(c -> matchingOsCollectorIds.contains(c.collectorId())).map(c -> {
// fill in ConfigurationAssignment.assignedFromTags()
// If we only support one tag on a configuration, this can be simplified
final Set<String> matchedTags = c.tags().stream().filter(sidecarTags::contains).collect(Collectors.toSet());
Expand Down Expand Up @@ -233,10 +236,10 @@ public Sidecar fromRequest(String nodeId, RegistrationRequest request, String co
collectorVersion);
}

public Sidecar applyManualAssignments(String collectorNodeId, List<ConfigurationAssignment> assignments) throws NotFoundException{
Sidecar sidecar = findByNodeId(collectorNodeId);
public Sidecar applyManualAssignments(String sidecarNodeId, List<ConfigurationAssignment> assignments) throws NotFoundException{
Sidecar sidecar = findByNodeId(sidecarNodeId);
if (sidecar == null) {
throw new NotFoundException("Couldn't find collector with ID " + collectorNodeId);
throw new NotFoundException("Couldn't find sidecar with nodeId " + sidecarNodeId);
}
for (ConfigurationAssignment assignment : assignments) {
Collector collector = collectorService.find(assignment.collectorId());
Expand Down

This file was deleted.

Loading

0 comments on commit 275c6b9

Please sign in to comment.