Search in sources :

Example 26 with AuthCredentialsServiceState

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

the class AWSRebootServiceTest method setUp.

@Before
public void setUp() throws Exception {
    CommandLineArgumentParser.parseFromProperties(this);
    setAwsClientMockInfo(this.isAwsClientMock, this.awsMockEndpointReference);
    AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
    creds.privateKey = this.secretKey;
    creds.privateKeyId = this.accessKey;
    this.client = AWSUtils.getAsyncClient(creds, TestAWSSetupUtils.regionId, getExecutor());
    this.awsTestContext = new HashMap<>();
    setUpTestVpc(this.client, this.awsTestContext, this.isMock);
    this.singleNicSpec = (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);
        AWSAdaptersTestUtils.startServicesSynchronously(this.host);
        this.host.setTimeoutSeconds(1200);
        this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelMetricServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
    } catch (Throwable e) {
        throw new Exception(e);
    }
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Before(org.junit.Before)

Example 27 with AuthCredentialsServiceState

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

the class AWSRebootServiceTest 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, zoneId, 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 28 with AuthCredentialsServiceState

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

the class AWSPowerServiceTest method setUp.

@Before
public void setUp() throws Throwable {
    CommandLineArgumentParser.parseFromProperties(this);
    // create credentials
    AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
    creds.privateKey = this.secretKey;
    creds.privateKeyId = this.accessKey;
    this.client = AWSUtils.getAsyncClient(creds, this.regionId, getExecutor());
    this.awsTestContext = new HashMap<>();
    setUpTestVpc(this.client, this.awsTestContext, this.isMock);
    this.singleNicSpec = (AwsNicSpecs) this.awsTestContext.get(TestAWSSetupUtils.NIC_SPECS_KEY);
    try {
        PhotonModelServices.startServices(this.host);
        PhotonModelMetricServices.startServices(this.host);
        PhotonModelTaskServices.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);
    } catch (Throwable e) {
        this.host.log("Error starting up services for the test %s", e.getMessage());
        throw new Exception(e);
    }
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Before(org.junit.Before)

Example 29 with AuthCredentialsServiceState

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

the class AWSClientManager method getArnCredentialsFromCache.

/**
 * Common client manager method to retrieve (or update) credentials from the
 * {@link #arnCredentialsCache} if ARN-based, or just return the current credentials set if not.
 * If expired, the credentials will be regenerated. Otherwise, they will continue to be
 * retrieved as normal.
 *
 * @param credentials The auth credentials to be used for the client creation
 * @param service A service to issue requests
 */
public synchronized DeferredResult<AuthCredentialsServiceState> getArnCredentialsFromCache(AuthCredentialsServiceState credentials, StatelessService service) {
    if (!isArnCredentials(credentials)) {
        return DeferredResult.completed(credentials);
    }
    String arn = credentials.customProperties.get(ARN_KEY);
    String arnCacheKey = Utils.computeHash(arn);
    // if they are expired. If not expired, continue to use them.
    if (this.arnCredentialsCache.containsKey(arnCacheKey)) {
        // cache reference.
        if (!this.arnCredentialsCache.get(arnCacheKey).isDone()) {
            return this.arnCredentialsCache.get(arnCacheKey);
        }
        // Check if the credentials are expired. If not, return. If so, refresh.
        AuthCredentialsServiceState arnCredentials = this.arnCredentialsCache.get(arnCacheKey).getNow(new AuthCredentialsServiceState());
        if (!AWSUtils.isExpiredCredentials(arnCredentials)) {
            return this.arnCredentialsCache.get(arnCacheKey);
        }
        service.logInfo("Refreshing session credentials for arn: '%s'", arn);
    }
    this.arnCredentialsCache.put(arnCacheKey, new DeferredResult<>());
    // If unavailable in the cache, or expired, generate a new set of session credentials.
    OperationContext operationContext = OperationContext.getOperationContext();
    getArnSessionCredentialsAsync(arn, credentials.customProperties.get(EXTERNAL_ID_KEY), getExecutor()).whenComplete((awsSessionCredentials, t) -> {
        OperationContext.restoreOperationContext(operationContext);
        if (t != null) {
            this.arnCredentialsCache.get(arnCacheKey).fail(t);
            return;
        }
        service.logInfo("Generated session credentials for arn: '%s'", arn);
        AuthCredentialsServiceState arnCredentials = awsSessionCredentialsToAuthCredentialsState(awsSessionCredentials);
        // Update the cache with the new credentials.
        this.arnCredentialsCache.get(arnCacheKey).complete(arnCredentials);
    });
    return this.arnCredentialsCache.get(arnCacheKey);
}
Also used : OperationContext(com.vmware.xenon.common.OperationContext) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 30 with AuthCredentialsServiceState

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

the class TestProvisionAWSDisk method createEndpoint.

private void createEndpoint() throws Throwable {
    AuthCredentialsServiceState auth = createAWSAuthentication(this.host, this.accessKey, this.secretKey);
    this.endpointState = TestAWSSetupUtils.createAWSEndpointState(this.host, auth.documentSelfLink, 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