Search in sources :

Example 6 with ResourceRemovalTaskState

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));
}
Also used : QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 7 with ResourceRemovalTaskState

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();
}
Also used : QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Query(com.vmware.xenon.services.common.QueryTask.Query) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState)

Aggregations

ResourceRemovalTaskState (com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState)7 QuerySpecification (com.vmware.xenon.services.common.QueryTask.QuerySpecification)6 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3 Query (com.vmware.xenon.services.common.QueryTask.Query)2 Lists (com.google.common.collect.Lists)1 AddressSpace (com.microsoft.azure.management.network.AddressSpace)1 LoadBalancerInner (com.microsoft.azure.management.network.implementation.LoadBalancerInner)1 LoadBalancersInner (com.microsoft.azure.management.network.implementation.LoadBalancersInner)1 VirtualNetworkInner (com.microsoft.azure.management.network.implementation.VirtualNetworkInner)1 VirtualNetworksInner (com.microsoft.azure.management.network.implementation.VirtualNetworksInner)1 ResourceGroupInner (com.microsoft.azure.management.resources.implementation.ResourceGroupInner)1 ResourceGroupsInner (com.microsoft.azure.management.resources.implementation.ResourceGroupsInner)1 PhotonModelMetricServices (com.vmware.photon.controller.model.PhotonModelMetricServices)1 LoadBalancerInstanceRequest (com.vmware.photon.controller.model.adapterapi.LoadBalancerInstanceRequest)1 SecurityGroupInstanceRequest (com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest)1 InstanceRequestType (com.vmware.photon.controller.model.adapterapi.SubnetInstanceRequest.InstanceRequestType)1 AzureAsyncCallback (com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback)1 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)1 ResourceGroupStateType (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType)1 AZURE_ADMIN_PASSWORD (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_ADMIN_PASSWORD)1