Extension point configuration

Hi all,
I’m currently trying to check whether newly added extension point configuration in the stock management service works. Unfortunately, I encountered issues during testing and I’m not sure if something is configured incorrectly in stock management or in my example extension.

Firstly, I had to build and use local fat jar of stock management because this service’s jar is not available on the remote repo. Then, when I was finally able to run a ref-distro with the extensions, I noticed that my extension bean is not initialized while starting ref-distro. I’ve tried the same for fulfillment extension point with the same result.

I’ve pushed my changes to dev branches of example-extensions and example-extension.

Does anyone know what can be the root cause?

Best,
Klaudia

@joshzamor I’ve just pushed my changes to the ref-distro dev branch and stock management dev branch.

The steps that we execute to run ref-distro with extension point:

  1. Build an image of stock management service with tag 5.1.2-SNAPSHOT
  2. Build a fat jar using the gradle fatJar task
  3. Copy this fat jar to the example-extension /libs directory
  4. Run docker builder for example-extension and copy created source jar to the /libs directory in example-extensions
  5. Run docker builder and build an image of example-extensions with tag 0.0.1-SNAPSHOT
  6. Run ref-distro

I have logging.level.org.springframework.beans.factory=DEBUG set in my settings.env to check which beans are initialized.

Thanks in advance for your help,
Klaudia

Hi @joshzamor, I hope you are well.

Did you manage to look at this? Do you happen to know what can be misconfigured here?

Best,
Klaudia

Hi @Klaudia_Palkowska and @joshzamor,

I have tried to run openlmis-example repository with the extension but the way we’re trying to do it for Stock Management. It also didn’t work until I added the path to the extensions package in @ComponentScan annotation in the Application class, like this:

   @ComponentScan(
    basePackages = {"org.openlmis.example*", "extensions.org.openlmis.example*"}
    )

However, doing similar thing in Stock Management service still doesn’t work. The fact that Stock Management’s Spring Boot version was recently upgraded to version 2 may matter here.

I upgraded the Spring Boot version to version 2 in the openlmis-example and checked it. It occurred that with upgraded Spring Boot it stopped working. In Spring Boot 2 I used the following annotation:

@SpringBootApplication(
    scanBasePackages = {"org.openlmis.example", "extensions.org.openlmis.example.extension"}
    )

For now I am not aware of what could be the reason for this, but maybe one of you will have an idea.

Best,
Paulina.

Just a thought - given that we know the extension point injection breaks on Spring Boot update, maybe we can identify which version exactly introduces this problem? E.g. Does it still work if we update Spring Boot from 1.3 to 1.5? How about 1.4? 2.0? 2.1? 2.2? Once we know the exact version that introduced the problem we can review the Spring Boot release notes for this version and perhaps find the solution there.

Another thing to consider is to check whether it still works if you keep the same @ComponentScan annotation (I think it still exists in Spring Boot 2 - why change it?)

Best,
Sebastian

Thank you Sebastian for your suggestions. Verifying the Spring Boot’s version which introduced this problem looks like an interesting way to continue our investigations.

According to the annotation, I think it doesn’t matter. I have also tried it with the same @ComponentScan annotation, but without success.

Best,
Paulina.

Are we blocked on this or is progress still being made?

Hi @ibewes ,

Following Sebastian’s suggestion, the Spring boot version was changed between versions 1.3 and 2.2, but example extension point behaved correctly, so this excludes the version of Spring Boot as the source of the problem.

Currently, we are still looking for a way to solve this issue, but we do not make much progress except to exclude what does not work.

Best,
Adrian.

Hi @joshzamor ,
Would you manage to take the look at this issue ?

Hi @Klaudia_Palkowska and @aswiszcz,

Who owns this issue now?

@Klaudia_Palkowska, I was stopped on the first step here. I went to build the branch OLMIS-6911 of openlmis-stockmanagement with the command docker-compose -f docker-compose.builder.yml run builder and encountered integration test errors pretty quickly:

org.openlmis.stockmanagement.service.StockCardServiceIntegrationTest > shouldReassignPhysicalInventoryReasonNames FAILED
    org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [uk_6uy5au82jp04x5wcg5wgj1j1k]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:298)
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)
        at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:538)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:744)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:712)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:631)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:385)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy180.save(Unknown Source)
        at org.openlmis.stockmanagement.service.StockCardServiceIntegrationTest.setUp(StockCardServiceIntegrationTest.java:134)

        Caused by:
        org.hibernate.exception.ConstraintViolationException: could not execute statement
            at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:109)
            at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
            at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200)
            at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3208)
            at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3722)
            at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:91)
            at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
            at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
            at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
            at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
            at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
            at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
            at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:108)
            at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1344)
            at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:435)
            at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3221)
            at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2389)
            at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
            at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
            at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:534)
            ... 15 more

            Caused by:
            org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "uk_6uy5au82jp04x5wcg5wgj1j1k"
              Detail: Key (name)=(reason) already exists.
                at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
                at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
                at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
                at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
                at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
                at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
                at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:136)
                at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
                at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
                at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
                ... 35 more

    org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [valid_source_assignments_nodeid_fkey]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:298)
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)
        at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:538)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:744)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:712)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:631)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:385)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy185.deleteAll(Unknown Source)
        at org.openlmis.stockmanagement.service.StockCardServiceIntegrationTest.tearDown(StockCardServiceIntegrationTest.java:143)

        Caused by:
        org.hibernate.exception.ConstraintViolationException: could not execute statement
            at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:109)
            at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
            at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200)
            at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
            at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3513)
            at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3772)
            at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:100)
            at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
            at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
            at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
            at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
            at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
            at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
            at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:108)
            at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1344)
            at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:435)
            at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3221)
            at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2389)
            at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
            at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
            at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:534)
            ... 15 more

            Caused by:
            org.postgresql.util.PSQLException: ERROR: update or delete on table "nodes" violates foreign key constraint "valid_source_assignments_nodeid_fkey" on table "valid_source_assignments"
              Detail: Key (id)=(0bd28568-43f1-4836-934d-ec5fb11398e8) is still referenced from table "valid_source_assignments".
                at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
                at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
                at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
                at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
                at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
                at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
                at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:136)
                at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
                at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
                at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
                ... 36 more

org.openlmis.stockmanagement.service.StockCardServiceIntegrationTest > shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement FAILED
    org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [uk_6uy5au82jp04x5wcg5wgj1j1k]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:298)
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)
        at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:538)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:744)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:712)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:631)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:385)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy180.save(Unknown Source)
        at org.openlmis.stockmanagement.service.StockCardServiceIntegrationTest.setUp(StockCardServiceIntegrationTest.java:134)

        Caused by:
        org.hibernate.exception.ConstraintViolationException: could not execute statement
            at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:109)
            at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
            at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200)
            at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3208)
            at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3722)
            at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:91)
            at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
            at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
            at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
            at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
            at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
            at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
            at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:108)
            at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1344)
            at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:435)
            at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3221)
            at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2389)
            at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
            at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
            at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:534)
            ... 15 more

            Caused by:
            org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "uk_6uy5au82jp04x5wcg5wgj1j1k"
              Detail: Key (name)=(reason) already exists.
                at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
                at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
                at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
                at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
                at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
                at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
                at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:136)
                at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
                at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
                at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
                ... 35 more

    org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [valid_source_assignments_nodeid_fkey]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:298)
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)
        at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:538)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:744)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:712)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:631)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:385)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy185.deleteAll(Unknown Source)
        at org.openlmis.stockmanagement.service.StockCardServiceIntegrationTest.tearDown(StockCardServiceIntegrationTest.java:143)

        Caused by:
        org.hibernate.exception.ConstraintViolationException: could not execute statement
            at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:109)
            at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
            at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200)
            at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
            at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3513)
            at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3772)
            at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:100)
            at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
            at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
            at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
            at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
            at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
            at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
            at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:108)
            at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1344)
            at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:435)
            at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3221)
            at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2389)
            at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40)
            at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
            at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
            at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:534)
            ... 15 more

            Caused by:
            org.postgresql.util.PSQLException: ERROR: update or delete on table "nodes" violates foreign key constraint "valid_source_assignments_nodeid_fkey" on table "valid_source_assignments"
              Detail: Key (id)=(0bd28568-43f1-4836-934d-ec5fb11398e8) is still referenced from table "valid_source_assignments".
                at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
                at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
                at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
                at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
                at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
                at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
                at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:136)
                at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
                at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
                at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
                ... 36 more

I know CI isn’t having this issue, so it looks like something on my end. Could someone verify this is still working and not a false success due to a cache that the CI server has? I have a fresh .env file, a clean docker environment (docker system prune -af --volumes), running recent versions (docker 19.03.13 and docker-compose 1.24.0), etc.

Hi @joshzamor
I also had this problem when one of profiles ‘spring_profiles_active’ was uncommented.
You need to comment all the profiles in env file, then this issue should no longer occur.

Best,
Aleksandra

1 Like

Hi @joshzamor,

currently, @aswiszcz owns the issue but since it’s a blocker for the release I’m also trying to help. In case of the error, it works exactly how @Aleksandra_Soltys described.

Best,
Klaudia

Thanks @Aleksandra_Soltys and @Klaudia_Palkowska , that’s what I’d forgotten (also we should probably add that to the docs - unless I missed it?). I got the build to work but unfortunately that’s all the time I had today with my other commitments. I’ll try to make more headway Wednesday, though it may not be until Friday until I can actually get a solid chunk of time.

At the moment we managed to verify the example extension point under versions 1.3, 1.5, and 2.2.2.
On all versions, we managed to run an example extension point on
api/extensionPoint
so we can exclude spring boot version as the reason for the problem.
In the case of openlmis-example version 2.2.2, to build the image we used gradle v6.5 with a wrapper by
./gradlew clean build
We tried a configuration in which we threw an extension point from openlmis-example into stockmanagement, but without a positive result.

The changes we have made to change the spring boot version in openlmis example are located on the branches:
OLMIS-6921-SB1.3.3
OLMIS-6921-1.5
OLMIS-6921 (for version 2.2.2)

Best,
Adrian

@joshzamor Yes, we probably should add this info somewhere but where is the best place? In the readme file?

Also, I’m adding more precise steps to reproduce the issue. To verify stock management extension point configuration you should use OLMIS-6911 branches of all mentioned GitHub repositories.

Start with stock management:

docker-compose run --service-ports stockmanagement
gradle clean build
exit

docker-compose -f docker-compose.builder.yml build image
docker tag openlmis/stockmanagement:latest openlmis/stockmanagement:5.1.2-SNAPSHOT

docker-compose run --service-ports stockmanagement
gradle fatJar
exit

cp build/libs/openlmis-stockmanagement-5.1.2-SNAPSHOT.jar openlmis-example-extension/libs/openlmis-stockmanagement-5.1.2-SNAPSHOT.jar

Example extension:

docker-compose -f docker-compose.yml run builder
cp build/libs/openlmis-example-extension-0.0.1-SNAPSHOT-sources.jar openlmis-example-extensions/libs/openlmis-example-extension-0.0.1-SNAPSHOT.jar

Example extensions:

docker-compose -f docker-compose.builder.yml run builder
docker-compose -f docker-compose.builder.yml build image
docker tag openlmis/openlmis-example-extensions:latest openlmis/openlmis-example-extensions:0.0.1-SNAPSHOT

Ref-distro:

docker-compose up

and check /api/extensionPoint via API definition: {your-ip}/stockmanagement/docs/.

Best,
Klaudia

1 Like

I spent some time digging into this yesterday, and I think the cause of the problem is that the example-extensions jar that is made available via docker volume and set as a runtime dependency, doesn’t make its way inside the service.jar

Taking a look at the behavior of the Spring Scanner, it scans two places:
service.jar!/BOOT-INF/classes - this contains our service source files
service.jar!/BOOT-INF/lib - this contains dependencies

Those are the log levels I used:

logging.level.org.springframework.beans.factory=DEBUG
logging.level.org.springframework.context.annotation=DEBUG
logging.level.org.springframework.core.io.support=DEBUG

The example-extensions jar is present inside the docker container via the docker volume named extensions but it doesn’t get included in the service.jar and thus isn’t discovered by the Spring Scanner when looking for spring beans.

It seems that for the example service, the example-extensions jar is properly placed inside the service.jar!/BOOT-INF/lib

If the above theory is true, the example service somewhere somehow has some magic that causes the example-extensions jar to be copied/moved inside the service.jar - the question remains where that magic is.

Best,
Sebastian

We managed to add an example-extension jar to service.jar file, the problem was the lack of volume extensions in the stockmanagement docker-compose file. However, we do not want extensions service in stockmanagement to be build-time dependency but run-time. Most likely the problem lies at the spring boot plugin level what we are trying to verify.

Best,
Adrian

Since the previous post we managed to verify the following things:

  • Removing uploadArchives task from the build.gradle in example service, to check if the example extension will still behave correctly - it still behaved correctly.

  • Adding
    java $JAVA_OPTS -classpath extensions/*:service.jar org.springframework.boot.loader.JarLauncher && java $JAVA_OPTS -jar service.jar
    to run.sh file in stockmanagement, following fix from this commit
    https://github.com/OpenLMIS/openlmis-example/commit/dec4e4bcf0916f2bb6f2bd9e6e1824fff40a5e93

  • Change service-base:4 in Dockerfile in stockmanagement to service-base:1 (as in example service)

We are still looking for a solution to this problem

We’ve also checked that removing run.sh from stock management doesn’t help. Moreover, even if the script in stock is different than it should, the proper version from openlmis-service-base v4 is used.

VERY IMPORTANT QUESTION

@joshzamor Do you happen to know if adding this dependency in example’s docker-compose file was intentional? If yes, should we create a public openlmis-stockmanagement-extensions and include it in stock management’s compose file? Otherwise, it means that the example also isn’t working properly with jars because we managed to verify that is stops working without the mentioned dependency.

Moreover, when we try to build the example (with the mentioned dependency) using the following commands, extensions don’t work (bean is not found):

docker-compose -f docker-compose.builder.yml run builder
docker-compose -f docker-compose.builder.yml build image

Usually, we use these:

docker-compose run --service-ports example
gradle clean build
exit
docker-compose -f docker-compose.builder.yml build image

Best,
Klaudia