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-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;
|
2019-12-11 11:02:31 +01:00
|
|
|
import org.springframework.context.ApplicationEventPublisher;
|
2018-11-14 13:58:27 +01:00
|
|
|
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-12-11 11:02:31 +01:00
|
|
|
import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.EventHandlingInit;
|
2018-11-14 13:58:27 +01:00
|
|
|
|
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-12-05 17:05:50 +01:00
|
|
|
static final Logger INIT_LOGGER = LoggerFactory.getLogger("SEB SERVER INIT");
|
|
|
|
|
|
|
|
private final Environment environment;
|
|
|
|
private final WebserviceInfo webserviceInfo;
|
|
|
|
private final AdminUserInitializer adminUserInitializer;
|
2019-12-11 11:02:31 +01:00
|
|
|
private final ApplicationEventPublisher applicationEventPublisher;
|
2019-12-05 17:05:50 +01:00
|
|
|
|
|
|
|
protected WebserviceInit(
|
|
|
|
final Environment environment,
|
|
|
|
final WebserviceInfo webserviceInfo,
|
2019-12-11 11:02:31 +01:00
|
|
|
final AdminUserInitializer adminUserInitializer,
|
|
|
|
final ApplicationEventPublisher applicationEventPublisher) {
|
2019-12-05 17:05:50 +01:00
|
|
|
|
|
|
|
this.environment = environment;
|
|
|
|
this.webserviceInfo = webserviceInfo;
|
|
|
|
this.adminUserInitializer = adminUserInitializer;
|
2019-12-11 11:02:31 +01:00
|
|
|
this.applicationEventPublisher = applicationEventPublisher;
|
2019-12-05 17:05:50 +01:00
|
|
|
}
|
2019-03-07 12:10:48 +01:00
|
|
|
|
2018-11-14 13:58:27 +01:00
|
|
|
@Override
|
|
|
|
public void onApplicationEvent(final ApplicationReadyEvent event) {
|
2019-12-05 17:05:50 +01:00
|
|
|
INIT_LOGGER.info("----> ___ ___ ___ ___ ");
|
|
|
|
INIT_LOGGER.info("----> / __|| __|| _ ) / __| ___ _ _ __ __ ___ _ _ ");
|
|
|
|
INIT_LOGGER.info("----> \\__ \\| _| | _ \\ \\__ \\/ -_)| '_|\\ V // -_)| '_|");
|
|
|
|
INIT_LOGGER.info("----> |___/|___||___/ |___/\\___||_| \\_/ \\___||_| ");
|
|
|
|
INIT_LOGGER.info("---->");
|
2019-12-11 11:15:35 +01:00
|
|
|
INIT_LOGGER.info("----> Webservice");
|
|
|
|
INIT_LOGGER.info("---->");
|
2019-12-11 11:02:31 +01:00
|
|
|
INIT_LOGGER.info("----> Starting up...");
|
|
|
|
|
|
|
|
INIT_LOGGER.info("----> ");
|
|
|
|
INIT_LOGGER.info("----> Init Databse with flyway...");
|
|
|
|
INIT_LOGGER.info("----> TODO ");
|
|
|
|
|
|
|
|
// TODO integration of Flyway for database initialization and migration: https://flywaydb.org
|
|
|
|
// see also https://flywaydb.org/getstarted/firststeps/api
|
|
|
|
|
|
|
|
INIT_LOGGER.info("----> ");
|
|
|
|
INIT_LOGGER.info("----> Init SEB Server Administrator account if needed...");
|
|
|
|
// Create an initial admin account if requested and not already in the data-base
|
|
|
|
this.adminUserInitializer.initAdminAccount();
|
|
|
|
|
|
|
|
INIT_LOGGER.info("----> ");
|
|
|
|
INIT_LOGGER.info("----> Start Services...");
|
|
|
|
INIT_LOGGER.info("----> ");
|
|
|
|
this.applicationEventPublisher.publishEvent(new EventHandlingInit(this));
|
|
|
|
INIT_LOGGER.info("----> ");
|
|
|
|
|
2019-12-05 17:05:50 +01:00
|
|
|
INIT_LOGGER.info("----> SEB Server successfully started up!");
|
|
|
|
INIT_LOGGER.info("---->");
|
2019-12-09 12:06:14 +01:00
|
|
|
INIT_LOGGER.info("----> Version: {}", this.webserviceInfo.getSebServerVersion());
|
2019-12-05 17:05:50 +01:00
|
|
|
|
2019-03-07 12:10:48 +01:00
|
|
|
try {
|
2019-12-09 12:06:14 +01:00
|
|
|
INIT_LOGGER.info("----> Server address: {}", this.environment.getProperty("server.address"));
|
|
|
|
INIT_LOGGER.info("----> Server port: {}", this.environment.getProperty("server.port"));
|
|
|
|
INIT_LOGGER.info("---->");
|
|
|
|
INIT_LOGGER.info("----> Local-Host address: {}", InetAddress.getLocalHost().getHostAddress());
|
|
|
|
INIT_LOGGER.info("----> Local-Host name: {}", InetAddress.getLocalHost().getHostName());
|
|
|
|
INIT_LOGGER.info("---->");
|
|
|
|
INIT_LOGGER.info("----> Remote-Host address: {}", InetAddress.getLoopbackAddress().getHostAddress());
|
|
|
|
INIT_LOGGER.info("----> Remote-Host name: {}", InetAddress.getLoopbackAddress().getHostName());
|
2019-03-07 12:10:48 +01:00
|
|
|
} catch (final UnknownHostException e) {
|
2019-12-11 11:02:31 +01:00
|
|
|
INIT_LOGGER.error("Unknown Host: ", e);
|
2019-03-07 12:10:48 +01:00
|
|
|
}
|
|
|
|
|
2019-12-11 11:02:31 +01:00
|
|
|
INIT_LOGGER.info("---->");
|
|
|
|
INIT_LOGGER.info("----> External-Host URL: {}", this.webserviceInfo.getExternalServerURL());
|
|
|
|
INIT_LOGGER.info("----> LMS-External-Address-Alias: {}", this.webserviceInfo.getLmsExternalAddressAlias());
|
2019-12-09 12:06:14 +01:00
|
|
|
INIT_LOGGER.info("---->");
|
|
|
|
INIT_LOGGER.info("----> HTTP Scheme {}", this.webserviceInfo.getHttpScheme());
|
2019-12-11 11:02:31 +01:00
|
|
|
INIT_LOGGER.info("---->");
|
2019-12-09 12:06:14 +01:00
|
|
|
INIT_LOGGER.info("----> Property Override Test: {}", this.webserviceInfo.getTestProperty());
|
2019-07-18 12:35:36 +02:00
|
|
|
|
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() {
|
2019-12-11 11:02:31 +01:00
|
|
|
INIT_LOGGER.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
|
|
|
}
|