use of com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest in project photon-model by vmware.
the class AWSEnumerationAdapterService method kickOffEnumerationWorkFlows.
/**
* Kicks off the enumeration flows for creation and deletion.
*/
public void kickOffEnumerationWorkFlows(EnumerationContext context, AWSEnumerationStages next) {
List<List<Operation>> enumOperations = new ArrayList<>();
if (!AWSUtils.isAwsClientMock()) {
ComputeEnumerateAdapterRequest awsS3EnumerationRequest = new ComputeEnumerateAdapterRequest(context.request, context.endpointAuth, context.parent, Regions.DEFAULT_REGION.getName());
Operation patchAWSS3StorageAdapterService = Operation.createPatch(this, AWSS3StorageEnumerationAdapterService.SELF_LINK).setBody(awsS3EnumerationRequest).setReferer(getHost().getUri());
enumOperations.add(Collections.singletonList(patchAWSS3StorageAdapterService));
}
for (String regionId : context.regions) {
List<Operation> enumOperationsForRegion = new ArrayList<>();
ComputeEnumerateAdapterRequest awsEnumerationRequest = new ComputeEnumerateAdapterRequest(context.request, context.endpointAuth, context.parent, regionId);
Operation patchAWSCreationAdapterService = Operation.createPatch(this, AWSEnumerationAndCreationAdapterService.SELF_LINK).setBody(awsEnumerationRequest).setReferer(this.getHost().getUri());
Operation patchAWSDeletionAdapterService = Operation.createPatch(this, AWSEnumerationAndDeletionAdapterService.SELF_LINK).setBody(awsEnumerationRequest).setReferer(getHost().getUri());
Operation patchAWSEBSStorageAdapterService = Operation.createPatch(this, AWSEBSStorageEnumerationAdapterService.SELF_LINK).setBody(awsEnumerationRequest).setReferer(getHost().getUri());
enumOperationsForRegion.add(patchAWSCreationAdapterService);
enumOperationsForRegion.add(patchAWSDeletionAdapterService);
enumOperationsForRegion.add(patchAWSEBSStorageAdapterService);
enumOperations.add(enumOperationsForRegion);
}
if (enumOperations.size() == 0) {
logFine(() -> "No enumeration tasks to run");
context.stage = next;
handleEnumerationRequest(context);
return;
}
OperationJoin.JoinedCompletionHandler joinCompletion = (ox, exc) -> {
if (exc != null) {
logSevere(() -> String.format("Error starting the enumeration workflows for AWS: %s", Utils.toString(exc)));
context.taskManager.patchTaskToFailure(exc.values().iterator().next());
return;
}
logInfo(() -> "Completed creation and deletion enumeration for compute and storage" + " states");
context.stage = next;
handleEnumerationRequest(context);
};
OperationSequence enumOp = OperationSequence.create(OperationJoin.create(enumOperations.get(0)));
for (int i = 1; i < enumOperations.size(); i++) {
enumOp = enumOp.next(OperationJoin.create(enumOperations.get(i)));
}
enumOp.setCompletion(joinCompletion);
enumOp.sendWith(getHost());
logFine(() -> "Started creation and deletion enumeration for AWS computes and storage");
}
use of com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest in project photon-model by vmware.
the class AWSEnumerationAndCreationAdapterService method refreshSecurityGroupInformation.
private void refreshSecurityGroupInformation(EnumerationCreationContext aws, AWSEnumerationRefreshSubStage next) {
ComputeEnumerateAdapterRequest sgEnumeration = new ComputeEnumerateAdapterRequest(aws.request.original, aws.endpointAuth, aws.parentCompute, aws.request.regionId);
Operation patchSGOperation = Operation.createPatch(this, AWSSecurityGroupEnumerationAdapterService.SELF_LINK).setBody(sgEnumeration).setReferer(UriUtils.buildUri(getHost().getPublicUri(), getSelfLink()));
this.getHost().sendWithDeferredResult(patchSGOperation, AWSSecurityGroupEnumerationAdapterService.AWSSecurityGroupEnumerationResponse.class).thenAccept(securityGroupEnumerationResponse -> {
logFine(() -> "Successfully enumerated security group states");
aws.enumeratedSecurityGroups = securityGroupEnumerationResponse;
aws.refreshSubStage = next;
processRefreshSubStages(aws);
}).exceptionally(throwable -> {
if (throwable != null) {
logWarning(() -> String.format("Failed to enumerate security groups: %s ", throwable.getLocalizedMessage()));
aws.error = throwable;
aws.refreshSubStage = next;
processRefreshSubStages(aws);
}
return null;
});
}
use of com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest 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.adapters.util.ComputeEnumerateAdapterRequest 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.adapters.util.ComputeEnumerateAdapterRequest 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