Skip to content

Commit

Permalink
YmlCore Finished
Browse files Browse the repository at this point in the history
  • Loading branch information
silentbalanceyh committed May 29, 2023
1 parent 62fe8b9 commit 571d0e7
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ interface LifeCycle {
}


// 「Micro Service」
interface Micro {
String ETCD = "etcd";
}


// 「Application Definition」
interface App {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ interface secure extends YmlSecure {
* </code></pre>
*/
interface shell extends YmlShell {

}

/**
Expand Down Expand Up @@ -395,11 +396,53 @@ interface excel extends YmlExcel {
* vertx-rpc.yml
* <pre><code>
* rpc:
* ssl:
* name:
* addr:
* path:
* rpc_client:
* type: {@link io.vertx.up.eon.em.secure.CertType}
* extension:
* uniform:
* etcd:
* micro:
* nodes:
* - host:
* port:
* timeout:
* circuit: {@see io.vertx.circuitbreaker.CircuitBreakerOptions}
*
* </code></pre>
*/
interface rpc extends YmlRpc {

}

interface etcd extends YmlEtcd {

}

interface circuit extends YmlCircuit {

}

/**
* vertx-workflow.yml
* <pre><code>
* workflow: {@see io.vertx.mod.workflow.atom.configuration.MetaWorkflow}
* name:
* builtIn:
* resource:
* database:
* </code></pre>
*/
interface workflow extends YmlWorkflow {

}

interface module extends YmlModule {

}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.vertx.up.eon.configure;

/**
* @author lang : 2023-05-29
*/
interface YmlCircuit {
String __KEY = "circuit";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.vertx.up.eon.configure;

/**
* @author lang : 2023-05-29
*/
interface YmlEtcd {
String __KEY = "etcd";
String MICRO = "micro";
String NODES = "nodes";
String TIMEOUT = "timeout";

interface nodes {
String HOST = "host";
String PORT = "port";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.vertx.up.eon.configure;

/**
* @author lang : 2023-05-29
*/
interface YmlModule {
String __KEY = "module";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@ interface YmlRpc {
String __KEY = "rpc";
String EXTENSION = "extension";
String UNIFORM = "uniform";
String SSL = "ssl";

String TYPE = "type";

// Client 专用
interface client {
String RPC_CLIENT = "rpc_client";
String ADDR = "addr";
String NAME = "name";
String PATH = "path";
String HOST = "host";
String PORT = "port";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.vertx.up.eon.configure;

import io.horizon.eon.VOption;

/**
* @author lang : 2023-05-29
*/
interface YmlWorkflow {
String __KEY = "workflow";

interface workflow {
String NAME = "name";
String BUILT_IN = "builtIn";
String RESOURCE = "resource";
String DATABASE = "database";

interface database extends VOption.database {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static boolean isSession() {
*/
public static boolean isEtcd() {
final JsonObject options = VISITOR.read();
return options.containsKey("etcd");
return options.containsKey(YmlCore.etcd.__KEY);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.vertx.core.json.JsonObject;
import io.vertx.up.bottle.ZeroHttpAgent;
import io.vertx.up.eon.KName;
import io.vertx.up.eon.KWeb;
import io.vertx.up.eon.configure.YmlCore;
import io.vertx.up.eon.em.container.ServerType;
import io.vertx.up.uca.yaml.Node;
import io.vertx.up.uca.yaml.ZeroUniform;
Expand Down Expand Up @@ -34,7 +34,7 @@ public class HttpFactor extends AbstractFactor {

static {
final JsonObject data = VISITOR.read();
if (data.containsKey(KName.Micro.ETCD)) {
if (data.containsKey(YmlCore.etcd.__KEY)) {
final Class<?> clazz = Ut.clazz(KWeb.COMPONENTS.AGENT_RPC, null);
if (Objects.nonNull(clazz)) {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.vertx.core.json.JsonObject;
import io.vertx.mod.battery.atom.PowerConfig;
import io.vertx.mod.battery.cv.BkCv;
import io.vertx.up.eon.configure.YmlCore;
import io.vertx.up.uca.yaml.Node;
import io.vertx.up.uca.yaml.ZeroUniform;
import io.vertx.up.util.Ut;
Expand All @@ -25,8 +25,8 @@ private BkConfiguration() {

static void init() {
final JsonObject configJson = READER.read();
if (configJson.containsKey(BkCv.FOLDER_MODULE)) {
final JsonObject configuration = configJson.getJsonObject(BkCv.FOLDER_MODULE, new JsonObject());
if (configJson.containsKey(YmlCore.module.__KEY)) {
final JsonObject configuration = configJson.getJsonObject(YmlCore.module.__KEY, new JsonObject());
LOG.Init.info(BkConfiguration.class, "The Modulat Engine will be initialized!! `{0}`",
configuration.encode());
CONFIG = Ut.deserialize(configuration, PowerConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.vertx.mod.ke.refine.Ke;
import io.vertx.mod.workflow.atom.configuration.MetaWorkflow;
import io.vertx.up.commune.config.Database;
import io.vertx.up.eon.configure.YmlCore;
import io.vertx.up.uca.yaml.Node;
import io.vertx.up.uca.yaml.ZeroUniform;
import io.vertx.up.unity.Ux;
Expand Down Expand Up @@ -48,8 +49,8 @@ private WfConfiguration() {

static void init() {
final JsonObject configJson = READER.read();
if (configJson.containsKey(WfCv.FOLDER_ROOT)) {
final JsonObject configuration = configJson.getJsonObject(WfCv.FOLDER_ROOT, new JsonObject());
if (configJson.containsKey(YmlCore.workflow.__KEY)) {
final JsonObject configuration = configJson.getJsonObject(YmlCore.workflow.__KEY, new JsonObject());
LOG.Init.info(WfConfiguration.class, "The Workflow Engine will be initialized!! `{0}`",
configuration.encode());
CONFIG = Ut.deserialize(configuration, MetaWorkflow.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.up.commune.Ruler;
import io.vertx.up.eon.configure.YmlCore;
import io.vertx.up.exception.booting.EtcdConfigEmptyException;
import io.vertx.up.exception.booting.EtcdNetworkException;
import io.vertx.up.fn.Fn;
Expand Down Expand Up @@ -38,21 +39,6 @@ public class EtcdData {
private static final Annal LOGGER = Annal.get(EtcdData.class);
private static final Node<JsonObject> NODE = Ut.singleton(ZeroUniform.class);
private static final Cc<Class<?>, EtcdData> CC_ETCD_DATA = Cc.open();
/**
* Config data
*/
private static final String KEY = "etcd";
/**
* It's required for micro service, it means cluster name for current micro services.
*/
private static final String MICRO = "micro";
private static final String NODES = "nodes";
private static final String TIMEOUT = "timeout";
/**
* Sub nodes of nodes
*/
private static final String PORT = "port";
private static final String HOST = "host";
/**
* Etcd Client
*/
Expand All @@ -67,20 +53,20 @@ private EtcdData(final Class<?> clazz) {
final Annal logger = Annal.get(clazz);
// Read configuration
final JsonObject config = NODE.read();
if (config.containsKey(KEY)) {
final JsonObject root = config.getJsonObject(KEY);
if (config.containsKey(YmlCore.etcd.__KEY)) {
final JsonObject root = config.getJsonObject(YmlCore.etcd.__KEY);
// Verify the data
Fn.outBug(() -> Fn.bugAt(() -> Ruler.verify(KEY, root), root),
Fn.outBug(() -> Fn.bugAt(() -> Ruler.verify(YmlCore.etcd.__KEY, root), root),
LOGGER);
if (root.containsKey(TIMEOUT)) {
this.timeout = root.getLong(TIMEOUT);
if (root.containsKey(YmlCore.etcd.TIMEOUT)) {
this.timeout = root.getLong(YmlCore.etcd.TIMEOUT);
}
if (root.containsKey(MICRO)) {
this.application = root.getString(MICRO);
if (root.containsKey(YmlCore.etcd.MICRO)) {
this.application = root.getString(YmlCore.etcd.MICRO);
}
// Nodes
if (root.containsKey(NODES)) {
this.config.addAll(root.getJsonArray(NODES));
if (root.containsKey(YmlCore.etcd.NODES)) {
this.config.addAll(root.getJsonArray(YmlCore.etcd.NODES));
}
LOGGER.info(Info.ETCD_TIMEOUT,
this.application, this.timeout, this.config.size());
Expand All @@ -93,10 +79,11 @@ private EtcdData(final Class<?> clazz) {
= new ConcurrentHashMap<>();
Observable.fromIterable(this.config)
.map(item -> (JsonObject) item)
.filter(item -> item.containsKey(PORT) && item.containsKey(HOST))
.filter(item -> item.containsKey(YmlCore.etcd.nodes.PORT)
&& item.containsKey(YmlCore.etcd.nodes.HOST))
.map(item -> {
final Integer port = item.getInteger(PORT);
final String host = item.getString(HOST);
final Integer port = item.getInteger(YmlCore.etcd.nodes.PORT);
final String host = item.getString(YmlCore.etcd.nodes.HOST);
networks.put(port, host);
return "http://" + host + ":" + port;
})
Expand Down Expand Up @@ -126,7 +113,7 @@ public static EtcdData create(final Class<?> clazz) {
*/
public static boolean enabled() {
final JsonObject config = NODE.read();
return null != config && config.containsKey(KEY);
return null != config && config.containsKey(YmlCore.etcd.__KEY);
}

public EtcdClient getClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.vertx.servicediscovery.Record;
import io.vertx.up.atom.agent.IpcData;
import io.vertx.up.commune.Envelop;
import io.vertx.up.eon.configure.YmlCore;
import io.vertx.up.eon.em.container.IpcType;
import io.vertx.up.uca.micro.ipc.DataEncap;
import io.vertx.up.util.Ut;
Expand Down Expand Up @@ -47,13 +48,13 @@ public RpcClient connect(final JsonObject config,
final Handler<AsyncResult<JsonObject>> handler) {
final Record record = RpcHelper.getRecord(config);
// Service Configuration
final String name = config.getString(Key.NAME);
final String address = config.getString(Key.ADDR);
final String name = config.getString(YmlCore.rpc.client.NAME);
final String address = config.getString(YmlCore.rpc.client.ADDR);

final JsonObject normalized = RpcHelper.normalize(name, config, record);
this.holder = this.lookupHolder(this.vertx, name, normalized);
// Get Channel
final IpcType type = Ut.toEnum(config.getString(Key.TYPE), IpcType.class);
final IpcType type = Ut.toEnum(config.getString(YmlCore.rpc.TYPE), IpcType.class);
final RpcStub stub = this.getStub(type);
// Future result return to client.
final IpcData request = new IpcData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class RpcHelper {

static Record getRecord(final JsonObject config) {
/* Config Verify **/
Fn.outBug(() -> Fn.bugAt(() -> Ruler.verify(Key.RULE_KEY, config), config),
Fn.outBug(() -> Fn.bugAt(() -> Ruler.verify(YmlCore.rpc.client.RPC_CLIENT, config), config),
LOGGER);
// Connect remote etcd to check service
final ConcurrentMap<String, Record> registryData = ORIGIN.getRegistryData();
final String name = config.getString(Key.NAME);
final String address = config.getString(Key.ADDR);
final String name = config.getString(YmlCore.rpc.client.NAME);
final String address = config.getString(YmlCore.rpc.client.ADDR);
LOGGER.debug(Info.RPC_SERVICE, name, address);
// Empty Found
Fn.outWeb(registryData.values().isEmpty(), LOGGER,
Expand All @@ -44,7 +44,7 @@ static Record getRecord(final JsonObject config) {
.filter(Objects::nonNull)
.filter(item -> Ut.isNotNil(item.getName()))
.filter(item -> name.equals(item.getName()) &&
address.equals(item.getMetadata().getString(Key.PATH)))
address.equals(item.getMetadata().getString(YmlCore.rpc.client.PATH)))
.subscribe(container::add)
.dispose();
// Service Not Found
Expand Down Expand Up @@ -76,18 +76,18 @@ static JsonObject normalize(
// Parse
final JsonObject ssl = getSslConfig(name, config);
final JsonObject normalized = new JsonObject();
normalized.put(Key.HOST, record.getLocation().getString(Key.HOST));
normalized.put(Key.PORT, record.getLocation().getInteger(Key.PORT));
normalized.put(Key.SSL, ssl);
normalized.put(YmlCore.rpc.client.HOST, record.getLocation().getString(YmlCore.rpc.client.HOST));
normalized.put(YmlCore.rpc.client.PORT, record.getLocation().getInteger(YmlCore.rpc.client.PORT));
normalized.put(YmlCore.rpc.client.RPC_CLIENT, ssl);
return normalized;
}

static JsonObject getSslConfig(final String name,
final JsonObject rpcConfig) {
return Fn.runOr(new JsonObject(), () -> {
final JsonObject sslConfig = new JsonObject();
if (rpcConfig.containsKey(Key.SSL) &&
Boolean.parseBoolean(rpcConfig.getValue(Key.SSL).toString())) {
if (rpcConfig.containsKey(YmlCore.rpc.SSL) &&
Boolean.parseBoolean(rpcConfig.getValue(YmlCore.rpc.SSL).toString())) {
if (rpcConfig.containsKey(YmlCore.rpc.EXTENSION)) {
// Non Uniform, Search by name
final JsonObject visited = Ut.visitJObject(rpcConfig, YmlCore.rpc.EXTENSION, name);
Expand Down Expand Up @@ -115,9 +115,9 @@ static JsonObject on(final String name,
final String addr,
final IpcType type) {
final JsonObject config = new JsonObject();
config.put(Key.NAME, name);
config.put(Key.ADDR, addr);
config.put(Key.TYPE, type);
config.put(YmlCore.rpc.client.NAME, name);
config.put(YmlCore.rpc.client.ADDR, addr);
config.put(YmlCore.rpc.TYPE, type);
return config;
}

Expand Down
Loading

0 comments on commit 571d0e7

Please sign in to comment.