From 1253af9756e8a7027fade727da68b38dff2d5159 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Thu, 27 Sep 2018 12:28:19 -0400 Subject: Fix more sonar issues Most of these are minor issues along with a few others. They have been bugging me so I thought I would get them done. Some also do not show up on sonarlint. Issue-ID: POLICY-1129 Change-Id: I31f2765f6babdfa80b23f0589daacc98da8d2002 Signed-off-by: Pamela Dragosh --- .../eventmanager/ControlLoopOperationManager.java | 115 +++++++------- .../feature/trans/ControlLoopMetrics.java | 8 +- .../java/org/onap/policy/guard/CallGuardTask.java | 2 +- .../org/onap/policy/guard/PipEngineGetHistory.java | 10 +- .../src/main/java/org/onap/policy/guard/Util.java | 10 +- .../org/onap/policy/aai/AaiNqResponseWrapper.java | 2 +- .../org/onap/policy/aai/util/Serialization.java | 8 +- .../org/onap/policy/appc/util/Serialization.java | 14 +- .../onap/policy/appclcm/util/Serialization.java | 22 +-- .../controlloop/PhysicalControlLoopEvent.java | 3 - .../PhysicalControlLoopNotification.java | 3 - .../policy/controlloop/util/Serialization.java | 36 ++--- .../org/onap/policy/rest/HttpDeleteWithBody.java | 9 +- .../org/onap/policy/sdnr/util/Serialization.java | 21 +-- .../org/onap/policy/vfc/util/Serialization.java | 9 +- .../common/policy-yaml/checkstyle-suppressions.xml | 2 +- .../controlloop/compiler/ControlLoopCompiler.java | 64 +++++--- .../org/onap/policy/controlloop/policy/Policy.java | 174 ++++++++++----------- .../org/onap/policy/controlloop/policy/Target.java | 32 ++-- .../policy/builder/BuilderException.java | 4 +- .../controlloop/policy/guard/Constraint.java | 20 ++- .../controlloop/policy/guard/GuardPolicy.java | 80 +++++----- .../controlloop/policy/guard/MatchParameters.java | 64 ++++---- .../builder/impl/ControlLoopGuardBuilderImpl.java | 2 +- .../onap/policy/simulators/AaiSimulatorJaxRs.java | 21 +-- .../main/java/org/onap/policy/simulators/Util.java | 35 +++-- 26 files changed, 401 insertions(+), 369 deletions(-) (limited to 'controlloop') diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java index c5344e38b..0b2c14e54 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java @@ -64,14 +64,6 @@ public class ControlLoopOperationManager implements Serializable { private static final String GENERIC_VNF_VNF_NAME = "generic-vnf.vnf-name"; private static final String GENERIC_VNF_VNF_ID = "generic-vnf.vnf-id"; - @Override - public String toString() { - return "ControlLoopOperationManager [onset=" + (onset != null ? onset.getRequestId() : "null") + ", policy=" - + (policy != null ? policy.getId() : "null") + ", attempts=" + attempts + ", policyResult=" - + policyResult + ", currentOperation=" + currentOperation + ", operationHistory=" + operationHistory - + "]"; - } - // // These properties are not changeable, but accessible // for Drools Rule statements. @@ -88,6 +80,51 @@ public class ControlLoopOperationManager implements Serializable { private PolicyResult policyResult = null; private ControlLoopEventManager eventManager = null; private String targetEntity; + private String guardApprovalStatus = "NONE";// "NONE", "PERMIT", "DENY" + private transient Object operationRequest; + + /** + * Construct an instance. + * + * @param onset the onset event + * @param policy the policy + * @param em the event manager + * @throws ControlLoopException if an error occurs + * @throws AaiException if an error occurs retrieving information from A&AI + */ + public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em) + throws ControlLoopException, AaiException { + this.onset = onset; + this.policy = policy; + this.guardApprovalStatus = "NONE"; + this.eventManager = em; + this.targetEntity = getTarget(policy); + + // + // Let's make a sanity check + // + switch (policy.getActor()) { + case "APPC": + if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) { + /* + * The target vnf-id may not be the same as the source vnf-id specified in the + * yaml, the target vnf-id is retrieved by a named query to A&AI. + */ + String targetVnf = AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(), + this.targetEntity); + this.targetEntity = targetVnf; + } + break; + case "SO": + break; + case "SDNR": + break; + case "VFC": + break; + default: + throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor."); + } + } public ControlLoopEventManager getEventManager() { return eventManager; @@ -101,6 +138,14 @@ public class ControlLoopOperationManager implements Serializable { return this.targetEntity; } + @Override + public String toString() { + return "ControlLoopOperationManager [onset=" + (onset != null ? onset.getRequestId() : "null") + ", policy=" + + (policy != null ? policy.getId() : "null") + ", attempts=" + attempts + ", policyResult=" + + policyResult + ", currentOperation=" + currentOperation + ", operationHistory=" + operationHistory + + "]"; + } + // // Internal class used for tracking // @@ -118,9 +163,6 @@ public class ControlLoopOperationManager implements Serializable { } } - private String guardApprovalStatus = "NONE";// "NONE", "PERMIT", "DENY" - private transient Object operationRequest; - public Object getOperationRequest() { return operationRequest; } @@ -184,49 +226,6 @@ public class ControlLoopOperationManager implements Serializable { } } - /** - * Construct an instance. - * - * @param onset the onset event - * @param policy the policy - * @param em the event manager - * @throws ControlLoopException if an error occurs - * @throws AaiException if an error occurs retrieving information from A&AI - */ - public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em) - throws ControlLoopException, AaiException { - this.onset = onset; - this.policy = policy; - this.guardApprovalStatus = "NONE"; - this.eventManager = em; - this.targetEntity = getTarget(policy); - - // - // Let's make a sanity check - // - switch (policy.getActor()) { - case "APPC": - if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) { - /* - * The target vnf-id may not be the same as the source vnf-id specified in the - * yaml, the target vnf-id is retrieved by a named query to A&AI. - */ - String targetVnf = AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(), - this.targetEntity); - this.targetEntity = targetVnf; - } - break; - case "SO": - break; - case "SDNR": - break; - case "VFC": - break; - default: - throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor."); - } - } - /** * Start an operation. * @@ -548,7 +547,7 @@ public class ControlLoopOperationManager implements Serializable { * @return The result of the response handling */ private PolicyResult onResponse(VFCResponse vfcResponse) { - if (vfcResponse.getResponseDescriptor().getStatus().equalsIgnoreCase("finished")) { + if ("finished".equalsIgnoreCase(vfcResponse.getResponseDescriptor().getStatus())) { // // Consider it as success // @@ -797,8 +796,6 @@ public class ControlLoopOperationManager implements Serializable { throw new ControlLoopException("current oepration has failed after " + this.attempts + " retries"); } } - - return; } private boolean isRetriesMaxedOut() { @@ -833,7 +830,7 @@ public class ControlLoopOperationManager implements Serializable { String opsHistPu = System.getProperty("OperationsHistoryPU"); - if (opsHistPu == null || !opsHistPu.equals("TestOperationsHistoryPU")) { + if (!"TestOperationsHistoryPU".equals(opsHistPu)) { opsHistPu = "OperationsHistoryPU"; } else { props.clear(); @@ -914,7 +911,7 @@ public class ControlLoopOperationManager implements Serializable { * @param outcome the abatement outcome */ public void commitAbatement(String message, String outcome) { - logger.info("commitAbatement: " + message + ", " + outcome); + logger.info("commitAbatement: {}. {}", message, outcome); if (this.currentOperation == null) { try { diff --git a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetrics.java b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetrics.java index 790d434fd..a1c587b07 100644 --- a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetrics.java +++ b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetrics.java @@ -313,8 +313,7 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics { } protected void evicted(VirtualControlLoopNotification notification) { - // transaction(notification, ZonedDateTime.now()); - MDCTransaction trans = MDCTransaction + MDCTransaction .newTransaction(notification.getRequestId().toString(), notification.getFrom()) .setServiceName(notification.getClosedLoopControlName()).setTargetEntity(notification.getTarget()) .setStartTime(notification.getNotificationTime().toInstant()).setEndTime(Instant.now()) @@ -439,7 +438,7 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics { default: /* unexpected */ logger.warn("unexpected notification type {} in notification {}", - notification.getNotification().toString(), notification); + notification.getNotification(), notification); break; } @@ -448,7 +447,8 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics { @Override public String toString() { - final StringBuffer sb = new StringBuffer("CacheBasedControlLoopMetricsManager{"); + final StringBuilder sb = new StringBuilder(); + sb.append("CacheBasedControlLoopMetricsManager{"); sb.append("cacheSize=").append(cacheSize); sb.append(", transactionTimeout=").append(transactionTimeout); sb.append('}'); diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java index 59a1816b7..fefea39ab 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java @@ -151,7 +151,7 @@ public class CallGuardTask implements Runnable { // // Create an artificial Guard response in case we didn't get a clear Permit or Deny // - if (guardResponse.getResult().equals("Indeterminate")) { + if ("Indeterminate".equals(guardResponse.getResult())) { guardResponse.setOperation(recipe); guardResponse.setRequestID(UUID.fromString(requestId)); } diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetHistory.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetHistory.java index 2a1ef2fc6..37c4e4c68 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetHistory.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetHistory.java @@ -122,7 +122,7 @@ public class PipEngineGetHistory extends StdConfigurableEngine { // Notice, we are checking here for the base issuer prefix. if (!string.contains(this.getIssuer())) { logger.debug("Requested issuer '{}' does not match {}", string, getIssuer()); - logger.debug("FeqLimiter PIP - Issuer {} does not match with: ", string, this.getIssuer()); + logger.debug("FeqLimiter PIP - Issuer {} does not match with: {}", string, this.getIssuer()); return StdPIPResponse.PIP_RESPONSE_EMPTY; } } @@ -184,14 +184,14 @@ public class PipEngineGetHistory extends StdConfigurableEngine { if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) { if (logger.isWarnEnabled()) { logger.warn("PIP response error {}: {}", pipRequest.getAttributeId().stringValue(), - pipResponse.getStatus().toString()); + pipResponse.getStatus()); } return null; } if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) { if (logger.isWarnEnabled()) { logger.warn("No attributes in POP response {}: {}", pipRequest.getAttributeId().stringValue(), - pipResponse.getStatus().toString()); + pipResponse.getStatus()); } return null; } @@ -309,7 +309,7 @@ public class PipEngineGetHistory extends StdConfigurableEngine { EntityManager em = null; String opsHistPu = System.getProperty("OperationsHistoryPU"); - if (opsHistPu == null || !opsHistPu.equals("TestOperationsHistoryPU")) { + if (!"TestOperationsHistoryPU".equals(opsHistPu)) { opsHistPu = "OperationsHistoryPU"; } else { props.clear(); @@ -328,7 +328,7 @@ public class PipEngineGetHistory extends StdConfigurableEngine { try { diff = now - getMsFromTimeWindow(timeWindow); } catch (Exception ex) { - logger.error("PIP thread got Exception " + ex); + logger.error("PIP thread got Exception ", ex); return -1; } diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java index 46a815cdd..d159bd425 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * guard * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,10 +36,6 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; public final class Util { - private Util() { - // This static class cannot be instantiated - } - /* * Keys for guard properties */ @@ -87,6 +83,10 @@ public final class Util { } } + private Util() { + // This static class cannot be instantiated + } + /** * Load a Yaml file. * diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java index eb4271b5c..038e3f88b 100644 --- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java +++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java @@ -133,7 +133,7 @@ public class AaiNqResponseWrapper implements Serializable { * Walk the items looking for VF modules, allocating the list only when an item is * found. */ - List vfModuleItems = new ArrayList<>(itemList.size());; + List vfModuleItems = new ArrayList<>(itemList.size()); for (AaiNqInventoryResponseItem inventoryResponseItem : itemList) { AaiNqVfModule vfmod = inventoryResponseItem.getVfModule(); diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/util/Serialization.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/util/Serialization.java index 2c8263467..5b504c09c 100644 --- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/util/Serialization.java +++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/util/Serialization.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * aai * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,9 @@ import com.google.gson.GsonBuilder; public final class Serialization { - private Serialization() {} - public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - // .registerTypeAdapter(AAIQueryParameters.class, new notificationTypeAdapter()) .create(); + + private Serialization() {} + } diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java index 3e16f2943..d8a397dca 100644 --- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java +++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java @@ -40,6 +40,13 @@ import org.slf4j.LoggerFactory; public final class Serialization { public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + // .registerTypeAdapter(CommonHeader1607.class, new gsonCommonHeaderInstance()) + // .registerTypeAdapter(ResponseStatus1607.class, new gsonResponseStatus()) + .create(); + private Serialization() {} public static class GsonUtcAdapter implements JsonSerializer, JsonDeserializer { @@ -75,11 +82,4 @@ public final class Serialization { } - public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) - .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) - // .registerTypeAdapter(CommonHeader1607.class, new gsonCommonHeaderInstance()) - // .registerTypeAdapter(ResponseStatus1607.class, new gsonResponseStatus()) - .create(); - } diff --git a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java index 944d56846..ee2d28094 100644 --- a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java +++ b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,16 @@ import org.onap.policy.appclcm.LcmRequest; import org.onap.policy.appclcm.LcmResponse; public final class Serialization { + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); + + public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(LcmRequest.class, new RequestAdapter()) + .registerTypeAdapter(LcmResponse.class, new ResponseAdapter()).create(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); + private Serialization() {} public static class RequestAdapter implements JsonSerializer, JsonDeserializer { @@ -100,14 +110,4 @@ public final class Serialization { } - public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); - - public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(LcmRequest.class, new RequestAdapter()) - .registerTypeAdapter(LcmResponse.class, new ResponseAdapter()).create(); - - public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); - } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java index 4cae5ca5d..9cb85ae7f 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java @@ -32,8 +32,5 @@ public class PhysicalControlLoopEvent extends ControlLoopEvent { */ public PhysicalControlLoopEvent(PhysicalControlLoopEvent event) { super(event); - if (event == null) { - return; - } } } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java index 5dbc7f498..0b5db3a1f 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java @@ -32,9 +32,6 @@ public class PhysicalControlLoopNotification extends ControlLoopNotification { */ public PhysicalControlLoopNotification(PhysicalControlLoopEvent event) { super(event); - if (event == null) { - return; - } } } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java index 864b31726..4bbab7a50 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java @@ -40,6 +40,24 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public final class Serialization { + public static final Gson gson = + new GsonBuilder().disableHtmlEscaping().registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); + + + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); + private Serialization() {} public static class NotificationTypeAdapter @@ -104,22 +122,4 @@ public final class Serialization { } - public static final Gson gson = - new GsonBuilder().disableHtmlEscaping().registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) - .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) - .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter()) - .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); - - - public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) - .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) - .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter()) - .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); - - public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) - .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) - .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); - } diff --git a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java index dc75334a2..3e52d4f10 100644 --- a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java +++ b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java @@ -31,10 +31,6 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { public static final String METHOD_NAME = "DELETE"; - public String getMethod() { - return METHOD_NAME; - } - public HttpDeleteWithBody(final String uri) { super(); setURI(URI.create(uri)); @@ -48,4 +44,9 @@ public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { public HttpDeleteWithBody() { super(); } + + public String getMethod() { + return METHOD_NAME; + } + } diff --git a/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java b/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java index 0208884ce..3a116d741 100644 --- a/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java +++ b/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java @@ -3,6 +3,7 @@ * sdnr * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +39,16 @@ import org.onap.policy.sdnr.PciResponse; public final class Serialization { + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); + + public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(PciRequest.class, new RequestAdapter()) + .registerTypeAdapter(PciResponse.class, new ResponseAdapter()).create(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); + private Serialization() {} public static class RequestAdapter implements JsonSerializer, JsonDeserializer { @@ -101,14 +112,4 @@ public final class Serialization { } - public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); - - public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(PciRequest.class, new RequestAdapter()) - .registerTypeAdapter(PciResponse.class, new ResponseAdapter()).create(); - - public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); - } diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java index 2259296d2..19aca3aae 100644 --- a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2017 Intel Corp. All rights reserved. + * Copyright (C) 2017-2018 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +23,11 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; public final class Serialization { - private Serialization() { - } - public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() .setPrettyPrinting() .create(); + private Serialization() { + } + } diff --git a/controlloop/common/policy-yaml/checkstyle-suppressions.xml b/controlloop/common/policy-yaml/checkstyle-suppressions.xml index a23b257a6..01e66442b 100644 --- a/controlloop/common/policy-yaml/checkstyle-suppressions.xml +++ b/controlloop/common/policy-yaml/checkstyle-suppressions.xml @@ -25,6 +25,6 @@ diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java index 76c6f8f14..f18752a62 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java @@ -268,7 +268,7 @@ public class ControlLoopCompiler implements Serializable { String policyId, String connectedPolicy, FinalResultNodeWrapper finalResultNodeWrapper, PolicyResult policyResult, NodeWrapper node) throws CompilerException { - FinalResult finalResult = FinalResult.toResult(finalResultNodeWrapper.getID()); + FinalResult finalResult = FinalResult.toResult(finalResultNodeWrapper.getId()); if (FinalResult.isResult(connectedPolicy, finalResult)) { graph.addEdge(node, finalResultNodeWrapper, new LabeledEdge(node, finalResultNodeWrapper, new FinalResultEdgeWrapper(finalResult))); @@ -294,7 +294,7 @@ public class ControlLoopCompiler implements Serializable { validatePolicyNodeWrapper(graph, node, callback); } for (LabeledEdge edge : graph.outgoingEdgesOf(node)) { - LOGGER.info(edge.from.getID() + " invokes " + edge.to.getID() + " upon " + edge.edge.getID()); + LOGGER.info("{} invokes {} upon {}", edge.from.getId(), edge.to.getId(), edge.edge.getId()); } } } @@ -302,7 +302,7 @@ public class ControlLoopCompiler implements Serializable { private static void validateTriggerNodeWrapper(DirectedGraph graph, NodeWrapper node) throws CompilerException { if (LOGGER.isDebugEnabled()) { - LOGGER.info("Trigger Node {}", node.toString()); + LOGGER.info("Trigger Node {}", node); } if (graph.inDegreeOf(node) > 0 ) { // @@ -321,7 +321,7 @@ public class ControlLoopCompiler implements Serializable { private static void validateFinalResultNodeWrapper(DirectedGraph graph, NodeWrapper node) throws CompilerException { if (LOGGER.isDebugEnabled()) { - LOGGER.info("FinalResult Node {}", node.toString()); + LOGGER.info("FinalResult Node {}", node); } // // FinalResult nodes should NEVER have an out edge @@ -334,7 +334,7 @@ public class ControlLoopCompiler implements Serializable { private static void validatePolicyNodeWrapper(DirectedGraph graph, NodeWrapper node, ControlLoopCompilerCallback callback) throws CompilerException { if (LOGGER.isDebugEnabled()) { - LOGGER.info("Policy Node {}", node.toString()); + LOGGER.info("Policy Node {}", node); } // // All Policy Nodes should have the 5 out degrees defined. @@ -346,16 +346,24 @@ public class ControlLoopCompiler implements Serializable { // All Policy Nodes should have at least 1 in degrees // if (graph.inDegreeOf(node) == 0 && callback != null) { - callback.onWarning("Policy " + node.getID() + " is not reachable."); + callback.onWarning("Policy " + node.getId() + " is not reachable."); } } private static boolean okToAdd(Policy operPolicy, ControlLoopCompilerCallback callback) { boolean isOk = isPolicyIdOk(operPolicy, callback); - isOk = isActorOk(operPolicy, callback) ? isOk : false; - isOk = isRecipeOk(operPolicy, callback) ? isOk : false; - isOk = isTargetOk(operPolicy, callback) ? isOk : false; - isOk = arePolicyResultsOk(operPolicy, callback) ? isOk : false; + if (! isActorOk(operPolicy, callback)) { + isOk = false; + } + if (! isRecipeOk(operPolicy, callback)) { + isOk = false; + } + if (! isTargetOk(operPolicy, callback) ) { + isOk = false; + } + if (! arePolicyResultsOk(operPolicy, callback) ) { + isOk = false; + } return isOk; } @@ -471,11 +479,21 @@ public class ControlLoopCompiler implements Serializable { // Check that policy results are connected to either default final * or another policy // boolean isOk = isSuccessPolicyResultOk(operPolicy, callback); - isOk = isFailurePolicyResultOk(operPolicy, callback) ? isOk : false; - isOk = isFailureRetriesPolicyResultOk(operPolicy, callback) ? isOk : false; - isOk = isFailureTimeoutPolicyResultOk(operPolicy, callback) ? isOk : false; - isOk = isFailureExceptionPolicyResultOk(operPolicy, callback) ? isOk : false; - isOk = isFailureGuardPolicyResultOk(operPolicy, callback) ? isOk : false; + if (! isFailurePolicyResultOk(operPolicy, callback) ) { + isOk = false; + } + if (! isFailureRetriesPolicyResultOk(operPolicy, callback) ) { + isOk = false; + } + if (! isFailureTimeoutPolicyResultOk(operPolicy, callback) ) { + isOk = false; + } + if (! isFailureExceptionPolicyResultOk(operPolicy, callback) ) { + isOk = false; + } + if (! isFailureGuardPolicyResultOk(operPolicy, callback) ) { + isOk = false; + } return isOk; } @@ -562,7 +580,7 @@ public class ControlLoopCompiler implements Serializable { @FunctionalInterface private interface NodeWrapper extends Serializable { - public String getID(); + public String getId(); } private static class TriggerNodeWrapper implements NodeWrapper { @@ -579,7 +597,7 @@ public class ControlLoopCompiler implements Serializable { } @Override - public String getID() { + public String getId() { return closedLoopControlName; } @@ -599,7 +617,7 @@ public class ControlLoopCompiler implements Serializable { } @Override - public String getID() { + public String getId() { return result.toString(); } } @@ -618,14 +636,14 @@ public class ControlLoopCompiler implements Serializable { } @Override - public String getID() { + public String getId() { return policy.getId(); } } @FunctionalInterface private interface EdgeWrapper extends Serializable { - public String getID(); + public String getId(); } @@ -638,7 +656,7 @@ public class ControlLoopCompiler implements Serializable { } @Override - public String getID() { + public String getId() { return trigger; } @@ -664,7 +682,7 @@ public class ControlLoopCompiler implements Serializable { } @Override - public String getID() { + public String getId() { return policyResult.toString(); } @@ -685,7 +703,7 @@ public class ControlLoopCompiler implements Serializable { } @Override - public String getID() { + public String getId() { return finalResult.toString(); } } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java index 22c58c8ab..06dc36e69 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java @@ -50,6 +50,93 @@ public class Policy implements Serializable { //Does Nothing Empty Constructor } + public Policy(String id) { + this.id = id; + } + + /** + * Constructor. + * + * @param name name + * @param actor actor + * @param recipe recipe + * @param payload payload + * @param target target + */ + public Policy(String name, String actor, String recipe, Map payload, Target target) { + this.name = name; + this.actor = actor; + this.recipe = recipe; + this.target = target; + if (payload != null) { + this.payload = Collections.unmodifiableMap(payload); + } + } + + /** + * Constructor. + * + * @param name name + * @param actor actor + * @param recipe recipe + * @param payload payload + * @param target target + * @param retries retries + * @param timeout timeout + */ + public Policy(String name, String actor, String recipe, Map payload, Target target, + Integer retries, Integer timeout) { + this(name, actor, recipe, payload, target); + this.retry = retries; + this.timeout = timeout; + } + + /** + * Constructor. + * + * @param id id + * @param name name + * @param description description + * @param actor actor + * @param payload payload + * @param target target + * @param recipe recipe + * @param retries retries + * @param timeout timeout + */ + public Policy(String id, String name, String description, String actor, Map payload, + Target target, String recipe, Integer retries, Integer timeout) { + this(name, actor, recipe, payload, target, retries, timeout); + this.id = id; + this.description = description; + } + + /** + * Constructor. + * + * @param policy copy object + */ + public Policy(Policy policy) { + this.id = policy.id; + this.name = policy.name; + this.description = policy.description; + this.actor = policy.actor; + this.recipe = policy.recipe; + if (policy.payload != null) { + this.payload = Collections.unmodifiableMap(policy.payload); + } + this.target = policy.target; + this.operationsAccumulateParams = policy.operationsAccumulateParams; + this.retry = policy.retry; + this.timeout = policy.timeout; + this.success = policy.success; + this.failure = policy.failure; + this.failureException = policy.failureException; + this.failureGuard = policy.failureGuard; + this.failureRetries = policy.failureRetries; + this.failureTimeout = policy.failureTimeout; + } + public String getId() { return id; } @@ -178,93 +265,6 @@ public class Policy implements Serializable { this.failureGuard = failureGuard; } - public Policy(String id) { - this.id = id; - } - - /** - * Constructor. - * - * @param name name - * @param actor actor - * @param recipe recipe - * @param payload payload - * @param target target - */ - public Policy(String name, String actor, String recipe, Map payload, Target target) { - this.name = name; - this.actor = actor; - this.recipe = recipe; - this.target = target; - if (payload != null) { - this.payload = Collections.unmodifiableMap(payload); - } - } - - /** - * Constructor. - * - * @param name name - * @param actor actor - * @param recipe recipe - * @param payload payload - * @param target target - * @param retries retries - * @param timeout timeout - */ - public Policy(String name, String actor, String recipe, Map payload, Target target, - Integer retries, Integer timeout) { - this(name, actor, recipe, payload, target); - this.retry = retries; - this.timeout = timeout; - } - - /** - * Constructor. - * - * @param id id - * @param name name - * @param description description - * @param actor actor - * @param payload payload - * @param target target - * @param recipe recipe - * @param retries retries - * @param timeout timeout - */ - public Policy(String id, String name, String description, String actor, Map payload, - Target target, String recipe, Integer retries, Integer timeout) { - this(name, actor, recipe, payload, target, retries, timeout); - this.id = id; - this.description = description; - } - - /** - * Constructor. - * - * @param policy copy object - */ - public Policy(Policy policy) { - this.id = policy.id; - this.name = policy.name; - this.description = policy.description; - this.actor = policy.actor; - this.recipe = policy.recipe; - if (policy.payload != null) { - this.payload = Collections.unmodifiableMap(policy.payload); - } - this.target = policy.target; - this.operationsAccumulateParams = policy.operationsAccumulateParams; - this.retry = policy.retry; - this.timeout = policy.timeout; - this.success = policy.success; - this.failure = policy.failure; - this.failureException = policy.failureException; - this.failureGuard = policy.failureGuard; - this.failureRetries = policy.failureRetries; - this.failureTimeout = policy.failureTimeout; - } - public boolean isValid() { return id != null && name != null && actor != null && recipe != null && target != null; } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java index 61d1ae285..eab6967f1 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java @@ -33,22 +33,6 @@ public class Target implements Serializable { //Does Nothing Empty Constructor } - public String getResourceID() { - return resourceId; - } - - public void setResourceID(String resourceId) { - this.resourceId = resourceId; - } - - public TargetType getType() { - return type; - } - - public void setType(TargetType type) { - this.type = type; - } - public Target(TargetType type) { this.type = type; } @@ -67,6 +51,22 @@ public class Target implements Serializable { this.resourceId = target.resourceId; } + public String getResourceID() { + return resourceId; + } + + public void setResourceID(String resourceId) { + this.resourceId = resourceId; + } + + public TargetType getType() { + return type; + } + + public void setType(TargetType type) { + this.type = type; + } + @Override public String toString() { return "Target [type=" + type + ", resourceId=" + resourceId + "]"; diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java index 618678e9c..4038f3b74 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java @@ -22,10 +22,10 @@ package org.onap.policy.controlloop.policy.builder; public class BuilderException extends Exception { + private static final long serialVersionUID = 610064813684337895L; + public BuilderException(String string) { super(string); } - private static final long serialVersionUID = 610064813684337895L; - } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java index 5ac1fdc91..9332bfbe4 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java @@ -191,10 +191,24 @@ public class Constraint { this.maxVnfCount = maxVnfCount; } - + /** + * Check if these constraint values are valid. + * + * @return true if valid + */ public boolean isValid() { - return ((freqLimitPerTarget == null && timeWindow != null) - || (timeWindow == null && freqLimitPerTarget != null)) ? false : true; + // + // Sonar likes these statements combined as well as not use + // boolean literals. + // + // If the freqLimitPerTarget is null AND the timeWindow is NOT null + // OR + // timeWindow is null AND the freqLimitPerTarget is NOT null + // + // then we want to return false (hence the preceding !) + // + return ! ((freqLimitPerTarget == null && timeWindow != null) + || (timeWindow == null && freqLimitPerTarget != null)); } @Override diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java index 799c5fcd7..b76c4578e 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java @@ -36,46 +36,6 @@ public class GuardPolicy { //Do Nothing Empty Constructor. } - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public MatchParameters getMatch_parameters() { - return matchParameters; - } - - public void setMatch_parameters(MatchParameters matchParameters) { - this.matchParameters = matchParameters; - } - - public LinkedList getLimit_constraints() { - return limitConstraints; - } - - public void setLimit_constraints(LinkedList limitConstraints) { - this.limitConstraints = limitConstraints; - } - public GuardPolicy(String id) { this.id = id; } @@ -140,6 +100,46 @@ public class GuardPolicy { } } + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public MatchParameters getMatch_parameters() { + return matchParameters; + } + + public void setMatch_parameters(MatchParameters matchParameters) { + this.matchParameters = matchParameters; + } + + public LinkedList getLimit_constraints() { + return limitConstraints; + } + + public void setLimit_constraints(LinkedList limitConstraints) { + this.limitConstraints = limitConstraints; + } + public boolean isValid() { return (id == null || name == null) ? false : true; } diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java index 1bf10734d..0b1380972 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java @@ -34,38 +34,6 @@ public class MatchParameters { // Do Nothing Empty Constructor. } - public String getControlLoopName() { - return controlLoopName; - } - - public void setControlLoopName(String controlLoopName) { - this.controlLoopName = controlLoopName; - } - - public String getActor() { - return actor; - } - - public void setActor(String actor) { - this.actor = actor; - } - - public String getRecipe() { - return recipe; - } - - public void setRecipe(String recipe) { - this.recipe = recipe; - } - - public List getTargets() { - return targets; - } - - public void setTargets(List targets) { - this.targets = targets; - } - public MatchParameters(String actor, String recipe) { this.actor = actor; this.recipe = recipe; @@ -105,6 +73,38 @@ public class MatchParameters { } } + public String getControlLoopName() { + return controlLoopName; + } + + public void setControlLoopName(String controlLoopName) { + this.controlLoopName = controlLoopName; + } + + public String getActor() { + return actor; + } + + public void setActor(String actor) { + this.actor = actor; + } + + public String getRecipe() { + return recipe; + } + + public void setRecipe(String recipe) { + this.recipe = recipe; + } + + public List getTargets() { + return targets; + } + + public void setTargets(List targets) { + this.targets = targets; + } + @Override public String toString() { return "MatchParameters [controlLoopName=" + controlLoopName + ", actor=" + actor + ", recipe=" + recipe diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java index f995ba4c6..da2b9a122 100644 --- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java +++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java @@ -235,7 +235,7 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder { try { ControlLoopGuardCompiler.compile(clGuard, callback); } catch (CompilerException e) { - logger.error(e.getMessage() + e); + logger.error("Build specification threw ", e); callback.results.addMessage(new MessageImpl(e.getMessage(), MessageLevel.EXCEPTION)); } // diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java index 3bacead01..8fa4892fb 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java @@ -43,6 +43,9 @@ import org.onap.policy.aai.util.Serialization; public class AaiSimulatorJaxRs { private static final String VSERVER = "vserver"; + private static final String DISABLE_CLOSEDLOOP = "disableClosedLoop"; + private static final String ERROR = "error"; + private static final String GETFAIL = "getFail"; /** * A&AI get query. @@ -77,7 +80,7 @@ public class AaiSimulatorJaxRs { if (request.getInstanceFilters().getInstanceFilter().get(0).containsKey(VSERVER)) { final String vserverName = request.getInstanceFilters().getInstanceFilter().get(0).get(VSERVER).get("vserver-name"); - if ("error".equals(vserverName)) { + if (ERROR.equals(vserverName)) { Map params = new TreeMap<>(); params.put("type", VSERVER); return load("aai/AaiNqResponse-Error.json", params); @@ -89,7 +92,7 @@ public class AaiSimulatorJaxRs { } else { final String vnfId = request.getInstanceFilters().getInstanceFilter().get(0).get("generic-vnf").get("vnf-id"); - if ("error".equals(vnfId)) { + if (ERROR.equals(vnfId)) { Map params = new TreeMap<>(); params.put("type", "generic-vnf"); return load("aai/AaiNqResponse-Error.json", params); @@ -120,14 +123,14 @@ public class AaiSimulatorJaxRs { @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") public String getByVnfName(@QueryParam("vnf-name") final String vnfName) { - if ("getFail".equals(vnfName)) { + if (GETFAIL.equals(vnfName)) { return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/" + "generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs" + "/generic-vnf\",\"ERR.5.4.6114\"]}}}"; } - final boolean isDisabled = "disableClosedLoop".equals(vnfName); - if ("error".equals(vnfName)) { + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfName); + if (ERROR.equals(vnfName)) { return "{ \"vnf-id\": \"error\", \"vnf-name\": \"" + vnfName + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"" + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"" @@ -195,13 +198,13 @@ public class AaiSimulatorJaxRs { @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") public String getByVnfId(@PathParam("vnfId") final String vnfId) { - if ("getFail".equals(vnfId)) { + if (GETFAIL.equals(vnfId)) { return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/" + "generic-vnf/getFail\",\"Node Not Found:No Node of type generic-vnf found at network/" + "generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}"; } - final boolean isDisabled = "disableClosedLoop".equals(vnfId); + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfId); final String vnfName = getUuidValue(vnfId, "USUCP0PCOIL0110UJRT01"); return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName + "\", \"vnf-type\": \"RT\", \"service-id\": \"" @@ -241,12 +244,12 @@ public class AaiSimulatorJaxRs { @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") public String getByVserverName(@QueryParam("vserver-name") final String vserverName) { - if ("getFail".equals(vserverName)) { + if (GETFAIL.equals(vserverName)) { return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not" + " Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}"; } - final boolean isDisabled = "disableClosedLoop".equals(vserverName); + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vserverName); final String vserverId = getUuidValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8"); return "{\"vserver\": [{ \"vserver-id\": \"" + vserverId + "\", \"vserver-name\": \"" + vserverName + "\", \"vserver-name2\": \"vjunos0\", \"vserver-selflink\": \"https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8\", \"in-maint\": false, \"is-closed-loop-disabled\": " diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java index 58aae6267..16ae615af 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -26,10 +26,6 @@ import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.utils.network.NetworkUtil; public class Util { - private Util() { - // Prevent instantiation of thic class - } - public static final String AAISIM_SERVER_NAME = "aaiSim"; public static final String SOSIM_SERVER_NAME = "soSim"; public static final String VFCSIM_SERVER_NAME = "vfcSim"; @@ -39,6 +35,13 @@ public class Util { public static final int SOSIM_SERVER_PORT = 6667; public static final int VFCSIM_SERVER_PORT = 6668; public static final int GUARDSIM_SERVER_PORT = 6669; + + private static final String CANNOT_CONNECT = "cannot connect to port "; + private static final String LOCALHOST = "localhost"; + + private Util() { + // Prevent instantiation of thic class + } /** * Build an A&AI simulator. @@ -49,11 +52,11 @@ public class Util { */ public static HttpServletServer buildAaiSim() throws InterruptedException, IOException { final HttpServletServer testServer = - HttpServletServer.factory.build(AAISIM_SERVER_NAME, "localhost", AAISIM_SERVER_PORT, "/", false, true); + HttpServletServer.factory.build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen("localhost", testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException("cannot connect to port " + testServer.getPort()); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); } return testServer; } @@ -67,11 +70,11 @@ public class Util { */ public static HttpServletServer buildSoSim() throws InterruptedException, IOException { final HttpServletServer testServer = - HttpServletServer.factory.build(SOSIM_SERVER_NAME, "localhost", SOSIM_SERVER_PORT, "/", false, true); + HttpServletServer.factory.build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen("localhost", testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException("cannot connect to port " + testServer.getPort()); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); } return testServer; } @@ -85,11 +88,11 @@ public class Util { */ public static HttpServletServer buildVfcSim() throws InterruptedException, IOException { final HttpServletServer testServer = - HttpServletServer.factory.build(VFCSIM_SERVER_NAME, "localhost", VFCSIM_SERVER_PORT, "/", false, true); + HttpServletServer.factory.build(VFCSIM_SERVER_NAME,LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen("localhost", testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException("cannot connect to port " + testServer.getPort()); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); } return testServer; } @@ -102,12 +105,12 @@ public class Util { * @throws IOException if an IO errror occurs */ public static HttpServletServer buildGuardSim() throws InterruptedException, IOException { - HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, "localhost", + HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen("localhost", testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException("cannot connect to port " + testServer.getPort()); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); } return testServer; } -- cgit 1.2.3-korg