-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XENOPS-983] Add postprocessor that forces tags on all services
- Loading branch information
1 parent
b4736a0
commit 8a2581d
Showing
8 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
75 changes: 75 additions & 0 deletions
75
nuntio-app/src/test/java/eu/xenit/nuntio/integtest/ContainerForceTagsTest.java
This file contains 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,75 @@ | ||
package eu.xenit.nuntio.integtest; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
||
import com.ecwid.consul.v1.ConsulClient; | ||
import com.ecwid.consul.v1.catalog.CatalogServiceRequest; | ||
import com.github.dockerjava.api.DockerClient; | ||
import com.github.dockerjava.api.command.CreateContainerResponse; | ||
import com.github.dockerjava.api.model.ExposedPort; | ||
import com.github.dockerjava.api.model.Ports.Binding; | ||
import eu.xenit.nuntio.integtest.containers.NuntioContainer; | ||
import eu.xenit.nuntio.integtest.containers.RegistratorContainer; | ||
import eu.xenit.nuntio.integtest.jupiter.annotations.CompatTest; | ||
import eu.xenit.nuntio.integtest.jupiter.annotations.ContainerTests; | ||
import eu.xenit.nuntio.integtest.util.SimpleContainerModifier; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@Testcontainers | ||
@ContainerTests | ||
public class ContainerForceTagsTest extends ContainerBaseTest { | ||
|
||
private NuntioContainer nuntio = new NuntioContainer() | ||
.withNetwork(network) | ||
.withConsulContainer(consulContainer) | ||
.withDindContainer(dindContainer) | ||
.withRegistratorCompat(true) | ||
.withForcedTags(Set.of("tag1", "tag2")); | ||
|
||
private RegistratorContainer registrator = new RegistratorContainer() | ||
.withNetwork(network) | ||
.withConsulContainer(consulContainer) | ||
.withDindContainer(dindContainer) | ||
.withForcedTags(Set.of("tag1", "tag2")); | ||
|
||
@CompatTest | ||
void forceAdditionalTags(DockerClient dockerClient, ConsulClient consulClient) { | ||
CreateContainerResponse myService = createContainer( | ||
SimpleContainerModifier.withPortBinding(ExposedPort.tcp(123), Binding.bindIp("127.0.0.1")) | ||
.andThen(SimpleContainerModifier.withLabel("SERVICE_NAME", "myService")) | ||
.andThen(SimpleContainerModifier.withLabel("SERVICE_TAGS", "mytag,tag2")) | ||
); | ||
|
||
dockerClient.startContainerCmd(myService.getId()).exec(); | ||
|
||
await.until(consulWaiter().serviceExists("myService")); | ||
|
||
var services = consulClient.getCatalogService("myService", CatalogServiceRequest.newBuilder().build()).getValue(); | ||
|
||
assertThat(services, hasSize(1)); | ||
|
||
assertThat(new HashSet<>(services.get(0).getServiceTags()), containsInAnyOrder("mytag", "tag1", "tag2")); | ||
} | ||
|
||
@CompatTest | ||
void forceTags(DockerClient dockerClient, ConsulClient consulClient) { | ||
CreateContainerResponse myService = createContainer( | ||
SimpleContainerModifier.withPortBinding(ExposedPort.tcp(123), Binding.bindIp("127.0.0.1")) | ||
.andThen(SimpleContainerModifier.withLabel("SERVICE_NAME", "myService")) | ||
); | ||
|
||
dockerClient.startContainerCmd(myService.getId()).exec(); | ||
|
||
await.until(consulWaiter().serviceExists("myService")); | ||
|
||
var services = consulClient.getCatalogService("myService", CatalogServiceRequest.newBuilder().build()).getValue(); | ||
|
||
assertThat(services, hasSize(1)); | ||
|
||
assertThat(services.get(0).getServiceTags(), containsInAnyOrder("tag1", "tag2")); | ||
} | ||
} |
This file contains 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 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 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 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 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
22 changes: 22 additions & 0 deletions
22
nuntio-engine/src/main/java/eu/xenit/nuntio/engine/postprocessor/ForceTagsPostProcessor.java
This file contains 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,22 @@ | ||
package eu.xenit.nuntio.engine.postprocessor; | ||
|
||
import eu.xenit.nuntio.api.platform.PlatformServiceConfiguration; | ||
import eu.xenit.nuntio.api.platform.PlatformServiceDescription; | ||
import eu.xenit.nuntio.api.postprocessor.PlatformServicePostProcessor; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public class ForceTagsPostProcessor implements PlatformServicePostProcessor { | ||
private final Set<String> tags; | ||
|
||
@Override | ||
public Stream<PlatformServiceConfiguration> process(PlatformServiceDescription serviceDescription, | ||
PlatformServiceConfiguration serviceConfiguration) { | ||
Set<String> newTags = new HashSet<>(serviceConfiguration.getServiceTags()); | ||
newTags.addAll(tags); | ||
return Stream.of(serviceConfiguration.toBuilder().serviceTags(newTags).build()); | ||
} | ||
} |