Search in sources :

Example 41 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class EndpointRemovalTaskServiceTest method createComputeState.

private static void createComputeState(BaseModelTest test, String endpointLink, List<String> tenantLinks) throws Throwable {
    ComputeState cs = new ComputeState();
    cs.id = UUID.randomUUID().toString();
    cs.name = "computeState";
    cs.descriptionLink = "descriptionLink";
    cs.tenantLinks = tenantLinks;
    cs.endpointLink = endpointLink;
    cs.endpointLinks = new HashSet<String>();
    cs.endpointLinks.add(endpointLink);
    test.postServiceSynchronously(ComputeService.FACTORY_LINK, cs, ComputeService.ComputeState.class);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeService(com.vmware.photon.controller.model.resources.ComputeService)

Example 42 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class ResourceIPDeallocationTaskService method getComputeResource.

private DeferredResult<ResourceIPDeallocationContext> getComputeResource(ResourceIPDeallocationContext ctx) {
    Operation op = Operation.createGet(ComputeService.ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), ctx.resourceLink)));
    return sendWithDeferredResult(op, ComputeState.class).thenApply(computeState -> {
        ctx.computeResource = computeState;
        logFine("Retrieved resource [%s]", ctx.resourceLink);
        return ctx;
    });
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Operation(com.vmware.xenon.common.Operation)

Example 43 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TagGroomerTaskServiceTest method createComputesWithTags.

/**
 * Create n computes associated with specific tags
 */
private void createComputesWithTags(int count, List<String> tagLinks) {
    ComputeState computeState = new ComputeState();
    computeState.descriptionLink = "description-link";
    computeState.id = UUID.randomUUID().toString();
    computeState.name = computeState.id;
    computeState.tagLinks = new HashSet<>();
    for (int i = 0; i < count; i++) {
        computeState.tagLinks.add(tagLinks.get(i));
        Operation op = Operation.createPost(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)).setBody(computeState);
        this.host.waitForResponse(op);
        // clear tagLinks and assign new one on the next round
        computeState.tagLinks.clear();
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Operation(com.vmware.xenon.common.Operation)

Example 44 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class StatsAggregationTaskServiceTest method testStatsAggregation.

private void testStatsAggregation(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 resource pool
    ResourcePoolState rpState = new ResourcePoolState();
    rpState.name = "testName";
    ResourcePoolState rpReturnState = postServiceSynchronously(ResourcePoolService.FACTORY_LINK, rpState, ResourcePoolState.class);
    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;
    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);
    }
    // kick off an aggregation task when stats are not populated
    StatsAggregationTaskState aggregationTaskState = new StatsAggregationTaskState();
    Query taskQuery = Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, rpReturnState.documentSelfLink).build();
    aggregationTaskState.query = taskQuery;
    aggregationTaskState.metricNames = Collections.singleton(MockStatsAdapter.KEY_1);
    aggregationTaskState.taskInfo = TaskState.createDirect();
    postServiceSynchronously(StatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, StatsAggregationTaskState.class);
    this.host.waitFor("Error waiting for stats", () -> {
        ServiceDocumentQueryResult aggrRes = verificationHost.getFactoryState(UriUtils.buildUri(verificationHost, ResourceMetricsService.FACTORY_LINK));
        // Expect 0 stats because they're not collected yet
        if (aggrRes.documentCount == 0) {
            return true;
        }
        return false;
    });
    StatsCollectionTaskState collectionTaskState = new StatsCollectionTaskState();
    collectionTaskState.resourcePoolLink = rpReturnState.documentSelfLink;
    collectionTaskState.taskInfo = TaskState.createDirect();
    postServiceSynchronously(StatsCollectionTaskService.FACTORY_LINK, collectionTaskState, StatsCollectionTaskState.class);
    int numberOfRawMetrics = this.numResources * 4;
    // kick off an aggregation task
    aggregationTaskState = new StatsAggregationTaskState();
    aggregationTaskState.query = taskQuery;
    aggregationTaskState.metricNames = Collections.singleton(MockStatsAdapter.KEY_1);
    aggregationTaskState.taskInfo = TaskState.createDirect();
    postServiceSynchronously(StatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, StatsAggregationTaskState.class);
    this.host.waitFor("Error waiting for stats", () -> {
        ServiceDocumentQueryResult aggrRes = verificationHost.getFactoryState(UriUtils.buildUri(verificationHost, ResourceMetricsService.FACTORY_LINK));
        if (aggrRes.documentCount == this.numResources + numberOfRawMetrics) {
            return true;
        }
        return false;
    });
    // 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, StatsAggregationTaskService.FACTORY_LINK));
        if (res.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) Query(com.vmware.xenon.services.common.QueryTask.Query) 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) StatsAggregationTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService.StatsAggregationTaskState) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState)

Example 45 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class ResourceGroomerTaskServiceTest method createComputes.

/**
 * Create given number of computes with given endpointLinks and tenantLink.
 */
private List<String> createComputes(int count, Set<String> endpointLinks, String tenantLink, String endpointLink) {
    List<String> computeLinks = new ArrayList<>();
    ComputeState computeState = new ComputeState();
    computeState.descriptionLink = "description-link";
    computeState.id = UUID.randomUUID().toString();
    computeState.name = computeState.id;
    computeState.tenantLinks = Collections.singletonList(tenantLink);
    computeState.endpointLinks = endpointLinks;
    computeState.endpointLink = endpointLink;
    for (int i = 0; i < count; i++) {
        Operation op = Operation.createPost(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)).setBody(computeState);
        Operation response = this.host.waitForResponse(op);
        if (response.getStatusCode() == Operation.STATUS_CODE_OK) {
            computeLinks.add(response.getBody(ComputeState.class).documentSelfLink);
        }
    }
    return computeLinks;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation)

Aggregations

ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)214 Operation (com.vmware.xenon.common.Operation)93 ArrayList (java.util.ArrayList)63 QueryTask (com.vmware.xenon.services.common.QueryTask)58 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)57 HashMap (java.util.HashMap)54 List (java.util.List)51 Map (java.util.Map)50 Utils (com.vmware.xenon.common.Utils)45 Test (org.junit.Test)45 UriUtils (com.vmware.xenon.common.UriUtils)44 URI (java.net.URI)42 Collectors (java.util.stream.Collectors)42 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)40 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)40 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)40 StatelessService (com.vmware.xenon.common.StatelessService)40 Query (com.vmware.xenon.services.common.QueryTask.Query)40 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)38 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)36