use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.
the class TestUtils method doPost.
/**
* Generic doPost.
*
* @param host VerificationHost
* @param inState Body to POST
* @param type Body type to return
* @param uri URI to post to
* @param <T> type
* @return State of service after POST
* @throws Throwable
*/
public static <T extends ServiceDocument, B extends ServiceDocument> B doPost(VerificationHost host, T inState, Class<B> type, URI uri) throws Throwable {
final ServiceDocument[] doc = { null };
host.testStart(1);
Operation post = Operation.createPost(uri).setBody(inState).setCompletion((o, e) -> {
if (e != null) {
host.failIteration(e);
return;
}
doc[0] = o.getBody(ServiceDocument.class);
host.completeIteration();
});
host.send(post);
host.testWait();
host.logThroughput();
B outState = host.getServiceState(null, type, UriUtils.buildUri(uri.getHost(), uri.getPort(), doc[0].documentSelfLink, null));
return outState;
}
use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.
the class TestUtils method doPost.
/**
* Generic doPost.
*
* @param host VerificationHost
* @param type Body type to return
* @param uri URI to post to
* @param <T> type
* @return State of service after POST
* @throws Throwable
*/
public static <T extends ServiceDocument, B extends ServiceDocument> B doPost(VerificationHost host, Class<B> type, URI uri) throws Throwable {
final ServiceDocument[] doc = { null };
host.testStart(1);
Operation post = Operation.createPost(uri).setCompletion((o, e) -> {
if (e != null) {
host.failIteration(e);
return;
}
doc[0] = o.getBody(ServiceDocument.class);
host.completeIteration();
});
host.send(post);
host.testWait();
host.logThroughput();
B outState = host.getServiceState(null, type, UriUtils.buildUri(uri.getHost(), uri.getPort(), doc[0].documentSelfLink, null));
return outState;
}
use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.
the class ComputeService method getDocumentTemplate.
@Override
public ServiceDocument getDocumentTemplate() {
ServiceDocument td = super.getDocumentTemplate();
// enable metadata indexing
td.documentDescription.documentIndexingOptions = EnumSet.of(DocumentIndexingOption.INDEX_METADATA);
ServiceUtils.setRetentionLimit(td);
ComputeState template = (ComputeState) td;
template.id = UUID.randomUUID().toString();
template.primaryMAC = "01:23:45:67:89:ab";
template.descriptionLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, "on-prem-one-cpu-vm-guest");
template.resourcePoolLink = null;
template.type = ComputeType.VM_GUEST;
template.environmentName = ENVIRONMENT_NAME_ON_PREMISE;
template.adapterManagementReference = URI.create("https://esxhost-01:443/sdk");
return template;
}
use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.
the class ResourceOperationSpecService method getDocumentTemplate.
@Override
public ServiceDocument getDocumentTemplate() {
ServiceDocument template = super.getDocumentTemplate();
ServiceUtils.setRetentionLimit(template);
return template;
}
use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.
the class AzureTestUtil method assertResourceDisassociated.
/**
* Assert that a resource with the provided name exist in the document store.
*
* @param factoryLink
* Factory link to the stateful service which states to check.
* @param name
* name of the resource to assert if exists.
* @param isDisassociated
* whether to assert if a resource exists or not.
*/
public static void assertResourceDisassociated(VerificationHost host, String factoryLink, String name, boolean isDisassociated) {
ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, factoryLink));
boolean disassociated = false;
for (Object document : result.documents.values()) {
// Read doc as ServiceDocument to access its 'documentKind'
ServiceDocument serviceDoc = Utils.fromJson(document, ServiceDocument.class);
Class<? extends ResourceState> resourceClass = ENDPOINT_LINK_EXPLICIT_SUPPORT.stream().filter(clazz -> serviceDoc.documentKind.equals(Utils.buildKind(clazz))).findFirst().orElse(null);
if (resourceClass != null) {
// Read doc as ResourceState to access its 'endpointLinks'
ResourceState resource = Utils.fromJson(document, resourceClass);
if (Objects.equals(name, resource.name) && resource.endpointLinks.isEmpty()) {
String endpointLink = PhotonModelUtils.getEndpointLink(resource);
if (endpointLink == null || endpointLink.isEmpty()) {
disassociated = true;
break;
}
}
}
}
assertEquals("isDisassociated", isDisassociated, disassociated);
}
Aggregations