Ejemplo n.º 1
0
  @Test(enabled = true)
  public void testCreateAndRunAService() throws Exception {

    String group = this.group + "s";
    try {
      client.destroyNodesMatching(inGroup(group));
    } catch (Exception e) {

    }

    try {
      createAndRunAServiceInGroup(group);
    } finally {
      client.destroyNodesMatching(inGroup(group));
    }
  }
Ejemplo n.º 2
0
  @Test(enabled = true, dependsOnMethods = "testConcurrentUseOfComputeServiceToCreateNodes")
  public void testCreateTwoNodesWithRunScript() throws Exception {
    try {
      client.destroyNodesMatching(inGroup(group));
    } catch (NoSuchElementException e) {

    }
    refreshTemplate();
    try {
      nodes = newTreeSet(client.createNodesInGroup(group, 2, template));
    } catch (RunNodesException e) {
      nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
      throw e;
    }

    assertEquals(nodes.size(), 2, "expected two nodes but was " + nodes);
    checkNodes(nodes, group, "bootstrap");
    NodeMetadata node1 = nodes.first();
    NodeMetadata node2 = nodes.last();
    // credentials aren't always the same
    // assertEquals(node1.getCredentials(), node2.getCredentials());

    assertLocationSameOrChild(
        checkNotNull(node1.getLocation(), "location of %s", node1), template.getLocation());
    assertLocationSameOrChild(
        checkNotNull(node2.getLocation(), "location of %s", node2), template.getLocation());
    checkImageIdMatchesTemplate(node1);
    checkImageIdMatchesTemplate(node2);
    checkOsMatchesTemplate(node1);
    checkOsMatchesTemplate(node2);
  }
Ejemplo n.º 3
0
  public void testOptionToNotBlock() throws Exception {
    String group = this.group + "block";
    try {
      client.destroyNodesMatching(inGroup(group));
    } catch (Exception e) {

    }
    // no inbound ports
    template = buildTemplate(client.templateBuilder());
    template.getOptions().blockUntilRunning(false).inboundPorts();
    try {
      long time = currentTimeMillis();
      Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
      NodeMetadata node = getOnlyElement(nodes);
      assert node.getStatus() != Status.RUNNING : node;
      long duration = (currentTimeMillis() - time) / 1000;
      assert duration < nonBlockDurationSeconds
          : format(
              "duration(%d) longer than expected(%d) seconds! ", duration, nonBlockDurationSeconds);
    } finally {
      client.destroyNodesMatching(inGroup(group));
    }
  }
Ejemplo n.º 4
0
 @Test(
     enabled = true,
     dependsOnMethods = {"testListNodes", "testGetNodesWithDetails", "testListNodesByIds"})
 public void testDestroyNodes() {
   int toDestroy = refreshNodes().size();
   Set<? extends NodeMetadata> destroyed = client.destroyNodesMatching(inGroup(group));
   assertEquals(toDestroy, destroyed.size());
   Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);
   for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), inGroup(group))) {
     assert node.getStatus() == Status.TERMINATED : node;
     assert view.utils().credentialStore().get("node#" + node.getId()) == null
         : "credential should have been null for " + "node#" + node.getId();
   }
 }
Ejemplo n.º 5
0
  @AfterClass(groups = {"integration", "live"})
  @Override
  protected void tearDownContext() {
    try {
      if (nodes != null) {
        // Destroy all nodes in the group but also make sure to destroy other created nodes that
        // might not be in it.
        // The "testCreateTwoNodesWithOneSpecifiedName" creates nodes with an explicit name that
        // puts them outside the group,
        // so the list of nodes should also be taken into account when destroying the nodes.
        client.destroyNodesMatching(Predicates.<NodeMetadata>or(inGroup(group), in(nodes)));
      }
    } catch (Exception e) {

    }
    super.tearDownContext();
  }
Ejemplo n.º 6
0
  @Test(enabled = true, dependsOnMethods = "testCompareSizes")
  public void testConcurrentUseOfComputeServiceToCreateNodes() throws Exception {
    final long timeoutMs = 20 * 60 * 1000;
    List<String> groups = Lists.newArrayList();
    List<ListenableFuture<NodeMetadata>> futures = Lists.newArrayList();
    ListeningExecutorService userExecutor =
        context
            .utils()
            .injector()
            .getInstance(
                Key.get(ListeningExecutorService.class, Names.named(PROPERTY_USER_THREADS)));

    try {
      for (int i = 0; i < 2; i++) {
        final int groupNum = i;
        final String group = "twin" + groupNum;
        groups.add(group);
        template = buildTemplate(client.templateBuilder());
        template.getOptions().inboundPorts(22, 8080).blockOnPort(22, 300 + groupNum);
        ListenableFuture<NodeMetadata> future =
            userExecutor.submit(
                new Callable<NodeMetadata>() {
                  public NodeMetadata call() throws Exception {
                    NodeMetadata node =
                        getOnlyElement(client.createNodesInGroup(group, 1, template));
                    getAnonymousLogger().info("Started node " + node.getId());
                    return node;
                  }
                });
        futures.add(future);
      }

      ListenableFuture<List<NodeMetadata>> compoundFuture = Futures.allAsList(futures);
      compoundFuture.get(timeoutMs, TimeUnit.MILLISECONDS);

    } finally {
      for (String group : groups) {
        client.destroyNodesMatching(inGroup(group));
      }
    }
  }
Ejemplo n.º 7
0
  // since surefire and eclipse don't otherwise guarantee the order, we are
  // starting this one alphabetically before create2nodes..
  @Test(
      enabled = true,
      dependsOnMethods = {"testCompareSizes"})
  public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception {
    String group = this.group + "r";
    try {
      client.destroyNodesMatching(inGroup(group));
    } catch (Exception e) {

    }
    template = buildTemplate(client.templateBuilder());
    template.getOptions().blockOnPort(22, 120);
    try {
      Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
      NodeMetadata node = get(nodes, 0);
      LoginCredentials good = node.getCredentials();
      assert good.identity != null : nodes;

      for (Entry<? extends NodeMetadata, ExecResponse> response :
          client
              .runScriptOnNodesMatching(
                  runningInGroup(group),
                  "hostname",
                  wrapInInitScript(false).runAsRoot(false).overrideLoginCredentials(good))
              .entrySet()) {
        checkResponseEqualsHostname(response.getValue(), response.getKey());
      }

      // test single-node execution
      ExecResponse response =
          client.runScriptOnNode(
              node.getId(), "hostname", wrapInInitScript(false).runAsRoot(false));
      checkResponseEqualsHostname(response, node);
      OperatingSystem os = node.getOperatingSystem();

      // test bad password
      tryBadPassword(group, good);

      runScriptWithCreds(group, os, good);

      checkNodes(nodes, group, "runScriptWithCreds");

      // test adding AdminAccess later changes the default boot user, in this
      // case to foo, with home dir /over/ridden/foo
      ListenableFuture<ExecResponse> future =
          client.submitScriptOnNode(
              node.getId(),
              AdminAccess.builder().adminUsername("foo").adminHome("/over/ridden/foo").build(),
              nameTask("adminUpdate"));

      response = future.get(3, TimeUnit.MINUTES);

      assert response.getExitStatus() == 0 : node.getId() + ": " + response;

      node = client.getNodeMetadata(node.getId());
      // test that the node updated to the correct admin user!
      assertEquals(node.getCredentials().identity, "foo");
      assert node.getCredentials().credential != null : nodes;

      weCanCancelTasks(node);

      assert response.getExitStatus() == 0 : node.getId() + ": " + response;

      response =
          client.runScriptOnNode(
              node.getId(), "echo $USER", wrapInInitScript(false).runAsRoot(false));

      assert response.getOutput().trim().equals("foo") : node.getId() + ": " + response;

    } finally {
      client.destroyNodesMatching(inGroup(group));
    }
  }