Search in sources :

Example 1 with VerificationHost

use of com.vmware.xenon.common.test.VerificationHost in project photon-model by vmware.

the class BaseTestCase method createHost.

protected VerificationHost createHost() throws Throwable {
    ServiceHost.Arguments args = new ServiceHost.Arguments();
    // ask runtime to pick a random storage location
    args.sandbox = null;
    // ask runtime to pick a random port
    args.port = 0;
    Map<Class<? extends Service>, Class<? extends OperationProcessingChain>> chains = new HashMap<>();
    customizeChains(chains);
    VerificationHost h = VerificationHost.initialize(new CustomizationVerificationHost(chains), args);
    h.setMaintenanceIntervalMicros(this.getMaintenanceIntervalMillis() * 1000);
    h.setTimeoutSeconds(HOST_TIMEOUT_SECONDS);
    h.setPeerSynchronizationEnabled(this.getPeerSynchronizationEnabled());
    h.start();
    return h;
}
Also used : HashMap(java.util.HashMap) Service(com.vmware.xenon.common.Service) StatefulService(com.vmware.xenon.common.StatefulService) FactoryService(com.vmware.xenon.common.FactoryService) ServiceHost(com.vmware.xenon.common.ServiceHost) OperationProcessingChain(com.vmware.xenon.common.OperationProcessingChain) VerificationHost(com.vmware.xenon.common.test.VerificationHost)

Example 2 with VerificationHost

use of com.vmware.xenon.common.test.VerificationHost in project photon-model by vmware.

the class StatsAggregationTaskServiceTest method setupMetricHost.

private VerificationHost setupMetricHost() throws Throwable {
    // Start a metric Host separately.
    VerificationHost metricHost = VerificationHost.create(0);
    metricHost.start();
    ServiceTypeCluster.METRIC_SERVICE.setUri(metricHost.getUri().toString());
    PhotonModelMetricServices.startServices(metricHost);
    return metricHost;
}
Also used : VerificationHost(com.vmware.xenon.common.test.VerificationHost)

Example 3 with VerificationHost

use of com.vmware.xenon.common.test.VerificationHost 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 4 with VerificationHost

use of com.vmware.xenon.common.test.VerificationHost in project photon-model by vmware.

the class StatsCollectionTaskServiceTest method setupMetricHost.

private VerificationHost setupMetricHost() throws Throwable {
    // Start a metric Host separately.
    VerificationHost metricHost = VerificationHost.create(0);
    metricHost.start();
    ServiceTypeCluster.METRIC_SERVICE.setUri(metricHost.getUri().toString());
    PhotonModelMetricServices.startServices(metricHost);
    return metricHost;
}
Also used : VerificationHost(com.vmware.xenon.common.test.VerificationHost)

Example 5 with VerificationHost

use of com.vmware.xenon.common.test.VerificationHost in project photon-model by vmware.

the class AWSPowerServiceTest method createTaskResultListener.

private void createTaskResultListener(VerificationHost host, String taskLink, Function<Operation, Boolean> h) {
    StatelessService service = new StatelessService() {

        @Override
        public void handleRequest(Operation update) {
            if (!h.apply(update)) {
                super.handleRequest(update);
            }
        }
    };
    TestContext ctx = this.host.testCreate(1);
    Operation startOp = Operation.createPost(host, taskLink).setCompletion((o, e) -> {
        if (e != null) {
            ctx.failIteration(e);
            return;
        }
        ctx.completeIteration();
    }).setReferer(this.host.getReferer());
    this.host.startService(startOp, service);
    ctx.await();
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) VerificationHost(com.vmware.xenon.common.test.VerificationHost) TestAWSSetupUtils.tearDownTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.tearDownTestVpc) TestAWSSetupUtils.setUpTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setUpTestVpc) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Map(java.util.Map) After(org.junit.After) TestUtils.getExecutor(com.vmware.photon.controller.model.adapters.awsadapter.TestUtils.getExecutor) EnumSet(java.util.EnumSet) AwsNicSpecs(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) TestAWSSetupUtils.waitForProvisioningToComplete(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.waitForProvisioningToComplete) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) UUID(java.util.UUID) UriUtils(com.vmware.xenon.common.UriUtils) Action(com.vmware.xenon.common.Service.Action) TaskState(com.vmware.xenon.common.TaskState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) ResourceRemovalTaskService(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) HashMap(java.util.HashMap) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) TestAWSSetupUtils.waitForInstancesToBeStopped(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.waitForInstancesToBeStopped) TestAWSSetupUtils.zoneId(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.zoneId) Function(java.util.function.Function) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) ArrayList(java.util.ArrayList) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) BasicReusableHostTestCase(com.vmware.xenon.common.BasicReusableHostTestCase) Before(org.junit.Before) ComputePowerRequest(com.vmware.photon.controller.model.adapterapi.ComputePowerRequest) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TestContext(com.vmware.xenon.common.test.TestContext) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) REGION_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.REGION_KEY) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) StatelessService(com.vmware.xenon.common.StatelessService) TestContext(com.vmware.xenon.common.test.TestContext) Operation(com.vmware.xenon.common.Operation)

Aggregations

VerificationHost (com.vmware.xenon.common.test.VerificationHost)12 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)8 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)7 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)7 TestUtils (com.vmware.photon.controller.model.tasks.TestUtils)6 Operation (com.vmware.xenon.common.Operation)6 UriUtils (com.vmware.xenon.common.UriUtils)6 ArrayList (java.util.ArrayList)6 UUID (java.util.UUID)6 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)5 TaskState (com.vmware.xenon.common.TaskState)5 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)5 Level (java.util.logging.Level)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Query (com.vmware.xenon.services.common.QueryTask.Query)4 HashMap (java.util.HashMap)4 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)3 ProvisionComputeTaskState (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState)3 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)2 InstanceViewTypes (com.microsoft.azure.management.compute.InstanceViewTypes)2