@Override public void handleGet(Operation get) { String template = "/offices/{location}/{site}"; Map<String, String> params = UriUtils.parseUriPathSegments(get.getUri(), template); get.setBody(params); get.complete(); } }
@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 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")); }
private void createHostInCluster(Operation post) { String clusterId = UriUtils.parseUriPathSegments(post.getUri(), CLUSTER_PATH_SEGMENT_TEMPLATE).get(CLUSTER_ID_PATH_SEGMENT); String resourcePoolDocumentSelfLink = UriUtils.buildUriPath(
private void getSingleHostInSingleCluster(Operation get) { Map<String, String> uriParams = UriUtils.parseUriPathSegments(get.getUri(), CLUSTER_PATH_SEGMENT_TEMPLATE); String clusterId = uriParams.get(CLUSTER_ID_PATH_SEGMENT); String hostId = uriParams.get(CLUSTER_HOST_ID_PATH_SEGMENT); String hostDocumentSelfLink = UriUtils.buildUriPath( ComputeService.FACTORY_LINK, hostId); sendWithDeferredResult( Operation.createGet(UriUtils.buildUri(getHost(), hostDocumentSelfLink)) .setReferer(getHost().getUri()), ComputeState.class) .thenAccept(cs -> { if (clusterId.equals(Service.getId(cs.resourcePoolLink))) { get.setBody(cs); } else { get.fail(new ServiceNotFoundException(String.format( HOST_NOT_IN_THIS_CLUSTER_EXCEPTION_TEMPLATE, hostId, clusterId))); } }) .whenCompleteNotify(get); }
private void deleteCluster(Operation delete) { String clusterId = UriUtils.parseUriPathSegments(delete.getUri(), CLUSTER_PATH_SEGMENT_TEMPLATE).get(CLUSTER_ID_PATH_SEGMENT); String pZILink = UriUtils.buildUriPath(
private void getSingleCluster(Operation get) { String clusterId = UriUtils.parseUriPathSegments(get.getUri(), CLUSTER_PATH_SEGMENT_TEMPLATE).get(CLUSTER_ID_PATH_SEGMENT); String pathPZId = UriUtils.buildUriPath( ElasticPlacementZoneConfigurationService.SELF_LINK, ResourcePoolService.FACTORY_LINK, clusterId); String projectLink = OperationUtil.extractProjectFromHeader(get); URI elasticPlacementZoneConfigurationUri = UriUtils.buildUri(getHost(), pathPZId, get.getUri().getQuery()); sendWithDeferredResult(Operation.createGet( UriUtils.buildExpandLinksQueryUri(elasticPlacementZoneConfigurationUri)) .setReferer(getUri()), ElasticPlacementZoneConfigurationState.class) .thenCompose(epzConfigState -> getInfoFromHostsWithinOnePlacementZone( projectLink, epzConfigState)) .thenAccept(clusterDto -> { if (clusterDto != null) { get.setBody(clusterDto); } }) .exceptionally(t -> { if (t != null && t.getCause() instanceof ServiceNotFoundException) { get.fail(Operation.STATUS_CODE_NOT_FOUND, t, null); } else { get.fail(t); } return null; }) .whenCompleteNotify(get); }
assertNotNullOrEmpty(dto.password, "password"); String principalId = UriUtils .parseUriPathSegments(post.getUri(), TEMPLATE_PRINCIPAL_SECURITY_CONTEXT) .get(PRINCIPAL_ID_PATH_SEGMENT);
private void deleteHostInCluster(Operation delete) { Map<String, String> uriParams = UriUtils.parseUriPathSegments(delete.getUri(), CLUSTER_PATH_SEGMENT_TEMPLATE); String clusterId = uriParams.get(CLUSTER_ID_PATH_SEGMENT);
@Override public void handlePatch(Operation patch) { try { validateClusterPatch(patch); } catch (Throwable ex) { logWarning("Failed to verify cluster PATCH: %s", Utils.toString(ex)); patch.fail(ex); return; } String clusterId = UriUtils.parseUriPathSegments(patch.getUri(), CLUSTER_PATH_SEGMENT_TEMPLATE).get(CLUSTER_ID_PATH_SEGMENT); String projectLink = OperationUtil.extractProjectFromHeader(patch); ClusterDto patchDto = patch.getBody(ClusterDto.class); patchUnderlyingPlacementZone(clusterId, patchDto) .thenCompose(epzConfigState -> getInfoFromHostsWithinOnePlacementZone(projectLink, epzConfigState)) .thenAccept(clusterDto -> propagatePublicAddressIfNeeded(patchDto, clusterDto)) .thenAccept(clusterDto -> { if (clusterDto != null) { patch.setBody(clusterDto); } }) .whenCompleteNotify(patch); }
public static void getHostsWithinPlacementZone( Operation get, ServiceHost host) { String clusterId = UriUtils.parseUriPathSegments(get.getUri(), ClusterService.CLUSTER_PATH_SEGMENT_TEMPLATE) .get(ClusterService.CLUSTER_ID_PATH_SEGMENT);