Search in sources :

Example 6 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class TestAWSClientManagement method testAWSClientManagement.

@Test
public void testAWSClientManagement() throws Throwable {
    this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
    this.cloudWatchClientReferenceCount = getClientReferenceCount(AwsClientType.CLOUD_WATCH);
    this.host.setTimeoutSeconds(60);
    // Getting a reference to client managers in the test
    AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
    ec2ClientManager.cleanUpArnCache();
    @SuppressWarnings("unused") AWSClientManager cloudWatchClientManager = getClientManager(AwsClientType.CLOUD_WATCH);
    cloudWatchClientManager.cleanUpArnCache();
    assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
    assertEquals(this.cloudWatchClientReferenceCount + 1, getClientReferenceCount(AwsClientType.CLOUD_WATCH));
    // Getting an AWSclient from the client manager
    this.creds = new AuthCredentialsServiceState();
    this.creds.privateKey = this.accessKey;
    this.creds.privateKeyId = this.secretKey;
    TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
    ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
        waitContext.fail(t);
        throw new CompletionException(t);
    }).thenAccept(ec2Client -> {
        this.client = ec2Client;
        waitContext.complete();
    });
    waitContext.await();
    this.clientCacheCount = ec2ClientManager.getCacheCount();
    // Requesting another AWS client with the same set of credentials will not
    // create a new entry in the cache
    TestContext nextContext = new TestContext(1, Duration.ofSeconds(30L));
    ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
        nextContext.fail(t);
        throw new CompletionException(t);
    }).thenAccept(ec2Client -> {
        this.client = ec2Client;
        nextContext.complete();
    });
    nextContext.await();
    assertEquals(this.clientCacheCount, ec2ClientManager.getCacheCount());
    // Emulating shutdown of individual services to check that the client resources are
    // cleaned up as expected.
    this.host.sendAndWaitExpectSuccess(Operation.createDelete(UriUtils.buildUri(this.host, AWSInstanceService.SELF_LINK)));
    assertEquals(this.ec2ClientReferenceCount, getClientReferenceCount(AwsClientType.EC2));
    this.host.sendAndWaitExpectSuccess(Operation.createDelete(UriUtils.buildUri(this.host, AWSStatsService.SELF_LINK)));
    assertEquals(this.cloudWatchClientReferenceCount, getClientReferenceCount(AwsClientType.CLOUD_WATCH));
    // Returning the references from the test
    returnClientManager(ec2ClientManager, AwsClientType.EC2);
    assertEquals(this.ec2ClientReferenceCount - 1, getClientReferenceCount(AwsClientType.EC2));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) BeforeClass(org.junit.BeforeClass) HashMap(java.util.HashMap) AWSClientManagerFactory.returnClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.returnClientManager) AWSClientManagerFactory.getClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.getClientManager) AWSClientManagerFactory.getClientReferenceCount(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.getClientReferenceCount) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) AWSSecurityTokenServiceException(com.amazonaws.services.securitytoken.model.AWSSecurityTokenServiceException) Duration(java.time.Duration) After(org.junit.After) EXTERNAL_ID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.EXTERNAL_ID_KEY) AWS_ARN_DEFAULT_SESSION_DURATION_SECONDS_PROPERTY(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_ARN_DEFAULT_SESSION_DURATION_SECONDS_PROPERTY) AwsClientType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType) BasicReusableHostTestCase(com.vmware.xenon.common.BasicReusableHostTestCase) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) Before(org.junit.Before) StatelessService(com.vmware.xenon.common.StatelessService) AWS_MASTER_ACCOUNT_ACCESS_KEY_PROPERTY(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_MASTER_ACCOUNT_ACCESS_KEY_PROPERTY) Operation(com.vmware.xenon.common.Operation) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) AWS_MASTER_ACCOUNT_SECRET_KEY_PROPERTY(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_MASTER_ACCOUNT_SECRET_KEY_PROPERTY) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TestContext(com.vmware.xenon.common.test.TestContext) Ignore(org.junit.Ignore) ARN_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ARN_KEY) UriUtils(com.vmware.xenon.common.UriUtils) Assume.assumeTrue(org.junit.Assume.assumeTrue) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) TestContext(com.vmware.xenon.common.test.TestContext) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test)

Example 7 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class LongRunEndToEndStatsCollectionTest method initResourcePoolAndComputeHost.

/**
 * Creates the state associated with the resource pool, compute host and the VM to be created.
 *
 * @throws Throwable
 */
private void initResourcePoolAndComputeHost() throws Throwable {
    // Create a resource pool where the VM will be housed
    ResourcePoolState resourcePool = createAWSResourcePool(this.host);
    AuthCredentialsServiceState auth = createAWSAuthentication(this.host, this.accessKey, this.secretKey);
    this.endpointState = TestAWSSetupUtils.createAWSEndpointState(this.host, auth.documentSelfLink, resourcePool.documentSelfLink);
    // create a compute host for the AWS EC2 VM
    this.computeHost = createAWSComputeHost(this.host, this.endpointState, null, /*zoneId*/
    this.useAllRegions ? null : regionId, this.isAwsClientMock, this.awsMockEndpointReference, null);
}
Also used : ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 8 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class LongRunEndToEndStatsCollectionTest method setUp.

@Before
public void setUp() throws Throwable {
    CommandLineArgumentParser.parseFromProperties(this);
    setAwsClientMockInfo(this.isAwsClientMock, this.awsMockEndpointReference);
    // create credentials
    AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
    creds.privateKey = this.secretKey;
    creds.privateKeyId = this.accessKey;
    this.client = AWSUtils.getAsyncClient(creds, null, getExecutor());
    try {
        PhotonModelServices.startServices(this.host);
        PhotonModelMetricServices.startServices(this.host);
        PhotonModelTaskServices.startServices(this.host);
        PhotonModelInMemoryServices.startServices(this.host);
        PhotonModelAdaptersRegistryAdapters.startServices(this.host);
        AWSAdaptersTestUtils.startServicesSynchronously(this.host);
        this.host.setTimeoutSeconds(this.timeoutSeconds);
        this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelInMemoryServices.LINKS);
    } catch (Throwable e) {
        this.host.log("Error starting up services for the test %s", e.getMessage());
        throw new Exception(e);
    }
    this.nodeStatsUri = UriUtils.buildUri(this.host.getUri(), ServiceUriPaths.CORE_MANAGEMENT);
    this.maxMemoryInMb = this.host.getState().systemInfo.maxMemoryByteCount / BYTES_TO_MB;
    // create the compute host, resource pool and the VM state to be used in the test.
    initResourcePoolAndComputeHost();
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Before(org.junit.Before)

Example 9 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class TestAWSEnumerationDocumentCountInLongRun method initResourcePoolAndComputeHostTwo.

private void initResourcePoolAndComputeHostTwo() throws Throwable {
    AuthCredentialsServiceState auth = createAWSAuthentication(this.host, this.accessKey, this.secretKey);
    this.endpointStateTwo = TestAWSSetupUtils.createAWSEndpointStateUsingAllocationTask(this.host, auth.documentSelfLink, this.resourcePool.documentSelfLink, this.accessKey, this.secretKey, "endpoint-two");
    this.computeHostTwo = this.computeHost;
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 10 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class TestAWSEnumerationDocumentCountInLongRun method initResourcePoolAndComputeHost.

/**
 * Creates the state associated with the resource pool, compute host and the VM to be created.
 *
 * @throws Throwable
 */
private void initResourcePoolAndComputeHost() throws Throwable {
    // Create a resource pool where the VM will be housed
    this.resourcePool = createAWSResourcePool(this.host);
    AuthCredentialsServiceState auth = createAWSAuthentication(this.host, this.accessKey, this.secretKey);
    if (this.isMock) {
        this.endpointState = TestAWSSetupUtils.createAWSEndpointState(this.host, auth.documentSelfLink, this.resourcePool.documentSelfLink);
    } else {
        this.endpointState = TestAWSSetupUtils.createAWSEndpointStateUsingAllocationTask(this.host, auth.documentSelfLink, this.resourcePool.documentSelfLink, this.accessKey, this.secretKey, "endpoint-one");
    }
    // create a compute host for the AWS EC2 VM
    this.computeHost = createAWSComputeHost(this.host, this.endpointState, null, /*zoneId*/
    this.useAllRegions ? null : regionId, this.isAwsClientMock, this.awsMockEndpointReference, null);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Aggregations

AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)98 Operation (com.vmware.xenon.common.Operation)33 Before (org.junit.Before)28 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)25 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)19 UriUtils (com.vmware.xenon.common.UriUtils)18 URI (java.net.URI)18 List (java.util.List)18 HashMap (java.util.HashMap)17 CompletionException (java.util.concurrent.CompletionException)16 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)15 Utils (com.vmware.xenon.common.Utils)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 StatelessService (com.vmware.xenon.common.StatelessService)13 TimeUnit (java.util.concurrent.TimeUnit)13 Collections (java.util.Collections)12 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)11 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)10