Search in sources :

Example 26 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class ComputeService method handleGet.

@Override
public void handleGet(Operation get) {
    ComputeState currentState = getState(get);
    boolean doExpand = get.getUri().getQuery() != null && UriUtils.hasODataExpandParamValue(get.getUri());
    if (!doExpand) {
        get.setBody(currentState).complete();
        return;
    }
    // retrieve the description and include in an augmented version of our
    // state.
    Operation getDesc = Operation.createGet(this, currentState.descriptionLink).setCompletion((o, e) -> {
        if (e != null) {
            get.fail(e);
            return;
        }
        ComputeDescription desc = o.getBody(ComputeDescription.class);
        ComputeStateWithDescription chsWithDesc = ComputeStateWithDescription.create(desc, currentState);
        get.setBody(chsWithDesc).complete();
    });
    sendRequest(getDesc);
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Operation(com.vmware.xenon.common.Operation)

Example 27 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class AzureTestUtil method createVMResourceFromSpec.

/**
 * Separate method to create VM from given spec
 */
public static ComputeState createVMResourceFromSpec(VMResourceSpec spec) throws Throwable {
    final String defaultVmRGName = spec.azureVmName;
    // TODO Modify createDefaultResourceGroupState() to have only spec parameter passed
    final ResourceGroupState defaultVmRG = createDefaultResourceGroupState(spec.host, defaultVmRGName, spec.computeHost, spec.endpointState, ResourceGroupStateType.AzureResourceGroup);
    final String defaultVmRGLink = defaultVmRG.documentSelfLink;
    if (spec.networkRGLink == null) {
        // The RG where the VM is deployed is also used as RG for the Network!
        spec.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(spec.host, AZURE_STORAGE_CONTAINER_RG_NAME, spec.computeHost, spec.endpointState, ResourceGroupStateType.AzureStorageContainer);
    final Set<String> networkRGLinks = new HashSet<>();
    networkRGLinks.add(spec.networkRGLink);
    networkRGLinks.add(azureStorageContainerRG.documentSelfLink);
    final Set<String> sgRGLinks = new HashSet<>();
    sgRGLinks.add(sgRGLink);
    sgRGLinks.add(azureStorageContainerRG.documentSelfLink);
    AuthCredentialsServiceState azureVMAuth = new AuthCredentialsServiceState();
    azureVMAuth.userEmail = AZURE_ADMIN_USERNAME;
    azureVMAuth.privateKey = AZURE_ADMIN_PASSWORD;
    azureVMAuth = TestUtils.doPost(spec.host, azureVMAuth, AuthCredentialsServiceState.class, UriUtils.buildUri(spec.host, AuthCredentialsService.FACTORY_LINK));
    // Create a VM desc
    ComputeDescription azureVMDesc = new ComputeDescription();
    azureVMDesc.id = UUID.randomUUID().toString();
    azureVMDesc.documentSelfLink = azureVMDesc.id;
    azureVMDesc.name = azureVMDesc.id;
    azureVMDesc.regionId = AZURE_RESOURCE_GROUP_LOCATION;
    azureVMDesc.authCredentialsLink = azureVMAuth.documentSelfLink;
    azureVMDesc.tenantLinks = spec.endpointState.tenantLinks;
    azureVMDesc.endpointLink = spec.endpointState.documentSelfLink;
    azureVMDesc.endpointLinks = new HashSet<>();
    azureVMDesc.endpointLinks.add(spec.endpointState.documentSelfLink);
    azureVMDesc.computeHostLink = spec.endpointState.computeHostLink;
    azureVMDesc.instanceType = AZURE_VM_SIZE;
    azureVMDesc.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
    azureVMDesc.customProperties = new HashMap<>();
    // set the create service to the azure instance service
    azureVMDesc.instanceAdapterReference = UriUtils.buildUri(spec.host, AzureUriPaths.AZURE_INSTANCE_ADAPTER);
    azureVMDesc.powerAdapterReference = UriUtils.buildUri(spec.host, AzureUriPaths.AZURE_POWER_ADAPTER);
    azureVMDesc = TestUtils.doPost(spec.host, azureVMDesc, ComputeDescription.class, UriUtils.buildUri(spec.host, ComputeDescriptionService.FACTORY_LINK));
    DiskState rootDisk = new DiskState();
    rootDisk.name = spec.azureVmName + "-boot-disk";
    rootDisk.id = UUID.randomUUID().toString();
    rootDisk.documentSelfLink = rootDisk.id;
    rootDisk.type = DiskType.HDD;
    rootDisk.storageType = AZURE_STORAGE_DISKS;
    // Custom OSDisk size of 32 GBs
    rootDisk.capacityMBytes = AZURE_CUSTOM_OSDISK_SIZE;
    rootDisk.bootOrder = 1;
    rootDisk.endpointLink = spec.endpointState.documentSelfLink;
    rootDisk.endpointLinks = new HashSet<>();
    rootDisk.endpointLinks.add(spec.endpointState.documentSelfLink);
    rootDisk.computeHostLink = spec.endpointState.computeHostLink;
    rootDisk.tenantLinks = spec.endpointState.tenantLinks;
    if (spec.isManagedDisk) {
        rootDisk.tagLinks = createTagStateSet(spec.host, spec.endpointState.tenantLinks, TAG_KEY_TYPE, AzureResourceType.azure_managed_disk.name());
    } else {
        rootDisk.tagLinks = createTagStateSet(spec.host, spec.endpointState.tenantLinks, TAG_KEY_TYPE, AzureResourceType.azure_vhd.name());
    }
    rootDisk.customProperties = new HashMap<>();
    rootDisk.customProperties.put(AZURE_OSDISK_CACHING, DEFAULT_OS_DISK_CACHING.name());
    if (spec.imageSource.type == Type.PRIVATE_IMAGE) {
        if (spec.isManagedDisk) {
            rootDisk.imageLink = spec.imageSource.asImageState().documentSelfLink;
            rootDisk.customProperties.put(AzureConstants.AZURE_MANAGED_DISK_TYPE, SkuName.STANDARD_LRS.toString());
        }
    } else if (spec.imageSource.type == Type.PUBLIC_IMAGE) {
        if (spec.isManagedDisk) {
            rootDisk.imageLink = spec.imageSource.asImageState().documentSelfLink;
            rootDisk.customProperties.put(AzureConstants.AZURE_MANAGED_DISK_TYPE, SkuName.STANDARD_LRS.toString());
        } else {
            rootDisk.imageLink = spec.imageSource.asImageState().documentSelfLink;
            if (spec.storageAccountName == null || spec.resourceGroupForStorageAccount == null) {
                rootDisk.customProperties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, (spec.azureVmName + "sa").replaceAll("[_-]", "").toLowerCase());
                rootDisk.customProperties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_RG_NAME, defaultVmRGName);
            } else {
                rootDisk.customProperties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, spec.storageAccountName);
                rootDisk.customProperties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_RG_NAME, spec.resourceGroupForStorageAccount);
            }
            rootDisk.customProperties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_TYPE, AZURE_STORAGE_ACCOUNT_TYPE);
        }
    } else if (spec.imageSource.type == Type.IMAGE_REFERENCE) {
        rootDisk.sourceImageReference = URI.create(spec.imageSource.asRef());
    }
    rootDisk = TestUtils.doPost(spec.host, rootDisk, DiskState.class, UriUtils.buildUri(spec.host, DiskService.FACTORY_LINK));
    List<String> vmDisks = new ArrayList<>();
    vmDisks.add(rootDisk.documentSelfLink);
    // create additional disks
    if (spec.numberOfAdditionalDisks > 0) {
        // TODO Need to modify createAdditionalDisks() to have only spec passed as parameter
        vmDisks.addAll(createAdditionalDisks(spec.host, spec.azureVmName, spec.endpointState, spec.numberOfAdditionalDisks, spec.persistentDisks, spec.isManagedDisk));
    }
    // Add external existing data disks (if present) to the list for attaching
    if (null != spec.externalDiskLinks && spec.externalDiskLinks.size() > 0) {
        vmDisks.addAll(spec.externalDiskLinks);
    }
    // Create NICs
    List<String> nicLinks = createDefaultNicStates(spec.host, spec.computeHost, spec.endpointState, networkRGLinks, sgRGLinks, spec.nicSpecs, spec.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 = spec.azureVmName;
    computeState.parentLink = spec.computeHost.documentSelfLink;
    computeState.type = ComputeType.VM_GUEST;
    computeState.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
    computeState.descriptionLink = azureVMDesc.documentSelfLink;
    computeState.resourcePoolLink = spec.computeHost.resourcePoolLink;
    computeState.diskLinks = vmDisks;
    computeState.networkInterfaceLinks = nicLinks;
    computeState.customProperties = Collections.singletonMap(RESOURCE_GROUP_NAME, defaultVmRGName);
    computeState.groupLinks = Collections.singleton(defaultVmRGLink);
    computeState.endpointLink = spec.endpointState.documentSelfLink;
    computeState.endpointLinks = new HashSet<>();
    computeState.endpointLinks.add(spec.endpointState.documentSelfLink);
    computeState.computeHostLink = spec.endpointState.computeHostLink;
    computeState.tenantLinks = spec.endpointState.tenantLinks;
    computeState.creationTimeMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
    return TestUtils.doPost(spec.host, computeState, ComputeState.class, UriUtils.buildUri(spec.host, ComputeService.FACTORY_LINK));
}
Also used : AZURE_STORAGE_ACCOUNTS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNTS) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) AZURE_STORAGE_BLOBS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_BLOBS) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) VerificationHost(com.vmware.xenon.common.test.VerificationHost) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) InetAddress(java.net.InetAddress) Utils(com.vmware.xenon.common.Utils) QueryTerm(com.vmware.xenon.services.common.QueryTask.QueryTerm) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) GatewaySpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs.GatewaySpec) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) COMPUTE_HOST_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.COMPUTE_HOST_LINK_PROP_NAME) ImageService(com.vmware.photon.controller.model.resources.ImageService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) EnumSet(java.util.EnumSet) VirtualNetworkGatewayIPConfigurationInner(com.microsoft.azure.management.network.implementation.VirtualNetworkGatewayIPConfigurationInner) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) AZURE_STORAGE_ACCOUNT_KEY1(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_KEY1) AZURE_STORAGE_ACCOUNT_KEY2(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_KEY2) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) CachingTypes(com.microsoft.azure.management.compute.CachingTypes) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) DEFAULT_INSTANCE_ADAPTER_REFERENCE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DEFAULT_INSTANCE_ADAPTER_REFERENCE) Set(java.util.Set) SecurityRuleAccess(com.microsoft.azure.management.network.SecurityRuleAccess) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) AZURE_STORAGE_CONTAINER_LEASE_STATUS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_STATUS) TagService(com.vmware.photon.controller.model.resources.TagService) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) AZURE_STORAGE_CONTAINER_LEASE_STATE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_STATE) TaskState(com.vmware.xenon.common.TaskState) AZURE_DATA_DISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DATA_DISK_CACHING) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) AzureResourceType.azure_net_interface(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType.azure_net_interface) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) ArrayList(java.util.ArrayList) VirtualNetworkGatewayInner(com.microsoft.azure.management.network.implementation.VirtualNetworkGatewayInner) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Rule(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState.Rule) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) MEMORY_USED_PERCENT(com.vmware.photon.controller.model.constants.PhotonModelConstants.MEMORY_USED_PERCENT) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) CPU_UTILIZATION_PERCENT(com.vmware.photon.controller.model.constants.PhotonModelConstants.CPU_UTILIZATION_PERCENT) VirtualNetworkGatewayType(com.microsoft.azure.management.network.VirtualNetworkGatewayType) AZURE_STORAGE_CONTAINER_LEASE_LAST_MODIFIED(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_LAST_MODIFIED) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) VirtualNetworkGatewaySkuName(com.microsoft.azure.management.network.VirtualNetworkGatewaySkuName) ServiceCallback(com.microsoft.rest.ServiceCallback) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SecurityGroupService(com.vmware.photon.controller.model.resources.SecurityGroupService) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ImageSource(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext.ImageSource) AzureComputeEnumerationAdapterService(com.vmware.photon.controller.model.adapters.azure.enumeration.AzureComputeEnumerationAdapterService) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) Assert.assertNull(org.junit.Assert.assertNull) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) SecurityRuleInner(com.microsoft.azure.management.network.implementation.SecurityRuleInner) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) STORAGE_USED_BYTES(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_USED_BYTES) NicSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs.NicSpec) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) SecurityRuleProtocol(com.microsoft.azure.management.network.SecurityRuleProtocol) IPAllocationMethod(com.microsoft.azure.management.network.IPAllocationMethod) QueryTask(com.vmware.xenon.services.common.QueryTask) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Random(java.util.Random) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) DEFAULT_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DEFAULT_DISK_TYPE) StatsAggregationTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService) ByteBuffer(java.nio.ByteBuffer) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) AzureResourceType.azure_subnet(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType.azure_subnet) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) StatsAggregationTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService.StatsAggregationTaskState) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SecurityRuleDirection(com.microsoft.azure.management.network.SecurityRuleDirection) StatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) SkuName(com.microsoft.azure.management.storage.SkuName) AddressSpace(com.microsoft.azure.management.network.AddressSpace) NetworkInterfaceDescriptionService(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService) DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) AZURE_STORAGE_CONTAINERS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINERS) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ENDPOINT_LINK_EXPLICIT_SUPPORT(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.ENDPOINT_LINK_EXPLICIT_SUPPORT) Objects(java.util.Objects) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) VirtualNetworkGatewaySkuTier(com.microsoft.azure.management.network.VirtualNetworkGatewaySkuTier) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) InstanceViewTypes(com.microsoft.azure.management.compute.InstanceViewTypes) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureEnumerationAdapterService(com.vmware.photon.controller.model.adapters.azure.enumeration.AzureEnumerationAdapterService) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) DiskService(com.vmware.photon.controller.model.resources.DiskService) SubResource(com.microsoft.azure.SubResource) AZURE_OSDISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_OSDISK_CACHING) Type(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext.ImageSource.Type) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) ResourceRemovalTaskService(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) HashMap(java.util.HashMap) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) Level(java.util.logging.Level) HashSet(java.util.HashSet) AZURE_STORAGE_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_TYPE) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) DEFAULT_DISK_CAPACITY(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DEFAULT_DISK_CAPACITY) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) VpnType(com.microsoft.azure.management.network.VpnType) AZURE_TENANT_ID(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_TENANT_ID) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Assert.assertNotNull(org.junit.Assert.assertNotNull) AzureResourceType.azure_vnet(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType.azure_vnet) Operation(com.vmware.xenon.common.Operation) AZURE_STORAGE_DISKS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_DISKS) VirtualNetworkGatewaySku(com.microsoft.azure.management.network.VirtualNetworkGatewaySku) TimeUnit(java.util.concurrent.TimeUnit) CloudException(com.microsoft.azure.CloudException) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) Collections(java.util.Collections) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) NetSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs.NetSpec) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ArrayList(java.util.ArrayList) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) HashSet(java.util.HashSet)

Example 28 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class AzureTestUtil method buildComputeDescription.

public static ComputeDescription buildComputeDescription(VerificationHost host, ComputeState computeHost, EndpointState endpointState, AuthCredentialsServiceState azureVMAuth) throws Throwable {
    if (azureVMAuth == null) {
        azureVMAuth = new AuthCredentialsServiceState();
        azureVMAuth.userEmail = AZURE_ADMIN_USERNAME;
        azureVMAuth.privateKey = AZURE_ADMIN_PASSWORD;
        azureVMAuth = TestUtils.doPost(host, azureVMAuth, AuthCredentialsServiceState.class, UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK));
    }
    ComputeDescription azureVMDesc = new ComputeDescription();
    azureVMDesc.id = UUID.randomUUID().toString();
    azureVMDesc.documentSelfLink = azureVMDesc.id;
    azureVMDesc.name = azureVMDesc.id;
    azureVMDesc.regionId = AZURE_RESOURCE_GROUP_LOCATION;
    azureVMDesc.authCredentialsLink = azureVMAuth.documentSelfLink;
    azureVMDesc.tenantLinks = endpointState.tenantLinks;
    azureVMDesc.endpointLink = endpointState.documentSelfLink;
    azureVMDesc.endpointLinks = new HashSet<>();
    azureVMDesc.endpointLinks.add(endpointState.documentSelfLink);
    azureVMDesc.computeHostLink = computeHost.documentSelfLink;
    azureVMDesc.instanceType = AZURE_VM_SIZE;
    azureVMDesc.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
    azureVMDesc.customProperties = new HashMap<>();
    // set the create service to the azure instance service
    azureVMDesc.instanceAdapterReference = UriUtils.buildUri(host, AzureUriPaths.AZURE_INSTANCE_ADAPTER);
    azureVMDesc.powerAdapterReference = UriUtils.buildUri(host, AzureUriPaths.AZURE_POWER_ADAPTER);
    azureVMDesc = TestUtils.doPost(host, azureVMDesc, ComputeDescription.class, UriUtils.buildUri(host, ComputeDescriptionService.FACTORY_LINK));
    return azureVMDesc;
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 29 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class AzurePowerServiceTest method test.

@Test
public void test() throws Throwable {
    assumeFalse(this.isMock);
    this.vmState = createDefaultVMResource(this.host, azureVMName, computeHost, endpointState, DEFAULT_NIC_SPEC);
    kickOffProvisionTask();
    ComputeDescription computeHostDesc = this.host.getServiceState(null, ComputeDescription.class, UriUtils.buildUri(this.host, this.vmState.descriptionLink));
    assertNotNull(computeHostDesc.powerAdapterReference);
    // by default new VM should be ON state
    assertVmCurrentPowerState(PowerState.ON);
    triggerPowerChange(PowerState.OFF, computeHostDesc.powerAdapterReference);
    assertVmCurrentPowerState(PowerState.OFF);
    // assert IP address to empty after POWER OFF
    assertVMCurrentAddressEmpty();
    triggerPowerChange(PowerState.ON, computeHostDesc.powerAdapterReference);
    assertVmCurrentPowerState(PowerState.ON);
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Test(org.junit.Test)

Example 30 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class AzureLoadBalancerServiceTest method setUpTests.

@Before
public void setUpTests() throws Throwable {
    if (computeHost == null) {
        ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
        endpointState = this.createEndpointState();
        // create a compute host for the Azure
        computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
    }
    AuthCredentialsServiceState azureVMAuth = new AuthCredentialsServiceState();
    azureVMAuth.userEmail = AZURE_ADMIN_USERNAME;
    azureVMAuth.privateKey = AZURE_ADMIN_PASSWORD;
    azureVMAuth = TestUtils.doPost(host, azureVMAuth, AuthCredentialsServiceState.class, UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK));
    ComputeDescription compDesc = buildComputeDescription(host, computeHost, endpointState, azureVMAuth);
    this.rgName = AzureUtils.DEFAULT_GROUP_PREFIX + compDesc.documentCreationTimeMicros / 1000;
    ResourceGroupState rgState = createDefaultResourceGroupState(this.host, this.rgName, computeHost, endpointState, ResourceGroupStateType.AzureResourceGroup);
    networkState = createNetworkState(rgState.documentSelfLink);
    vmStates = new ArrayList<>();
    for (int i = 0; i < poolSize; i++) {
        ComputeState vmState = createDefaultVMResource(getHost(), this.rgName + "VM" + i, computeHost, endpointState, NO_PUBLIC_IP_NIC_SPEC, null, 0, compDesc, this.rgName);
        vmStates.add(vmState);
    }
    subnetState = createSubnetState(this.subnetName);
    if (!this.isMock) {
        this.loadBalancerClient = getAzureSdkClients().getNetworkManagementClientImpl().loadBalancers();
        this.rgOpsClient = getAzureSdkClients().getResourceManagementClientImpl().resourceGroups();
        ResourceGroupInner rg = new ResourceGroupInner();
        rg.withName(this.rgName);
        rg.withLocation(this.regionId);
        this.rgOpsClient.createOrUpdate(this.rgName, rg);
        VirtualNetworkInner vNet = new VirtualNetworkInner();
        AddressSpace addressSpace = new AddressSpace();
        addressSpace.withAddressPrefixes(Collections.singletonList(AZURE_DEFAULT_VPC_CIDR));
        vNet.withAddressSpace(addressSpace);
        vNet.withLocation(this.regionId);
        VirtualNetworksInner vNetClient = getAzureSdkClients().getNetworkManagementClientImpl().virtualNetworks();
        vNetClient.createOrUpdate(this.rgName, this.vNetName, vNet);
        kickOffComputeProvision();
        kickOffSubnetProvision(InstanceRequestType.CREATE, subnetState, TaskStage.FINISHED);
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VirtualNetworksInner(com.microsoft.azure.management.network.implementation.VirtualNetworksInner) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) AddressSpace(com.microsoft.azure.management.network.AddressSpace) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) AzureTestUtil.buildComputeDescription(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.buildComputeDescription) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) Before(org.junit.Before)

Aggregations

ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)78 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 Operation (com.vmware.xenon.common.Operation)21 ArrayList (java.util.ArrayList)21 QueryTask (com.vmware.xenon.services.common.QueryTask)17 Test (org.junit.Test)17 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)15 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 List (java.util.List)15 Utils (com.vmware.xenon.common.Utils)14 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)14 URI (java.net.URI)14 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)13 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)12 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)12 UriUtils (com.vmware.xenon.common.UriUtils)12 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)11