...
This section is an proposition keeping using exiting event schema implementation.
CPS Events Releases
CPS events are defined (JSON Schema) and generated (Java classes) from cps repository in cps-events module: https://github.com/onap/cps/tree/master/cps-events
...
Then, cps-event artifact built contains the generated classes for both new and previous event schema. Both are available to be used by producer and consumers that are importing this specific cps-events jar as a dependency.
cps-events Maven Artifact Version
Note |
---|
To be detailed ... |
DataUpdatedEvent Schema Version
Note |
---|
To be detailed ... |
Consumers of CPS Events
Compiled Code
When using cps-events artifact, consumers has access to both new and previous cps events classes.
...
From a compiled code point of view, supporting both event type versions is in place.
Runtime Configuration
The challenge is now to be able to choose which event version a listener is consuming at startup, by configuration only, without changing the application compiled code.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
app: listener: data-updated: v0: topic: ${CPS_CHANGE_EVENT_V0_LISTENER_TOPIC:cps.dev.null} autoStartup: ${CPS_CHANGE_EVENT_V0_LISTENER_ENABLED:false} v1: topic: ${CPS_CHANGE_EVENT_V1_LISTENER_TOPIC:cps.cfg-state-events} autoStartup: ${CPS_CHANGE_EVENT_V1_LISTENER_ENABLED:true} |
Producer of CPS Events
Compiled Code
The producer is able to send both current and previous versions of events by implementing 2 sets of Notification Service and Notification Publisher using Template Method design pattern.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import org.onap.cps.event.model.v1.CpsDataUpdatedEvent; public class V1NotificationPublisher extends NotificationPublisher<CpsDataUpdatedEvent> { public V1NotificationPublisher( final KafkaTemplate<String, CpsDataUpdatedEvent> kafkaTemplate, final @Value("${notification.data-updated.topic}") String topicName) { super(kafkaTemplate, topicName); } protected void sendNotification(@NonNull final CpsDataUpdatedEvent cpsDataUpdatedEvent) { final var messageKey = cpsDataUpdatedEvent.getContent().getDataspaceName() + "," + cpsDataUpdatedEvent.getContent().getAnchorName(); super.getKafkaTemplate().send(super.getTopicName(), messageKey, cpsDataUpdatedEvent); } } |
Runtime Configuration
The event schema version to be published is specified and configurable in application properties. The specified value is used by Spring when the application is starting to instantiate the expected concrete classes for Notification Service and Publisher.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public class CpsDataServiceImpl implements CpsDataService { ... @Value("${notification.event-schema-version}NotificationService") private String notificationServiceQualifier; private NotificationService notificationService; @Autowired public void setNotificationService(final ApplicationContext applicationContext) { this.notificationService = (NotificationService) applicationContext.getBean(notificationServiceQualifier); } ... } |
POC
POC code can be found in Gerrit WIP changes:
Conclusion
Proposed solution above gives flexibility to deploy new releases of the components (producer or consumers) independently, in any order.
...