public S3BulkEventStore(Metastore metastore, AWSConfig config, FieldDependencyBuilder.FieldDependency fieldDependency) { this.metastore = metastore; this.config = config; this.s3Client = new AmazonS3Client(config.getCredentials()); s3Client.setRegion(config.getAWSRegion()); if (config.getS3Endpoint() != null) { s3Client.setEndpoint(config.getS3Endpoint()); } kinesis = new AmazonKinesisClient(config.getCredentials()); kinesis.setRegion(config.getAWSRegion()); if (config.getKinesisEndpoint() != null) { kinesis.setEndpoint(config.getKinesisEndpoint()); } cloudWatchClient = new AmazonCloudWatchAsyncClient(config.getCredentials()); cloudWatchClient.setRegion(config.getAWSRegion()); this.conditionalMagicFieldsSize = fieldDependency.dependentFields.size(); }
@Bean @ConditionalOnMissingBean(AmazonCloudWatchAsyncClient.class) public AmazonCloudWatchAsync amazonCloudWatchAsync(AWSCredentialsProvider credentialsProvider) { return AmazonCloudWatchAsyncClientBuilder.standard() .withCredentials(credentialsProvider) .build(); }
private AmazonCloudWatchAsyncClient getAWSAsyncBillingClient(AWSStatsDataHolder statsData) { statsData.billingClient = this.clientManager.getOrCreateCloudWatchClient( statsData.parentAuth, COST_ZONE_ID, this, statsData.statsRequest.isMockRequest, getFailureConsumer(statsData)); return statsData.billingClient; }
public static AmazonCloudWatchAsyncClient getStatsAsyncClient( AuthCredentialsServiceState credentials, String region, ExecutorService executorService, boolean isMockRequest) { ClientConfiguration configuration = new ClientConfiguration(); configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(), DEFAULT_BACKOFF_STRATEGY, DEFAULT_MAX_ERROR_RETRY, false)); AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider( new BasicAWSCredentials(credentials.privateKeyId, EncryptionUtils.decrypt(credentials.privateKey))); AmazonCloudWatchAsyncClientBuilder amazonCloudWatchAsyncClientBuilder = AmazonCloudWatchAsyncClientBuilder .standard() .withClientConfiguration(configuration) .withCredentials(awsStaticCredentialsProvider) .withExecutorFactory(() -> executorService); if (region == null) { region = Regions.DEFAULT_REGION.getName(); } if (isAwsClientMock()) { configuration.addHeader(AWS_REGION_HEADER, region); amazonCloudWatchAsyncClientBuilder.setClientConfiguration(configuration); AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration( getAWSMockHost() + AWS_MOCK_CLOUDWATCH_ENDPOINT, region); amazonCloudWatchAsyncClientBuilder.setEndpointConfiguration(endpointConfiguration); } else { amazonCloudWatchAsyncClientBuilder.setRegion(region); } return (AmazonCloudWatchAsyncClient) amazonCloudWatchAsyncClientBuilder.build(); }
/** * Get or create a CloudWatch Client instance that will be used to get stats from AWS. * @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."); } 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; }
protected void initReporter(AWSCredentials awsCredentials) { final AmazonCloudWatchAsyncClient cloudWatchClient = new AmazonCloudWatchAsyncClient(awsCredentials); cloudWatchClient.setEndpoint(settings.endPoint); //start cloudwatch reporting new CloudWatchReporter( metricRegistry, settings.cloudWatchNamespace, cloudWatchClient ).start(settings.reportInterval, TimeUnit.SECONDS); }
private AmazonCloudWatchAsyncClient getAWSAsyncStatsClient(AWSStatsDataHolder statsData) { statsData.statsClient = this.clientManager.getOrCreateCloudWatchClient(statsData.parentAuth, statsData.computeDesc.description.regionId, this, statsData.statsRequest.isMockRequest, getFailureConsumer(statsData)); return statsData.statsClient; }
@Bean @Scope(WebApplicationContext.SCOPE_APPLICATION) public AmazonCloudWatchAsyncClient cloudwatchClient(final AWSCredentialsProvider creds, final Region region) { return region.createClient(AmazonCloudWatchAsyncClient.class, creds, null); }
public CloudWatchMetricsEmitter(String metricsNamespace, AWSCredentialsProvider credentials) { this.metricsNamespace = metricsNamespace; this.cloudWatchClient = new AmazonCloudWatchAsyncClient(credentials); }
/** * @return a new CloudWatchReporter instance based on the state of this builder */ public CloudWatchReporter build() { Preconditions.checkState(!Strings.isNullOrEmpty(namespace), "Metric namespace is required."); String resolvedNamespace = namespace; // Use specified or fall back to default. Don't secretly modify the fields of this builder // in case the caller wants to re-use it to build other reporters, or something. MetricRegistry resolvedRegistry = null != registry ? registry : new MetricRegistry(); MetricFilter resolvedFilter = null != filter ? filter : MetricFilter.ALL; AmazonCloudWatchAsync resolvedCloudWatchClient = null != client ? client : new AmazonCloudWatchAsyncClient(); String resolvedDimensions = null != dimensions ? dimensions : null; Boolean resolvedTimestampLocal = null != timestampLocal ? timestampLocal : false; String resolvedTypeDimName = null != typeDimName ? typeDimName : Constants.DEF_DIM_NAME_TYPE; String resolvedTypeDimValGauge = null != typeDimValGauge ? typeDimValGauge : Constants.DEF_DIM_VAL_GAUGE; String resolvedTypeDimValCounterCount = null != typeDimValCounterCount ? typeDimValCounterCount : Constants.DEF_DIM_VAL_COUNTER_COUNT; String resolvedTypeDimValMeterCount = null != typeDimValMeterCount ? typeDimValMeterCount : Constants.DEF_DIM_VAL_METER_COUNT; String resolvedTypeDimValHistoSamples = null != typeDimValHistoSamples ? typeDimValHistoSamples : Constants.DEF_DIM_VAL_HISTO_SAMPLES; String resolvedTypeDimValHistoStats = null != typeDimValHistoStats ? typeDimValHistoStats : Constants.DEF_DIM_VAL_HISTO_STATS; String resolvedTypeDimValTimerSamples = null != typeDimValTimerSamples ? typeDimValTimerSamples : Constants.DEF_DIM_VAL_TIMER_SAMPLES; String resolvedTypeDimValTimerStats = null != typeDimValTimerStats ? typeDimValTimerStats : Constants.DEF_DIM_VAL_TIMER_STATS; Predicate<MetricDatum> resolvedReporterFilter = null != reporterFilter ? reporterFilter : Predicates.<MetricDatum>alwaysTrue(); return new CloudWatchReporter( resolvedRegistry, resolvedNamespace, resolvedFilter, resolvedCloudWatchClient) .withDimensions(resolvedDimensions) .withTimestampLocal(resolvedTimestampLocal) .withTypeDimName(resolvedTypeDimName) .withTypeDimValGauge(resolvedTypeDimValGauge) .withTypeDimValCounterCount(resolvedTypeDimValCounterCount) .withTypeDimValMeterCount(resolvedTypeDimValMeterCount) .withTypeDimValHistoSamples(resolvedTypeDimValHistoSamples) .withTypeDimValHistoStats(resolvedTypeDimValHistoStats) .withTypeDimValTimerSamples(resolvedTypeDimValTimerSamples) .withTypeDimValTimerStats(resolvedTypeDimValTimerStats) .withReporterFilter(resolvedReporterFilter); }
private void initCloudWatch(String keyId, String keySecret) { log.debug("Initializing CloudWatch Client"); cloudWatch = new AmazonCloudWatchAsyncClient(new BasicAWSCredentials(keyId, keySecret)); }