@Test(dataProvider = "environment") private void testHostTypeQueries( String environmentName, TestEnvironment cloudStoreEnvironment, CloudStoreConstraintChecker checker) throws Throwable { logger.info("Testing host type boundaries with {}", environmentName); List<DatastoreService.State> datastores = createDatastoreDescriptions(10); List<HostService.State> cloudHosts = createHostDescriptions(10, false, datastores); List<HostService.State> managementHosts = createHostDescriptions(10, true, datastores); logger.info("Making 10 datastores..."); createDatastores(cloudStoreEnvironment, datastores); logger.info("Making 10 cloud hosts..."); createHosts(cloudStoreEnvironment, cloudHosts); logger.info("Making 10 management hosts..."); createHosts(cloudStoreEnvironment, managementHosts); Map<String, ServerAddress> selectedHosts; ResourceConstraint constraint; constraint = new ResourceConstraint(ResourceConstraintType.MANAGEMENT_ONLY, null); selectedHosts = checker.getCandidatesSync(Arrays.asList(constraint), 2); assertThat(selectedHosts.size(), equalTo(2)); for (String hostId : selectedHosts.keySet()) { assertThat(hostId, startsWith(MGMT_HOST_PREFIX)); } constraint = new ResourceConstraint(ResourceConstraintType.MANAGEMENT_ONLY, null); constraint.setNegative(true); selectedHosts = checker.getCandidatesSync(Arrays.asList(constraint), 2); assertThat(selectedHosts.size(), equalTo(2)); for (String hostId : selectedHosts.keySet()) { assertThat(hostId, startsWith(CLOUD_HOST_PREFIX)); } selectedHosts = checker.getCandidatesSync(null, 2); assertThat(selectedHosts.size(), equalTo(2)); for (String hostId : selectedHosts.keySet()) { assertThat(hostId, startsWith(CLOUD_HOST_PREFIX)); } List<String> datastoreList = new ArrayList<>(); datastoreList.addAll(cloudHosts.get(0).reportedDatastores); constraint = new ResourceConstraint(ResourceConstraintType.DATASTORE, datastoreList); selectedHosts = checker.getCandidatesSync(Arrays.asList(constraint), 1); assertThat(selectedHosts.size(), equalTo(1)); for (String hostId : selectedHosts.keySet()) { assertThat(hostId, startsWith(CLOUD_HOST_PREFIX)); } deleteDatastores(cloudStoreEnvironment, datastores); deleteHosts(cloudStoreEnvironment, cloudHosts); deleteHosts(cloudStoreEnvironment, managementHosts); }
public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); }
CloudStoreConstraintChecker implements ConstraintChecker { public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); } }
CloudStoreConstraintChecker implements ConstraintChecker { public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); } CloudStoreConstraintChecker(CloudStoreHelper cloudStoreHelper, ServiceHost xenonHost); }
CloudStoreConstraintChecker implements ConstraintChecker { public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); } CloudStoreConstraintChecker(CloudStoreHelper cloudStoreHelper, ServiceHost xenonHost); Map<String, ServerAddress> getCandidatesSync(
      List<ResourceConstraint> resourceConstraints,
      int numCandidates); @Override void getCandidates(
      List<ResourceConstraint> resourceConstraints,
      int numCandidates,
      GetCandidatesCompletion completion); }
CloudStoreConstraintChecker implements ConstraintChecker { public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); } CloudStoreConstraintChecker(CloudStoreHelper cloudStoreHelper, ServiceHost xenonHost); Map<String, ServerAddress> getCandidatesSync(
      List<ResourceConstraint> resourceConstraints,
      int numCandidates); @Override void getCandidates(
      List<ResourceConstraint> resourceConstraints,
      int numCandidates,
      GetCandidatesCompletion completion);  }