From 77df45928640808633af05908c680955848e4cd2 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 14 Jun 2019 15:02:00 -0400 Subject: Fix simple sonar issues in models: errors to sim-pdp models-errors models-pdp models-provider models-sim-pdp Also had to work around this checkstyle issue: src/test/java/org/onap/policy/models/sim/pdp/comm/ TestPdpStateChangeListener.java:[77,32] (javadoc) JavadocMethod: Unable to get class information for @throws tag 'PdpSimulatorException'. The error appears to be bogus, as PdpSimulatorException is on the "throws" line thus indicating that the class IS accessible to the above java file. Change-Id: Iaca58457a32b00121000fc0bab12a8be4cb19bac Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn --- .../policy/models/sim/pdp/PdpSimulatorActivator.java | 20 ++++++++++---------- .../onap/policy/models/sim/pdp/PdpSimulatorMain.java | 7 ++++--- .../models/sim/pdp/handler/PdpMessageHandler.java | 3 +-- .../pdp/handler/PdpStateChangeMessageHandler.java | 6 +----- .../sim/pdp/handler/PdpUpdateMessageHandler.java | 15 ++++----------- .../pdp/parameters/PdpSimulatorParameterHandler.java | 11 +++++------ 6 files changed, 25 insertions(+), 37 deletions(-) (limited to 'models-sim/policy-models-sim-pdp/src/main/java/org') diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java index be396de05..502dec7b3 100644 --- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java +++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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,9 @@ package org.onap.policy.models.sim.pdp; import java.util.List; import java.util.Properties; - +import java.util.Random; import lombok.Getter; import lombok.Setter; - - import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; @@ -57,6 +56,7 @@ public class PdpSimulatorActivator { private List topicSinks;// topics to which pdp sends pdp status private List topicSources; // topics to which pdp listens to for messages from pap. private static final String[] MSG_TYPE_NAMES = { "messageName" }; + private static final Random RANDOM = new Random(); /** * Listens for messages on the topic, decodes them into a message, and then dispatches them. @@ -85,9 +85,9 @@ public class PdpSimulatorActivator { topicSinks = TopicEndpoint.manager.addTopicSinks(topicProperties); topicSources = TopicEndpoint.manager.addTopicSources(topicProperties); - final int random = (int) (Math.random() * 1000); + final int random = RANDOM.nextInt(); final String instanceId = "pdp_" + random; - LOGGER.debug("PdpSimulatorActivator initializing with instance id:" + instanceId); + LOGGER.debug("PdpSimulatorActivator initializing with instance id: {}", instanceId); try { this.pdpSimulatorParameterGroup = pdpSimulatorParameterGroup; this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES); @@ -100,8 +100,8 @@ public class PdpSimulatorActivator { // @formatter:off this.manager = new ServiceManager() .addAction("topics", - () -> TopicEndpoint.manager.start(), - () -> TopicEndpoint.manager.shutdown()) + TopicEndpoint.manager::start, + TopicEndpoint.manager::shutdown) .addAction("set alive", () -> setAlive(true), () -> setAlive(false)) @@ -117,7 +117,7 @@ public class PdpSimulatorActivator { () -> Registry.register(PdpSimulatorConstants.REG_PDP_STATUS_PUBLISHER, new PdpStatusPublisher(topicSinks, pdpSimulatorParameterGroup.getPdpStatusParameters().getTimeIntervalMs())), - () -> stopAndRemovePdpStatusPublisher()) + this::stopAndRemovePdpStatusPublisher) .addAction("Register pdp update listener", () -> msgDispatcher.register(PdpMessageType.PDP_UPDATE.name(), pdpUpdateListener), () -> msgDispatcher.unregister(PdpMessageType.PDP_UPDATE.name())) @@ -125,8 +125,8 @@ public class PdpSimulatorActivator { () -> msgDispatcher.register(PdpMessageType.PDP_STATE_CHANGE.name(), pdpStateChangeListener), () -> msgDispatcher.unregister(PdpMessageType.PDP_STATE_CHANGE.name())) .addAction("Message Dispatcher", - () -> registerMsgDispatcher(), - () -> unregisterMsgDispatcher()); + this::registerMsgDispatcher, + this::unregisterMsgDispatcher); // @formatter:on } diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java index f5892d5c8..78330135a 100644 --- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java +++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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. @@ -23,8 +24,6 @@ package org.onap.policy.models.sim.pdp; import java.io.FileInputStream; import java.util.Arrays; import java.util.Properties; - - import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException; import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup; @@ -52,7 +51,9 @@ public class PdpSimulatorMain { * @param args the command line arguments */ public PdpSimulatorMain(final String[] args) { - LOGGER.info("In PdpSimulator with parameters ", Arrays.toString(args)); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("In PdpSimulator with parameters {}", Arrays.toString(args)); + } // Check the arguments final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments(); diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java index d4296c6df..7b8f29c4b 100644 --- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java +++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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,8 +23,6 @@ package org.onap.policy.models.sim.pdp.handler; import java.util.ArrayList; import java.util.List; - - import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.pdp.concepts.PdpResponseDetails; import org.onap.policy.models.pdp.concepts.PdpStatus; diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java index ec1fa25a3..9df1aa103 100644 --- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java +++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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. @@ -21,7 +22,6 @@ package org.onap.policy.models.sim.pdp.handler; import java.util.List; - import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.pdp.concepts.PdpResponseDetails; import org.onap.policy.models.pdp.concepts.PdpStateChange; @@ -31,8 +31,6 @@ import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.sim.pdp.PdpSimulatorConstants; import org.onap.policy.models.sim.pdp.comm.PdpStatusPublisher; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This class supports the handling of pdp state change messages. @@ -41,8 +39,6 @@ import org.slf4j.LoggerFactory; */ public class PdpStateChangeMessageHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(PdpStateChangeMessageHandler.class); - /** * Method which handles a pdp state change event from PAP. * diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java index 94499f43d..4f33d079f 100644 --- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java +++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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. @@ -21,8 +22,6 @@ package org.onap.policy.models.sim.pdp.handler; import java.util.List; - - import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.pdp.concepts.PdpResponseDetails; @@ -32,8 +31,6 @@ import org.onap.policy.models.pdp.enums.PdpResponseStatus; import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.sim.pdp.PdpSimulatorConstants; import org.onap.policy.models.sim.pdp.comm.PdpStatusPublisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This class supports the handling of pdp update messages. @@ -42,8 +39,6 @@ import org.slf4j.LoggerFactory; */ public class PdpUpdateMessageHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(PdpUpdateMessageHandler.class); - /** * Method which handles a pdp update event from PAP. * @@ -68,11 +63,9 @@ public class PdpUpdateMessageHandler { pdpStatusContext.setPdpSubgroup(pdpUpdateMsg.getPdpSubgroup()); pdpStatusContext .setPolicies(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies())); - if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) { - if (!pdpUpdateMsg.getPolicies().isEmpty()) { - pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(), - PdpResponseStatus.SUCCESS, "Pdp engine started and policies are running."); - } + if (pdpStatusContext.getState().equals(PdpState.ACTIVE) && !pdpUpdateMsg.getPolicies().isEmpty()) { + pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(), + PdpResponseStatus.SUCCESS, "Pdp engine started and policies are running."); } Registry.registerOrReplace(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST, pdpUpdateMsg.getPolicies()); if (null == pdpResponseDetails) { diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java index 2c5ccebf9..84ae53908 100644 --- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java +++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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. @@ -21,8 +22,6 @@ package org.onap.policy.models.sim.pdp.parameters; import java.io.File; - - import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -39,7 +38,7 @@ import org.slf4j.LoggerFactory; */ public class PdpSimulatorParameterHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(PdpSimulatorParameterHandler.class); + private static final Logger logger = LoggerFactory.getLogger(PdpSimulatorParameterHandler.class); private static final Coder CODER = new StandardCoder(); /** @@ -61,14 +60,14 @@ public class PdpSimulatorParameterHandler { } catch (final CoderException e) { final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath() + "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage(); - LOGGER.error(errorMessage, e); + logger.error(errorMessage); throw new PdpSimulatorException(errorMessage, e); } // The JSON processing returns null if there is an empty file if (pdpSimulatorParameterGroup == null) { final String errorMessage = "no parameters found in \"" + arguments.getConfigurationFilePath() + "\""; - LOGGER.error(errorMessage); + logger.error(errorMessage); throw new PdpSimulatorException(errorMessage); } @@ -79,7 +78,7 @@ public class PdpSimulatorParameterHandler { "validation error(s) on parameters from \"" + arguments.getConfigurationFilePath() + "\"\n"; returnMessage += validationResult.getResult(); - LOGGER.error(returnMessage); + logger.error(returnMessage); throw new PdpSimulatorException(returnMessage); } -- cgit 1.2.3-korg