Search in sources :

Example 1 with FactoryService

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

the class AuthCredentialsOperationProcessingChainTest method setUp.

@Override
@Before
public void setUp() throws Throwable {
    // wait for needed services
    waitForServiceAvailability(AuthCredentialsService.FACTORY_LINK);
    // set AuthCredentialsOperationProcessingChain in the factory
    FactoryService fs = (FactoryService) findService.invoke(host, AuthCredentialsService.FACTORY_LINK);
    fs.setOperationProcessingChain(AuthCredentialsOperationProcessingChain.createOperationProcessingChain(fs));
    // common setup
    System.clearProperty(EncryptionUtils.ENCRYPTION_KEY);
    System.clearProperty(EncryptionUtils.INIT_KEY_IF_MISSING);
    EncryptionUtils.initEncryptionService();
}
Also used : FactoryService(com.vmware.xenon.common.FactoryService) Before(org.junit.Before)

Example 2 with FactoryService

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

the class AWSComputeDiskDay2ServiceTest method setUp.

@Before
public void setUp() throws Exception {
    CommandLineArgumentParser.parseFromProperties(this);
    setAwsClientMockInfo(this.isAwsClientMock, this.awsMockEndpointReference);
    AuthCredentialsService.AuthCredentialsServiceState creds = new AuthCredentialsService.AuthCredentialsServiceState();
    creds.privateKey = this.secretKey;
    creds.privateKeyId = this.accessKey;
    TestContext ec2WaitContext = new TestContext(1, Duration.ofSeconds(30L));
    AWSUtils.getEc2AsyncClient(creds, TestAWSSetupUtils.regionId, getExecutor()).exceptionally(t -> {
        ec2WaitContext.fail(t);
        throw new CompletionException(t);
    }).thenAccept(ec2Client -> {
        this.client = ec2Client;
        ec2WaitContext.complete();
    });
    ec2WaitContext.await();
    this.awsTestContext = new HashMap<>();
    setUpTestVpc(this.client, this.awsTestContext, this.isMock, this.zoneId);
    this.singleNicSpec = (TestAWSSetupUtils.AwsNicSpecs) this.awsTestContext.get(TestAWSSetupUtils.NIC_SPECS_KEY);
    this.host = VerificationHost.create(0);
    try {
        this.host.setMaintenanceIntervalMicros(TimeUnit.MILLISECONDS.toMicros(250));
        this.host.start();
        PhotonModelServices.startServices(this.host);
        PhotonModelAdaptersRegistryAdapters.startServices(this.host);
        PhotonModelMetricServices.startServices(this.host);
        PhotonModelTaskServices.startServices(this.host);
        ServiceMetadata[] serviceMetadata = { factoryService(DiskTaskService.class, DiskTaskService::createFactory) };
        StartServicesHelper.startServices(this.host, serviceMetadata);
        AWSAdaptersTestUtils.startServicesSynchronously(this.host);
        this.host.setTimeoutSeconds(1200);
        this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelMetricServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
        initResourcePoolAndComputeHost(this.zoneId);
    } catch (Throwable e) {
        throw new Exception(e);
    }
}
Also used : Arrays(java.util.Arrays) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) TestAWSSetupUtils.createAWSComputeHost(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSComputeHost) ServiceMetadata(com.vmware.photon.controller.model.util.StartServicesHelper.ServiceMetadata) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) VerificationHost(com.vmware.xenon.common.test.VerificationHost) TestAWSSetupUtils.createAWSResourcePool(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSResourcePool) TestAWSSetupUtils.tearDownTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.tearDownTestVpc) DEVICE_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_NAME) TestAWSSetupUtils.setUpTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setUpTestVpc) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) StartServicesHelper(com.vmware.photon.controller.model.util.StartServicesHelper) Gson(com.google.gson.Gson) AWSBlockDeviceNameMapper(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSBlockDeviceNameMapper) TestAWSSetupUtils.verifyRemovalOfResourceState(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.verifyRemovalOfResourceState) Duration(java.time.Duration) Map(java.util.Map) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier) After(org.junit.After) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) TestUtils.getExecutor(com.vmware.photon.controller.model.adapters.awsadapter.TestUtils.getExecutor) ProvisionDiskTaskService(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Collector(java.util.stream.Collector) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) AWS_VM_REQUEST_TIMEOUT_MINUTES(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AWS_VM_REQUEST_TIMEOUT_MINUTES) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) CompletionException(java.util.concurrent.CompletionException) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) Collectors(java.util.stream.Collectors) TestAWSSetupUtils.getResourceState(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getResourceState) TestAWSSetupUtils.avalabilityZoneIdentifier(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.avalabilityZoneIdentifier) TestAWSSetupUtils.getSecurityGroupsIdUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getSecurityGroupsIdUsingEC2Client) List(java.util.List) TestAWSSetupUtils.getAwsDisksByIds(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getAwsDisksByIds) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) AWSSupportedOS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSSupportedOS) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) FactoryService(com.vmware.xenon.common.FactoryService) DiskService(com.vmware.photon.controller.model.resources.DiskService) TaskService(com.vmware.xenon.services.common.TaskService) ServiceMetadata.factoryService(com.vmware.photon.controller.model.util.StartServicesHelper.ServiceMetadata.factoryService) TestAWSSetupUtils.deleteSecurityGroupUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.deleteSecurityGroupUsingEC2Client) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TestAWSSetupUtils.getAwsInstancesByIds(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getAwsInstancesByIds) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) TestProvisionAWSDisk.createAWSDiskState(com.vmware.photon.controller.model.adapters.awsadapter.TestProvisionAWSDisk.createAWSDiskState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TestName(org.junit.rules.TestName) Volume(com.amazonaws.services.ec2.model.Volume) PLACEMENT_LINK(com.vmware.photon.controller.model.ComputeProperties.PLACEMENT_LINK) DEVICE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_TYPE) Instance(com.amazonaws.services.ec2.model.Instance) Before(org.junit.Before) TestAWSSetupUtils.createAWSAuthentication(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSAuthentication) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Assert.assertNotNull(org.junit.Assert.assertNotNull) AWSStorageType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSStorageType) Operation(com.vmware.xenon.common.Operation) SecurityGroupService(com.vmware.photon.controller.model.resources.SecurityGroupService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AWSSupportedVirtualizationTypes(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSSupportedVirtualizationTypes) TimeUnit(java.util.concurrent.TimeUnit) TestAWSSetupUtils.createAWSVMResource(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSVMResource) Rule(org.junit.Rule) TestContext(com.vmware.xenon.common.test.TestContext) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) TestAWSSetupUtils.regionId(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.regionId) TestAWSSetupUtils.setAwsClientMockInfo(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setAwsClientMockInfo) IpPermission(com.amazonaws.services.ec2.model.IpPermission) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) ProvisionDiskTaskService(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService) TestContext(com.vmware.xenon.common.test.TestContext) CompletionException(java.util.concurrent.CompletionException) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) CompletionException(java.util.concurrent.CompletionException) ServiceMetadata(com.vmware.photon.controller.model.util.StartServicesHelper.ServiceMetadata) Before(org.junit.Before)

Example 3 with FactoryService

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

the class BaseTestCase method verifyService.

protected void verifyService(URI factoryUri, FactoryService factoryInstance, Class<? extends ServiceDocument> serviceDocumentType, TestServiceDocumentInitialization serviceDocumentInit, TestServiceDocumentAssertion assertion) throws Throwable {
    int childCount = 1;
    TestContext ctx = testCreate(childCount);
    String prefix = "example-";
    URI[] childURIs = new URI[childCount];
    for (int i = 0; i < childCount; i++) {
        ServiceDocument serviceDocument = serviceDocumentInit.create(prefix, i);
        final int finalI = i;
        // create a ServiceDocument instance.
        Operation createPost = createForcedPost(factoryUri).setBody(serviceDocument).setCompletion((o, e) -> {
            if (e != null) {
                ctx.failIteration(e);
                return;
            }
            ServiceDocument rsp = o.getBody(serviceDocumentType);
            childURIs[finalI] = UriUtils.buildUri(this.host, rsp.documentSelfLink);
            ctx.completeIteration();
        });
        this.host.send(createPost);
    }
    try {
        // verify factory and service instance wiring.
        factoryInstance.setHost(this.host);
        Service serviceInstance = factoryInstance.createServiceInstance();
        serviceInstance.setHost(this.host);
        assertNotNull(serviceInstance);
        ctx.await();
        // do GET on all child URIs
        Map<URI, ? extends ServiceDocument> childStates = this.host.getServiceState(null, serviceDocumentType, childURIs);
        for (ServiceDocument s : childStates.values()) {
            assertion.assertState(prefix, s);
        }
        // verify template GET works on factory
        ServiceDocumentQueryResult templateResult = this.host.getServiceState(null, ServiceDocumentQueryResult.class, UriUtils.extendUri(factoryUri, ServiceHost.SERVICE_URI_SUFFIX_TEMPLATE));
        assertTrue(templateResult.documentLinks.size() == templateResult.documents.size());
        ServiceDocument childTemplate = Utils.fromJson(templateResult.documents.get(templateResult.documentLinks.iterator().next()), serviceDocumentType);
        assertTrue(childTemplate.documentDescription != null);
        assertTrue(childTemplate.documentDescription.propertyDescriptions != null && childTemplate.documentDescription.propertyDescriptions.size() > 0);
    } catch (Throwable t) {
        if (t instanceof RuntimeException) {
            throw t;
        }
        throw new RuntimeException(t);
    }
}
Also used : TestContext(com.vmware.xenon.common.test.TestContext) Service(com.vmware.xenon.common.Service) StatefulService(com.vmware.xenon.common.StatefulService) FactoryService(com.vmware.xenon.common.FactoryService) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 4 with FactoryService

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

the class BaseTestCase method verifyService.

protected void verifyService(Service factoryInstance, Class<? extends ServiceDocument> serviceDocumentType, TestServiceDocumentInitialization serviceDocumentInit, TestServiceDocumentAssertion assertion) throws Throwable {
    URI factoryUri = UriUtils.buildFactoryUri(this.host, ((FactoryService) factoryInstance).createServiceInstance().getClass());
    verifyService(factoryUri, (FactoryService) factoryInstance, serviceDocumentType, serviceDocumentInit, assertion);
}
Also used : FactoryService(com.vmware.xenon.common.FactoryService) URI(java.net.URI)

Aggregations

FactoryService (com.vmware.xenon.common.FactoryService)4 Operation (com.vmware.xenon.common.Operation)2 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)2 TestContext (com.vmware.xenon.common.test.TestContext)2 URI (java.net.URI)2 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 GroupIdentifier (com.amazonaws.services.ec2.model.GroupIdentifier)1 Instance (com.amazonaws.services.ec2.model.Instance)1 IpPermission (com.amazonaws.services.ec2.model.IpPermission)1 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1 Volume (com.amazonaws.services.ec2.model.Volume)1 Gson (com.google.gson.Gson)1 PLACEMENT_LINK (com.vmware.photon.controller.model.ComputeProperties.PLACEMENT_LINK)1 PhotonModelMetricServices (com.vmware.photon.controller.model.PhotonModelMetricServices)1 PhotonModelServices (com.vmware.photon.controller.model.PhotonModelServices)1 UriPaths (com.vmware.photon.controller.model.UriPaths)1 ResourceOperationResponse (com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse)1 AWSStorageType (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSStorageType)1 AWSSupportedOS (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSSupportedOS)1 AWSSupportedVirtualizationTypes (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSSupportedVirtualizationTypes)1