下载nacos源码: https://github.com/alibaba/nacos/tree/2.3.1
瀚高技术文档
1、修改pom.xml
根目录nacos-all => pom.xml<dependencyManagement><dependency><groupId>com.highgo</groupId><artifactId>HgdbJdbc</artifactId><version>6.2.3</version></dependency></dependencyManagement>.nacos-config模块 => pom.xml
<dependency><groupId>com.highgo</groupId><artifactId>HgdbJdbc</artifactId>
</dependency>
2、修改nacos-config模块 连接驱动 ExternalDataSourceProperties
com.alibaba.nacos.persistence.datasource.ExternalDataSourcePropertiesprivate static final String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
修改为:
private static final String JDBC_DRIVER_NAME = "com.highgo.jdbc.Driver";
3、nacos-datasource-plugin模块增加支持的数据库类型
com.alibaba.nacos.plugin.datasource.constants.DataSourceConstantpublic class DataSourceConstant {public static final String MYSQL = "mysql";public static final String DERBY = "derby";public static final String HIGHGO = "highgo";
}
4、 根据SPI机制进行代码扩展
ConfigInfoAggrMapperByHighgo
ConfigInfoBetaMapperByHighgo
ConfigInfoMapperByHighgo
ConfigInfoTagMapperByHighgo
ConfigTagsRelationMapperByHighgo
GroupCapacityMapperByHighgo
HistoryConfigInfoMapperByHighgo
TenantCapacityMapperByHighgo
TenantInfoMapperByHighgo
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;import java.util.List;/*** The highgo implementation of ConfigInfoAggrMapper.** @Date: 2023/05/11*/
public class ConfigInfoAggrMapperByHighgo extends AbstractMapper implements ConfigInfoAggrMapper {@Overridepublic MapperResult findConfigInfoAggrByPageFetchRows(MapperContext context) {int startRow = context.getStartRow();int pageSize = context.getPageSize();String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);String groupId = (String) context.getWhereParameter(FieldConstant.GROUP_ID);String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);String sql ="SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "+ " group_id= ? AND tenant_id= ? ORDER BY datum_id " + " OFFSET " + startRow + " LIMIT " + pageSize;List<Object> paramList = CollectionUtils.list(dataId, groupId, tenantId);return new MapperResult(sql, paramList);}@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}
}
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;import java.util.ArrayList;
import java.util.List;/*** The highgo implementation of ConfigInfoBetaMapper.** @Date: 2023/05/11*/
public class ConfigInfoBetaMapperByHighgo extends AbstractMapper implements ConfigInfoBetaMapper {@Overridepublic MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext context) {int startRow = context.getStartRow();int pageSize = context.getPageSize();String sql = " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "+ " FROM ( SELECT id FROM config_info_beta ORDER BY id OFFSET " + startRow + " LIMIT " + pageSize + ")"+ " g, config_info_beta t WHERE g.id = t.id ";List<Object> paramList = new ArrayList<>();paramList.add(startRow);paramList.add(pageSize);return new MapperResult(sql, paramList);}@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}
}
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.plugin.datasource.constants.ContextConstant;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;/*** The highgo implementation of ConfigInfoMapper.** @Date: 2023/05/11*/
public class ConfigInfoMapperByHighgo extends AbstractMapper implements ConfigInfoMapper {private static final String DATA_ID = "dataId";private static final String GROUP = "group";private static final String APP_NAME = "appName";private static final String CONTENT = "content";private static final String TENANT = "tenant";@Overridepublic MapperResult findConfigInfoByAppFetchRows(MapperContext context) {final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info"+ " WHERE tenant_id LIKE ? AND app_name= ?" + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize();return new MapperResult(sql, CollectionUtils.list(tenantId, appName));}@Overridepublic MapperResult getTenantIdList(MapperContext context) {String sql = "SELECT tenant_id FROM config_info WHERE tenant_id != '" + NamespaceUtil.getNamespaceDefaultId()+ "' GROUP BY tenant_id OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize();return new MapperResult(sql, Collections.emptyList());}@Overridepublic MapperResult getGroupIdList(MapperContext context) {String sql = "SELECT group_id FROM config_info WHERE tenant_id ='" + NamespaceUtil.getNamespaceDefaultId()+ "' GROUP BY group_id OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize();return new MapperResult(sql, Collections.emptyList());}@Overridepublic MapperResult findAllConfigKey(MapperContext context) {String sql = " SELECT data_id,group_id,app_name FROM ( "+ " SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id OFFSET " + context.getStartRow() + " LIMIT "+ context.getPageSize() + " )" + " g, config_info t WHERE g.id = t.id ";return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID)));}@Overridepublic MapperResult findAllConfigInfoBaseFetchRows(MapperContext context) {String sql = "SELECT t.id,data_id,group_id,content,md5"+ " FROM ( SELECT id FROM config_info ORDER BY id OFFSET ? LIMIT ? ) "+ " g, config_info t WHERE g.id = t.id ";return new MapperResult(sql, Collections.emptyList());}@Overridepublic MapperResult findAllConfigInfoFragment(MapperContext context) {String contextParameter = context.getContextParameter(ContextConstant.NEED_CONTENT);boolean needContent = contextParameter != null && Boolean.parseBoolean(contextParameter);String sql = "SELECT id,data_id,group_id,tenant_id,app_name," + (needContent ? "content," : "")+ "md5,gmt_modified,type,encrypted_data_key FROM config_info WHERE id > ? ORDER BY id ASC OFFSET "+ context.getStartRow() + " LIMIT " + context.getPageSize();return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID)));}@Overridepublic MapperResult findChangeConfigFetchRows(MapperContext context) {final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);final String tenantTmp = com.alibaba.nacos.common.utils.StringUtils.isBlank(tenant)? com.alibaba.nacos.common.utils.StringUtils.EMPTY : tenant;final Timestamp startTime = (Timestamp) context.getWhereParameter(FieldConstant.START_TIME);final Timestamp endTime = (Timestamp) context.getWhereParameter(FieldConstant.END_TIME);List<Object> paramList = new ArrayList<>();final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,type,md5,gmt_modified FROM config_info WHERE ";String where = " 1=1 ";if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(dataId)) {where += " AND data_id LIKE ? ";paramList.add(dataId);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(group)) {where += " AND group_id LIKE ? ";paramList.add(group);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(tenantTmp)) {where += " AND tenant_id = ? ";paramList.add(tenantTmp);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(appName)) {where += " AND app_name = ? ";paramList.add(appName);}if (startTime != null) {where += " AND gmt_modified >=? ";paramList.add(startTime);}if (endTime != null) {where += " AND gmt_modified <=? ";paramList.add(endTime);}return new MapperResult(sqlFetchRows + where + " AND id > " + context.getWhereParameter(FieldConstant.LAST_MAX_ID)+ " ORDER BY id ASC" + " OFFSET " + 0 + " LIMIT " + context.getPageSize(), paramList);}@Overridepublic MapperResult listGroupKeyMd5ByPageFetchRows(MapperContext context) {String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "+ "( SELECT id FROM config_info ORDER BY id OFFSET " + context.getStartRow() + " LIMIT "+ context.getPageSize() + " ) g, config_info t WHERE g.id = t.id";return new MapperResult(sql, Collections.emptyList());}@Overridepublic MapperResult findConfigInfoBaseLikeFetchRows(MapperContext context) {final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";String where = " 1=1 AND tenant_id='" + NamespaceUtil.getNamespaceDefaultId() + "' ";List<Object> paramList = new ArrayList<>();if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(dataId)) {where += " AND data_id LIKE ? ";paramList.add(dataId);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(group)) {where += " AND group_id LIKE ";paramList.add(group);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(content)) {where += " AND content LIKE ? ";paramList.add(content);}return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),paramList);}@Overridepublic MapperResult findConfigInfo4PageFetchRows(MapperContext context) {final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);List<Object> paramList = new ArrayList<>();final String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info";StringBuilder where = new StringBuilder(" WHERE ");where.append(" tenant_id=? ");paramList.add(tenant);if (com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dataId)) {where.append(" AND data_id=? ");paramList.add(dataId);}if (com.alibaba.nacos.common.utils.StringUtils.isNotBlank(group)) {where.append(" AND group_id=? ");paramList.add(group);}if (com.alibaba.nacos.common.utils.StringUtils.isNotBlank(appName)) {where.append(" AND app_name=? ");paramList.add(appName);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(content)) {where.append(" AND content LIKE ? ");paramList.add(content);}return new MapperResult(sql + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),paramList);}@Overridepublic MapperResult findConfigInfoBaseByGroupFetchRows(MapperContext context) {String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=?" + " OFFSET "+ context.getStartRow() + " LIMIT " + context.getPageSize();return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.GROUP_ID),context.getWhereParameter(FieldConstant.TENANT_ID)));}@Overridepublic MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);List<Object> paramList = new ArrayList<>();final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info";StringBuilder where = new StringBuilder(" WHERE ");where.append(" tenant_id LIKE ? ");paramList.add(tenant);if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(dataId)) {where.append(" AND data_id LIKE ? ");paramList.add(dataId);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(group)) {where.append(" AND group_id LIKE ? ");paramList.add(group);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(appName)) {where.append(" AND app_name = ? ");paramList.add(appName);}if (!com.alibaba.nacos.common.utils.StringUtils.isBlank(content)) {where.append(" AND content LIKE ? ");paramList.add(content);}return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),paramList);}@Overridepublic MapperResult findAllConfigInfoFetchRows(MapperContext context) {String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "+ " FROM ( SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id OFFSET ? LIMIT ? )"+ " g, config_info t WHERE g.id = t.id ";return new MapperResult(sql,CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID), context.getStartRow(),context.getPageSize()));}@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}}
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;import java.util.Collections;/*** The highgo implementation of ConfigInfoTagMapper.** @Date: 2023/05/11*/
public class ConfigInfoTagMapperByHighgo extends AbstractMapper implements ConfigInfoTagMapper {@Overridepublic MapperResult findAllConfigInfoTagForDumpAllFetchRows(MapperContext context) {String sql = " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified "+ " FROM ( SELECT id FROM config_info_tag ORDER BY id OFFSET " + context.getStartRow() + " LIMIT "+ context.getPageSize() + " ) " + "g, config_info_tag t WHERE g.id = t.id ";return new MapperResult(sql, Collections.emptyList());}@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}
}
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;import java.util.ArrayList;
import java.util.List;/*** The highgo implementation of ConfigTagsRelationMapper.** @Date: 2023/05/11*/
public class ConfigTagsRelationMapperByHighgo extends AbstractMapper implements ConfigTagsRelationMapper {@Overridepublic MapperResult findConfigInfo4PageFetchRows(MapperContext context) {final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);List<Object> paramList = new ArrayList<>();StringBuilder where = new StringBuilder(" WHERE ");final String sql ="SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "+ " config_tags_relation b ON a.id=b.id";where.append(" a.tenant_id=? ");paramList.add(tenant);if (StringUtils.isNotBlank(dataId)) {where.append(" AND a.data_id=? ");paramList.add(dataId);}if (StringUtils.isNotBlank(group)) {where.append(" AND a.group_id=? ");paramList.add(group);}if (StringUtils.isNotBlank(appName)) {where.append(" AND a.app_name=? ");paramList.add(appName);}if (!StringUtils.isBlank(content)) {where.append(" AND a.content LIKE ? ");paramList.add(content);}where.append(" AND b.tag_name IN (");for (int i = 0; i < tagArr.length; i++) {if (i != 0) {where.append(", ");}where.append('?');paramList.add(tagArr[i]);}where.append(") ");return new MapperResult(sql + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),paramList);}@Overridepublic MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);List<Object> paramList = new ArrayList<>();StringBuilder where = new StringBuilder(" WHERE ");final String sqlFetchRows = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content "+ "FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";where.append(" a.tenant_id LIKE ? ");paramList.add(tenant);if (!StringUtils.isBlank(dataId)) {where.append(" AND a.data_id LIKE ? ");paramList.add(dataId);}if (!StringUtils.isBlank(group)) {where.append(" AND a.group_id LIKE ? ");paramList.add(group);}if (!StringUtils.isBlank(appName)) {where.append(" AND a.app_name = ? ");paramList.add(appName);}if (!StringUtils.isBlank(content)) {where.append(" AND a.content LIKE ? ");paramList.add(content);}where.append(" AND b.tag_name IN (");for (int i = 0; i < tagArr.length; i++) {if (i != 0) {where.append(", ");}where.append('?');paramList.add(tagArr[i]);}where.append(") ");return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),paramList);}@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}
}
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;/*** The highgo implementation of GroupCapacityMapper.** @Date: 2023/05/11*/
public class GroupCapacityMapperByHighgo extends AbstractMapper implements GroupCapacityMapper {@Overridepublic MapperResult selectGroupInfoBySize(MapperContext context) {String sql = "SELECT id, group_id FROM group_capacity WHERE id > ? LIMIT ?";return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize()));}@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}
}
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;/*** The highgo implementation of HistoryConfigInfoMapper.** @Date: 2023/05/11*/
public class HistoryConfigInfoMapperByHighgo extends AbstractMapper implements HistoryConfigInfoMapper {@Overridepublic MapperResult removeConfigHistory(MapperContext context) {String sql = "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?";return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.START_TIME),context.getWhereParameter(FieldConstant.LIMIT_SIZE)));}@Overridepublic MapperResult pageFindConfigHistoryFetchRows(MapperContext context) {String sql ="SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC OFFSET "+ context.getStartRow() + " LIMIT " + context.getPageSize();return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.DATA_ID),context.getWhereParameter(FieldConstant.GROUP_ID), context.getWhereParameter(FieldConstant.TENANT_ID)));}@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}
}
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;/*** The highgo implementation of TenantCapacityMapper.** @Date: 2023/05/11*/
public class TenantCapacityMapperByHighgo extends AbstractMapper implements TenantCapacityMapper {@Overridepublic MapperResult getCapacityList4CorrectUsage(MapperContext context) {String sql = "SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ?";return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID),context.getWhereParameter(FieldConstant.LIMIT_SIZE)));}@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}
}
/** Copyright 1999-2022 Alibaba Group Holding Ltd.** Licensed 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 com.alibaba.nacos.plugin.datasource.impl.highgo;import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper;/*** The highgo implementation of TenantInfoMapper.** @Date: 2023/05/11*/
public class TenantInfoMapperByHighgo extends AbstractMapper implements TenantInfoMapper {@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}
}
com.alibaba.nacos.plugin.datasource.mapper.Mapper文件
plugin/datasource/src/main/resources/META-INF/servicescom.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysqlcom.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagsRelationMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.HistoryConfigInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.TenantInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.TenantCapacityMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.GroupCapacityMapperByDerby-- 新增highgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoAggrMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoBetaMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoTagMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigTagsRelationMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.HistoryConfigInfoMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.TenantInfoMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.TenantCapacityMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.GroupCapacityMapperByHighgo
5、修改nacos-console模块
瀚高数据库 需要添加 currentSchema=nacos_config 否则连不上数据库
console/src/main/resources/application.propertiesspring.sql.init.platform=highgo
db.num=1
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
db.user.0=nacos
db.password.0=nacos
db.pool.config.driverClassName=com.highgo.jdbc.Driver
6、单机启动
启动的时候添加 -Dnacos.standalone=true 参数来表明我们是单机启动的
7、打包
mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true clean install -U在nacos-2.2.0\distribution\target下生成压缩文件,可直接使用
8、适配ARM架构
8.1下载源码以及build/Dockerfile.Slim 对应的镜像
找到对应版本的nacos-dockerhttps://github.com/nacos-group/nacos-docker/tree/v2.3.1
下载对应的镜像
https://hub.docker.com/_/buildpack-deps/tags?page=&page_size=&ordering=&name=buster-curlhttps://hub.docker.com/r/adoptopenjdk/openjdk8/tags?page=2&page_size=&name=jre8u372-b07&ordering=
8.2 在naocs源码的根目录增加二个文件 方便修改后打包直接上次镜像
"""
/** Copyright 1999-2021 Alibaba Group Holding Ltd.** Licensed 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.*/
"""
pipeline {agent {docker {image 'reg.xxx.com/library/arm64/maven-arm64:3.5.3'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'label 'arm64'}}stages {stage('build') {steps {sh 'mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true clean install -U'}}stage('deploy') {steps {withCredentials([usernamePassword(credentialsId: 'harbor-xxx', passwordVariable: 'HPASSWD', usernameVariable: 'HUSER')]) {sh '''docker build -f Dockerfile_arm -t reg.xxx.com/dev/arm64/nacos-arm64-linux:2.3.1 .docker login reg.sdses.com -u $HUSER -p $HPASSWDdocker push reg.xxx.com/dev/arm64/nacos-arm64-linux:2.3.1'''}}}}
}
dockerFile
#
# Copyright 1999-2021 Alibaba Group Holding Ltd.
#
# Licensed 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.
#FROM reg.xxx.com/library/arm64/buildpack-deps:buster-curl as installerARG NACOS_VERSION=2.3.1
ARG HOT_FIX_FLAG=""COPY distribution/target/nacos-server-2.3.1.tar.gz /var/tmp/RUN tar -xzvf /var/tmp/nacos-server-2.3.1.tar.gz -C /home/FROM reg.xxx.com/library/arm64/nacos/openjdk8:jre8u372-b07# set environment
ENV MODE="cluster" \PREFER_HOST_MODE="ip"\BASE_DIR="/home/nacos" \CLASSPATH=".:/home/nacos/conf:$CLASSPATH" \CLUSTER_CONF="/home/nacos/conf/cluster.conf" \FUNCTION_MODE="all" \NACOS_USER="nacos" \JAVA="/opt/java/openjdk/bin/java" \JVM_XMS="1g" \JVM_XMX="1g" \JVM_XMN="512m" \JVM_MS="128m" \JVM_MMS="320m" \NACOS_DEBUG="n" \TOMCAT_ACCESSLOG_ENABLED="false" \TZ="Asia/Shanghai"WORKDIR $BASE_DIR# copy nacos bin
COPY --from=installer ["/home/nacos", "/home/nacos"]ADD build/bin/docker-startup.sh bin/docker-startup.sh
#ADD conf/application.properties conf/application.properties# set startup log dir
RUN mkdir -p logs \&& cd logs \&& touch start.out \&& ln -sf /dev/stdout start.out \&& ln -sf /dev/stderr start.out
RUN chmod +x bin/docker-startup.shEXPOSE 8848
ENTRYPOINT ["bin/docker-startup.sh"]