Search in sources :

Example 26 with ResourcePoolState

use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.

the class BaseVSphereAdapterTest method createResourcePool.

protected ResourcePoolState createResourcePool() throws Throwable {
    ResourcePoolState inPool = new ResourcePoolState();
    inPool.name = nextName("rp");
    inPool.id = inPool.name;
    inPool.minCpuCount = 1L;
    inPool.minMemoryBytes = 1024L;
    ResourcePoolState returnPool = TestUtils.doPost(this.host, inPool, ResourcePoolState.class, UriUtils.buildUri(this.host, ResourcePoolService.FACTORY_LINK));
    return returnPool;
}
Also used : ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)

Example 27 with ResourcePoolState

use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.

the class SingleResourceStatsAggregationTaskServiceTest method testResourceStatsAggregation.

@Test
public void testResourceStatsAggregation() throws Throwable {
    // create a resource pool
    ResourcePoolState rpState = new ResourcePoolState();
    rpState.name = "testName";
    ResourcePoolState rpReturnState = postServiceSynchronously(ResourcePoolService.FACTORY_LINK, rpState, ResourcePoolState.class);
    ComputeState[] computeStateArray = new ComputeState[NUM_COMPUTE_RESOURCES];
    for (int i = 0; i < NUM_COMPUTE_RESOURCES; i++) {
        ComputeDescription cDesc = new ComputeDescription();
        cDesc.name = rpState.name;
        cDesc.statsAdapterReference = UriUtils.buildUri(this.host, MockStatsAdapter.SELF_LINK);
        ComputeDescription descReturnState = postServiceSynchronously(ComputeDescriptionService.FACTORY_LINK, cDesc, ComputeDescription.class);
        ComputeState computeState = new ComputeState();
        computeState.name = rpState.name;
        computeState.descriptionLink = descReturnState.documentSelfLink;
        computeState.resourcePoolLink = rpReturnState.documentSelfLink;
        computeStateArray[i] = postServiceSynchronously(ComputeService.FACTORY_LINK, computeState, ComputeState.class);
    }
    StatsCollectionTaskState collectionTaskState = new StatsCollectionTaskState();
    collectionTaskState.resourcePoolLink = rpReturnState.documentSelfLink;
    collectionTaskState.taskInfo = TaskState.createDirect();
    int counter = 0;
    // executing stats collection multiple times
    while (counter < NUM_COLLECTIONS) {
        this.postServiceSynchronously(StatsCollectionTaskService.FACTORY_LINK, collectionTaskState, StatsCollectionTaskState.class);
        counter++;
    }
    // wait for stats to be populated
    this.host.waitFor("Error waiting for stats", () -> {
        boolean returnStatus = false;
        for (int i = 0; i < NUM_COMPUTE_RESOURCES; i++) {
            String statsUriPath = UriUtils.buildUriPath(computeStateArray[i].documentSelfLink, ServiceHost.SERVICE_URI_SUFFIX_STATS);
            ServiceStats resStats = getServiceSynchronously(statsUriPath, ServiceStats.class);
            for (ServiceStat stat : resStats.entries.values()) {
                if (stat.name.startsWith(UriUtils.getLastPathSegment(MockStatsAdapter.SELF_LINK))) {
                    returnStatus = true;
                    break;
                }
            }
        }
        return returnStatus;
    });
    // number of keys = 2, number of lastCollectionTimeMetrics = 2
    int numberOfRawMetrics = NUM_COLLECTIONS * NUM_COMPUTE_RESOURCES * 2 * 2;
    // kick off an aggregation task
    SingleResourceStatsAggregationTaskState aggregationTaskState = new SingleResourceStatsAggregationTaskState();
    aggregationTaskState.resourceLink = computeStateArray[0].documentSelfLink;
    aggregationTaskState.metricNames = new HashSet<>(Arrays.asList(MockStatsAdapter.KEY_1, MockStatsAdapter.KEY_2, MockStatsAdapter.KEY_3));
    postServiceSynchronously(SingleResourceStatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, SingleResourceStatsAggregationTaskState.class);
    long expectedExpirationTime = Utils.getNowMicrosUtc() + TimeUnit.DAYS.toMicros(DEFAULT_RETENTION_LIMIT_DAYS);
    this.host.waitFor("Error waiting for rolled up stats", () -> {
        ServiceDocumentQueryResult result = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, ResourceMetricsService.FACTORY_LINK));
        String randomDocumentLink = result.documentLinks.get(0);
        ResourceMetrics metric = Utils.fromJson(result.documents.get(randomDocumentLink), ResourceMetrics.class);
        // Make sure all the documents have expiration time set.
        Assert.assertTrue("Expiration time is not correctly set.", metric.documentExpirationTimeMicros < expectedExpirationTime);
        return (result.documentCount == 2 + numberOfRawMetrics);
    });
    String statsUriPath = UriUtils.buildUriPath(computeStateArray[0].documentSelfLink, ServiceHost.SERVICE_URI_SUFFIX_STATS);
    ServiceStats resStats = getServiceSynchronously(statsUriPath, ServiceStats.class);
    int statCount = 0;
    for (ServiceStat stat : resStats.entries.values()) {
        if (stat.name.startsWith(MockStatsAdapter.KEY_1) || stat.name.startsWith(MockStatsAdapter.KEY_2)) {
            statCount++;
        }
    }
    Assert.assertEquals("Did not find in-memory stats", 2, statCount);
    // verify that the aggregation tasks have been deleted
    this.host.waitFor("Timeout waiting for task to expire", () -> {
        ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildUri(this.host, SingleResourceStatsAggregationTaskService.FACTORY_LINK));
        return res.documentLinks.size() == 0;
    });
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) SingleResourceStatsAggregationTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsAggregationTaskService.SingleResourceStatsAggregationTaskState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) 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) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 28 with ResourcePoolState

use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState 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 29 with ResourcePoolState

use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState 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 30 with ResourcePoolState

use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.

the class AzureTestUtil method createDefaultResourcePool.

public static ResourcePoolState createDefaultResourcePool(VerificationHost host) throws Throwable {
    ResourcePoolState inPool = new ResourcePoolState();
    inPool.name = UUID.randomUUID().toString();
    inPool.id = inPool.name;
    inPool.minCpuCount = 1L;
    inPool.minMemoryBytes = 1024L;
    return TestUtils.doPost(host, inPool, ResourcePoolState.class, UriUtils.buildUri(host, ResourcePoolService.FACTORY_LINK));
}
Also used : ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)

Aggregations

ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)38 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)22 Test (org.junit.Test)12 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)10 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)10 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)10 Operation (com.vmware.xenon.common.Operation)10 ArrayList (java.util.ArrayList)9 StatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState)7 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)7 Before (org.junit.Before)7 ServiceStats (com.vmware.xenon.common.ServiceStats)6 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)5 SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)5 ComputeManagementClientImpl (com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl)4 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)4 ProvisionSecurityGroupTaskState (com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState)4 ScheduledTaskState (com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState)4 Query (com.vmware.xenon.services.common.QueryTask.Query)4 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)3