Skip to content

Commit

Permalink
Merge pull request #7788 from lpalashevski/new-omag-server
Browse files Browse the repository at this point in the history
OMAG server updates, add javadocs, change package name
  • Loading branch information
lpalashevski authored Jul 18, 2023
2 parents 8cb859c + 9b1f24d commit 49aeb43
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

# OMAG Server Chassis Spring

### This module is IN DEVELOPMENT
[More about content status](https://egeria-project.org/release-notes/content-status/)
![egeria-content-status-in-development.png](..%2F..%2F..%2Fimages%2Fegeria-content-status-in-development.png)

This module is providing OMAG server chassis spring-boot based application that is able to launch single pre-configured OMAG server instance.

Expand All @@ -19,7 +18,7 @@ To build current module from the project home folder execute following Gradle co
To start the OMAG Server application manually using java from the project home, execute following bash command:

```bash
# Go to project home folder'
# Go to project home folder
cd ../../../
# Execute java using -jar parameter starting the bootJar package and --omag.server.config setting the location of the OMAG server configuration file
java -jar open-metadata-implementation/server-chassis/server-chassis-spring/build/libs/server-chassis-spring-*-SNAPSHOT.jar --omag.server.config=file:open-metadata-implementation/server-chassis/server-chassis-spring/src/main/resources/metadata-repository-server.json
Expand All @@ -28,4 +27,4 @@ Alternately, for development purpose in IDE such as IntelliJ you can use default

### Application Properties

`omag.server.config` - The OMAG server configuration JSON file location. Notice the 'file:' prefix. With this, spring-boot loads the resource form a file on a given path on the filesystem.
`omag.server.config` - The OMAG server configuration JSON file location. Notice the 'file:' prefix. With this, spring-boot loads the resource from a file on a given path on the filesystem.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.server;
package org.odpi.openmetadata.serverchassis.springboot;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.odpi.openmetadata.adminservices.configuration.properties.OMAGServerConfig;
Expand Down Expand Up @@ -30,17 +30,19 @@
import java.nio.file.Path;
import java.util.List;

/**
* OMAGServer provides the main program for the OMAG Server spring-boot based starter application.
*/
@SpringBootApplication(
scanBasePackages = {"org.odpi.openmetadata"}
)
//TODO: ADD JAVADOCS!!!
public class OMAGServer {

private static final Logger LOG = LoggerFactory.getLogger(OMAGServer.class);
private final OMAGServerOperationalServices operationalServices;

@Value("${startup.user:system}")
String sysUser;
@Value("${omag.server.user:system}")
String omagServerUser;

@Value("${omag.server.config}")
Resource omagServerConfigLocation;
Expand All @@ -50,7 +52,10 @@ public class OMAGServer {
private String serverName = null;
private OMAGServerConfig serverConfig = null;


/**
* Default constructor.
* Creates instance of OMAG operational services.
*/
public OMAGServer() {
this.operationalServices = new OMAGServerOperationalServices();
}
Expand All @@ -67,33 +72,52 @@ public void onApplicationEvent(ApplicationEvent applicationEvent) {
.sources(OMAGServer.class).run(args);
}


/**
* Handling Spring Boot ApplicationReadyEvent
*/
@EventListener(ApplicationReadyEvent.class)
private void onApplicationReadyEvent() {
LOG.info("{} is accepting traffic.", serverName);
}

/**
* Handling Spring Boot ApplicationStartedEvent
* This handler calls the method for OMAGServerConfig loading.
*
* @link loadServerConfig
*/
@EventListener(ApplicationStartedEvent.class)
private void onApplicationStartedEvent() throws Exception {
LOG.debug("Application started.");
loadServerConfig();
}

/**
* Handling Spring Boot ApplicationFailedEvent
*/
@EventListener(ApplicationFailedEvent.class)
private void onApplicationFailedEvent() {
LOG.debug("Application failed.");
}

/**
* Handling Spring Boot ContextClosedEvent
* This handler provides a way to hook to the standard Spring Boot application shut-down event and call OMAG operational services to deactivate the OMAG server instance.
*/
@EventListener(ContextClosedEvent.class)
private void onContextClosedEvent() {
LOG.debug("Application stopped.");

if (serverName != null) {
LOG.info("Application stopped, deactivating server {}", serverName);
operationalServices.deactivateTemporarilyServerList(sysUser, List.of(serverName));
operationalServices.deactivateTemporarilyServerList(omagServerUser, List.of(serverName));
}
}

/**
* This method activates single OMAGServer instance with supplied OMAGServerConfig document.
* Depending on the outcome of activation call, it will change the application availability state.
*/
private void activateOMAGServerUsingPlatformServices() {

LOG.info("Activation started for {}", serverName);
Expand All @@ -110,7 +134,7 @@ private void activateOMAGServerUsingPlatformServices() {
LOG.info("Activation started, request sent for server {}", serverName);

SuccessMessageResponse response = operationalServices
.activateWithSuppliedConfig(sysUser.trim(), serverConfig.getLocalServerName(), serverConfig);
.activateWithSuppliedConfig(omagServerUser.trim(), serverConfig.getLocalServerName(), serverConfig);

if (response == null) {
LOG.info("Activation has failed. The cause is that response is null.");
Expand Down Expand Up @@ -139,6 +163,10 @@ private void activateOMAGServerUsingPlatformServices() {

}

/**
* This method loads the OMAGServerConfig document from location provided by 'omag.server.config' application property defined as spring Resource.
* @see org.springframework.core.io.Resource
*/
private void loadServerConfig() {


Expand All @@ -154,7 +182,7 @@ private void loadServerConfig() {
LOG.trace("Configuration from path: {} is being parsed.", Files.readString(Path.of(omagServerConfigLocation.getFile().getPath())));
serverConfig = objectMapper.reader().readValue(omagServerConfigLocation.getFile(), OMAGServerConfig.class);
serverName = serverConfig.getLocalServerName();
LOG.info("Configuration loading from document for OMAG server {} succeded", serverName);
LOG.info("Configuration loading from document for OMAG server {} succeeded", serverName);

} catch (IOException e) {
LOG.error("Failed loading OMAG server configuration with exception message : {}", e.getMessage());
Expand All @@ -165,6 +193,10 @@ private void loadServerConfig() {
}
}

/**
* Application Runner implementation class.
* The purpose of this class is to provide a standard way to run the OMAG server activation task, separate from the main application tread.
*/
@Component
public class OMAGServerStartup implements ApplicationRunner {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.server.config;
package org.odpi.openmetadata.serverchassis.springboot.config;

import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.availability.LivenessStateHealthIndicator;
Expand All @@ -14,6 +14,9 @@
import org.springframework.context.annotation.Configuration;


/**
* This class provides configuration for Application Availability support components.
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(ApplicationAvailabilityAutoConfiguration.class)
public class AvailabilityProbesAutoConfiguration {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.server.config;
package org.odpi.openmetadata.serverchassis.springboot.config;


import com.fasterxml.jackson.databind.DeserializationFeature;
Expand All @@ -16,6 +16,9 @@

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

/**
* This class provides configuration bean for customizing Jackson object mapper singleton instance configuration.
*/
@Configuration
public class ObjectMapperConfiguration {
public static final String PREFIX = "Object mapper configuration started.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.server.config;
package org.odpi.openmetadata.serverchassis.springboot.config;

import org.odpi.openmetadata.http.HttpHelper;
import org.slf4j.Logger;
Expand All @@ -11,8 +11,11 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
* This class provides configuration bean for customizing the SSL environment used by java.net.ssl and Tomcat server ssl.
*/
@Configuration
public class InitializingBeanConfig {
public class SSLEnvironmentConfiguration {
public static final String PREFIX = "SSL configuration started";

private final Logger log = LoggerFactory.getLogger(this.getClass());
Expand All @@ -31,7 +34,7 @@ public class InitializingBeanConfig {
@Value("${server.ssl.enabled:true}")
Boolean serverSSL;

public InitializingBeanConfig(Environment env) {
public SSLEnvironmentConfiguration(Environment env) {
this.env = env;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */

/**
* This package contains classes relevant for spring configuration bootstrapping.
*/
package org.odpi.openmetadata.serverchassis.springboot.config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */

/**
* This package contains classes relevant for OMAG server spring boot based starter application.
*/
package org.odpi.openmetadata.serverchassis.springboot;
Loading

0 comments on commit 49aeb43

Please sign in to comment.