This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from spotify/rculbertson/test-helios-on-helios
Added integration test which uses TempJobs
- Loading branch information
Showing
22 changed files
with
272 additions
and
14 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
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
99 changes: 99 additions & 0 deletions
99
helios-integration-tests/src/test/java/com/spotify/helios/HeliosIT.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,99 @@ | ||
package com.spotify.helios; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.spotify.helios.Utils.AgentStatusProber; | ||
import com.spotify.helios.common.protocol.CreateJobResponse; | ||
import com.spotify.helios.common.protocol.JobDeleteResponse; | ||
import com.spotify.helios.common.protocol.JobDeployResponse; | ||
import com.spotify.helios.common.protocol.JobUndeployResponse; | ||
import com.spotify.helios.testing.TemporaryJob; | ||
import com.spotify.helios.testing.TemporaryJobBuilder; | ||
import com.spotify.helios.testing.TemporaryJobs; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static com.spotify.helios.Utils.agentImage; | ||
import static com.spotify.helios.Utils.masterImage; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class HeliosIT { | ||
|
||
@Rule | ||
public final TemporaryJobs temporaryJobs = TemporaryJobs.create(); | ||
|
||
private static final String TEST_USER = "HeliosIT"; | ||
private static final String TEST_HOST = "test-host"; | ||
|
||
private String masterEndpoint; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
// zookeeper | ||
final TemporaryJob zk = temporaryJobs.job() | ||
.image("jplock/zookeeper:3.4.5") | ||
.port("zk", 2181) | ||
.deploy(); | ||
|
||
final String zkEndpoint = zk.address("zk").toString(); | ||
|
||
// helios master | ||
final TemporaryJob master = temporaryJobs.job() | ||
.image(masterImage()) | ||
.port("helios", 5801) | ||
.command("--zk", zkEndpoint) | ||
.deploy(); | ||
|
||
masterEndpoint = "http://" + master.address("helios").toString(); | ||
|
||
final ImmutableList.Builder<String> args = new ImmutableList.Builder<String>() | ||
.add("--zk") | ||
.add(zkEndpoint) | ||
.add("--docker") | ||
.add(System.getenv("DOCKER_HOST")) | ||
.add("--name") | ||
.add(TEST_HOST); | ||
|
||
final String certPath = System.getenv("DOCKER_CERT_PATH"); | ||
if (certPath != null) { | ||
args.add("--docker-cert-path=/certs"); | ||
} | ||
|
||
// helios agent | ||
final TemporaryJobBuilder agent = temporaryJobs.job() | ||
.image(agentImage()) | ||
.prober(new AgentStatusProber(masterEndpoint, TEST_USER, TEST_HOST)) | ||
.port("agent", 8080) // need to expose fake port just so prober gets invoked | ||
.command(args.build()); | ||
|
||
if (certPath != null) { | ||
agent.volume("/certs", certPath); | ||
} | ||
|
||
agent.deploy(); | ||
} | ||
|
||
@Test | ||
public void test() throws Exception { | ||
final CreateJobResponse create = cli(CreateJobResponse.class, "create", "test:1", "busybox"); | ||
assertThat(create.getStatus(), equalTo(CreateJobResponse.Status.OK)); | ||
|
||
final JobDeployResponse deploy = cli(JobDeployResponse.class, "deploy", "test:1", TEST_HOST); | ||
assertThat(deploy.getStatus(), equalTo(JobDeployResponse.Status.OK)); | ||
|
||
final JobUndeployResponse undeploy = cli(JobUndeployResponse.class, | ||
"undeploy", "--yes", "test:1", "-a"); | ||
assertThat(undeploy.getStatus(), equalTo(JobUndeployResponse.Status.OK)); | ||
|
||
final JobDeleteResponse delete = cli(JobDeleteResponse.class, "remove", "--yes", "test:1"); | ||
assertThat(delete.getStatus(), equalTo(JobDeleteResponse.Status.OK)); | ||
} | ||
|
||
private <T> T cli(final Class<T> klass, final String... args) throws Exception { | ||
return Utils.cli(klass, masterEndpoint, args); | ||
} | ||
|
||
} |
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
100 changes: 100 additions & 0 deletions
100
helios-integration-tests/src/test/java/com/spotify/helios/Utils.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,100 @@ | ||
package com.spotify.helios; | ||
|
||
import com.google.common.base.Throwables; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.spotify.helios.cli.CliMain; | ||
import com.spotify.helios.client.HeliosClient; | ||
import com.spotify.helios.common.Json; | ||
import com.spotify.helios.common.descriptors.HostStatus; | ||
import com.spotify.helios.testing.Prober; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import static com.fasterxml.jackson.databind.node.JsonNodeType.STRING; | ||
import static java.util.Arrays.asList; | ||
|
||
public class Utils { | ||
|
||
public static final String DEFAULT_IMAGE_INFO_PATH = "../helios-services/target/test-classes/"; | ||
|
||
public static <T> T cli(final Class<T> klass, final String masterEndpoint, final String... args) | ||
throws Exception { | ||
return cli(klass, masterEndpoint, asList(args)); | ||
} | ||
|
||
private static <T> T cli(final Class<T> klass, final String masterEndpoint, | ||
final List<String> args) throws Exception { | ||
final ImmutableList<String> argList = new ImmutableList.Builder<String>() | ||
.add("-z") | ||
.add(masterEndpoint) | ||
.add("--json") | ||
.addAll(args) | ||
.build(); | ||
|
||
return Json.read(main(argList).toString(), klass); | ||
} | ||
|
||
public static ByteArrayOutputStream main(final List<String> args) throws Exception { | ||
final ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
final ByteArrayOutputStream err = new ByteArrayOutputStream(); | ||
final CliMain main = new CliMain(new PrintStream(out), new PrintStream(err), | ||
args.toArray(new String[args.size()])); | ||
main.run(); | ||
return out; | ||
} | ||
|
||
public static String masterImage() throws IOException { | ||
final String path = System.getProperty("masterImage", | ||
DEFAULT_IMAGE_INFO_PATH + "master-image.json"); | ||
return imageInfo(path); | ||
} | ||
|
||
public static String agentImage() throws IOException { | ||
final String path = System.getProperty("agentImage", | ||
DEFAULT_IMAGE_INFO_PATH + "agent-image.json"); | ||
return imageInfo(path); | ||
} | ||
|
||
private static String imageInfo(final String path) throws IOException { | ||
final String json = new String(Files.readAllBytes(Paths.get(path))); | ||
final JsonNode node = Json.readTree(json); | ||
final JsonNode imageNode = node.get("image"); | ||
return (imageNode == null || imageNode.getNodeType() != STRING) ? null : imageNode.asText(); | ||
} | ||
|
||
public static class AgentStatusProber implements Prober { | ||
|
||
private final HeliosClient client; | ||
private final String hostName; | ||
|
||
public AgentStatusProber(final String masterEndpoint, final String user, | ||
final String hostName) { | ||
this.hostName = hostName; | ||
client = HeliosClient.newBuilder() | ||
.setEndpoints(masterEndpoint) | ||
.setUser(user) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public boolean probe(String host, int port) { | ||
try { | ||
final HostStatus hostStatus = client.hostStatus(hostName).get(10, TimeUnit.SECONDS); | ||
return hostStatus != null && hostStatus.getStatus() == HostStatus.Status.UP; | ||
} catch (InterruptedException | ExecutionException | TimeoutException e) { | ||
throw Throwables.propagate(e); | ||
} | ||
} | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.