2018-11-14 13:58:27 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package ch.ethz.seb.sebserver.webservice;
|
|
|
|
|
2019-03-07 12:10:48 +01:00
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
2019-11-20 15:08:59 +01:00
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
|
2018-11-14 13:58:27 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2019-03-07 12:10:48 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2019-02-04 18:28:31 +01:00
|
|
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
2018-11-14 13:58:27 +01:00
|
|
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
|
|
|
import org.springframework.context.ApplicationListener;
|
2019-02-04 18:28:31 +01:00
|
|
|
import org.springframework.context.annotation.Import;
|
2019-03-07 12:10:48 +01:00
|
|
|
import org.springframework.core.env.Environment;
|
2019-11-20 15:08:59 +01:00
|
|
|
import org.springframework.stereotype.Component;
|
2018-11-14 13:58:27 +01:00
|
|
|
|
|
|
|
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
|
|
|
|
2019-11-20 15:08:59 +01:00
|
|
|
@Component
|
2018-11-14 13:58:27 +01:00
|
|
|
@WebServiceProfile
|
2019-02-04 18:28:31 +01:00
|
|
|
@Import(DataSourceAutoConfiguration.class)
|
2019-11-20 15:08:59 +01:00
|
|
|
public class WebserviceInit implements ApplicationListener<ApplicationReadyEvent> {
|
2018-11-14 13:58:27 +01:00
|
|
|
|
2019-11-20 15:08:59 +01:00
|
|
|
private static final Logger log = LoggerFactory.getLogger(WebserviceInit.class);
|
2018-11-14 13:58:27 +01:00
|
|
|
|
2019-03-07 12:10:48 +01:00
|
|
|
@Autowired
|
|
|
|
private Environment environment;
|
2019-07-18 12:35:36 +02:00
|
|
|
@Autowired
|
|
|
|
private WebserviceInfo webserviceInfo;
|
2019-03-07 12:10:48 +01:00
|
|
|
|
2018-11-14 13:58:27 +01:00
|
|
|
@Override
|
|
|
|
public void onApplicationEvent(final ApplicationReadyEvent event) {
|
|
|
|
log.info("Initialize SEB-Server Web-Service Component");
|
|
|
|
|
2019-03-07 12:10:48 +01:00
|
|
|
try {
|
|
|
|
log.info("----> config server address: {}", this.environment.getProperty("server.address"));
|
|
|
|
log.info("----> config server port: {}", this.environment.getProperty("server.port"));
|
|
|
|
|
|
|
|
log.info("----> local host address: {}", InetAddress.getLocalHost().getHostAddress());
|
|
|
|
log.info("----> local host name: {}", InetAddress.getLocalHost().getHostName());
|
|
|
|
|
|
|
|
log.info("----> remote host address: {}", InetAddress.getLoopbackAddress().getHostAddress());
|
2019-07-18 12:35:36 +02:00
|
|
|
log.info("----> remote host name: {}", InetAddress.getLoopbackAddress().getHostName());
|
2019-03-07 12:10:48 +01:00
|
|
|
} catch (final UnknownHostException e) {
|
|
|
|
log.error("Unknown Host: ", e);
|
|
|
|
}
|
|
|
|
|
2019-07-18 12:35:36 +02:00
|
|
|
log.info("{}", this.webserviceInfo);
|
|
|
|
|
2019-11-20 15:08:59 +01:00
|
|
|
// TODO integration of Flyway for database initialization and migration: https://flywaydb.org
|
|
|
|
// see also https://flywaydb.org/getstarted/firststeps/api
|
2018-11-14 13:58:27 +01:00
|
|
|
|
|
|
|
}
|
2019-02-04 18:28:31 +01:00
|
|
|
|
2019-11-20 15:08:59 +01:00
|
|
|
@PreDestroy
|
|
|
|
public void gracefulShutdown() {
|
|
|
|
log.info("**** Gracefully Shutdown of SEB Server instance {} ****", this.webserviceInfo.getHostAddress());
|
2019-04-23 12:34:11 +02:00
|
|
|
}
|
2019-07-18 12:35:36 +02:00
|
|
|
|
2018-11-14 13:58:27 +01:00
|
|
|
}
|