use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestVSphereDiskService method getStoragePolicyLink.
private String getStoragePolicyLink() {
QueryTask.Query.Builder builder = QueryTask.Query.Builder.create().addKindFieldClause(ResourceGroupState.class);
builder.addFieldClause(ResourceGroupState.FIELD_NAME_ID, this.spId);
builder.addCaseInsensitiveFieldClause(StorageDescriptionService.StorageDescription.FIELD_NAME_NAME, this.spName, QueryTask.QueryTerm.MatchType.TERM, QueryTask.Query.Occurance.MUST_OCCUR);
QueryTask task = QueryTask.Builder.createDirectTask().setQuery(builder.build()).build();
Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
return result.results.documentLinks.get(0);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestVSphereEnumerationTask method testGetAvailableRegions.
@Test
public void testGetAvailableRegions() throws Throwable {
Assume.assumeFalse(isMock());
startAdditionalServices();
this.host.waitForServiceAvailable(VSphereUriPaths.VSPHERE_REGION_ENUMERATION_ADAPTER_SERVICE);
URI uri = UriUtils.buildUri(ServiceHost.LOCAL_HOST, host.getPort(), UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(PhotonModelConstants.EndpointType.vsphere.toString().toLowerCase()), null);
Operation post = Operation.createPost(uri);
post.setBody(createEndpoint((a) -> {
}, (b) -> {
}));
Operation operation = host.getTestRequestSender().sendAndWait(post);
RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
assertTrue(!result.regions.isEmpty());
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestVSphereEnumerationTask method testRefresh.
@Test
public void testRefresh() throws Throwable {
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
// Always create endpoint, so that there is no bogus
// endpointLink. This enumeration task is started on a real
// endpoint. This will also help tango based adapters
// as the existence of endpoint is more critical there to
// extract data collector identifier.
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
refreshAndRetire();
if (!isMock()) {
ComputeState vm = findRandomVm();
assertInternalPropertiesSet(vm);
assertNotNull(vm.endpointLink);
assertNotNull(vm.tenantLinks);
}
captureFactoryState("initial");
String aComputeLink = null;
String anUsedHostLink = null;
String anUnusedHostLink = null;
if (!isMock()) {
// clone a random compute and save it under different id
ComputeState randVm = findRandomVm();
ComputeState vm = Utils.clone(randVm);
vm.documentSelfLink = null;
vm.id = "fake-vm-" + vm.id;
vm.documentSelfLink = null;
vm = TestUtils.doPost(this.host, vm, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
aComputeLink = vm.documentSelfLink;
ComputeState randomHost = findRandomHost();
{
ComputeState host = Utils.clone(randomHost);
host.documentSelfLink = null;
host.powerState = PowerState.ON;
host.id = "fake-host-" + host.id;
host.documentSelfLink = null;
host = TestUtils.doPost(this.host, host, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
anUsedHostLink = host.documentSelfLink;
ComputeState update = new ComputeState();
update.customProperties = new HashMap<>();
update.customProperties.put(ComputeProperties.PLACEMENT_LINK, host.documentSelfLink);
TestUtils.doPatch(this.host, update, ComputeState.class, UriUtils.buildUri(this.host, randVm.documentSelfLink));
}
{
ComputeState host = Utils.clone(randomHost);
host.documentSelfLink = null;
host.powerState = PowerState.ON;
host.id = "fake-host-unused" + host.id;
host.documentSelfLink = null;
host = TestUtils.doPost(this.host, host, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
anUnusedHostLink = host.documentSelfLink;
}
}
// do a second refresh to test update path
refreshAndRetire();
captureFactoryState("updated");
snapshotFactoryState("metrics", ResourceMetricsService.class);
if (aComputeLink != null) {
// the second enumeration marked the fake vm as retired
Operation op = Operation.createGet(this.host, aComputeLink);
op = this.host.waitForResponse(op);
ComputeState compute = op.getBody(ComputeState.class);
assertEquals(compute.lifecycleState, LifecycleState.RETIRED);
assertEquals(PowerState.OFF, compute.powerState);
}
if (anUsedHostLink != null) {
// the second enumeration marked the fake vm as retired
Operation op = Operation.createGet(this.host, anUsedHostLink);
op = this.host.waitForResponse(op);
ComputeState compute = op.getBody(ComputeState.class);
assertEquals(compute.lifecycleState, LifecycleState.RETIRED);
assertEquals(PowerState.OFF, compute.powerState);
}
if (anUnusedHostLink != null) {
// the unused host is wiped out unconditionally
Operation op = Operation.createGet(this.host, anUnusedHostLink);
op = this.host.waitForResponse(op);
assertEquals(op.getStatusCode(), 404);
}
verifyDatastoreAndStoragePolicy();
if (!isMock()) {
verifyCIGapForComputeResourcesAndVMs();
verifyCIGapForDatacenterOrFolder(VimNames.TYPE_DATACENTER);
verifyCIGapForDatacenterOrFolder(VimNames.TYPE_FOLDER);
verifyCIGapForDatastore();
verifyCIGapForComputeResource();
}
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestVSphereEnumerationTask method withTaskResults.
private void withTaskResults(QueryTask task, Consumer<ServiceDocumentQueryResult> handler) {
task.querySpec.options = EnumSet.of(QueryOption.EXPAND_CONTENT);
task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(QUERY_TASK_EXPIRY_MICROS);
Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
handler.accept(result.results);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestVSphereCloneTaskBase method findFirstNetwork.
private String findFirstNetwork() {
QueryTask.Query q = QueryTask.Query.Builder.create().addFieldClause(ServiceDocument.FIELD_NAME_KIND, Utils.buildKind(NetworkService.NetworkState.class)).addCompositeFieldClause(NetworkService.NetworkState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.TYPE, VimNames.TYPE_NETWORK).build();
QueryTask task = QueryTask.Builder.createDirectTask().setQuery(q).build();
Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
Operation result = this.host.waitForResponse(op);
try {
return result.getBody(QueryTask.class).results.documentLinks.get(0);
} catch (Exception e) {
result.fail(e);
Assert.fail(e.getMessage());
// never gets here
return null;
}
}
Aggregations