private void waitForDataCollectionFinished() throws Throwable { AtomicBoolean cotinue = new AtomicBoolean(); String dataCollectionLink = DEFAULT_HOST_CONTAINER_LIST_DATA_COLLECTION_LINK; waitFor(() -> { ServiceDocumentQuery<HostContainerListDataCollectionState> query = new ServiceDocumentQuery<>(host, HostContainerListDataCollectionState.class); query.queryDocument( dataCollectionLink, (r) -> { if (r.hasException()) { host.log("Exception while retrieving default host container list data" + " collection: " + (r.getException() instanceof CancellationException ? r.getException().getMessage() : Utils.toString(r.getException()))); cotinue.set(true); } else if (r.hasResult()) { if (r.getResult().containerHostLinks.isEmpty()) { cotinue.set(true); } } }); return cotinue.get(); }); }
private ContainerState waitForContainer(String containerLink, String image, PowerState expectedPowerState, String errorMessage) throws Throwable { ContainerState[] result = new ContainerState[1]; AtomicBoolean cotinue = new AtomicBoolean(); waitFor(errorMessage, () -> { ServiceDocumentQuery<ContainerState> query = new ServiceDocumentQuery<>(host, ContainerState.class); query.queryDocument(containerLink, (r) -> { if (r.hasException()) { host.log("Exception while retrieving ContainerState: " + (r.getException() instanceof CancellationException ? r.getException() .getMessage() : Utils.toString(r.getException()))); cotinue.set(true); } else if (r.hasResult()) { // wait until container is ready with the expected image if (r.getResult().id != null && image.equals(r.getResult().image)) { if (expectedPowerState == null || expectedPowerState == r.getResult().powerState) { cotinue.set(true); result[0] = r.getResult(); } } } }); return cotinue.get(); }); return result[0]; }
private void addContainerToMockAdapter(String hostLink, String containerId, String containerName, String containerImage, PowerState powerState, List<String> tenantLinks) throws Throwable { MockDockerContainerToHostState mockContainerToHostState = new MockDockerContainerToHostState(); mockContainerToHostState.documentSelfLink = UriUtils.buildUriPath( MockDockerContainerToHostService.FACTORY_LINK, UUID.randomUUID().toString()); mockContainerToHostState.parentLink = hostLink; mockContainerToHostState.id = containerId; mockContainerToHostState.name = containerName; mockContainerToHostState.image = containerImage; mockContainerToHostState.powerState = powerState; mockContainerToHostState.tenantLinks = tenantLinks; host.sendRequest(Operation.createPost(host, MockDockerContainerToHostService.FACTORY_LINK) .setBody(mockContainerToHostState) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { host.log("Cannot create mock container to host state. Error: %s", e.getMessage()); } })); // wait until container to host is created in the mock adapter waitFor(() -> { getDocument(MockDockerContainerToHostState.class, mockContainerToHostState.documentSelfLink); return true; }); } }