You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tubemq.apache.org by go...@apache.org on 2020/12/01 02:07:13 UTC

[incubator-tubemq] branch TUBEMQ-430 updated: [TUBEMQ-435] Create Web field Mapping (#331)

This is an automated email from the ASF dual-hosted git repository.

gosonzhang pushed a commit to branch TUBEMQ-430
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git


The following commit(s) were added to refs/heads/TUBEMQ-430 by this push:
     new 9146ca3  [TUBEMQ-435] Create Web field Mapping (#331)
9146ca3 is described below

commit 9146ca3ddab0906fda032f9f434c8e4dd581a896
Author: gosonzhang <46...@qq.com>
AuthorDate: Tue Dec 1 10:07:06 2020 +0800

    [TUBEMQ-435] Create Web field Mapping (#331)
    
    Co-authored-by: gosonzhang <go...@tencent.com>
---
 .../org/apache/tubemq/corebase/utils/RegexDef.java |  60 ++++++++
 .../tubemq/server/common/utils/ProcessResult.java  |  53 +++++++
 .../tubemq/server/common/webbase/WebFieldDef.java  | 155 +++++++++++++++++++++
 .../tubemq/server/common/webbase/WebFieldType.java |  60 ++++++++
 4 files changed, 328 insertions(+)

diff --git a/tubemq-core/src/main/java/org/apache/tubemq/corebase/utils/RegexDef.java b/tubemq-core/src/main/java/org/apache/tubemq/corebase/utils/RegexDef.java
new file mode 100644
index 0000000..842c6a9
--- /dev/null
+++ b/tubemq-core/src/main/java/org/apache/tubemq/corebase/utils/RegexDef.java
@@ -0,0 +1,60 @@
+/*
+ * 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.corebase.utils;
+
+
+
+public enum RegexDef {
+
+    TMP_FILTER(0, "^[_A-Za-z0-9]+$",
+            "must only contain characters,numbers,and underscores"),
+    TMP_STRING(1, "^[a-zA-Z]\\w+$",
+                       "must begin with a letter,can only contain characters,numbers,and underscores"),
+    TMP_NUMBER(2, "^-?[0-9]\\d*$", "must only contain numbers"),
+    TMP_GROUP(3, "^[a-zA-Z][\\w-]+$",
+                       "must begin with a letter,can only contain characters,numbers,hyphen,and underscores"),
+    TMP_CONSUMERID(4, "^[_A-Za-z0-9\\.\\-]+$",
+                      "must begin with a letter,can only contain characters,numbers,dot,scores,and underscores"),
+    TMP_IPV4ADDRESS(5,
+            "((?:(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d))))",
+            "must matches the IP V4 address regulation");
+
+
+    private final int id;
+    private final String pattern;
+    private final String errMsgTemp;
+
+
+    RegexDef(int id, String pattern, String errMsgTemp) {
+        this.id = id;
+        this.pattern = pattern;
+        this.errMsgTemp = errMsgTemp;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getPattern() {
+        return pattern;
+    }
+
+    public String getErrMsgTemp() {
+        return errMsgTemp;
+    }
+}
diff --git a/tubemq-server/src/main/java/org/apache/tubemq/server/common/utils/ProcessResult.java b/tubemq-server/src/main/java/org/apache/tubemq/server/common/utils/ProcessResult.java
new file mode 100644
index 0000000..3688b1c
--- /dev/null
+++ b/tubemq-server/src/main/java/org/apache/tubemq/server/common/utils/ProcessResult.java
@@ -0,0 +1,53 @@
+/**
+ * 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 org.apache.tubemq.corebase.TErrCodeConstants;
+
+public class ProcessResult {
+    public boolean success = true;
+    public int errCode = TErrCodeConstants.SUCCESS;
+    public String errInfo = "";
+    public Object retData1 = null;
+
+    public ProcessResult() {
+
+    }
+
+    public ProcessResult(Object retData) {
+        this.success = true;
+        this.retData1 = retData;
+    }
+
+    public ProcessResult(int errCode, String errInfo) {
+        this.success = false;
+        this.errCode = errCode;
+        this.errInfo = errInfo;
+    }
+
+    public void setFailResult(int errCode, final String errMsg) {
+        this.success = false;
+        this.errCode = errCode;
+        this.errInfo = errMsg;
+    }
+
+    public void setSuccResult(Object retData) {
+        this.success = true;
+        this.retData1 = retData;
+    }
+}
diff --git a/tubemq-server/src/main/java/org/apache/tubemq/server/common/webbase/WebFieldDef.java b/tubemq-server/src/main/java/org/apache/tubemq/server/common/webbase/WebFieldDef.java
new file mode 100644
index 0000000..4f298f8
--- /dev/null
+++ b/tubemq-server/src/main/java/org/apache/tubemq/server/common/webbase/WebFieldDef.java
@@ -0,0 +1,155 @@
+/**
+ * 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.webbase;
+
+import org.apache.tubemq.corebase.TBaseConstants;
+import org.apache.tubemq.corebase.TokenConstants;
+import org.apache.tubemq.corebase.utils.RegexDef;
+import org.apache.tubemq.server.common.TServerConstants;
+
+
+
+public enum WebFieldDef {
+
+    TOPICNAME(0, "topicName", "topic", WebFieldType.STRING,
+            "Topic name", TBaseConstants.META_MAX_TOPICNAME_LENGTH,
+            RegexDef.TMP_STRING),
+    GROUPNAME(1, "groupName", "grp", WebFieldType.STRING,
+            "Group name", TBaseConstants.META_MAX_GROUPNAME_LENGTH,
+            RegexDef.TMP_GROUP),
+    PARTITIONID(2, "partitionId", "pid", WebFieldType.INT,
+            "Partition id", RegexDef.TMP_NUMBER),
+    CREATEUSER(3, "createUser", "cur", WebFieldType.STRING,
+            "Record creator", TBaseConstants.META_MAX_USERNAME_LENGTH,
+            RegexDef.TMP_STRING),
+    MODIFYUSER(4, "modifyUser", "mur", WebFieldType.STRING,
+            "Record modifier", TBaseConstants.META_MAX_USERNAME_LENGTH,
+            RegexDef.TMP_STRING),
+    MANUALOFFSET(5, "manualOffset", "ofs", WebFieldType.LONG,
+            "Reset offset value", RegexDef.TMP_NUMBER),
+    MSGCOUNT(6, "msgCount", "cnt", WebFieldType.INT,
+            "Number of returned messages", RegexDef.TMP_NUMBER),
+    FILTERCONDS(7, "filterConds", "fls", WebFieldType.COMPSTRING,
+            "Filter condition items", TBaseConstants.CFG_FLT_MAX_FILTER_ITEM_LENGTH,
+            TBaseConstants.CFG_FLT_MAX_FILTER_ITEM_COUNT, RegexDef.TMP_FILTER),
+    REQUIREREALOFFSET(8, "requireRealOffset", "dko", WebFieldType.BOOLEAN,
+            "Require return disk offset details"),
+    NEEDREFRESH(9, "needRefresh", "nrf", WebFieldType.BOOLEAN,
+            "Require refresh data"),
+    COMPSGROUPNAME(10, "groupName", "grp", WebFieldType.COMPSTRING,
+            "Group name", TBaseConstants.META_MAX_GROUPNAME_LENGTH,
+                   RegexDef.TMP_GROUP),
+    COMPSTOPICNAME(11, "topicName", "topic", WebFieldType.COMPSTRING,
+            "Topic name", TBaseConstants.META_MAX_TOPICNAME_LENGTH,
+            RegexDef.TMP_STRING),
+    COMPSPARTITIONID(12, "partitionId", "pid", WebFieldType.COMPINT,
+            "Partition id", RegexDef.TMP_NUMBER);
+
+
+
+
+    public final int id;
+    public final String name;
+    public final String shortName;
+    public final WebFieldType type;
+    public final String desc;
+    public final boolean compVal;
+    public final String splitToken;
+    public final int itemMaxCnt;
+    public final int valMaxLen;
+    public final boolean regexCheck;
+    public final RegexDef regexDef;
+
+
+    WebFieldDef(int id, String name, String shortName, WebFieldType type, String desc) {
+        this(id, name, shortName, type, desc, TBaseConstants.META_VALUE_UNDEFINED,
+                TBaseConstants.META_VALUE_UNDEFINED, false, null);
+    }
+
+    WebFieldDef(int id, String name, String shortName, WebFieldType type,
+                String desc, RegexDef regexDef) {
+        this(id, name, shortName, type, desc,
+                TBaseConstants.META_VALUE_UNDEFINED, regexDef);
+    }
+
+    WebFieldDef(int id, String name, String shortName, WebFieldType type,
+                String desc, int valMaxLen, RegexDef regexDef) {
+        this(id, name, shortName, type, desc, valMaxLen,
+                TServerConstants.CFG_BATCH_RECORD_OPERATE_MAX_COUNT,
+                true, regexDef);
+    }
+
+    WebFieldDef(int id, String name, String shortName, WebFieldType type,
+                String desc, int valMaxLen, int itemMaxCnt, RegexDef regexDef) {
+        this(id, name, shortName, type, desc, valMaxLen,
+                itemMaxCnt, true, regexDef);
+    }
+
+    WebFieldDef(int id, String name, String shortName, WebFieldType type,
+                String desc, int valMaxLen, int itemMaxCnt,
+                boolean regexChk, RegexDef regexDef) {
+        this.id = id;
+        this.name = name;
+        this.shortName = shortName;
+        this.type = type;
+        this.desc = desc;
+        if (isCompFieldType()) {
+            this.compVal = true;
+            this.splitToken = TokenConstants.ARRAY_SEP;
+            this.itemMaxCnt = itemMaxCnt;
+        } else {
+            this.compVal = false;
+            this.splitToken = "";
+            this.itemMaxCnt = TBaseConstants.META_VALUE_UNDEFINED;
+        }
+        this.valMaxLen = valMaxLen;
+        this.regexCheck = regexChk;
+        this.regexDef = regexDef;
+    }
+
+    public boolean isCompFieldType() {
+        return (this.type == WebFieldType.COMPINT
+                || this.type == WebFieldType.COMPSTRING);
+    }
+
+    private static final WebFieldDef[] WEB_FIELD_DEFS;
+    private static final int MIN_FIELD_ID = 0;
+    public static final int MAX_FIELD_ID;
+
+    static {
+        int maxId = -1;
+        for (WebFieldDef fieldDef : WebFieldDef.values()) {
+            maxId = Math.max(maxId, fieldDef.id);
+        }
+        WebFieldDef[] idToType = new WebFieldDef[maxId + 1];
+        for (WebFieldDef fieldDef : WebFieldDef.values()) {
+            idToType[fieldDef.id] = fieldDef;
+        }
+        WEB_FIELD_DEFS = idToType;
+        MAX_FIELD_ID = maxId;
+    }
+
+    public static WebFieldDef valueOf(int fieldId) {
+        if (fieldId >= MIN_FIELD_ID && fieldId <= MAX_FIELD_ID) {
+            return WEB_FIELD_DEFS[fieldId];
+        }
+        throw new IllegalArgumentException(
+                String.format("Unexpected WebFieldDef id `%s`, it should be between `%s` " +
+                "and `%s` (inclusive)", fieldId, MIN_FIELD_ID, MAX_FIELD_ID));
+    }
+}
diff --git a/tubemq-server/src/main/java/org/apache/tubemq/server/common/webbase/WebFieldType.java b/tubemq-server/src/main/java/org/apache/tubemq/server/common/webbase/WebFieldType.java
new file mode 100644
index 0000000..b83a966
--- /dev/null
+++ b/tubemq-server/src/main/java/org/apache/tubemq/server/common/webbase/WebFieldType.java
@@ -0,0 +1,60 @@
+/**
+ * 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.webbase;
+
+
+
+public enum WebFieldType {
+
+    UNKNOWN(-1, "Unknown field type"),
+    STRING(1, "String"),
+    INT(2, "int"),
+    LONG(3, "long"),
+    BOOLEAN(4, "Boolean"),
+    DATE(5, "Date"),
+    COMPSTRING(6, "Compound string"),
+    COMPINT(7, "Compound integer");
+
+
+    public int value;
+    public String desc;
+
+    WebFieldType(int value, String desc) {
+        this.value = value;
+        this.desc = desc;
+    }
+
+    public static WebFieldType valueOf(int value) {
+        for (WebFieldType fieldType : WebFieldType.values()) {
+            if (fieldType.getValue() == value) {
+                return fieldType;
+            }
+        }
+
+        return UNKNOWN;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public String getDesc(){
+        return desc;
+    }
+
+}