diff options
Diffstat (limited to 'holmes-actions/src/main')
10 files changed, 91 insertions, 55 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java index d60a31b..4cf2aba 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java @@ -34,6 +34,9 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class AaiQuery4Ccvpn { private MultivaluedMap<String, Object> headers; @@ -42,6 +45,10 @@ public class AaiQuery4Ccvpn { return new AaiQuery4Ccvpn(); } + private static final String EMPTY_STR = ""; + + private static final JSONObject EMPTY_JSON = new JSONObject(); + private AaiQuery4Ccvpn() { headers = new MultivaluedHashMap<>(); headers.add("X-TransactionId", AaiConfig.X_TRANSACTION_ID); @@ -71,6 +78,11 @@ public class AaiQuery4Ccvpn { Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_LINK_QUERY, params) + (status == null ? "" : String.format("&operational-status=%s", status))); JSONObject linkInfo = getInfo(response.readEntity(String.class), "p-interface", "logical-link"); + if (linkInfo == null) { + log.warn(String.format("Link information is missing from AAI. Method: [getLogicLink], " + + "params: [networkId - %s, pnfName - %s, ifName - %s].", networkId, pnfName, ifName)); + return EMPTY_STR; + } return extractValueFromJsonArray(linkInfo.getJSONArray("relationship-data"), "logical-link.link-name"); } @@ -90,12 +102,30 @@ public class AaiQuery4Ccvpn { public JSONObject getServiceInstance(String networkId, String pnfName, String ifName, String status) { try { JSONObject vpnBindingInfo = getVpnBindingInfo(networkId, pnfName, ifName, status); + if (vpnBindingInfo == null) { + log.warn(String.format("VPN binding information is missing from AAI. " + + "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " + + "ifName - %s, status - %s].", networkId, pnfName, ifName, status)); + return EMPTY_JSON; + } String vpnBindingId = extractValueFromJsonArray(vpnBindingInfo.getJSONArray("relationship-data"), - "vpn-binding.vpn-id"); + "vpn-binding.vpn-id"); JSONObject connectivityInfo = getConnectivityInfo(vpnBindingId); + if (connectivityInfo == null) { + log.warn(String.format("Connectivity information is missing from AAI. " + + "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " + + "ifName - %s, status - %s].", networkId, pnfName, ifName, status)); + return EMPTY_JSON; + } String connectivityId = extractValueFromJsonArray(connectivityInfo.getJSONArray("relationship-data"), - "connectivity.connectivity-id"); + "connectivity.connectivity-id"); JSONObject serviceInstanceInfo = getServiceInstanceByConn(connectivityId); + if (serviceInstanceInfo == null) { + log.warn(String.format("Service instance information is missing from AAI. " + + "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " + + "ifName - %s, status - %s].", networkId, pnfName, ifName, status)); + return EMPTY_JSON; + } String serviceInstancePath = serviceInstanceInfo.getString("related-link"); Response response = get(getHostAddr(), getPath(serviceInstancePath)); @@ -103,8 +133,8 @@ public class AaiQuery4Ccvpn { String[] params = new String[2]; Pattern pattern = Pattern.compile("/aai/v\\d+/business/customers/customer/(.+)" + - "/service-subscriptions/service-subscription/(.+)" + - "/service-instances/service-instance/(.+)"); + "/service-subscriptions/service-subscription/(.+)" + + "/service-instances/service-instance/(.+)"); Matcher matcher = pattern.matcher(serviceInstancePath); if (matcher.find()) { params[0] = matcher.group(1); @@ -157,7 +187,7 @@ public class AaiQuery4Ccvpn { private JSONObject getServiceInstanceByConn(String connectivityId) throws CorrelationException { Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SERVICE_INSTANCE_ADDR_4_CCVPN, - "connectivityId", connectivityId)); + "connectivityId", connectivityId)); return getInfo(response.readEntity(String.class), "connectivity", "service-instance"); } @@ -171,7 +201,7 @@ public class AaiQuery4Ccvpn { private String getPath(String urlTemplate, Map<String, String> pathParams) { String url = urlTemplate; - for(Map.Entry<String, String> entry : pathParams.entrySet()){ + for (Map.Entry<String, String> entry : pathParams.entrySet()) { url = url.replaceAll("\\{" + entry.getKey() + "\\}", entry.getValue()); } return url; @@ -199,15 +229,15 @@ public class AaiQuery4Ccvpn { Response response = target.request().headers(getAaiHeaders()).get(); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new CorrelationException("Failed to connect to AAI. \nCause: " - + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n" - + getErrorMsg(String.format("%s%s", host, path), null, response)); + + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n" + + getErrorMsg(String.format("%s%s", host, path), null, response)); } return response; } catch (CorrelationException e) { throw e; } catch (Exception e) { throw new CorrelationException(e.getMessage() + "More info: " - + getErrorMsg(String.format("%s%s", host, path), null, null), e); + + getErrorMsg(String.format("%s%s", host, path), null, null), e); } } @@ -219,14 +249,14 @@ public class AaiQuery4Ccvpn { .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true).invoke(); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new CorrelationException("Failed to connect to AAI. \nCause: " - + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n" - + getErrorMsg(String.format("%s%s", host, path), body, response)); + + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n" + + getErrorMsg(String.format("%s%s", host, path), body, response)); } } catch (CorrelationException e) { throw e; } catch (Exception e) { throw new CorrelationException(e.getMessage() + "More info: " - + getErrorMsg(String.format("%s%s", host, path), body, null), e); + + getErrorMsg(String.format("%s%s", host, path), body, null), e); } } @@ -272,10 +302,12 @@ public class AaiQuery4Ccvpn { } private String extractValueFromJsonArray(JSONArray relationshipData, String keyName) { - for (int i = 0; i < relationshipData.size(); ++i) { - JSONObject item = relationshipData.getJSONObject(i); - if (item.getString("relationship-key").equals(keyName)) { - return item.getString("relationship-value"); + if (relationshipData != null) { + for (int i = 0; i < relationshipData.size(); ++i) { + JSONObject item = relationshipData.getJSONObject(i); + if (item.getString("relationship-key").equals(keyName)) { + return item.getString("relationship-value"); + } } } return null; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java index fe1f677..c7881d1 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java @@ -17,9 +17,12 @@ package org.onap.holmes.common.api.entity; import com.google.gson.annotations.SerializedName;
import lombok.Data;
+import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.Setter;
-@Data
+@Getter
+@Setter
@NoArgsConstructor
public class AlarmInfo {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java index 4cbd6bf..e21f97d 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java @@ -18,9 +18,12 @@ package org.onap.holmes.common.api.entity; import com.google.gson.annotations.SerializedName;
import java.util.Date;
import lombok.Data;
+import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.Setter;
-@Data
+@Getter
+@Setter
@NoArgsConstructor
public class AlarmsCorrelation {
@@ -47,4 +50,18 @@ public class AlarmsCorrelation { private long reserve2 = -1;
private long reserve3 = -1;
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("[");
+ sb.append("ruleId=").append(ruleId).append(",");
+ sb.append("ruleInfo=").append(ruleInfo).append(",");
+ sb.append("createTime=").append(createTime == null ? null : createTime.toString()).append(",");
+ sb.append("parentAlarmId=").append(parentAlarmId).append(",");
+ sb.append("childAlarmId=").append(childAlarmId).append(",");
+ sb.append("reserve1=").append(reserve1).append(",");
+ sb.append("reserve2=").append(reserve2).append(",");
+ sb.append("reserve3=").append(reserve3).append("]");
+ return sb.toString();
+ }
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java index db6c19f..14a3f07 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java @@ -61,23 +61,23 @@ public class CorrelationRule implements Cloneable { throw new InternalError(e);
}
- r.rid = rid == null ? null : rid;
- r.name = name == null ? null : name;
- r.description = description == null ? null : description;
+ r.rid = rid;
+ r.name = name;
+ r.description = description;
r.enabled = enabled;
r.templateID = templateID;
- r.engineID = engineID == null ? null : engineID;
- r.engineType = engineType == null ? null : engineType;
- r.creator = creator == null ? null : creator;
- r.modifier = modifier == null ? null : modifier;
+ r.engineID = engineID;
+ r.engineType = engineType;
+ r.creator = creator;
+ r.modifier = modifier;
r.params = params == null ? null : (Properties) params.clone();
- r.content = content == null ? null : content;
- r.vendor = vendor == null ? null : vendor;
+ r.content = content;
+ r.vendor = vendor;
r.createTime = createTime == null ? null : (Date) createTime.clone();
r.updateTime = updateTime == null ? null : (Date) updateTime.clone();
- r.packageName = packageName == null ? null : packageName;
- r.closedControlLoopName = closedControlLoopName == null ? null : closedControlLoopName;
- r.engineInstance = engineInstance == null ? null : engineInstance;
+ r.packageName = packageName;
+ r.closedControlLoopName = closedControlLoopName;
+ r.engineInstance = engineInstance;
return r;
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java index 0244f84..4bfb3cf 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java @@ -16,16 +16,14 @@ package org.onap.holmes.common.api.entity; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.util.List; - -@Data @NoArgsConstructor @AllArgsConstructor +@Getter +@Setter public class ServiceEntity { private String serviceName; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java index 2c2b793..a8fc04d 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java @@ -23,7 +23,6 @@ import lombok.Getter; import lombok.NoArgsConstructor;
import lombok.Setter;
-@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java index 205126d..98e5506 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java @@ -15,11 +15,10 @@ */ package org.onap.holmes.common.api.entity; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; -@Data +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor public class ServiceNode4Query { diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java index f5dca01..eba7544 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java @@ -24,7 +24,6 @@ import lombok.Getter; import lombok.NoArgsConstructor;
import lombok.Setter;
-@Data
@NoArgsConstructor
@AllArgsConstructor
@Setter
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java index a8045ec..4b90dd7 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.List;
import java.util.Map;
import java.util.Set;
-import lombok.NoArgsConstructor;
public class DcaeConfigurations extends HashMap<String, Object>{
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java index e3f6e58..ba52262 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java @@ -70,19 +70,9 @@ public class DmaapService { if (rootAlarm.getAlarmIsCleared() == PolicyMassgeConstant.POLICY_MESSAGE_ONSET) { enrichVnfInfo(vmEntity, childAlarm, policyMsg); policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ONSET); - try { - policyMsg.getAai().put("vserver.in-maint", vmEntity.getInMaint()); - } catch (Exception e) { - log.error("Failed to parse the field \"in-maint\". A boolean string (\"true\"/\"false\")" - + " is expected but the actual value is " + vmEntity.getInMaint() + ".", e); - } - try { - policyMsg.getAai().put("vserver.is-closed-loop-disabled", + policyMsg.getAai().put("vserver.in-maint", vmEntity.getInMaint()); + policyMsg.getAai().put("vserver.is-closed-loop-disabled", vmEntity.getClosedLoopDisable()); - } catch (Exception e) { - log.error("Failed to parse the field \"is-closed-loop-disabled\". A boolean string (\"true\"/\"false\")" - + " is expected but the actual value is " + vmEntity.getClosedLoopDisable() + ".", e); - } policyMsg.getAai().put("vserver.prov-status", vmEntity.getProvStatus()); policyMsg.getAai().put("vserver.resource-version", vmEntity.getResourceVersion()); } else { @@ -196,7 +186,7 @@ public class DmaapService { break; } } - log.info("Clear alarm, requestId deleted successful"); + log.info("An alarm is cleared and the corresponding requestId is deleted successfully"); } } } |