protected void register(NewService newService) { log.info("Registering service with consul: {}", newService.toString()); if (properties.getAclToken() == null) { client.agentServiceRegister(newService); } else { client.agentServiceRegister(newService, properties.getAclToken()); } if (ttlConfig.isEnabled() && ttlScheduler != null) { ttlScheduler.add(newService); } }
private List<String> createTags() { List<String> tags = new LinkedList<>(properties.getTags()); if (servletContext != null && StringUtils.isNotBlank(servletContext.getContextPath()) && StringUtils.isNotBlank(servletContext.getContextPath().replaceAll("/", ""))) { tags.add("contextPath=" + servletContext.getContextPath()); } return tags; }
@Override protected void registerManagement() { NewService management = new NewService(); management.setId(getManagementServiceId()); management.setName(getManagementServiceName()); management.setPort(getManagementPort()); management.setTags(properties.getManagementTags()); management.setCheck(createCheck(getManagementPort())); register(management); }
@Override protected void register() { Assert.notNull(service.getPort(), "service.port has not been set"); String appName = getAppName(); String id; if (properties.getInstanceId() == null) { id = getServiceId(); } else { id = normalizeForDns(properties.getInstanceId()); } service.setId(id); service.setName(normalizeForDns(appName)); service.setTags(createTags()); Integer port; if (shouldRegisterManagement()) { port = getManagementPort(); } else { port = service.getPort(); } service.setCheck(createCheck(port)); register(service); }
private NewService.Check createCheck(Integer port) { NewService.Check check = new NewService.Check(); if (ttlConfig.isEnabled()) { check.setTtl(ttlConfig.getTtl()); return check; } if (properties.getHealthCheckUrl() != null) { check.setHttp(properties.getHealthCheckUrl()); } else { check.setHttp( String.format( "%s://%s:%s%s", properties.getScheme(), properties.getHostname(), port, properties.getHealthCheckPath())); } check.setInterval(properties.getHealthCheckInterval()); // TODO support http check timeout return check; }
/** @return the service name of the Management Service */ public String getManagementServiceName() { return normalizeForDns(getAppName()) + SEPARATOR + properties.getManagementSuffix(); }
/** @return the serviceId of the Management Service */ public String getManagementServiceId() { return normalizeForDns(getContext().getId()) + SEPARATOR + properties.getManagementSuffix(); }
@Override protected boolean isEnabled() { return properties.isEnabled(); }