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 510e521  [SYNCOPE-1459] Ensure to unregister services at shutdown
510e521 is described below

commit 510e52185065f9c47c51f157ca92489b40a37d09
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Wed May 15 11:39:23 2019 +0200

    [SYNCOPE-1459] Ensure to unregister services at shutdown
---
 .../client/console/SyncopeWebApplication.java      | 19 +++++++++++---
 .../client/enduser/SyncopeWebApplication.java      | 21 ++++++++++-----
 .../syncope/core/starter/SyncopeCoreShutdown.java  | 28 ++++++++++----------
 .../syncope/core/starter/SyncopeCoreStartStop.java | 30 ++++++++++++----------
 ...oreInitializer.java => SyncopeCoreStartup.java} | 19 +++-----------
 .../client/self/SelfKeymasterServiceOps.java       |  4 +--
 sra/pom.xml                                        | 13 +++++++++-
 ...Application.java => SyncopeSRAApplication.java} |  4 +--
 ...essApplication.java => SyncopeSRAShutdown.java} | 21 +++++----------
 ...ssApplication.java => SyncopeSRAStartStop.java} | 28 ++++++++++----------
 ...cessApplication.java => SyncopeSRAStartup.java} | 21 +++++----------
 sra/src/main/resources/application.properties      |  2 ++
 ...application.properties => keymaster.properties} | 17 +++---------
 13 files changed, 113 insertions(+), 114 deletions(-)

diff --git 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/SyncopeWebApplication.java
 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/SyncopeWebApplication.java
index 368b0a6..4174226 100644
--- 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/SyncopeWebApplication.java
+++ 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/SyncopeWebApplication.java
@@ -158,6 +158,13 @@ public class SyncopeWebApplication extends 
WicketBootSecuredWebApplication {
         }
     }
 
+    private NetworkService getNetworkService() {
+        NetworkService ns = new NetworkService();
+        ns.setType(NetworkService.Type.CONSOLE);
+        ns.setAddress(address);
+        return ns;
+    }
+
     @Override
     protected void init() {
         super.init();
@@ -289,10 +296,14 @@ public class SyncopeWebApplication extends 
WicketBootSecuredWebApplication {
             getDebugSettings().setComponentPathAttributeName("syncope-path");
         }
 
-        NetworkService ns = new NetworkService();
-        ns.setType(NetworkService.Type.CONSOLE);
-        ns.setAddress(address);
-        serviceOps.register(ns);
+        serviceOps.register(getNetworkService());
+    }
+
+    @Override
+    protected void onDestroy() {
+        serviceOps.unregister(getNetworkService());
+
+        super.onDestroy();
     }
 
     @Override
diff --git 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeWebApplication.java
 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeWebApplication.java
index 34dce75..29b3931 100644
--- 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeWebApplication.java
+++ 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeWebApplication.java
@@ -123,10 +123,15 @@ public class SyncopeWebApplication extends 
WicketBootStandardWebApplication {
 
     private Integer maxUploadFileSizeMB;
 
-    private List<String> domains;
-
     private Map<String, CustomAttributesInfo> customFormAttributes;
 
+    private NetworkService getNetworkService() {
+        NetworkService ns = new NetworkService();
+        ns.setType(NetworkService.Type.ENDUSER);
+        ns.setAddress(address);
+        return ns;
+    }
+
     @Override
     protected void init() {
         super.init();
@@ -299,10 +304,14 @@ public class SyncopeWebApplication extends 
WicketBootStandardWebApplication {
             getDebugSettings().setComponentPathAttributeName("syncope-path");
         }
 
-        NetworkService ns = new NetworkService();
-        ns.setType(NetworkService.Type.ENDUSER);
-        ns.setAddress(address);
-        serviceOps.register(ns);
+        serviceOps.register(getNetworkService());
+    }
+
+    @Override
+    protected void onDestroy() {
+        serviceOps.unregister(getNetworkService());
+
+        super.onDestroy();
     }
 
     @Override
diff --git 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java 
b/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreShutdown.java
similarity index 55%
copy from 
sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
copy to 
core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreShutdown.java
index 7112ac2..256607e 100644
--- 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
+++ 
b/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreShutdown.java
@@ -16,23 +16,21 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.syncope.sra;
+package org.apache.syncope.core.starter;
 
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.gateway.route.RouteLocator;
-import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
-import org.springframework.context.annotation.Bean;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextClosedEvent;
+import org.springframework.stereotype.Component;
 
-@SpringBootApplication
-public class SyncopeRemoteAccessApplication {
-
-    public static void main(final String[] args) {
-        SpringApplication.run(SyncopeRemoteAccessApplication.class, args);
-    }
+/**
+ * Take care of cleanup actions needed by Syncope Core.
+ */
+@Component
+public class SyncopeCoreShutdown extends SyncopeCoreStartStop
+        implements ApplicationListener<ContextClosedEvent> {
 
-    @Bean
-    public RouteLocator routes(final RouteLocatorBuilder builder) {
-        return builder.routes().build();
+    @Override
+    public void onApplicationEvent(final ContextClosedEvent event) {
+        serviceOps.unregister(getNetworkService());
     }
 }
diff --git 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java 
b/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreStartStop.java
similarity index 55%
copy from 
sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
copy to 
core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreStartStop.java
index 7112ac2..7f52923 100644
--- 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
+++ 
b/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreStartStop.java
@@ -16,23 +16,25 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.syncope.sra;
+package org.apache.syncope.core.starter;
 
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.gateway.route.RouteLocator;
-import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
-import org.springframework.context.annotation.Bean;
+import org.apache.syncope.common.keymaster.client.api.ServiceOps;
+import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 
-@SpringBootApplication
-public class SyncopeRemoteAccessApplication {
+abstract class SyncopeCoreStartStop {
 
-    public static void main(final String[] args) {
-        SpringApplication.run(SyncopeRemoteAccessApplication.class, args);
-    }
+    @Autowired
+    protected ServiceOps serviceOps;
+
+    @Value("${service.discovery.address}")
+    private String address;
 
-    @Bean
-    public RouteLocator routes(final RouteLocatorBuilder builder) {
-        return builder.routes().build();
+    protected NetworkService getNetworkService() {
+        NetworkService ns = new NetworkService();
+        ns.setType(NetworkService.Type.CORE);
+        ns.setAddress(address);
+        return ns;
     }
 }
diff --git 
a/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreInitializer.java
 
b/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreStartup.java
similarity index 80%
rename from 
core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreInitializer.java
rename to 
core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreStartup.java
index 5c2bbff..a1d130a 100644
--- 
a/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreInitializer.java
+++ 
b/core/starter/src/main/java/org/apache/syncope/core/starter/SyncopeCoreStartup.java
@@ -19,15 +19,12 @@
 package org.apache.syncope.core.starter;
 
 import java.util.Comparator;
-import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
-import org.apache.syncope.common.keymaster.client.api.ServiceOps;
 import org.apache.syncope.core.persistence.api.DomainHolder;
 import org.apache.syncope.core.persistence.api.SyncopeCoreLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.aop.support.AopUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.core.Ordered;
@@ -37,19 +34,14 @@ import org.springframework.stereotype.Component;
  * Take care of all initializations needed by Syncope Core to run up and safe.
  */
 @Component
-public class SyncopeCoreInitializer implements 
ApplicationListener<ContextRefreshedEvent>, Ordered {
+public class SyncopeCoreStartup extends SyncopeCoreStartStop
+        implements ApplicationListener<ContextRefreshedEvent>, Ordered {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(SyncopeCoreInitializer.class);
+    private static final Logger LOG = 
LoggerFactory.getLogger(SyncopeCoreStartup.class);
 
     @Autowired
     private DomainHolder domainHolder;
 
-    @Autowired
-    private ServiceOps serviceOps;
-
-    @Value("${service.discovery.address}")
-    private String address;
-
     @Override
     public int getOrder() {
         return 0;
@@ -75,9 +67,6 @@ public class SyncopeCoreInitializer implements 
ApplicationListener<ContextRefres
                     LOG.debug("[{}] Initialization completed", loaderName);
                 });
 
-        NetworkService ns = new NetworkService();
-        ns.setType(NetworkService.Type.CORE);
-        ns.setAddress(address);
-        serviceOps.register(ns);
+        serviceOps.register(getNetworkService());
     }
 }
diff --git 
a/ext/self-keymaster/client/src/main/java/org/apache/syncope/common/keymaster/client/self/SelfKeymasterServiceOps.java
 
b/ext/self-keymaster/client/src/main/java/org/apache/syncope/common/keymaster/client/self/SelfKeymasterServiceOps.java
index f969565..56fad28 100644
--- 
a/ext/self-keymaster/client/src/main/java/org/apache/syncope/common/keymaster/client/self/SelfKeymasterServiceOps.java
+++ 
b/ext/self-keymaster/client/src/main/java/org/apache/syncope/common/keymaster/client/self/SelfKeymasterServiceOps.java
@@ -85,7 +85,7 @@ public class SelfKeymasterServiceOps extends SelfKeymasterOps 
implements Service
             final BackOffExecution backOffExecution) {
 
         try {
-            if (retries > 0) {
+            if (action == Action.register && retries > 0) {
                 long nextBackoff = backOffExecution.nextBackOff();
 
                 LOG.debug("Still {} retries available for {}; waiting for {} 
ms", retries, service, nextBackoff);
@@ -97,7 +97,7 @@ public class SelfKeymasterServiceOps extends SelfKeymasterOps 
implements Service
 
                 retry(completionStage(action, service), service, action, 
retries - 1, backOffExecution);
             } else {
-                LOG.debug("No more retries for {}", service);
+                LOG.debug("No more retries {} for {}", action, service);
             }
         } catch (Throwable t) {
             LOG.error("Could not continue {} for {}, aborting", action, 
service, t);
diff --git a/sra/pom.xml b/sra/pom.xml
index ca1c5de..b9df9a8 100644
--- a/sra/pom.xml
+++ b/sra/pom.xml
@@ -77,6 +77,17 @@ under the License.
     </dependency>
 
     <dependency>
+      <groupId>org.apache.syncope.ext.self-keymaster</groupId>
+      <artifactId>syncope-ext-self-keymaster-client</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.syncope.common.keymaster</groupId>
+      <artifactId>syncope-common-keymaster-client-zookeeper</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.syncope.client.am</groupId>
       <artifactId>syncope-client-am-lib</artifactId>
       <version>${project.version}</version>
@@ -130,7 +141,7 @@ under the License.
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
         <configuration>
-          
<mainClass>org.apache.syncope.sra.SyncopeRemoteAccessApplication</mainClass>
+          <mainClass>org.apache.syncope.sra.SyncopeSRAApplication</mainClass>
         </configuration>
         <executions>
           <execution>
diff --git 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java 
b/sra/src/main/java/org/apache/syncope/sra/SyncopeSRAApplication.java
similarity index 91%
copy from 
sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
copy to sra/src/main/java/org/apache/syncope/sra/SyncopeSRAApplication.java
index 7112ac2..09c620d 100644
--- 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
+++ b/sra/src/main/java/org/apache/syncope/sra/SyncopeSRAApplication.java
@@ -25,10 +25,10 @@ import 
org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
 import org.springframework.context.annotation.Bean;
 
 @SpringBootApplication
-public class SyncopeRemoteAccessApplication {
+public class SyncopeSRAApplication {
 
     public static void main(final String[] args) {
-        SpringApplication.run(SyncopeRemoteAccessApplication.class, args);
+        SpringApplication.run(SyncopeSRAApplication.class, args);
     }
 
     @Bean
diff --git 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java 
b/sra/src/main/java/org/apache/syncope/sra/SyncopeSRAShutdown.java
similarity index 57%
copy from 
sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
copy to sra/src/main/java/org/apache/syncope/sra/SyncopeSRAShutdown.java
index 7112ac2..d335836 100644
--- 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
+++ b/sra/src/main/java/org/apache/syncope/sra/SyncopeSRAShutdown.java
@@ -18,21 +18,14 @@
  */
 package org.apache.syncope.sra;
 
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.gateway.route.RouteLocator;
-import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
-import org.springframework.context.annotation.Bean;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextClosedEvent;
 
-@SpringBootApplication
-public class SyncopeRemoteAccessApplication {
+public class SyncopeSRAShutdown extends SyncopeSRAStartStop
+        implements ApplicationListener<ContextClosedEvent> {
 
-    public static void main(final String[] args) {
-        SpringApplication.run(SyncopeRemoteAccessApplication.class, args);
-    }
-
-    @Bean
-    public RouteLocator routes(final RouteLocatorBuilder builder) {
-        return builder.routes().build();
+    @Override
+    public void onApplicationEvent(final ContextClosedEvent event) {
+        serviceOps.unregister(getNetworkService());
     }
 }
diff --git 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java 
b/sra/src/main/java/org/apache/syncope/sra/SyncopeSRAStartStop.java
similarity index 57%
copy from 
sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
copy to sra/src/main/java/org/apache/syncope/sra/SyncopeSRAStartStop.java
index 7112ac2..926a608 100644
--- 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
+++ b/sra/src/main/java/org/apache/syncope/sra/SyncopeSRAStartStop.java
@@ -18,21 +18,23 @@
  */
 package org.apache.syncope.sra;
 
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.gateway.route.RouteLocator;
-import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
-import org.springframework.context.annotation.Bean;
+import org.apache.syncope.common.keymaster.client.api.ServiceOps;
+import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 
-@SpringBootApplication
-public class SyncopeRemoteAccessApplication {
+abstract class SyncopeSRAStartStop {
 
-    public static void main(final String[] args) {
-        SpringApplication.run(SyncopeRemoteAccessApplication.class, args);
-    }
+    @Autowired
+    protected ServiceOps serviceOps;
+
+    @Value("${service.discovery.address}")
+    private String address;
 
-    @Bean
-    public RouteLocator routes(final RouteLocatorBuilder builder) {
-        return builder.routes().build();
+    protected NetworkService getNetworkService() {
+        NetworkService ns = new NetworkService();
+        ns.setType(NetworkService.Type.SRA);
+        ns.setAddress(address);
+        return ns;
     }
 }
diff --git 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java 
b/sra/src/main/java/org/apache/syncope/sra/SyncopeSRAStartup.java
similarity index 57%
rename from 
sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
rename to sra/src/main/java/org/apache/syncope/sra/SyncopeSRAStartup.java
index 7112ac2..08ea447 100644
--- 
a/sra/src/main/java/org/apache/syncope/sra/SyncopeRemoteAccessApplication.java
+++ b/sra/src/main/java/org/apache/syncope/sra/SyncopeSRAStartup.java
@@ -18,21 +18,14 @@
  */
 package org.apache.syncope.sra;
 
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.gateway.route.RouteLocator;
-import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
-import org.springframework.context.annotation.Bean;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
 
-@SpringBootApplication
-public class SyncopeRemoteAccessApplication {
+public class SyncopeSRAStartup extends SyncopeSRAStartStop
+        implements ApplicationListener<ContextRefreshedEvent> {
 
-    public static void main(final String[] args) {
-        SpringApplication.run(SyncopeRemoteAccessApplication.class, args);
-    }
-
-    @Bean
-    public RouteLocator routes(final RouteLocatorBuilder builder) {
-        return builder.routes().build();
+    @Override
+    public void onApplicationEvent(final ContextRefreshedEvent event) {
+        serviceOps.register(getNetworkService());
     }
 }
diff --git a/sra/src/main/resources/application.properties 
b/sra/src/main/resources/application.properties
index cc8c14b..98bc964 100644
--- a/sra/src/main/resources/application.properties
+++ b/sra/src/main/resources/application.properties
@@ -28,3 +28,5 @@ management.endpoint.metrics.enabled=true
 management.endpoints.web.exposure.include=*
 management.endpoint.prometheus.enabled=true
 management.metrics.export.prometheus.enabled=true
+
+service.discovery.address=http://localhost:8080/
diff --git a/sra/src/main/resources/application.properties 
b/sra/src/main/resources/keymaster.properties
similarity index 62%
copy from sra/src/main/resources/application.properties
copy to sra/src/main/resources/keymaster.properties
index cc8c14b..033fe3b 100644
--- a/sra/src/main/resources/application.properties
+++ b/sra/src/main/resources/keymaster.properties
@@ -14,17 +14,6 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-spring.application.name=Apache Syncope ${syncope.version} SRA
-spring.groovy.template.check-template-location=false
-spring.main.banner-mode=log
-
-server.port=8080
-
-management.endpoint.gateway.enabled=true
-management.endpoints.web.exposure.include=gateway
-
-spring.cloud.gateway.metrics.enabled=true
-management.endpoint.metrics.enabled=true
-management.endpoints.web.exposure.include=*
-management.endpoint.prometheus.enabled=true
-management.metrics.export.prometheus.enabled=true
+keymaster.address=http://localhost:9080/syncope/rest/keymaster
+keymaster.username=${anonymousUser}
+keymaster.password=${anonymousKey}

Reply via email to