Symptoms

After Azure CSP application upgrade to 5.0, many periodic tasks to synchronize resource usage for Azure fail with errors like:

Could not get resource usage for resource with UUID 'c81f263c-6bbe-4ffa-92ae-ac838ff211a8': HTTP request has failed.
500 Internal Server Error

with the following pattern in Azure log /usr/local/azure/site/log/azure.log:

2018-02-13 07:27:52,714 DEBUG [com.odin.azure.controllers.AzureApsControllerBase] (azure task-26) Called: com.odin.azure.controllers.ResellersController.get(65f2be78-65c7-4ed5-851d-9a2e8b952868)
2018-02-13 07:27:53,198 ERROR [com.odin.azure.server.ErrorsHandler] (azure task-26) <APS-APP> Error: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not extract ResultSet
...
Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "consumption_records" violates foreign key constraint "fk_consumption_records_reseller_oss_report_id"
  Detail: Key (reseller_oss_report_id)=(0) is not present in table "oss_reports".
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
        at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]

from postgres log /var/log/pgsql/9.6/data/pg_log/postgresql-Thu.log:

< 2018-02-12 04:02:45.692 AEDT > ERROR:  insert or update on table "consumption_records" violates foreign key constraint "fk_consumption_records_reseller_oss_report_id"
< 2018-02-12 04:02:45.692 AEDT > DETAIL:  Key (reseller_oss_report_id)=(0) is not present in table "oss_reports".
< 2018-02-12 04:02:45.692 AEDT > STATEMENT:  WITH deleted AS ( DELETE FROM consumption_queue WHERE oss_id = $1 RETURNING *), updated AS ( UPDATE consumption_records cr SET reseller_oss_report_id = $2 FROM deleted WHERE cr.id = deleted.consumption_record_id RETURNING cr.*) SELECT COALESCE(SUM(cost), 0) AS total_cost, COALESCE(SUM(reseller_cost), 0) AS total_reseller_cost, COALESCE(SUM(partner_cost), 0) AS total_partner_cost, COALESCE(MAX(end_time), TO_TIMESTAMP(0)) AS last_update_time FROM updated

Cause

An Azure CSP application issue APSA-19544: "Synchronize resource usage for Azure CSP periodic task fails after upgrade to 5.x due to null reseller_oss_report_id values in consumption_records".

Resolution

Contact Odin Technical Support to apply the fix.

Internal content

Link on internal Article