forked from apache/eventmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eventmesh-admin-rocketmq submodule and createTopic REST API (apache#530)
* eventmesh-admin-rocketmq submodule and createTopic draft API * add license header * change to /topicmanage * fix build error * fix some code check style issues close apache#435 apache#346
- Loading branch information
Showing
13 changed files
with
641 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
|
||
dependencies { | ||
compileOnly project(":eventmesh-common") | ||
|
||
implementation "org.apache.httpcomponents:httpclient" | ||
implementation project(":eventmesh-connector-plugin:eventmesh-connector-api") | ||
|
||
testImplementation project(":eventmesh-connector-plugin:eventmesh-connector-api") | ||
} |
17 changes: 17 additions & 0 deletions
17
eventmesh-admin/eventmesh-admin-rocketmq/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 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. | ||
# | ||
|
||
rocketmq_version=4.7.1 |
42 changes: 42 additions & 0 deletions
42
...ocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/controller/AdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.admin.rocketmq.controller; | ||
|
||
import org.apache.eventmesh.admin.rocketmq.handler.TopicsHandler; | ||
|
||
import java.io.IOException; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.sun.net.httpserver.HttpServer; | ||
|
||
public class AdminController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AdminController.class); | ||
|
||
public AdminController() { | ||
} | ||
|
||
public void run(HttpServer server) throws IOException { | ||
|
||
server.createContext("/topicmanage", new TopicsHandler()); | ||
|
||
logger.info("EventMesh-Admin Controller server context created successfully"); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...min-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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.admin.rocketmq.handler; | ||
|
||
import org.apache.eventmesh.admin.rocketmq.request.TopicCreateRequest; | ||
import org.apache.eventmesh.admin.rocketmq.response.TopicResponse; | ||
import org.apache.eventmesh.admin.rocketmq.util.JsonUtils; | ||
import org.apache.eventmesh.admin.rocketmq.util.NetUtils; | ||
import org.apache.eventmesh.admin.rocketmq.util.RequestMapping; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.sun.net.httpserver.HttpExchange; | ||
import com.sun.net.httpserver.HttpHandler; | ||
|
||
public class TopicsHandler implements HttpHandler { | ||
private static final Logger logger = LoggerFactory.getLogger(TopicsHandler.class); | ||
|
||
@Override | ||
public void handle(HttpExchange httpExchange) throws IOException { | ||
|
||
// create a new topic | ||
if (RequestMapping.postMapping("/topicmanage", httpExchange)) { | ||
createTopicHandler(httpExchange); | ||
return; | ||
} | ||
|
||
OutputStream out = httpExchange.getResponseBody(); | ||
httpExchange.sendResponseHeaders(500, 0); | ||
String result = String.format("Please check your request url"); | ||
logger.error(result); | ||
out.write(result.getBytes()); | ||
return; | ||
} | ||
|
||
public void createTopicHandler(HttpExchange httpExchange) throws IOException { | ||
String result = ""; | ||
OutputStream out = httpExchange.getResponseBody(); | ||
try { | ||
String params = NetUtils.parsePostBody(httpExchange); | ||
TopicCreateRequest topicCreateRequest = | ||
JsonUtils.toObject(params, TopicCreateRequest.class); | ||
String topic = topicCreateRequest.getName(); | ||
|
||
if (StringUtils.isBlank(topic)) { | ||
result = "Create topic failed. Parameter topic not found."; | ||
logger.error(result); | ||
out.write(result.getBytes()); | ||
return; | ||
} | ||
|
||
//TBD: A new rocketmq service will be implemented for creating topics | ||
TopicResponse topicResponse = null; | ||
if (topicResponse != null) { | ||
logger.info("create a new topic: {}", topic); | ||
httpExchange.getResponseHeaders().add("Content-Type", "appication/json"); | ||
httpExchange.sendResponseHeaders(200, 0); | ||
result = JsonUtils.toJson(topicResponse); | ||
logger.info(result); | ||
out.write(result.getBytes()); | ||
return; | ||
} else { | ||
httpExchange.sendResponseHeaders(500, 0); | ||
result = String.format("create topic failed! Server side error"); | ||
logger.error(result); | ||
out.write(result.getBytes()); | ||
return; | ||
} | ||
} catch (Exception e) { | ||
httpExchange.getResponseHeaders().add("Content-Type", "appication/json"); | ||
httpExchange.sendResponseHeaders(500, 0); | ||
result = String.format("create topic failed! Server side error"); | ||
logger.error(result); | ||
out.write(result.getBytes()); | ||
return; | ||
} finally { | ||
if (out != null) { | ||
try { | ||
out.close(); | ||
} catch (IOException e) { | ||
logger.warn("out close failed...", e); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...ocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/request/TopicCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.admin.rocketmq.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class TopicCreateRequest { | ||
|
||
private String name; | ||
|
||
@JsonCreator | ||
public TopicCreateRequest(@JsonProperty("name") String topic) { | ||
super(); | ||
this.name = topic; | ||
} | ||
|
||
@JsonProperty("name") | ||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
@JsonProperty("name") | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...in-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/response/TopicResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.admin.rocketmq.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class TopicResponse { | ||
|
||
private String topic; | ||
private String createdTime; | ||
|
||
@JsonCreator | ||
public TopicResponse(@JsonProperty("topic") String topic, | ||
@JsonProperty("created_time") String createdTime) { | ||
super(); | ||
this.topic = topic; | ||
this.createdTime = createdTime; | ||
} | ||
|
||
@JsonProperty("topic") | ||
public String getTopic() { | ||
return this.topic; | ||
} | ||
|
||
@JsonProperty("topic") | ||
public void setTopic(String topic) { | ||
this.topic = topic; | ||
} | ||
|
||
@JsonProperty("created_time") | ||
public String getCreatedTime() { | ||
return createdTime; | ||
} | ||
|
||
@JsonProperty("created_time") | ||
public void setCreatedTime(String createdTime) { | ||
this.createdTime = createdTime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("TopicResponse {topic=" + this.topic + ","); | ||
sb.append("created_time=" + this.createdTime + "}"); | ||
return sb.toString(); | ||
} | ||
|
||
} |
Oops, something went wrong.