.setType("eventbus-service-proxy") .setLocation(new JsonObject().put("endpoint", "the-service-address")) .setName("my-service")
protected Future<Void> publishApiGateway(String host, int port) { Record record = HttpEndpoint.createRecord("api-gateway", true, host, port, "/", null) .setType("api-gateway"); return publish(record); }
@Override public ConcurrentMap<String, Record> getRegistryData() { final ConcurrentMap<String, Record> map = this.readData(EtcdPath.IPC); for (final Record record : map.values()) { record.setStatus(Status.UP); record.setType("IPC"); // Alpn Enabled for Rpc, ssl must be true. record.getLocation().put("ssl", Boolean.TRUE); } return map; }
@Override public ConcurrentMap<String, Record> getRegistryData() { final ConcurrentMap<String, Record> map = this.readData(EtcdPath.IPC); for (final Record record : map.values()) { record.setStatus(Status.UP); record.setType("IPC"); // Alpn Enabled for Rpc, ssl must be true. record.getLocation().put("ssl", Boolean.TRUE); } return map; }
private Record manageUnknownService(Record record, ContainerPort port) { if (port.getPublicPort() == null || port.getPublicPort() == 0) { return null; } JsonObject location = new JsonObject(); location.put("port", port.getPublicPort()); location.put("internal-port", port.getPrivatePort()); location.put("type", port.getType()); location.put("ip", host); return record.setLocation(location).setType(ServiceType.UNKNOWN); }
static Record createRecord(String name, JsonObject location, JsonObject metadata) { Objects.requireNonNull(name); Objects.requireNonNull(location); Record record = new Record().setName(name) .setType(TYPE) .setLocation(location); if (metadata != null) { record.setMetadata(metadata); } return record; }
static Record createRecord(String name, JsonObject location, JsonObject metadata) { Objects.requireNonNull(name); Objects.requireNonNull(location); Record record = new Record().setName(name) .setType(TYPE) .setLocation(location); if (metadata != null) { record.setMetadata(metadata); } return record; }
/** * Convenient method to create a record for a Redis data source. * * @param name the service name * @param location the location of the service (e.g. url, port...) * @param metadata additional metadata * @return the created record */ static Record createRecord(String name, JsonObject location, JsonObject metadata) { Objects.requireNonNull(name); Objects.requireNonNull(location); Record record = new Record().setName(name) .setType(TYPE) .setLocation(location); if (metadata != null) { record.setMetadata(metadata); } return record; }
/** * Convenient method to create a record for a Redis data source. * * @param name the service name * @param location the location of the service (e.g. url, port...) * @param metadata additional metadata * @return the created record */ static Record createRecord(String name, JsonObject location, JsonObject metadata) { Objects.requireNonNull(name); Objects.requireNonNull(location); Record record = new Record().setName(name) .setType(TYPE) .setLocation(location); if (metadata != null) { record.setMetadata(metadata); } return record; }
/** * Convenient method to create a record for a Mongo data source. * * @param name the service name * @param location the location of the service (e.g. url, port...) * @param metadata additional metadata * @return the created record */ static Record createRecord(String name, JsonObject location, JsonObject metadata) { Objects.requireNonNull(name); Objects.requireNonNull(location); Record record = new Record().setName(name) .setType(TYPE) .setLocation(location); if (metadata != null) { record.setMetadata(metadata); } return record; }
@Test public void TestTypeMatch() { Record record = new Record().setName("Name").setType(HttpEndpoint.TYPE); assertThat(record.match(new JsonObject().put("name", "Name").put("type", "any"))).isFalse(); assertThat(record.match(new JsonObject().put("name", "Name").put("type", HttpEndpoint.TYPE))).isTrue(); assertThat(record.match(new JsonObject().put("type", HttpEndpoint.TYPE))).isTrue(); assertThat(record.match(new JsonObject().put("name", "Name").put("type", "*"))).isTrue(); }
@Test public void TestTypeMatch() { Record record = new Record().setName("Name").setType(HttpEndpoint.TYPE); assertThat(record.match(new JsonObject().put("name", "Name").put("type", "any"))).isFalse(); assertThat(record.match(new JsonObject().put("name", "Name").put("type", HttpEndpoint.TYPE))).isTrue(); assertThat(record.match(new JsonObject().put("type", HttpEndpoint.TYPE))).isTrue(); assertThat(record.match(new JsonObject().put("name", "Name").put("type", "*"))).isTrue(); }
@Test(expected = IllegalArgumentException.class) public void unknown() { Record record = new Record(); record.setType(ServiceType.UNKNOWN); ServiceTypes.get(record); }
@Test(expected = IllegalArgumentException.class) public void unknown() { Record record = new Record(); record.setType(ServiceType.UNKNOWN); ServiceTypes.get(record); }
@Test(expected = IllegalArgumentException.class) public void notAKnownType() { Record record = new Record(); record.setType("bob"); ServiceTypes.get(record); }
@Test(expected = IllegalArgumentException.class) public void notAKnownType() { Record record = new Record(); record.setType("bob"); ServiceTypes.get(record); }
@Test public void should_Fail_Service_Proxy_With_Record_Status_Not_UP(TestContext context) { GraphQLClient.getSchemaProxy(discovery, new Record() .setName("DroidQueries").setType(Queryable.SERVICE_TYPE), context.asyncAssertFailure(ex -> assertEquals("Record status indicates service 'DroidQueries' is: UNKNOWN. Expected: UP", ex.getMessage()) )); }
@Before public void setUp() { vertx = Vertx.vertx(); options = new ServiceDiscoveryOptions().setName("theDiscovery") .setAnnounceAddress("theAnnounceAddress").setUsageAddress("theUsageAddress"); discovery = ServiceDiscovery.create(vertx, options); record = new Record() .setName("theRecord") .setType(Queryable.SERVICE_TYPE) .setMetadata(new JsonObject().put("publisherId", "thePublisherId")) .setLocation(new JsonObject().put(Record.ENDPOINT, Queryable.ADDRESS_PREFIX + ".DroidQueries")) .setStatus(Status.UP); definition = SchemaDefinition.createInstance(droidsSchema, SchemaMetadata.create(new JsonObject().put("publisherId", "thePublisherId"))); consumer = ProxyHelper.registerService(Queryable.class, vertx, definition, Queryable.ADDRESS_PREFIX + ".DroidQueries"); }
@Test public void should_Fail_Service_Proxy_With_Record_Not_Registered(TestContext context) { GraphQLClient.getSchemaProxy(discovery, new Record() .setName("DroidQueries").setType(Queryable.SERVICE_TYPE).setStatus(Status.UP), context.asyncAssertFailure(ex -> assertEquals("Record 'DroidQueries' has no service discovery registration", ex.getMessage()) )); } }
private static Record manageHttpService(Record record, ContainerPort port, Map<String, String> labels) { if (port.getPublicPort() == null || port.getPublicPort() == 0) { return null; } record.setType(HttpEndpoint.TYPE); HttpLocation location = new HttpLocation() .setHost(port.getIp()) .setPort(port.getPublicPort()); if (isTrue(labels, "ssl") || port.getPrivatePort() == 443) { location.setSsl(true); } return record.setLocation(location.toJson()); }