use of com.vmware.xenon.services.common.QueryTask.QuerySpecification in project photon-model by vmware.
the class TestVSphereProvisionWithStaticIpTask method findTemplate.
private ComputeState findTemplate() throws InterruptedException, ExecutionException, TimeoutException {
String templateVmName = System.getProperty("vc.templateVmName");
QuerySpecification qs = new QuerySpecification();
qs.options.add(QueryOption.EXPAND_CONTENT);
qs.query.addBooleanClause(Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_NAME, templateVmName).addFieldClause(ServiceDocument.FIELD_NAME_KIND, Utils.buildKind(ComputeState.class)).build());
QueryTask qt = QueryTask.create(qs).setDirect(true);
Operation op = QueryUtils.createQueryTaskOperation(this.host, qt, ServiceTypeCluster.INVENTORY_SERVICE);
QueryTask result = this.host.sendWithFuture(op).thenApply(o -> o.getBody(QueryTask.class)).get(10, TimeUnit.SECONDS);
return Utils.fromJson(result.results.documents.values().iterator().next(), ComputeState.class);
}
use of com.vmware.xenon.services.common.QueryTask.QuerySpecification in project photon-model by vmware.
the class AWSPowerServiceTest method tearDown.
@After
public void tearDown() throws Throwable {
Query resourceQuery = Query.Builder.create().addKindFieldClause(ComputeState.class).addInClause(ComputeState.FIELD_NAME_SELF_LINK, this.computesToRemove).build();
QuerySpecification qSpec = new QuerySpecification();
qSpec.query = resourceQuery;
ResourceRemovalTaskState state = new ResourceRemovalTaskState();
state.isMockRequest = this.isMock;
state.resourceQuerySpec = qSpec;
ResourceRemovalTaskState removalTaskState = TestUtils.doPost(this.host, state, ResourceRemovalTaskState.class, UriUtils.buildUri(this.host, ResourceRemovalTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(ResourceRemovalTaskState.class, removalTaskState.documentSelfLink);
if (this.deleteResourcesFlag) {
this.awsTestContext.put(TestAWSSetupUtils.DELETE_RESOURCES_KEY, TestAWSSetupUtils.DELETE_RESOURCES_KEY);
}
tearDownTestVpc(this.client, this.host, this.awsTestContext, this.isMock);
this.client.shutdown();
}
use of com.vmware.xenon.services.common.QueryTask.QuerySpecification in project photon-model by vmware.
the class BaseVSphereAdapterTest method deleteVmAndWait.
protected void deleteVmAndWait(ComputeState vm) {
try {
ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
deletionState.isMockRequest = isMock();
QuerySpecification resourceQuerySpec = new QuerySpecification();
resourceQuerySpec.query.setTermPropertyName(ServiceDocument.FIELD_NAME_SELF_LINK).setTermMatchValue(vm.documentSelfLink);
deletionState.resourceQuerySpec = resourceQuerySpec;
ResourceRemovalTaskState outDelete = TestUtils.doPost(this.host, deletionState, ResourceRemovalTaskState.class, UriUtils.buildUri(this.host, ResourceRemovalTaskService.FACTORY_LINK));
awaitTaskEnd(outDelete);
} catch (Throwable e) {
this.host.log("Error deleting VM %s", e.getMessage());
}
}
use of com.vmware.xenon.services.common.QueryTask.QuerySpecification in project photon-model by vmware.
the class AzureLoadBalancerServiceTest method deleteVirtualMachines.
private void deleteVirtualMachines() {
List<ResourceRemovalTaskState> removeTaskStates = this.vmStates.stream().map(vmState -> {
getHost().log(Level.INFO, "%s: Deleting [%s] VM", this.currentTestName.getMethodName(), vmState.name);
try {
QuerySpecification resourceQuerySpec = new QuerySpecification();
resourceQuerySpec.query.setTermPropertyName(ServiceDocument.FIELD_NAME_SELF_LINK).setTermMatchValue(vmState.documentSelfLink);
ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
deletionState.resourceQuerySpec = resourceQuerySpec;
deletionState.isMockRequest = isMock;
// Post/Start the ResourceRemovalTaskState...
deletionState = TestUtils.doPost(host, deletionState, ResourceRemovalTaskState.class, UriUtils.buildUri(host, ResourceRemovalTaskService.FACTORY_LINK));
return deletionState;
} catch (Throwable deleteExc) {
// just log and move on
getHost().log(Level.WARNING, "%s: Deleting [%s] VM: FAILED. Details: %s", this.currentTestName.getMethodName(), vmState.name, deleteExc.getMessage());
return null;
}
}).collect(Collectors.toList());
removeTaskStates.forEach(deletionState -> {
if (deletionState != null) {
getHost().waitForFinishedTask(ResourceRemovalTaskState.class, deletionState.documentSelfLink);
}
});
}
use of com.vmware.xenon.services.common.QueryTask.QuerySpecification in project photon-model by vmware.
the class AzureTestUtil method deleteVMs.
public static void deleteVMs(VerificationHost host, String documentSelfLink, boolean isMock, int numberOfRemainingVMs) throws Throwable {
// query VM doc to delete
QuerySpecification resourceQuerySpec = new QuerySpecification();
resourceQuerySpec.query.setTermPropertyName(ServiceDocument.FIELD_NAME_SELF_LINK).setTermMatchValue(documentSelfLink);
ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
deletionState.resourceQuerySpec = resourceQuerySpec;
deletionState.isMockRequest = isMock;
// Post/Start the ResourceRemovalTaskState...
deletionState = TestUtils.doPost(host, deletionState, ResourceRemovalTaskState.class, UriUtils.buildUri(host, ResourceRemovalTaskService.FACTORY_LINK));
// ...and wait for the task to complete
host.waitForFinishedTask(ResourceRemovalTaskState.class, deletionState.documentSelfLink);
ProvisioningUtils.queryDocumentsAndAssertExpectedCount(host, numberOfRemainingVMs, ComputeService.FACTORY_LINK, false);
}
Aggregations