Search in sources :

Example 61 with ComputeDescription

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

the class StatsCollectionTaskServiceTest method testCustomStatsAdapter.

@Test
public void testCustomStatsAdapter() throws Throwable {
    ResourcePoolState rpState = new ResourcePoolState();
    rpState.name = UUID.randomUUID().toString();
    ResourcePoolState rpReturnState = postServiceSynchronously(ResourcePoolService.FACTORY_LINK, rpState, ResourcePoolState.class);
    ComputeDescription desc = new ComputeDescription();
    desc.name = rpState.name;
    desc.statsAdapterReferences = Collections.singleton(UriUtils.buildUri(this.host, CustomStatsAdapter.SELF_LINK));
    ComputeDescription descReturnState = postServiceSynchronously(ComputeDescriptionService.FACTORY_LINK, desc, ComputeDescription.class);
    ComputeState computeState = new ComputeState();
    computeState.name = rpState.name;
    computeState.descriptionLink = descReturnState.documentSelfLink;
    computeState.resourcePoolLink = rpReturnState.documentSelfLink;
    List<String> computeLinks = new ArrayList<>();
    for (int i = 0; i < this.numResources; i++) {
        ComputeState res = postServiceSynchronously(ComputeService.FACTORY_LINK, computeState, ComputeState.class);
        computeLinks.add(res.documentSelfLink);
    }
    // create a stats collection scheduler task
    StatsCollectionTaskState statCollectionState = new StatsCollectionTaskState();
    statCollectionState.resourcePoolLink = rpReturnState.documentSelfLink;
    statCollectionState.statsAdapterReference = UriUtils.buildUri(this.host, CustomStatsAdapter.SELF_LINK);
    statCollectionState.options = EnumSet.of(TaskOption.SELF_DELETE_ON_COMPLETION);
    ScheduledTaskState statsCollectionTaskState = new ScheduledTaskState();
    statsCollectionTaskState.factoryLink = StatsCollectionTaskService.FACTORY_LINK;
    statsCollectionTaskState.initialStateJson = Utils.toJson(statCollectionState);
    statsCollectionTaskState.intervalMicros = TimeUnit.MILLISECONDS.toMicros(500);
    statsCollectionTaskState = postServiceSynchronously(ScheduledTaskService.FACTORY_LINK, statsCollectionTaskState, ScheduledTaskState.class);
    ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ScheduledTaskService.FACTORY_LINK)));
    assertTrue(res.documents.size() > 0);
    // get stats from resources
    for (int i = 0; i < computeLinks.size(); i++) {
        String statsUriPath = UriUtils.buildUriPath(computeLinks.get(i), ServiceHost.SERVICE_URI_SUFFIX_STATS);
        this.host.waitFor("Error waiting for stats", () -> {
            ServiceStats resStats = getServiceSynchronously(statsUriPath, ServiceStats.class);
            boolean returnStatus = false;
            // was populated in the in memory stats
            for (ServiceStat stat : resStats.entries.values()) {
                if (stat.name.startsWith(UriUtils.getLastPathSegment(CustomStatsAdapter.SELF_LINK))) {
                    returnStatus = true;
                    break;
                }
            }
            return returnStatus;
        });
    }
    // clean up
    deleteServiceSynchronously(statsCollectionTaskState.documentSelfLink);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ArrayList(java.util.ArrayList) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ServiceStats(com.vmware.xenon.common.ServiceStats) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 62 with ComputeDescription

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

the class StatsCollectionTaskServiceTest method testStatsCollection.

private void testStatsCollection(boolean testOnCluster) throws Throwable {
    VerificationHost metricHost = null;
    if (testOnCluster) {
        metricHost = this.setupMetricHost();
    }
    // Use this.host if metricHost is null.
    VerificationHost verificationHost = (metricHost == null ? this.host : metricHost);
    // create a metric host
    // create a compute description for all the computes
    ComputeDescription cDesc = new ComputeDescription();
    cDesc.name = UUID.randomUUID().toString();
    cDesc.statsAdapterReference = UriUtils.buildUri(this.host, MockStatsAdapter.SELF_LINK);
    ComputeDescription descReturnState = postServiceSynchronously(ComputeDescriptionService.FACTORY_LINK, cDesc, ComputeDescription.class);
    // create multiple computes
    ComputeState computeState = new ComputeState();
    computeState.name = UUID.randomUUID().toString();
    computeState.descriptionLink = descReturnState.documentSelfLink;
    List<String> computeLinks = new ArrayList<>(this.numResources);
    for (int i = 0; i < this.numResources; i++) {
        ComputeState res = postServiceSynchronously(ComputeService.FACTORY_LINK, computeState, ComputeState.class);
        computeLinks.add(res.documentSelfLink);
    }
    // create a resource pool including all the created computes
    ResourcePoolState rpState = new ResourcePoolState();
    rpState.name = UUID.randomUUID().toString();
    rpState.properties = EnumSet.of(ResourcePoolProperty.ELASTIC);
    rpState.query = Query.Builder.create().addKindFieldClause(ComputeState.class).addInClause(ServiceDocument.FIELD_NAME_SELF_LINK, computeLinks).build();
    ResourcePoolState rpReturnState = postServiceSynchronously(ResourcePoolService.FACTORY_LINK, rpState, ResourcePoolState.class);
    // create a stats collection scheduler task
    StatsCollectionTaskState statCollectionState = new StatsCollectionTaskState();
    statCollectionState.resourcePoolLink = rpReturnState.documentSelfLink;
    statCollectionState.options = EnumSet.of(TaskOption.SELF_DELETE_ON_COMPLETION);
    ScheduledTaskState statsCollectionTaskState = new ScheduledTaskState();
    statsCollectionTaskState.factoryLink = StatsCollectionTaskService.FACTORY_LINK;
    statsCollectionTaskState.initialStateJson = Utils.toJson(statCollectionState);
    statsCollectionTaskState.intervalMicros = TimeUnit.SECONDS.toMicros(2);
    statsCollectionTaskState = postServiceSynchronously(ScheduledTaskService.FACTORY_LINK, statsCollectionTaskState, ScheduledTaskState.class);
    ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ScheduledTaskService.FACTORY_LINK)));
    assertTrue(res.documents.size() > 0);
    // the last successful collection time should be populated as an in memory stat.
    for (int i = 0; i < this.numResources; i++) {
        String statsUriPath = UriUtils.buildUriPath(computeLinks.get(i), ServiceHost.SERVICE_URI_SUFFIX_STATS);
        this.host.waitFor("Error waiting for in memory stats", () -> {
            ServiceStats resStats = getServiceSynchronously(statsUriPath, ServiceStats.class);
            boolean returnStatus = false;
            for (ServiceStat stat : resStats.entries.values()) {
                if (stat.latestValue > 0) {
                    returnStatus = true;
                    break;
                }
            }
            return returnStatus;
        });
    }
    host.log(Level.INFO, "Successfully verified that all the last collection time is available in memory.");
    // persisted at a per metric level along with the last collection run time
    for (String computeLink : computeLinks) {
        ResourceMetrics metric = getResourceMetrics(verificationHost, computeLink, MockStatsAdapter.KEY_1);
        assertNotNull("The resource metric for" + MockStatsAdapter.KEY_1 + " should not be null ", metric);
        assertEquals(metric.entries.size(), 1);
        assertEquals(metric.customProperties.get("prop1"), "val1");
        ResourceMetrics metric2 = getResourceMetrics(verificationHost, computeLink, MockStatsAdapter.KEY_2);
        assertNotNull("The resource metric for" + MockStatsAdapter.KEY_2 + "should not be null ", metric2);
        assertEquals(metric2.entries.size(), 1);
        String lastSuccessfulRunMetricKey = UriUtils.getLastPathSegment(MockStatsAdapter.SELF_LINK) + StatsUtil.SEPARATOR + PhotonModelConstants.LAST_SUCCESSFUL_STATS_COLLECTION_TIME;
        ResourceMetrics metricLastRun = getResourceMetrics(verificationHost, computeLink, lastSuccessfulRunMetricKey);
        assertNotNull("The resource metric for" + lastSuccessfulRunMetricKey + " should not be null ", metricLastRun);
    }
    host.log(Level.INFO, "Successfully verified that the required resource metrics are persisted in the resource metrics table");
    // Verify sorted order of the metrics versions by timestamp
    for (String computeLink : computeLinks) {
        // get all versions
        QueryTask qt = QueryTask.Builder.createDirectTask().addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.SORT).orderAscending(ServiceDocument.FIELD_NAME_SELF_LINK, TypeName.STRING).setQuery(Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, UriUtils.getLastPathSegment(computeLink)), MatchType.PREFIX).addRangeClause(QuerySpecification.buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, MockStatsAdapter.KEY_1), NumericRange.createDoubleRange(Double.MIN_VALUE, Double.MAX_VALUE, true, true)).build()).build();
        verificationHost.createQueryTaskService(qt, false, true, qt, null);
        ResourceMetrics prevMetric = null;
        for (String documentLink : qt.results.documentLinks) {
            ResourceMetrics metric = Utils.fromJson(qt.results.documents.get(documentLink), ResourceMetrics.class);
            if (prevMetric == null) {
                prevMetric = metric;
                continue;
            }
            assertTrue(prevMetric.timestampMicrosUtc < metric.timestampMicrosUtc);
        }
    }
    // verify that the aggregation tasks have been deleted
    this.host.waitFor("Timeout waiting for task to expire", () -> {
        ServiceDocumentQueryResult collectRes = this.host.getFactoryState(UriUtils.buildUri(this.host, StatsCollectionTaskService.FACTORY_LINK));
        if (collectRes.documentLinks.size() == 0) {
            return true;
        }
        return false;
    });
    if (testOnCluster) {
        this.cleanUpMetricHost(metricHost);
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ArrayList(java.util.ArrayList) VerificationHost(com.vmware.xenon.common.test.VerificationHost) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ServiceStats(com.vmware.xenon.common.ServiceStats) QueryTask(com.vmware.xenon.services.common.QueryTask) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)

Example 63 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription 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));
}
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) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 64 with ComputeDescription

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

the class AzureTestUtil method createDefaultComputeHost.

/**
 * Create a compute host description for an Azure instance
 */
public static ComputeState createDefaultComputeHost(VerificationHost host, String resourcePoolLink, EndpointState endpointState) throws Throwable {
    ComputeDescription azureHostDescription = new ComputeDescription();
    azureHostDescription.id = UUID.randomUUID().toString();
    azureHostDescription.name = azureHostDescription.id;
    azureHostDescription.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
    azureHostDescription.documentSelfLink = azureHostDescription.id;
    azureHostDescription.supportedChildren = new ArrayList<>();
    azureHostDescription.supportedChildren.add(ComputeType.VM_GUEST.name());
    azureHostDescription.instanceAdapterReference = UriUtils.buildUri(host, AzureUriPaths.AZURE_INSTANCE_ADAPTER);
    azureHostDescription.enumerationAdapterReference = UriUtils.buildUri(host, AzureUriPaths.AZURE_ENUMERATION_ADAPTER);
    azureHostDescription.statsAdapterReference = UriUtils.buildUri(host, AzureUriPaths.AZURE_STATS_ADAPTER);
    azureHostDescription.authCredentialsLink = endpointState.authCredentialsLink;
    azureHostDescription.endpointLink = endpointState.documentSelfLink;
    azureHostDescription.endpointLinks = new HashSet<>();
    azureHostDescription.endpointLinks.add(endpointState.documentSelfLink);
    azureHostDescription.computeHostLink = endpointState.computeHostLink;
    azureHostDescription.tenantLinks = endpointState.tenantLinks;
    azureHostDescription = TestUtils.doPost(host, azureHostDescription, ComputeDescription.class, UriUtils.buildUri(host, ComputeDescriptionService.FACTORY_LINK));
    ComputeState azureComputeHost = new ComputeState();
    azureComputeHost.id = UUID.randomUUID().toString();
    azureComputeHost.documentSelfLink = azureComputeHost.id;
    azureComputeHost.type = ComputeType.ENDPOINT_HOST;
    azureComputeHost.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
    azureComputeHost.name = azureHostDescription.name;
    azureComputeHost.descriptionLink = azureHostDescription.documentSelfLink;
    azureComputeHost.resourcePoolLink = resourcePoolLink;
    azureComputeHost.endpointLink = endpointState.documentSelfLink;
    azureComputeHost.endpointLinks = new HashSet<>();
    azureComputeHost.endpointLinks.add(endpointState.documentSelfLink);
    azureComputeHost.tenantLinks = endpointState.tenantLinks;
    return TestUtils.doPost(host, azureComputeHost, ComputeState.class, UriUtils.buildUri(host, ComputeService.FACTORY_LINK));
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 65 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription 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);
}
Also used : GCPUriPaths(com.vmware.photon.controller.model.adapters.gcp.GCPUriPaths) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) GCPUtils.privateKeyFromPkcs8(com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils.privateKeyFromPkcs8) QueryTask(com.vmware.xenon.services.common.QueryTask) OSType(com.vmware.photon.controller.model.ComputeProperties.OSType) GCPInstance(com.vmware.photon.controller.model.adapters.gcp.podo.vm.GCPInstance) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) ENVIRONMENT_NAME_GCP(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_GCP) Utils(com.vmware.xenon.common.Utils) GeneralSecurityException(java.security.GeneralSecurityException) GCPInstancesList(com.vmware.photon.controller.model.adapters.gcp.podo.vm.GCPInstancesList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) URI(java.net.URI) DEFAULT_DISK_SOURCE_IMAGE(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.DEFAULT_DISK_SOURCE_IMAGE) GCPUtils.assignPowerState(com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils.assignPowerState) GCPUtils.extractActualInstanceType(com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils.extractActualInstanceType) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) DISK_AUTO_DELETE(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.DISK_AUTO_DELETE) StatelessService(com.vmware.xenon.common.StatelessService) DEFAULT_DISK_SERVICE_REFERENCE(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.DEFAULT_DISK_SERVICE_REFERENCE) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GCPDisk(com.vmware.photon.controller.model.adapters.gcp.podo.vm.GCPDisk) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) LIST_VM_TEMPLATE_URI(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.LIST_VM_TEMPLATE_URI) UUID(java.util.UUID) ServiceHost(com.vmware.xenon.common.ServiceHost) List(java.util.List) AUTH_HEADER_BEARER_PREFIX(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.AUTH_HEADER_BEARER_PREFIX) PrivateKey(java.security.PrivateKey) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) DiskService(com.vmware.photon.controller.model.resources.DiskService) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) GCPUtils(com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils) MAX_RESULTS(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.MAX_RESULTS) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PAGE_TOKEN(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.PAGE_TOKEN) UriPaths(com.vmware.photon.controller.model.UriPaths) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) LinkedList(java.util.LinkedList) GCPAccessTokenResponse(com.vmware.photon.controller.model.adapters.gcp.podo.authorization.GCPAccessTokenResponse) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) GCPUtils.extractRegionFromZone(com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils.extractRegionFromZone) EncryptionUtils(com.vmware.photon.controller.model.security.util.EncryptionUtils) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) IOException(java.io.IOException) ComputeScopes(com.google.api.services.compute.ComputeScopes) Consumer(java.util.function.Consumer) CUSTOM_OS_TYPE(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE) DEFAULT_DISK_CAPACITY(com.vmware.photon.controller.model.adapters.gcp.constants.GCPConstants.DEFAULT_DISK_CAPACITY) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) GCPUtils.assignIPAddress(com.vmware.photon.controller.model.adapters.gcp.utils.GCPUtils.assignIPAddress) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) JSONWebToken(com.vmware.photon.controller.model.adapters.gcp.utils.JSONWebToken) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) GCPDisk(com.vmware.photon.controller.model.adapters.gcp.podo.vm.GCPDisk) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation)

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