Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void handleMessageInternal(Message<?> message) {

// TODO: support headers
// TODO: support consul event filters: NodeFilter, ServiceFilter, TagFilter
ResponseEntity<Event> event = this.consul.eventFire(this.eventName, (String) payload);
ResponseEntity<Event> event = this.consul.eventFire(this.eventName, (String) payload, null);
// TODO: return event?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ private void setLastIndex(ResponseEntity<?> response) {
}

public Event fire(String name, String payload) {
ResponseEntity<Event> response = this.consul.eventFire(name, payload);
ResponseEntity<Event> response = this.consul.eventFire(name, payload, null);
return response.getBody();
}

public ResponseEntity<List<Event>> getEventsResponse() {
return this.consul.eventList();
return this.consul.eventList(null, null, null, null, null);
}

public List<Event> getEvents() {
Expand All @@ -98,7 +98,8 @@ public List<Event> watch(Long lastIndex) {
if (this.properties != null) {
eventTimeout = this.properties.getEventTimeout();
}
ResponseEntity<List<Event>> watch = this.consul.eventList((long) eventTimeout, index);
ResponseEntity<List<Event>> watch = this.consul.eventList((long) eventTimeout, index, null, null, null, null,
null);
return filterEvents(readEvents(watch), lastIndex);
}

Expand Down
6 changes: 1 addition & 5 deletions spring-cloud-consul-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ecwid.consul</groupId>
<artifactId>consul-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>consul</artifactId>
Expand Down
13 changes: 2 additions & 11 deletions spring-cloud-consul-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,8 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.ecwid.consul</groupId>
<artifactId>consul-api</artifactId>
<optional>true</optional>
</dependency>
<!-- required by com.ecwid.consul but not as a pom dependency -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<optional>true</optional>
</dependency>


<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Collections;

import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
Expand Down Expand Up @@ -242,8 +241,7 @@ public boolean resolve(Object argument, MethodParameter parameter, HttpRequestVa
}

if (params.getConsistencyMode() != ConsulClient.ConsistencyMode.DEFAULT) {
builder.configureRequestParams(
map -> map.put(params.getConsistencyMode().getParamName(), Collections.emptyList()));
builder.addRequestParameter(params.getConsistencyMode().getParamName(), "true");
}

if (params.getWaitTime() != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.springframework.cloud.consul.model.http.agent.NewService;
import org.springframework.cloud.consul.model.http.agent.Service;
import org.springframework.cloud.consul.model.http.catalog.CatalogDeregistration;
import org.springframework.cloud.consul.model.http.catalog.CatalogRegistration;
import org.springframework.cloud.consul.model.http.catalog.CatalogService;
import org.springframework.cloud.consul.model.http.catalog.Node;
import org.springframework.cloud.consul.model.http.event.Event;
Expand Down Expand Up @@ -97,6 +99,16 @@ ResponseEntity<Void> agentServiceSetMaintenance(@PathVariable String serviceId,
@GetExchange("/v1/catalog/nodes")
ResponseEntity<List<Node>> getCatalogNodes();

@PutExchange("/v1/catalog/register")
ResponseEntity<Void> catalogServiceRegister(
@RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken,
@RequestBody CatalogRegistration registration);

@PutExchange("/v1/catalog/deregister")
ResponseEntity<Void> catalogServiceDeregister(
@RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken,
@RequestBody CatalogDeregistration deregistration);

@GetExchange("/v1/health/checks/{serviceName}")
ResponseEntity<List<Check>> getHealthChecksForService(@PathVariable String serviceName);

Expand All @@ -108,6 +120,12 @@ ResponseEntity<List<HealthService>> getHealthServices(@PathVariable String servi
@RequestParam boolean passing, @RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken,
@RequestParam(required = false) List<String> tag, QueryParams queryParams);

@GetExchange("/v1/health/service/{serviceName}")
ResponseEntity<List<HealthService>> getHealthServices(@PathVariable String serviceName,
@RequestParam boolean passing, @RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken,
@RequestParam(required = false) List<String> tag, QueryParams queryParams,
@RequestParam(required = false) boolean cached);

@DeleteExchange("/v1/kv/{context}")
ResponseEntity<Void> deleteKVValues(@PathVariable String context);

Expand All @@ -131,15 +149,24 @@ ResponseEntity<List<GetValue>> getKVValues(@PathVariable String context,
@PutExchange(url = "/v1/kv/{context}", contentType = MediaType.TEXT_PLAIN_VALUE)
ResponseEntity<Boolean> setKVValue(@PathVariable String context, @RequestBody String value);

@GetExchange("/v1/events")
ResponseEntity<List<Event>> eventList();
@GetExchange("/v1/event/list")
ResponseEntity<List<Event>> eventList(@RequestParam(name = "name", required = false) String name,
@RequestParam(name = "node", required = false) String node,
@RequestParam(name = "service", required = false) String service,
@RequestParam(name = "tag", required = false) String tag,
@RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken);

@GetExchange("/v1/events")
@GetExchange("/v1/event/list")
ResponseEntity<List<Event>> eventList(@RequestParam("wait") @WaitTimeFormat Long eventTimeout,
@RequestParam("index") long index);
@RequestParam("index") long index, @RequestParam(name = "name", required = false) String name,
@RequestParam(name = "node", required = false) String node,
@RequestParam(name = "service", required = false) String service,
@RequestParam(name = "tag", required = false) String tag,
@RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken);

@PostExchange("/v1/event/fire/{name}")
ResponseEntity<Event> eventFire(@PathVariable String name, @RequestBody String payload);
ResponseEntity<Event> eventFire(@PathVariable String name, @RequestBody String payload,
@RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken);

class QueryParams {

Expand Down Expand Up @@ -182,12 +209,11 @@ public QueryParams(String datacenter, long waitTime, long index) {
this(datacenter, ConsistencyMode.DEFAULT, waitTime, index, null);
}

private QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index) {
public QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index) {
this(datacenter, consistencyMode, waitTime, index, null);
}

private QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index,
String near) {
public QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index, String near) {
this.datacenter = datacenter;
this.consistencyMode = consistencyMode;
this.waitTime = waitTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2026-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.consul.model.http.catalog;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;

import org.springframework.core.style.ToStringCreator;

/**
* This class is for /v1/catalog/deregister API.
*
* @author Varnson Fan
* @since 5.0.3
*/
public class CatalogDeregistration {

@JsonProperty("Datacenter")
private String datacenter;

@JsonProperty("Node")
private String node;

@JsonProperty("ServiceID")
private String serviceId;

@JsonProperty("CheckID")
private String checkId;

public String getDatacenter() {
return datacenter;
}

public void setDatacenter(String datacenter) {
this.datacenter = datacenter;
}

public String getNode() {
return node;
}

public void setNode(String node) {
this.node = node;
}

public String getServiceId() {
return serviceId;
}

public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}

public String getCheckId() {
return checkId;
}

public void setCheckId(String checkId) {
this.checkId = checkId;
}

@Override
public String toString() {
return new ToStringCreator(this).append("datacenter", datacenter)
.append("node", node)
.append("serviceId", serviceId)
.append("checkId", checkId)
.toString();
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
CatalogDeregistration that = (CatalogDeregistration) o;
return Objects.equals(datacenter, that.datacenter) && Objects.equals(node, that.node)
&& Objects.equals(serviceId, that.serviceId) && Objects.equals(checkId, that.checkId);
}

@Override
public int hashCode() {
return Objects.hash(datacenter, node, serviceId, checkId);
}

}
Loading
Loading