Skip to content

Commit

Permalink
Merge "Add classifiers and decorators"
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnKeeneyEST authored and Gerrit Code Review committed Aug 20, 2024
2 parents abe98a3 + 1335824 commit b59b816
Show file tree
Hide file tree
Showing 324 changed files with 28,248 additions and 14,341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,4 @@ application:
retry-policies:
deadlock:
retry-attempts: 10
retry-backoff-ms: 200

feature_flags:
use_alternate_delete_logic: false
retry-backoff-ms: 200
3 changes: 0 additions & 3 deletions charts/smo/topology-exposure-inventory/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ application: &applicationConfig
retry-attempts: 10
retry-backoff-ms: 200

feature_flags:
use_alternate_delete_logic: false

topology-exposure:
name: topology-exposure
namespace: default
Expand Down
11 changes: 7 additions & 4 deletions teiv/src/main/antlr4/org/oran/smo/teiv/antlr4/tiesPath.g4
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@

grammar tiesPath ;

tiesPath : ( prefix | incorrectPrefix ) multipleLeafConditions? textFunctionCondition? containsFunctionCondition? ancestorAxis? invalidPostFix? containerName? fieldLeaf?;
tiesPath : ( prefix | incorrectPrefix ) multipleLeafConditions? containsTextFunctionCondition? textFunctionCondition? containsFunctionCondition? ancestorAxis? invalidPostFix? containerName? fieldLeaf?;

ancestorAxis : SLASH KW_ANCESTOR COLONCOLON ancestorPath ;

ancestorPath : yangElement ( SLASH yangElement)* ;

textFunctionCondition : SLASH leafName OB KW_TEXT_FUNCTION EQ StringLiteral CB ;
textFunctionCondition : OB KW_TEXT_FUNCTION EQ StringLiteral CB ;

containsTextFunctionCondition : OB KW_CONTAINS_FUNCTION OP KW_TEXT_FUNCTION COMMA StringLiteral CP CB ;

containsFunctionCondition : OB KW_CONTAINS_FUNCTION OP AT leafName COMMA StringLiteral CP CB ;

Expand All @@ -79,7 +81,8 @@ leafName : QName ;

booleanOperators : ( KW_AND | KW_OR ) ;

comparativeOperators : ( EQ | GT | LT | GE | LE ) ;
// Onnly EQ supported for now
comparativeOperators : ( EQ /*| GT | LT | GE | LE */ ) ;

invalidPostFix : (AT | CB | COLONCOLON | comparativeOperators ).+ ;

Expand Down Expand Up @@ -165,4 +168,4 @@ fragment FragChar : '\u0009' | '\u000a' | '\u000d'
Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;

// handle characters which failed to match any other token (otherwise Antlr will ignore them)
ErrorCharacter : . ;
ErrorCharacter : . ;
28 changes: 14 additions & 14 deletions teiv/src/main/java/org/oran/smo/teiv/CustomMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import org.springframework.stereotype.Component;

@Data
@Component
public class CustomMetrics {

@Getter(AccessLevel.PRIVATE)
private final AtomicLong tiesSubscriptionGaugeCounter = new AtomicLong(0L);

private final MeterRegistry meterRegistry;

private final Counter numReceivedCloudEventCreate;
Expand Down Expand Up @@ -115,6 +109,10 @@ public class CustomMetrics {

private final Counter numUnsuccessfullyExposedDomainTypes;

private final Counter numUnsuccessfullyUpdatedClassifiers;

private final Counter numUnsuccessfullyUpdatedDecorators;

private final Counter numIgnoredAttributes;

public CustomMetrics(MeterRegistry meterRegistry) {
Expand Down Expand Up @@ -208,6 +206,12 @@ public CustomMetrics(MeterRegistry meterRegistry) {
numUnsuccessfullyExposedDomainTypes = Counter.builder("ties_exposure_http_get_domain_types_fail_total").register(
meterRegistry);

numUnsuccessfullyUpdatedClassifiers = Counter.builder("ties_exposure_http_update_classifiers_fail_total").register(
meterRegistry);

numUnsuccessfullyUpdatedDecorators = Counter.builder("ties_exposure_http_update_decorators_fail_total").register(
meterRegistry);

cloudEventMergePersistTime = Timer.builder("ties_ingestion_event_topology_merge_persist_seconds").register(
meterRegistry);

Expand Down Expand Up @@ -525,16 +529,12 @@ public void incrementNumUnsuccessfullyExposedDomainTypes() {
numUnsuccessfullyExposedDomainTypes.increment();
}

public void incrementNumReceivedTiesSubscriptions(int amountToAdd) {
tiesSubscriptionGaugeCounter.addAndGet(amountToAdd);
}

public void resetNumReceivedTiesSubscriptions() {
tiesSubscriptionGaugeCounter.set(0);
public void incrementNumUnsuccessfullyUpdatedClassifiers() {
numUnsuccessfullyUpdatedClassifiers.increment();
}

public void setNumReceivedTiesSubscriptions(int amount) {
tiesSubscriptionGaugeCounter.set(amount);
public void incrementNumUnsuccessfullyUpdatedDecorators() {
numUnsuccessfullyUpdatedDecorators.increment();
}

public void incrementNumIgnoredAttributes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

@Slf4j
public abstract class DependentServiceAvailability {
protected String serviceName;

protected int retryIntervalMs;

protected int retryAttempts;
Expand All @@ -41,7 +39,7 @@ public abstract class DependentServiceAvailability {
* @return true once service is reached, false if max retries exhausted
*/
public boolean checkService() {
RetryTemplate retryTemplate = RetryOperationUtils.getRetryTemplate(serviceName,
RetryTemplate retryTemplate = RetryOperationUtils.getRetryTemplate(getServiceName(),
UnsatisfiedExternalDependencyException.class, retryAttempts, retryIntervalMs);
try {
return retryTemplate.execute(retryContext -> isServiceAvailable());
Expand All @@ -51,5 +49,10 @@ public boolean checkService() {
return false; // exhausted retries
}

/**
* @return Name of the service, e.g.: Kafka.
*/
protected abstract String getServiceName();

abstract boolean isServiceAvailable() throws UnsatisfiedExternalDependencyException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
*/
package org.oran.smo.teiv.availability;

import lombok.RequiredArgsConstructor;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.ListTopicsOptions;
import org.apache.kafka.clients.admin.ListTopicsResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.kafka.core.KafkaAdmin;
import org.springframework.stereotype.Component;

Expand All @@ -37,7 +37,7 @@

@Component
@Slf4j
@Profile("ingestion")
@RequiredArgsConstructor
public class DependentServiceAvailabilityKafka extends DependentServiceAvailability {

@Getter
Expand All @@ -49,10 +49,9 @@ public class DependentServiceAvailabilityKafka extends DependentServiceAvailabil
@Setter
private Integer listTopicTimeout = null;

public DependentServiceAvailabilityKafka(KafkaAdminConfig kafkaAdminConfig, KafkaAdmin kafkaAdmin) {
this.kafkaAdminConfig = kafkaAdminConfig;
this.kafkaAdmin = kafkaAdmin;
serviceName = "Kafka";
@Override
protected String getServiceName() {
return "Kafka";
}

@Value("${kafka.availability.retry-interval-ms}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public DSLContext dslContextWrite() {
public DSLContext dslContextRead() {
return DSL.using(dataSourceRead(), SQLDialect.POSTGRES);
}

@Bean(name = "readWriteDataDslContext")
public DSLContext dslContextReadWrite() {
return DSL.using(dataSourceWrite(), SQLDialect.POSTGRES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import lombok.Data;

import org.oran.smo.teiv.service.kafka.KafkaAddressSupplier;

@Configuration
@Data
@Profile("ingestion")
@Slf4j
public class KafkaAdminConfig {

Expand Down
13 changes: 7 additions & 6 deletions teiv/src/main/java/org/oran/smo/teiv/config/KafkaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,31 @@
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Data
@Profile("ingestion")
public class KafkaConfig {

private final TopologyIngestion topologyIngestion;

@Data
@Configuration
public static class TopologyIngestion {
@Value("${kafka.topology-ingestion.consumer.topic.name}")
@Value("${kafka.topology-ingestion.topic.name}")
private String topicName;

@Value("${kafka.topology-ingestion.consumer.topic.partitions}")
@Value("${kafka.topology-ingestion.topic.partitions}")
private int partitions;

@Value("${kafka.topology-ingestion.consumer.topic.replicas}")
@Value("${kafka.topology-ingestion.topic.replicas}")
private int replicas;

@Value("${kafka.topology-ingestion.consumer.topic.retention-ms}")
@Value("${kafka.topology-ingestion.topic.retention-ms}")
private String retention;

@Value("${kafka.topology-ingestion.topic.retention-bytes}")
private String retentionBytes;

@Value("${kafka.topology-ingestion.consumer.group-id}")
private String groupId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,34 @@
*/
package org.oran.smo.teiv.controller.health;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.oran.smo.teiv.availability.DependentServiceAvailabilityKafka;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Health Check component for TIES exposure.
*/

@RequiredArgsConstructor
@Component
@Slf4j
@Profile("!ingestion")
public class TiesExposureHealthIndicator implements HealthIndicator {
public class TiesExposureHealthIndicator extends TiesHealthIndicator {

private final HealthStatus healthStatus;
public TiesExposureHealthIndicator(HealthStatus healthStatus,
DependentServiceAvailabilityKafka dependentServiceAvailabilityKafka) {
super(healthStatus, dependentServiceAvailabilityKafka);
}

private static final String SERVICE_NAME = "topology-exposure-inventory";
@Override
protected String getServiceName() {
return "topology-exposure-inventory";
}

@Override
public Health health() {
if (!healthStatus.isSchemaInitialized()) {
String errorMessage = SERVICE_NAME + " is DOWN because: Schema is yet to be initialized.";
log.error(errorMessage);
return Health.down().withDetail("Error", errorMessage).build();
} else {
String message = SERVICE_NAME + " is UP and Healthy.";
log.debug(message);
return Health.up().withDetail("UP", message).build();
return healthDown("Schema is yet to be initialized.");
}
return healthUp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2024 Ericsson
* Modifications Copyright (C) 2024 OpenInfra Foundation Europe
* ================================================================================
* 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.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.oran.smo.teiv.controller.health;

import org.oran.smo.teiv.availability.DependentServiceAvailabilityKafka;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class TiesHealthIndicator implements HealthIndicator {

protected final HealthStatus healthStatus;
protected final DependentServiceAvailabilityKafka dependentServiceAvailabilityKafka;

protected abstract String getServiceName();

protected TiesHealthIndicator(HealthStatus healthStatus,
DependentServiceAvailabilityKafka dependentServiceAvailabilityKafka) {
this.healthStatus = healthStatus;
this.dependentServiceAvailabilityKafka = dependentServiceAvailabilityKafka;
}

protected Health healthUp() {
String message = getServiceName() + " is UP and Healthy.";
log.debug(message);
return Health.up().withDetail("UP", message).build();
}

protected Health healthDown(String reason) {
String errorMessage = getServiceName() + " is DOWN because: " + reason;
log.error(errorMessage);
return Health.down().withDetail("Error", errorMessage).build();
}

protected boolean isKafkaReachable() {
return dependentServiceAvailabilityKafka.checkService();
}
}
Loading

0 comments on commit b59b816

Please sign in to comment.