You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

References:

CPS-1005 - Getting issue details... STATUS

Overview:

This POC is for finding ways to create a resource (NCMP for this instance).

Few possibilities were discussed during the Grooming session which are listed as below.

  1. init-container
  2. k8s hooks
  3. Events in Spring.
  4.  ....(explore others if any)

Issues and decisions

#

Questions/Open Issues

Notes

Decision/Answer





Analysis

  1. init-container

    Init containers are exactly like regular containers, except:
        -  Init containers always run to completion.
        -  Each init container must complete successfully before the next one starts.

    Since our application container would not be running the before the init-container so we cant invoke any endpoint to create a resource and we dont want to go with DB related script(SQL) to create a resource (insert a row in the database) so I am not exploring this further for this use case.
  2. k8s hooks



  3. Events in Spring

    We can use the ApplicationReadyEvent which is published when the application is ready to service requests.
    We can listen to this event , which is thrown by the SpringApplication itself and then execute some code (which is creating a dataspace in our scenario)

    Example

    ApplicationReadyEvent
    @EventListener(ApplicationReadyEvent.class)
        public void initializeNcmp() {
            log.info("Initializing NCMP when the ApplicationReadyEvent is received");
            try {
                cpsAdminService.createDataspace("NCMP-CmHandle-Operational-Data");
            } catch (final AlreadyDefinedException ex) {
                log.info("Already defined : {} ", ex.getMessage());
            } catch (final Exception ex) {
                log.warn("Failed to create dataspace, cause : {}", ex.getMessage());
            }
        }



References

https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/context/event/ApplicationReadyEvent.html

https://kubernetes.io/docs/concepts/workloads/pods/init-containers/



  • No labels