use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class TestAWSSetupUtils method getComputeByAWSId.
/**
* Lookup a Compute by aws Id
*/
public static ComputeState getComputeByAWSId(VerificationHost host, String awsId) throws Throwable {
URI computesURI = UriUtils.buildUri(host, ComputeService.FACTORY_LINK);
computesURI = UriUtils.buildExpandLinksQueryUri(computesURI);
computesURI = UriUtils.appendQueryParam(computesURI, "$filter", String.format("id eq %s", awsId));
Operation op = host.waitForResponse(Operation.createGet(computesURI));
ServiceDocumentQueryResult result = op.getBody(ServiceDocumentQueryResult.class);
assertNotNull(result);
assertNotNull(result.documents);
assertEquals(1, result.documents.size());
return Utils.fromJson(result.documents.values().iterator().next(), ComputeState.class);
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class TestAWSSetupUtils method getLoadBalancerByAWSId.
/**
* Lookup a Load Balancer by aws Id
*/
public static LoadBalancerState getLoadBalancerByAWSId(VerificationHost host, String awsId) throws Throwable {
URI lbURI = UriUtils.buildUri(host, LoadBalancerService.FACTORY_LINK);
lbURI = UriUtils.buildExpandLinksQueryUri(lbURI);
lbURI = UriUtils.appendQueryParam(lbURI, "$filter", String.format("id eq %s", awsId));
Operation op = host.waitForResponse(Operation.createGet(lbURI));
ServiceDocumentQueryResult result = op.getBody(ServiceDocumentQueryResult.class);
assertNotNull(result);
assertNotNull(result.documents);
assertEquals(1, result.documents.size());
return Utils.fromJson(result.documents.values().iterator().next(), LoadBalancerState.class);
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class TestAWSMissingEnumerationResourcesService method verifyLinkedAccountsCreation.
private void verifyLinkedAccountsCreation(Request request, int expectedCount) {
this.host.waitFor("Timeout while waiting for verifyLinkedAccountsCreation()", () -> {
ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(getQuerySpecForComputeStates(request), expectedCount, expectedCount);
Collection<Object> values = result.documents.values();
if (values.size() != expectedCount) {
return false;
}
for (Object computeState : result.documents.values()) {
ComputeState cs = Utils.fromJson(computeState, ComputeState.class);
if (!cs.descriptionLink.equals(linkedAccountDescriptions.get(cs.name).documentSelfLink)) {
return false;
}
if (!cs.endpointLink.equals(request.primaryAccountCompute.endpointLink)) {
return false;
}
if (cs.creationTimeMicros == null) {
return false;
}
}
return true;
});
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class TestAWSEnumerationTask method validateTagInEntity.
/**
* Validates that the given internal tag is present on the passed in entity.
*/
private void validateTagInEntity(ServiceDocumentQueryResult queryResult, Class<?> documentKind, String internalTagType) {
ServiceDocumentQueryResult tagsResult;
String tagLink;
tagsResult = getInternalTagsByType(this.host, internalTagType);
assertEquals(count1, tagsResult.documentLinks.size());
tagLink = tagsResult.documentLinks.get(0);
for (Map.Entry<String, Object> resourceMap : queryResult.documents.entrySet()) {
if (documentKind == ComputeState.class) {
ComputeState compute = Utils.fromJson(resourceMap.getValue(), ComputeState.class);
if (!compute.type.equals(ComputeType.ZONE) && !compute.type.equals(ComputeType.ENDPOINT_HOST)) {
assertTrue(compute.tagLinks.contains(tagLink));
}
} else {
ResourceState resourceState = Utils.fromJson(resourceMap.getValue(), ResourceState.class);
if (resourceState.tagLinks != null) {
assertTrue(resourceState.tagLinks.contains(tagLink));
}
}
}
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class BaseTestCase method verifyService.
protected void verifyService(URI factoryUri, FactoryService factoryInstance, Class<? extends ServiceDocument> serviceDocumentType, TestServiceDocumentInitialization serviceDocumentInit, TestServiceDocumentAssertion assertion) throws Throwable {
int childCount = 1;
TestContext ctx = testCreate(childCount);
String prefix = "example-";
URI[] childURIs = new URI[childCount];
for (int i = 0; i < childCount; i++) {
ServiceDocument serviceDocument = serviceDocumentInit.create(prefix, i);
final int finalI = i;
// create a ServiceDocument instance.
Operation createPost = createForcedPost(factoryUri).setBody(serviceDocument).setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ServiceDocument rsp = o.getBody(serviceDocumentType);
childURIs[finalI] = UriUtils.buildUri(this.host, rsp.documentSelfLink);
ctx.completeIteration();
});
this.host.send(createPost);
}
try {
// verify factory and service instance wiring.
factoryInstance.setHost(this.host);
Service serviceInstance = factoryInstance.createServiceInstance();
serviceInstance.setHost(this.host);
assertNotNull(serviceInstance);
ctx.await();
// do GET on all child URIs
Map<URI, ? extends ServiceDocument> childStates = this.host.getServiceState(null, serviceDocumentType, childURIs);
for (ServiceDocument s : childStates.values()) {
assertion.assertState(prefix, s);
}
// verify template GET works on factory
ServiceDocumentQueryResult templateResult = this.host.getServiceState(null, ServiceDocumentQueryResult.class, UriUtils.extendUri(factoryUri, ServiceHost.SERVICE_URI_SUFFIX_TEMPLATE));
assertTrue(templateResult.documentLinks.size() == templateResult.documents.size());
ServiceDocument childTemplate = Utils.fromJson(templateResult.documents.get(templateResult.documentLinks.iterator().next()), serviceDocumentType);
assertTrue(childTemplate.documentDescription != null);
assertTrue(childTemplate.documentDescription.propertyDescriptions != null && childTemplate.documentDescription.propertyDescriptions.size() > 0);
} catch (Throwable t) {
if (t instanceof RuntimeException) {
throw t;
}
throw new RuntimeException(t);
}
}
Aggregations