本文整理汇总了Java中com.nike.riposte.server.config.AppInfo类的典型用法代码示例。如果您正苦于以下问题:Java AppInfo类的具体用法?Java AppInfo怎么用?Java AppInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AppInfo类属于com.nike.riposte.server.config包,在下文中一共展示了AppInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAwsInstanceId
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
/**
* @param asyncHttpClientHelper The async HTTP client you want this method to use to make the AWS metadata call.
*
* @return A {@link CompletableFuture} that will contain the AWS instance ID this app is running on (assuming it
* completes successfully). If an error occurs retrieving the instance ID from AWS then the error will be logged and
* {@link AppInfo#UNKNOWN_VALUE} returned as the value.
*/
public static CompletableFuture<String> getAwsInstanceId(AsyncHttpClientHelper asyncHttpClientHelper) {
return asyncHttpClientHelper.executeAsyncHttpRequest(
asyncHttpClientHelper.getRequestBuilder(AMAZON_METADATA_INSTANCE_ID_URL, HttpMethod.GET),
Response::getResponseBody
).handle((instanceId, error) -> {
if (error != null) {
logger.error("Unable to get instance ID info from AWS metadata service.", error);
return AppInfo.UNKNOWN_VALUE;
}
if (instanceId == null) {
logger.error("AWS metadata service returned null for instance ID. Using 'unknown' as fallback.");
return AppInfo.UNKNOWN_VALUE;
}
return instanceId;
});
}
示例2: getAppInfoFutureWithAwsInfo
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
/**
* Helper that uses {@link AppInfoImpl#detectAppId()} and {@link AppInfoImpl#detectEnvironment()} to get the app ID
* and environment values, then returns {@link #getAppInfoFutureWithAwsInfo(String, String, AsyncHttpClientHelper)}
* using those values. If either app ID or environment cannot be determined then an {@link IllegalStateException}
* will be thrown, therefore if you know that your app's app ID and/or environment will not be successfully
* extracted using those methods then you should call {@link #getAppInfoFutureWithAwsInfo(String, String,
* AsyncHttpClientHelper)} directly with the correct values.
* <p/>
* See {@link #getAppInfoFutureWithAwsInfo(String, String, AsyncHttpClientHelper)} for more details on how the
* {@link AppInfo} returned by the {@link CompletableFuture} will be structured.
*/
public static CompletableFuture<AppInfo> getAppInfoFutureWithAwsInfo(AsyncHttpClientHelper asyncHttpClientHelper) {
String appId = AppInfoImpl.detectAppId();
if (appId == null)
throw new IllegalStateException(
"Unable to autodetect app ID. Please call getAppInfoFutureWithAwsInfo(String, String, "
+ "AsyncHttpClientHelper) instead and pass the app ID and environment manually"
);
String environment = AppInfoImpl.detectEnvironment();
if (environment == null)
throw new IllegalStateException(
"Unable to autodetect environment. Please call getAppInfoFutureWithAwsInfo(String, String, "
+ "AsyncHttpClientHelper) instead and pass the app ID and environment manually"
);
return getAppInfoFutureWithAwsInfo(appId, environment, asyncHttpClientHelper);
}
示例3: getAwsRegion_returns_AppInfo_UNKNOWN_VALUE_if_response_from_aws_does_not_contain_region_value
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@DataProvider(value = {
"true",
"false"
})
@Test
public void getAwsRegion_returns_AppInfo_UNKNOWN_VALUE_if_response_from_aws_does_not_contain_region_value(
boolean useJunkJson
) throws Throwable {
// given
String result = (useJunkJson) ? "i am not parseable as json" : "{\"notregion\":\"stillnotregion\"}";
doReturn(result).when(responseMockForAwsMetadataDoc).getResponseBody();
// when
Pair<CompletableFuture<String>, AsyncResponseHandler<String>> resultAndHandler =
executeGetAwsRegionAndExtractHandler();
// then
assertThat(resultAndHandler.getLeft()).isCompleted();
String regionResult = resultAndHandler.getLeft().join();
assertThat(regionResult).isEqualTo(AppInfo.UNKNOWN_VALUE);
assertThat(resultAndHandler.getRight().handleResponse(responseMockForAwsMetadataDoc))
.isEqualTo(AppInfo.UNKNOWN_VALUE);
}
示例4: assertThat
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Test
public void getAppInfoFutureWithAwsInfo_with_all_args_uses_data_from_getAwsRegion_and_getAwsInstanceId_to_build_result() {
// given
String appId = "appid-" + UUID.randomUUID().toString();
String environment = "environment-" + UUID.randomUUID().toString();
String expectedDataCenter = AwsUtil.getAwsRegion(asyncClientMock).join();
String expectedInstanceId = AwsUtil.getAwsInstanceId(asyncClientMock).join();
// when
AppInfo result = AwsUtil.getAppInfoFutureWithAwsInfo(appId, environment, asyncClientMock).join();
// then
assertThat(result.appId()).isEqualTo(appId);
assertThat(result.environment()).isEqualTo(environment);
assertThat(result.dataCenter()).isEqualTo(expectedDataCenter);
assertThat(result.instanceId()).isEqualTo(expectedInstanceId);
}
示例5: doReturn
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Test
public void getAppInfoFutureWithAwsInfo_with_all_args_uses_InetAddress_local_hostname_if_getAwsInstanceId_returns_unknown()
throws IOException {
// given
String appId = "appid-" + UUID.randomUUID().toString();
String environment = "environment-" + UUID.randomUUID().toString();
String expectedDataCenter = AwsUtil.getAwsRegion(asyncClientMock).join();
doReturn(null).when(responseMockForAwsInstanceId).getResponseBody();
String expectedInstanceId = InetAddress.getLocalHost().getHostName();
// when
AppInfo result = AwsUtil.getAppInfoFutureWithAwsInfo(appId, environment, asyncClientMock).join();
// then
assertThat(result.appId()).isEqualTo(appId);
assertThat(result.environment()).isEqualTo(environment);
assertThat(result.dataCenter()).isEqualTo(expectedDataCenter);
assertThat(result.instanceId()).isEqualTo(expectedInstanceId);
}
示例6: getAppInfoFutureWithAwsInfo_with_minimal_args_delegates_to_kitchen_sink_overload_method
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Test
public void getAppInfoFutureWithAwsInfo_with_minimal_args_delegates_to_kitchen_sink_overload_method() {
// given
String appId = "appid-" + UUID.randomUUID().toString();
String environment = "environment-" + UUID.randomUUID().toString();
String expectedDataCenter = AwsUtil.getAwsRegion(asyncClientMock).join();
String expectedInstanceId = AwsUtil.getAwsInstanceId(asyncClientMock).join();
setAppIdAndEnvironemntSystemProperties(appId, environment);
// when
AppInfo result = AwsUtil.getAppInfoFutureWithAwsInfo(asyncClientMock).join();
// then
assertThat(result.appId()).isEqualTo(appId);
assertThat(result.environment()).isEqualTo(environment);
assertThat(result.dataCenter()).isEqualTo(expectedDataCenter);
assertThat(result.instanceId()).isEqualTo(expectedInstanceId);
}
示例7: GuiceProvidedServerConfigValues
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Inject
public GuiceProvidedServerConfigValues(@Named("endpoints.port") Integer endpointsPort,
@Named("endpoints.sslPort") Integer endpointsSslPort,
@Named("endpoints.useSsl") Boolean endpointsUseSsl,
@Named("netty.bossThreadCount") Integer numBossThreads,
@Named("netty.workerThreadCount") Integer numWorkerThreads,
@Named("netty.maxRequestSizeInBytes") Integer maxRequestSizeInBytes,
@Named("appEndpoints") Set<Endpoint<?>> appEndpoints,
@Named("debugActionsEnabled") Boolean debugActionsEnabled,
@Named("debugChannelLifecycleLoggingEnabled") Boolean debugChannelLifecycleLoggingEnabled,
RiposteErrorHandler riposteErrorHandler,
RiposteUnhandledErrorHandler riposteUnhandledErrorHandler,
RequestValidator validationService,
@Nullable CodahaleMetricsListener metricsListener,
@Named("appInfoFuture") CompletableFuture<AppInfo> appInfoFuture,
CmsRequestSecurityValidator cmsRequestSecurityValidator,
HystrixRequestAndResponseFilter hystrixRequestAndResponseFilter
) {
super(endpointsPort, endpointsSslPort, endpointsUseSsl, numBossThreads, numWorkerThreads, maxRequestSizeInBytes, appEndpoints,
debugActionsEnabled, debugChannelLifecycleLoggingEnabled);
this.riposteErrorHandler = riposteErrorHandler;
this.riposteUnhandledErrorHandler = riposteUnhandledErrorHandler;
this.validationService = validationService;
this.metricsListener = metricsListener;
this.appInfoFuture = appInfoFuture;
this.cmsRequestSecurityValidator = cmsRequestSecurityValidator;
this.requestAndResponseFilters = Lists.newArrayList(hystrixRequestAndResponseFilter);
}
示例8: AppInfoImpl
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Test
public void createLocalInstance_with_appId_uses_UNKNOWN_VALUE_for_local_hostname_if_it_throws_UnknownHostException() throws UnknownHostException {
AppInfoImpl instanceForStaticVariableReflectionJunk = new AppInfoImpl("testappid", "testenvironment", "nodatacenter", "someinstanceid");
String localHostnameGetterStaticVariableName = "LOCAL_HOSTNAME_GETTER";
AppInfoImpl.LocalHostnameGetter existingLocalHostnameGetter =
(AppInfoImpl.LocalHostnameGetter) Whitebox.getInternalState(instanceForStaticVariableReflectionJunk, localHostnameGetterStaticVariableName);
try {
// given
String appId = UUID.randomUUID().toString();
AppInfoImpl.LocalHostnameGetter localHostnameGetterMock = mock(AppInfoImpl.LocalHostnameGetter.class);
doThrow(new UnknownHostException("intentionaltestexplosion")).when(localHostnameGetterMock).getLocalHostname();
Whitebox.setInternalState(instanceForStaticVariableReflectionJunk, localHostnameGetterStaticVariableName, localHostnameGetterMock);
// when
AppInfoImpl localInstance = AppInfoImpl.createLocalInstance(appId);
// then
assertThat(localInstance.appId).isEqualTo(appId);
assertThat(localInstance.environment).isEqualTo("local");
assertThat(localInstance.dataCenter).isEqualTo("local");
assertThat(localInstance.instanceId).isEqualTo(AppInfo.UNKNOWN_VALUE);
}
finally {
Whitebox.setInternalState(instanceForStaticVariableReflectionJunk, localHostnameGetterStaticVariableName, existingLocalHostnameGetter);
}
}
示例9: getAwsRegion
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
/**
* @param asyncHttpClientHelper The async HTTP client you want this method to use to make the AWS metadata call.
*
* @return A {@link CompletableFuture} that will contain the AWS region this app is running in (assuming it
* completes successfully). If an error occurs retrieving the region from AWS then the error will be logged and
* {@link AppInfo#UNKNOWN_VALUE} returned as the value.
*/
public static CompletableFuture<String> getAwsRegion(AsyncHttpClientHelper asyncHttpClientHelper) {
return asyncHttpClientHelper.executeAsyncHttpRequest(
asyncHttpClientHelper.getRequestBuilder(AMAZON_METADATA_DOCUMENT_URL, HttpMethod.GET),
response -> {
String region = null;
try {
ObjectMapper objectMapper = new ObjectMapper();
Map<String, String> resultMap =
objectMapper.readValue(response.getResponseBody(), new TypeReference<Map<String, String>>() {});
region = resultMap.get("region");
}
catch (Throwable t) {
logger.error("Error retrieving region from AWS", t);
}
if (region == null) {
logger.error("AWS metadata service returned null for region. Using 'unknown' as fallback.");
region = AppInfo.UNKNOWN_VALUE;
}
return region;
}
).handle((region, error) -> {
if (error != null) {
logger.error("Unable to get region info from AWS metadata service.", error);
return AppInfo.UNKNOWN_VALUE;
}
if (region == null) {
logger.error("AWS metadata service returned null for region. Using 'unknown' as fallback.");
region = AppInfo.UNKNOWN_VALUE;
}
return region;
});
}
示例10: getAwsRegion_returns_completable_future_with_fallback_handling_logic
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@DataProvider(value = {
"true",
"false"
})
@Test
public void getAwsRegion_returns_completable_future_with_fallback_handling_logic(boolean completeExceptionally) {
// given
// Don't complete the core future, just return it, so we can complete it how we want.
doReturn(regionCoreFuture).when(asyncClientMock)
.executeAsyncHttpRequest(eq(regionRequestBuilderWrapperMock),
any(AsyncResponseHandler.class));
Pair<CompletableFuture<String>, AsyncResponseHandler<String>> resultAndHandler =
executeGetAwsRegionAndExtractHandler();
assertThat(regionCoreFuture).isNotDone();
assertThat(resultAndHandler.getLeft()).isNotDone();
// when
if (completeExceptionally)
regionCoreFuture.completeExceptionally(new RuntimeException("kaboom"));
else
regionCoreFuture.complete(null);
// then
// In either case, we should get AppInfo.UNKNOWN_VALUE as the final result from the future with fallback logic.
assertThat(resultAndHandler.getLeft()).isCompleted();
assertThat(resultAndHandler.getLeft().join()).isEqualTo(AppInfo.UNKNOWN_VALUE);
}
示例11: getAwsInstanceId_returns_completable_future_with_fallback_handling_logic
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@DataProvider(value = {
"true",
"false"
})
@Test
public void getAwsInstanceId_returns_completable_future_with_fallback_handling_logic(
boolean completeExceptionally) {
// given
// Don't complete the core future, just return it, so we can complete it how we want.
doReturn(awsInstanceIdCoreFuture)
.when(asyncClientMock)
.executeAsyncHttpRequest(eq(awsInstanceIdRequestBuilderWrapperMock), any(AsyncResponseHandler.class));
Pair<CompletableFuture<String>, AsyncResponseHandler<String>> resultAndHandler =
executeGetAwsInstanceIdAndExtractHandler();
assertThat(awsInstanceIdCoreFuture).isNotDone();
assertThat(resultAndHandler.getLeft()).isNotDone();
// when
if (completeExceptionally)
awsInstanceIdCoreFuture.completeExceptionally(new RuntimeException("kaboom"));
else
awsInstanceIdCoreFuture.complete(null);
// then
// In either case, we should get AppInfo.UNKNOWN_VALUE as the final result from the future with fallback logic.
assertThat(resultAndHandler.getLeft()).isCompleted();
assertThat(resultAndHandler.getLeft().join()).isEqualTo(AppInfo.UNKNOWN_VALUE);
}
示例12: GuiceProvidedServerConfigValues
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Inject
public GuiceProvidedServerConfigValues(
@Named("endpoints.port") Integer endpointsPort,
@Named("endpoints.sslPort") Integer endpointsSslPort,
@Named("endpoints.useSsl") Boolean endpointsUseSsl,
@Named("netty.bossThreadCount") Integer numBossThreads,
@Named("netty.workerThreadCount") Integer numWorkerThreads,
@Named("netty.maxRequestSizeInBytes") Integer maxRequestSizeInBytes,
@Named("appEndpoints") Set<Endpoint<?>> appEndpoints,
@Named("debugActionsEnabled") Boolean debugActionsEnabled,
@Named("debugChannelLifecycleLoggingEnabled") Boolean debugChannelLifecycleLoggingEnabled,
RiposteErrorHandler riposteErrorHandler,
RiposteUnhandledErrorHandler riposteUnhandledErrorHandler,
RequestValidator validationService,
@Named("appInfoFuture") CompletableFuture<AppInfo> appInfoFuture,
@Nullable CodahaleMetricsListener metricsListener,
EurekaServerHook eurekaServerHook,
BasicAuthSecurityValidator basicAuthSecurityValidator
) {
super(
endpointsPort, endpointsSslPort, endpointsUseSsl, numBossThreads, numWorkerThreads, maxRequestSizeInBytes,
appEndpoints, debugActionsEnabled, debugChannelLifecycleLoggingEnabled
);
this.riposteErrorHandler = riposteErrorHandler;
this.riposteUnhandledErrorHandler = riposteUnhandledErrorHandler;
this.validationService = validationService;
this.eurekaServerHook = eurekaServerHook;
this.metricsListener = metricsListener;
this.appInfoFuture = appInfoFuture;
this.basicAuthSecurityValidator = basicAuthSecurityValidator;
}
示例13: metricsReporters
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Provides
@Singleton
public List<ReporterFactory> metricsReporters(
@Named("metrics.slf4j.reporting.enabled") boolean slf4jReportingEnabled,
@Named("metrics.jmx.reporting.enabled") boolean jmxReportingEnabled,
@Named("metrics.graphite.url") String graphiteUrl,
@Named("metrics.graphite.port") int graphitePort,
@Named("metrics.graphite.reporting.enabled") boolean graphiteEnabled,
@Named("appInfoFuture") CompletableFuture<AppInfo> appInfoFuture
) {
List<ReporterFactory> reporters = new ArrayList<>();
if (slf4jReportingEnabled)
reporters.add(new DefaultSLF4jReporterFactory());
if (jmxReportingEnabled)
reporters.add(new DefaultJMXReporterFactory());
if (graphiteEnabled) {
AppInfo appInfo = appInfoFuture.join();
String graphitePrefix = appInfo.appId() + "." + appInfo.dataCenter() + "." + appInfo.environment()
+ "." + appInfo.instanceId();
reporters.add(new DefaultGraphiteReporterFactory(graphitePrefix, graphiteUrl, graphitePort));
}
if (reporters.isEmpty()) {
logger.info("No metrics reporters enabled - disabling metrics entirely.");
return null;
}
String metricReporterTypes = reporters.stream()
.map(rf -> rf.getClass().getSimpleName())
.collect(Collectors.joining(",", "[", "]"));
logger.info("Metrics reporters enabled. metric_reporter_types={}", metricReporterTypes);
return reporters;
}
示例14: appInfoFuture_returns_non_null_object
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Test
public void appInfoFuture_returns_non_null_object() throws Exception {
// when
CompletableFuture<AppInfo> appInfoFuture =
injector.getInstance(Key.get(new TypeLiteral<CompletableFuture<AppInfo>>() {},
Names.named("appInfoFuture")));
// then
assertThat(appInfoFuture).isNotNull();
AppInfo appInfo = appInfoFuture.get(1, TimeUnit.SECONDS);
assertThat(appInfo).isNotNull();
}
示例15: appInfo_returns_non_null_object
import com.nike.riposte.server.config.AppInfo; //导入依赖的package包/类
@Test
public void appInfo_returns_non_null_object() {
// when
CompletableFuture<AppInfo> obj = appServerConfig.appInfo();
// then
assertThat(obj).isNotNull();
assertThat(obj.join()).isNotNull();
}