Available APIs

cbs-client - a Config Binding Service client

CbsClientFactory can be used to lookup for CBS in your application. Returned CbsClient can then be used to get a configuration, poll for configuration or poll for configuration changes.

The following CBS endpoints are supported by means of different CbsRequests:
  • get-configuration created by CbsRequests.getConfiguration method - returns the service configuration

  • get-by-key created by CbsRequests.getByKey method - returns componentName:key entry from Consul

  • get-all created by CbsRequests.getAll method - returns everything which relates to the service (configuration, policies, etc.)

Sample usage:

// Generate RequestID and InvocationID which will be used when logging and in HTTP requests
final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create();
final CbsRequest request = CbsRequests.getConfiguration(diagnosticContext);

// Read necessary properties from the environment
final CbsClientConfiguration config = CbsClientConfiguration.fromEnvironment();

// Create the client and use it to get the configuration
CbsClientFactory.createCbsClient(config)
        .flatMap(cbsClient -> cbsClient.get(request))
        .subscribe(
                jsonObject -> {
                    // do a stuff with your JSON configuration using GSON API
                    final int port = Integer.parseInt(jsonObject.get("collector.listen_port").getAsString());
                    // ...
                },
                throwable -> {
                    logger.warn("Ooops", throwable);
                });

Note that a subscribe handler can/will be called in separate thread asynchronously after CBS address lookup succeeds and CBS service call returns a result.

If you are interested in calling CBS periodically and react only when the configuration changed you can use updates method:

// Generate RequestID and InvocationID which will be used when logging and in HTTP requests
final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create();
final CbsRequest request = CbsRequests.getConfiguration(diagnosticContext);

// Read necessary configuration from the environment
final CbsClientConfiguration config = CbsClientConfiguration.fromEnvironment();

// Polling properties
final Duration initialDelay = Duration.ofSeconds(5);
final Duration period = Duration.ofMinutes(1);

// Create the client and use it to get the configuration
CbsClientFactory.createCbsClient(config)
        .flatMapMany(cbsClient -> cbsClient.updates(request, initialDelay, period))
        .subscribe(
                jsonObject -> {
                    // do a stuff with your JSON configuration using GSON API
                    final int port = Integer.parseInt(jsonObject.get("collector.listen_port").getAsString());
                    // ...
                },
                throwable -> {
                    logger.warn("Ooops", throwable);
                });

The most significant change is in line 14. We are using flatMapMany since we want to map one CbsClient to many JsonObject updates. After 5 seconds CbsClient will call CBS every minute. If the configuration has changed it will pass the JsonObject downstream - in our case consumer of JsonObject will be called.

Parsing streams’ definitions:

  • CBS configuration response contains various service-specific entries. It also contains a standardized DCAE streams definitions as streams_publishes and streams_subscribes JSON objects. CBS Client API provides a way of parsing this part of configuration so you can use Java objects instead of low-level GSON API.

  • Because streams definitions are a simple value objects we were not able to provide you a nice polymorphic API. Instead you have 2-level API at your disposal:
    • You can extract raw streams by means of DataStreams.namedSinks (for streams_publishes) and DataStreams.namedSources (for streams_subscribes).

    • Then you will be able to parse the specific entry from returned collection to a desired stream type by means of parsers built by StreamFromGsonParsers factory.

  • Sample usage:

    final CbsRequest request = CbsRequests.getConfiguration(RequestDiagnosticContext.create());
    final StreamFromGsonParser<MessageRouterSink> mrSinkParser = StreamFromGsonParsers.messageRouterSinkParser();
    
    CbsClientFactory.createCbsClient(CbsClientConfiguration.fromEnvironment())
        .flatMapMany(cbsClient -> cbsClient.updates(request, Duration.ofSeconds(5), Duration.ofMinutes(1)))
        .map(DataStreams::namedSinks)
        .map(sinks -> sinks.filter(StreamPredicates.streamOfType(MESSAGE_ROUTER)).map(mrSinkParser::unsafeParse).toList())
        .subscribe(
            mrSinks -> mrSinks.forEach(mrSink -> {
                logger.info(mrSink.name()); // name = the configuration key
                logger.info(mrSink.aafCredentials().username()); // = aaf_username
                logger.info(mrSink.topicUrl());
                // ...
            }),
            throwable -> logger.warn("Ooops", throwable)
    );
    

    For details and sample usage please refer to JavaDoc and unit and integration tests. Especially CbsClientImplIT, MessageRouterSinksIT and MixedDmaapStreamsIT might be useful.

  • INFO

    Results of these parsers (MessageRouterSink, MessageRouterSource) can be directly used to connect to DMaaP MR by means of dmaap-client API described below.

crypt-password - an utility for BCrypt passwords

Library to generate and match cryptography password using BCrypt algorithm

java -jar crypt-password-${sdk.version}.jar password_to_crypt

$2a$10$iDEKdKknakPqH5XZb6wEmeBP2SMRwwiWHy8RNioUTNycIomjIqCAO

Can be used like maven dependency to match generated password.

dmaap-client - a DMaaP MR client (upto version 1.9.3)

After parsing CBS sink definitions you will get a Source or Sink value object. It can be then directly used to communicate with DMaaP Message Router REST API.

Writing message publisher

final MessageRouterPublisher publisher = DmaapClientFactory.createMessageRouterPublisher();
final MessageRouterSink sinkDefinition; //... Sink definition obtained by parsing CBS response
final MessageRouterPublishRequest request = ImmutableMessageRouterPublishRequest.builder()
        .sinkDefinition(sinkDefinition)
        .build();

Flux.just(1, 2, 3)
        .map(JsonPrimitive::new)
        .transform(input -> publisher.put(request, input))
        .subscribe(resp -> {
                    if (resp.successful()) {
                        logger.debug("Sent a batch of messages to the MR");
                    } else {
                        logger.warn("Message sending has failed: {}", resp.failReason());
                    }
                },
                ex -> {
                    logger.warn("An unexpected error while sending messages to DMaaP", ex);
                });

Note that we are using Reactor transform operator. As an alternative you could assign Flux of JSON values to the variable and then invoke publisher.put on it. The important performance-related thing to remember is that you should feed the put method with a stream of messages instead of multiple calls with single messages. This way the client API will be able to send them in batches which should significantly improve performance (at least on transfer level).

Writing message subscriber

final MessageRouterSource sourceDefinition; //... Source definition obtained by parsing CBS response
final MessageRouterSubscribeRequest request = ImmutableMessageRouterSubscribeRequest.builder()
        .sourceDefinition(sourceDefinition)
        .build();

cut.subscribeForElements(request, Duration.ofMinutes(1))
        .map(JsonElement::getAsJsonObject)
        .subscribe(json -> {
                // application logic
            },
            ex -> {
                logger.warn("An unexpected error while receiving messages from DMaaP", ex);
            });

Configure timeout when talking to DMaaP-MR

  • publisher:

final MessageRouterPublishRequest request = ImmutableMessageRouterPublishRequest.builder()
             .timeoutConfig(ImmutableDmaapTimeoutConfig.builder()
                     .timeout(Duration.ofSeconds(2))
                     .build())
             .
             .
             .
             .build();
  • subscriber:

final MessageRouterSubscribeRequest request = ImmutableMessageRouterSubscribeRequest.builder()
              .timeoutConfig(ImmutableDmaapTimeoutConfig.builder()
                      .timeout(Duration.ofSeconds(2))
                      .build())
              .
              .
              .
              .build();

The default timeout value (4 seconds) can be used:

ImmutableDmaapTimeoutConfig.builder().build()

For timeout exception following message is return as failReason in DmaapResponse:

408 Request Timeout
{"requestError":{"serviceException":{"messageId":"SVC0001","text":"Client timeout exception occurred, Error code is %1","variables":["408"]}}}

Configure retry mechanism

  • publisher:

final MessageRouterPublisherConfig config = ImmutableMessageRouterPublisherConfig.builder()
         .retryConfig(ImmutableDmaapRetryConfig.builder()
                 .retryIntervalInSeconds(2)
                 .retryCount(2)
                 .build())
         .
         .
         .
         .build();
final MessageRouterPublisher publisher = DmaapClientFactory.createMessageRouterPublisher(config);
  • subscriber:

final MessageRouterSubscriberConfig config = ImmutableMessageRouterSubscriberConfig.builder()
            .retryConfig(ImmutableDmaapRetryConfig.builder()
                    .retryIntervalInSeconds(2)
                    .retryCount(2)
                    .build())
            .
            .
            .
            .build();
final MessageRouterSubscriber subscriber = DmaapClientFactory.createMessageRouterSubscriber(config);

The default retry config (retryCount=3, retryIntervalInSeconds=1) can be used:

ImmutableDmaapRetryConfig.builder().build()
Retry functionality works for:
  • DMaaP MR HTTP response status codes: 404, 408, 413, 429, 500, 502, 503, 504

  • Java Exception classes: ReadTimeoutException, ConnectException

Configure custom persistent connection

  • publisher:

final MessageRouterPublisherConfig connectionPoolConfiguration = ImmutableMessageRouterPublisherConfig.builder()
          .connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
                 .connectionPool(16)
                 .maxIdleTime(10) //in seconds
                 .maxLifeTime(20) //in seconds
                 .build())
         .build();
final MessageRouterPublisher publisher = DmaapClientFactory.createMessageRouterPublisher(connectionPoolConfiguration);
  • subscriber:

final MessageRouterSubscriberConfig connectionPoolConfiguration = ImmutableMessageRouterSubscriberConfig.builder()
                .connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
                    .connectionPool(16)
                    .maxIdleTime(10) //in seconds
                    .maxLifeTime(20) //in seconds
                    .build())
            .build();
final MessageRouterSubscriber subscriber = DmaapClientFactory.createMessageRouterSubscriber(connectionPoolConfiguration);

The default custom persistent connection configuration (connectionPool=16, maxLifeTime=2147483647, maxIdleTime=2147483647) can be used:

ImmutableDmaapConnectionPoolConfig.builder().build()

Configure request for authorized topics

  • publisher:

final MessageRouterSink sink = ImmutableMessageRouterSink.builder()
            .aafCredentials(ImmutableAafCredentials.builder()
                    .username("username")
                    .password("password").build())
            .
            .
            .
            .build();

final MessageRouterPublishRequest request = ImmutableMessageRouterPublishRequest.builder()
            .sinkDefinition(sink)
            .
            .
            .
            .build();
  • subscriber:

final MessageRouterSource sourceDefinition = ImmutableMessageRouterSource.builder()
            .aafCredentials(ImmutableAafCredentials.builder()
                    .username("username")
                    .password("password")
                    .build())
            .
            .
            .
            .build();

final MessageRouterSubscribeRequest request = ImmutableMessageRouterSubscribeRequest.builder()
            .sourceDefinition(sourceDefinition)
            .
            .
            .
            .build();

AAF Credentials are optional for subscribe/publish requests. Username and password are used for basic authentication header during sending HTTP request to dmaap-mr.

dmaap-client - a Kafka client (For version 1.9.4)

Version 1.9.4 has tried to keep method signatures same as previous version so as to reduce impact on services using previous version of this library. You can create publisher and subscriber like it is done using previous version of this library (as shown above).

Alternatively, version 1.9.4 of the library provides another constructor for creating them which is suggested to be used by new services.

Writing Publisher and subscriber

Writing message publisher

final MessageRouterPublisher publisher = new MessageRouterPublisherImpl();
final MessageRouterSink sinkDefinition; //... Sink definition obtained by parsing CBS response
final MessageRouterPublishRequest request = ImmutableMessageRouterPublishRequest.builder()
        .sinkDefinition(sinkDefinition)
        .build();

Writing message subscriber

final MessageRouterPublisher subscriber = new MessageRouterSubscriberImpl();
final MessageRouterSource sourceDefinition; //... Source definition obtained by parsing CBS response
final MessageRouterSubscribeRequest request = ImmutableMessageRouterSubscribeRequest.builder()
        .sourceDefinition(sourceDefinition)
        .build();

Closing Publisher and subscriber

From version 1.9.4, the service needs to explicitly close the publisher and subscriber to avoid resource leakage. New close methods are introduced to do the same.

Closing message publisher

publisher.close();

Closing message subscriber

subscriber.close();

Environment variables required

If the service uses sdk library version 1.9.4, the service needs to ensure that two new environment variables are declared. These two environment variables are mandatory and are required to establish connection with kafka. They are as follows:

- name: BOOTSTRAP_SERVERS
  value: onap-strimzi-kafka-bootstrap:9092
- name: JAAS_CONFIG
      valueFrom:
    secretKeyRef:
      key: sasl.jaas.config
      name: strimzi-kafka-admin

The service can also provide optional standard Kafka properties as environment variables to override the default values used by the library. Such property names must be prefixed with string “kafka.”. An example is given below:

# To override Kafka property "max.poll.interval.ms"
- name: kafka.max.poll.interval.ms
  value: 35000
# To override Kafka property "heartbeat.interval.ms"
- name: kafka.heartbeat.interval.ms
  value: 50000

hvvesclient-producer - a reference Java implementation of High Volume VES Collector client

This library is used in xNF simulator which helps us test HV VES Collector in CSIT tests. You may use it as a reference when implementing your code in non-JVM language or directly when using Java/Kotlin/etc.

Sample usage:

final ProducerOptions producerOptions = ImmutableProducerOptions.builder()
        .collectorAddresses(HashSet.of(
                InetSocketAddress.createUnresolved("dcae-hv-ves-collector", 30222)))
        .build();
final HvVesProducer hvVesProducer = HvVesProducerFactory.create(producerOptions);

Flux<VesEvent> events; // ...
Mono.from(hvVesProducer.send(events))
        .doOnSuccess(() -> logger.info("All events has been sent"))
        .doOnError(ex -> logger.warn("Failed to send one or more events", ex))
        .subscribe();

external-schema-manager - JSON Validator with schema mapping

This library can be used to validate any JSON content incoming as JsonNode. What differs it from other validation libraries is mapping of externally located schemas to local schema files.

Validated JSON must have one field that will refer to an external schema, which will be mapped to local file and then validation of any chosen part of JSON is executed using local schema.

Mapping file is cached on validator creation, so it’s not read every time validation is performed. Schemas’ content couldn’t be cached due to external library restrictions (OpenAPI4j).

Example JSON:

{
    "schemaReference": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml",
    "data":
    {
        "exampleData": "SAMPLE_VALUE"
    }
}

Interface:

There are two methods, that are interface of this sub-project.

Validator builder:

new StndDefinedValidator.ValidatorBuilder()
        .mappingFilePath(mappingFilePath)
        .schemasPath(schemasPath)
        .schemaRefPath(schemaRefPath)
        .stndDefinedDataPath(stndDefinedDataPath)
        .build();

Validator usage:

stndDefinedValidator.validate(event);

There are 4 string parameters of the builder:

String parameters of the builder

Name

Description

Example

Note

mappingFilePath

This should be a local filesystem path to file with mappings of public URLs to local URLs. Format of the schema mapping file is a JSON file with list of mappings

etc/externalRepo/schema-map.json

schemasPath

Schemas path is a directory under which external-schema-manager will search for local schemas

./etc/externalRepo/ and first mapping from example mappingFile is taken, validator will look for schema under the path: ./etc/externalRepo/3gpp/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml

schemaRefPath

This is an internal path from validated JSON. It should define which field will be taken as public schema reference, which is later mapped

/event/stndDefinedFields/schemaReference

In SDK version 1.4.2 this path doesn’t use JSON path notation (with . signs). It might change in further versions

stndDefinedDataPath

This is path to stndDefined data in JSON. This fields will be validated during stndDefined validation.

/event/stndDefinedFields/data

In SDK version 1.4.2 this path doesn’t use JSON path notation (with . signs). It might change in further versions.

Format of the schema mapping file is a JSON file with list of mappings, as shown in the example below.

[
    {
        "publicURL": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml",
        "localURL": "3gpp/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml"
    },
    {
        "publicURL": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/heartbeatNtf.yaml",
        "localURL": "3gpp/rep/sa5/data-models/blob/REL-16/OpenAPI/heartbeatNtf.yaml"
    },
    {
        "publicURL": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/PerDataFileReportMnS.yaml",
        "localURL": "3gpp/rep/sa5/data-models/blob/REL-16/OpenAPI/PerDataFileReportMnS.yaml"
    },
    {
        "publicURL": "https://forge.3gpp.org/rep/sa5/data-models/blob/master/OpenAPI/provMnS.yaml",
        "localURL": "3gpp/rep/sa5/data-models/blob/REL-16/OpenAPI/provMnS.yaml"
    }
]

Possible scenarios when using external-schema-manger:

When the schema-map file, the schema and the sent event are correct, then the validation is successful and the log shows “Validation of stndDefinedDomain has been successful”.

Errors in the schema-map - none of the mappings are cached:

  • When no schema-map file exists, “Unable to read mapping file. Mapping file path: {}” is logged.

  • When a schema-map file exists, but has an incorrect format, a warning is logged: “Schema mapping file has incorrect format. Mapping file path: {}”

Errors in one of the mappings in schema-map - this mapping is not cached, a warning is logged “Mapping for publicURL ({}) will not be cached to validator.”:

  • When the local url in the schema-map file references a file that does not exist, the warning “Local schema resource missing. Schema file with path {} has not been found.”

  • When the schema file is empty, the information “Schema file is empty. Schema path: {}” is logged

  • When a schema file has an incorrect format (not a yaml), the following information is logged: Schema has incorrect YAML structure. Schema path: {} “

Errors in schemaRefPath returns errors:

  • If in the schemaRef path in the event we provide an url that refers to an existing schema, but the part after # refers to a non-existent part of it, then an error is thrown: IncorrectInternalFileReferenceException (“Schema reference refer to existing file, but internal reference (after #) is incorrect.”) “

  • When in the schemaRef path in the event, we provide a url that refers to a non-existent mapping from public to localURL, a NoLocalReferenceException is thrown, which logs to the console: “Couldn’t find mapping for public url. PublicURL: {}”