use of com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState in project photon-model by vmware.
the class TestAWSSetupUtils method deleteVMs.
/**
* Deletes the VM that is present on an endpoint and represented by the passed in ID.
*
* @param documentSelfLink
* @param isMock
* @param host
* @param deleteDocumentOnly
* @throws Throwable
*/
public static void deleteVMs(String documentSelfLink, boolean isMock, VerificationHost host, boolean deleteDocumentOnly) throws Throwable {
ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
QuerySpecification resourceQuerySpec = new QueryTask.QuerySpecification();
// query all ComputeState resources for the cluster
resourceQuerySpec.query.setTermPropertyName(ServiceDocument.FIELD_NAME_SELF_LINK).setTermMatchValue(documentSelfLink);
deletionState.resourceQuerySpec = resourceQuerySpec;
deletionState.isMockRequest = isMock;
// Waiting for default request timeout in minutes for the machine to be turned OFF on AWS.
deletionState.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + TimeUnit.MINUTES.toMicros(AWS_VM_REQUEST_TIMEOUT_MINUTES);
if (deleteDocumentOnly) {
deletionState.options = EnumSet.of(TaskOption.DOCUMENT_CHANGES_ONLY);
}
deletionState = TestUtils.doPost(host, deletionState, ResourceRemovalTaskState.class, UriUtils.buildUri(host, ResourceRemovalTaskService.FACTORY_LINK));
ProvisioningUtils.waitForTaskCompletion(host, deletionState.documentSelfLink, ResourceRemovalTaskState.class);
// check that the VMs are gone
ServiceDocumentQueryResult serviceDocumentQueryResult = ProvisioningUtils.queryAllFactoryResources(host, ComputeService.FACTORY_LINK);
List<String> documentLinks = serviceDocumentQueryResult.documentLinks;
assertFalse(documentLinks.contains(documentSelfLink));
}
use of com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState in project photon-model by vmware.
the class TestAWSSetupUtils method deleteVMsOnThisEndpoint.
/**
* A utility method that deletes the VMs on the specified endpoint filtered by the instanceIds
* that are passed in. It expects peerURI and tenantLinks to be populated.
*
* @throws Throwable
*/
public static void deleteVMsOnThisEndpoint(VerificationHost host, URI peerURI, boolean isMock, String parentComputeLink, List<String> instanceIdsToDelete, List<String> tenantLinks) throws Throwable {
host.testStart(1);
ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
deletionState.tenantLinks = tenantLinks;
// All AWS Compute States AND Ids in (Ids to delete)
QuerySpecification compositeQuery = new QueryTask.QuerySpecification();
// Document Kind = Compute State AND Parent Compute Link = AWS
QueryTask.Query awsComputeStatesQuery = new QueryTask.Query();
awsComputeStatesQuery = Query.Builder.create().addKindFieldClause(ComputeService.ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_PARENT_LINK, parentComputeLink).build();
compositeQuery.query.addBooleanClause(awsComputeStatesQuery);
if (instanceIdsToDelete != null && instanceIdsToDelete.size() > 0) {
// Instance Ids in List of instance Ids to delete
QueryTask.Query instanceIdFilterParentQuery = new QueryTask.Query();
for (String instanceId : instanceIdsToDelete) {
if (!instanceId.startsWith(AWS_INSTANCE_PREFIX)) {
continue;
}
QueryTask.Query instanceIdFilter = new QueryTask.Query().setTermPropertyName(ComputeState.FIELD_NAME_ID).setTermMatchValue(instanceId);
instanceIdFilter.occurance = QueryTask.Query.Occurance.SHOULD_OCCUR;
instanceIdFilterParentQuery.addBooleanClause(instanceIdFilter);
}
instanceIdFilterParentQuery.occurance = Occurance.MUST_OCCUR;
compositeQuery.query.addBooleanClause(instanceIdFilterParentQuery);
}
deletionState.resourceQuerySpec = compositeQuery;
deletionState.isMockRequest = isMock;
host.send(Operation.createPost(createServiceURI(host, peerURI, ResourceRemovalTaskService.FACTORY_LINK)).setBody(deletionState).setCompletion(host.getCompletion()));
// Re-setting the test timeout value so that it clean up spawned instances even if it has
// timed out based on the original value.
host.setTimeoutSeconds(500);
host.testWait();
}
Aggregations