@Before public void createTestModel() throws Throwable { this.epz1 = createEpz("tag1"); this.epz2 = createEpz("tag2"); this.epz3 = createEpz(); this.cs1 = createComputeState("desc1", "addr-sof-1", null, "tag1"); this.cs2 = createComputeState("desc1", "addr-sof-2", null, "tag1"); this.cs3 = createComputeState("desc2", "addr-sof-3", null, "tag2"); this.cs4 = createComputeState("desc2", "addr-pa-4", null, "tag1", "tag2"); this.cs5 = createComputeState("desc2", "addr-pa-5", null); this.cs6 = createComputeState("desc2", "addr-pa-6", this.epz3.documentSelfLink); this.cs7 = createComputeState("desc1", "addr-sof-1", this.epz2.documentSelfLink, "tag1"); }
private ComputeState createComputeState(String desc, String address, String rpLink, String... tags) throws Throwable { ComputeState cs = new ComputeState(); cs.address = address; cs.descriptionLink = desc; cs.resourcePoolLink = rpLink; cs.type = ComputeType.VM_GUEST; cs.tagLinks = tagSet(tags); return doPost(cs, ComputeService.FACTORY_LINK); }
@Test public void testInitialEnumeration() throws Throwable { enumerateAllEpzs(); validateCompute(this.cs1, this.epz1); validateCompute(this.cs2, this.epz1); validateCompute(this.cs3, this.epz2); validateCompute(this.cs4, this.epz1, this.epz2); validateCompute(this.cs5); validateCompute(this.cs6, this.epz3); validateCompute(this.cs7, this.epz1, this.epz2); }
private void enumerateAllEpzs() throws Throwable { // run them in parallel String task1Link = startTask(this.epz1.documentSelfLink); String task2Link = startTask(this.epz2.documentSelfLink); String task3Link = startTask(this.epz3.documentSelfLink); waitFor(() -> getDocumentNoWait(EpzComputeEnumerationTaskState.class, task1Link) == null); waitFor(() -> getDocumentNoWait(EpzComputeEnumerationTaskState.class, task2Link) == null); waitFor(() -> getDocumentNoWait(EpzComputeEnumerationTaskState.class, task3Link) == null); this.cs1 = getDocument(ComputeState.class, this.cs1.documentSelfLink); this.cs2 = getDocument(ComputeState.class, this.cs2.documentSelfLink); this.cs3 = getDocument(ComputeState.class, this.cs3.documentSelfLink); this.cs4 = getDocument(ComputeState.class, this.cs4.documentSelfLink); this.cs5 = getDocument(ComputeState.class, this.cs5.documentSelfLink); this.cs6 = getDocument(ComputeState.class, this.cs6.documentSelfLink); this.cs7 = getDocument(ComputeState.class, this.cs7.documentSelfLink); }
@Test public void testEpzChanges() throws Throwable { enumerateAllEpzs(); this.epz1.epzState.tagLinksToMatch.add("tag2"); this.epz2.epzState.tagLinksToMatch.remove("tag2"); this.epz3.epzState = new ElasticPlacementZoneState(); this.epz3.epzState.resourcePoolLink = this.epz3.documentSelfLink; this.epz3.epzState.tagLinksToMatch = new HashSet<>(); this.epz3.epzState.tagLinksToMatch.addAll(Arrays.asList("tag1")); doPut(this.epz1.epzState); doPut(this.epz2.epzState); doPost(this.epz3.epzState, ElasticPlacementZoneService.FACTORY_LINK); enumerateAllEpzs(); validateCompute(this.cs1, this.epz3); validateCompute(this.cs2, this.epz3); validateCompute(this.cs3); validateCompute(this.cs4, this.epz3, this.epz1); validateCompute(this.cs5); validateCompute(this.cs6, this.epz3); }
private ElasticPlacementZoneConfigurationState createEpz(String ...tags) throws Throwable { ElasticPlacementZoneConfigurationState epz = new ElasticPlacementZoneConfigurationState(); epz.resourcePoolState = new ResourcePoolState(); epz.resourcePoolState.name = UUID.randomUUID().toString(); if (tags.length > 0) { epz.epzState = new ElasticPlacementZoneState(); epz.epzState.tagLinksToMatch = tagSet(tags); } return doOperation(epz, UriUtils.buildUri(host, ElasticPlacementZoneConfigurationService.SELF_LINK), ElasticPlacementZoneConfigurationState.class, false, Action.POST); }
private void validateCompute(ComputeState compute, ElasticPlacementZoneConfigurationState... expectedRps) { Collection<String> returnedRps = extractRpLinks(compute); assertEquals(expectedRps.length, returnedRps.size()); for (ElasticPlacementZoneConfigurationState expectedRp : expectedRps) { assertTrue(returnedRps.contains(expectedRp.documentSelfLink)); } }
private String startTask(String resourcePoolLink) throws Throwable { EpzComputeEnumerationTaskState initialState = new EpzComputeEnumerationTaskState(); initialState.resourcePoolLink = resourcePoolLink; EpzComputeEnumerationTaskState returnState = doOperation(initialState, UriUtils.buildUri(this.host, EpzComputeEnumerationTaskService.FACTORY_LINK), EpzComputeEnumerationTaskState.class, false, Action.POST); return returnState.documentSelfLink; } }