Search in sources :

Example 6 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestVSphereProvisionFromImageLink method provisionVMAndGetState.

private ComputeState provisionVMAndGetState() throws Throwable {
    if (isMock()) {
        return null;
    }
    // Create a resource pool where the VM will be housed
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost(this.computeHostDescription);
    EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
    this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    enumerateComputes(this.computeHost, this.endpoint);
    doRefresh();
    snapshotFactoryState("images", ImageService.class);
    String imageLink = findImage();
    ComputeDescription desc = createVmDescription();
    ComputeState vm = createVmState(desc, imageLink);
    // kick off a provision task to do the actual VM creation
    ProvisionComputeTaskState outTask = createProvisionTask(vm);
    awaitTaskEnd(outTask);
    return getComputeState(vm);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 7 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestVSphereEnumerationTask method testRefresh.

@Test
public void testRefresh() throws Throwable {
    // Create a resource pool where the VM will be housed
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost(this.computeHostDescription);
    // Always create endpoint, so that there is no bogus
    // endpointLink. This enumeration task is started on a real
    // endpoint. This will also help tango based adapters
    // as the existence of endpoint is more critical there to
    // extract data collector identifier.
    EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
    this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    refreshAndRetire();
    if (!isMock()) {
        ComputeState vm = findRandomVm();
        assertInternalPropertiesSet(vm);
        assertNotNull(vm.endpointLink);
        assertNotNull(vm.tenantLinks);
    }
    captureFactoryState("initial");
    String aComputeLink = null;
    String anUsedHostLink = null;
    String anUnusedHostLink = null;
    if (!isMock()) {
        // clone a random compute and save it under different id
        ComputeState randVm = findRandomVm();
        ComputeState vm = Utils.clone(randVm);
        vm.documentSelfLink = null;
        vm.id = "fake-vm-" + vm.id;
        vm.documentSelfLink = null;
        vm = TestUtils.doPost(this.host, vm, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
        aComputeLink = vm.documentSelfLink;
        ComputeState randomHost = findRandomHost();
        {
            ComputeState host = Utils.clone(randomHost);
            host.documentSelfLink = null;
            host.powerState = PowerState.ON;
            host.id = "fake-host-" + host.id;
            host.documentSelfLink = null;
            host = TestUtils.doPost(this.host, host, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
            anUsedHostLink = host.documentSelfLink;
            ComputeState update = new ComputeState();
            update.customProperties = new HashMap<>();
            update.customProperties.put(ComputeProperties.PLACEMENT_LINK, host.documentSelfLink);
            TestUtils.doPatch(this.host, update, ComputeState.class, UriUtils.buildUri(this.host, randVm.documentSelfLink));
        }
        {
            ComputeState host = Utils.clone(randomHost);
            host.documentSelfLink = null;
            host.powerState = PowerState.ON;
            host.id = "fake-host-unused" + host.id;
            host.documentSelfLink = null;
            host = TestUtils.doPost(this.host, host, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
            anUnusedHostLink = host.documentSelfLink;
        }
    }
    // do a second refresh to test update path
    refreshAndRetire();
    captureFactoryState("updated");
    snapshotFactoryState("metrics", ResourceMetricsService.class);
    if (aComputeLink != null) {
        // the second enumeration marked the fake vm as retired
        Operation op = Operation.createGet(this.host, aComputeLink);
        op = this.host.waitForResponse(op);
        ComputeState compute = op.getBody(ComputeState.class);
        assertEquals(compute.lifecycleState, LifecycleState.RETIRED);
        assertEquals(PowerState.OFF, compute.powerState);
    }
    if (anUsedHostLink != null) {
        // the second enumeration marked the fake vm as retired
        Operation op = Operation.createGet(this.host, anUsedHostLink);
        op = this.host.waitForResponse(op);
        ComputeState compute = op.getBody(ComputeState.class);
        assertEquals(compute.lifecycleState, LifecycleState.RETIRED);
        assertEquals(PowerState.OFF, compute.powerState);
    }
    if (anUnusedHostLink != null) {
        // the unused host is wiped out unconditionally
        Operation op = Operation.createGet(this.host, anUnusedHostLink);
        op = this.host.waitForResponse(op);
        assertEquals(op.getStatusCode(), 404);
    }
    verifyDatastoreAndStoragePolicy();
    if (!isMock()) {
        verifyCIGapForComputeResourcesAndVMs();
        verifyCIGapForDatacenterOrFolder(VimNames.TYPE_DATACENTER);
        verifyCIGapForDatacenterOrFolder(VimNames.TYPE_FOLDER);
        verifyCIGapForDatastore();
        verifyCIGapForComputeResource();
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) HashMap(java.util.HashMap) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test)

Example 8 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestVSphereCloneTaskBase method createInstanceFromTemplate.

protected void createInstanceFromTemplate(boolean withAdditionalDisks) throws Throwable {
    ComputeService.ComputeState vm = null;
    ComputeService.ComputeState clonedVm = null;
    try {
        this.auth = createAuth();
        this.resourcePool = createResourcePool();
        if (isMock()) {
            createNetwork(networkId);
        }
        this.computeHostDescription = createComputeDescription();
        this.computeHost = createComputeHost(this.computeHostDescription);
        EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
        this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
        doRefresh();
        snapshotFactoryState("clone-refresh", NetworkService.class);
        ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
        vm = createVmState(vmDescription, false, null, withAdditionalDisks);
        // kick off a provision task to do the actual VM creation
        ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(vm);
        awaitTaskEnd(provisionTask);
        vm = getComputeState(vm);
        // put fake moref in the vm
        if (isMock()) {
            ManagedObjectReference moref = new ManagedObjectReference();
            moref.setValue("vm-0");
            moref.setType(VimNames.TYPE_VM);
            CustomProperties.of(vm).put(MOREF, moref);
            vm = doPost(this.host, vm, ComputeService.ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
        }
        // create state & desc of the clone
        ComputeDescriptionService.ComputeDescription cloneDescription = createCloneDescription(vm.documentSelfLink);
        clonedVm = createCloneVmState(cloneDescription, false, withAdditionalDisks);
        provisionTask = createProvisionTask(clonedVm);
        awaitTaskEnd(provisionTask);
        clonedVm = getComputeState(clonedVm);
        if (!isMock()) {
            // Verify that the disk is resized
            BasicConnection connection = createConnection();
            GetMoRef get = new GetMoRef(connection);
            if (withAdditionalDisks) {
                List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
                assertEquals(3, virtualDisks.size());
            } else {
                verifyDiskSize(clonedVm, get, CLONE_HDD_DISK_SIZE);
            }
        }
    } finally {
        if (!isMock()) {
            cleanUpVm(vm, clonedVm);
        }
    }
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VirtualDisk(com.vmware.vim25.VirtualDisk) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 9 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestVSphereImageEnumerationTask method testRefresh.

@Test
public void testRefresh() throws Throwable {
    // Create a resource pool where the VM will be housed
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost(this.computeHostDescription);
    EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
    this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    doRefresh();
    captureFactoryState("initial");
    Query q = Query.Builder.create().addKindFieldClause(ImageState.class).build();
    ImageState anImage = null;
    try {
        anImage = findFirstMatching(q, ImageState.class);
    } catch (Exception ignore) {
    }
    if (anImage != null) {
        assertFalse(anImage.tenantLinks.isEmpty());
    }
    doRefresh();
    captureFactoryState("updated");
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) Query(com.vmware.xenon.services.common.QueryTask.Query) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) Test(org.junit.Test)

Example 10 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class ModelUtils method createEndpoint.

public static EndpointState createEndpoint(BaseModelTest test) throws Throwable {
    EndpointState endpointState = new EndpointState();
    endpointState.endpointType = "vsphere";
    endpointState.computeLink = "/resources/compute/fakeGuidA";
    endpointState.computeDescriptionLink = "/resources/compute-descriptions/fakeGuidB";
    endpointState.resourcePoolLink = "/resources/pools/fakeGuidC";
    endpointState.endpointProperties = new HashMap<>();
    endpointState.endpointProperties.put("hostName", "sqa-nsxt2-vc.sqa.local");
    endpointState.endpointProperties.put("regionId", "Datacenter:datacenter-2");
    endpointState.endpointProperties.put("privateKeyId", "install.admin@sqa.local");
    endpointState.endpointProperties.put("supportDatastores", "true");
    endpointState.name = "vCenter";
    endpointState = test.postServiceSynchronously(EndpointService.FACTORY_LINK, endpointState, EndpointState.class);
    return endpointState;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Aggregations

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)69 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)23 Operation (com.vmware.xenon.common.Operation)22 Test (org.junit.Test)16 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)13 URI (java.net.URI)13 HashMap (java.util.HashMap)13 Query (com.vmware.xenon.services.common.QueryTask.Query)12 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 List (java.util.List)11 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)10 ServiceDocument (com.vmware.xenon.common.ServiceDocument)10 Collectors (java.util.stream.Collectors)10 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9