Java 类com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient 实例源码

项目:rakam    文件:S3BulkEventStore.java   
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();
}
项目:micrometer    文件:CloudWatchExportConfiguration.java   
@Bean
@ConditionalOnMissingBean(AmazonCloudWatchAsyncClient.class)
public AmazonCloudWatchAsync amazonCloudWatchAsync(AWSCredentialsProvider credentialsProvider) {
    return AmazonCloudWatchAsyncClientBuilder.standard()
        .withCredentials(credentialsProvider)
        .build();
}
项目:photon-model    文件:AWSStatsService.java   
private AmazonCloudWatchAsyncClient getAWSAsyncBillingClient(AWSStatsDataHolder statsData) {
    statsData.billingClient = this.clientManager.getOrCreateCloudWatchClient(
            statsData.parentAuth,
            COST_ZONE_ID, this, statsData.statsRequest.isMockRequest,
            getFailureConsumer(statsData));
    return statsData.billingClient;
}
项目:photon-model    文件:AWSUtils.java   
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();
}
项目:photon-model    文件:AWSClientManager.java   
/**
 * 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;
}
项目:jmx-cloudwatch-reporter    文件:ReporterAgent.java   
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);
}
项目:photon-model    文件:AWSStatsService.java   
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;
}
项目:amediamanager    文件:ServerConfig.java   
@Bean
@Scope(WebApplicationContext.SCOPE_APPLICATION)
public AmazonCloudWatchAsyncClient cloudwatchClient(final AWSCredentialsProvider creds,
                                            final Region region) {
    return region.createClient(AmazonCloudWatchAsyncClient.class, creds, null);
}
项目:amazon-kinesis-aggregators    文件:CloudWatchMetricsEmitter.java   
public CloudWatchMetricsEmitter(String metricsNamespace,
        AWSCredentialsProvider credentials) {
    this.metricsNamespace = metricsNamespace;
    this.cloudWatchClient = new AmazonCloudWatchAsyncClient(credentials);
}
项目:metrics-cloudwatch    文件:CloudWatchReporterBuilder.java   
/**
 * @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);
}
项目:s3mper    文件:CloudWatchAlertDispatcher.java   
private void initCloudWatch(String keyId, String keySecret) {
    log.debug("Initializing CloudWatch Client");
    cloudWatch = new AmazonCloudWatchAsyncClient(new BasicAWSCredentials(keyId, keySecret));
}