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