public static Operation createDefaultPostOp( ServiceHost host) { LoaderServiceState d = new LoaderServiceState(); d.documentSelfLink = LoaderService.FILESYSTEM_DEFAULT_GROUP; d.loaderType = LoaderService.LoaderType.FILESYSTEM; d.path = LoaderService.FILESYSTEM_DEFAULT_PATH; d.servicePackages = new HashMap<String, LoaderService.LoaderServiceInfo>(); return Operation .createPost(UriUtils.buildUri(host, LoaderFactoryService.class)) .setBody(d); }
private DeferredResult patchComputeState(String documentSelfLink, ComputeState computeState) { URI uri = UriUtils.buildUri(host, documentSelfLink); Operation op = Operation.createPatch(uri) .setBody(computeState) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { logger.warning(String.format("Failed to patch compute state: [%s]", Utils.toString(e))); return; } logger.info(String.format("Successfully patched compute state [%s]", documentSelfLink)); }); return host.sendWithDeferredResult(op); }
@Test public void buildUriFromString() throws Throwable { assertEquals(null, UriUtils.buildUri("http://finance.yahoo.com/q/h?s=^IXIC")); assertEquals(new URI(""), UriUtils.buildUri("")); assertEquals(new URI("http://example.com/example"), UriUtils.buildUri("http://example.com/example")); assertEquals(new URI("/one/two/three"), UriUtils.buildUri("/one/two/three")); }
@Test public void testSimplePathParamParsing() { String template = "/vmware/offices/{location}/sites/{site}"; URI u = UriUtils.buildUri("http://example.com:8000/vmware/offices/pa/sites/prom-e"); Map<String, String> pathParams = UriUtils.parseUriPathSegments(u, template); assertEquals(2, pathParams.size()); assertTrue(pathParams.keySet().contains("location")); assertTrue(pathParams.keySet().contains("site")); assertTrue(pathParams.get("location").equals("pa")); assertTrue(pathParams.get("site").equals("prom-e")); }
@Test public void testTenantLinksInODataQuery() { Operation inputOp = new Operation(); URI queryUri = UriUtils.buildUri("foo.com", 80, "/", "$tenantLinks=/links/foo, bar"); inputOp.setUri(queryUri); QueryTask resultTask = ODataUtils.toQuery(inputOp, true); assertTrue(resultTask.tenantLinks.contains("/links/foo")); assertTrue(resultTask.tenantLinks.contains("bar")); } }
@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 sendSelfPatch(SshCommandTaskState state, TaskStage stage, Map<String, String> commandResponse, Throwable t) { SshCommandTaskState patch = new SshCommandTaskState(); patch.taskInfo = new TaskState(); patch.taskInfo.stage = stage; patch.commandResponse = commandResponse; if (t != null) { patch.taskInfo.failure = Utils.toServiceErrorResponse(t); } Operation patchOperation = Operation.createPatch( UriUtils.buildUri(getHost(), state.documentSelfLink)).setBody( patch); sendRequest(patchOperation); }
private void startAllocationTask(ContainerAllocationTaskState allocationTask) { URI uri = UriUtils.buildUri(getHost(), ContainerAllocationTaskFactoryService.SELF_LINK); sendRequest(OperationUtil.createForcedPost(uri) .setBody(allocationTask) .setCompletion((o, e) -> { if (e != null) { logSevere("Exception while submitting allocation closure: %s", Utils.toString(e)); return; } logInfo("Allocation closure submitted successfully"); })); }
public Operation createServiceStartPost(TestContext ctx) { Operation post = Operation.createPost(null); post.setUri(UriUtils.buildUri(this, "service/" + post.getId())); return post.setCompletion(ctx.getCompletion()); }
public static void stopContinuousQuerySubscription(TestRequestSender s, ServiceHost host, URI notificationTarget, QueryTask qt) { TestContext ctx = new TestContext(1, s.getTimeout()); Operation delete = Operation .createDelete(UriUtils.buildUri(notificationTarget, qt.documentSelfLink)) .setReferer(host.getUri()) .setCompletion(ctx.getCompletion()); host.stopSubscriptionService(delete, notificationTarget); ctx.await(); }
@Test public void testSimplePathParamParsing() { String template = "/vmware/offices/{location}/sites/{site}"; URI u = UriUtils.buildUri("http://example.com:8000/vmware/offices/pa/sites/prom-e"); Map<String, String> pathParams = UriUtils.parseUriPathSegments(u, template); assertEquals(2, pathParams.size()); assertTrue(pathParams.keySet().contains("location")); assertTrue(pathParams.keySet().contains("site")); assertTrue(pathParams.get("location").equals("pa")); assertTrue(pathParams.get("site").equals("prom-e")); }
@Test public void testTenantLinksInODataQuery() { Operation inputOp = new Operation(); URI queryUri = UriUtils.buildUri("foo.com", 80, "/", "$tenantLinks=/links/foo, bar"); inputOp.setUri(queryUri); QueryTask resultTask = ODataUtils.toQuery(inputOp, true); assertTrue(resultTask.tenantLinks.contains("/links/foo")); assertTrue(resultTask.tenantLinks.contains("bar")); } }
private void updateContainerHostInfo(String documentSelfLink) { URI uri = UriUtils.buildUri(getHost(), ContainerHostDataCollectionService.HOST_INFO_DATA_COLLECTION_LINK); ContainerHostDataCollectionState state = new ContainerHostDataCollectionState(); state.createOrUpdateHost = true; state.computeContainerHostLinks = Collections.singleton(documentSelfLink); sendRequest(Operation.createPatch(uri) .setBody(state) .setCompletion((o, ex) -> { if (ex != null) { logWarning("Failed to update host data collection: %s", ex.getMessage()); } })); }
@Test public void testPATCH() throws Throwable { sslTrustCert = doPost(sslTrustCert, SslTrustCertificateService.FACTORY_LINK); sslTrustCert.certificate = sslTrust2; boolean expectedFailure = false; URI uri = UriUtils.buildUri(host, sslTrustCert.documentSelfLink); doOperation(sslTrustCert, uri, expectedFailure, Action.PATCH); SslTrustCertificateState updatedSslTrustCert = getDocument(SslTrustCertificateState.class, sslTrustCert.documentSelfLink); assertEquals(sslTrust2, updatedSslTrustCert.certificate); validateCertProperties(updatedSslTrustCert); }
private void sendSelfPatch(SshCommandTaskState state, TaskStage stage, Map<String, String> commandResponse, Throwable t) { SshCommandTaskState patch = new SshCommandTaskState(); patch.taskInfo = new TaskState(); patch.taskInfo.stage = stage; patch.commandResponse = commandResponse; if (t != null) { patch.taskInfo.failure = Utils.toServiceErrorResponse(t); } Operation patchOperation = Operation.createPatch( UriUtils.buildUri(getHost(), state.documentSelfLink)).setBody( patch); sendRequest(patchOperation); }
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(); } })); }
public static Operation createNodeGroupPostOp( ServiceHost host, String groupName) { ServiceDocument d = new ServiceDocument(); d.documentSelfLink = groupName; return Operation .createPost(UriUtils.buildUri(host, NodeGroupFactoryService.class)) .setBody(d); }
@Override public Operation createServiceStartPost(TestContext ctx) { if (!enablePostgres) { return super.createServiceStartPost(ctx); } Operation post = Operation.createPost(null); post.setUri(UriUtils.buildUri(this, createServiceFactoryLink + "/" + post.getId())); return post.setCompletion(ctx.getCompletion()); }
@Test public void testParseUriQueryParams() { URI u = UriUtils.buildUri("http://example.com:8000/?a=b&c=d&d&e=f=g&h=&=z"); Map<String, String> queryParams = UriUtils.parseUriQueryParams(u); assertEquals(5, queryParams.size()); assertTrue(queryParams.get("a").equals("b")); assertTrue(queryParams.get("c").equals("d")); assertTrue(queryParams.get("d").equals("")); assertTrue(queryParams.get("e").equals("f=g")); assertTrue(queryParams.get("h").equals("")); }
@Test public void completeOk() throws InterruptedException, ExecutionException { CompletableFuture<Operation> f = this.host.sendWithFuture(Operation .createGet(UriUtils.buildUri(this.host, "/"))); // callback with only a success branch ServiceDocumentQueryResult body = f.get().getBody(ServiceDocumentQueryResult.class); assertTrue(body.documentLinks.size() > 0); }