Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Add ServiceTags in checks #272

Merged
merged 1 commit into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/com/orbitz/consul/model/agent/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import org.immutables.value.Value;

import java.util.List;

import static com.google.common.base.Preconditions.checkState;

@Value.Immutable
Expand Down Expand Up @@ -45,6 +48,10 @@ public abstract class Check {
@JsonProperty("ServiceID")
public abstract Optional<String> getServiceId();

@JsonProperty("ServiceTags")
@JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
public abstract List<String> getServiceTags();

@JsonProperty("DeregisterCriticalServiceAfter")
public abstract Optional<String> getDeregisterCriticalServiceAfter();

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/orbitz/consul/model/health/HealthCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import org.immutables.value.Value;

import java.util.List;

@Value.Immutable
@JsonSerialize(as = ImmutableHealthCheck.class)
@JsonDeserialize(as = ImmutableHealthCheck.class)
Expand Down Expand Up @@ -37,4 +40,8 @@ public abstract class HealthCheck {
@JsonProperty("ServiceName")
public abstract Optional<String> getServiceName();

@JsonProperty("ServiceTags")
@JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
public abstract List<String> getServiceTags();

}
27 changes: 26 additions & 1 deletion src/test/java/com/orbitz/consul/model/agent/CheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import org.junit.Test;

import java.util.Collections;

import static org.junit.Assert.assertEquals;

public class CheckTest {

@Test(expected = IllegalStateException.class)
Expand Down Expand Up @@ -33,4 +37,25 @@ public void testCheckIntervalScript() throws Exception {
.name("name")
.build();
}
}

@Test
public void serviceTagsAreNotNullWhenNotSpecified() {
Check check = ImmutableCheck.builder()
.name("name")
.id("id")
.build();

assertEquals(Collections.emptyList(), check.getServiceTags());
}

@Test
public void serviceTagsCanBeAddedToCheck() {
Check check = ImmutableCheck.builder()
.name("name")
.id("id")
.addServiceTags("myTag")
.build();

assertEquals(Collections.singletonList("myTag"), check.getServiceTags());
}
}
35 changes: 35 additions & 0 deletions src/test/java/com/orbitz/consul/model/health/HealthCheckTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.orbitz.consul.model.health;

import org.junit.Test;

import java.util.Collections;

import static org.junit.Assert.assertEquals;

public class HealthCheckTest {

@Test
public void serviceTagsAreNotNullWhenNotSpecified() {
HealthCheck check = ImmutableHealthCheck.builder()
.name("name")
.node("node")
.checkId("id")
.status("passing")
.build();

assertEquals(Collections.emptyList(), check.getServiceTags());
}

@Test
public void serviceTagsCanBeAddedToHealthCheck() {
HealthCheck check = ImmutableHealthCheck.builder()
.name("name")
.node("node")
.checkId("id")
.status("passing")
.addServiceTags("myTag")
.build();

assertEquals(Collections.singletonList("myTag"), check.getServiceTags());
}
}