Search in sources :

Example 1 with ResourceRemovalTaskState

use of com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState in project photon-model by vmware.

the class ResourceRemovalTaskServiceTest method buildValidStartState.

private static ResourceRemovalTaskState buildValidStartState() {
    ResourceRemovalTaskState startState = new ResourceRemovalTaskState();
    startState.resourceQuerySpec = new QueryTask.QuerySpecification();
    QueryTask.Query kindClause = new QueryTask.Query().setTermPropertyName(ServiceDocument.FIELD_NAME_KIND).setTermMatchValue(Utils.buildKind(ComputeService.ComputeState.class));
    startState.resourceQuerySpec.query.addBooleanClause(kindClause);
    startState.isMockRequest = true;
    return startState;
}
Also used : 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)

Example 2 with ResourceRemovalTaskState

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

Example 3 with ResourceRemovalTaskState

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

Example 4 with ResourceRemovalTaskState

use of com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState 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);
        }
    });
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) VerificationHost(com.vmware.xenon.common.test.VerificationHost) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) ServiceDocument(com.vmware.xenon.common.ServiceDocument) LifecycleState(com.vmware.photon.controller.model.support.LifecycleState) AzureTestUtil.createDefaultResourcePool(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourcePool) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) FACTORY_LINK(com.vmware.photon.controller.model.tasks.ProvisionLoadBalancerTaskService.FACTORY_LINK) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) AzureTestUtil.createDefaultComputeHost(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultComputeHost) After(org.junit.After) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) ProvisionSecurityGroupTaskService(com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) LoadBalancerService(com.vmware.photon.controller.model.resources.LoadBalancerService) HealthCheckConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.HealthCheckConfiguration) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) AddressSpace(com.microsoft.azure.management.network.AddressSpace) LoadBalancersInner(com.microsoft.azure.management.network.implementation.LoadBalancersInner) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) NO_PUBLIC_IP_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.NO_PUBLIC_IP_NIC_SPEC) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) Stream(java.util.stream.Stream) UriUtils(com.vmware.xenon.common.UriUtils) LoadBalancerInner(com.microsoft.azure.management.network.implementation.LoadBalancerInner) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.SubnetInstanceRequest.InstanceRequestType) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) ResourceGroupsInner(com.microsoft.azure.management.resources.implementation.ResourceGroupsInner) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest) ProvisionSubnetTaskState(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) VirtualNetworksInner(com.microsoft.azure.management.network.implementation.VirtualNetworksInner) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) ResourceRemovalTaskService(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService) ProvisionSubnetTaskService(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService) ProvisionLoadBalancerTaskState(com.vmware.photon.controller.model.tasks.ProvisionLoadBalancerTaskService.ProvisionLoadBalancerTaskState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) RouteConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ProvisionSecurityGroupTaskState(com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState) AZURE_ADMIN_USERNAME(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_ADMIN_USERNAME) AZURE_RESOURCE_GROUP_LOCATION(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_RESOURCE_GROUP_LOCATION) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) AzureTestUtil.createDefaultVMResource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultVMResource) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) AzureAsyncCallback(com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback) Lists(com.google.common.collect.Lists) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) AzureTestUtil.createSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createSecurityGroupState) SubStage(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState.SubStage) Before(org.junit.Before) AZURE_ADMIN_PASSWORD(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_ADMIN_PASSWORD) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) AzureTestUtil.generateName(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.generateName) LoadBalancerInstanceRequest(com.vmware.photon.controller.model.adapterapi.LoadBalancerInstanceRequest) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) AzureTestUtil.buildComputeDescription(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.buildComputeDescription) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState)

Example 5 with ResourceRemovalTaskState

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