[irish-monitor-service | WIP | CHANGED]: Monitor Service to work as standalone and as library (classifier library) at the same time.

1. pom.xml: Added plugin "maven-jar-plugin" and an <execution> with <classifier> library which creates a jar and excluded files from library setup.
2. UoaMonitorServiceApplication.java: Moved to package application and removed @EnableConfigurationProperties and @Import of other configurations (moved to UoaMonitorServiceConfiguration.java).
3. UoaMonitorServiceConfiguration.java: Added @EnableConfigurationProperties and @Import of configurations and @ComponentScan.
4. ServletInitializer.java: Moved to package application.
5. MonitorLibraryCheckDeployController.java: Added this copy of MonitorServiceCheckDeployController.java to be used only in library setup with @RequestMapping("/monitor-library").
This commit is contained in:
Konstantina Galouni 2023-12-01 10:19:20 +02:00
parent 9d585f12e0
commit c55d2836d7
5 changed files with 132 additions and 13 deletions

35
pom.xml
View File

@ -59,14 +59,26 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
<configuration>
<mainClass>eu.dnetlib.uoamonitorservice.UoaMonitorServiceApplication</mainClass>
<mainClass>eu.dnetlib.uoamonitorservice.application.UoaMonitorServiceApplication</mainClass>
<executable>true</executable>
<excludes>
<!-- <packagingExcludes>**/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.class</packagingExcludes>-->
<!-- <exclude>**/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.class</exclude>-->
</excludes>
</configuration>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<excludes>
<!-- <packagingExcludes>**/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.class</packagingExcludes>-->
<!-- <exclude>**/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.class</exclude>-->
</excludes>
</configuration>
</execution>
</executions>
</plugin>
@ -78,6 +90,27 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>library</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>library</classifier>
<excludes>
<exclude>**/eu/dnetlib/uoamonitorservice/application/**</exclude>
<exclude>**/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.class</exclude>
<exclude>**/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>uoa-monitor-service</finalName>
<resources>

View File

@ -1,13 +1,29 @@
package eu.dnetlib.uoamonitorservice;
import eu.dnetlib.uoaadmintoolslibrary.UoaAdminToolsLibraryConfiguration;
import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
import eu.dnetlib.uoamonitorservice.configuration.GlobalVars;
import eu.dnetlib.uoamonitorservice.configuration.properties.APIProperties;
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
import eu.dnetlib.uoanotificationservice.configuration.NotificationConfiguration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@EnableConfigurationProperties({ MongoConfig.class, GlobalVars.class, APIProperties.class})
@ComponentScan(basePackages = { "eu.dnetlib.uoamonitorservice" })
@Import({
AuthorizationConfiguration.class,
UoaAdminToolsLibraryConfiguration.class,
NotificationConfiguration.class
})
public class UoaMonitorServiceConfiguration extends WebMvcConfigurerAdapter {
private final Logger log = LogManager.getLogger(this.getClass());

View File

@ -1,4 +1,4 @@
package eu.dnetlib.uoamonitorservice;
package eu.dnetlib.uoamonitorservice.application;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

View File

@ -1,15 +1,7 @@
package eu.dnetlib.uoamonitorservice;
package eu.dnetlib.uoamonitorservice.application;
import eu.dnetlib.uoaadmintoolslibrary.UoaAdminToolsLibraryConfiguration;
import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
import eu.dnetlib.uoamonitorservice.configuration.GlobalVars;
import eu.dnetlib.uoamonitorservice.configuration.properties.APIProperties;
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
import eu.dnetlib.uoanotificationservice.configuration.NotificationConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
//uoahelptexts
@ -21,8 +13,6 @@ import org.springframework.context.annotation.PropertySources;
@PropertySource("classpath:monitorservice.properties"),
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
})
@EnableConfigurationProperties({ MongoConfig.class, GlobalVars.class, APIProperties.class})
@Import({AuthorizationConfiguration.class, UoaAdminToolsLibraryConfiguration.class, NotificationConfiguration.class})
public class UoaMonitorServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UoaMonitorServiceApplication.class, args);

View File

@ -0,0 +1,80 @@
package eu.dnetlib.uoamonitorservice.controllers;
import com.mongodb.BasicDBObject;
import com.mongodb.CommandResult;
import com.mongodb.DBObject;
import eu.dnetlib.uoamonitorservice.application.UoaMonitorServiceApplication;
import eu.dnetlib.uoamonitorservice.configuration.GlobalVars;
import eu.dnetlib.uoamonitorservice.configuration.mongo.MongoConnection;
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Conditional;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/monitor-library")
//@ConditionalOnBean(UoaMonitorServiceApplication.class)
public class MonitorLibraryCheckDeployController {
private final Logger log = LogManager.getLogger(this.getClass());
@Autowired
private MongoConnection mongoConnection;
@Autowired
private MongoConfig mongoConfig;
@Autowired
private GlobalVars globalVars;
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
public String hello() {
log.debug("Hello from uoa-monitor-service library!");
return "Hello from uoa-monitor-service library!";
}
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
public Map<String, String> checkEverything() {
Map<String, String> response = new HashMap<>();
MongoTemplate mt = mongoConnection.getMongoTemplate();
DBObject ping = new BasicDBObject("ping", "1");
try {
CommandResult answer = mt.getDb().command(ping);
response.put("Mongo try: error", answer.getErrorMessage());
} catch (Exception e) {
response.put("Mongo catch: error", e.getMessage());
}
response.put("monitorservice.mongodb.database", mongoConfig.getDatabase());
response.put("monitorservice.mongodb.host", mongoConfig.getHost());
response.put("monitorservice.mongodb.port", mongoConfig.getPort()+"");
response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
// response.put("Define also", "monitorservice.mongodb.username, monitorservice.mongodb.password");
if(globalVars.date != null) {
response.put("Date of deploy", globalVars.date.toString());
}
if(globalVars.getBuildDate() != null) {
response.put("Date of build", globalVars.getBuildDate());
}
if(globalVars.getVersion() != null) {
response.put("Version", globalVars.getVersion());
}
return response;
}
}