This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/master by this push:
new f3d08ee [SYNCOPE-1460] zookeeper profile for IT
f3d08ee is described below
commit f3d08eea82c35ea26414d35b1c0332f2410fbc60
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Fri May 10 15:51:38 2019 +0200
[SYNCOPE-1460] zookeeper profile for IT
---
.../common/keymaster/client/api/DomainWatcher.java | 4 +-
common/keymaster/client-zookeeper/pom.xml | 1 -
.../client/zookeper/ZookeeperDomainOps.java | 44 ++++++++-----
...rTestContext.java => LoggingDomainWatcher.java} | 17 +++--
.../client/zookeper/ZookeeperTestContext.java | 6 ++
.../core/persistence/jpa/RuntimeDomainLoader.java | 49 +++++---------
.../jpa/spring/CommonEntityManagerFactoryConf.java | 3 +-
.../org/apache/syncope/core/logic/DomainLogic.java | 3 +-
fit/core-reference/pom.xml | 77 ++++++++++++++++++++++
fit/core-reference/src/main/resources/log4j2.xml | 8 +++
fit/core-reference/src/test/resources/log4j2.xml | 8 ++-
11 files changed, 159 insertions(+), 61 deletions(-)
diff --git
a/common/keymaster/client-api/src/main/java/org/apache/syncope/common/keymaster/client/api/DomainWatcher.java
b/common/keymaster/client-api/src/main/java/org/apache/syncope/common/keymaster/client/api/DomainWatcher.java
index 95feeaf..e850202 100644
---
a/common/keymaster/client-api/src/main/java/org/apache/syncope/common/keymaster/client/api/DomainWatcher.java
+++
b/common/keymaster/client-api/src/main/java/org/apache/syncope/common/keymaster/client/api/DomainWatcher.java
@@ -18,12 +18,12 @@
*/
package org.apache.syncope.common.keymaster.client.api;
-import java.util.List;
+import org.apache.syncope.common.keymaster.client.api.model.Domain;
/**
* Interface to be implemented by anyone that wants to be notified when
domains are created / updated / deleted.
*/
public interface DomainWatcher {
- void update(List<String> domains);
+ void process(Domain domain);
}
diff --git a/common/keymaster/client-zookeeper/pom.xml
b/common/keymaster/client-zookeeper/pom.xml
index 17952bf..5389818 100644
--- a/common/keymaster/client-zookeeper/pom.xml
+++ b/common/keymaster/client-zookeeper/pom.xml
@@ -118,7 +118,6 @@ under the License.
<build>
<plugins>
-
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
diff --git
a/common/keymaster/client-zookeeper/src/main/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperDomainOps.java
b/common/keymaster/client-zookeeper/src/main/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperDomainOps.java
index a66b89b..fd04051 100644
---
a/common/keymaster/client-zookeeper/src/main/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperDomainOps.java
+++
b/common/keymaster/client-zookeeper/src/main/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperDomainOps.java
@@ -19,21 +19,19 @@
package org.apache.syncope.common.keymaster.client.zookeper;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.x.async.AsyncCuratorFramework;
-import org.apache.curator.x.async.WatchMode;
+import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.syncope.common.keymaster.client.api.DomainOps;
import org.apache.syncope.common.keymaster.client.api.DomainWatcher;
import org.apache.syncope.common.keymaster.client.api.KeymasterException;
import org.apache.syncope.common.keymaster.client.api.model.Domain;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.types.CipherAlgorithm;
-import org.apache.zookeeper.Watcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
@@ -63,16 +61,30 @@ public class ZookeeperDomainOps implements DomainOps,
InitializingBean {
client.create().creatingParentContainersIfNeeded().forPath(buildDomainPath());
}
-
AsyncCuratorFramework.wrap(client).with(WatchMode.successOnly).watched().getChildren().
- forPath(buildDomainPath()).event().thenAccept(event -> {
- if (event.getType() ==
Watcher.Event.EventType.NodeChildrenChanged) {
- try {
- List<String> children = client.getChildren().
-
forPath(event.getPath()).stream().collect(Collectors.toList());
- watcher.update(children);
- } catch (Exception e) {
- LOG.error("Unexpected exception", e);
- }
+ new TreeCache(client,
buildDomainPath()).start().getListenable().addListener((cf, event) -> {
+ switch (event.getType()) {
+ case NODE_ADDED:
+ LOG.debug("Domain {} added",
event.getData().getPath());
+ try {
+ Domain domain =
MAPPER.readValue(event.getData().getData(), Domain.class);
+
+ LOG.info("Domain {} created", domain.getKey());
+ watcher.process(domain);
+ } catch (IOException e) {
+ LOG.debug("Could not parse {}", new
String(event.getData().getData()), e);
+ }
+ break;
+
+ case NODE_UPDATED:
+ LOG.debug("Domain {} update",
event.getData().getPath());
+ break;
+
+ case NODE_REMOVED:
+ LOG.debug("Domain {} removed",
event.getData().getPath());
+ break;
+
+ default:
+ LOG.debug("Event {} received", event);
}
});
}
@@ -125,8 +137,8 @@ public class ZookeeperDomainOps implements DomainOps,
InitializingBean {
throw new KeymasterException("Domain " + domain.getKey() + "
existing");
}
-
client.create().creatingParentContainersIfNeeded().forPath(buildDomainPath(domain.getKey()));
- client.setData().forPath(buildDomainPath(domain.getKey()),
MAPPER.writeValueAsBytes(domain));
+ client.create().creatingParentContainersIfNeeded().
+ forPath(buildDomainPath(domain.getKey()),
MAPPER.writeValueAsBytes(domain));
} catch (KeymasterException e) {
throw e;
} catch (Exception e) {
diff --git
a/common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperTestContext.java
b/common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/LoggingDomainWatcher.java
similarity index 65%
copy from
common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperTestContext.java
copy to
common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/LoggingDomainWatcher.java
index 31560d1..f340f35 100644
---
a/common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperTestContext.java
+++
b/common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/LoggingDomainWatcher.java
@@ -18,14 +18,17 @@
*/
package org.apache.syncope.common.keymaster.client.zookeper;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
+import org.apache.syncope.common.keymaster.client.api.DomainWatcher;
+import org.apache.syncope.common.keymaster.client.api.model.Domain;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-@Configuration
-public class ZookeeperTestContext {
+public class LoggingDomainWatcher implements DomainWatcher {
- @Bean
- public ZookeeperTestContentLoader zookeeperTestContentLoader() {
- return new ZookeeperTestContentLoader();
+ private static final Logger LOG =
LoggerFactory.getLogger(LoggingDomainWatcher.class);
+
+ @Override
+ public void process(final Domain domain) {
+ LOG.info("Domain {} created", domain);
}
}
diff --git
a/common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperTestContext.java
b/common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperTestContext.java
index 31560d1..c50dded 100644
---
a/common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperTestContext.java
+++
b/common/keymaster/client-zookeeper/src/test/java/org/apache/syncope/common/keymaster/client/zookeper/ZookeeperTestContext.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.common.keymaster.client.zookeper;
+import org.apache.syncope.common.keymaster.client.api.DomainWatcher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -28,4 +29,9 @@ public class ZookeeperTestContext {
public ZookeeperTestContentLoader zookeeperTestContentLoader() {
return new ZookeeperTestContentLoader();
}
+
+ @Bean
+ public DomainWatcher loggingDomainWatcher() {
+ return new LoggingDomainWatcher();
+ }
}
diff --git
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/RuntimeDomainLoader.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/RuntimeDomainLoader.java
index 031927c..901980e 100644
---
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/RuntimeDomainLoader.java
+++
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/RuntimeDomainLoader.java
@@ -19,10 +19,8 @@
package org.apache.syncope.core.persistence.jpa;
import java.util.Comparator;
-import java.util.List;
-import java.util.Objects;
-import org.apache.syncope.common.keymaster.client.api.DomainOps;
import org.apache.syncope.common.keymaster.client.api.DomainWatcher;
+import org.apache.syncope.common.keymaster.client.api.model.Domain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -42,41 +40,30 @@ public class RuntimeDomainLoader implements DomainWatcher {
private DomainHolder domainHolder;
@Autowired
- private DomainOps domainOps;
-
- @Autowired
private DomainRegistry domainRegistry;
@Override
- public void update(final List<String> domains) {
- domains.stream().filter(domain ->
!domainHolder.getDomains().containsKey(domain)).
- map(domain -> {
- try {
- return domainOps.read(domain);
- } catch (Exception e) {
- LOG.error("Could not read {}", domain, e);
- return null;
- }
- }).
- filter(Objects::nonNull).
- forEach(domain -> {
- LOG.info("Domain {} initialization", domain.getKey());
+ public void process(final Domain domain) {
+ if (domainHolder.getDomains().containsKey(domain.getKey())) {
+ LOG.debug("Domain {} already inited, skipping", domain.getKey());
+ } else {
+ LOG.info("Domain {} initialization", domain.getKey());
- domainRegistry.register(domain);
+ domainRegistry.register(domain);
-
ApplicationContextProvider.getApplicationContext().getBeansOfType(SyncopeCoreLoader.class).values().
-
stream().sorted(Comparator.comparing(SyncopeCoreLoader::getOrder)).
- forEach(loader -> {
- String loaderName =
AopUtils.getTargetClass(loader).getName();
+
ApplicationContextProvider.getApplicationContext().getBeansOfType(SyncopeCoreLoader.class).values().
+
stream().sorted(Comparator.comparing(SyncopeCoreLoader::getOrder)).
+ forEach(loader -> {
+ String loaderName =
AopUtils.getTargetClass(loader).getName();
- loader.load();
+ loader.load();
- LOG.debug("[{}] Starting on domain '{}'",
loaderName, domain);
- loader.load(domain.getKey(),
domainHolder.getDomains().get(domain.getKey()));
- LOG.debug("[{}] Completed on domain '{}'",
loaderName, domain);
- });
+ LOG.debug("[{}] Starting on domain '{}'", loaderName,
domain);
+ loader.load(domain.getKey(),
domainHolder.getDomains().get(domain.getKey()));
+ LOG.debug("[{}] Completed on domain '{}'", loaderName,
domain);
+ });
- LOG.info("Domain {} successfully inited", domain.getKey());
- });
+ LOG.info("Domain {} successfully inited", domain.getKey());
+ }
}
}
diff --git
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/spring/CommonEntityManagerFactoryConf.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/spring/CommonEntityManagerFactoryConf.java
index c7bbe77..536a367 100644
---
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/spring/CommonEntityManagerFactoryConf.java
+++
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/spring/CommonEntityManagerFactoryConf.java
@@ -20,6 +20,7 @@ package org.apache.syncope.core.persistence.jpa.spring;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.persistence.ValidationMode;
import javax.sql.DataSource;
import
org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor;
@@ -31,7 +32,7 @@ import org.apache.syncope.core.persistence.api.DomainHolder;
*/
public class CommonEntityManagerFactoryConf implements DomainHolder {
- private final Map<String, DataSource> domains = new HashMap<>();
+ private final Map<String, DataSource> domains = new ConcurrentHashMap<>();
private String[] packagesToScan;
diff --git
a/ext/self-keymaster/logic/src/main/java/org/apache/syncope/core/logic/DomainLogic.java
b/ext/self-keymaster/logic/src/main/java/org/apache/syncope/core/logic/DomainLogic.java
index 2362bb0..585ecf7 100644
---
a/ext/self-keymaster/logic/src/main/java/org/apache/syncope/core/logic/DomainLogic.java
+++
b/ext/self-keymaster/logic/src/main/java/org/apache/syncope/core/logic/DomainLogic.java
@@ -19,7 +19,6 @@
package org.apache.syncope.core.logic;
import java.lang.reflect.Method;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -75,7 +74,7 @@ public class DomainLogic extends
AbstractTransactionalLogic<EntityTO> {
domainEntity.set(domain);
domainEntity = domainDAO.save(domainEntity);
- domainWatcher.update(Collections.singletonList(domain.getKey()));
+ domainWatcher.process(domain);
return domainEntity.get();
}
diff --git a/fit/core-reference/pom.xml b/fit/core-reference/pom.xml
index ecd6d72..039d1f74 100644
--- a/fit/core-reference/pom.xml
+++ b/fit/core-reference/pom.xml
@@ -466,6 +466,83 @@ under the License.
</profile>
<profile>
+ <id>zookeper-it</id>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <configuration>
+ <images>
+ <image>
+ <name>zookeeper:${zookeeper.version}</name>
+ <run>
+ <ports>
+ <port>2181:2181</port>
+ </ports>
+ <volumes>
+ <bind>
+
<volume>${project.build.directory}/test-classes/zoo.cfg:/conf/zoo.cfg</volume>
+
<volume>${project.build.directory}/test-classes/java.env:/conf/java.env</volume>
+
<volume>${project.build.directory}/test-classes/server-jaas.conf:/conf/server-jaas.conf</volume>
+
<volume>${project.build.directory}/test-classes/client-jaas.conf:/conf/client-jaas.conf</volume>
+ </bind>
+ </volumes>
+ </run>
+ </image>
+ </images>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start-zookeeper</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-zookeeper</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ <goal>remove</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <inherited>true</inherited>
+ </plugin>
+ </plugins>
+
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ <excludes>
+ <exclude>keystore</exclude>
+ </excludes>
+ </testResource>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>false</filtering>
+ <includes>
+ <include>keystore</include>
+ </includes>
+ </testResource>
+ <testResource>
+
<directory>${basedir}/../../common/keymaster/client-zookeeper/src/main/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
+ </build>
+ </profile>
+
+ <profile>
<id>elasticsearch-it</id>
<dependencies>
diff --git a/fit/core-reference/src/main/resources/log4j2.xml
b/fit/core-reference/src/main/resources/log4j2.xml
index ebbd2e2..41909ed 100644
--- a/fit/core-reference/src/main/resources/log4j2.xml
+++ b/fit/core-reference/src/main/resources/log4j2.xml
@@ -196,6 +196,14 @@ under the License.
<appender-ref ref="mainFile"/>
<appender-ref ref="main"/>
</asyncLogger>
+ <asyncLogger name="org.apache.zookeeper" additivity="false" level="ERROR">
+ <appender-ref ref="mainFile"/>
+ <appender-ref ref="main"/>
+ </asyncLogger>
+ <asyncLogger name="org.apache.curator" additivity="false" level="ERROR">
+ <appender-ref ref="mainFile"/>
+ <appender-ref ref="main"/>
+ </asyncLogger>
<!-- To enable when setting 'mail.debug=true' in mail.properties -->
<!--<asyncLogger
name="org.apache.syncope.core.provisioning.java.job.notification"
additivity="false" level="DEBUG">
diff --git a/fit/core-reference/src/test/resources/log4j2.xml
b/fit/core-reference/src/test/resources/log4j2.xml
index fe68df8..875d5e7 100644
--- a/fit/core-reference/src/test/resources/log4j2.xml
+++ b/fit/core-reference/src/test/resources/log4j2.xml
@@ -45,7 +45,13 @@ under the License.
<appender-ref ref="main"/>
</asyncLogger>
- <asyncLogger name="org.apache.syncope.common.keymaster" additivity="false"
level="DEBUG">
+ <asyncLogger name="org.apache.syncope.common.keymaster" additivity="false"
level="ERROR">
+ <appender-ref ref="main"/>
+ </asyncLogger>
+ <asyncLogger name="org.apache.zookeeper" additivity="false" level="ERROR">
+ <appender-ref ref="main"/>
+ </asyncLogger>
+ <asyncLogger name="org.apache.curator" additivity="false" level="ERROR">
<appender-ref ref="main"/>
</asyncLogger>