@Provides @ForDiscoveryClient public URI getDiscoveryUri(ServiceInventory serviceInventory, DiscoveryClientConfig config) { Iterable<ServiceDescriptor> discovery = serviceInventory.getServiceDescriptors("discovery"); for (ServiceDescriptor descriptor : discovery) { if (descriptor.getState() != ServiceState.RUNNING) { continue; } try { return new URI(descriptor.getProperties().get("https")); } catch (Exception ignored) { } try { return new URI(descriptor.getProperties().get("http")); } catch (Exception ignored) { } } if (config != null) { return config.getDiscoveryServiceURI(); } return null; } }
@Provides @ForDiscoveryClient public URI getDiscoveryUri(ServiceInventory serviceInventory, DiscoveryClientConfig config) { Iterable<ServiceDescriptor> discovery = serviceInventory.getServiceDescriptors("discovery"); for (ServiceDescriptor descriptor : discovery) { if (descriptor.getState() != ServiceState.RUNNING) { continue; } try { return new URI(descriptor.getProperties().get("https")); } catch (Exception ignored) { } try { return new URI(descriptor.getProperties().get("http")); } catch (Exception ignored) { } } if (config != null) { return config.getDiscoveryServiceURI(); } return null; }
@Provides @ForDiscoveryClient public URI getDiscoveryUri(ServiceInventory serviceInventory, DiscoveryClientConfig config) { Iterable<ServiceDescriptor> discovery = serviceInventory.getServiceDescriptors("discovery"); for (ServiceDescriptor descriptor : discovery) { if (descriptor.getState() != ServiceState.RUNNING) { continue; } try { return new URI(descriptor.getProperties().get("https")); } catch (Exception ignored) { } try { return new URI(descriptor.getProperties().get("http")); } catch (Exception ignored) { } } if (config != null) { return config.getDiscoveryServiceURI(); } return null; }
@Test public void testBuilderNodeId() { ServiceDescriptor expected = new ServiceDescriptor( UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana")); ServiceDescriptorBuilder builder = serviceDescriptor(expected.getType()) .setId(expected.getId()) .setLocation(expected.getLocation()) .setNodeId(expected.getNodeId()) .setPool(expected.getPool()) .setState(expected.getState()); for (Map.Entry<String, String> entry : expected.getProperties().entrySet()) { builder.addProperty(entry.getKey(), entry.getValue()); } assertDescriptorEquals(expected, builder.build()); }
@Test public void testBuilderNodeId() { ServiceDescriptor expected = new ServiceDescriptor( UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana")); ServiceDescriptorBuilder builder = serviceDescriptor(expected.getType()) .setId(expected.getId()) .setLocation(expected.getLocation()) .setNodeId(expected.getNodeId()) .setPool(expected.getPool()) .setState(expected.getState()); for (Map.Entry<String, String> entry : expected.getProperties().entrySet()) { builder.addProperty(entry.getKey(), entry.getValue()); } assertDescriptorEquals(expected, builder.build()); }
@Test public void testBuilderNodeInfo() { NodeInfo nodeInfo = new NodeInfo(new NodeConfig().setEnvironment("test").setPool("pool")); ServiceDescriptor expected = new ServiceDescriptor( UUID.fromString("12345678-1234-1234-1234-123456789012"), nodeInfo.getNodeId(), "type", nodeInfo.getPool(), "location", ServiceState.STOPPED, ImmutableMap.of("a", "apple", "b", "banana")); ServiceDescriptor actual = serviceDescriptor(expected.getType()) .setId(expected.getId()) .setLocation(expected.getLocation()) .setNodeInfo(nodeInfo) .setState(expected.getState()) .addProperties(expected.getProperties()) .build(); assertDescriptorEquals(expected, actual); }
@Test public void testBuilderNodeInfo() { NodeInfo nodeInfo = new NodeInfo(new NodeConfig().setEnvironment("test").setPool("pool")); ServiceDescriptor expected = new ServiceDescriptor( UUID.fromString("12345678-1234-1234-1234-123456789012"), nodeInfo.getNodeId(), "type", nodeInfo.getPool(), "location", ServiceState.STOPPED, ImmutableMap.of("a", "apple", "b", "banana")); ServiceDescriptor actual = serviceDescriptor(expected.getType()) .setId(expected.getId()) .setLocation(expected.getLocation()) .setNodeInfo(nodeInfo) .setState(expected.getState()) .addProperties(expected.getProperties()) .build(); assertDescriptorEquals(expected, actual); }