Java Code Examples for com.ecwid.consul.v1.agent.model.NewService#setTags()
The following examples show how to use
com.ecwid.consul.v1.agent.model.NewService#setTags() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceDefinitionToConsulRegistration.java From camel-spring-boot with Apache License 2.0 | 7 votes |
@Override public ConsulRegistration convert(ServiceDefinition source) { NewService service = new NewService(); service.setName(source.getName()); service.setId(source.getId()); service.setAddress(properties.getServiceRegistry().getServiceHost()); service.setPort(source.getPort()); service.setTags( source.getMetadata().entrySet().stream() .map(e -> e.getKey() + "=" + e.getValue()) .collect(Collectors.toList()) ); return new ConsulRegistration(service, null) { @Override public boolean isSecure() { return service.getPort() == 443 || Objects.equals("https", source.getMetadata().get(ServiceDefinition.SERVICE_META_PROTOCOL)); } }; }
Example 2
Source File: NacosSyncToConsulServiceImpl.java From nacos-sync with Apache License 2.0 | 7 votes |
public NewService buildSyncInstance(Instance instance, TaskDO taskDO) { NewService newService = new NewService(); newService.setAddress(instance.getIp()); newService.setPort(instance.getPort()); newService.setName(taskDO.getServiceName()); newService.setId(instance.getInstanceId()); List<String> tags = Lists.newArrayList(); tags.addAll(instance.getMetadata().entrySet().stream() .map(entry -> String.join("=", entry.getKey(), entry.getValue())).collect(Collectors.toList())); tags.add(String.join("=", SkyWalkerConstants.DEST_CLUSTERID_KEY, taskDO.getDestClusterId())); tags.add(String.join("=", SkyWalkerConstants.SYNC_SOURCE_KEY, skyWalkerCacheServices.getClusterType(taskDO.getSourceClusterId()).getCode())); tags.add(String.join("=", SkyWalkerConstants.SOURCE_CLUSTERID_KEY, taskDO.getSourceClusterId())); newService.setTags(tags); return newService; }
Example 3
Source File: ConsulRegistry.java From dubbo3 with Apache License 2.0 | 7 votes |
@Override protected void doRegister(URL url) { NewService dubboService = new NewService(); dubboService.setTags(Arrays.asList("dubbo")); dubboService.setAddress(url.toFullString()); dubboService.setPort(url.getPort()); dubboService.setId(convertConsulSerivceId(url)); dubboService.setName(url.getServiceInterface()); //set health checker String dubboHTTPCheckURL = System.getProperty("DUBBO_HTTP_CHECK_URL"); if (dubboHTTPCheckURL == null) { dubboHTTPCheckURL = System.getenv("DUBBO_HTTP_CHECK_URL"); } if (dubboHTTPCheckURL != null) { NewService.Check check = new NewService.Check(); check.setHttp(dubboHTTPCheckURL); check.setInterval("15s"); check.setTimeout("3s"); dubboService.setCheck(check); } consulClient.agentServiceRegister(dubboService); }
Example 4
Source File: ConsulAutoRegistration.java From spring-cloud-consul with Apache License 2.0 | 7 votes |
public static ConsulAutoRegistration managementRegistration( AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, List<ConsulManagementRegistrationCustomizer> managementRegistrationCustomizers, HeartbeatProperties heartbeatProperties) { NewService management = new NewService(); management.setId(getManagementServiceId(properties, context)); management.setAddress(properties.getHostname()); management .setName(getManagementServiceName(properties, context.getEnvironment())); management.setPort(getManagementPort(properties, context)); management.setTags(properties.getManagementTags()); management.setEnableTagOverride(properties.getManagementEnableTagOverride()); management.setMeta(properties.getManagementMetadata()); if (properties.isRegisterHealthCheck()) { management.setCheck(createCheck(getManagementPort(properties, context), heartbeatProperties, properties)); } ConsulAutoRegistration registration = new ConsulAutoRegistration(management, autoServiceRegistrationProperties, properties, context, heartbeatProperties, managementRegistrationCustomizers); managementCustomize(managementRegistrationCustomizers, registration); return registration; }
Example 5
Source File: ConsulNamingService.java From brpc-java with Apache License 2.0 | 6 votes |
private NewService getConsulNewService(RegisterInfo registerInfo) { NewService newService = new NewService(); newService.setName(registerInfo.getServiceId()); newService.setId(generateInstanceId(registerInfo)); newService.setAddress(registerInfo.getHost()); newService.setPort(registerInfo.getPort()); newService.setTags(Arrays.asList(ConsulConstants.CONSUL_SERVICE_TAG)); NewService.Check check = new NewService.Check(); check.setTtl(this.consulInterval + "s"); check.setDeregisterCriticalServiceAfter("3m"); newService.setCheck(check); return newService; }
Example 6
Source File: ConsulService.java From saluki with Apache License 2.0 | 6 votes |
public NewService getNewService() { NewService consulService = new NewService(); consulService.setName(this.name); consulService.setId(this.id); consulService.setAddress(this.address); consulService.setPort(this.port); consulService.setTags(unmodifiableList(new ArrayList<>(this.tags))); NewService.Check check = new NewService.Check(); check.setTtl(this.interval + "s"); check.setDeregisterCriticalServiceAfter("3m"); consulService.setCheck(check); return consulService; }
Example 7
Source File: ConsulRegistry.java From dubbox with Apache License 2.0 | 6 votes |
private NewService createServiceDef(URL url, long ttl) { NewService newService = new NewService(); newService.setId(toCategoryPath(url)); newService.setName(url.getServiceInterface()); newService.setAddress(URL.encode(url.toFullString())); newService.setPort(url.getPort()); String version = makeVersionTag(url); newService.setTags(Collections.singletonList(version)); int ttlInSeconds = (int) ttl / 1000; NewService.Check check = new NewService.Check(); check.setTtl(ttlInSeconds + "s"); newService.setCheck(check); return newService; }
Example 8
Source File: GrpcConsulRegistrar.java From grpc-spring-boot-starter with Apache License 2.0 | 6 votes |
private ConsulRegistration getRegistration(GRpcServerInitializedEvent event) { ApplicationContext applicationContext = event.getApplicationContext(); ConsulDiscoveryProperties consulProperties = applicationContext.getBean(ConsulDiscoveryProperties.class); GRpcServerProperties gRpcServerProperties = event.getApplicationContext().getBean(GRpcServerProperties.class); NewService grpcService = new NewService(); grpcService.setPort(event.getServer().getPort()); if (!consulProperties.isPreferAgentAddress()) { grpcService.setAddress(consulProperties.getHostname()); } String appName = "grpc-" + ConsulAutoRegistration.getAppName(consulProperties, applicationContext.getEnvironment()); grpcService.setName(ConsulAutoRegistration.normalizeForDns(appName)); grpcService.setId("grpc-" + ConsulAutoRegistration.getInstanceId(consulProperties, applicationContext)); grpcService.setTags(ConsulAutoRegistration.createTags(consulProperties) .stream() .filter(t->!t.startsWith("secure=")) .collect(Collectors.toList()) ); if(consulProperties.isRegisterHealthCheck()) { GRpcConsulHealthCheck health = GRpcConsulHealthCheck.builder() .socketAddr(consulProperties.getHostname() + ":" + event.getServer().getPort()) .grpcUseTlc(Objects.nonNull(gRpcServerProperties.getSecurity())) .interval(consulProperties.getHealthCheckInterval()) .timeout(consulProperties.getHealthCheckTimeout()) .build(); health.setDeregisterCriticalServiceAfter(consulProperties.getHealthCheckCriticalTimeout()); grpcService.setCheck(health); } return new ConsulRegistration(grpcService, consulProperties); }
Example 9
Source File: ConsulHostsSupplierTest.java From dyno with Apache License 2.0 | 6 votes |
@Test public void testAwsHosts() throws JSONException { List<String> tags = new ArrayList<>(); tags.add("cloud=aws"); tags.add("availability-zone=us-east-1b"); tags.add("datacenter=us-east-1"); NewService service = new NewService(); service.setName(APPLICATION_NAME); service.setTags(tags); consulClient.agentServiceRegister(service); NewCheck check = new NewCheck(); check.setName(APPLICATION_NAME); check.setScript("true"); check.setTtl("1m"); check.setInterval("30s"); consulClient.agentCheckRegister(check); consulClient.agentCheckPass(APPLICATION_NAME); ConsulHostsSupplier hostSupplier = new ConsulHostsSupplier(APPLICATION_NAME, consulClient); assertEquals(hostSupplier.getApplicationName(), APPLICATION_NAME); List<Host> hosts = hostSupplier.getHosts(); assertEquals(hosts.size(), 1); Host host = hosts.get(0); assertEquals(host.getRack(), "us-east-1b"); assertEquals(host.getDatacenter(), "us-east-1"); assertEquals(host.getHostName(), "127.0.0.1"); assertEquals(host.getIpAddress(), "127.0.0.1"); assertTrue(host.isUp()); }
Example 10
Source File: ConsulHostsSupplierTest.java From dyno with Apache License 2.0 | 6 votes |
@Test public void testOtherCloudProviderHosts() throws JSONException { List<String> tags = new ArrayList<>(); tags.add("cloud=kubernetes"); tags.add("rack=rack1"); tags.add("datacenter=dc1"); NewService service = new NewService(); service.setName(APPLICATION_NAME); service.setTags(tags); consulClient.agentServiceRegister(service); NewCheck check = new NewCheck(); check.setName(APPLICATION_NAME); check.setScript("true"); check.setTtl("1m"); check.setInterval("30s"); consulClient.agentCheckRegister(check); consulClient.agentCheckPass(APPLICATION_NAME); ConsulHostsSupplier hostSupplier = new ConsulHostsSupplier(APPLICATION_NAME, consulClient); assertEquals(hostSupplier.getApplicationName(), APPLICATION_NAME); List<Host> hosts = hostSupplier.getHosts(); assertEquals(hosts.size(), 1); Host host = hosts.get(0); assertEquals(host.getRack(), "rack1"); assertEquals(host.getDatacenter(), "dc1"); assertEquals(host.getHostName(), "127.0.0.1"); assertEquals(host.getIpAddress(), "127.0.0.1"); assertTrue(host.isUp()); }
Example 11
Source File: ConsulDiscoveryClientDefaultQueryTagTests.java From spring-cloud-consul with Apache License 2.0 | 5 votes |
private NewService serviceForEnvironment(String env, int port) { NewService service = new NewService(); service.setAddress("localhost"); service.setId(NAME + env); service.setName(NAME); service.setPort(port); service.setTags(Arrays.asList(env)); return service; }
Example 12
Source File: ConsulServiceRegistryTests.java From spring-cloud-consul with Apache License 2.0 | 4 votes |
@Test public void contextLoads() { assertThat(this.autoRegistration).as("autoRegistration created erroneously") .isNull(); String serviceId = "myNonAutoRegisteredService"; NewService service = new NewService(); service.setAddress("localhost"); service.setId("myNonAutoRegisteredService-A1"); service.setName(serviceId); service.setPort(this.port); service.setTags(Collections.singletonList("mytag")); ConsulRegistration registration = new ConsulRegistration(service, this.properties); Throwable t = null; try { this.serviceRegistry.register(registration); assertHasInstance(serviceId); assertStatus(registration, "UP"); // only works if query-passing = true this.serviceRegistry.setStatus(registration, "OUT_OF_SERVICE"); assertEmptyInstances(serviceId); assertStatus(registration, "OUT_OF_SERVICE"); this.serviceRegistry.setStatus(registration, "UP"); assertHasInstance(serviceId); } catch (RuntimeException e) { throw e; } finally { this.serviceRegistry.deregister(registration); if (t == null) { // just deregister, test already failed assertEmptyInstances(serviceId); } } }