Skip to content

Commit

Permalink
feat: (DHEI-15120) - Introduce clean schemastore usage
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisingenhaag committed Feb 28, 2024
1 parent dd750e6 commit de50788
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 451 deletions.
38 changes: 17 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import org.springframework.boot.gradle.plugin.SpringBootPlugin

plugins {
id 'org.springframework.boot' version '3.2.2'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
id 'java'
id "org.sonarqube" version "4.4.1.3373"
id "jacoco"
}

Expand Down Expand Up @@ -44,27 +43,13 @@ configurations {
}
}

ext {
repoBase = System.getenv("PANDORA_ARTIFACTORY_GRADLE_CONTEXT") ?: "$artifactory_contextUrl"
repositories {
mavenCentral()
}

repositories {
maven {
credentials {
username System.getenv('PANDORA_ARTIFACTORY_GRADLE_USERNAME') ?: "$artifactory_user"
password System.getenv('PANDORA_ARTIFACTORY_GRADLE_PASSWORD') ?: "$artifactory_password"
}
url "$repoBase/maven-central"
}
maven {
credentials {
username System.getenv('PANDORA_ARTIFACTORY_GRADLE_USERNAME') ?: "$artifactory_user"
password System.getenv('PANDORA_ARTIFACTORY_GRADLE_PASSWORD') ?: "$artifactory_password"
}
url "$repoBase/dhei-pandora-gradle"
}
maven { url 'https://repo.spring.io/milestone' }
mavenLocal()
ext {
// this is internal, overwrite with your specific implementation if you want
schemalValidationImplDependency = System.getenv('ADDITIONAL_SCHEMASTORE_IMPL') ?: ""
}

dependencies {
Expand All @@ -82,6 +67,9 @@ dependencies {
testImplementation 'org.springframework.kafka:spring-kafka-test'
testImplementation 'org.springframework.security:spring-security-test'

testImplementation 'commons-codec:commons-codec:1.16.1'


// 3rd party
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation ("com.github.erosb:everit-json-schema:${everitJsonVersion}") {
Expand All @@ -97,13 +85,21 @@ dependencies {
// Telekom Integration Platform
implementation "de.telekom.eni:horizon-spring-boot-starter:${horizonParentVersion}"

// optional
if (!schemalValidationImplDependency.allWhitespace) {
implementation "${schemalValidationImplDependency}"
}

testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
}

dependencyManagement {
imports {
mavenBom SpringBootPlugin.BOM_COORDINATES
if (!schemalValidationImplDependency.allWhitespace) {
mavenBom "${schemalValidationImplDependency}"
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
everitJsonVersion=1.14.4
horizonParentVersion=3.2.1
horizonParentVersion=0.0.0-main-SNAPSHOT
18 changes: 1 addition & 17 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,8 @@
// SPDX-License-Identifier: Apache-2.0

pluginManagement {
ext {
repoBase = System.getenv("PANDORA_ARTIFACTORY_GRADLE_CONTEXT") ?: "$artifactory_contextUrl"
}
repositories {
maven {
credentials {
username System.getenv('PANDORA_ARTIFACTORY_GRADLE_USERNAME') ?: "$artifactory_user"
password System.getenv('PANDORA_ARTIFACTORY_GRADLE_PASSWORD') ?: "$artifactory_password"
}
url "$repoBase/maven-central"
}
maven {
credentials {
username System.getenv('PANDORA_ARTIFACTORY_GRADLE_USERNAME') ?: "$artifactory_user"
password System.getenv('PANDORA_ARTIFACTORY_GRADLE_PASSWORD') ?: "$artifactory_password"
}
url "$repoBase/gradle-plugins-cache/"
}
mavenCentral()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import de.telekom.eni.pandora.horizon.model.event.Event;
import de.telekom.eni.pandora.horizon.tracing.HorizonTracer;
import de.telekom.eni.pandora.horizon.victorialog.client.VictoriaLogClient;
import de.telekom.eni.pandora.horizon.victorialog.model.HTTPHeader;
import de.telekom.eni.pandora.horizon.victorialog.model.Observation;
import de.telekom.horizon.starlight.exception.HorizonStarlightException;
import de.telekom.horizon.starlight.service.PublisherService;
import de.telekom.horizon.starlight.service.TokenService;
Expand Down Expand Up @@ -37,20 +34,16 @@ public class EventController {

private final HorizonTracer tracer;

private final VictoriaLogClient victoriaLogClient;

private final ReportingService reportingService;

@Autowired
EventController(TokenService tokenService,
PublisherService publisherService,
HorizonTracer tracer,
VictoriaLogClient victoriaLogClient,
ReportingService reportingService) {
this.tokenService = tokenService;
this.publisherService = publisherService;
this.tracer = tracer;
this.victoriaLogClient = victoriaLogClient;
this.reportingService = reportingService;
}

Expand All @@ -63,12 +56,6 @@ public ResponseEntity<Void> headRequest(@PathVariable String environment) {
public ResponseEntity<Event> publishEvent(@RequestBody Event event,
@PathVariable String environment,
@RequestHeader MultiValueMap<String, String> httpHeaders) throws HorizonStarlightException {


var observation = createObservationFromEvent(event);

httpHeaders.add(HTTPHeader.TRACK_LATENCY.getValue(), observation.isEmpty() ? "0": "1");

addTracingTags(event);

publisherService.checkRealm(tokenService.getRealm(), environment);
Expand All @@ -78,24 +65,9 @@ public ResponseEntity<Event> publishEvent(@RequestBody Event event,

reportingService.markEventProduced(event);

observation.ifPresent(v -> {
victoriaLogClient.finishAndAddObservation(v);
victoriaLogClient.countEvent(event);
});

return ResponseEntity.status(HttpStatus.CREATED).body(null);
}

private Optional<Observation> createObservationFromEvent(Event event) {
Observation observation = null;
if (victoriaLogClient.shouldStartTrackingLatency()) {
observation = victoriaLogClient.startObservationFromEvent(event);

}

return Optional.ofNullable(observation);
}

private void addTracingTags(Event event) {
var currentSpan = Optional.ofNullable(tracer.getCurrentSpan());

Expand Down
115 changes: 0 additions & 115 deletions src/main/java/de/telekom/horizon/starlight/cache/SchemaCache.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 Deutsche Telekom IT GmbH
//
// SPDX-License-Identifier: Apache-2.0

package de.telekom.horizon.starlight.cache;

import de.telekom.eni.pandora.horizon.schema.SchemaStore;
import de.telekom.horizon.starlight.config.StarlightConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SchemaCacheUpdateService {

private final StarlightConfig starlightConfig;

private final SchemaStore schemaStore;

@Autowired
public SchemaCacheUpdateService(SchemaStore schemaStore, StarlightConfig starlightConfig) {
this.schemaStore = schemaStore;
this.starlightConfig = starlightConfig;
}

@Scheduled(fixedRateString = "${eniapi.refreshInterval}")
protected void scheduledPollSchemas() {
if(starlightConfig.isEnableSchemaValidation()) {
schemaStore.pollSchemas();
}
}
}
Loading

0 comments on commit de50788

Please sign in to comment.