public ServiceDescriptor build() { return new ServiceDescriptor(id, nodeId, type, pool, location, state, properties.build()); } }
public ServiceDescriptor build() { return new ServiceDescriptor(id, nodeId, type, pool, location, state, properties.build()); } }
public ServiceDescriptor build() { UUID id = (this.id == null) ? UUID.randomUUID() : this.id; return new ServiceDescriptor(id, nodeId, type, pool, location, state, properties.build()); } }
@Test public void testToString() { assertNotNull(new ServiceDescriptor(UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana"))); }
@Test public void testToString() { assertNotNull(new ServiceDescriptor(UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana"))); }
@Test public void testToString() { assertNotNull(new ServiceDescriptor(UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana"))); }
@Override public CheckedFuture<Duration, DiscoveryException> announce(Set<ServiceAnnouncement> services) { Preconditions.checkNotNull(services, "services is null"); ImmutableSet.Builder<ServiceDescriptor> builder = ImmutableSet.builder(); for (ServiceAnnouncement service : services) { builder.add(new ServiceDescriptor(service.getId(), nodeInfo.getNodeId(), service.getType(), nodeInfo.getPool(), null, ServiceState.RUNNING, service.getProperties())); } announcements.set(builder.build()); return Futures.immediateCheckedFuture(maxAge); }
@Test public void testEquivalence() { UUID serviceA = UUID.randomUUID(); UUID serviceB = UUID.randomUUID(); equivalenceTester() .addEquivalentGroup( new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node-X", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type-X", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool-X", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location-X", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a-X", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple-X"))) .addEquivalentGroup( new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node-X", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type-X", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool-X", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location-X", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a-X", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple-X"))) .check(); }
@Test public void testEquivalence() { UUID serviceA = UUID.randomUUID(); UUID serviceB = UUID.randomUUID(); equivalenceTester() .addEquivalentGroup( new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node-X", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type-X", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool-X", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location-X", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a-X", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple-X"))) .addEquivalentGroup( new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node-X", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type-X", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool-X", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location-X", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a-X", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple-X"))) .check(); }
@Test public void testJsonDecode() throws Exception { ServiceDescriptor expected = new ServiceDescriptor(UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana")); String json = Resources.toString(Resources.getResource("service-descriptor.json"), UTF_8); ServiceDescriptor actual = serviceDescriptorCodec.fromJson(json); assertDescriptorEquals(expected, actual); }
@Test public void testEquivalence() { UUID serviceA = UUID.randomUUID(); UUID serviceB = UUID.randomUUID(); equivalenceTester() .addEquivalentGroup( new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node-X", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type-X", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool-X", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location-X", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a-X", "apple")), new ServiceDescriptor(serviceA, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple-X")) ) .addEquivalentGroup( new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node-X", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type-X", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool-X", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location-X", ServiceState.RUNNING, ImmutableMap.of("a", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a-X", "apple")), new ServiceDescriptor(serviceB, "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple-X")) ) .check(); }
@Test public void testJsonDecode() throws Exception { ServiceDescriptor expected = new ServiceDescriptor(UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana")); String json = Resources.toString(Resources.getResource("service-descriptor.json"), UTF_8); ServiceDescriptor actual = serviceDescriptorCodec.fromJson(json); assertDescriptorEquals(expected, actual); }
@Override public ImmutableList<ServiceDescriptor> getServiceInventory(Iterable<SlotStatus> allSlotStatus) { ImmutableList.Builder<ServiceDescriptor> newDescriptors = ImmutableList.builder(); for (SlotStatus slotStatus : allSlotStatus) { // if the self reference is null, the slot is totally offline so skip for now if (slotStatus.getSelf() == null) { continue; } List<ServiceDescriptor> serviceDescriptors = getServiceInventory(slotStatus); if (serviceDescriptors == null) { continue; } for (ServiceDescriptor serviceDescriptor : serviceDescriptors) { newDescriptors.add(new ServiceDescriptor(null, slotStatus.getId().toString(), serviceDescriptor.getType(), serviceDescriptor.getPool(), slotStatus.getLocation(), slotStatus.getState() == SlotLifecycleState.RUNNING ? ServiceState.RUNNING : ServiceState.STOPPED, interpolateProperties(serviceDescriptor.getProperties(), slotStatus))); } } return newDescriptors.build(); }
@Test public void testJsonDecode() throws Exception { ServiceDescriptor expected = new ServiceDescriptor(UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana")); String json = Resources.toString(Resources.getResource("service-descriptor.json"), Charsets.UTF_8); ServiceDescriptor actual = serviceDescriptorCodec.fromJson(json); assertEquals(actual, expected); assertEquals(actual.getId(), expected.getId()); assertEquals(actual.getNodeId(), expected.getNodeId()); assertEquals(actual.getType(), expected.getType()); assertEquals(actual.getPool(), expected.getPool()); assertEquals(actual.getLocation(), expected.getLocation()); assertEquals(actual.getProperties(), expected.getProperties()); }
@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); }