forked from apache/inlong
-
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.
[TUBEMQ-447] Add Broker-Admin Cli (apache#347)
Co-authored-by: gosonzhang <gosonzhang@tencent.com>
- Loading branch information
Showing
14 changed files
with
355 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# 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. | ||
# | ||
|
||
if [ -z "$BASE_DIR" ] ; then | ||
PRG="$0" | ||
|
||
# need this for relative symlinks | ||
while [ -h "$PRG" ] ; do | ||
ls=`ls -ld "$PRG"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
PRG="$link" | ||
else | ||
PRG="`dirname "$PRG"`/$link" | ||
fi | ||
done | ||
BASE_DIR=`dirname "$PRG"`/.. | ||
|
||
# make it fully qualified | ||
BASE_DIR=`cd "$BASE_DIR" && pwd` | ||
#echo "TubeMQ master is at $BASE_DIR" | ||
fi | ||
source $BASE_DIR/bin/env.sh | ||
$JAVA $TOOLS_ARGS org.apache.tubemq.server.tools.cli.CliBrokerAdmin $@ |
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
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
112 changes: 112 additions & 0 deletions
112
tubemq-server/src/main/java/org/apache/tubemq/server/common/utils/HttpUtils.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,112 @@ | ||
/** | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.tubemq.server.common.utils; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.client.entity.UrlEncodedFormEntity; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.message.BasicNameValuePair; | ||
import org.apache.http.util.EntityUtils; | ||
import org.apache.tubemq.corebase.utils.AddressUtils; | ||
import org.apache.tubemq.corebase.utils.TStringUtils; | ||
import org.apache.tubemq.server.common.fielddef.WebFieldDef; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
|
||
/** | ||
* This class is used to process http connection and return result conversion, | ||
* currently does not support https | ||
*/ | ||
public class HttpUtils { | ||
// log printer | ||
private static final Logger logger = | ||
LoggerFactory.getLogger(HttpUtils.class); | ||
|
||
|
||
/* Send request to target server. */ | ||
public static JsonObject requestWebService(String url, | ||
Map<String, String> inParamMap) throws Exception { | ||
if (url == null) { | ||
throw new Exception("Web service url is null!"); | ||
} | ||
if (url.trim().toLowerCase().startsWith("https://")) { | ||
throw new Exception("Unsupported https protocol!"); | ||
} | ||
// process business parameters | ||
ArrayList<BasicNameValuePair> params = new ArrayList<>(); | ||
if (inParamMap != null && !inParamMap.isEmpty()) { | ||
for (Map.Entry<String, String> entry : inParamMap.entrySet()) { | ||
params.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); | ||
} | ||
if (inParamMap.containsKey(WebFieldDef.CALLERIP.shortName) | ||
|| inParamMap.containsKey(WebFieldDef.CALLERIP.name)) { | ||
params.add(new BasicNameValuePair(WebFieldDef.CALLERIP.name, | ||
AddressUtils.getIPV4LocalAddress())); | ||
} | ||
} | ||
// build connect configure | ||
RequestConfig requestConfig = RequestConfig.custom() | ||
.setConnectTimeout(50000).setSocketTimeout(60000).build(); | ||
// build HttpClient and HttpPost objects | ||
CloseableHttpClient httpclient = null; | ||
HttpPost httpPost = null; | ||
JsonObject jsonRes = null; | ||
JsonParser jsonParser = new JsonParser(); | ||
try { | ||
httpclient = HttpClients.custom() | ||
.setDefaultRequestConfig(requestConfig).build(); | ||
httpPost = new HttpPost(url); | ||
UrlEncodedFormEntity se = new UrlEncodedFormEntity(params); | ||
httpPost.setEntity(se); | ||
// send http request and process response | ||
CloseableHttpResponse response = httpclient.execute(httpPost); | ||
String returnStr = EntityUtils.toString(response.getEntity()); | ||
if (TStringUtils.isNotBlank(returnStr) | ||
&& response.getStatusLine().getStatusCode() == 200) { | ||
jsonRes = jsonParser.parse(returnStr).getAsJsonObject(); | ||
} | ||
} catch (Throwable e) { | ||
throw new Exception("Connecting " + url + " throw an error!", e); | ||
} finally { | ||
if (httpPost != null) { | ||
httpPost.releaseConnection(); | ||
} | ||
if (httpclient != null) { | ||
try { | ||
httpclient.close(); | ||
} catch (IOException ie) { | ||
logger.error("Close HttpClient error.", ie); | ||
} | ||
} | ||
} | ||
return jsonRes; | ||
} | ||
|
||
} |
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
Oops, something went wrong.