Пример #1
0
  @Override
  public void release(DockerContainerLocation machine) {
    lock.readLock().lock();
    try {
      LOG.info("Releasing {}", machine);

      DynamicCluster cluster = dockerHost.getDockerContainerCluster();
      DockerContainer container = machine.getOwner();
      if (cluster.removeMember(container)) {
        LOG.info("Docker Host {}: member {} released", dockerHost.getDockerHostName(), machine);
      } else {
        LOG.warn(
            "Docker Host {}: member {} not found for release",
            dockerHost.getDockerHostName(),
            machine);
      }

      // Now close and unmange the container
      try {
        machine.close();
        container.stop();
      } catch (Exception e) {
        LOG.warn("Error stopping container: " + container, e);
        Exceptions.propagateIfFatal(e);
      } finally {
        Entities.unmanage(container);
      }
    } finally {
      lock.readLock().unlock();
    }
  }
  @Test
  public void testAddChild() throws Exception {
    try {
      // to test in GUI:
      // services: [ { type: org.apache.brooklyn.entity.stock.BasicEntity }]
      Response response =
          client()
              .path(entityEndpoint + "/children")
              .query("timeout", "10s")
              .post(
                  javax.ws.rs.client.Entity.entity(
                      "services: [ { type: " + TestEntity.class.getName() + " }]",
                      "application/yaml"));

      HttpAsserts.assertHealthyStatusCode(response.getStatus());
      Assert.assertEquals(entity.getChildren().size(), 1);
      Entity child = Iterables.getOnlyElement(entity.getChildren());
      Assert.assertTrue(Entities.isManaged(child));

      TaskSummary task = response.readEntity(TaskSummary.class);
      Assert.assertEquals(task.getResult(), MutableList.of(child.getId()));

    } finally {
      // restore it for other tests
      Collection<Entity> children = entity.getChildren();
      if (!children.isEmpty()) Entities.unmanage(Iterables.getOnlyElement(children));
    }
  }
Пример #3
0
 @Override
 public void removeHost(DockerHost host) {
   SdnAgent agent = host.sensors().get(SdnAgent.SDN_AGENT);
   if (agent == null) {
     LOG.warn("{} cannot find calico service: {}", this, host);
     return;
   }
   agent.stop();
   getAgents().removeMember(agent);
   Entities.unmanage(agent);
   if (LOG.isDebugEnabled()) LOG.debug("{} removed calico plugin {}", this, agent);
 }
Пример #4
0
  public List<String> scanSlaves(JsonArray slaves) throws UnknownHostException {
    List<String> slaveIds = MutableList.<String>of();
    for (int i = 0; i < slaves.size(); i++) {
      JsonObject slave = slaves.get(i).getAsJsonObject();
      boolean active = slave.get("active").getAsBoolean();
      String id = slave.get("id").getAsString();
      String hostname = slave.get("hostname").getAsString();
      Double registered = slave.get("registered_time").getAsDouble();
      Group group = sensors().get(MESOS_SLAVES);

      Optional<Entity> entity =
          Iterables.tryFind(
              group.getMembers(),
              Predicates.compose(
                  Predicates.equalTo(id), EntityFunctions.attribute(MesosSlave.MESOS_SLAVE_ID)));
      if (entity.isPresent()) {
        Entity found = entity.get();
        found.sensors().set(MesosSlave.SLAVE_ACTIVE, active);
        if (!active) {
          Lifecycle state = found.sensors().get(Attributes.SERVICE_STATE_ACTUAL);
          if (Lifecycle.ON_FIRE.equals(state) || Lifecycle.STARTING.equals(state)) {
            continue;
          } else if (Lifecycle.STOPPING.equals(state) || Lifecycle.STOPPED.equals(state)) {
            group.removeMember(found);
            group.removeChild(found);
            Entities.unmanage(found);
          } else {
            ServiceStateLogic.setExpectedState(found, Lifecycle.STOPPING);
          }
        }
      } else if (active) {
        LocationSpec<SshMachineLocation> spec =
            LocationSpec.create(SshMachineLocation.class)
                .configure(SshMachineLocation.SSH_HOST, hostname)
                .configure("address", InetAddress.getByName(hostname))
                .displayName(hostname);
        if (config().get(MESOS_SLAVE_ACCESSIBLE)) {
          spec.configure(CloudLocationConfig.WAIT_FOR_SSHABLE, "true")
              .configure(SshMachineLocation.DETECT_MACHINE_DETAILS, true)
              .configure(SshMachineLocation.SSH_PORT, config().get(MesosSlave.SLAVE_SSH_PORT))
              .configure(LocationConfigKeys.USER, config().get(MesosSlave.SLAVE_SSH_USER))
              .configure(LocationConfigKeys.PASSWORD, config().get(MesosSlave.SLAVE_SSH_PASSWORD))
              .configure(SshTool.PROP_PASSWORD, config().get(MesosSlave.SLAVE_SSH_PASSWORD))
              .configure(SshTool.PROP_PORT, config().get(MesosSlave.SLAVE_SSH_PORT))
              .configure(
                  LocationConfigKeys.PRIVATE_KEY_DATA,
                  config().get(MesosSlave.SLAVE_SSH_PRIVATE_KEY_DATA))
              .configure(
                  LocationConfigKeys.PRIVATE_KEY_FILE,
                  config().get(MesosSlave.SLAVE_SSH_PRIVATE_KEY_FILE));
        } else {
          spec.configure(CloudLocationConfig.WAIT_FOR_SSHABLE, "false")
              .configure(SshMachineLocation.DETECT_MACHINE_DETAILS, false);
        }
        SshMachineLocation machine =
            getManagementContext().getLocationManager().createLocation(spec);

        // Setup port forwarding
        MarathonPortForwarder portForwarder = new MarathonPortForwarder();
        portForwarder.setManagementContext(getManagementContext());

        EntitySpec<MesosSlave> slaveSpec =
            EntitySpec.create(MesosSlave.class)
                .configure(MesosSlave.MESOS_SLAVE_ID, id)
                .configure(MesosSlave.REGISTERED_AT, registered.longValue())
                .configure(MesosSlave.MESOS_CLUSTER, this)
                .displayName("Mesos Slave (" + hostname + ")");
        MesosSlave added = sensors().get(MESOS_SLAVES).addMemberChild(slaveSpec);
        added.sensors().set(MesosSlave.SLAVE_ACTIVE, active);
        added.sensors().set(MesosSlave.HOSTNAME, hostname);
        added.sensors().set(MesosSlave.ADDRESS, hostname);

        added.start(ImmutableList.of(machine));
        portForwarder.init(hostname, this);

        // Setup subnet tier
        SubnetTier subnetTier =
            added.addChild(
                EntitySpec.create(SubnetTier.class)
                    .configure(SubnetTier.PORT_FORWARDER, portForwarder)
                    .configure(SubnetTier.SUBNET_CIDR, Cidr.UNIVERSAL));
        Entities.start(subnetTier, ImmutableList.of(machine));
        added.sensors().set(MesosSlave.SUBNET_TIER, subnetTier);
      }

      if (active) slaveIds.add(id);
    }
    return slaveIds;
  }