Skip to content

Commit

Permalink
Merge pull request #117 from ruslansennov/consul-connect-v5
Browse files Browse the repository at this point in the history
Consul connect support
  • Loading branch information
ruslansennov authored Nov 27, 2024
2 parents c472b79 + 5d548ce commit 12f49d4
Show file tree
Hide file tree
Showing 15 changed files with 613 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@
</dependencies>
</profile>
</profiles>
</project>
</project>
22 changes: 22 additions & 0 deletions src/main/java/io/vertx/ext/consul/ServiceOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.json.annotations.JsonGen;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.consul.connect.ConnectOptions;

import java.util.List;
import java.util.Map;
Expand All @@ -42,6 +43,7 @@ public class ServiceOptions {
private List<CheckOptions> checkListOptions;
private long createIndex;
private long modifyIndex;
private ConnectOptions connectOptions;

/**
* Default constructor
Expand All @@ -65,6 +67,7 @@ public ServiceOptions(ServiceOptions options) {
this.checkListOptions = options.checkListOptions;
this.createIndex = options.createIndex;
this.modifyIndex = options.modifyIndex;
this.connectOptions = options.connectOptions;
}

/**
Expand Down Expand Up @@ -287,4 +290,23 @@ public ServiceOptions setModifyIndex(long modifyIndex) {
return this;
}

/**
* Get consul-connect options of service
*
* @return consul-connect options
*/
public ConnectOptions getConnectOptions() {
return connectOptions;
}

/**
* Set consul-connect options of service
*
* @param connectOptions consul-connect options
* @return reference to this, for fluency
*/
public ServiceOptions setConnectOptions(ConnectOptions connectOptions) {
this.connectOptions = connectOptions;
return this;
}
}
48 changes: 48 additions & 0 deletions src/main/java/io/vertx/ext/consul/connect/ConnectOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.vertx.ext.consul.connect;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;

@DataObject
public class ConnectOptions {
private static final String SIDECAR = "SidecarService";

private SidecarServiceOptions sidecarService;

/**
* Default constructor
*/
public ConnectOptions() {
}

/**
* Constructor from JSON
*
* @param options the JSON
*/
public ConnectOptions(JsonObject options) {
this.sidecarService = new SidecarServiceOptions(options.getJsonObject(SIDECAR));
}

/**
* Convert to JSON
*
* @return the JSON
*/
public JsonObject toJson() {
JsonObject jsonObject = new JsonObject();
if (sidecarService != null) {
jsonObject.put(SIDECAR, sidecarService.toJson());
}
return jsonObject;
}

public SidecarServiceOptions getSidecarService() {
return sidecarService;
}

public ConnectOptions setSidecarService(SidecarServiceOptions sidecarService) {
this.sidecarService = sidecarService;
return this;
}
}
51 changes: 51 additions & 0 deletions src/main/java/io/vertx/ext/consul/connect/ExposeOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.vertx.ext.consul.connect;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;

import java.util.List;
import java.util.stream.Collectors;

@DataObject
public class ExposeOptions {
private static final String PATHS = "Paths";

private List<ExposePathOptions> paths;

/**
* Default constructor
*/
public ExposeOptions() {
}

/**
* Constructor from JSON
*
* @param options the JSON
*/
public ExposeOptions(JsonObject options) {
this.paths = options.getJsonArray(PATHS).stream()
.map(o -> new ExposePathOptions((JsonObject) o))
.collect(Collectors.toList());
}

/**
* Convert to JSON
*
* @return the JSON
*/
public JsonObject toJson() {
JsonObject jsonObject = new JsonObject();
jsonObject.put(PATHS, paths.stream().map(ExposePathOptions::toJson).collect(Collectors.toList()));
return jsonObject;
}

public List<ExposePathOptions> getPaths() {
return paths;
}

public ExposeOptions setPaths(List<ExposePathOptions> paths) {
this.paths = paths;
return this;
}
}
85 changes: 85 additions & 0 deletions src/main/java/io/vertx/ext/consul/connect/ExposePathOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package io.vertx.ext.consul.connect;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;

@DataObject
public class ExposePathOptions {
private static final String PATH = "Path";
private static final String PROTOCOL = "Protocol";
private static final String LOC_PATH = "LocalPathPort";
private static final String LIS_PORT = "ListenerPort";

private String path;
private String protocol;
private Integer localPathPort;
private Integer listenerPort;

/**
* Default constructor
*/
public ExposePathOptions() {
}

/**
* Constructor from JSON
*
* @param options the JSON
*/
public ExposePathOptions(JsonObject options) {
this.path = options.getString(PATH);
this.protocol = options.getString(PROTOCOL);
this.localPathPort = options.getInteger(LOC_PATH);
this.listenerPort = options.getInteger(LIS_PORT);
}

/**
* Convert to JSON
*
* @return the JSON
*/
public JsonObject toJson() {
JsonObject jsonObject = new JsonObject();
jsonObject.put(PATH, path);
jsonObject.put(PROTOCOL, protocol);
jsonObject.put(LOC_PATH, localPathPort);
jsonObject.put(LIS_PORT, listenerPort);
return jsonObject;
}

public String getPath() {
return path;
}

public ExposePathOptions setPath(String path) {
this.path = path;
return this;
}

public String getProtocol() {
return protocol;
}

public ExposePathOptions setProtocol(String protocol) {
this.protocol = protocol;
return this;
}

public Integer getLocalPathPort() {
return localPathPort;
}

public ExposePathOptions setLocalPathPort(Integer localPathPort) {
this.localPathPort = localPathPort;
return this;
}

public Integer getListenerPort() {
return listenerPort;
}

public ExposePathOptions setListenerPort(Integer listenerPort) {
this.listenerPort = listenerPort;
return this;
}
}
83 changes: 83 additions & 0 deletions src/main/java/io/vertx/ext/consul/connect/ProxyOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package io.vertx.ext.consul.connect;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;

import java.util.List;
import java.util.stream.Collectors;

@DataObject
public class ProxyOptions {
private static final String CONFIG = "Config";
private static final String UPSTREAMS = "Upstreams";
private static final String EXPOSE = "Expose";

private JsonObject config;
private List<UpstreamOptions> upstreams;
private ExposeOptions expose;

/**
* Default constructor
*/
public ProxyOptions() {
}

/**
* Constructor from JSON
*
* @param options the JSON
*/
public ProxyOptions(JsonObject options) {
this.config = options.getJsonObject(CONFIG);
this.upstreams = options.getJsonArray(UPSTREAMS).stream()
.map(o -> new UpstreamOptions((JsonObject) o))
.collect(Collectors.toList());
this.expose = new ExposeOptions(options.getJsonObject(EXPOSE));
}

/**
* Convert to JSON
*
* @return the JSON
*/
public JsonObject toJson() {
JsonObject jsonObject = new JsonObject();
if (upstreams != null) {
jsonObject.put(UPSTREAMS, upstreams.stream().map(UpstreamOptions::toJson).collect(Collectors.toList()));
}
if (config != null) {
jsonObject.put(CONFIG, config);
}
if (expose != null) {
jsonObject.put(EXPOSE, expose.toJson());
}
return jsonObject;
}

public JsonObject getConfig() {
return config;
}

public ProxyOptions setConfig(JsonObject config) {
this.config = config;
return this;
}

public List<UpstreamOptions> getUpstreams() {
return upstreams;
}

public ProxyOptions setUpstreams(List<UpstreamOptions> upstreams) {
this.upstreams = upstreams;
return this;
}

public ExposeOptions getExpose() {
return expose;
}

public ProxyOptions setExpose(ExposeOptions expose) {
this.expose = expose;
return this;
}
}
Loading

0 comments on commit 12f49d4

Please sign in to comment.