use of com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE in project photon-model by vmware.
the class AWSS3StorageEnumerationAdapterService method createInternalTypeTag.
/**
* Send a POST to create internal type tag for S3. Don't wait for completion, tag will eventually get created
* while we go through the enumeration flow. If tag creation is successful, we set the internalTypeTagCreated
* flag and add the internalTypeTagSelfLink to DiskStates.
*/
private void createInternalTypeTag(S3StorageEnumerationContext aws, S3StorageEnumerationSubStage next) {
TagState internalTypeTagState = TagsUtil.newTagState(TAG_KEY_TYPE, AWSResourceType.s3_bucket.toString(), false, aws.parentCompute.tenantLinks);
Operation.createPost(aws.service, TagService.FACTORY_LINK).setBody(internalTypeTagState).setReferer(aws.service.getUri()).setCompletion((o, e) -> {
// log exception if tag creation fails with anything other than IDEMPOTENT_POST behaviour.
if (e != null) {
logSevere("Error creating internal type tag for S3");
return;
}
aws.internalTypeTagSelfLink = internalTypeTagState.documentSelfLink;
}).sendWith(aws.service);
aws.subStage = next;
handleReceivedEnumerationData(aws);
}
use of com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE in project photon-model by vmware.
the class AzureStorageEnumerationAdapterService method createInternalTypeTags.
private void createInternalTypeTags(StorageEnumContext context, StorageEnumStages next) {
TagState blobTypeTag = newTagState(TAG_KEY_TYPE, AzureResourceType.azure_blob.name(), false, context.parentCompute.tenantLinks);
TagState vhdTypeTag = newTagState(TAG_KEY_TYPE, AzureResourceType.azure_vhd.name(), false, context.parentCompute.tenantLinks);
Collection<Operation> opCollection = new ArrayList<>();
Operation blobTypeTagOp = Operation.createPost(getHost(), TagService.FACTORY_LINK).setBody(blobTypeTag);
opCollection.add(blobTypeTagOp);
Operation vhdTypeTagOp = Operation.createPost(getHost(), TagService.FACTORY_LINK).setBody(vhdTypeTag);
opCollection.add(vhdTypeTagOp);
OperationJoin.create(opCollection).setCompletion((ops, exs) -> {
if (exs != null) {
exs.values().forEach(ex -> logWarning(() -> String.format("Error: %s", ex.getMessage())));
} else {
for (Operation taskOp : ops.values()) {
TagState state = taskOp.getBody(TagState.class);
if (EnumUtils.isValidEnum(AzureResourceType.class, state.value)) {
switch(AzureResourceType.valueOf(state.value)) {
case azure_vhd:
context.internalVhdTypeTag = vhdTypeTag.documentSelfLink;
break;
case azure_blob:
context.internalBlobTypeTag = blobTypeTag.documentSelfLink;
break;
default:
break;
}
}
}
}
context.subStage = next;
handleSubStage(context);
}).sendWith(this);
}
use of com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE 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.constants.PhotonModelConstants.TAG_KEY_TYPE in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createInternalTypeTag.
private void createInternalTypeTag(EnumerationContext context, ComputeEnumerationSubStages next) {
TagService.TagState typeTag = newTagState(TAG_KEY_TYPE, AzureResourceType.azure_vm.toString(), false, context.parentCompute.tenantLinks);
Operation.CompletionHandler handler = (completedOp, failure) -> {
if (failure == null) {
// if no error, store the internal tag into context
context.internalTagLinks.add(typeTag.documentSelfLink);
} else {
// log the error and continue the enumeration
logWarning(() -> String.format("Error creating internal tag: %s", failure.getMessage()));
}
context.subStage = next;
handleSubStage(context);
};
sendRequest(Operation.createPost(this, TagService.FACTORY_LINK).setBody(typeTag).setCompletion(handler));
}
Aggregations