• nacos 适配瀚高数据库、ARM 架构


    下载nacos源码: https://github.com/alibaba/nacos/tree/2.3.1

    瀚高技术文档

    1、修改pom.xml

    1. 根目录nacos-all => pom.xml
    2. com.highgo
    3. HgdbJdbc
    4. 6.2.3
    5. .nacos-config模块 => pom.xml
    6. com.highgo
    7. HgdbJdbc

    2、修改nacos-config模块 连接驱动    ExternalDataSourceProperties

    1. com.alibaba.nacos.persistence.datasource.ExternalDataSourceProperties
    2. private static final String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
    3. 修改为:
    4. private static final String JDBC_DRIVER_NAME = "com.highgo.jdbc.Driver";

    3、nacos-datasource-plugin模块增加支持的数据库类型

    1. com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant
    2. public class DataSourceConstant {
    3. public static final String MYSQL = "mysql";
    4. public static final String DERBY = "derby";
    5. public static final String HIGHGO = "highgo";
    6. }

    4、 根据SPI机制进行代码扩展

    1. ConfigInfoAggrMapperByHighgo
    2. ConfigInfoBetaMapperByHighgo
    3. ConfigInfoMapperByHighgo
    4. ConfigInfoTagMapperByHighgo
    5. ConfigTagsRelationMapperByHighgo
    6. GroupCapacityMapperByHighgo
    7. HistoryConfigInfoMapperByHighgo
    8. TenantCapacityMapperByHighgo
    9. TenantInfoMapperByHighgo

    1. /*
    2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
    3. *
    4. * Licensed under the Apache License, Version 2.0 (the "License");
    5. * you may not use this file except in compliance with the License.
    6. * You may obtain a copy of the License at
    7. *
    8. * http://www.apache.org/licenses/LICENSE-2.0
    9. *
    10. * Unless required by applicable law or agreed to in writing, software
    11. * distributed under the License is distributed on an "AS IS" BASIS,
    12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13. * See the License for the specific language governing permissions and
    14. * limitations under the License.
    15. */
    16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
    17. import com.alibaba.nacos.common.utils.CollectionUtils;
    18. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
    19. import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
    20. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
    21. import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
    22. import com.alibaba.nacos.plugin.datasource.model.MapperContext;
    23. import com.alibaba.nacos.plugin.datasource.model.MapperResult;
    24. import java.util.List;
    25. /**
    26. * The highgo implementation of ConfigInfoAggrMapper.
    27. *
    28. * @Date: 2023/05/11
    29. */
    30. public class ConfigInfoAggrMapperByHighgo extends AbstractMapper implements ConfigInfoAggrMapper {
    31. @Override
    32. public MapperResult findConfigInfoAggrByPageFetchRows(MapperContext context) {
    33. int startRow = context.getStartRow();
    34. int pageSize = context.getPageSize();
    35. String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
    36. String groupId = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
    37. String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
    38. String sql =
    39. "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "
    40. + " group_id= ? AND tenant_id= ? ORDER BY datum_id " + " OFFSET " + startRow + " LIMIT " + pageSize;
    41. List paramList = CollectionUtils.list(dataId, groupId, tenantId);
    42. return new MapperResult(sql, paramList);
    43. }
    44. @Override
    45. public String getDataSource() {
    46. return DataSourceConstant.HIGHGO;
    47. }
    48. }
      1. /*
      2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
      3. *
      4. * Licensed under the Apache License, Version 2.0 (the "License");
      5. * you may not use this file except in compliance with the License.
      6. * You may obtain a copy of the License at
      7. *
      8. * http://www.apache.org/licenses/LICENSE-2.0
      9. *
      10. * Unless required by applicable law or agreed to in writing, software
      11. * distributed under the License is distributed on an "AS IS" BASIS,
      12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13. * See the License for the specific language governing permissions and
      14. * limitations under the License.
      15. */
      16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
      17. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
      18. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
      19. import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper;
      20. import com.alibaba.nacos.plugin.datasource.model.MapperContext;
      21. import com.alibaba.nacos.plugin.datasource.model.MapperResult;
      22. import java.util.ArrayList;
      23. import java.util.List;
      24. /**
      25. * The highgo implementation of ConfigInfoBetaMapper.
      26. *
      27. * @Date: 2023/05/11
      28. */
      29. public class ConfigInfoBetaMapperByHighgo extends AbstractMapper implements ConfigInfoBetaMapper {
      30. @Override
      31. public MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext context) {
      32. int startRow = context.getStartRow();
      33. int pageSize = context.getPageSize();
      34. String sql = " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "
      35. + " FROM ( SELECT id FROM config_info_beta ORDER BY id OFFSET " + startRow + " LIMIT " + pageSize + ")"
      36. + " g, config_info_beta t WHERE g.id = t.id ";
      37. List paramList = new ArrayList<>();
      38. paramList.add(startRow);
      39. paramList.add(pageSize);
      40. return new MapperResult(sql, paramList);
      41. }
      42. @Override
      43. public String getDataSource() {
      44. return DataSourceConstant.HIGHGO;
      45. }
      46. }
        1. /*
        2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
        3. *
        4. * Licensed under the Apache License, Version 2.0 (the "License");
        5. * you may not use this file except in compliance with the License.
        6. * You may obtain a copy of the License at
        7. *
        8. * http://www.apache.org/licenses/LICENSE-2.0
        9. *
        10. * Unless required by applicable law or agreed to in writing, software
        11. * distributed under the License is distributed on an "AS IS" BASIS,
        12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        13. * See the License for the specific language governing permissions and
        14. * limitations under the License.
        15. */
        16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
        17. import com.alibaba.nacos.common.utils.CollectionUtils;
        18. import com.alibaba.nacos.common.utils.NamespaceUtil;
        19. import com.alibaba.nacos.plugin.datasource.constants.ContextConstant;
        20. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
        21. import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
        22. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
        23. import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
        24. import com.alibaba.nacos.plugin.datasource.model.MapperContext;
        25. import com.alibaba.nacos.plugin.datasource.model.MapperResult;
        26. import java.sql.Timestamp;
        27. import java.util.ArrayList;
        28. import java.util.Collections;
        29. import java.util.List;
        30. /**
        31. * The highgo implementation of ConfigInfoMapper.
        32. *
        33. * @Date: 2023/05/11
        34. */
        35. public class ConfigInfoMapperByHighgo extends AbstractMapper implements ConfigInfoMapper {
        36. private static final String DATA_ID = "dataId";
        37. private static final String GROUP = "group";
        38. private static final String APP_NAME = "appName";
        39. private static final String CONTENT = "content";
        40. private static final String TENANT = "tenant";
        41. @Override
        42. public MapperResult findConfigInfoByAppFetchRows(MapperContext context) {
        43. final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
        44. final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
        45. String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info"
        46. + " WHERE tenant_id LIKE ? AND app_name= ?" + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize();
        47. return new MapperResult(sql, CollectionUtils.list(tenantId, appName));
        48. }
        49. @Override
        50. public MapperResult getTenantIdList(MapperContext context) {
        51. String sql = "SELECT tenant_id FROM config_info WHERE tenant_id != '" + NamespaceUtil.getNamespaceDefaultId()
        52. + "' GROUP BY tenant_id OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize();
        53. return new MapperResult(sql, Collections.emptyList());
        54. }
        55. @Override
        56. public MapperResult getGroupIdList(MapperContext context) {
        57. String sql = "SELECT group_id FROM config_info WHERE tenant_id ='" + NamespaceUtil.getNamespaceDefaultId()
        58. + "' GROUP BY group_id OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize();
        59. return new MapperResult(sql, Collections.emptyList());
        60. }
        61. @Override
        62. public MapperResult findAllConfigKey(MapperContext context) {
        63. String sql = " SELECT data_id,group_id,app_name FROM ( "
        64. + " SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id OFFSET " + context.getStartRow() + " LIMIT "
        65. + context.getPageSize() + " )" + " g, config_info t WHERE g.id = t.id ";
        66. return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID)));
        67. }
        68. @Override
        69. public MapperResult findAllConfigInfoBaseFetchRows(MapperContext context) {
        70. String sql = "SELECT t.id,data_id,group_id,content,md5"
        71. + " FROM ( SELECT id FROM config_info ORDER BY id OFFSET ? LIMIT ? ) "
        72. + " g, config_info t WHERE g.id = t.id ";
        73. return new MapperResult(sql, Collections.emptyList());
        74. }
        75. @Override
        76. public MapperResult findAllConfigInfoFragment(MapperContext context) {
        77. String contextParameter = context.getContextParameter(ContextConstant.NEED_CONTENT);
        78. boolean needContent = contextParameter != null && Boolean.parseBoolean(contextParameter);
        79. String sql = "SELECT id,data_id,group_id,tenant_id,app_name," + (needContent ? "content," : "")
        80. + "md5,gmt_modified,type,encrypted_data_key FROM config_info WHERE id > ? ORDER BY id ASC OFFSET "
        81. + context.getStartRow() + " LIMIT " + context.getPageSize();
        82. return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID)));
        83. }
        84. @Override
        85. public MapperResult findChangeConfigFetchRows(MapperContext context) {
        86. final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
        87. final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
        88. final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
        89. final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
        90. final String tenantTmp = com.alibaba.nacos.common.utils.StringUtils.isBlank(tenant)
        91. ? com.alibaba.nacos.common.utils.StringUtils.EMPTY : tenant;
        92. final Timestamp startTime = (Timestamp) context.getWhereParameter(FieldConstant.START_TIME);
        93. final Timestamp endTime = (Timestamp) context.getWhereParameter(FieldConstant.END_TIME);
        94. List paramList = new ArrayList<>();
        95. final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,type,md5,gmt_modified FROM config_info WHERE ";
        96. String where = " 1=1 ";
        97. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(dataId)) {
        98. where += " AND data_id LIKE ? ";
        99. paramList.add(dataId);
        100. }
        101. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(group)) {
        102. where += " AND group_id LIKE ? ";
        103. paramList.add(group);
        104. }
        105. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(tenantTmp)) {
        106. where += " AND tenant_id = ? ";
        107. paramList.add(tenantTmp);
        108. }
        109. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(appName)) {
        110. where += " AND app_name = ? ";
        111. paramList.add(appName);
        112. }
        113. if (startTime != null) {
        114. where += " AND gmt_modified >=? ";
        115. paramList.add(startTime);
        116. }
        117. if (endTime != null) {
        118. where += " AND gmt_modified <=? ";
        119. paramList.add(endTime);
        120. }
        121. return new MapperResult(
        122. sqlFetchRows + where + " AND id > " + context.getWhereParameter(FieldConstant.LAST_MAX_ID)
        123. + " ORDER BY id ASC" + " OFFSET " + 0 + " LIMIT " + context.getPageSize(), paramList);
        124. }
        125. @Override
        126. public MapperResult listGroupKeyMd5ByPageFetchRows(MapperContext context) {
        127. String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "
        128. + "( SELECT id FROM config_info ORDER BY id OFFSET " + context.getStartRow() + " LIMIT "
        129. + context.getPageSize() + " ) g, config_info t WHERE g.id = t.id";
        130. return new MapperResult(sql, Collections.emptyList());
        131. }
        132. @Override
        133. public MapperResult findConfigInfoBaseLikeFetchRows(MapperContext context) {
        134. final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
        135. final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
        136. final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
        137. final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
        138. String where = " 1=1 AND tenant_id='" + NamespaceUtil.getNamespaceDefaultId() + "' ";
        139. List paramList = new ArrayList<>();
        140. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(dataId)) {
        141. where += " AND data_id LIKE ? ";
        142. paramList.add(dataId);
        143. }
        144. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(group)) {
        145. where += " AND group_id LIKE ";
        146. paramList.add(group);
        147. }
        148. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(content)) {
        149. where += " AND content LIKE ? ";
        150. paramList.add(content);
        151. }
        152. return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
        153. paramList);
        154. }
        155. @Override
        156. public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
        157. final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
        158. final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
        159. final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
        160. final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
        161. final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
        162. List paramList = new ArrayList<>();
        163. final String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info";
        164. StringBuilder where = new StringBuilder(" WHERE ");
        165. where.append(" tenant_id=? ");
        166. paramList.add(tenant);
        167. if (com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dataId)) {
        168. where.append(" AND data_id=? ");
        169. paramList.add(dataId);
        170. }
        171. if (com.alibaba.nacos.common.utils.StringUtils.isNotBlank(group)) {
        172. where.append(" AND group_id=? ");
        173. paramList.add(group);
        174. }
        175. if (com.alibaba.nacos.common.utils.StringUtils.isNotBlank(appName)) {
        176. where.append(" AND app_name=? ");
        177. paramList.add(appName);
        178. }
        179. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(content)) {
        180. where.append(" AND content LIKE ? ");
        181. paramList.add(content);
        182. }
        183. return new MapperResult(sql + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
        184. paramList);
        185. }
        186. @Override
        187. public MapperResult findConfigInfoBaseByGroupFetchRows(MapperContext context) {
        188. String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=?" + " OFFSET "
        189. + context.getStartRow() + " LIMIT " + context.getPageSize();
        190. return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.GROUP_ID),
        191. context.getWhereParameter(FieldConstant.TENANT_ID)));
        192. }
        193. @Override
        194. public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
        195. final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
        196. final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
        197. final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
        198. final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
        199. final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
        200. List paramList = new ArrayList<>();
        201. final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info";
        202. StringBuilder where = new StringBuilder(" WHERE ");
        203. where.append(" tenant_id LIKE ? ");
        204. paramList.add(tenant);
        205. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(dataId)) {
        206. where.append(" AND data_id LIKE ? ");
        207. paramList.add(dataId);
        208. }
        209. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(group)) {
        210. where.append(" AND group_id LIKE ? ");
        211. paramList.add(group);
        212. }
        213. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(appName)) {
        214. where.append(" AND app_name = ? ");
        215. paramList.add(appName);
        216. }
        217. if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(content)) {
        218. where.append(" AND content LIKE ? ");
        219. paramList.add(content);
        220. }
        221. return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
        222. paramList);
        223. }
        224. @Override
        225. public MapperResult findAllConfigInfoFetchRows(MapperContext context) {
        226. String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "
        227. + " FROM ( SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id OFFSET ? LIMIT ? )"
        228. + " g, config_info t WHERE g.id = t.id ";
        229. return new MapperResult(sql,
        230. CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID), context.getStartRow(),
        231. context.getPageSize()));
        232. }
        233. @Override
        234. public String getDataSource() {
        235. return DataSourceConstant.HIGHGO;
        236. }
        237. }
          1. /*
          2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
          3. *
          4. * Licensed under the Apache License, Version 2.0 (the "License");
          5. * you may not use this file except in compliance with the License.
          6. * You may obtain a copy of the License at
          7. *
          8. * http://www.apache.org/licenses/LICENSE-2.0
          9. *
          10. * Unless required by applicable law or agreed to in writing, software
          11. * distributed under the License is distributed on an "AS IS" BASIS,
          12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
          13. * See the License for the specific language governing permissions and
          14. * limitations under the License.
          15. */
          16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
          17. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
          18. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
          19. import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper;
          20. import com.alibaba.nacos.plugin.datasource.model.MapperContext;
          21. import com.alibaba.nacos.plugin.datasource.model.MapperResult;
          22. import java.util.Collections;
          23. /**
          24. * The highgo implementation of ConfigInfoTagMapper.
          25. *
          26. * @Date: 2023/05/11
          27. */
          28. public class ConfigInfoTagMapperByHighgo extends AbstractMapper implements ConfigInfoTagMapper {
          29. @Override
          30. public MapperResult findAllConfigInfoTagForDumpAllFetchRows(MapperContext context) {
          31. String sql = " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified "
          32. + " FROM ( SELECT id FROM config_info_tag ORDER BY id OFFSET " + context.getStartRow() + " LIMIT "
          33. + context.getPageSize() + " ) " + "g, config_info_tag t WHERE g.id = t.id ";
          34. return new MapperResult(sql, Collections.emptyList());
          35. }
          36. @Override
          37. public String getDataSource() {
          38. return DataSourceConstant.HIGHGO;
          39. }
          40. }
          1. /*
          2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
          3. *
          4. * Licensed under the Apache License, Version 2.0 (the "License");
          5. * you may not use this file except in compliance with the License.
          6. * You may obtain a copy of the License at
          7. *
          8. * http://www.apache.org/licenses/LICENSE-2.0
          9. *
          10. * Unless required by applicable law or agreed to in writing, software
          11. * distributed under the License is distributed on an "AS IS" BASIS,
          12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
          13. * See the License for the specific language governing permissions and
          14. * limitations under the License.
          15. */
          16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
          17. import com.alibaba.nacos.common.utils.StringUtils;
          18. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
          19. import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
          20. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
          21. import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;
          22. import com.alibaba.nacos.plugin.datasource.model.MapperContext;
          23. import com.alibaba.nacos.plugin.datasource.model.MapperResult;
          24. import java.util.ArrayList;
          25. import java.util.List;
          26. /**
          27. * The highgo implementation of ConfigTagsRelationMapper.
          28. *
          29. * @Date: 2023/05/11
          30. */
          31. public class ConfigTagsRelationMapperByHighgo extends AbstractMapper implements ConfigTagsRelationMapper {
          32. @Override
          33. public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
          34. final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
          35. final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
          36. final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
          37. final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
          38. final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
          39. final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);
          40. List paramList = new ArrayList<>();
          41. StringBuilder where = new StringBuilder(" WHERE ");
          42. final String sql =
          43. "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
          44. + " config_tags_relation b ON a.id=b.id";
          45. where.append(" a.tenant_id=? ");
          46. paramList.add(tenant);
          47. if (StringUtils.isNotBlank(dataId)) {
          48. where.append(" AND a.data_id=? ");
          49. paramList.add(dataId);
          50. }
          51. if (StringUtils.isNotBlank(group)) {
          52. where.append(" AND a.group_id=? ");
          53. paramList.add(group);
          54. }
          55. if (StringUtils.isNotBlank(appName)) {
          56. where.append(" AND a.app_name=? ");
          57. paramList.add(appName);
          58. }
          59. if (!StringUtils.isBlank(content)) {
          60. where.append(" AND a.content LIKE ? ");
          61. paramList.add(content);
          62. }
          63. where.append(" AND b.tag_name IN (");
          64. for (int i = 0; i < tagArr.length; i++) {
          65. if (i != 0) {
          66. where.append(", ");
          67. }
          68. where.append('?');
          69. paramList.add(tagArr[i]);
          70. }
          71. where.append(") ");
          72. return new MapperResult(sql + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
          73. paramList);
          74. }
          75. @Override
          76. public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
          77. final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
          78. final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
          79. final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
          80. final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
          81. final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
          82. final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);
          83. List paramList = new ArrayList<>();
          84. StringBuilder where = new StringBuilder(" WHERE ");
          85. final String sqlFetchRows = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content "
          86. + "FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";
          87. where.append(" a.tenant_id LIKE ? ");
          88. paramList.add(tenant);
          89. if (!StringUtils.isBlank(dataId)) {
          90. where.append(" AND a.data_id LIKE ? ");
          91. paramList.add(dataId);
          92. }
          93. if (!StringUtils.isBlank(group)) {
          94. where.append(" AND a.group_id LIKE ? ");
          95. paramList.add(group);
          96. }
          97. if (!StringUtils.isBlank(appName)) {
          98. where.append(" AND a.app_name = ? ");
          99. paramList.add(appName);
          100. }
          101. if (!StringUtils.isBlank(content)) {
          102. where.append(" AND a.content LIKE ? ");
          103. paramList.add(content);
          104. }
          105. where.append(" AND b.tag_name IN (");
          106. for (int i = 0; i < tagArr.length; i++) {
          107. if (i != 0) {
          108. where.append(", ");
          109. }
          110. where.append('?');
          111. paramList.add(tagArr[i]);
          112. }
          113. where.append(") ");
          114. return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
          115. paramList);
          116. }
          117. @Override
          118. public String getDataSource() {
          119. return DataSourceConstant.HIGHGO;
          120. }
          121. }
            1. /*
            2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
            3. *
            4. * Licensed under the Apache License, Version 2.0 (the "License");
            5. * you may not use this file except in compliance with the License.
            6. * You may obtain a copy of the License at
            7. *
            8. * http://www.apache.org/licenses/LICENSE-2.0
            9. *
            10. * Unless required by applicable law or agreed to in writing, software
            11. * distributed under the License is distributed on an "AS IS" BASIS,
            12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            13. * See the License for the specific language governing permissions and
            14. * limitations under the License.
            15. */
            16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
            17. import com.alibaba.nacos.common.utils.CollectionUtils;
            18. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
            19. import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
            20. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
            21. import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper;
            22. import com.alibaba.nacos.plugin.datasource.model.MapperContext;
            23. import com.alibaba.nacos.plugin.datasource.model.MapperResult;
            24. /**
            25. * The highgo implementation of GroupCapacityMapper.
            26. *
            27. * @Date: 2023/05/11
            28. */
            29. public class GroupCapacityMapperByHighgo extends AbstractMapper implements GroupCapacityMapper {
            30. @Override
            31. public MapperResult selectGroupInfoBySize(MapperContext context) {
            32. String sql = "SELECT id, group_id FROM group_capacity WHERE id > ? LIMIT ?";
            33. return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize()));
            34. }
            35. @Override
            36. public String getDataSource() {
            37. return DataSourceConstant.HIGHGO;
            38. }
            39. }
            1. /*
            2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
            3. *
            4. * Licensed under the Apache License, Version 2.0 (the "License");
            5. * you may not use this file except in compliance with the License.
            6. * You may obtain a copy of the License at
            7. *
            8. * http://www.apache.org/licenses/LICENSE-2.0
            9. *
            10. * Unless required by applicable law or agreed to in writing, software
            11. * distributed under the License is distributed on an "AS IS" BASIS,
            12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            13. * See the License for the specific language governing permissions and
            14. * limitations under the License.
            15. */
            16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
            17. import com.alibaba.nacos.common.utils.CollectionUtils;
            18. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
            19. import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
            20. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
            21. import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;
            22. import com.alibaba.nacos.plugin.datasource.model.MapperContext;
            23. import com.alibaba.nacos.plugin.datasource.model.MapperResult;
            24. /**
            25. * The highgo implementation of HistoryConfigInfoMapper.
            26. *
            27. * @Date: 2023/05/11
            28. */
            29. public class HistoryConfigInfoMapperByHighgo extends AbstractMapper implements HistoryConfigInfoMapper {
            30. @Override
            31. public MapperResult removeConfigHistory(MapperContext context) {
            32. String sql = "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?";
            33. return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.START_TIME),
            34. context.getWhereParameter(FieldConstant.LIMIT_SIZE)));
            35. }
            36. @Override
            37. public MapperResult pageFindConfigHistoryFetchRows(MapperContext context) {
            38. String sql =
            39. "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
            40. + "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC OFFSET "
            41. + context.getStartRow() + " LIMIT " + context.getPageSize();
            42. return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.DATA_ID),
            43. context.getWhereParameter(FieldConstant.GROUP_ID), context.getWhereParameter(FieldConstant.TENANT_ID)));
            44. }
            45. @Override
            46. public String getDataSource() {
            47. return DataSourceConstant.HIGHGO;
            48. }
            49. }
            1. /*
            2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
            3. *
            4. * Licensed under the Apache License, Version 2.0 (the "License");
            5. * you may not use this file except in compliance with the License.
            6. * You may obtain a copy of the License at
            7. *
            8. * http://www.apache.org/licenses/LICENSE-2.0
            9. *
            10. * Unless required by applicable law or agreed to in writing, software
            11. * distributed under the License is distributed on an "AS IS" BASIS,
            12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            13. * See the License for the specific language governing permissions and
            14. * limitations under the License.
            15. */
            16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
            17. import com.alibaba.nacos.common.utils.CollectionUtils;
            18. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
            19. import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
            20. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
            21. import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper;
            22. import com.alibaba.nacos.plugin.datasource.model.MapperContext;
            23. import com.alibaba.nacos.plugin.datasource.model.MapperResult;
            24. /**
            25. * The highgo implementation of TenantCapacityMapper.
            26. *
            27. * @Date: 2023/05/11
            28. */
            29. public class TenantCapacityMapperByHighgo extends AbstractMapper implements TenantCapacityMapper {
            30. @Override
            31. public MapperResult getCapacityList4CorrectUsage(MapperContext context) {
            32. String sql = "SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ?";
            33. return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID),
            34. context.getWhereParameter(FieldConstant.LIMIT_SIZE)));
            35. }
            36. @Override
            37. public String getDataSource() {
            38. return DataSourceConstant.HIGHGO;
            39. }
            40. }
            1. /*
            2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
            3. *
            4. * Licensed under the Apache License, Version 2.0 (the "License");
            5. * you may not use this file except in compliance with the License.
            6. * You may obtain a copy of the License at
            7. *
            8. * http://www.apache.org/licenses/LICENSE-2.0
            9. *
            10. * Unless required by applicable law or agreed to in writing, software
            11. * distributed under the License is distributed on an "AS IS" BASIS,
            12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            13. * See the License for the specific language governing permissions and
            14. * limitations under the License.
            15. */
            16. package com.alibaba.nacos.plugin.datasource.impl.highgo;
            17. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
            18. import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
            19. import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper;
            20. /**
            21. * The highgo implementation of TenantInfoMapper.
            22. *
            23. * @Date: 2023/05/11
            24. */
            25. public class TenantInfoMapperByHighgo extends AbstractMapper implements TenantInfoMapper {
            26. @Override
            27. public String getDataSource() {
            28. return DataSourceConstant.HIGHGO;
            29. }
            30. }
            com.alibaba.nacos.plugin.datasource.mapper.Mapper文件
            1. plugin/datasource/src/main/resources/META-INF/services
            2. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql
            3. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql
            4. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql
            5. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql
            6. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql
            7. com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql
            8. com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql
            9. com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql
            10. com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql
            11. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby
            12. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby
            13. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby
            14. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby
            15. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagsRelationMapperByDerby
            16. com.alibaba.nacos.plugin.datasource.impl.derby.HistoryConfigInfoMapperByDerby
            17. com.alibaba.nacos.plugin.datasource.impl.derby.TenantInfoMapperByDerby
            18. com.alibaba.nacos.plugin.datasource.impl.derby.TenantCapacityMapperByDerby
            19. com.alibaba.nacos.plugin.datasource.impl.derby.GroupCapacityMapperByDerby
            20. -- 新增highgo
            21. com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoAggrMapperByHighgo
            22. com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoBetaMapperByHighgo
            23. com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoMapperByHighgo
            24. com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoTagMapperByHighgo
            25. com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigTagsRelationMapperByHighgo
            26. com.alibaba.nacos.plugin.datasource.impl.highgo.HistoryConfigInfoMapperByHighgo
            27. com.alibaba.nacos.plugin.datasource.impl.highgo.TenantInfoMapperByHighgo
            28. com.alibaba.nacos.plugin.datasource.impl.highgo.TenantCapacityMapperByHighgo
            29. com.alibaba.nacos.plugin.datasource.impl.highgo.GroupCapacityMapperByHighgo

            5、修改nacos-console模块

            瀚高数据库 需要添加  currentSchema=nacos_config   否则连不上数据库

            1. console/src/main/resources/application.properties
            2. spring.sql.init.platform=highgo
            3. db.num=1
            4. db.url.0=jdbc:highgo://xxxx:5866/nacos_config?currentSchema=nacos_config&characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
            5. db.user.0=nacos
            6. db.password.0=nacos
            7. db.pool.config.driverClassName=com.highgo.jdbc.Driver

             6、单机启动  

            启动的时候添加 -Dnacos.standalone=true 参数来表明我们是单机启动的

            7、打包 

            1. mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true clean install -U
            2. 在nacos-2.2.0\distribution\target下生成压缩文件,可直接使用

            8、适配ARM架构

            8.1下载源码以及build/Dockerfile.Slim 对应的镜像
            1. 找到对应版本的nacos-docker
            2. https://github.com/nacos-group/nacos-docker/tree/v2.3.1

            1. 下载对应的镜像
            2. https://hub.docker.com/_/buildpack-deps/tags?page=&page_size=&ordering=&name=buster-curl
            3. https://hub.docker.com/r/adoptopenjdk/openjdk8/tags?page=2&page_size=&name=jre8u372-b07&ordering=

             

             8.2 在naocs源码的根目录增加二个文件 方便修改后打包直接上次镜像
            1. """
            2. /*
            3. * Copyright 1999-2021 Alibaba Group Holding Ltd.
            4. *
            5. * Licensed under the Apache License, Version 2.0 (the "License");
            6. * you may not use this file except in compliance with the License.
            7. * You may obtain a copy of the License at
            8. *
            9. * http://www.apache.org/licenses/LICENSE-2.0
            10. *
            11. * Unless required by applicable law or agreed to in writing, software
            12. * distributed under the License is distributed on an "AS IS" BASIS,
            13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            14. * See the License for the specific language governing permissions and
            15. * limitations under the License.
            16. */
            17. """
            18. pipeline {
            19. agent {
            20. docker {
            21. image 'reg.xxx.com/library/arm64/maven-arm64:3.5.3'
            22. args '-v /root/.m2:/root/.m2 -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/kubectl:/usr/bin/kubectl'
            23. label 'arm64'
            24. }
            25. }
            26. stages {
            27. stage('build') {
            28. steps {
            29. sh 'mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true clean install -U'
            30. }
            31. }
            32. stage('deploy') {
            33. steps {
            34. withCredentials([usernamePassword(credentialsId: 'harbor-xxx', passwordVariable: 'HPASSWD', usernameVariable: 'HUSER')]) {
            35. sh '''
            36. docker build -f Dockerfile_arm -t reg.xxx.com/dev/arm64/nacos-arm64-linux:2.3.1 .
            37. docker login reg.sdses.com -u $HUSER -p $HPASSWD
            38. docker push reg.xxx.com/dev/arm64/nacos-arm64-linux:2.3.1
            39. '''
            40. }
            41. }
            42. }
            43. }
            44. }

            dockerFile

            1. #
            2. # Copyright 1999-2021 Alibaba Group Holding Ltd.
            3. #
            4. # Licensed under the Apache License, Version 2.0 (the "License");
            5. # you may not use this file except in compliance with the License.
            6. # You may obtain a copy of the License at
            7. #
            8. # http://www.apache.org/licenses/LICENSE-2.0
            9. #
            10. # Unless required by applicable law or agreed to in writing, software
            11. # distributed under the License is distributed on an "AS IS" BASIS,
            12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            13. # See the License for the specific language governing permissions and
            14. # limitations under the License.
            15. #
            16. FROM reg.xxx.com/library/arm64/buildpack-deps:buster-curl as installer
            17. ARG NACOS_VERSION=2.3.1
            18. ARG HOT_FIX_FLAG=""
            19. COPY distribution/target/nacos-server-2.3.1.tar.gz /var/tmp/
            20. RUN tar -xzvf /var/tmp/nacos-server-2.3.1.tar.gz -C /home/
            21. FROM reg.xxx.com/library/arm64/nacos/openjdk8:jre8u372-b07
            22. # set environment
            23. ENV MODE="cluster" \
            24. PREFER_HOST_MODE="ip"\
            25. BASE_DIR="/home/nacos" \
            26. CLASSPATH=".:/home/nacos/conf:$CLASSPATH" \
            27. CLUSTER_CONF="/home/nacos/conf/cluster.conf" \
            28. FUNCTION_MODE="all" \
            29. NACOS_USER="nacos" \
            30. JAVA="/opt/java/openjdk/bin/java" \
            31. JVM_XMS="1g" \
            32. JVM_XMX="1g" \
            33. JVM_XMN="512m" \
            34. JVM_MS="128m" \
            35. JVM_MMS="320m" \
            36. NACOS_DEBUG="n" \
            37. TOMCAT_ACCESSLOG_ENABLED="false" \
            38. TZ="Asia/Shanghai"
            39. WORKDIR $BASE_DIR
            40. # copy nacos bin
            41. COPY --from=installer ["/home/nacos", "/home/nacos"]
            42. ADD build/bin/docker-startup.sh bin/docker-startup.sh
            43. #ADD conf/application.properties conf/application.properties
            44. # set startup log dir
            45. RUN mkdir -p logs \
            46. && cd logs \
            47. && touch start.out \
            48. && ln -sf /dev/stdout start.out \
            49. && ln -sf /dev/stderr start.out
            50. RUN chmod +x bin/docker-startup.sh
            51. EXPOSE 8848
            52. ENTRYPOINT ["bin/docker-startup.sh"]

          122. 相关阅读:
            OpenCV(三十八):二维码检测
            携创教育:自考本科和成考本科区别在哪?本科自考和成考哪个含金量高点?
            2023最新SSM计算机毕业设计选题大全(附源码+LW)之java新能源汽车销售管理系统gooct
            ChatGPT被曝测试新功能:学习所有历史聊天,还能重置记忆、“阅后即焚”
            最全高并发学习笔记,收藏起来
            Redis学习笔记--002
            Archlinux Gnome上解决N卡驱动安装和IBUS输入法两个小问题记录
            Machine learning week 10(Andrew Ng)
            Npm 工具完全删除 - 安装 npm多版本管理工具 nvm
            ZYNQ之FPGA学习----IIC协议驱动模块仿真实验
          123. 原文地址:https://blog.csdn.net/duanyuanjun/article/details/140443827