Skip to content

Commit

Permalink
[ISSUE apache#550] Remove unused jar in plugin module (apache#551)
Browse files Browse the repository at this point in the history
* optimize build.gradle, remove unused jar in plugin module

* resolve license check

* format code

* fix doc
  • Loading branch information
ruanwenjun authored and xwm1992 committed Dec 27, 2021
1 parent 91dacf0 commit 37fbff2
Show file tree
Hide file tree
Showing 44 changed files with 1,408 additions and 1,077 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ subprojects {
dependency "org.apache.logging.log4j:log4j-web:2.13.3"

dependency "com.lmax:disruptor:3.4.2"
dependency "com.alibaba:fastjson:1.2.71"

dependency "com.fasterxml.jackson.core:jackson-databind:2.11.0"
dependency "com.fasterxml.jackson.core:jackson-core:2.11.0"
Expand Down
4 changes: 2 additions & 2 deletions docs/cn/instructions/eventmesh-runtime-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gradle至少为7.0, 推荐 7.0.*
```$ xslt
unzip EventMesh-master.zip
cd / *您的部署路径* /EventMesh-master
gradle clean dist copyConnectorPlugin tar -x test
gradle clean dist
```

您将在目录/ *您的部署路径* /EventMesh-master/eventmesh-runtime/dist中获得**eventmesh-runtime_1.0.0.tar.gz**
Expand Down Expand Up @@ -68,7 +68,7 @@ sh start.sh
> 插件实例需要在对应模块中的/main/resources/META-INF/eventmesh 下配置相关接口与实现类的映射文件,文件名为SPI接口全类名.
> 文件内容为插件实例名到插件实例的映射, 具体可以参考eventmesh-connector-rocketmq插件模块
插件可以从classpath和插件目录下面加载. 在本地开发阶段可以将使用的插件在eventmesh-starter模块build.gradle中进行声明,或者执行gradle的copyConnectorPlugin任务
插件可以从classpath和插件目录下面加载. 在本地开发阶段可以将使用的插件在eventmesh-starter模块build.gradle中进行声明,或者执行gradle的dist任务
将插件拷贝至dist/plugin目录下, eventmesh默认会加载项目下dist/plugin目录下的插件, 加载目录可以通过-DeventMeshPluginDir=your_plugin_directory来改变插件目录.
运行时需要使用的插件实例可以在eventmesh.properties中进行配置.如果需要使用rocketmq插件实行快速启动,需要在eventmesh-starter模块build.gradle中进行如下声明
```
Expand Down
2 changes: 1 addition & 1 deletion docs/en/instructions/eventmesh-runtime-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You will get **EventMesh-master.zip**
```$xslt
unzip EventMesh-master.zip
cd /*YOUR DEPLOY PATH*/EventMesh-master
gradle clean dist copyConnectorPlugin tar -x test
gradle clean dist
```

You will get **EventMesh_1.3.0-SNAPSHOT.tar.gz** in directory /* YOUR DEPLOY PATH */EventMesh-master/build
Expand Down
40 changes: 17 additions & 23 deletions eventmesh-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,31 @@
dependencies {
api "org.apache.commons:commons-lang3"
api "org.apache.commons:commons-collections4"
api "commons-io:commons-io"
api "org.apache.commons:commons-text"

api "com.google.guava:guava"

api "org.slf4j:slf4j-api"
api "org.apache.logging.log4j:log4j-api"
api "org.apache.logging.log4j:log4j-core"
api "org.apache.logging.log4j:log4j-core"
api "org.apache.logging.log4j:log4j-slf4j-impl"
api "org.apache.logging.log4j:log4j-web"
api "junit:junit"
api "org.assertj:assertj-core"

api "com.lmax:disruptor"
api "com.alibaba:fastjson"
implementation "commons-io:commons-io"
implementation "org.apache.commons:commons-text"

api "com.fasterxml.jackson.core:jackson-databind"
api "com.fasterxml.jackson.core:jackson-core"
api "com.fasterxml.jackson.core:jackson-annotations"
implementation "org.apache.logging.log4j:log4j-api"
implementation "org.apache.logging.log4j:log4j-core"
implementation "org.apache.logging.log4j:log4j-core"
implementation "org.apache.logging.log4j:log4j-slf4j-impl"
implementation "org.apache.logging.log4j:log4j-web"

api "org.apache.httpcomponents:httpclient"
implementation "com.lmax:disruptor"

api "io.netty:netty-all"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.core:jackson-core"
implementation "com.fasterxml.jackson.core:jackson-annotations"

api "junit:junit"
api "com.github.stefanbirkner:system-rules"
api "org.assertj:assertj-core"
implementation "org.apache.httpcomponents:httpclient"

implementation "io.netty:netty-all"

api "org.mockito:mockito-core"
api "org.powermock:powermock-module-junit4"
api "org.powermock:powermock-api-mockito2"
implementation "com.github.stefanbirkner:system-rules"

testImplementation "org.apache.commons:commons-lang3"
testImplementation "org.apache.commons:commons-collections4"
Expand All @@ -64,7 +59,6 @@ dependencies {
testImplementation "org.apache.logging.log4j:log4j-web"

testImplementation "com.lmax:disruptor"
testImplementation "com.alibaba:fastjson"

testImplementation "com.fasterxml.jackson.core:jackson-databind"
testImplementation "com.fasterxml.jackson.core:jackson-core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@

package org.apache.eventmesh.common.command;

import com.alibaba.fastjson.JSON;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.*;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.protocol.http.body.BaseResponseBody;
import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.protocol.http.header.BaseResponseHeader;
import org.apache.eventmesh.common.protocol.http.header.Header;
import org.apache.eventmesh.common.utils.JsonUtils;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;

public class HttpCommand {

private static AtomicLong requestId = new AtomicLong(0);
Expand Down Expand Up @@ -178,46 +185,46 @@ public void setBody(Body body) {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("httpCommand={")
.append(cmdType).append(",")
.append(httpMethod).append("/").append(httpVersion).append(",")
.append("requestCode=").append(requestCode).append(",")
.append("opaque=").append(opaque).append(",");
.append(cmdType).append(",")
.append(httpMethod).append("/").append(httpVersion).append(",")
.append("requestCode=").append(requestCode).append(",")
.append("opaque=").append(opaque).append(",");

if (cmdType == CmdType.RES) {
sb.append("cost=").append(resTime - reqTime).append(",");
}

sb.append("header=").append(header).append(",")
.append("body=").append(body)
.append("}");
.append("body=").append(body)
.append("}");

return sb.toString();
}

public String abstractDesc() {
StringBuilder sb = new StringBuilder();
sb.append("httpCommand={")
.append(cmdType).append(",")
.append(httpMethod).append("/").append(httpVersion).append(",")
.append("requestCode=").append(requestCode).append(",")
.append("opaque=").append(opaque).append(",");
.append(cmdType).append(",")
.append(httpMethod).append("/").append(httpVersion).append(",")
.append("requestCode=").append(requestCode).append(",")
.append("opaque=").append(opaque).append(",");

if (cmdType == CmdType.RES) {
sb.append("cost=").append(resTime - reqTime).append(",");
}

sb.append("header=").append(header).append(",")
.append("bodySize=").append(body.toString().length()).append("}");
.append("bodySize=").append(body.toString().length()).append("}");

return sb.toString();
}

public String simpleDesc() {
StringBuilder sb = new StringBuilder();
sb.append("httpCommand={")
.append(cmdType).append(",")
.append(httpMethod).append("/").append(httpVersion).append(",")
.append("requestCode=").append(requestCode).append("}");
.append(cmdType).append(",")
.append(httpMethod).append("/").append(httpVersion).append(",")
.append("requestCode=").append(requestCode).append("}");

return sb.toString();
}
Expand All @@ -228,10 +235,11 @@ public DefaultFullHttpResponse httpResponse() throws Exception {
}

DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.OK,
Unpooled.wrappedBuffer(JSON.toJSONString(this.getBody()).getBytes(Constants.DEFAULT_CHARSET)));
HttpResponseStatus.OK,
Unpooled.wrappedBuffer(
JsonUtils.serialize(this.getBody()).getBytes(Constants.DEFAULT_CHARSET)));
response.headers().add(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.TEXT_PLAIN +
"; charset=" + Constants.DEFAULT_CHARSET);
"; charset=" + Constants.DEFAULT_CHARSET);
response.headers().add(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
response.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
Map<String, Object> customHeader = this.getHeader().toMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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.apache.eventmesh.common.exception;

/**
* Json format exception, see {@link org.apache.eventmesh.common.utils.JsonUtils}.
*/
public class JsonException extends RuntimeException {

public JsonException(String message) {
super(message);
}

public JsonException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@

package org.apache.eventmesh.common.protocol.http.body.client;

import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.utils.JsonUtils;

import org.apache.commons.collections4.MapUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import org.apache.commons.collections4.MapUtils;
import org.apache.eventmesh.common.protocol.http.body.Body;
import com.fasterxml.jackson.core.type.TypeReference;

public class HeartbeatRequestBody extends Body {

public static final String CLIENTTYPE = "clientType";
public static final String CLIENTTYPE = "clientType";
public static final String HEARTBEATENTITIES = "heartbeatEntities";
public static final String CONSUMERGROUP = "consumerGroup";
public static final String CONSUMERGROUP = "consumerGroup";

private String consumerGroup;

Expand Down Expand Up @@ -67,16 +68,19 @@ public static HeartbeatRequestBody buildBody(Map<String, Object> bodyParam) {
HeartbeatRequestBody body = new HeartbeatRequestBody();
body.setClientType(MapUtils.getString(bodyParam, CLIENTTYPE));
body.setConsumerGroup(MapUtils.getString(bodyParam, CONSUMERGROUP));
body.setHeartbeatEntities(JSONArray.parseArray(MapUtils.getString(bodyParam, HEARTBEATENTITIES), HeartbeatEntity.class));
body.setHeartbeatEntities(JsonUtils
.deserialize(MapUtils.getString(bodyParam, HEARTBEATENTITIES),
new TypeReference<List<HeartbeatEntity>>() {
}));
return body;
}

@Override
public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put(CLIENTTYPE, clientType);
map.put(CONSUMERGROUP, consumerGroup);
map.put(HEARTBEATENTITIES, JSON.toJSONString(heartbeatEntities));
map.put(HEARTBEATENTITIES, JsonUtils.serialize(heartbeatEntities));
return map;
}

Expand All @@ -90,10 +94,10 @@ public static class HeartbeatEntity {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("heartbeatEntity={")
.append("topic=").append(topic).append(",")
.append("serviceId=").append(serviceId).append(",")
.append("instanceId=").append(instanceId).append(",")
.append("url=").append(url).append("}");
.append("topic=").append(topic).append(",")
.append("serviceId=").append(serviceId).append(",")
.append("instanceId=").append(instanceId).append(",")
.append("url=").append(url).append("}");
return sb.toString();
}
}
Expand All @@ -102,8 +106,8 @@ public String toString() {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("heartbeatRequestBody={")
.append("consumerGroup=").append(consumerGroup).append(",")
.append("clientType=").append(clientType).append("}");
.append("consumerGroup=").append(consumerGroup).append(",")
.append("clientType=").append(clientType).append("}");
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@

package org.apache.eventmesh.common.protocol.http.body.client;

import org.apache.eventmesh.common.protocol.SubscriptionItem;
import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.utils.JsonUtils;

import org.apache.commons.collections4.MapUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import org.apache.commons.collections4.MapUtils;
import org.apache.eventmesh.common.protocol.SubscriptionItem;
import org.apache.eventmesh.common.protocol.http.body.Body;
import com.fasterxml.jackson.core.type.TypeReference;

public class RegRequestBody extends Body {

Expand Down Expand Up @@ -70,25 +71,27 @@ public static RegRequestBody buildBody(Map<String, Object> bodyParam) {
RegRequestBody body = new RegRequestBody();
body.setClientType(MapUtils.getString(bodyParam, CLIENTTYPE));
body.setEndPoint(MapUtils.getString(bodyParam, ENDPOINT));
body.setTopics(JSONArray.parseArray(MapUtils.getString(bodyParam, TOPICS), SubscriptionItem.class));
body.setTopics(JsonUtils.deserialize(MapUtils.getString(bodyParam, TOPICS),
new TypeReference<List<SubscriptionItem>>() {
}));
return body;
}

@Override
public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put(CLIENTTYPE, clientType);
map.put(ENDPOINT, endPoint);
map.put(TOPICS, JSON.toJSONString(topics));
map.put(TOPICS, JsonUtils.serialize(topics));
return map;
}

@Override
public String toString() {
return "regRequestBody{" +
"clientType='" + clientType + '\'' +
", endPoint='" + endPoint + '\'' +
", topics=" + topics +
'}';
return "regRequestBody{"
+ "clientType='" + clientType + '\''
+ ", endPoint='" + endPoint + '\''
+ ", topics=" + topics
+ '}';
}
}
Loading

0 comments on commit 37fbff2

Please sign in to comment.