@Test
  public void testTerminate() throws Exception {
    initializeOneAgent();

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId);
    SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId);

    Request request =
        Request.Builder.prepareDelete()
            .setUri(
                coordinatorUriBuilder()
                    .appendPath("/v1/slot")
                    .addParameter("host", "apple*")
                    .build())
            .build();
    List<SlotStatusRepresentation> actual =
        httpClient.execute(
            request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode()));

    apple1Status = apple1Status.changeState(TERMINATED);
    apple2Status = apple2Status.changeState(TERMINATED);
    SlotStatus bananaStatus = coordinator.getAgentByAgentId(agentId).getSlotStatus(bananaSlotId);

    List<SlotStatusRepresentation> expected =
        ImmutableList.of(
            slotStatusRepresentationFactory.create(apple1Status),
            slotStatusRepresentationFactory.create(apple2Status.changeState(TERMINATED)));

    assertEqualsNoOrder(actual, expected);

    assertEquals(apple1Status.getState(), TERMINATED);
    assertEquals(apple2Status.getState(), TERMINATED);
    assertEquals(bananaStatus.getState(), STOPPED);
  }
  @Test
  public void testKill() throws Exception {
    initializeOneAgent();

    coordinator.setState(RUNNING, Predicates.<SlotStatus>alwaysTrue(), null);

    Request request =
        Request.Builder.preparePut()
            .setUri(
                coordinatorUriBuilder()
                    .appendPath("/v1/slot/lifecycle")
                    .addParameter("binary", "apple:*")
                    .build())
            .setBodyGenerator(createStaticBodyGenerator("killing", UTF_8))
            .build();
    List<SlotStatusRepresentation> actual =
        httpClient.execute(
            request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode()));

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId);
    SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId);
    SlotStatus bananaStatus = agentStatus.getSlotStatus(bananaSlotId);

    List<SlotStatusRepresentation> expected =
        ImmutableList.of(
            slotStatusRepresentationFactory.create(apple1Status),
            slotStatusRepresentationFactory.create(apple2Status));

    assertEqualsNoOrder(actual, expected);
    assertEquals(apple1Status.getState(), STOPPED);
    assertEquals(apple2Status.getState(), STOPPED);
    assertEquals(bananaStatus.getState(), RUNNING);
  }
Example #3
0
 public Coordinator getCoordinator() {
   for (Coordinator coordinator : getExecutionDegree().getCoordinatorsList()) {
     if (this.getPerson().equals(coordinator.getPerson())) {
       return coordinator;
     }
   }
   return null;
 }
Example #4
0
 public List<Coordinator> getResponsibleCoordinators() {
   List<Coordinator> result = new ArrayList<Coordinator>();
   for (final Coordinator coordinator : getCoordinatorsListSet()) {
     if (coordinator.getResponsible()) {
       result.add(coordinator);
     }
   }
   return result;
 }
Example #5
0
  public Coordinator getCoordinatorByTeacher(Person person) {
    for (Coordinator coordinator : getCoordinatorsListSet()) {
      if (coordinator.getPerson() == person) {
        return coordinator;
      }
    }

    return null;
  }
 private CoordinatorStatusRepresentation getNonMainCoordinator(
     List<CoordinatorStatusRepresentation> coordinators) {
   assertEquals(coordinators.size(), 2);
   CoordinatorStatusRepresentation actual;
   if (coordinators.get(0).getInstanceId().equals(coordinator.status().getInstanceId())) {
     actual = coordinators.get(1);
   } else {
     actual = coordinators.get(0);
     assertEquals(coordinators.get(1).getInstanceId(), coordinator.status().getInstanceId());
   }
   return actual;
 }
  @BeforeMethod
  public void resetState() {
    provisioner.clearCoordinators();
    coordinator.updateAllCoordinatorsAndWait();
    assertEquals(coordinator.getCoordinators().size(), 1);

    provisioner.clearAgents();
    coordinator.updateAllAgentsAndWait();
    assertTrue(coordinator.getAgents().isEmpty());

    stateManager.clearAll();
    assertTrue(coordinator.getAllSlotStatus().isEmpty());
  }
  private void initializeOneAgent() {
    apple1SotId = UUID.randomUUID();
    SlotStatus appleSlotStatus1 =
        createSlotStatus(
            apple1SotId,
            URI.create("fake://appleServer1/v1/agent/slot/apple1"),
            URI.create("fake://appleServer1/v1/agent/slot/apple1"),
            "instance",
            "/location",
            STOPPED,
            APPLE_ASSIGNMENT,
            "/apple1",
            ImmutableMap.<String, Integer>of());
    apple2SlotId = UUID.randomUUID();
    SlotStatus appleSlotStatus2 =
        createSlotStatus(
            apple2SlotId,
            URI.create("fake://appleServer2/v1/agent/slot/apple1"),
            URI.create("fake://appleServer2/v1/agent/slot/apple1"),
            "instance",
            "/location",
            STOPPED,
            APPLE_ASSIGNMENT,
            "/apple2",
            ImmutableMap.<String, Integer>of());
    bananaSlotId = UUID.randomUUID();
    SlotStatus bananaSlotStatus =
        createSlotStatus(
            bananaSlotId,
            URI.create("fake://bananaServer/v1/agent/slot/banana"),
            URI.create("fake://bananaServer/v1/agent/slot/banana"),
            "instance",
            "/location",
            STOPPED,
            BANANA_ASSIGNMENT,
            "/banana",
            ImmutableMap.<String, Integer>of());

    agentId = UUID.randomUUID().toString();
    AgentStatus agentStatus =
        new AgentStatus(
            agentId,
            ONLINE,
            "instance-id",
            URI.create("fake://foo/"),
            URI.create("fake://foo/"),
            "/unknown/location",
            "instance.type",
            ImmutableList.of(appleSlotStatus1, appleSlotStatus2, bananaSlotStatus),
            ImmutableMap.of("cpu", 8, "memory", 1024));

    provisioner.addAgents(agentStatus);
    coordinator.updateAllAgentsAndWait();

    stateManager.clearAll();

    slotStatusRepresentationFactory =
        new SlotStatusRepresentationFactory(
            ImmutableList.of(appleSlotStatus1, appleSlotStatus2, bananaSlotStatus), repository);
  }
  @Test
  public void testLifecycleUnknown() throws Exception {
    initializeOneAgent();

    Request request =
        Request.Builder.preparePut()
            .setUri(
                coordinatorUriBuilder()
                    .appendPath("/v1/slot/lifecycle")
                    .addParameter("binary", "apple:*")
                    .build())
            .setBodyGenerator(createStaticBodyGenerator("unknown", UTF_8))
            .build();
    StatusResponse response = httpClient.execute(request, createStatusResponseHandler());

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId);
    SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId);
    SlotStatus bananaStatus = agentStatus.getSlotStatus(bananaSlotId);

    assertEquals(response.getStatusCode(), Status.BAD_REQUEST.getStatusCode());
    assertEquals(apple1Status.getState(), STOPPED);
    assertEquals(apple2Status.getState(), STOPPED);
    assertEquals(bananaStatus.getState(), STOPPED);
  }
  @Test
  public void testGetAllSlots() throws Exception {
    initializeOneAgent();

    Request request =
        Request.Builder.prepareGet()
            .setUri(
                coordinatorUriBuilder().appendPath("/v1/slot").addParameter("name", "*").build())
            .build();
    List<SlotStatusRepresentation> actual =
        httpClient.execute(
            request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode()));

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);

    int prefixSize =
        shortestUniquePrefix(
            asList(
                agentStatus.getSlotStatus(apple1SotId).getId().toString(),
                agentStatus.getSlotStatus(apple2SlotId).getId().toString(),
                agentStatus.getSlotStatus(bananaSlotId).getId().toString()),
            MIN_PREFIX_SIZE);

    assertEqualsNoOrder(
        actual,
        ImmutableList.of(
            SlotStatusRepresentation.from(
                agentStatus.getSlotStatus(apple1SotId), prefixSize, MOCK_REPO),
            SlotStatusRepresentation.from(
                agentStatus.getSlotStatus(apple2SlotId), prefixSize, MOCK_REPO),
            SlotStatusRepresentation.from(
                agentStatus.getSlotStatus(bananaSlotId), prefixSize, MOCK_REPO)));
  }
Example #11
0
 private void doUpdateDomain(HttpServletRequest req, HttpServletResponse resp) throws IOException {
   final String domainName = req.getParameter("name");
   final String storageEngineOptions = req.getParameter("storageEngineOptions");
   final Domain domain = coordinator.getDomain(domainName);
   if (domain == null) {
     throw new IOException("Could not get Domain '" + domainName + "' from Configurator.");
   } else {
     coordinator.updateDomain(
         domainName,
         domain.getNumParts(),
         domain.getStorageEngineFactoryClass().getName(),
         storageEngineOptions,
         domain.getPartitioner().getClass().getName());
   }
   resp.sendRedirect("/domains.jsp");
 }
Example #12
0
  public static List<ExecutionDegree> getAllCoordinatedByTeacher(Person person) {
    List<ExecutionDegree> result = new ArrayList<ExecutionDegree>();

    if (person == null) {
      return result;
    }

    for (Coordinator coordinator : person.getCoordinatorsSet()) {
      result.add(coordinator.getExecutionDegree());
    }

    Comparator<ExecutionDegree> degreNameComparator =
        new Comparator<ExecutionDegree>() {

          @Override
          public int compare(ExecutionDegree o1, ExecutionDegree o2) {
            String name1 = o1.getDegreeCurricularPlan().getDegree().getName();
            String name2 = o2.getDegreeCurricularPlan().getDegree().getName();

            return String.CASE_INSENSITIVE_ORDER.compare(name1, name2);
          }
        };

    Comparator<ExecutionDegree> yearComparator =
        new Comparator<ExecutionDegree>() {

          @Override
          public int compare(ExecutionDegree o1, ExecutionDegree o2) {
            String year1 = o1.getExecutionYear().getYear();
            String year2 = o2.getExecutionYear().getYear();

            return String.CASE_INSENSITIVE_ORDER.compare(year1, year2);
          }
        };

    // sort by degreeCurricularPlan.degree.nome ascending,
    // executionYear.year descending
    ComparatorChain comparatorChain = new ComparatorChain();
    comparatorChain.addComparator(degreNameComparator, false);
    comparatorChain.addComparator(yearComparator, true);

    Collections.sort(result, comparatorChain);

    return result;
  }
Example #13
0
 public void start(final InetAddress IP, final Integer serverPort, final Boolean debug) {
   this.om.setMyInfo(IP, serverPort);
   logger.info("Set myInfo\n" + this.om.getMyInfo());
   this.initialize(IP, serverPort, debug);
   // initialize state wrapper
   StateWrapper st = StateWrapper.getInstance();
   st.setState(new Idle());
   // initiate Coordinator
   coo.start();
 }
 @Test
 public void testValidVersion() {
   UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/lifecycle?binary=*:apple:*");
   String slotsVersion =
       VersionsUtil.createSlotsVersion(
           coordinator.getAllSlotsStatus(
               SlotFilterBuilder.build(uriInfo, false, ImmutableList.<UUID>of())));
   assertOkResponse(
       resource.setState("running", uriInfo, slotsVersion), RUNNING, apple1SlotId, apple2SlotId);
 }
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public Response getAllSlots(@Context UriInfo uriInfo) {
   Predicate<RemoteSlot> slotFilter = SlotFilterBuilder.build(uriInfo);
   List<SlotStatusRepresentation> representations = Lists.newArrayList();
   for (RemoteSlot remoteSlot : coordinator.getAllSlots()) {
     if (slotFilter.apply(remoteSlot)) {
       representations.add(SlotStatusRepresentation.from(remoteSlot.status()));
     }
   }
   return Response.ok(representations).build();
 }
Example #16
0
  private void doDeleteDomain(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    final Domain domain = coordinator.getDomain(req.getParameter("name"));
    boolean isInUse = false;
    // check if this domain is in use anywhere
    for (RingGroup rg : coordinator.getRingGroups()) {
      if (rg.getTargetVersion() == null) {
        continue;
      }

      DomainGroup dg = rg.getDomainGroup();
      DomainGroupVersion dgv = rg.getTargetVersion();
      if (DomainGroupVersions.containsDomain(dgv, domain)) {
        isInUse = true;
        break;
      }
    }

    if (!isInUse) {
      coordinator.deleteDomain(domain.getName());
    }
    resp.sendRedirect("/domains.jsp");
  }
Example #17
0
 public void start(
     final InetAddress serverIP,
     final Integer serverPort,
     final InetAddress seedIP,
     final Integer seedPort,
     final Boolean debug)
     throws DBlncrException {
   this.om.setMyInfo(serverIP, serverPort);
   // initialize (retrieve other servers)
   this.initializeClient(seedIP, seedPort);
   this.initialize(serverIP, serverPort, debug);
   // initiate Coordinator
   coo.start();
 }
 @Test
 public void testInvalidVersion() {
   UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/lifecycle?binary=*:apple:*");
   try {
     resource.setState("running", uriInfo, "invalid-version");
     fail("Expected VersionConflictException");
   } catch (VersionConflictException e) {
     assertEquals(e.getName(), AIRSHIP_SLOTS_VERSION_HEADER);
     assertEquals(
         e.getVersion(),
         VersionsUtil.createSlotsVersion(
             coordinator.getAllSlotsStatus(
                 SlotFilterBuilder.build(uriInfo, false, ImmutableList.<UUID>of()))));
   }
 }
  private void assertOkResponse(Response response, SlotLifecycleState state, UUID... slotIds) {
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    Builder<SlotStatusRepresentation> builder = ImmutableList.builder();
    for (UUID slotId : slotIds) {
      SlotStatus slotStatus = agentStatus.getSlotStatus(slotId);
      builder.add(
          SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO));
      assertEquals(slotStatus.getAssignment(), APPLE_ASSIGNMENT);
    }
    assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build());
    assertNull(
        response
            .getMetadata()
            .get("Content-Type")); // content type is set by jersey based on @Produces
  }
  @Test
  public void testGetAllAgentsSingle() throws Exception {
    String agentId = UUID.randomUUID().toString();
    URI internalUri = URI.create("fake://agent/" + agentId + "/internal");
    URI externalUri = URI.create("fake://agent/" + agentId + "/external");
    String instanceId = "instance-id";
    String location = "/unknown/location";
    String instanceType = "instance.type";
    Map<String, Integer> resources = ImmutableMap.of("cpu", 8, "memory", 1024);

    AgentStatus status =
        new AgentStatus(
            agentId,
            AgentLifecycleState.ONLINE,
            instanceId,
            internalUri,
            externalUri,
            location,
            instanceType,
            ImmutableList.<SlotStatus>of(),
            resources);

    // add the agent
    provisioner.addAgents(status);
    coordinator.updateAllAgentsAndWait();

    Request request =
        Request.Builder.prepareGet()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/agent").build())
            .build();

    List<AgentStatusRepresentation> agents =
        httpClient.execute(
            request, createJsonResponseHandler(agentStatusesCodec, Status.OK.getStatusCode()));
    assertEquals(agents.size(), 1);

    AgentStatusRepresentation actual = agents.get(0);
    assertEquals(actual.getAgentId(), agentId);
    assertEquals(actual.getState(), AgentLifecycleState.ONLINE);
    assertEquals(actual.getInstanceId(), instanceId);
    assertEquals(actual.getLocation(), location);
    assertEquals(actual.getInstanceType(), instanceType);
    assertEquals(actual.getSelf(), internalUri);
    assertEquals(actual.getExternalUri(), externalUri);
    assertEquals(actual.getResources(), resources);
  }
  @Test
  public void testUpgrade() throws Exception {
    initializeOneAgent();

    UpgradeVersions upgradeVersions = new UpgradeVersions("2.0", "2.0");
    Request request =
        Request.Builder.preparePost()
            .setUri(
                coordinatorUriBuilder()
                    .appendPath("/v1/slot/assignment")
                    .addParameter("host", "apple*")
                    .build())
            .setHeader(CONTENT_TYPE, APPLICATION_JSON)
            .setBodyGenerator(jsonBodyGenerator(upgradeVersionsCodec, upgradeVersions))
            .build();
    List<SlotStatusRepresentation> actual =
        httpClient.execute(
            request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode()));

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId);
    SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId);
    SlotStatus bananaStatus = agentStatus.getSlotStatus(bananaSlotId);

    List<SlotStatusRepresentation> expected =
        ImmutableList.of(
            slotStatusRepresentationFactory.create(apple1Status),
            slotStatusRepresentationFactory.create(apple2Status));

    assertEqualsNoOrder(actual, expected);

    assertEquals(apple1Status.getState(), STOPPED);
    assertEquals(apple2Status.getState(), STOPPED);
    assertEquals(bananaStatus.getState(), STOPPED);

    assertEquals(
        apple1Status.getAssignment(),
        upgradeVersions.upgradeAssignment(MOCK_REPO, APPLE_ASSIGNMENT));
    assertEquals(
        apple2Status.getAssignment(),
        upgradeVersions.upgradeAssignment(MOCK_REPO, APPLE_ASSIGNMENT));
    assertEquals(bananaStatus.getAssignment(), BANANA_ASSIGNMENT);
  }
  @Test
  public void testGetAllCoordinatorsSingle() throws Exception {
    // add a coordinator directly to the provisioner
    String coordinatorId = UUID.randomUUID().toString();
    String instanceId = "instance-id";
    URI internalUri = URI.create("fake://coordinator/" + instanceId + "/internal");
    URI externalUri = URI.create("fake://coordinator/" + instanceId + "/external");
    String location = "/unknown/location";
    String instanceType = "instance.type";

    CoordinatorStatus status =
        new CoordinatorStatus(
            coordinatorId,
            CoordinatorLifecycleState.ONLINE,
            instanceId,
            internalUri,
            externalUri,
            location,
            instanceType);
    provisioner.addCoordinators(status);
    coordinator.updateAllCoordinatorsAndWait();

    // verify coordinator appears
    Request request =
        Request.Builder.prepareGet()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/coordinator").build())
            .build();

    List<CoordinatorStatusRepresentation> coordinators =
        httpClient.execute(
            request,
            createJsonResponseHandler(coordinatorStatusesCodec, Status.OK.getStatusCode()));
    CoordinatorStatusRepresentation actual = getNonMainCoordinator(coordinators);

    assertEquals(actual.getCoordinatorId(), coordinatorId);
    assertEquals(actual.getState(), CoordinatorLifecycleState.ONLINE);
    assertEquals(actual.getInstanceId(), instanceId);
    assertEquals(actual.getLocation(), location);
    assertEquals(actual.getInstanceType(), instanceType);
    assertEquals(actual.getSelf(), internalUri);
    assertEquals(actual.getExternalUri(), externalUri);
  }
  @Test
  public void testCoordinatorProvision() throws Exception {
    // provision the coordinator and verify
    String instanceType = "instance-type";
    CoordinatorProvisioningRepresentation coordinatorProvisioningRepresentation =
        new CoordinatorProvisioningRepresentation(
            "coordinator:config:1", 1, instanceType, null, null, null, null, null);
    Request request =
        Request.Builder.preparePost()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/coordinator").build())
            .setHeader(CONTENT_TYPE, APPLICATION_JSON)
            .setBodyGenerator(
                jsonBodyGenerator(
                    coordinatorProvisioningCodec, coordinatorProvisioningRepresentation))
            .build();
    List<CoordinatorStatusRepresentation> coordinators =
        httpClient.execute(
            request,
            createJsonResponseHandler(coordinatorStatusesCodec, Status.OK.getStatusCode()));

    assertEquals(coordinators.size(), 1);
    String instanceId = coordinators.get(0).getInstanceId();
    assertNotNull(instanceId);
    String location = coordinators.get(0).getLocation();
    assertNotNull(location);
    assertEquals(coordinators.get(0).getInstanceType(), instanceType);
    assertNull(coordinators.get(0).getCoordinatorId());
    assertNull(coordinators.get(0).getSelf());
    assertNull(coordinators.get(0).getExternalUri());
    assertEquals(coordinators.get(0).getState(), CoordinatorLifecycleState.PROVISIONING);

    // start the coordinator and verify
    CoordinatorStatus expectedCoordinatorStatus = provisioner.startCoordinator(instanceId);
    coordinator.updateAllCoordinatorsAndWait();
    assertEquals(coordinator.getCoordinators().size(), 2);
    assertEquals(coordinator.getCoordinator(instanceId).getInstanceId(), instanceId);
    assertEquals(coordinator.getCoordinator(instanceId).getInstanceType(), instanceType);
    assertEquals(coordinator.getCoordinator(instanceId).getLocation(), location);
    assertEquals(
        coordinator.getCoordinator(instanceId).getCoordinatorId(),
        expectedCoordinatorStatus.getCoordinatorId());
    assertEquals(
        coordinator.getCoordinator(instanceId).getInternalUri(),
        expectedCoordinatorStatus.getInternalUri());
    assertEquals(
        coordinator.getCoordinator(instanceId).getExternalUri(),
        expectedCoordinatorStatus.getExternalUri());
    assertEquals(
        coordinator.getCoordinator(instanceId).getState(), CoordinatorLifecycleState.ONLINE);

    request =
        Request.Builder.prepareGet()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/coordinator").build())
            .build();

    coordinators =
        httpClient.execute(
            request,
            createJsonResponseHandler(coordinatorStatusesCodec, Status.OK.getStatusCode()));
    CoordinatorStatusRepresentation actual = getNonMainCoordinator(coordinators);

    assertEquals(actual.getInstanceId(), instanceId);
    assertEquals(actual.getInstanceType(), instanceType);
    assertEquals(actual.getLocation(), location);
    assertEquals(actual.getCoordinatorId(), expectedCoordinatorStatus.getCoordinatorId());
    assertEquals(actual.getSelf(), expectedCoordinatorStatus.getInternalUri());
    assertEquals(actual.getExternalUri(), expectedCoordinatorStatus.getExternalUri());
    assertEquals(actual.getState(), CoordinatorLifecycleState.ONLINE);
  }
  @Test
  public void testAgentProvision() throws Exception {
    // provision the agent and verify
    String instanceType = "instance-type";
    AgentProvisioningRepresentation agentProvisioningRepresentation =
        new AgentProvisioningRepresentation(
            "agent:config:1", 1, instanceType, null, null, null, null, null);
    Request request =
        Request.Builder.preparePost()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/agent").build())
            .setHeader(CONTENT_TYPE, APPLICATION_JSON)
            .setBodyGenerator(
                jsonBodyGenerator(agentProvisioningCodec, agentProvisioningRepresentation))
            .build();
    List<AgentStatusRepresentation> agents =
        httpClient.execute(
            request, createJsonResponseHandler(agentStatusesCodec, Status.OK.getStatusCode()));

    assertEquals(agents.size(), 1);
    String instanceId = agents.get(0).getInstanceId();
    assertNotNull(instanceId);
    String location = agents.get(0).getLocation();
    assertNotNull(location);
    assertEquals(agents.get(0).getInstanceType(), instanceType);
    assertNull(agents.get(0).getAgentId());
    assertNull(agents.get(0).getSelf());
    assertNull(agents.get(0).getExternalUri());
    assertEquals(agents.get(0).getState(), AgentLifecycleState.PROVISIONING);

    // start the agent and verify
    AgentStatus expectedAgentStatus = provisioner.startAgent(instanceId);
    coordinator.updateAllAgentsAndWait();
    assertEquals(coordinator.getAgents().size(), 1);
    assertEquals(coordinator.getAgent(instanceId).getInstanceId(), instanceId);
    assertEquals(coordinator.getAgent(instanceId).getInstanceType(), instanceType);
    assertEquals(coordinator.getAgent(instanceId).getLocation(), location);
    assertEquals(coordinator.getAgent(instanceId).getAgentId(), expectedAgentStatus.getAgentId());
    assertEquals(
        coordinator.getAgent(instanceId).getInternalUri(), expectedAgentStatus.getInternalUri());
    assertEquals(
        coordinator.getAgent(instanceId).getExternalUri(), expectedAgentStatus.getExternalUri());
    assertEquals(coordinator.getAgent(instanceId).getState(), AgentLifecycleState.ONLINE);

    request =
        Request.Builder.prepareGet()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/agent").build())
            .build();

    agents =
        httpClient.execute(
            request, createJsonResponseHandler(agentStatusesCodec, Status.OK.getStatusCode()));
    assertEquals(agents.size(), 1);

    AgentStatusRepresentation actual = agents.get(0);
    assertEquals(actual.getInstanceId(), instanceId);
    assertEquals(actual.getInstanceType(), instanceType);
    assertEquals(actual.getLocation(), location);
    assertEquals(actual.getAgentId(), expectedAgentStatus.getAgentId());
    assertEquals(actual.getSelf(), expectedAgentStatus.getInternalUri());
    assertEquals(actual.getExternalUri(), expectedAgentStatus.getExternalUri());
    assertEquals(actual.getState(), AgentLifecycleState.ONLINE);
  }
Example #25
0
 public DBalancer() {
   this.om = OverlayManager.getInstance();
   this.coo = Coordinator.getInstance();
   // BasicConfigurator replaced with PropertyConfigurator.
   PropertyConfigurator.configure("src/main/resources/log4j.properties");
 }
Example #26
0
 private void doCleanDomains() throws IOException {
   Domains.cleanDomains(coordinator.getDomains());
 }
  @BeforeMethod
  public void setup() throws Exception {
    NodeInfo nodeInfo = new NodeInfo("testing");

    MockProvisioner provisioner = new MockProvisioner();
    coordinator =
        new Coordinator(
            nodeInfo,
            new HttpServerInfo(new HttpServerConfig(), nodeInfo),
            new CoordinatorConfig().setStatusExpiration(new Duration(1, TimeUnit.DAYS)),
            provisioner.getCoordinatorFactory(),
            provisioner.getAgentFactory(),
            MOCK_REPO,
            provisioner,
            new InMemoryStateManager(),
            new MockServiceInventory());
    resource = new CoordinatorLifecycleResource(coordinator, MOCK_REPO);

    apple1SlotId = UUID.randomUUID();
    SlotStatus appleSlotStatus1 =
        createSlotStatus(
            apple1SlotId,
            URI.create("fake://foo/v1/agent/slot/apple1"),
            URI.create("fake://foo/v1/agent/slot/apple1"),
            "instance",
            "/location",
            STOPPED,
            APPLE_ASSIGNMENT,
            "/apple1",
            ImmutableMap.<String, Integer>of());
    apple2SlotId = UUID.randomUUID();
    SlotStatus appleSlotStatus2 =
        createSlotStatus(
            apple2SlotId,
            URI.create("fake://foo/v1/agent/slot/apple1"),
            URI.create("fake://foo/v1/agent/slot/apple1"),
            "instance",
            "/location",
            STOPPED,
            APPLE_ASSIGNMENT,
            "/apple2",
            ImmutableMap.<String, Integer>of());
    bananaSlotId = UUID.randomUUID();
    SlotStatus bananaSlotStatus =
        createSlotStatus(
            bananaSlotId,
            URI.create("fake://foo/v1/agent/slot/banana"),
            URI.create("fake://foo/v1/agent/slot/banana"),
            "instance",
            "/location",
            STOPPED,
            BANANA_ASSIGNMENT,
            "/banana",
            ImmutableMap.<String, Integer>of());

    agentId = UUID.randomUUID().toString();
    AgentStatus agentStatus =
        new AgentStatus(
            agentId,
            ONLINE,
            "instance-id",
            URI.create("fake://foo/"),
            URI.create("fake://foo/"),
            "/unknown/location",
            "instance.type",
            ImmutableList.of(appleSlotStatus1, appleSlotStatus2, bananaSlotStatus),
            ImmutableMap.of("cpu", 8, "memory", 1024));

    prefixSize =
        shortestUniquePrefix(
            asList(
                appleSlotStatus1.getId().toString(),
                appleSlotStatus2.getId().toString(),
                bananaSlotStatus.getId().toString()),
            MIN_PREFIX_SIZE);

    provisioner.addAgents(agentStatus);
    coordinator.updateAllAgents();
  }
 private void assertSlotState(UUID slotId, SlotLifecycleState state) {
   assertEquals(coordinator.getAgentByAgentId(agentId).getSlotStatus(slotId).getState(), state);
 }
Example #29
0
 public void showLoad() {
   String load = coo.getLoad();
   System.out.println(load);
 }
  void show(ServiceInstance service) {
    detectUpdates(false);
    _target = service;

    //
    // If it's not a template instance, it's shown using
    // ServiceEditor.show()
    //
    assert getDescriptor().template.length() > 0;

    ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor) service.getDescriptor();
    Coordinator coordinator = service.getCoordinator();
    boolean isEditable = service.isEphemeral() || !coordinator.substitute();

    Utils.Resolver resolver = isEditable ? null : ((TreeNode) service.getParent()).getResolver();

    //
    // Need to make control enabled before changing it
    //
    _template.setEnabled(true);

    ServiceTemplates serviceTemplates = service.getRoot().getServiceTemplates();
    _template.setModel(serviceTemplates.createComboBoxModel());

    ServiceTemplate t = (ServiceTemplate) serviceTemplates.findChild(descriptor.template);
    assert t != null;
    _template.setSelectedItem(t);

    ListDataListener templateListener =
        new ListDataListener() {
          @Override
          public void contentsChanged(ListDataEvent e) {
            updated();

            ServiceTemplate t = (ServiceTemplate) _template.getModel().getSelectedItem();

            TemplateDescriptor td = (TemplateDescriptor) t.getDescriptor();

            //
            // Replace parameters but keep existing values
            //
            _parameters.set(
                td.parameters,
                makeParameterValues(_parameters.getValues(), td.parameters),
                td.parameterDefaults,
                null);
          }

          @Override
          public void intervalAdded(ListDataEvent e) {}

          @Override
          public void intervalRemoved(ListDataEvent e) {}
        };

    _template.getModel().addListDataListener(templateListener);
    _template.setEnabled(isEditable);

    TemplateDescriptor td = (TemplateDescriptor) t.getDescriptor();
    _parameters.set(td.parameters, descriptor.parameterValues, td.parameterDefaults, resolver);

    _propertySets.setList(
        java.util.Arrays.asList(descriptor.propertySet.references), getDetailResolver());
    _propertySets.setEditable(isEditable);

    _properties.setProperties(
        descriptor.propertySet.properties, null, null, getDetailResolver(), isEditable);

    _applyButton.setEnabled(service.isEphemeral());
    _discardButton.setEnabled(service.isEphemeral());
    detectUpdates(true);
    if (service.isEphemeral()) {
      updated();
    }
  }