use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class AzureLifecycleOperationServiceTest 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();
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class BaseVSphereAdapterTest method createTaskResultListener.
protected 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);
}
}
};
Operation startOp = Operation.createPost(host, taskLink).setCompletion(this.host.getCompletion()).setReferer(this.host.getReferer());
this.host.startService(startOp, service);
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class AWSClientManager method getOrCreateCloudWatchClient.
/**
* Get or create a CloudWatch Client instance that will be used to get stats from AWS.
*
* Note: ARN-based credentials will not be accepted unless they have already been exchanged to
* AWS for session credentials. If unset, this method will throw a
* {@link UnsupportedOperationException} exception in this circumstance. To enable ARN-based
* credentials, migrate to {@link #getOrCreateCloudWatchClientAsync(AuthCredentialsServiceState,
* String, StatelessService, boolean)}.
*
* @param credentials The auth credentials to be used for the client creation
* @param regionId The region of the AWS client
* @param service The stateless service for which the operation is being performed.
* @param isMock Indicates if this a mock request
* @return
*/
public AmazonCloudWatchAsyncClient getOrCreateCloudWatchClient(AuthCredentialsServiceState credentials, String regionId, StatelessService service, boolean isMock, Consumer<Throwable> failConsumer) {
if (this.awsClientType != AwsClientType.CLOUD_WATCH) {
throw new UnsupportedOperationException("This client manager supports only AWS " + this.awsClientType + " clients.");
}
if (isArnCredentials(credentials) && !isSetCredentials(credentials)) {
throw new UnsupportedOperationException("For ARN-based credentials, exchange for session-based access key/secret key first before retrieving the client.");
}
String cacheKey = createCredentialRegionCacheKey(credentials, regionId);
if (isCloudWatchClientInvalid(cacheKey)) {
failConsumer.accept(new IllegalStateException("Invalid cloud watch client for key: " + cacheKey));
return null;
}
AmazonCloudWatchAsyncClient amazonCloudWatchClient = null;
try {
amazonCloudWatchClient = this.cloudWatchClientCache.computeIfAbsent(cacheKey, key -> {
AmazonCloudWatchAsyncClient client = AWSUtils.getStatsAsyncClient(credentials, regionId, getExecutor(), isMock);
client.describeAlarmsAsync(new AsyncHandler<DescribeAlarmsRequest, DescribeAlarmsResult>() {
@Override
public void onError(Exception exception) {
markCloudWatchClientInvalid(service, cacheKey);
}
@Override
public void onSuccess(DescribeAlarmsRequest request, DescribeAlarmsResult result) {
// noop
}
});
return client;
});
} catch (Throwable e) {
service.logSevere(e);
failConsumer.accept(e);
}
return amazonCloudWatchClient;
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class AWSClientManager method getOrCreateEC2Client.
/**
* Accesses the client cache to get the EC2 client for the given auth credentials and regionId.
* If a client is not found to exist, creates a new one and adds an entry in the cache for it.
*
* Note: ARN-based credentials will not be accepted unless they have already been exchanged to
* AWS for session credentials. If unset, this method will throw a
* {@link UnsupportedOperationException} exception in this circumstance. To enable ARN-based
* credentials, migrate to {@link #getOrCreateEC2ClientAsync(AuthCredentialsServiceState,
* String, StatelessService)}.
*
* @param credentials The auth credentials to be used for the client creation
* @param regionId The region of the AWS client
* @param service The stateless service making the request and for which the executor pool needs to be allocated.
* @return The AWSClient
*/
public AmazonEC2AsyncClient getOrCreateEC2Client(AuthCredentialsServiceState credentials, String regionId, StatelessService service, Consumer<Throwable> failConsumer) {
if (this.awsClientType != AwsClientType.EC2) {
throw new UnsupportedOperationException("This client manager supports only AWS " + this.awsClientType + " clients.");
}
if (isArnCredentials(credentials) && !isSetCredentials(credentials)) {
throw new UnsupportedOperationException("For ARN-based credentials, exchange for session-based access key/secret key first before retrieving the client.");
}
AmazonEC2AsyncClient amazonEC2Client = null;
String cacheKey = createCredentialRegionCacheKey(credentials, regionId);
try {
amazonEC2Client = this.ec2ClientCache.computeIfAbsent(cacheKey, key -> AWSUtils.getAsyncClient(credentials, regionId, getExecutor()));
} catch (Throwable e) {
service.logSevere(e);
failConsumer.accept(e);
}
return amazonEC2Client;
}
use of com.vmware.xenon.common.StatelessService in project photon-model by vmware.
the class AWSResetServiceTest 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);
}
}
};
Operation startOp = Operation.createPost(host, taskLink).setCompletion(this.host.getCompletion()).setReferer(this.host.getReferer());
this.host.startService(startOp, service);
}
Aggregations