diff options
30 files changed, 431 insertions, 401 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java index 4ab7b494f..e9fc27734 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java @@ -499,9 +499,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { this.currentOperation.getTargetEntity(), this.onset.getRequestId(), this); this.targetLock = lock; - LockResult<GuardResult, TargetLock> lockResult = - LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock); - return lockResult; + return LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock); } // // Have we acquired it already? 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; } @@ -185,49 +227,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. * * @param onset the onset event @@ -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/PipEngineGetStatus.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java index 36bb36f5c..b61ab5d73 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java @@ -148,7 +148,7 @@ public class PipEngineGetStatus extends StdConfigurableEngine { try { pipResponse = pipFinder.getMatchingAttributes(pipRequest, this); } catch (PIPException ex) { - logger.error("getAttribute threw:", ex); + logger.error("getAttribute threw", ex); return null; } if (pipResponse == null) { @@ -197,16 +197,17 @@ public class PipEngineGetStatus extends StdConfigurableEngine { Set<String> setUids = new HashSet<>(); for (Attribute attributeUid : listUids) { Iterator<AttributeValue<String>> iterAttributeValues = attributeUid.findValues(DataTypes.DT_STRING); - if (iterAttributeValues != null) { - while (iterAttributeValues.hasNext()) { - String uid = iterAttributeValues.next().getValue(); - if (uid != null) { - setUids.add(uid); - } + if (iterAttributeValues == null) { + continue; + } + while (iterAttributeValues.hasNext()) { + String uid = iterAttributeValues.next().getValue(); + if (uid == null) { + continue; } + setUids.add(uid); } } - return setUids; } @@ -220,13 +221,13 @@ public class PipEngineGetStatus extends StdConfigurableEngine { props.put(Util.ECLIPSE_LINK_KEY_USER, PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_USER)); props.put(Util.ECLIPSE_LINK_KEY_PASS, PolicyEngine.manager.getEnvironmentProperty(Util.ONAP_KEY_PASS)); } catch (NullPointerException e) { - logger.error("getStatusFromDB: {} when setting properties", e.getMessage()); + logger.error("getStatusFromDb: when setting properties", e); } // // Set opsHistPu to the correct value and clear properties if necessary. // String opsHistPu = System.getProperty("OperationsHistoryPU"); - if (opsHistPu == null || !opsHistPu.equals("TestOperationsHistoryPU")) { + if (!"TestOperationsHistoryPU".equals(opsHistPu)) { opsHistPu = "OperationsHistoryPU"; } else { props.clear(); @@ -240,14 +241,14 @@ public class PipEngineGetStatus extends StdConfigurableEngine { emf = Persistence.createEntityManagerFactory(opsHistPu, props); } catch (Exception ex) { logger.error("PIP thread got Exception. Can't connect to Operations History DB -- {}", opsHistPu); - logger.error("getStatusFromDb threw: ", ex); + logger.error("getStatusFromDb threw", ex); return null; } try { em = emf.createEntityManager(); } catch (Exception ex) { logger.error("PIP thread got Exception. Problem creating EntityManager"); - logger.error("getStatusFromDb threw: ", ex); + logger.error("getStatusFromDb threw", ex); emf.close(); return null; } @@ -269,7 +270,7 @@ public class PipEngineGetStatus extends StdConfigurableEngine { try { ret = ((String)nq.getSingleResult()); } catch (NoResultException ex) { - logger.debug("NoResultException for getSingleResult()"); + logger.debug("NoResultException for getSingleResult()", ex); ret = "NO_MATCHING_ENTRY"; } catch (Exception ex) { logger.error("getStatusFromDB threw an exception", ex); @@ -283,12 +284,12 @@ public class PipEngineGetStatus extends StdConfigurableEngine { try { em.close(); } catch (Exception ex) { - logger.error("getStatusFromDB threw an exception ", ex); + logger.error("getStatusFromDB threw an exception", ex); } try { emf.close(); } catch (Exception ex) { - logger.error("getStatusFromDB threw an exception ", ex); + logger.error("getStatusFromDB threw an exception", ex); } return ret; } 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<AaiNqInventoryResponseItem> vfModuleItems = new ArrayList<>(itemList.size());; + List<AaiNqInventoryResponseItem> 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<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { @@ -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<LcmRequest>, JsonDeserializer<LcmRequest> { @@ -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<PciRequest>, JsonDeserializer<PciRequest> { @@ -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 @@ <suppressions> <suppress checks="AbbreviationAsWordInName" - files="ControlLoopCompiler.java|Target.java|ControlLoopPolicyBuilder.java" + files="Target.java|ControlLoopPolicyBuilder.java" lines="1-9999"/> </suppressions> 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<NodeWrapper, LabeledEdge> 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<NodeWrapper, LabeledEdge> 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<NodeWrapper, LabeledEdge> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<Constraint> getLimit_constraints() { - return limitConstraints; - } - - public void setLimit_constraints(LinkedList<Constraint> 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<Constraint> getLimit_constraints() { + return limitConstraints; + } + + public void setLimit_constraints(LinkedList<Constraint> 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<String> getTargets() { - return targets; - } - - public void setTargets(List<String> 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<String> getTargets() { + return targets; + } + + public void setTargets(List<String> 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<String,String> 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<String,String> 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; } diff --git a/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java b/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java index 7abf38620..c75c8a0b7 100644 --- a/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java +++ b/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/CallGuardTaskEmbedded.java @@ -151,7 +151,7 @@ public class CallGuardTaskEmbedded 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/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java b/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java index e14946274..64fb70bbd 100644 --- a/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java +++ b/controlloop/templates/template.demo.clc/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelperEmbedded.java @@ -60,9 +60,14 @@ public class PolicyGuardXacmlHelperEmbedded { private static final Logger netLogger = LoggerFactory.getLogger(org.onap.policy.common.endpoints.event.comm.Topic.NETWORK_LOGGER); - // Constant for the systme line separator + // Constant for the system line separator private static final String SYSTEM_LS = System.lineSeparator(); - private static String propfile; + private String propfile; + private UrlEntry[] restUrls = null; + private int restUrlIndex = 0; + + // REST timeout, initialized from 'pdpx.timeout' property + private int timeout = 20000; public PolicyGuardXacmlHelperEmbedded() { init(PolicyEngine.manager.getEnvironment()); @@ -82,12 +87,6 @@ public class PolicyGuardXacmlHelperEmbedded { String environment = null; } - private UrlEntry[] restUrls = null; - private int restUrlIndex = 0; - - // REST timeout, initialized from 'pdpx.timeout' property - private int timeout = 20000; - /** * Call PDP. * @@ -133,7 +132,7 @@ public class PolicyGuardXacmlHelperEmbedded { urlEntry.authorization, urlEntry.clientAuth, urlEntry.environment); netLogger.info("[IN|{}|{}|]{}{}", "GUARD", urlEntry.restUrl, SYSTEM_LS, response); } catch (Exception e) { - logger.error("Error in sending RESTful request: ", e); + logger.error("Error in sending RESTful request", e); } return response; @@ -235,7 +234,7 @@ public class PolicyGuardXacmlHelperEmbedded { * @param xacmlReq the XACML request * @return the response */ - public static String callEmbeddedPdp(PolicyGuardXacmlRequestAttributes xacmlReq) { + public String callEmbeddedPdp(PolicyGuardXacmlRequestAttributes xacmlReq) { com.att.research.xacml.api.Response response = null; Properties props = new Properties(); // @@ -246,7 +245,7 @@ public class PolicyGuardXacmlHelperEmbedded { BufferedReader br = new BufferedReader(isr) ) { props.load(br); } catch (Exception e) { - logger.error("Unable to load properties file {} {}", propfile, e.getMessage()); + logger.error("Unable to load properties file {}", propfile, e); } // // Create embedded PDPEngine @@ -255,7 +254,7 @@ public class PolicyGuardXacmlHelperEmbedded { try { xacmlPdpEngine = ATTPDPEngineFactory.newInstance().newEngine(props); } catch (Exception e) { - logger.error("Failed to create new PDPEngine {}", e.getMessage()); + logger.error("callEmbeddedPdpEngine failed to create new PDPEngine", e); return null; } logger.debug("embedded Engine created"); @@ -269,7 +268,7 @@ public class PolicyGuardXacmlHelperEmbedded { try { response = xacmlPdpEngine.decide(RequestParser.parseRequest(xacmlReq)); } catch (Exception e) { - logger.error(e.getMessage(), e); + logger.error("callEmbeddedPdpEngine failed on decide", e); } long timeEnd = System.currentTimeMillis(); logger.debug("Elapsed Time: {} ms", (timeEnd - timeStart)); |