use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureTestUtil method createDefaultVMResource.
public static ComputeState createDefaultVMResource(VerificationHost host, String azureVMName, ComputeState computeHost, EndpointState endpointState, AzureNicSpecs nicSpecs, String networkRGLink, ImageSource imageSource, int numberOfAdditionalDisks, ComputeDescription azureVMDesc, String azureRgName) throws Throwable {
if (azureRgName == null) {
azureRgName = azureVMName;
}
final ResourceGroupState defaultVmRG = createDefaultResourceGroupState(host, azureRgName, computeHost, endpointState, ResourceGroupStateType.AzureResourceGroup);
final String defaultVmRGLink = defaultVmRG.documentSelfLink;
if (networkRGLink == null) {
// The RG where the VM is deployed is also used as RG for the Network!
networkRGLink = defaultVmRGLink;
}
// The RG where the VM is deployed is also used as RG for the SecurityGroup!
final String sgRGLink = defaultVmRGLink;
// Create resource group with a different type. It should be filtered out.
ResourceGroupState azureStorageContainerRG = createDefaultResourceGroupState(host, AZURE_STORAGE_CONTAINER_RG_NAME, computeHost, endpointState, ResourceGroupStateType.AzureStorageContainer);
final Set<String> networkRGLinks = new HashSet<>();
networkRGLinks.add(networkRGLink);
networkRGLinks.add(azureStorageContainerRG.documentSelfLink);
final Set<String> sgRGLinks = new HashSet<>();
sgRGLinks.add(sgRGLink);
sgRGLinks.add(azureStorageContainerRG.documentSelfLink);
if (azureVMDesc == null) {
azureVMDesc = buildComputeDescription(host, computeHost, endpointState, null);
}
List<String> vmDisks = new ArrayList<>();
DiskState rootDisk = new DiskState();
rootDisk.name = azureVMName + "-boot-disk";
rootDisk.id = UUID.randomUUID().toString();
rootDisk.documentSelfLink = rootDisk.id;
rootDisk.type = DiskType.HDD;
// Custom OSDisk size of 32 GBs
rootDisk.capacityMBytes = AZURE_CUSTOM_OSDISK_SIZE;
if (imageSource.type == Type.PRIVATE_IMAGE || imageSource.type == Type.PUBLIC_IMAGE) {
rootDisk.imageLink = imageSource.asImageState().documentSelfLink;
} else if (imageSource.type == Type.IMAGE_REFERENCE) {
rootDisk.sourceImageReference = URI.create(imageSource.asRef());
}
rootDisk.bootOrder = 1;
rootDisk.endpointLink = endpointState.documentSelfLink;
rootDisk.endpointLinks = new HashSet<>();
rootDisk.endpointLinks.add(endpointState.documentSelfLink);
rootDisk.computeHostLink = computeHost.documentSelfLink;
rootDisk.tenantLinks = endpointState.tenantLinks;
rootDisk.storageType = AZURE_STORAGE_DISKS;
rootDisk.tagLinks = createTagStateSet(host, endpointState.tenantLinks, TAG_KEY_TYPE, AzureResourceType.azure_vhd.name());
rootDisk.customProperties = new HashMap<>();
rootDisk.customProperties.put(AZURE_OSDISK_CACHING, DEFAULT_OS_DISK_CACHING.name());
rootDisk.customProperties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, (azureVMName + "sa").replaceAll("[_-]", "").toLowerCase());
rootDisk.customProperties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_RG_NAME, azureRgName);
rootDisk.customProperties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_TYPE, AZURE_STORAGE_ACCOUNT_TYPE);
rootDisk = TestUtils.doPost(host, rootDisk, DiskState.class, UriUtils.buildUri(host, DiskService.FACTORY_LINK));
vmDisks.add(rootDisk.documentSelfLink);
// create additional disks
vmDisks.addAll(createAdditionalDisks(host, azureVMName, endpointState, numberOfAdditionalDisks, VMResourceSpec.PersistentDisks.NONE, false));
// Create NICs
List<String> nicLinks = createDefaultNicStates(host, computeHost, endpointState, networkRGLinks, sgRGLinks, nicSpecs, azureVMName).stream().map(nic -> nic.documentSelfLink).collect(Collectors.toList());
// Finally create the compute resource state to provision using all constructs above.
ComputeState computeState = new ComputeState();
computeState.id = UUID.randomUUID().toString();
computeState.name = azureVMName;
computeState.parentLink = computeHost.documentSelfLink;
computeState.type = ComputeType.VM_GUEST;
computeState.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
computeState.descriptionLink = azureVMDesc.documentSelfLink;
computeState.resourcePoolLink = computeHost.resourcePoolLink;
computeState.diskLinks = vmDisks;
computeState.networkInterfaceLinks = nicLinks;
computeState.customProperties = Collections.singletonMap(RESOURCE_GROUP_NAME, azureRgName);
computeState.groupLinks = Collections.singleton(defaultVmRGLink);
computeState.endpointLink = endpointState.documentSelfLink;
computeState.endpointLinks = new HashSet<>();
computeState.endpointLinks.add(endpointState.documentSelfLink);
computeState.computeHostLink = computeHost.documentSelfLink;
computeState.tenantLinks = endpointState.tenantLinks;
computeState.tagLinks = createTagStateSet(host, endpointState.tenantLinks, TAG_KEY_TYPE, AzureConstants.AzureResourceType.azure_vm.toString());
computeState.creationTimeMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
return TestUtils.doPost(host, computeState, ComputeState.class, UriUtils.buildUri(host, ComputeService.FACTORY_LINK));
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionsEnumerationServiceTest method setUp.
@Before
public void setUp() throws Exception {
this.host = VerificationHost.create(0);
this.isMock = true;
this.createdComputeLinks = new ArrayList<>();
try {
this.host.start();
PhotonModelServices.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
AzureAdaptersTestUtils.startServicesSynchronouslyAzure(this.host);
AzureAdaptersTestUtils.startServicesSynchronouslyEaAzure(this.host);
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelMetricServices.LINKS);
this.host.setTimeoutSeconds(600);
// Create Azure non-ea endpoints
EndpointState nonEaEp1 = createNonEaEndpointState(SUBSCRIPTION_EXISTING_1);
EndpointAllocationTaskState state1 = createEndpoint(nonEaEp1);
this.existingSubsComputeLink1 = state1.endpointState.computeLink;
EndpointState nonEaEp2 = createNonEaEndpointState(SUBSCRIPTION_EXISTING_2);
EndpointAllocationTaskState state2 = createEndpoint(nonEaEp2);
this.existingSubsComputeLink2 = state2.endpointState.computeLink;
// Create an Azure endpoint which will act as Azure EA endpoint
EndpointState ep = createEaEndpointState();
EndpointAllocationTaskState taskState = createEndpoint(ep);
this.computeLink = taskState.endpointState.computeLink;
this.compute = getServiceSynchronously(this.computeLink, ComputeState.class);
} catch (Throwable e) {
throw new Exception(e);
}
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionsEnumerationServiceTest method testAddNonEaAzureSubscriptionLater.
private void testAddNonEaAzureSubscriptionLater() throws Throwable {
// Create Azure non-ea endpoints
EndpointState nonEaEp3 = createNonEaEndpointState(SUBSCRIPTION_ID_2);
EndpointAllocationTaskState state3 = createEndpoint(nonEaEp3);
this.existingSubsComputeLink3 = state3.endpointState.computeLink;
AzureSubscription subscription1 = getAzureSubscription(SUBSCRIPTION_ID_1, ACCOUNT_EMAIL_ID_1);
AzureSubscription subscription2 = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_EMAIL_ID_2);
AzureSubscription existingSubscription2 = getAzureSubscription(SUBSCRIPTION_EXISTING_2, ACCOUNT_EMAIL_ID_2);
createAzureCostComputesForSubscriptions(Arrays.asList(subscription1, subscription2, existingSubscription2));
// Query for Azure Computes created with CLIENT_ID as enrollment Number
QueryTask task = createQueryTaskForAzureComputes(ENROLLMENT_NUMNBER, Collections.singletonList(TENANT_ID));
QueryTask queryTaskResponse = executQuerySynchronously(task);
assertQueryTaskResponse(queryTaskResponse, 7);
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureInstanceTypeServiceTest method testGetInstanceTypes_invalidEndpoint.
@Test(expected = IllegalArgumentException.class)
public void testGetInstanceTypes_invalidEndpoint() throws Throwable {
EndpointState endpointNoRegion;
{
endpointNoRegion = new EndpointState();
// Copy from original end-point
endpointNoRegion.id = this.endpointState.id;
endpointNoRegion.name = this.endpointState.name;
endpointNoRegion.endpointType = this.endpointState.endpointType;
endpointNoRegion.authCredentialsLink = this.endpointState.authCredentialsLink;
endpointNoRegion.tenantLinks = this.endpointState.tenantLinks;
// Do NOT set REGION
endpointNoRegion.endpointProperties = Collections.emptyMap();
endpointNoRegion = TestUtils.doPost(getHost(), endpointNoRegion, EndpointState.class, UriUtils.buildUri(getHost(), EndpointService.FACTORY_LINK));
}
URI uri = UriUtils.appendQueryParam(UriUtils.buildUri(AzureInstanceTypeService.SELF_LINK), "endpoint", endpointNoRegion.documentSelfLink);
getServiceSynchronously(uri.toString(), ServiceDocument.class);
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class TestAzureImageEnumerationTask method testPublicImageEnumeration_delete.
/**
* Validate that during enum only images of this 'endpointType' are deleted.
*/
@Test
public void testPublicImageEnumeration_delete() throws Throwable {
Assume.assumeFalse(this.isMock);
setImagesLoadMode(ImagesLoadMode.STANDARD);
try {
// Those images should not be touched by this image enum. {{
//
// Pre-create public and private image in different end-point
EndpointState vSphereEndpointState = createEndpointState(EndpointType.vsphere);
ImageState publicImageState_diffEP = createImageState(vSphereEndpointState, true, PUBLIC);
ImageState privateImageState_diffEP = createImageState(vSphereEndpointState, true, PRIVATE);
// Pre-create public and private image in same end-point but different region
ImageState publicImageState_diffRegion = createImageState(this.endpointState, false, PUBLIC);
ImageState privateImageState_diffRegion = createImageState(this.endpointState, false, PRIVATE);
// }}
// Create one stale image that should be deleted by this enumeration
ImageState staleImageState = createImageState(this.endpointState, true, PUBLIC);
// Validate 5 image states are preCREATED: 1 stale and 2 vSphere and 2 diff region
final int preCreatedCount = 1 + 2 + 2;
queryDocumentsAndAssertExpectedCount(getHost(), preCreatedCount, ImageService.FACTORY_LINK, EXACT_COUNT);
// Under TESTING
kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_SINGLE_IMAGE_FILTER);
// Validate 1 image state is CREATED and the 2 vSphere and 2 diff region are UNtouched
// plus 1 because we are not deleting the
final int postEnumCount = 1 + 2 + 2 + 1;
// resource, only disassociating it.
ServiceDocumentQueryResult imagesAfterEnum = queryDocumentsAndAssertExpectedCount(getHost(), postEnumCount, ImageService.FACTORY_LINK, EXACT_COUNT);
// Validate 1 stale image state is DISASSOCIATED
ImageState staleImage = Utils.fromJson(imagesAfterEnum.documents.get(staleImageState.documentSelfLink), ImageState.class);
Assert.assertTrue("Dummy image should have been disassociated.", staleImage.endpointLinks.isEmpty());
// Validate vSphere images are untouched
Assert.assertTrue("Private images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(privateImageState_diffEP.documentSelfLink));
Assert.assertTrue("Public images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(publicImageState_diffEP.documentSelfLink));
Assert.assertTrue("Private images from same endpoints but different region should not have been deleted.", imagesAfterEnum.documentLinks.contains(privateImageState_diffRegion.documentSelfLink));
Assert.assertTrue("Public images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(publicImageState_diffRegion.documentSelfLink));
} finally {
setImagesLoadMode(ImagesLoadMode.ALL);
}
}
Aggregations