private void getCompute(Operation op, String hostLink, Consumer<ComputeState> consumer) { Operation.createGet(this, hostLink).setCompletion((o, e) -> { if (e != null) { op.fail(e); return; } consumer.accept(o.getBody(ComputeState.class)); }).sendWith(this); } }
private void sendHostServiceRequest(Object body, URI adapterReference) { sendRequest(Operation.createPatch(adapterReference).setBody(body) .setCompletion((o, e) -> { if (e != null) { failTask(e); return; } })); }
private void getConfigProperty(String propName, Consumer<ConfigurationState> callback) { sendRequest(Operation .createGet(getHost(), UriUtils.buildUriPath(CONFIG_PROPS, propName)) .setCompletion((res, ex) -> { if (ex == null && res.hasBody()) { ConfigurationState body = res.getBody(ConfigurationState.class); callback.accept(body); } })); }
private void patchKubernetesEntity(RequestContext context, Operation inspectResponse, CompletionHandler handler) { String jsonResponse = inspectResponse.getBody(String.class); BaseKubernetesState newState = null; try { newState = context.kubernetesState.getClass().newInstance(); newState.setKubernetesEntityFromJson(jsonResponse); } catch (Throwable ex) { fail(context.request, ex); } sendRequest(Operation.createPatch(this, context.kubernetesState.documentSelfLink) .setBody(newState) .setCompletion(handler)); } }
private void startAndWaitHostNetworkListDataCollection() throws Throwable { host.testStart(1); host.sendRequest(Operation .createPatch(UriUtils.buildUri(host, HostNetworkListDataCollection.DEFAULT_HOST_NETWORK_LIST_DATA_COLLECTION_LINK)) .setBody(networkListCallback) .setReferer(host.getUri()) .setCompletion(host.getCompletion())); host.testWait(); // Wait for data collection to finish waitForDataCollectionFinished(); }
private ContainerDescription patchContainerDescription(ContainerDescription containerDescription) { List<ContainerDescription> result = new LinkedList<>(); Operation op = Operation.createPatch(UriUtils.buildUri(host,containerDescription.documentSelfLink)) .setBody(containerDescription) .setCompletion((o, e) -> { if (e != null) { host.failIteration(e); } result.add(o.getBody(ContainerDescription.class)); host.completeIteration(); }); host.testStart(1); host.send(op); host.testWait(); return result.get(0); }
void doHealthCheck(ServiceHost host, String containerDescriptionLink) { host.sendRequest(Operation .createGet(host, containerDescriptionLink) .setReferer(UriUtils.buildUri(host, SERVICE_REFERRER_PATH)) .setCompletion((o, ex) -> { if (ex != null) { host.log(Level.SEVERE, "Failed to fetch %s : %s", containerDescriptionLink, Utils.toJson(ex)); } else { processContainerHealth(host, o.getBody(ContainerDescription.class)); } })); }
public Operation createServiceStartPost(TestContext ctx) { Operation post = Operation.createPost(null); post.setUri(UriUtils.buildUri(this, "service/" + post.getId())); return post.setCompletion(ctx.getCompletion()); }
private void getExternalPopularImages(Operation get, Runnable notFoundHandler) { sendRequest(Operation.createGet(UriUtils.buildUri(getHost(), EXTERNAL_LINK)) .setCompletion((op, ex) -> { if (ex != null || op.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) { notFoundHandler.run(); } else { get.setBody(op.getBodyRaw()); get.setStatusCode(op.getStatusCode()); get.setContentType(Operation.MEDIA_TYPE_APPLICATION_JSON); get.complete(); } })); }
@Test public void systemUser() throws Throwable { URI uri = UriUtils.buildUri(this.host, SystemUserService.SELF_LINK); Operation get = Operation .createGet(uri) .setCompletion(this.host.getCompletion()); this.host.testStart(1); this.host.send(get); this.host.testWait(); } }
private void doDelete(VerificationHost h, String documentSelfLink, Consumer<Throwable> callback) { this.host.send(Operation.createDelete( UriUtils.buildUri(h, documentSelfLink)) .setBody(new ExampleServiceState()) .setCompletion( (o, e) -> { if (e != null) { callback.accept(e); } else { callback.accept(null); } })); }
private PlacementHostSelectionTaskState startPlacementTask( PlacementHostSelectionTaskState placementTask, boolean expectError) throws Throwable { PlacementHostSelectionTaskState[] result = new PlacementHostSelectionTaskState[] { null }; host.testStart(1); host.sendRequest(Operation.createPost(host, PlacementHostSelectionTaskService.FACTORY_LINK) .setBody(placementTask) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { host.failIteration(e); return; } result[0] = o.getBody(PlacementHostSelectionTaskState.class); host.completeIteration(); })); host.testWait(); return result[0]; }
private void postEventlogError(ComputeState hostState, String message) { EventLogState eventLog = new EventLogState(); eventLog.description = message == null ? "Unexpected error" : message; eventLog.eventLogType = EventLogType.ERROR; eventLog.resourceType = getClass().getName(); eventLog.tenantLinks = hostState.tenantLinks; sendRequest(Operation.createPost(this, EventLogService.FACTORY_LINK) .setBody(eventLog) .setCompletion((o, e) -> { if (e != null) { logWarning("Failed to create event log: %s", Utils.toString(e)); } })); }
private DeferredResult<ComputeState> requestComputeState(String selfLink) { URI uri = UriUtils.buildUri(host, selfLink); Operation op = Operation.createGet(uri) .setCompletion((o, e) -> { if (e != null) { logger.warning(String.format("Failed to retrieve compute state: [%s]", Utils.toString(e))); return; } }); prepareRequest(op, false); return host.sendWithDeferredResult(op, ComputeState.class); }
private void delete(URI uri) throws Throwable { this.host.testStart(1); this.host.sendRequest(Operation .createDelete(uri) .setBody(new ServiceDocument()) .setCompletion(this.host.getCompletion()) .setReferer(this.host.getUri())); this.host.testWait(); }
@Override public void handleMaintenance(Operation op) { logFine("Maintenance called"); sendRequest(Operation.createGet(getUri()).setCompletion( (o, e) -> performMaintenance(op, o, e))); }
private void doPost(VerificationHost h, ExampleServiceState doc, Consumer<Throwable> callback) { h.send(Operation .createPost(this.factoryUri) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_FORCE_INDEX_UPDATE) .setBody(doc) .setCompletion((o, e) -> { if (e != null) { callback.accept(e); } else { callback.accept(null); } })); }
private void startAndWaitHostVolumeListDataCollection() throws Throwable { host.testStart(1); host.sendRequest(Operation .createPatch(UriUtils.buildUri(host, HostVolumeListDataCollection.DEFAULT_HOST_VOLUME_LIST_DATA_COLLECTION_LINK)) .setBody(volumeListCallback) .setReferer(host.getUri()) .setCompletion(host.getCompletion())); host.testWait(); // Wait for data collection to finish waitForDataCollectionFinished(); }
public void doPatch(EnumSet<TestProperty> props, int c, ServiceDocumentQueryResult initialStates, TenantService.TenantState patchBody) throws Throwable { this.host.testStart(c); for (String link : initialStates.documentLinks) { Operation patch = Operation.createPatch(UriUtils.buildUri(this.host, link)) .setBody(patchBody) .setCompletion(this.host.getCompletion()); if (props.contains(TestProperty.FORCE_REMOTE)) { patch.forceRemote(); } this.host.send(patch); } this.host.testWait(); }
private void getClusterDto(String clusterLink, Consumer<ClusterService.ClusterDto> consumer) { Operation.createGet(this, clusterLink) .setCompletion((o, e) -> { if (e != null) { failTask("Failed to get cluster " + clusterLink, e); return; } consumer.accept(o.getBody(ClusterService.ClusterDto.class)); }) .sendWith(this); }