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);
}
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations