This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 3_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/3_0_X by this push:
new 78022a415b [SYNCOPE-1762] Extending DefaultSyncopeCoreInfoContributor
with JPA provider info
78022a415b is described below
commit 78022a415b9235aa29edbb1446d9e4a6fdf10d31
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Thu Jun 1 15:35:24 2023 +0200
[SYNCOPE-1762] Extending DefaultSyncopeCoreInfoContributor with JPA
provider info
---
.../persistence/api/dao/PersistenceInfoDAO.java} | 10 +-
.../core/persistence/jpa/PersistenceContext.java | 8 ++
.../persistence/jpa/dao/JPAPersistenceInfoDAO.java | 107 +++++++++++++++++++++
.../core/starter/SyncopeCoreApplication.java | 7 +-
.../actuate/DefaultSyncopeCoreInfoContributor.java | 9 +-
.../actuate/SyncopeCoreInfoContributor.java | 2 +-
pom.xml | 2 +-
7 files changed, 134 insertions(+), 11 deletions(-)
diff --git
a/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/SyncopeCoreInfoContributor.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/PersistenceInfoDAO.java
similarity index 72%
copy from
core/starter/src/main/java/org/apache/syncope/core/starter/actuate/SyncopeCoreInfoContributor.java
copy to
core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/PersistenceInfoDAO.java
index ad97624e0e..dc9fafd6bf 100644
---
a/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/SyncopeCoreInfoContributor.java
+++
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/PersistenceInfoDAO.java
@@ -16,13 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.syncope.core.persistence.api.dao;
-package org.apache.syncope.core.starter.actuate;
+import java.util.Map;
-import org.apache.syncope.common.lib.info.SystemInfo;
-import org.springframework.context.PayloadApplicationEvent;
+public interface PersistenceInfoDAO {
-@FunctionalInterface
-public interface SyncopeCoreInfoContributor {
- void addLoadInstant(PayloadApplicationEvent<SystemInfo.LoadInstant> event);
+ Map<String, Object> info();
}
diff --git
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/PersistenceContext.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/PersistenceContext.java
index 3c2b99d6b4..54594b76ba 100644
---
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/PersistenceContext.java
+++
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/PersistenceContext.java
@@ -54,6 +54,7 @@ import
org.apache.syncope.core.persistence.api.dao.MailTemplateDAO;
import org.apache.syncope.core.persistence.api.dao.NotificationDAO;
import org.apache.syncope.core.persistence.api.dao.OIDCJWKSDAO;
import org.apache.syncope.core.persistence.api.dao.OIDCRPClientAppDAO;
+import org.apache.syncope.core.persistence.api.dao.PersistenceInfoDAO;
import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO;
import org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO;
import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
@@ -111,6 +112,7 @@ import
org.apache.syncope.core.persistence.jpa.dao.JPAMailTemplateDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPANotificationDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPAOIDCJWKSDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPAOIDCRPClientAppDAO;
+import org.apache.syncope.core.persistence.jpa.dao.JPAPersistenceInfoDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPAPlainAttrDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPAPlainAttrValueDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPAPlainSchemaDAO;
@@ -307,6 +309,12 @@ public class PersistenceContext {
return new JPAEntityCacheDAO();
}
+ @ConditionalOnMissingBean
+ @Bean
+ public PersistenceInfoDAO persistenceInfoDAO() {
+ return new JPAPersistenceInfoDAO();
+ }
+
@ConditionalOnMissingBean
@Bean
public AccessTokenDAO accessTokenDAO() {
diff --git
a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPersistenceInfoDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPersistenceInfoDAO.java
new file mode 100644
index 0000000000..66c80f7075
--- /dev/null
+++
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPersistenceInfoDAO.java
@@ -0,0 +1,107 @@
+/*
+ * 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.syncope.core.persistence.jpa.dao;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Triple;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.event.RemoteCommitEventManager;
+import org.apache.openjpa.event.RemoteCommitProvider;
+import org.apache.openjpa.event.TCPRemoteCommitProvider;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.syncope.core.persistence.api.dao.PersistenceInfoDAO;
+import org.apache.syncope.core.persistence.api.entity.Entity;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
+
+public class JPAPersistenceInfoDAO extends AbstractDAO<Entity> implements
PersistenceInfoDAO {
+
+ @Override
+ public Map<String, Object> info() {
+ Map<String, Object> result = new LinkedHashMap<>();
+
+ OpenJPAEntityManagerFactorySPI emfspi =
+ (OpenJPAEntityManagerFactorySPI)
OpenJPAPersistence.cast(entityManagerFactory());
+ OpenJPAConfiguration conf = emfspi.getConfiguration();
+
+ Map<String, Object> properties = emfspi.getProperties();
+ result.put("vendor", properties.get("VendorName"));
+ result.put("version", properties.get("VersionNumber"));
+ result.put("platform", properties.get("Platform"));
+
+ Map<String, Object> remoteCommitProvider = new LinkedHashMap<>();
+ result.put("remoteCommitProvider", remoteCommitProvider);
+
+ RemoteCommitEventManager rcem = conf.getRemoteCommitEventManager();
+
+ remoteCommitProvider.put("remoteEventsEnabled",
rcem.areRemoteEventsEnabled());
+ remoteCommitProvider.put("transmitPersistedObjectIds",
rcem.getTransmitPersistedObjectIds());
+ remoteCommitProvider.put("failFast", rcem.isFailFast());
+
+ RemoteCommitProvider rcp = rcem.getRemoteCommitProvider();
+ List<Triple<String, Integer, Boolean>> addresses = new ArrayList<>();
+ if (rcp instanceof TCPRemoteCommitProvider) {
+ try {
+ Field addressesField =
ReflectionUtils.findField(TCPRemoteCommitProvider.class, "_addresses");
+ addressesField.setAccessible(true);
+
+ Class<?> hostClass = ClassUtils.forName(
+
"org.apache.openjpa.event.TCPRemoteCommitProvider$HostAddress",
+ ClassUtils.getDefaultClassLoader());
+ Field addressField = ReflectionUtils.findField(hostClass,
"_address");
+ addressField.setAccessible(true);
+ Field portField = ReflectionUtils.findField(hostClass,
"_port");
+ portField.setAccessible(true);
+ Field isAvailableField = ReflectionUtils.findField(hostClass,
"_isAvailable");
+ isAvailableField.setAccessible(true);
+
+ @SuppressWarnings("unchecked")
+ List<Object> hosts = (List<Object>)
ReflectionUtils.getField(addressesField, rcp);
+ hosts.forEach(host -> {
+ InetAddress address = (InetAddress)
ReflectionUtils.getField(addressField, host);
+ Integer port = (Integer)
ReflectionUtils.getField(portField, host);
+ Boolean isAvailable = (Boolean)
ReflectionUtils.getField(isAvailableField, host);
+
+ addresses.add(Triple.of(address.getHostAddress(), port,
isAvailable));
+ });
+ } catch (Exception e) {
+ LOG.error("Could not fetch information about
TCPRemoteCommitProvider", e);
+ }
+ }
+
+ remoteCommitProvider.put(
+ "addresses",
+ addresses.stream().map(address -> {
+ Map<String, Object> map = new LinkedHashMap<>();
+ map.put("ip", address.getLeft());
+ map.put("port", address.getMiddle());
+ map.put("available", address.getRight());
+ return map;
+ }).collect(Collectors.toList()));
+
+ return result;
+ }
+}
diff --git
a/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreApplication.java
b/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreApplication.java
index ff8b64e9de..fa67fdfae8 100644
---
a/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreApplication.java
+++
b/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreApplication.java
@@ -32,6 +32,7 @@ import
org.apache.syncope.core.persistence.api.dao.EntityCacheDAO;
import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
import org.apache.syncope.core.persistence.api.dao.GroupDAO;
import org.apache.syncope.core.persistence.api.dao.NotificationDAO;
+import org.apache.syncope.core.persistence.api.dao.PersistenceInfoDAO;
import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
import org.apache.syncope.core.persistence.api.dao.RoleDAO;
import org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO;
@@ -132,7 +133,8 @@ public class SyncopeCoreApplication extends
SpringBootServletInitializer {
final ConfParamOps confParamOps,
final ConnIdBundleManager bundleManager,
final ImplementationLookup implLookup,
- final ApplicationContext ctx) {
+ final ApplicationContext ctx,
+ final PersistenceInfoDAO persistenceInfoDAO) {
return new DefaultSyncopeCoreInfoContributor(
anyTypeDAO,
@@ -150,7 +152,8 @@ public class SyncopeCoreApplication extends
SpringBootServletInitializer {
confParamOps,
bundleManager,
implLookup,
- ctx.getBeansOfType(ThreadPoolTaskExecutor.class));
+ ctx.getBeansOfType(ThreadPoolTaskExecutor.class),
+ persistenceInfoDAO);
}
@ConditionalOnMissingBean
diff --git
a/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/DefaultSyncopeCoreInfoContributor.java
b/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/DefaultSyncopeCoreInfoContributor.java
index 5e17374918..bbcdd31c38 100644
---
a/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/DefaultSyncopeCoreInfoContributor.java
+++
b/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/DefaultSyncopeCoreInfoContributor.java
@@ -44,6 +44,7 @@ import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
import org.apache.syncope.core.persistence.api.dao.GroupDAO;
import org.apache.syncope.core.persistence.api.dao.NotificationDAO;
+import org.apache.syncope.core.persistence.api.dao.PersistenceInfoDAO;
import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
import org.apache.syncope.core.persistence.api.dao.RoleDAO;
import org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO;
@@ -168,6 +169,8 @@ public class DefaultSyncopeCoreInfoContributor implements
SyncopeCoreInfoContrib
protected final Map<String, ThreadPoolTaskExecutor> taskExecutors;
+ protected final PersistenceInfoDAO persistenceInfoDAO;
+
public DefaultSyncopeCoreInfoContributor(
final AnyTypeDAO anyTypeDAO,
final AnyTypeClassDAO anyTypeClassDAO,
@@ -184,7 +187,8 @@ public class DefaultSyncopeCoreInfoContributor implements
SyncopeCoreInfoContrib
final ConfParamOps confParamOps,
final ConnIdBundleManager bundleManager,
final ImplementationLookup implLookup,
- final Map<String, ThreadPoolTaskExecutor> taskExecutors) {
+ final Map<String, ThreadPoolTaskExecutor> taskExecutors,
+ final PersistenceInfoDAO persistenceInfoDAO) {
this.anyTypeDAO = anyTypeDAO;
this.anyTypeClassDAO = anyTypeClassDAO;
@@ -202,6 +206,7 @@ public class DefaultSyncopeCoreInfoContributor implements
SyncopeCoreInfoContrib
this.bundleManager = bundleManager;
this.implLookup = implLookup;
this.taskExecutors = taskExecutors;
+ this.persistenceInfoDAO = persistenceInfoDAO;
}
protected boolean isSelfRegAllowed() {
@@ -335,6 +340,8 @@ public class DefaultSyncopeCoreInfoContributor implements
SyncopeCoreInfoContrib
buildPlatform();
builder.withDetail("platform", PLATFORM_INFO);
+ builder.withDetail("persistence", persistenceInfoDAO.info());
+
builder.withDetail("numbers", buildNumbers());
buildSystem();
diff --git
a/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/SyncopeCoreInfoContributor.java
b/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/SyncopeCoreInfoContributor.java
index ad97624e0e..6b8272bbe9 100644
---
a/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/SyncopeCoreInfoContributor.java
+++
b/core/starter/src/main/java/org/apache/syncope/core/starter/actuate/SyncopeCoreInfoContributor.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.syncope.core.starter.actuate;
import org.apache.syncope.common.lib.info.SystemInfo;
@@ -24,5 +23,6 @@ import org.springframework.context.PayloadApplicationEvent;
@FunctionalInterface
public interface SyncopeCoreInfoContributor {
+
void addLoadInstant(PayloadApplicationEvent<SystemInfo.LoadInstant> event);
}
diff --git a/pom.xml b/pom.xml
index fcbedcd14d..29e1587326 100644
--- a/pom.xml
+++ b/pom.xml
@@ -444,7 +444,7 @@ under the License.
<h2.version>2.1.214</h2.version>
- <swagger-core.version>2.2.10</swagger-core.version>
+ <swagger-core.version>2.2.11</swagger-core.version>
<swagger-ui.version>4.18.2</swagger-ui.version>
<jquery-slimscroll.version>1.3.8</jquery-slimscroll.version>