Package com.spotify.helios.client

Examples of com.spotify.helios.client.HeliosClient$Response


  public void deleteAttachment(ERS3Attachment attachment)
      throws MalformedURLException, IOException {
    AWSAuthConnection conn = attachment.awsConnection();
    String bucket = attachment.bucket();
    String key = attachment.key();
    Response response = conn.delete(bucket, key, null);
    if (failed(response)) {
      throw new IOException("Failed to delete '" + bucket + "/" + key
          + "' to S3: Error " + response.connection.getResponseCode()
          + ": " + response.connection.getResponseMessage());
    }
View Full Code Here


          headers.put("Content-Disposition", Arrays
              .asList(new String[] { "attachment; filename="
                  + originalFileName }));
        }

        Response response = conn.putStream(bucket, key,
            attachmentStreamObject, headers);
        if (failed(response)) {
          throw new IOException("Failed to write '" + bucket + "/"
              + key + "' to S3: Error "
              + response.connection.getResponseCode() + ": "
View Full Code Here

    try {
      send_raw(q.build().toByteArray());
    } catch (IOException ex) {
      throw new RqlDriverException(ex.getMessage());
    }
    Response rsp = get();

    // For this version we only support success :-(
    switch(rsp.getType()) {
    case SUCCESS_ATOM:
    case SUCCESS_SEQUENCE:
    case SUCCESS_PARTIAL:
      return new RqlCursor(this,rsp);
    case CLIENT_ERROR:
    case COMPILE_ERROR:
    case RUNTIME_ERROR:
    default:
      throw new RqlDriverException(rsp.toString());             
    }             
  }
View Full Code Here

  @Test
  public void test() throws Exception {

    startDefaultMasterDontWaitForZK(new MockCuratorClientFactory(), "--zk-connection-timeout", "1");

    final HeliosClient client = defaultClient();

    try {
      final String result = client.listMasters().get().get(0);

      fail("Exception should have been thrown, as ZK doesnt exist - got " + result);

    } catch (ExecutionException e) {
      assertTrue(e.getCause() instanceof HeliosException);
View Full Code Here

  @Test
  public void test() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());

    final HeliosClient client = defaultClient();

    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);

    JobId jobId = createJob(testJobName, testJobVersion, "this_sould_not_exist",
                            ImmutableList.of("/bin/true"));

    deployJob(jobId, testHost());
    awaitJobThrottle(client, testHost(), jobId, IMAGE_MISSING, LONG_WAIT_SECONDS, SECONDS);

    final HostStatus hostStatus = client.hostStatus(testHost()).get();
    final TaskStatus taskStatus = hostStatus.getStatuses().get(jobId);
    assertEquals(TaskStatus.State.FAILED, taskStatus.getState());
  }
View Full Code Here

    final Map<String, HostStatus> cliStatuses = new ObjectMapper().readValue(cli("hosts", "--json"),
        new TypeReference<Map<String, HostStatus>>(){});
    assertTrue("status must contain key for " + aHost, cliStatuses.containsKey(aHost));
    assertTrue("status must contain key for " + bHost, cliStatuses.containsKey(bHost));

    final HeliosClient client = defaultClient();
    final Map<String, HostStatus> clientStatuses = client.hostStatuses(
        ImmutableList.of(aHost, bHost)).get();

    assertTrue("status must contain key for " + aHost, clientStatuses.containsKey(aHost));
    assertTrue("status must contain key for " + bHost, clientStatuses.containsKey(bHost));
  }
View Full Code Here

  @Test
  public void test() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());

    final HeliosClient client = defaultClient();

    // Create a job using an image exposing port 11211 but without mapping it
    final Job job1 = Job.newBuilder()
        .setName(testTag + "memcached")
        .setVersion("v1")
        .setImage("rohan/memcached-mini")
        .build();
    final JobId jobId1 = job1.getId();
    client.createJob(job1).get();

    // Create a job using an image exposing port 11211 and map it to a specific external port
    final Job job2 = Job.newBuilder()
        .setName(testTag + "memcached")
        .setVersion("v2")
        .setImage("rohan/memcached-mini")
        .setPorts(ImmutableMap.of("tcp", PortMapping.of(11211, externalPort)))
        .build();
    final JobId jobId2 = job2.getId();
    client.createJob(job2).get();

    // Wait for agent to come up
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);

    // Deploy the jobs on the agent
    client.deploy(Deployment.of(jobId1, START), testHost()).get();
    client.deploy(Deployment.of(jobId2, START), testHost()).get();

    // Wait for the jobs to run
    awaitJobState(client, testHost(), jobId1, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    awaitJobState(client, testHost(), jobId2, RUNNING, LONG_WAIT_SECONDS, SECONDS);
  }
View Full Code Here

    final AgentMain agent1 = startDefaultAgent(testHost(), "--port-range=" +
                                                          portRange.lowerEndpoint() + ":" +
                                                          portRange.upperEndpoint());

    try (final DockerClient dockerClient = getNewDockerClient()) {
      final HeliosClient client = defaultClient();

      awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);

      final Map<String, PortMapping> ports1 =
          ImmutableMap.of("foo", PortMapping.of(4711),
                          "bar", PortMapping.of(4712, externalPort1));

      final ImmutableMap<String, PortMapping> expectedMapping1 =
          ImmutableMap.of("foo", PortMapping.of(4711, portRange.lowerEndpoint()),
                          "bar", PortMapping.of(4712, externalPort1));

      final Map<String, PortMapping> ports2 =
          ImmutableMap.of("foo", PortMapping.of(4711),
                          "bar", PortMapping.of(4712, externalPort2));

      final ImmutableMap<String, PortMapping> expectedMapping2 =
          ImmutableMap.of("foo", PortMapping.of(4711, portRange.lowerEndpoint() + 1),
                          "bar", PortMapping.of(4712, externalPort2));

      final JobId jobId1 = createJob(testJobName + 1, testJobVersion, BUSYBOX, IDLE_COMMAND,
                                     EMPTY_ENV, ports1);

      assertNotNull(jobId1);
      deployJob(jobId1, testHost());
      final TaskStatus firstTaskStatus1 = awaitJobState(client, testHost(), jobId1, RUNNING,
                                                        LONG_WAIT_SECONDS, SECONDS);

      final JobId jobId2 = createJob(testJobName + 2, testJobVersion, BUSYBOX, IDLE_COMMAND,
                                     EMPTY_ENV, ports2);

      assertNotNull(jobId2);
      deployJob(jobId2, testHost());
      final TaskStatus firstTaskStatus2 = awaitJobState(client, testHost(), jobId2, RUNNING,
                                                        LONG_WAIT_SECONDS, SECONDS);

      assertEquals(expectedMapping1, firstTaskStatus1.getPorts());
      assertEquals(expectedMapping2, firstTaskStatus2.getPorts());

      // TODO (dano): the supervisor should report the allocated ports at all times

      // Verify that port allocation is kept across container restarts
      dockerClient.killContainer(firstTaskStatus1.getContainerId());
      final TaskStatus restartedTaskStatus1 = Polling.await(
          LONG_WAIT_SECONDS, SECONDS, new Callable<TaskStatus>() {
        @Override
        public TaskStatus call() throws Exception {
          final HostStatus hostStatus = client.hostStatus(testHost()).get();
          final TaskStatus taskStatus = hostStatus.getStatuses().get(jobId1);
          return (taskStatus != null && taskStatus.getState() == RUNNING &&
                  !Objects.equals(taskStatus.getContainerId(), firstTaskStatus1.getContainerId()))
                 ? taskStatus : null;
        }
      });
      assertEquals(expectedMapping1, restartedTaskStatus1.getPorts());

      // Verify that port allocation is kept across agent restarts
      agent1.stopAsync().awaitTerminated();
      dockerClient.killContainer(firstTaskStatus2.getContainerId());
      startDefaultAgent(testHost());
      final TaskStatus restartedTaskStatus2 = Polling.await(
          LONG_WAIT_SECONDS, SECONDS, new Callable<TaskStatus>() {
        @Override
        public TaskStatus call() throws Exception {
          final HostStatus hostStatus = client.hostStatus(testHost()).get();
          final TaskStatus taskStatus = hostStatus.getStatuses().get(jobId2);
          return (taskStatus != null && taskStatus.getState() == RUNNING &&
                  !Objects.equals(taskStatus.getContainerId(), firstTaskStatus2.getContainerId()))
                 ? taskStatus : null;
        }
View Full Code Here

  @Test
  public void testMaster() throws Exception {
    startDefaultMaster("--zk-cluster-id=" + zkClusterId);

    final HeliosClient client = defaultClient();

    // This should succeed since the cluster ID was created by SystemTestBase
    client.jobs().get();

    // Delete the cluster ID
    zk().curator().delete().forPath(Paths.configId(zkClusterId));

    // Call jobs again, and this time it should throw an exception because the cluster ID is gone
    try {
      client.jobs().get();
    } catch (ExecutionException e) {
      assertThat(e.getMessage(), containsString("500"));
    }
  }
View Full Code Here

    startDefaultMaster();

    final String host = testHost();
    startDefaultAgent(host);

    final HeliosClient client = defaultClient();

    awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);

    // Note: signal 2 is SIGINT
    final Job jobToInterrupt = Job.newBuilder()
        .setName(testJobName)
        .setVersion(testJobVersion)
        .setImage(BUSYBOX)
        .setCommand(asList("/bin/sh", "-c", "trap handle 2; handle() { echo int; exit 0; }; "
                                            + "while true; do sleep 1; done"))
        .build();

    final JobId jobId = createJob(jobToInterrupt);
    deployJob(jobId, host);
    awaitTaskState(jobId, host, RUNNING);

    client.setGoal(new Deployment(jobId, Goal.STOP, Deployment.EMTPY_DEPLOYER_USER), host);

    final TaskStatus taskStatus = awaitTaskState(jobId, host, STOPPED);

    final String log;
    try (final DockerClient dockerClient = getNewDockerClient();
View Full Code Here

TOP

Related Classes of com.spotify.helios.client.HeliosClient$Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.