Skip to content

Commit

Permalink
[INLONG-11683][SDK] Optimize the functions return of the ProxyConfigM…
Browse files Browse the repository at this point in the history
…anager class (#11684)

* [INLONG-11683][SDK] Optimize the functions return of the ProxyConfigManager class

* [INLONG-11683][SDK] Optimize the functions return of the ProxyConfigManager class

---------

Co-authored-by: gosonzhang <[email protected]>
  • Loading branch information
gosonzhang and gosonzhang authored Jan 20, 2025
1 parent 5fcc384 commit d66bd13
Show file tree
Hide file tree
Showing 10 changed files with 467 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.inlong.common.msg.AttributeConstants;
import org.apache.inlong.common.util.MessageUtils;
import org.apache.inlong.sdk.dataproxy.codec.EncodeObject;
import org.apache.inlong.sdk.dataproxy.common.ProcessResult;
import org.apache.inlong.sdk.dataproxy.common.SdkConsts;
import org.apache.inlong.sdk.dataproxy.common.SendMessageCallback;
import org.apache.inlong.sdk.dataproxy.common.SendResult;
Expand All @@ -30,7 +31,6 @@
import org.apache.inlong.sdk.dataproxy.network.SequentialID;
import org.apache.inlong.sdk.dataproxy.threads.IndexCollectThread;
import org.apache.inlong.sdk.dataproxy.utils.ProxyUtils;
import org.apache.inlong.sdk.dataproxy.utils.Tuple2;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -102,20 +102,20 @@ public static DefaultMessageSender generateSenderByClusterId(TcpMsgSenderConfig
ThreadFactory selfDefineFactory) throws Exception {
LOGGER.info("Initial tcp sender, configure is {}", tcpConfig);
// initial sender object
ProcessResult procResult = new ProcessResult();
ProxyConfigManager proxyConfigManager = new ProxyConfigManager(tcpConfig);
Tuple2<ProxyConfigEntry, String> result =
proxyConfigManager.getGroupIdConfigure(true);
if (result.getF0() == null) {
throw new Exception(result.getF1());
if (!proxyConfigManager.getGroupIdConfigure(true, procResult)) {
throw new Exception(procResult.toString());
}
DefaultMessageSender sender = CACHE_SENDER.get(result.getF0().getClusterId());
ProxyConfigEntry configEntry = (ProxyConfigEntry) procResult.getRetData();
DefaultMessageSender sender = CACHE_SENDER.get(configEntry.getClusterId());
if (sender != null) {
return sender;
} else {
DefaultMessageSender tmpMessageSender =
new DefaultMessageSender(tcpConfig, selfDefineFactory);
tmpMessageSender.setMaxPacketLength(result.getF0().getMaxPacketLength());
CACHE_SENDER.put(result.getF0().getClusterId(), tmpMessageSender);
tmpMessageSender.setMaxPacketLength(configEntry.getMaxPacketLength());
CACHE_SENDER.put(configEntry.getClusterId(), tmpMessageSender);
return tmpMessageSender;
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public void setMaxPacketLength(int maxPacketLength) {
}

public String getSDKVersion() {
return SdkConsts.PROXY_SDK_VERSION;
return ProxyUtils.getJarVersion();
}

private SendResult attemptSendMessage(Function<Sender, SendResult> sendOperation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.inlong.sdk.dataproxy.common;

import org.apache.commons.lang3.math.NumberUtils;

/**
* Error Code class
*
* Used to identify different types of errors
*/
public enum ErrorCode {

OK(0, "Ok"),

SDK_CLOSED(11, "SDK service closed"),
//
ILLEGAL_CALL_STATE(21, "Only allowed for meta query"),
CONFIGURE_NOT_INITIALIZED(22, "Configure not initialized"),
FREQUENT_RMT_FAILURE_VISIT(23, "Frequent manager failure visit"),

// file visit
LOCAL_FILE_NOT_EXIST(31, "Local file not exist"),
LOCAL_FILE_EXPIRED(32, "Local file expired"),
READ_LOCAL_FILE_FAILURE(33, "Read local file failure"),
BLANK_FILE_CONTENT(34, "Blank file content"),
PARSE_FILE_CONTENT_FAILURE(35, "Parse file content failure"),
//
PARSE_FILE_CONTENT_IS_NULL(36, "Parse file content is null"),

// remote visit
BUILD_HTTP_CLIENT_EXCEPTION(41, "Build http client exception"),
HTTP_VISIT_EXCEPTION(42, "Visit http server exception"),
RMT_RETURN_FAILURE(43, "Http server return failure"),
RMT_RETURN_BLANK_CONTENT(44, "Http server return blank content"),
PARSE_RMT_CONTENT_FAILURE(45, "Parse manager content failure"),
//
PARSE_RMT_CONTENT_IS_NULL(46, "Parse manager content is null"),
RMT_RETURN_ERROR(47, "Manager return error info"),
META_FIELD_DATA_IS_NULL(48, "Field data is null"),
META_NODE_LIST_IS_EMPTY(49, "Field nodeList is empty"),
NODE_LIST_RECORD_INVALID(50, "No valid nodeList records"),
//
PARSE_PROXY_META_EXCEPTION(51, "No valid nodeList records"),
PARSE_ENCRYPT_META_EXCEPTION(52, "Parse encrypt content failure"),
META_REQUIRED_FIELD_NOT_EXIST(53, "Required meta field not exist"),
META_FIELD_VALUE_ILLEGAL(54, "Meta field value illegal"),

//
UNKNOWN_ERROR(9999, "Unknown error");

public static ErrorCode valueOf(int value) {
for (ErrorCode errCode : ErrorCode.values()) {
if (errCode.getErrCode() == value) {
return errCode;
}
}
return UNKNOWN_ERROR;
}

public static String getErrMsg(String errCode) {
int codeVal = NumberUtils.toInt(errCode, Integer.MAX_VALUE);
return valueOf(codeVal).errMsg;
}

private final int errCode;
private final String errMsg;

ErrorCode(int errCode, String errMsg) {
this.errCode = errCode;
this.errMsg = errMsg;
}

public int getErrCode() {
return errCode;
}

public String getErrMsg() {
return errMsg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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.inlong.sdk.dataproxy.common;

/**
* Process Result class
*
* Used to return the result of task processing
*/
public class ProcessResult {

// error code
private int errCode = ErrorCode.UNKNOWN_ERROR.getErrCode();
// error message
private String errMsg = "";
// return data if success
private Object retData = null;

public ProcessResult() {
//
}

public ProcessResult(ErrorCode errCode) {
this.errCode = errCode.getErrCode();
}

public ProcessResult(ErrorCode errCode, String errMsg) {
this.errCode = errCode.getErrCode();
this.errMsg = errMsg;
}

public boolean setSuccess() {
this.errCode = ErrorCode.OK.getErrCode();
this.errMsg = "";
this.retData = null;
return isSuccess();
}

public boolean setSuccess(Object retData) {
this.errCode = ErrorCode.OK.getErrCode();
this.errMsg = "";
this.retData = retData;
return isSuccess();
}

public boolean setFailResult(ProcessResult other) {
this.errCode = other.getErrCode();
this.errMsg = other.getErrMsg();
this.retData = other.getRetData();
return isSuccess();
}

public boolean setFailResult(ErrorCode errCode) {
this.errCode = errCode.getErrCode();
this.errMsg = "";
this.retData = null;
return isSuccess();
}

public boolean setFailResult(ErrorCode errCode, String errMsg) {
this.errCode = errCode.getErrCode();
this.errMsg = errMsg;
this.retData = null;
return isSuccess();
}

public boolean isSuccess() {
return (this.errCode == ErrorCode.OK.getErrCode());
}

public int getErrCode() {
return errCode;
}

public String getErrMsg() {
return errMsg;
}

public Object getRetData() {
return retData;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ProcessResult{");
sb.append("errCode=").append(errCode);
sb.append(", errMsg='").append(errMsg).append('\'');
sb.append('}');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

public class SdkConsts {

public static final String PROXY_SDK_VERSION = "1.2.11";

public static String PREFIX_HTTP = "http://";
public static String PREFIX_HTTPS = "https://";

Expand Down
Loading

0 comments on commit d66bd13

Please sign in to comment.