2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia;
19 import java.util.concurrent.Callable;
20 import java.util.concurrent.ExecutorService;
21 import java.util.concurrent.Executors;
22 import java.util.concurrent.Future;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager;
26 import org.slf4j.Logger;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.boot.SpringApplication;
29 import org.springframework.boot.autoconfigure.SpringBootApplication;
30 import org.springframework.boot.context.event.ApplicationReadyEvent;
31 import org.springframework.context.ApplicationListener;
32 import org.springframework.context.annotation.Profile;
33 import org.springframework.context.event.ContextClosedEvent;
34 import org.springframework.stereotype.Component;
36 import static java.util.concurrent.Executors.newCachedThreadPool;
38 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
39 import static org.slf4j.LoggerFactory.getLogger;
42 * Represents the spring boot application
44 @SpringBootApplication
45 public class NokiaSvnfmApplication {
46 private static Logger logger = getLogger(NokiaSvnfmApplication.class);
49 * Entry point for the Spring boot application
51 * @param args arguments for the application (not used)
53 public static void main(String[] args) {
54 systemFunctions().newSpringApplication(NokiaSvnfmApplication.class).run(args);
58 * Responsible for starting the self registration process after the servlet has been started
59 * and is ready to answer REST request
60 * - has been disabled in the test because the application that provides the ONAP simulator
61 * has already not yet been started (can not answer REST requests)
65 public static class SelfRegistrationTrigger implements ApplicationListener<ApplicationReadyEvent> {
66 private final SelfRegistrationManager selfRegistrationManager;
67 private final JobManager jobManager;
69 * Runs the registration process
71 private ExecutorService executorService = newCachedThreadPool();
74 SelfRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager){
75 this.jobManager = jobManager;
76 this.selfRegistrationManager = selfRegistrationManager;
80 public void onApplicationEvent(ApplicationReadyEvent contextRefreshedEvent) {
81 Callable<Boolean> singleRegistration = () -> {
82 logger.info("Self registration started");
84 selfRegistrationManager.register();
85 logger.info("Self registration finished");
86 } catch (RuntimeException e) {
87 logger.error("Self registration failed", e);
92 executorService.submit(() -> {
93 while(!jobManager.isPreparingForShutDown()){
95 executorService.submit(singleRegistration).get();
96 //registration successful
100 logger.warn("Unable to execute self registration process", e);
102 systemFunctions().sleep(5000);
109 * Responsible for starting the un-registration process after the service has been ramped down
110 * - has been disabled in test because the same application that provides the ONAP simulator
111 * has already been ramped down (can not answer REST requests)
115 public static class SelfDeRegistrationTrigger implements ApplicationListener<ContextClosedEvent> {
116 private final SelfRegistrationManager selfRegistrationManager;
117 private final JobManager jobManager;
120 SelfDeRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager){
121 this.jobManager = jobManager;
122 this.selfRegistrationManager = selfRegistrationManager;
126 public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
127 logger.info("Self de-registration started");
129 jobManager.prepareForShutdown();
130 selfRegistrationManager.deRegister();
131 } catch (RuntimeException e) {
132 logger.error("Self de-registration failed", e);
135 logger.info("Self de-registration finished");