Search in sources :

Example 1 with QuerySpecification

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);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Arrays(java.util.Arrays) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) TimeoutException(java.util.concurrent.TimeoutException) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) ArrayList(java.util.ArrayList) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) URI(java.net.URI) VirtualMachineGuestOsIdentifier(com.vmware.vim25.VirtualMachineGuestOsIdentifier) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) NetworkInterfaceDescriptionService(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Test(org.junit.Test) UUID(java.util.UUID) File(java.io.File) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IOUtils(org.apache.commons.io.IOUtils) BootConfig(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) Ignore(org.junit.Ignore) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Assert(org.junit.Assert) DiskService(com.vmware.photon.controller.model.resources.DiskService) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Operation(com.vmware.xenon.common.Operation)

Example 2 with QuerySpecification

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();
}
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 QuerySpecification

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

Example 4 with QuerySpecification

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);
        }
    });
}
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 QuerySpecification

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

Aggregations

QuerySpecification (com.vmware.xenon.services.common.QueryTask.QuerySpecification)8 ResourceRemovalTaskState (com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState)6 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3 QueryTask (com.vmware.xenon.services.common.QueryTask)3 ArrayList (java.util.ArrayList)3 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)2 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 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)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