本文整理汇总了Java中com.netflix.discovery.shared.Application类的典型用法代码示例。如果您正苦于以下问题:Java Application类的具体用法?Java Application怎么用?Java Application使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Application类属于com.netflix.discovery.shared包,在下文中一共展示了Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getApplications
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
private List<Map<String, Object>> getApplications() {
List<Application> sortedApplications = getRegistry().getSortedApplications();
ArrayList<Map<String, Object>> apps = new ArrayList<>();
for (Application app : sortedApplications) {
LinkedHashMap<String, Object> appData = new LinkedHashMap<>();
apps.add(appData);
appData.put("name", app.getName());
List<Map<String, Object>> instances = new ArrayList<>();
for (InstanceInfo info : app.getInstances()) {
Map<String, Object> instance = new HashMap<>();
instance.put("instanceId", info.getInstanceId());
instance.put("homePageUrl", info.getHomePageUrl());
instance.put("healthCheckUrl", info.getHealthCheckUrl());
instance.put("statusPageUrl", info.getStatusPageUrl());
instance.put("status", info.getStatus().name());
instance.put("metadata", info.getMetadata());
instances.add(instance);
}
appData.put("instances", instances);
}
return apps;
}
示例2: getAllUsingCereebroMetadata
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Test
public void getAllUsingCereebroMetadata() throws IOException {
Mockito.when(eurekaServerContextMock.getRegistry()).thenReturn(instanceRegistryMock);
String uri = "http://not-used.never.nope";
String json = "{}";
Map<String, String> metadata = new HashMap<>();
metadata.put(CereebroMetadata.KEY_SNITCH_URI, uri);
metadata.put(CereebroMetadata.KEY_SNITCH_SYSTEM_FRAGMENT_JSON, json);
// @formatter:off
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
.setInstanceId("id")
.setAppName("a")
.setMetadata(metadata)
.build();
// @formatter:on
Application application = new Application("a", Arrays.asList(instanceInfo));
Mockito.when(instanceRegistryMock.getSortedApplications()).thenReturn(Arrays.asList(application));
Mockito.when(objectMapperMock.readValue(json, SystemFragment.class)).thenReturn(SystemFragment.empty());
List<Snitch> result = registry.getAll();
Assertions.assertThat(result).hasSize(1);
Snitch snitch = result.get(0);
Assertions.assertThat(snitch.getUri()).isEqualTo(URI.create(uri));
Assertions.assertThat(snitch.snitch()).isEqualTo(SystemFragment.empty());
}
示例3: getAllWithoutCereebroMetadataShouldUseServiceInstanceInfo
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Test
public void getAllWithoutCereebroMetadataShouldUseServiceInstanceInfo() {
Mockito.when(eurekaServerContextMock.getRegistry()).thenReturn(instanceRegistryMock);
// @formatter:off
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
.setInstanceId("id")
.setAppName("a")
.setMetadata(new HashMap<>())
.setHostName("service-instance")
.setPort(6090)
.build();
// @formatter:on
Application application = new Application("a", Arrays.asList(instanceInfo));
Mockito.when(instanceRegistryMock.getSortedApplications()).thenReturn(Arrays.asList(application));
List<Snitch> result = registry.getAll();
Assertions.assertThat(result).hasSize(1);
Snitch snitch = result.get(0);
Assertions.assertThat(snitch.getUri()).isEqualTo(URI.create("http://service-instance:6090"));
Component expectedComponent = Component.of("a", ComponentType.HTTP_APPLICATION);
SystemFragment expected = SystemFragment.of(ComponentRelationships.of(expectedComponent));
Assertions.assertThat(snitch.snitch()).isEqualTo(expected);
}
示例4: renew
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Override
public boolean renew(final String appName, final String serverId,
boolean isReplication) {
log("renew " + appName + " serverId " + serverId + ", isReplication {}"
+ isReplication);
List<Application> applications = getSortedApplications();
for (Application input : applications) {
if (input.getName().equals(appName)) {
InstanceInfo instance = null;
for (InstanceInfo info : input.getInstances()) {
if (info.getId().equals(serverId)) {
instance = info;
break;
}
}
publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId,
instance, isReplication));
break;
}
}
return super.renew(appName, serverId, isReplication);
}
示例5: getApplications
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
private List<Map<String, Object>> getApplications() {
List<Application> sortedApplications = getRegistry().getSortedApplications();
ArrayList<Map<String, Object>> apps = new ArrayList<>();
for (Application app : sortedApplications) {
LinkedHashMap<String, Object> appData = new LinkedHashMap<>();
apps.add(appData);
appData.put("name", app.getName());
List<Map<String, String>> instances = new ArrayList<>();
for (InstanceInfo info : app.getInstances()) {
Map<String, String> instance = new HashMap<>();
instance.put("instanceId", info.getInstanceId());
instance.put("homePageUrl", info.getHomePageUrl());
instance.put("healthCheckUrl", info.getHealthCheckUrl());
instance.put("statusPageUrl", info.getStatusPageUrl());
instance.put("status", info.getStatus().name());
instances.add(instance);
}
appData.put("instances", instances);
}
return apps;
}
示例6: verifyEurekaRegistration
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@VisibleForTesting
void verifyEurekaRegistration() {
String applicationName = applicationInfoManager.getEurekaInstanceConfig().getAppname();
Application application;
do {
try {
getLogger().info("Waiting for registration with Eureka...");
application = eurekaClient.getApplication(applicationName);
if (application != null) {
break;
}
} catch (Throwable t) {
if (t instanceof Error) {
throw (Error) t;
}
}
try {
TimeUnit.SECONDS.sleep(VERIFICATION_WAIT_TIMEOUT);
} catch (InterruptedException almostIgnore) {
Thread.currentThread().interrupt();
}
} while (true);
}
示例7: shouldOnlyDiscoverInstancesWithUpStatus
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Test
public void shouldOnlyDiscoverInstancesWithUpStatus(){
Application application = new Application();
List<InstanceInfo> infoList = InstanceInfoGenerator
.newBuilder(5, 1)
.build()
.toInstanceList();
for (InstanceInfo info : infoList) {
info.setStatus(InstanceInfo.InstanceStatus.DOWN);
application.addInstance(info);
}
when(eurekaClient.getApplication(APPLICATION_NAME)).thenReturn(application);
Iterable<DiscoveryNode> nodes = strategy.discoverNodes();
assertThat(nodes.iterator().hasNext(), is(false));
}
示例8: shouldOnlyDiscoverInstancesWithValidAddress
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Test
public void shouldOnlyDiscoverInstancesWithValidAddress(){
Application application = new Application();
InstanceInfo mockInfo = mock(InstanceInfo.class);
when(mockInfo.getId()).thenReturn(RandomStringUtils.random(42));
when(mockInfo.getStatus()).thenReturn(InstanceInfo.InstanceStatus.UP);
when(mockInfo.getIPAddr()).thenReturn("local");
application.addInstance(mockInfo);
when(eurekaClient.getApplication(APPLICATION_NAME)).thenReturn(application);
Iterable<DiscoveryNode> nodes = strategy.discoverNodes();
verify(eurekaClient).getApplication(APPLICATION_NAME);
verify(mockInfo).getStatus();
verify(mockInfo).getIPAddr();
assertThat(nodes.iterator().hasNext(), is(false));
}
示例9: testInstanceRegistrationUsingProvidedEurekaClient
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Test
public void testInstanceRegistrationUsingProvidedEurekaClient() {
EurekaClient eurekaClient = mock(EurekaClient.class);
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
EurekaInstanceConfig eurekaInstanceConfig = mock(EurekaInstanceConfig.class);
when(eurekaClient.getApplicationInfoManager()).thenReturn(applicationInfoManager);
when(eurekaClient.getApplication(anyString())).thenReturn(new Application(APP_NAME));
when(applicationInfoManager.getEurekaInstanceConfig()).thenReturn(eurekaInstanceConfig);
when(eurekaInstanceConfig.getAppname()).thenReturn(APP_NAME);
// use provided EurekaClient
EurekaOneDiscoveryStrategyFactory.setEurekaClient(eurekaClient);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
verify(eurekaClient, times(2)).getApplicationInfoManager();
verify(eurekaClient, times(2)).getApplication(APP_NAME);
verify(applicationInfoManager, never()).setInstanceStatus(InstanceStatus.UP);
verify(applicationInfoManager, never()).setInstanceStatus(any(InstanceStatus.class));
assertClusterSizeEventually(2, hz1);
assertClusterSizeEventually(2, hz2);
}
示例10: getServices
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Override
public List<String> getServices() {
Applications applications = this.eurekaClient.getApplications();
if (applications == null) {
return Collections.emptyList();
}
List<Application> registered = applications.getRegisteredApplications();
List<String> names = new ArrayList<>();
for (Application app : registered) {
if (app.getInstances().isEmpty()) {
continue;
}
names.add(app.getName().toLowerCase());
}
return names;
}
示例11: getClusterNames
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Override
public Collection<String> getClusterNames() {
final Pattern regex = Pattern.compile(this.config.getString(PROPERTY_MATCH));
return Collections2.filter(
Collections2.transform(client.getApplications().getRegisteredApplications(),
new Function<Application, String>() {
@Override
public String apply(Application app) {
return app.getName();
}
}),
new Predicate<String>() {
@Override
public boolean apply(String clusterName) {
Matcher m = regex.matcher(clusterName);
return m.matches();
}
});
}
示例12: getEurekaDetails
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@GET
public Response getEurekaDetails() {
List<EurekaInstanceInfo> instanceInfoList = new ArrayList<EurekaInstanceInfo>();
DiscoveryClient discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient();
if (null != discoveryClient) {
Applications apps = discoveryClient.getApplications();
for (Application app : apps.getRegisteredApplications()) {
for (InstanceInfo inst : app.getInstances()) {
instanceInfoList.add(new EurekaInstanceInfo(inst.getAppName(), inst.getId(), inst.getStatus().name(), inst.getIPAddr(), inst.getHostName()));
}
}
}
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
Gson gson = gsonBuilder.create();
String response = gson.toJson(new KaryonAdminResponse(instanceInfoList));
return Response.ok(response).build();
}
示例13: getConfigServiceInstances
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
public List<InstanceInfo> getConfigServiceInstances() {
Application application = eurekaClient.getApplication(Constant.APPLICATION_NAME);
if (application == null) {
LOGGER.error("获取eureka服务失败!");
}
return application != null ? application.getInstances() : new ArrayList<>();
}
示例14: getAll
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
@Override
public List<Snitch> getAll() {
// @formatter:off
return eurekaServerContext.getRegistry().getSortedApplications().stream()
.map(Application::getInstances)
.flatMap(Collection::stream)
.map(instance -> new ServiceInstanceSnitch(objectMapper, new EurekaServiceInstance(instance)))
.collect(Collectors.toList());
// @formatter:on
}
示例15: getConfigServiceInstances
import com.netflix.discovery.shared.Application; //导入依赖的package包/类
public List<InstanceInfo> getConfigServiceInstances() {
Application application = eurekaClient.getApplication(tmKey);
if (application == null) {
LOGGER.error("获取eureka服务失败!");
}
return application != null ? application.getInstances() : new ArrayList<>();
}