public synchronized static ServiceType get(Record record) { load(); String type = record.getType(); Objects.requireNonNull(type); ServiceType found = get(type); if (found != null) { return found; } else { throw new IllegalArgumentException("Unsupported service type " + type); } }
public synchronized static ServiceType get(Record record) { load(); String type = record.getType(); Objects.requireNonNull(type); ServiceType found = get(type); if (found != null) { return found; } else { throw new IllegalArgumentException("Unsupported service type " + type); } }
/** * Get all REST endpoints from the service discovery infrastructure. * * @return async result */ private Future<List<Record>> getAllEndpoints() { Future<List<Record>> future = Future.future(); discovery.getRecords(record -> record.getType().equals(HttpEndpoint.TYPE), future.completer()); return future; }
private Future<List<Record>> getEndPoints() { final Future<List<Record>> future = Future.future(); this.discovery.getRecords(record -> record.getType().equals(HttpEndpoint.TYPE), future.completer()); return future; }
private Future<List<Record>> getEndPoints() { final Future<List<Record>> future = Future.future(); this.discovery.getRecords(record -> record.getType().equals(HttpEndpoint.TYPE), future.completer()); return future; }
private void successLog(final Record record) { final String key = this.getID(record); final String id = record.getRegistration(); final String endpoint = MessageFormat.format("http://{0}:{1}{2}", record.getLocation().getString(Origin.HOST), String.valueOf(record.getLocation().getInteger(Origin.PORT)), record.getMetadata().getString(Origin.PATH)); LOGGER.debug(Info.REG_SUCCESS, record.getStatus(), record.getType(), record.getName(), endpoint, key, id); }
private void successLog(final Record record) { final String key = this.getID(record); final String id = record.getRegistration(); final String endpoint = MessageFormat.format("http://{0}:{1}{2}", record.getLocation().getString(Origin.HOST), String.valueOf(record.getLocation().getInteger(Origin.PORT)), record.getMetadata().getString(Origin.PATH)); LOGGER.debug(Info.REG_SUCCESS, record.getStatus(), record.getType(), record.getName(), endpoint, key, id); }
@Test public void testHttpRecordCreation() { Service service = getHttpService(); Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service))); assertThat(record).isNotNull(); assertThat(record.getName()).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project"); assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid"); assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(record.getLocation().getInteger("port")).isEqualTo(8080); assertThat(record.getLocation().getBoolean("ssl")).isFalse(); }
@Test public void testHttpRecordCreation() { Service service = getHttpService(); Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service))); assertThat(record).isNotNull(); assertThat(record.getName()).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project"); assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid"); assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(record.getLocation().getInteger("port")).isEqualTo(8080); assertThat(record.getLocation().getBoolean("ssl")).isFalse(); }
@Test public void testUnknownExternalServiceRecordCreation() { // JDBC Example int servicePort = 5432; Service service = getExternalService(servicePort); Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service))); assertThat(record).isNotNull(); assertThat(record.getName()).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project"); assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid"); assertThat(record.getType()).isEqualTo(JDBCDataSource.TYPE); assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service"); assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort); }
@Test public void testUnknownExternalServiceRecordCreation() { // JDBC Example int servicePort = 5432; Service service = getExternalService(servicePort); Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service))); assertThat(record).isNotNull(); assertThat(record.getName()).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project"); assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid"); assertThat(record.getType()).isEqualTo(JDBCDataSource.TYPE); assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service"); assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort); }
@Test public void testHttpImport() { services.add(buildService("172.17.0.2", "web", "web", new String[]{"rails", "http-endpoint"}, 80, "passing")); discovery = ServiceDiscovery.create(vertx) .registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601)); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(1); assertThat(list.get(0).getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(list.get(0).getLocation().getString("endpoint")).isEqualTo("http://172.17.0.2:80"); }
@Test public void testHttpExternalServiceRecordCreation() { int servicePort = 8080; Service service = getExternalService(servicePort); Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service))); assertThat(record).isNotNull(); assertThat(record.getName()).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project"); assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid"); assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service"); assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort); assertThat(record.getLocation().getBoolean("ssl")).isFalse(); assertThat(record.getLocation().getString("endpoint")).isEqualTo("http://my-external-service:" + servicePort); }
@Test public void testHttpWithSSLExternalServiceRecordCreation() { int servicePort = 443; Service service = getExternalService(servicePort); Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service))); assertThat(record).isNotNull(); assertThat(record.getName()).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project"); assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid"); assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service"); assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort); assertThat(record.getLocation().getBoolean("ssl")).isTrue(); assertThat(record.getLocation().getString("endpoint")).isEqualTo("https://my-external-service:" + servicePort); }
@Test public void testHttpExternalServiceRecordCreation() { int servicePort = 8080; Service service = getExternalService(servicePort); Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service))); assertThat(record).isNotNull(); assertThat(record.getName()).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project"); assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid"); assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service"); assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort); assertThat(record.getLocation().getBoolean("ssl")).isFalse(); assertThat(record.getLocation().getString("endpoint")).isEqualTo("http://my-external-service:" + servicePort); }
@Test public void testHttpWithSSLExternalServiceRecordCreation() { int servicePort = 443; Service service = getExternalService(servicePort); Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service))); assertThat(record).isNotNull(); assertThat(record.getName()).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service"); assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project"); assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid"); assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service"); assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort); assertThat(record.getLocation().getBoolean("ssl")).isTrue(); assertThat(record.getLocation().getString("endpoint")).isEqualTo("https://my-external-service:" + servicePort); }
@Test public void testHttpImport() { services.add(buildService("172.17.0.2", "web", "web", new String[]{"rails", "http-endpoint"}, 80, "passing")); discovery = ServiceDiscovery.create(vertx) .registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601)); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(1); assertThat(list.get(0).getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(list.get(0).getLocation().getString("endpoint")).isEqualTo("http://172.17.0.2:80"); }
@Test public void testNoUriSpec() throws Exception { ServiceInstance<JsonObject> instance = ServiceInstance.<JsonObject>builder() .name("foo-service") .payload(new JsonObject().put("foo", "bar")) .sslPort(42406) .address("localhost") .build(); Record record = ZookeeperServiceImporter.createRecordForInstance(instance); assertThat(record.getName()).isEqualTo("foo-service"); assertThat(record.getType()).isEqualTo("unknown"); assertThat(record.getMetadata().getString("foo")).isEqualTo("bar"); assertThat(record.getMetadata().getString("zookeeper-id")).isNotEmpty(); assertThat(record.getLocation()) .contains(entry("endpoint", "https://localhost:42406")) .contains(entry("ssl-port", 42406)); }
@Test public void testHttpRecordCreation() throws Exception { UriSpec uriSpec = new UriSpec("{scheme}://example.com:{port}/foo"); ServiceInstance<JsonObject> instance = ServiceInstance.<JsonObject>builder() .name("foo-service") .payload(new JsonObject().put("foo", "bar").put("service-type", "http-endpoint")) .port(8080) .uriSpec(uriSpec) .build(); Record record = ZookeeperServiceImporter.createRecordForInstance(instance); assertThat(record.getName()).isEqualTo("foo-service"); assertThat(record.getType()).isEqualTo("http-endpoint"); assertThat(record.getMetadata().getString("foo")).isEqualTo("bar"); assertThat(record.getMetadata().getString("zookeeper-id")).isNotEmpty(); assertThat(record.getLocation()) .contains(entry("endpoint", "http://example.com:8080/foo")) .contains(entry("port", 8080)); }
@Test public void testNoUriSpec() throws Exception { ServiceInstance<JsonObject> instance = ServiceInstance.<JsonObject>builder() .name("foo-service") .payload(new JsonObject().put("foo", "bar")) .sslPort(42406) .address("localhost") .build(); Record record = ZookeeperServiceImporter.createRecordForInstance(instance); assertThat(record.getName()).isEqualTo("foo-service"); assertThat(record.getType()).isEqualTo("unknown"); assertThat(record.getMetadata().getString("foo")).isEqualTo("bar"); assertThat(record.getMetadata().getString("zookeeper-id")).isNotEmpty(); assertThat(record.getLocation()) .contains(entry("endpoint", "https://localhost:42406")) .contains(entry("ssl-port", 42406)); }