From e0d6ec6fc37bbcac731870a44c98c113efdf4e5c Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Mon, 6 Nov 2023 13:33:14 +0200 Subject: [PATCH] Initial commit (cherry picked from commit 0ca7c8b9d82da8081f6dbd598fab8dd8e8710014) --- .gitignore | 4 + Dockerfile.centrallog | 6 + pom.xml | 209 ++++++++++++++++++ .../centrallog/service/CentralLogService.java | 56 +++++ .../service/CentralLoggerConfig.java | 45 ++++ .../service/CentralLoggerRouteBuilder.java | 73 ++++++ src/main/resources/application.yml | 39 ++++ src/main/resources/bootstrap.yml | 0 src/main/resources/logback.xml | 60 +++++ 9 files changed, 492 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile.centrallog create mode 100644 pom.xml create mode 100644 src/main/java/org/etsi/osl/centrallog/service/CentralLogService.java create mode 100644 src/main/java/org/etsi/osl/centrallog/service/CentralLoggerConfig.java create mode 100644 src/main/java/org/etsi/osl/centrallog/service/CentralLoggerRouteBuilder.java create mode 100644 src/main/resources/application.yml create mode 100644 src/main/resources/bootstrap.yml create mode 100644 src/main/resources/logback.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5601d3b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target/ +.project +.classpath +/.settings diff --git a/Dockerfile.centrallog b/Dockerfile.centrallog new file mode 100644 index 0000000..3fe8ac2 --- /dev/null +++ b/Dockerfile.centrallog @@ -0,0 +1,6 @@ +FROM ibm-semeru-runtimes:open-17.0.7_7-jdk +MAINTAINER openslice.io +RUN mkdir /opt/shareclasses +RUN mkdir -p /opt/openslice/lib/ +COPY target/org.etsi.osl.centrallog.service-1.2.0-SNAPSHOT.jar /opt/openslice/lib/ +CMD ["java", "-Xshareclasses:cacheDir=/opt/shareclasses", "-jar", "/opt/openslice/lib/org.etsi.osl.centrallog.service-1.2.0-SNAPSHOT.jar"] \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e7c5e5b --- /dev/null +++ b/pom.xml @@ -0,0 +1,209 @@ + + + 4.0.0 + + + org.etsi.osl + org.etsi.osl.main + 1.2.0-SNAPSHOT + ../org.etsi.osl.main + + + org.etsi.osl.centrallog.service + org.etsi.osl.centrallog.service + + + UTF-8 + UTF-8 + ${spring-boot-version} + ${spring-cloud-consul-version} + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot-version} + pom + import + + + + org.apache.camel.springboot + camel-spring-boot-dependencies + ${camel.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-cache + + + + org.apache.camel.springboot + camel-undertow-starter + + + org.springframework.boot + spring-boot-starter-undertow + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-bootstrap + 3.0.2 + + + + + + + + org.springframework.boot + spring-boot-starter-activemq + + + org.apache.activemq + activemq-amqp + test + + + org.apache.qpid + proton-j + + + + + org.messaginghub + pooled-jms + + + + + + org.apache.camel.springboot + camel-spring-boot-starter + + + org.apache.activemq + activemq-pool + + + org.apache.camel + camel-activemq + + + org.apache.activemq + activemq-broker + + + + + org.apache.camel.springboot + camel-service-starter + + + + org.apache.camel.springboot + camel-http-starter + + + org.apache.camel + camel-jackson + + + org.apache.camel + camel-http-common + + + org.apache.camel + camel-stream + + + com.h2database + h2 + + + + + org.etsi.osl + org.etsi.osl.model + ${project.version} + + + org.etsi.osl + org.etsi.osl.tmf.api + ${project.version} + + + + + com.fasterxml.jackson.core + jackson-databind + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-version} + + + + repackage + + + + + + + + + + + diff --git a/src/main/java/org/etsi/osl/centrallog/service/CentralLogService.java b/src/main/java/org/etsi/osl/centrallog/service/CentralLogService.java new file mode 100644 index 0000000..c4b34df --- /dev/null +++ b/src/main/java/org/etsi/osl/centrallog/service/CentralLogService.java @@ -0,0 +1,56 @@ +package org.etsi.osl.centrallog.service; + +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.bugzilla + * %% + * Copyright (C) 2019 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.context.config.annotation.RefreshScope; + + +/** + * @author ichatzis + * + * based on + * https://github.com/apache/camel/tree/master/examples/camel-example-spring-boot-activemq + * https://github.com/indrabasak/spring-consul-example + */ +// This is equivalent to @Configuration, @EnableAutoConfiguration, and @ComponentScan +@SpringBootApplication +// This annotation is used for consul +@EnableDiscoveryClient +//@EnableRetry +// This is from spring-cloud to allow local configuration application +@RefreshScope +// @EnableAutoConfiguration annotation tells Spring Boot to "guess" how you will want to configure Spring, +// based on the jar dependencies that you have added. For example, If HSQLDB is on your classpath, and you +// have not manually configured any database connection beans, then Spring will auto-configure an in-memory database. +@EnableAutoConfiguration +// This is enabled by default +@EnableConfigurationProperties +public class CentralLogService { + public static void main(String[] args) { + SpringApplication.run( CentralLogService.class, args); + } +} diff --git a/src/main/java/org/etsi/osl/centrallog/service/CentralLoggerConfig.java b/src/main/java/org/etsi/osl/centrallog/service/CentralLoggerConfig.java new file mode 100644 index 0000000..756d141 --- /dev/null +++ b/src/main/java/org/etsi/osl/centrallog/service/CentralLoggerConfig.java @@ -0,0 +1,45 @@ +package org.etsi.osl.centrallog.service; + +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.portal.api + * %% + * Copyright (C) 2019 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +/** + * @author ichatzis + **/ + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties +@ConfigurationProperties +public class CentralLoggerConfig { + + + private String centrallogurl; + + public String getCentrallogurl() { + return centrallogurl; + } + + public void setCentrallogurl(String centrallogurl) { + this.centrallogurl = centrallogurl; + } +} diff --git a/src/main/java/org/etsi/osl/centrallog/service/CentralLoggerRouteBuilder.java b/src/main/java/org/etsi/osl/centrallog/service/CentralLoggerRouteBuilder.java new file mode 100644 index 0000000..60b6bc9 --- /dev/null +++ b/src/main/java/org/etsi/osl/centrallog/service/CentralLoggerRouteBuilder.java @@ -0,0 +1,73 @@ +package org.etsi.osl.centrallog.service; +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.portal.api + * %% + * Copyright (C) 2019 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +/** + * @author ichatzis + **/ + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +@Configuration +@Component +public class CentralLoggerRouteBuilder extends RouteBuilder{ + + + private static String CENTRALLOGGERURL = ""; + + @Autowired + private CentralLoggerConfig centrallogerconfig; + private static final transient Log logger = LogFactory.getLog( CentralLoggerRouteBuilder.class.getName()); + + public void configure() { + + + if ( centrallogerconfig.getCentrallogurl() != null) { + CENTRALLOGGERURL = centrallogerconfig.getCentrallogurl(); + } + + if ( ( CENTRALLOGGERURL == null ) || CENTRALLOGGERURL.equals( "" ) ){ + logger.info( "NO CENTRALLOGGERURL ROUTING. ELASTICURL = " + CENTRALLOGGERURL); + return; + } + logger.info( "ENABLED CENTRALLOGGERURL ROUTING. ELASTICURL = " + CENTRALLOGGERURL); + + String url = CENTRALLOGGERURL; + + from("activemq:queue:centrallogger.log") + .log( "activemq:queue:centrallogger.log package with body ${body} !" ) + .setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http.HttpMethods.POST)) + .setHeader("Content-Type", constant("application/json")) + .to("log:DEBUG?showBody=true&showHeaders=true") + .doTry() + .toD( url ) + .to("log:DEBUG?showBody=true&showHeaders=true") + .doCatch(Exception.class) + .setBody(exceptionMessage().convertToString()) + .to("log:DEBUG?showBody=true&showHeaders=true") + .end(); + } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..67fb3f7 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,39 @@ + +# For Spring Actuator /info endpoint +info: + artifact: centrallog-service + name: centrallog-service + description: Spring centrallog-service + version: 1.0.0 + +server: + port: 13013 + + +logging: + level: + org.apache.camel: INFO + file: logs/application-debug.log + pattern: + console: "%d %-5level %logger : %msg%n" + file: "%d %-5level [%thread] %logger : %msg%n" + + +spring: + config: + activate: + on-profile: "default" + application: + name: centrallog-service + activemq: + brokerUrl: tcp://localhost:61616?jms.watchTopicAdvisories=false + user: artemis + password: artemis + pool: + enabled: true + max-connections: 100 + packages: + trust-all: true + +centrallogurl: "http://elk_ip:elk_port/index_name/_doc" + diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..208c635 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + app.log + + + logs/archived/app.%d{yyyy-MM-dd}.%i.log + + 10MB + + 20GB + + 60 + + + + %d %p %c{1.} [%t] %m%n + + + + + + + + + + + -- GitLab