diff --git a/auth/pom.xml b/auth/pom.xml
index 5f70b6263..b1cf74cda 100644
--- a/auth/pom.xml
+++ b/auth/pom.xml
@@ -71,6 +71,11 @@
tomcat-embed-core
+
+ org.apache.derby
+ derby
+
+
io.jsonwebtoken
jjwt-api
@@ -80,6 +85,7 @@
jjwt-impl
runtime
+
io.jsonwebtoken
jjwt-jackson
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/configuration/ConditionOnEmbeddedStorage.java b/auth/src/main/java/com/alibaba/nacos/auth/configuration/ConditionOnEmbeddedStorage.java
new file mode 100644
index 000000000..31c890402
--- /dev/null
+++ b/auth/src/main/java/com/alibaba/nacos/auth/configuration/ConditionOnEmbeddedStorage.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 1999-2018 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.auth.configuration;
+
+import com.alibaba.nacos.auth.util.AuthPropertyUtil;
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+/**
+ * Judge whether to user EmbeddedStorage by condition.
+ *
+ * @author liaochuntao
+ */
+public class ConditionOnEmbeddedStorage implements Condition {
+
+ @Override
+ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ return AuthPropertyUtil.isEmbeddedStorage();
+ }
+}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/configuration/ConditionStandaloneEmbedStorage.java b/auth/src/main/java/com/alibaba/nacos/auth/configuration/ConditionStandaloneEmbedStorage.java
new file mode 100644
index 000000000..3bcfefc60
--- /dev/null
+++ b/auth/src/main/java/com/alibaba/nacos/auth/configuration/ConditionStandaloneEmbedStorage.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 1999-2018 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.auth.configuration;
+
+import com.alibaba.nacos.auth.util.AuthPropertyUtil;
+import com.alibaba.nacos.sys.env.EnvUtil;
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+/**
+ * Judge whether to user StandaloneEmbedStorage by condition.
+ * When embeddedStorage==false.
+ *
+ * @author liaochuntao
+ */
+public class ConditionStandaloneEmbedStorage implements Condition {
+
+ @Override
+ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ return AuthPropertyUtil.isEmbeddedStorage() && EnvUtil.getStandaloneMode();
+ }
+}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedPermissionPersistServiceImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedPermissionPersistServiceImpl.java
new file mode 100644
index 000000000..8a4d27700
--- /dev/null
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedPermissionPersistServiceImpl.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 1999-2018 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.auth.persist;
+
+import com.alibaba.nacos.auth.configuration.ConditionOnEmbeddedStorage;
+import com.alibaba.nacos.auth.model.Page;
+import com.alibaba.nacos.auth.model.PermissionInfo;
+import com.alibaba.nacos.auth.persist.repository.PaginationHelper;
+import com.alibaba.nacos.auth.persist.repository.embedded.DatabaseOperate;
+import com.alibaba.nacos.auth.persist.repository.embedded.AuthEmbeddedStoragePersistServiceImpl;
+import com.alibaba.nacos.common.utils.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * There is no self-augmented primary key.
+ *
+ * @author liaochuntao
+ */
+@Conditional(value = ConditionOnEmbeddedStorage.class)
+@Component
+public class AuthEmbeddedPermissionPersistServiceImpl implements PermissionPersistService {
+
+ public static final PermissionRowMapper PERMISSION_ROW_MAPPER = new PermissionRowMapper();
+
+ @Autowired
+ private DatabaseOperate databaseOperate;
+
+ @Autowired
+ private AuthEmbeddedStoragePersistServiceImpl persistService;
+
+ @Override
+ public Page getPermissions(String role, int pageNo, int pageSize) {
+ PaginationHelper helper = persistService.createPaginationHelper();
+
+ String sqlCountRows = "SELECT count(*) FROM permissions WHERE ";
+
+ String sqlFetchRows = "SELECT role,resource,action FROM permissions WHERE ";
+
+ String where = " role= ? ";
+ List params = new ArrayList<>();
+ if (StringUtils.isNotBlank(role)) {
+ params = Collections.singletonList(role);
+ } else {
+ where = " 1=1 ";
+ }
+
+ Page pageInfo = helper
+ .fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), pageNo,
+ pageSize, PERMISSION_ROW_MAPPER);
+
+ if (pageInfo == null) {
+ pageInfo = new Page<>();
+ pageInfo.setTotalCount(0);
+ pageInfo.setPageItems(new ArrayList<>());
+ }
+ return pageInfo;
+ }
+
+ public static final class PermissionRowMapper implements RowMapper {
+
+ @Override
+ public PermissionInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
+ PermissionInfo info = new PermissionInfo();
+ info.setResource(rs.getString("resource"));
+ info.setAction(rs.getString("action"));
+ info.setRole(rs.getString("role"));
+ return info;
+ }
+ }
+
+}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedRolePersistServiceImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedRolePersistServiceImpl.java
new file mode 100644
index 000000000..91ddef0a0
--- /dev/null
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedRolePersistServiceImpl.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 1999-2018 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.auth.persist;
+
+import com.alibaba.nacos.auth.configuration.ConditionOnEmbeddedStorage;
+import com.alibaba.nacos.auth.model.Page;
+import com.alibaba.nacos.auth.persist.repository.PaginationHelper;
+import com.alibaba.nacos.auth.persist.repository.embedded.DatabaseOperate;
+import com.alibaba.nacos.auth.persist.repository.embedded.AuthEmbeddedStoragePersistServiceImpl;
+import com.alibaba.nacos.auth.roles.RoleInfo;
+import com.alibaba.nacos.common.utils.StringUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+
+/**
+ * There is no self-augmented primary key.
+ *
+ * @author liaochuntao
+ */
+@Conditional(value = ConditionOnEmbeddedStorage.class)
+@Component
+public class AuthEmbeddedRolePersistServiceImpl implements RolePersistService {
+
+ @Autowired
+ private DatabaseOperate databaseOperate;
+
+ @Autowired
+ private AuthEmbeddedStoragePersistServiceImpl persistService;
+
+ public static final RoleInfoRowMapper ROLE_INFO_ROW_MAPPER = new RoleInfoRowMapper();
+
+ @Override
+ public Page getRolesByUserName(String username, int pageNo, int pageSize) {
+
+ PaginationHelper helper = persistService.createPaginationHelper();
+
+ String sqlCountRows = "SELECT count(*) FROM roles WHERE ";
+
+ String sqlFetchRows = "SELECT role,username FROM roles WHERE ";
+
+ String where = " username= ? ";
+ List params = new ArrayList<>();
+ if (StringUtils.isNotBlank(username)) {
+ params = Collections.singletonList(username);
+ } else {
+ where = " 1=1 ";
+ }
+
+ return helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), pageNo,
+ pageSize, ROLE_INFO_ROW_MAPPER);
+
+ }
+
+ public static final class RoleInfoRowMapper implements RowMapper {
+
+ @Override
+ public RoleInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
+ RoleInfo roleInfo = new RoleInfo();
+ roleInfo.setRole(rs.getString("role"));
+ roleInfo.setUsername(rs.getString("username"));
+ return roleInfo;
+ }
+ }
+
+}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedUserPersistServiceImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedUserPersistServiceImpl.java
new file mode 100644
index 000000000..e11d73ae7
--- /dev/null
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthEmbeddedUserPersistServiceImpl.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 1999-2018 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.auth.persist;
+
+import com.alibaba.nacos.auth.configuration.ConditionOnEmbeddedStorage;
+import com.alibaba.nacos.auth.model.Page;
+import com.alibaba.nacos.auth.persist.repository.PaginationHelper;
+import com.alibaba.nacos.auth.persist.repository.embedded.DatabaseOperate;
+import com.alibaba.nacos.auth.persist.repository.embedded.AuthEmbeddedStoragePersistServiceImpl;
+import com.alibaba.nacos.auth.persist.sql.EmbeddedStorageContextUtils;
+import com.alibaba.nacos.auth.users.User;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+/**
+ * There is no self-augmented primary key.
+ *
+ * @author liaochuntao
+ */
+@Conditional(value = ConditionOnEmbeddedStorage.class)
+@Component
+public class AuthEmbeddedUserPersistServiceImpl implements UserPersistService {
+
+ public static final RowMapper USER_ROW_MAPPER = new UserRowMapper();
+
+ @Autowired
+ private DatabaseOperate databaseOperate;
+
+ @Autowired
+ private AuthEmbeddedStoragePersistServiceImpl persistService;
+
+ @Override
+ public User findUserByUsername(String username) {
+ String sql = "SELECT username,password FROM users WHERE username=? ";
+ return databaseOperate.queryOne(sql, new Object[] {username}, USER_ROW_MAPPER);
+ }
+
+ /**
+ * Execute create user operation.
+ *
+ * @param username username string value.
+ * @param password password string value.
+ */
+ @Override
+ public void createUser(String username, String password) {
+ String sql = "INSERT INTO users (username, password, enabled) VALUES (?, ?, ?)";
+
+ try {
+ EmbeddedStorageContextUtils.addSqlContext(sql, username, password, true);
+ databaseOperate.blockUpdate();
+ } finally {
+ EmbeddedStorageContextUtils.cleanAllContext();
+ }
+ }
+
+ @Override
+ public Page getUsers(int pageNo, int pageSize) {
+
+ PaginationHelper helper = persistService.createPaginationHelper();
+
+ String sqlCountRows = "SELECT count(*) FROM users WHERE ";
+
+ String sqlFetchRows = "SELECT username,password FROM users WHERE ";
+
+ String where = " 1=1 ";
+ Page pageInfo = helper
+ .fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList().toArray(), pageNo,
+ pageSize, USER_ROW_MAPPER);
+ if (pageInfo == null) {
+ pageInfo = new Page<>();
+ pageInfo.setTotalCount(0);
+ pageInfo.setPageItems(new ArrayList<>());
+ }
+ return pageInfo;
+ }
+
+ public static final class UserRowMapper implements RowMapper {
+
+ @Override
+ public User mapRow(ResultSet rs, int rowNum) throws SQLException {
+ User user = new User();
+ user.setUsername(rs.getString("username"));
+ user.setPassword(rs.getString("password"));
+ return user;
+ }
+ }
+}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalPermissionPersistServiceImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalPermissionPersistServiceImpl.java
similarity index 93%
rename from auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalPermissionPersistServiceImpl.java
rename to auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalPermissionPersistServiceImpl.java
index ac2bcefd5..4cbeaa47e 100644
--- a/auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalPermissionPersistServiceImpl.java
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalPermissionPersistServiceImpl.java
@@ -20,7 +20,7 @@ import com.alibaba.nacos.auth.configuration.ConditionOnExternalStorage;
import com.alibaba.nacos.auth.model.Page;
import com.alibaba.nacos.auth.model.PermissionInfo;
import com.alibaba.nacos.auth.persist.repository.PaginationHelper;
-import com.alibaba.nacos.auth.persist.repository.externel.ExternalStoragePersistServiceImpl;
+import com.alibaba.nacos.auth.persist.repository.externel.AuthExternalStoragePersistServiceImpl;
import com.alibaba.nacos.auth.util.LogUtil;
import com.alibaba.nacos.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,12 +44,12 @@ import java.util.List;
*/
@Conditional(value = ConditionOnExternalStorage.class)
@Component
-public class ExternalPermissionPersistServiceImpl implements PermissionPersistService {
+public class AuthExternalPermissionPersistServiceImpl implements PermissionPersistService {
public static final PermissionRowMapper PERMISSION_ROW_MAPPER = new PermissionRowMapper();
@Autowired
- private ExternalStoragePersistServiceImpl persistService;
+ private AuthExternalStoragePersistServiceImpl persistService;
private JdbcTemplate jt;
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalRolePersistServiceImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalRolePersistServiceImpl.java
similarity index 93%
rename from auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalRolePersistServiceImpl.java
rename to auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalRolePersistServiceImpl.java
index 96a232ce7..161d65135 100644
--- a/auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalRolePersistServiceImpl.java
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalRolePersistServiceImpl.java
@@ -19,7 +19,7 @@ package com.alibaba.nacos.auth.persist;
import com.alibaba.nacos.auth.configuration.ConditionOnExternalStorage;
import com.alibaba.nacos.auth.model.Page;
import com.alibaba.nacos.auth.persist.repository.PaginationHelper;
-import com.alibaba.nacos.auth.persist.repository.externel.ExternalStoragePersistServiceImpl;
+import com.alibaba.nacos.auth.persist.repository.externel.AuthExternalStoragePersistServiceImpl;
import com.alibaba.nacos.auth.roles.RoleInfo;
import com.alibaba.nacos.auth.util.LogUtil;
import com.alibaba.nacos.common.utils.StringUtils;
@@ -44,12 +44,12 @@ import java.util.List;
*/
@Conditional(value = ConditionOnExternalStorage.class)
@Component
-public class ExternalRolePersistServiceImpl implements RolePersistService {
+public class AuthExternalRolePersistServiceImpl implements RolePersistService {
public static final RoleInfoRowMapper ROLE_INFO_ROW_MAPPER = new RoleInfoRowMapper();
@Autowired
- private ExternalStoragePersistServiceImpl persistService;
+ private AuthExternalStoragePersistServiceImpl persistService;
private JdbcTemplate jt;
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalUserPersistServiceImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalUserPersistServiceImpl.java
similarity index 94%
rename from auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalUserPersistServiceImpl.java
rename to auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalUserPersistServiceImpl.java
index 661d932a5..22ccc4a8c 100644
--- a/auth/src/main/java/com/alibaba/nacos/auth/persist/ExternalUserPersistServiceImpl.java
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/AuthExternalUserPersistServiceImpl.java
@@ -19,7 +19,7 @@ package com.alibaba.nacos.auth.persist;
import com.alibaba.nacos.auth.configuration.ConditionOnExternalStorage;
import com.alibaba.nacos.auth.model.Page;
import com.alibaba.nacos.auth.persist.repository.PaginationHelper;
-import com.alibaba.nacos.auth.persist.repository.externel.ExternalStoragePersistServiceImpl;
+import com.alibaba.nacos.auth.persist.repository.externel.AuthExternalStoragePersistServiceImpl;
import com.alibaba.nacos.auth.users.User;
import com.alibaba.nacos.auth.util.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
@@ -42,12 +42,12 @@ import java.util.ArrayList;
*/
@Conditional(value = ConditionOnExternalStorage.class)
@Component
-public class ExternalUserPersistServiceImpl implements UserPersistService {
+public class AuthExternalUserPersistServiceImpl implements UserPersistService {
public static final RowMapper USER_ROW_MAPPER = new UserRowMapper();
@Autowired
- private ExternalStoragePersistServiceImpl persistService;
+ private AuthExternalStoragePersistServiceImpl persistService;
private JdbcTemplate jt;
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/DynamicDataSource.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/AuthDynamicDataSource.java
similarity index 91%
rename from auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/DynamicDataSource.java
rename to auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/AuthDynamicDataSource.java
index d67f7603c..dc7904266 100644
--- a/auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/DynamicDataSource.java
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/AuthDynamicDataSource.java
@@ -25,15 +25,15 @@ import org.springframework.stereotype.Component;
* @author Nacos
*/
@Component
-public class DynamicDataSource {
+public class AuthDynamicDataSource {
private DataSourceService localDataSourceService = null;
private DataSourceService basicDataSourceService = null;
- private static final DynamicDataSource INSTANCE = new DynamicDataSource();
+ private static final AuthDynamicDataSource INSTANCE = new AuthDynamicDataSource();
- public static DynamicDataSource getInstance() {
+ public static AuthDynamicDataSource getInstance() {
return INSTANCE;
}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/ExternalDataSourceServiceImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/ExternalDataSourceServiceImpl.java
index 05a66597a..4e2526846 100644
--- a/auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/ExternalDataSourceServiceImpl.java
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/datasource/ExternalDataSourceServiceImpl.java
@@ -103,13 +103,6 @@ public class ExternalDataSourceServiceImpl implements DataSourceService {
FATAL_LOG.error("[ExternalDataSourceService] dats source reload error", e);
throw new RuntimeException(DB_LOAD_ERROR_MSG);
}
- /*
- if (this.dataSourceList.size() > DB_MASTER_SELECT_THRESHOLD) {
- ConfigExecutor.scheduleConfigTask(new SelectMasterTask(), 10, 10, TimeUnit.SECONDS);
- }
- ConfigExecutor.scheduleConfigTask(new CheckDbHealthTask(), 10, 10, TimeUnit.SECONDS);
-
- */
}
}
@@ -125,7 +118,6 @@ public class ExternalDataSourceServiceImpl implements DataSourceService {
isHealthList.add(Boolean.TRUE);
});
new SelectMasterTask().run();
- //new CheckDbHealthTask().run();
} catch (RuntimeException e) {
FATAL_LOG.error(DB_LOAD_ERROR_MSG, e);
throw new IOException(e);
@@ -222,39 +214,8 @@ public class ExternalDataSourceServiceImpl implements DataSourceService {
if (!isFound) {
FATAL_LOG.error("[master-db] master db not found.");
- //MetricsMonitor.getDbException().increment();
}
}
}
- /*
- @SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
- class CheckDbHealthTask implements Runnable {
-
- @Override
- public void run() {
- if (DEFAULT_LOG.isDebugEnabled()) {
- DEFAULT_LOG.debug("check db health.");
- }
- String sql = "SELECT * FROM config_info_beta WHERE id = 1";
-
- for (int i = 0; i < testJtList.size(); i++) {
- JdbcTemplate jdbcTemplate = testJtList.get(i);
- try {
- jdbcTemplate.query(sql, CONFIG_INFO4BETA_ROW_MAPPER);
- isHealthList.set(i, Boolean.TRUE);
- } catch (DataAccessException e) {
- if (i == masterIndex) {
- FATAL_LOG.error("[db-error] master db {} down.",
- InternetAddressUtil.getIPFromString(dataSourceList.get(i).getJdbcUrl()));
- } else {
- FATAL_LOG.error("[db-error] slave db {} down.",
- InternetAddressUtil.getIPFromString(dataSourceList.get(i).getJdbcUrl()));
- }
- isHealthList.set(i, Boolean.FALSE);
-
- MetricsMonitor.getDbException().increment();
- }
- }
- }
- }*/
+
}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/repository/embedded/AuthEmbeddedStoragePersistServiceImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/repository/embedded/AuthEmbeddedStoragePersistServiceImpl.java
new file mode 100644
index 000000000..520a2ec89
--- /dev/null
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/repository/embedded/AuthEmbeddedStoragePersistServiceImpl.java
@@ -0,0 +1,47 @@
+package com.alibaba.nacos.auth.persist.repository.embedded;
+
+import com.alibaba.nacos.auth.configuration.ConditionOnEmbeddedStorage;
+import com.alibaba.nacos.auth.persist.datasource.DataSourceService;
+import com.alibaba.nacos.auth.persist.datasource.AuthDynamicDataSource;
+import com.alibaba.nacos.auth.persist.repository.PaginationHelper;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Component;
+import javax.annotation.PostConstruct;
+
+@Conditional(value = ConditionOnEmbeddedStorage.class)
+@Component
+public class AuthEmbeddedStoragePersistServiceImpl {
+
+ private DataSourceService dataSourceService;
+
+ private final DatabaseOperate databaseOperate;
+
+ public AuthEmbeddedStoragePersistServiceImpl(DatabaseOperate databaseOperate) {
+ this.databaseOperate = databaseOperate;
+ }
+
+ /**
+ * init datasource.
+ */
+ @PostConstruct
+ public void init() {
+ dataSourceService = AuthDynamicDataSource.getInstance().getDataSource();
+ }
+
+ public PaginationHelper createPaginationHelper() {
+ return new EmbeddedPaginationHelperImpl(databaseOperate);
+ }
+
+ /**
+ * For unit testing.
+ */
+ public JdbcTemplate getJdbcTemplate() {
+ return this.dataSourceService.getJdbcTemplate();
+ }
+
+ public DatabaseOperate getDatabaseOperate() {
+ return databaseOperate;
+ }
+
+}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/persist/repository/embedded/AuthStandaloneDatabaseOperateImpl.java b/auth/src/main/java/com/alibaba/nacos/auth/persist/repository/embedded/AuthStandaloneDatabaseOperateImpl.java
new file mode 100644
index 000000000..a0271f97d
--- /dev/null
+++ b/auth/src/main/java/com/alibaba/nacos/auth/persist/repository/embedded/AuthStandaloneDatabaseOperateImpl.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 1999-2018 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.auth.persist.repository.embedded;
+
+import com.alibaba.nacos.auth.configuration.ConditionStandaloneEmbedStorage;
+import com.alibaba.nacos.auth.persist.datasource.DataSourceService;
+import com.alibaba.nacos.auth.persist.datasource.AuthDynamicDataSource;
+import com.alibaba.nacos.auth.persist.sql.ModifyRequest;
+import com.alibaba.nacos.auth.util.LogUtil;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.support.TransactionTemplate;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
+
+/**
+ * Derby operation in stand-alone mode.
+ *
+ * @author liaochuntao
+ */
+@Conditional(ConditionStandaloneEmbedStorage.class)
+@Component
+public class AuthStandaloneDatabaseOperateImpl implements BaseDatabaseOperate {
+
+ private JdbcTemplate jdbcTemplate;
+
+ private TransactionTemplate transactionTemplate;
+
+ @PostConstruct
+ protected void init() {
+ DataSourceService dataSourceService = AuthDynamicDataSource.getInstance().getDataSource();
+ jdbcTemplate = dataSourceService.getJdbcTemplate();
+ transactionTemplate = dataSourceService.getTransactionTemplate();
+ LogUtil.DEFAULT_LOG.info("use StandaloneDatabaseOperateImpl");
+ }
+
+ @Override
+ public R queryOne(String sql, Class cls) {
+ return queryOne(jdbcTemplate, sql, cls);
+ }
+
+ @Override
+ public R queryOne(String sql, Object[] args, Class cls) {
+ return queryOne(jdbcTemplate, sql, args, cls);
+ }
+
+ @Override
+ public R queryOne(String sql, Object[] args, RowMapper mapper) {
+ return queryOne(jdbcTemplate, sql, args, mapper);
+ }
+
+ @Override
+ public List queryMany(String sql, Object[] args, RowMapper mapper) {
+ return queryMany(jdbcTemplate, sql, args, mapper);
+ }
+
+ @Override
+ public List queryMany(String sql, Object[] args, Class rClass) {
+ return queryMany(jdbcTemplate, sql, args, rClass);
+ }
+
+ @Override
+ public List