Some changes in status notifications
[nonrtric.git] / enrichment-coordinator-service / src / main / java / org / oransc / enrichment / controllers / consumer / ConsumerCallbacks.java
index cded953..9087355 100644 (file)
@@ -63,25 +63,39 @@ public class ConsumerCallbacks {
     public void notifyConsumersProducerDeleted(EiProducer eiProducer) {
         for (EiType type : eiProducer.getEiTypes()) {
             if (this.eiTypes.get(type.getId()) == null) {
+                // The type is removed
                 for (EiJob job : this.eiJobs.getJobsForType(type)) {
-                    noifyJobOwner(job, new ConsumerEiJobStatus(ConsumerEiJobStatus.EiJobStatusValues.DISABLED));
+                    if (job.isLastStatusReportedEnabled()) {
+                        noifyJobOwner(job, new ConsumerEiJobStatus(ConsumerEiJobStatus.EiJobStatusValues.DISABLED));
+                        job.setLastReportedStatus(false);
+                    }
                 }
             }
         }
     }
 
+    public void notifyConsumersProducerAdded(EiProducer eiProducer) {
+        for (EiType type : eiProducer.getEiTypes()) {
+            notifyConsumersTypeAdded(type);
+        }
+    }
+
     public void notifyConsumersTypeAdded(EiType eiType) {
         for (EiJob job : this.eiJobs.getJobsForType(eiType)) {
-            noifyJobOwner(job, new ConsumerEiJobStatus(ConsumerEiJobStatus.EiJobStatusValues.ENABLED));
+            if (!job.isLastStatusReportedEnabled()) {
+                noifyJobOwner(job, new ConsumerEiJobStatus(ConsumerEiJobStatus.EiJobStatusValues.ENABLED));
+                job.setLastReportedStatus(true);
+            }
         }
     }
 
     private void noifyJobOwner(EiJob job, ConsumerEiJobStatus status) {
-        if (!job.jobStatusUrl().isEmpty()) {
+        if (!job.getJobStatusUrl().isEmpty()) {
             String body = gson.toJson(status);
-            this.restClient.post(job.jobStatusUrl(), body) //
-                .subscribe(notUsed -> logger.debug("Consumer notified OK {}", job.id()), //
-                    throwable -> logger.warn("Consumer notify failed {} {}", job.jobStatusUrl(), throwable.toString()), //
+            this.restClient.post(job.getJobStatusUrl(), body) //
+                .subscribe(notUsed -> logger.debug("Consumer notified OK {}", job.getId()), //
+                    throwable -> logger.warn("Consumer notify failed {} {}", job.getJobStatusUrl(),
+                        throwable.toString()), //
                     null);
         }
     }