You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/05/30 13:09:04 UTC

[shardingsphere] branch master updated: remove users node in registry center node. (#10482)

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

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new af62541  remove users node in registry center node. (#10482)
af62541 is described below

commit af625415f144cdf2a6f87c8add0c12e56a5beb3e
Author: huanghao495430759 <34...@users.noreply.github.com>
AuthorDate: Sun May 30 08:08:20 2021 -0500

    remove users node in registry center node. (#10482)
    
    * add test unit for renew CreateUserStatementEvent.
    
    * fix unused import.
    
    * fix remove users node.
---
 .../authority/listener/UserChangedListener.java    | 46 ---------------------
 .../factory/UserChangedListenerFactory.java        | 43 -------------------
 ...ore.registry.listener.GovernanceListenerFactory |  1 -
 .../listener/UserChangedListenerTest.java          | 48 ----------------------
 .../governance/core/registry/UserNode.java         | 40 ------------------
 .../governance/core/registry/UserNodeTest.java     | 31 --------------
 .../impl/GovernanceBootstrapInitializerTest.java   | 17 --------
 .../src/test/resources/conf/reg_center/users.yaml  | 19 ---------
 8 files changed, 245 deletions(-)

diff --git a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/listener/UserChangedListener.java b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/listener/UserChangedListener.java
deleted file mode 100644
index 60dd435..0000000
--- a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/listener/UserChangedListener.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.context.authority.listener;
-
-import org.apache.shardingsphere.governance.context.authority.listener.event.AuthorityChangedEvent;
-import org.apache.shardingsphere.governance.core.registry.UserNode;
-import org.apache.shardingsphere.governance.core.registry.listener.PostGovernanceRepositoryEventListener;
-import org.apache.shardingsphere.governance.core.registry.listener.event.GovernanceEvent;
-import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
-import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfigurationConverter;
-import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-
-/**
- * User changed listener.
- */
-public final class UserChangedListener extends PostGovernanceRepositoryEventListener<GovernanceEvent> {
-    
-    public UserChangedListener(final RegistryCenterRepository registryCenterRepository) {
-        super(registryCenterRepository, Collections.singletonList(UserNode.getRootNode()));
-    }
-    
-    @Override
-    protected Optional<GovernanceEvent> createEvent(final DataChangedEvent event) {
-        return Optional.of(new AuthorityChangedEvent(YamlUsersConfigurationConverter.convertShardingSphereUser(YamlEngine.unmarshal(event.getValue(), Collection.class))));
-    }
-}
diff --git a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/listener/factory/UserChangedListenerFactory.java b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/listener/factory/UserChangedListenerFactory.java
deleted file mode 100644
index d0f8fd5..0000000
--- a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/listener/factory/UserChangedListenerFactory.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.context.authority.listener.factory;
-
-import org.apache.shardingsphere.governance.context.authority.listener.UserChangedListener;
-import org.apache.shardingsphere.governance.core.registry.listener.GovernanceListener;
-import org.apache.shardingsphere.governance.core.registry.listener.GovernanceListenerFactory;
-import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
-import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent.Type;
-
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * User changed listener factory.
- */
-public final class UserChangedListenerFactory implements GovernanceListenerFactory {
-    
-    @Override
-    public GovernanceListener create(final RegistryCenterRepository registryCenterRepository, final Collection<String> schemaNames) {
-        return new UserChangedListener(registryCenterRepository);
-    }
-    
-    @Override
-    public Collection<Type> getWatchTypes() {
-        return Collections.singleton(Type.UPDATED);
-    }
-}
diff --git a/shardingsphere-governance/shardingsphere-governance-context/src/main/resources/META-INF/services/org.apache.shardingsphere.governance.core.registry.listener.GovernanceListenerFactory b/shardingsphere-governance/shardingsphere-governance-context/src/main/resources/META-INF/services/org.apache.shardingsphere.governance.core.registry.listener.GovernanceListenerFactory
index 464adc4..f1b4b14 100644
--- a/shardingsphere-governance/shardingsphere-governance-context/src/main/resources/META-INF/services/org.apache.shardingsphere.governance.core.registry.listener.GovernanceListenerFactory
+++ b/shardingsphere-governance/shardingsphere-governance-context/src/main/resources/META-INF/services/org.apache.shardingsphere.governance.core.registry.listener.GovernanceListenerFactory
@@ -15,5 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.governance.context.authority.listener.factory.UserChangedListenerFactory
 org.apache.shardingsphere.governance.context.authority.listener.factory.PrivilegeNodeChangedListenerFactory
diff --git a/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/authority/listener/UserChangedListenerTest.java b/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/authority/listener/UserChangedListenerTest.java
deleted file mode 100644
index e23d1ee..0000000
--- a/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/authority/listener/UserChangedListenerTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.context.authority.listener;
-
-import org.apache.shardingsphere.governance.context.authority.listener.event.AuthorityChangedEvent;
-import org.apache.shardingsphere.governance.core.registry.listener.event.GovernanceEvent;
-import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
-import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
-import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent.Type;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.junit.Test;
-
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class UserChangedListenerTest {
-    
-    private static final String AUTHENTICATION_YAML = "- root1@:root1\n" + "- root2@:root2\n";
-    
-    @Test
-    public void assertCreateEvent() {
-        Optional<GovernanceEvent> actual = new UserChangedListener(mock(RegistryCenterRepository.class)).createEvent(new DataChangedEvent("test", AUTHENTICATION_YAML, Type.UPDATED));
-        assertTrue(actual.isPresent());
-        Optional<ShardingSphereUser> user = ((AuthorityChangedEvent) actual.get()).getUsers().stream().filter(each -> each.getGrantee().equals(new Grantee("root1", ""))).findFirst();
-        assertTrue(user.isPresent());
-        assertThat(user.get().getPassword(), is("root1"));
-    }
-}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/UserNode.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/UserNode.java
deleted file mode 100644
index 10456da..0000000
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/UserNode.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.core.registry;
-
-import com.google.common.base.Joiner;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * User node.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class UserNode {
-    
-    private static final String ROOT_NODE = "users";
-    
-    /**
-     * Get users path.
-     *
-     * @return users path
-     */
-    public static String getRootNode() {
-        return Joiner.on("/").join("", ROOT_NODE);
-    }
-}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/UserNodeTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/UserNodeTest.java
deleted file mode 100644
index f62e885..0000000
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/UserNodeTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.core.registry;
-
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class UserNodeTest {
-    
-    @Test
-    public void assertGetUsersNodePath() {
-        assertThat(UserNode.getRootNode(), is("/users"));
-    }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
index 1c43ee3..efbd02f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.proxy.initializer.impl;
 import lombok.SneakyThrows;
 import org.apache.shardingsphere.governance.context.metadata.GovernanceMetaDataContexts;
 import org.apache.shardingsphere.governance.context.transaction.GovernanceTransactionContexts;
-import org.apache.shardingsphere.governance.core.registry.UserNode;
 import org.apache.shardingsphere.governance.core.registry.service.config.node.GlobalNode;
 import org.apache.shardingsphere.governance.core.registry.service.config.node.SchemaMetadataNode;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -29,9 +28,6 @@ import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
 import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
 import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
 import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
 import org.apache.shardingsphere.proxy.config.ProxyConfigurationLoader;
 import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
@@ -50,7 +46,6 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Collection;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Properties;
 import java.util.stream.Collectors;
 
@@ -69,8 +64,6 @@ public final class GovernanceBootstrapInitializerTest extends AbstractBootstrapI
     
     private static final String SHARDING_RULE_YAML = "conf/reg_center/sharding-rule.yaml";
     
-    private static final String USERS_YAML = "conf/reg_center/users.yaml";
-    
     private static final String PROPS_YAML = "conf/reg_center/props.yaml";
     
     private final FixtureRegistryCenterRepository registryCenterRepository = new FixtureRegistryCenterRepository();
@@ -84,7 +77,6 @@ public final class GovernanceBootstrapInitializerTest extends AbstractBootstrapI
     }
     
     private void initConfigCenter() {
-        registryCenterRepository.persist(UserNode.getRootNode(), readYAML(USERS_YAML));
         registryCenterRepository.persist(GlobalNode.getPropsPath(), readYAML(PROPS_YAML));
         registryCenterRepository.persist(SchemaMetadataNode.getMetadataNodePath(), "db");
         registryCenterRepository.persist(SchemaMetadataNode.getMetadataDataSourcePath("db"), readYAML(DATA_SOURCE_YAML));
@@ -192,15 +184,6 @@ public final class GovernanceBootstrapInitializerTest extends AbstractBootstrapI
         assertThat(props.getProperty("algorithm-expression"), is(expectedAlgorithmExpr));
     }
     
-    private void assertUsers(final ShardingSphereUsers actual) {
-        Optional<ShardingSphereUser> rootUser = actual.findUser(new Grantee("root", ""));
-        assertTrue(rootUser.isPresent());
-        assertThat(rootUser.get().getPassword(), is("root"));
-        Optional<ShardingSphereUser> shardingUser = actual.findUser(new Grantee("sharding", ""));
-        assertTrue(shardingUser.isPresent());
-        assertThat(shardingUser.get().getPassword(), is("sharding"));
-    }
-    
     @Test
     public void assertDecorateMetaDataContexts() {
         StandardMetaDataContexts metaDataContexts = mock(StandardMetaDataContexts.class);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/users.yaml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/users.yaml
deleted file mode 100644
index 7b9f5ba..0000000
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/users.yaml
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-- root@%:root
-- sharding@:sharding