Search in sources :

Example 16 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VsphereDatacenterEnumerationHelper method makeDatacenterFromResults.

private static ResourceGroupService.ResourceGroupState makeDatacenterFromResults(EnumerationProgress ctx, Element element) {
    ComputeEnumerateResourceRequest request = ctx.getRequest();
    String dcName = StringUtils.substringAfterLast(element.path, "/");
    String moref = VimUtils.convertMoRefToString(element.object);
    String type = element.object.getType();
    ResourceGroupService.ResourceGroupState state = new ResourceGroupService.ResourceGroupState();
    state.name = dcName;
    state.endpointLink = request.endpointLink;
    AdapterUtils.addToEndpointLinks(state, request.endpointLink);
    state.tenantLinks = ctx.getTenantLinks();
    CustomProperties.of(state).put(CustomProperties.MOREF, moref).put(CustomProperties.TYPE, type).put(ComputeProperties.ENDPOINT_LINK_PROP_NAME, request.endpointLink);
    VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(state, ctx.getVcUuid());
    return state;
}
Also used : ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService)

Example 17 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VsphereStoragePolicyEnumerationHelper method updateStoragePolicy.

static void updateStoragePolicy(VSphereIncrementalEnumerationService service, ResourceGroupState oldDocument, EnumerationProgress enumerationProgress, StoragePolicyOverlay sp) {
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    ResourceGroupState rgState = makeStoragePolicyFromResults(request, sp, enumerationProgress.getDcLink());
    rgState.documentSelfLink = oldDocument.documentSelfLink;
    if (oldDocument.tenantLinks == null) {
        rgState.tenantLinks = enumerationProgress.getTenantLinks();
    }
    service.logFine(() -> String.format("Syncing Storage %s", sp.getName()));
    Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), rgState.documentSelfLink)).setBody(rgState).setCompletion((o, e) -> {
        trackStoragePolicy(service, enumerationProgress, sp).handle(o, e);
        if (e == null) {
            // Update all compatible datastores group link with the self link of this
            // storage policy
            updateDataStoreWithStoragePolicyGroup(service, enumerationProgress, sp, o.getBody(ResourceGroupState.class).documentSelfLink);
        }
    }).sendWith(service);
}
Also used : ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Utils(com.vmware.xenon.common.Utils) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) PbmProfile(com.vmware.pbm.PbmProfile) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) Stream(java.util.stream.Stream) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)

Example 18 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class AzureStorageEnumerationServiceTest method kickOffStorageAccountEnumeration.

private void kickOffStorageAccountEnumeration() throws Throwable {
    // Create Compute Enumerate Adapter Request
    ComputeEnumerateResourceRequest resourceRequest = new ComputeEnumerateResourceRequest();
    resourceRequest.endpointLink = this.endpointState.documentSelfLink;
    resourceRequest.enumerationAction = EnumerationAction.START;
    resourceRequest.adapterManagementReference = UriUtils.buildUri(AzureEnumerationAdapterService.SELF_LINK);
    resourceRequest.resourcePoolLink = this.resourcePool.documentSelfLink;
    resourceRequest.resourceReference = UriUtils.buildUri(getHost(), "");
    resourceRequest.isMockRequest = this.isMock;
    ComputeEnumerateAdapterRequest request = new ComputeEnumerateAdapterRequest(resourceRequest, this.authState, this.computeHost);
    // patch synchronously to enumeration service
    patchServiceSynchronously(AzureStorageEnumerationAdapterService.SELF_LINK, request);
}
Also used : ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest)

Example 19 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class AzureDiskEnumerationServiceTest method testVMAndDiskEnumeration.

@Test
public void testVMAndDiskEnumeration() throws Throwable {
    // Exit if it is mock
    if (this.isMock) {
        return;
    }
    this.resourceGroup = SdkContext.randomResourceName(RESOURCE_GROUP_NAME, RESOURCE_GROUP_NAME.length() + 5);
    // Create a vm with one additional disk
    VirtualMachine vm = getAzureSdkClients().getComputeManager().virtualMachines().define("TestVM").withRegion(Region.US_WEST).withNewResourceGroup(this.resourceGroup).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withoutPrimaryPublicIPAddress().withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername(AzureTestUtil.AZURE_ADMIN_USERNAME).withRootPassword(AzureTestUtil.AZURE_ADMIN_PASSWORD).withNewDataDisk(5).create();
    assertNotNull(vm);
    DataDisk dataDisk = vm.storageProfile().dataDisks().get(0);
    assertNotNull(dataDisk);
    ComputeEnumerateResourceRequest resourceRequest = kickOffEnumeration();
    ComputeEnumerateAdapterRequest request = new ComputeEnumerateAdapterRequest(resourceRequest, this.authState, this.computeHost);
    // Run VM enumeration
    patchServiceSynchronously(AzureComputeEnumerationAdapterService.SELF_LINK, request);
    // Run disk enumeration
    patchServiceSynchronously(AzureDiskEnumerationAdapterService.SELF_LINK, request);
    // Verify disk state is created in local store
    Map<String, DiskState> diskStateMap = ProvisioningUtils.getResourceStates(getHost(), DiskService.FACTORY_LINK, DiskState.class);
    assertTrue(diskStateMap.keySet().stream().anyMatch(s -> s.equalsIgnoreCase(dataDisk.managedDisk().id())));
    // Detach disk
    vm.update().withoutDataDisk(dataDisk.lun()).apply();
    // Run Disk enumeration
    patchServiceSynchronously(AzureDiskEnumerationAdapterService.SELF_LINK, request);
    // Verify if the status of disk state is updated to Available state or not
    diskStateMap = ProvisioningUtils.getResourceStates(getHost(), DiskService.FACTORY_LINK, DiskState.class);
    diskStateMap.values().forEach(diskState -> {
        if (diskState.name.equalsIgnoreCase(dataDisk.name())) {
            assertTrue("Status of disk state should be Available", diskState.status.equals(DiskService.DiskStatus.AVAILABLE));
        }
    });
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) Level(java.util.logging.Level) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Map(java.util.Map) After(org.junit.After) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) AzureTestUtil(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) DataDisk(com.microsoft.azure.management.compute.DataDisk) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) Disk(com.microsoft.azure.management.compute.Disk) UriUtils(com.vmware.xenon.common.UriUtils) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) DiskService(com.vmware.photon.controller.model.resources.DiskService) SdkContext(com.microsoft.azure.management.resources.fluentcore.utils.SdkContext) DataDisk(com.microsoft.azure.management.compute.DataDisk) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 20 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class AzureDiskEnumerationServiceTest method testManagedDiskEnumeration.

@Test
public void testManagedDiskEnumeration() throws Throwable {
    // Exit if it is mock
    if (this.isMock) {
        return;
    }
    // create a disk in Azure
    Disk disk = createDisk("disk");
    assertNotNull(disk);
    ComputeEnumerateResourceRequest resourceRequest = kickOffEnumeration();
    ComputeEnumerateAdapterRequest request = new ComputeEnumerateAdapterRequest(resourceRequest, this.authState, this.computeHost);
    // Run disk enumeration
    patchServiceSynchronously(AzureDiskEnumerationAdapterService.SELF_LINK, request);
    // Fetch disks from local store to verify if diskState is created after enumeration
    Map<String, DiskState> diskStateMap = ProvisioningUtils.getResourceStates(getHost(), DiskService.FACTORY_LINK, DiskState.class);
    assertTrue("Newly created disk state is not found.", diskStateMap.keySet().stream().anyMatch(s -> s.equalsIgnoreCase(disk.id())));
    // verify internal tag links
    DiskState createdDisk = diskStateMap.entrySet().stream().filter(en -> en.getKey().equalsIgnoreCase(disk.id())).findFirst().get().getValue();
    assertNotNull(createdDisk.tagLinks);
    TagState typeTag = TagsUtil.newTagState(PhotonModelConstants.TAG_KEY_TYPE, AzureConstants.AzureResourceType.azure_managed_disk.toString(), false, this.computeHost.tenantLinks);
    assertTrue("internal tag not found", createdDisk.tagLinks.stream().anyMatch(s -> s.equalsIgnoreCase(typeTag.documentSelfLink)));
    // verify regionId
    assertNotNull("regionId not found", createdDisk.regionId);
    // Delete disk from Azure
    getAzureSdkClients().getComputeManager().disks().deleteById(disk.id());
    // Run enumeration to sync local disk states with disks in Azure
    patchServiceSynchronously(AzureDiskEnumerationAdapterService.SELF_LINK, request);
    // Need to wait for completion of patch operation on disk states
    TimeUnit.SECONDS.sleep(5);
    // After sync, query local disk states to verify endpoint links of disk state are disassociated
    diskStateMap = ProvisioningUtils.getResourceStates(getHost(), DiskService.FACTORY_LINK, DiskState.class);
    diskStateMap.values().forEach(diskState -> {
        if (diskState.id.equalsIgnoreCase(disk.id())) {
            assertTrue("Endpoint link must be null", diskState.endpointLink.isEmpty());
            assertTrue("Endpoint links in DiskState must be empty", diskState.endpointLinks.isEmpty());
        }
    });
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) Level(java.util.logging.Level) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Map(java.util.Map) After(org.junit.After) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) AzureTestUtil(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) DataDisk(com.microsoft.azure.management.compute.DataDisk) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) Disk(com.microsoft.azure.management.compute.Disk) UriUtils(com.vmware.xenon.common.UriUtils) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) DiskService(com.vmware.photon.controller.model.resources.DiskService) SdkContext(com.microsoft.azure.management.resources.fluentcore.utils.SdkContext) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) DataDisk(com.microsoft.azure.management.compute.DataDisk) Disk(com.microsoft.azure.management.compute.Disk) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Aggregations

ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)29 QueryTask (com.vmware.xenon.services.common.QueryTask)16 Operation (com.vmware.xenon.common.Operation)12 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)11 List (java.util.List)11 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)10 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)10 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)10 Utils (com.vmware.xenon.common.Utils)10 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)9 VsphereEnumerationHelper.convertOnlyResultToDocument (com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument)8 VsphereEnumerationHelper.withTaskResults (com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults)8 ObjectUpdateKind (com.vmware.vim25.ObjectUpdateKind)8 CompletionHandler (com.vmware.xenon.common.Operation.CompletionHandler)8 UriUtils (com.vmware.xenon.common.UriUtils)8 Map (java.util.Map)8 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)7 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)7 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)7 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)7