Switched from Dropwizard to Springboot
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / dmaap / DmaapService.java
index 7e33bf9..de7d74f 100644 (file)
@@ -15,7 +15,6 @@
  */
 package org.onap.holmes.common.dmaap;
 
-import org.jvnet.hk2.annotations.Service;
 import org.onap.holmes.common.aai.AaiQuery;
 import org.onap.holmes.common.aai.entity.RelationshipList.Relationship;
 import org.onap.holmes.common.aai.entity.VmEntity;
@@ -30,8 +29,9 @@ import org.onap.holmes.common.exception.CorrelationException;
 import org.onap.holmes.common.utils.GsonUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
-import javax.inject.Inject;
 import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.UUID;
@@ -45,17 +45,17 @@ public class DmaapService {
     private ClosedLoopControlNameCache closedLoopControlNameCache;
     private UniqueRequestIdCache uniqueRequestIdCache;
 
-    @Inject
+    @Autowired
     public void setAaiQuery(AaiQuery aaiQuery) {
         this.aaiQuery = aaiQuery;
     }
 
-    @Inject
+    @Autowired
     public void setClosedLoopControlNameCache(ClosedLoopControlNameCache closedLoopControlNameCache) {
         this.closedLoopControlNameCache = closedLoopControlNameCache;
     }
 
-    @Inject
+    @Autowired
     public void setUniqueRequestIdCache(UniqueRequestIdCache uniqueRequestIdCache) {
         this.uniqueRequestIdCache = uniqueRequestIdCache;
     }
@@ -67,12 +67,14 @@ public class DmaapService {
                     .getTopicUrl());
             publisher.publish(policyMsg);
             deleteRequestIdIfNecessary(policyMsg);
+
             log.info("send policyMsg: " + GsonUtil.beanToJson(policyMsg));
-        } catch (CorrelationException e) {
-            log.error("Failed to publish the control loop event to DMaaP", e);
         } catch (NullPointerException e) {
             log.error(String.format("DMaaP configurations do not exist!\n DCAE Configurations: \n %s",
                     DcaeConfigurationsCache.getDcaeConfigurations()), e);
+        } catch (Exception e) {
+            log.error(String.format("An error occurred when publishing a message to Policy: %s",
+                    e.getMessage()), e);
         }
     }
 
@@ -83,7 +85,7 @@ public class DmaapService {
     }
 
     private PolicyMsg getEnrichedPolicyMsg(VmEntity vmEntity, VesAlarm rootAlarm, VesAlarm childAlarm,
-            String packageName) {
+                                           String packageName) {
         PolicyMsg policyMsg = new PolicyMsg();
         policyMsg.setRequestID(getUniqueRequestId(rootAlarm));
         if (rootAlarm.getAlarmIsCleared() == PolicyMassgeConstant.POLICY_MESSAGE_ONSET) {
@@ -91,7 +93,7 @@ public class DmaapService {
             policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ONSET);
             policyMsg.getAai().put("vserver.in-maint", vmEntity.getInMaint());
             policyMsg.getAai().put("vserver.is-closed-loop-disabled",
-                        vmEntity.getClosedLoopDisable());
+                    vmEntity.getClosedLoopDisable());
             policyMsg.getAai().put("vserver.prov-status", vmEntity.getProvStatus());
             policyMsg.getAai().put("vserver.resource-version", vmEntity.getResourceVersion());
         } else {
@@ -195,12 +197,12 @@ public class DmaapService {
         return vmEntity;
     }
 
-    private void deleteRequestIdIfNecessary(PolicyMsg policyMsg){
-       EVENT_STATUS status = policyMsg.getClosedLoopEventStatus();
-        if(EVENT_STATUS.ABATED.equals(status)) {
+    private void deleteRequestIdIfNecessary(PolicyMsg policyMsg) {
+        EVENT_STATUS status = policyMsg.getClosedLoopEventStatus();
+        if (EVENT_STATUS.ABATED.equals(status)) {
             String requestId = policyMsg.getRequestID();
-            for(Entry<String, String> kv: uniqueRequestIdCache.entrySet()) {
-                if(kv.getValue().equals(requestId)) {
+            for (Entry<String, String> kv : uniqueRequestIdCache.entrySet()) {
+                if (kv.getValue().equals(requestId)) {
                     uniqueRequestIdCache.remove(kv.getKey());
                     break;
                 }