use of com.vmware.photon.controller.model.resources.DiskService.DiskState 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.resources.DiskService.DiskState 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());
}
});
}
use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.
the class GCPEnumerationAdapterService method updateHelper.
/**
* This function will update the root disk data of a compute state. If the
* instance on the cloud does not have any disks or does not have a boot
* disk, the update will skip this instance. After all local vms are updated
* it will jump to create stage.
*
* So far we update ip address, power state in compute state and instance type
* in compute description and disk custom properties
* @param ctx The Enumeration Context.
* @param computeState The compute state to be updated.
* @param vm The virtual machine used to update compute state.
* @param numOfUpdates The number of remaining compute states to be updated.
*/
private void updateHelper(EnumerationContext ctx, ComputeState computeState, GCPInstance vm, AtomicInteger numOfUpdates) {
List<Operation> operations = new ArrayList<>();
ComputeState computeStatePatch = new ComputeState();
assignIPAddress(computeStatePatch, vm);
assignPowerState(computeStatePatch, vm.status);
operations.add(Operation.createPatch(getHost(), computeState.documentSelfLink).setBody(computeStatePatch));
ComputeDescription computeDescription = new ComputeDescription();
computeDescription.instanceType = extractActualInstanceType(vm.machineType);
operations.add(Operation.createPatch(getHost(), computeState.descriptionLink).setBody(computeDescription));
if (vm.disks != null && !vm.disks.isEmpty()) {
for (GCPDisk gcpDisk : vm.disks) {
if (gcpDisk.boot) {
DiskState diskState = new DiskState();
diskState.customProperties = new HashMap<>();
diskState.customProperties.put(DISK_AUTO_DELETE, gcpDisk.autoDelete.toString());
diskState.documentSelfLink = computeState.diskLinks.get(0);
operations.add(Operation.createPatch(getHost(), diskState.documentSelfLink).setBody(diskState));
break;
}
}
}
OperationJoin.create(operations).setCompletion((ops, exs) -> {
if (exs != null) {
exs.values().forEach(ex -> logWarning(() -> String.format("Error: %s", ex.getMessage())));
}
countAndFinishUpdating(ctx, numOfUpdates);
}).sendWith(this);
}
use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.
the class ModelUtils method createDiskState.
public static DiskState createDiskState(BaseModelTest test, String name) throws Throwable {
DiskState d = new DiskState();
d.id = UUID.randomUUID().toString();
d.name = name;
d.documentSelfLink = d.id;
d.type = DiskType.HDD;
d.sourceImageReference = new URI("http://sourceImageReference");
DiskState returnState = test.postServiceSynchronously(DiskService.FACTORY_LINK, d, DiskState.class);
return returnState;
}
use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.
the class DiskServiceTest method buildValidStartState.
private static DiskState buildValidStartState(boolean assignHost) throws Throwable {
DiskState disk = new DiskState();
disk.id = UUID.randomUUID().toString();
disk.type = DiskService.DiskType.HDD;
disk.name = "friendly-name";
disk.capacityMBytes = 100L;
if (assignHost) {
disk.computeHostLink = "host-1";
}
return disk;
}
Aggregations