From 6a9b54b275feff5369419a86997e94d0a95fc48e Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Thu, 7 Jun 2018 16:01:35 +0100 Subject: Fixing Sonar bugs and Vulnerabilities Change-Id: Id5a95f23f1308dbb9f7f0c0f5567e238ecf830af Issue-ID: POLICY-859 Signed-off-by: waqas.ikram --- .../apex/auth/clieditor/ApexCLIEditorMain.java | 8 +- .../auth/clieditor/TestCLIEditorEventsContext.java | 96 +++++++++++++++++----- .../src/test/resources/model/empty_commands.json | 3 + .../test/locking/ConcurrentContextThread.java | 8 +- .../apex/core/deployment/DeploymentClient.java | 35 ++++---- .../apex/core/deployment/EngineServiceFacade.java | 26 ++++-- .../apex/core/engine/executor/StateOutput.java | 21 ++--- .../engine/executor/context/AxStateFacade.java | 2 +- .../core/engine/executor/context/AxTaskFacade.java | 2 +- .../context/StateFinalizerExecutionContext.java | 2 +- .../messaging/impl/ws/RawMessageHandler.java | 24 ++++-- .../messaging/impl/ws/client/MessagingClient.java | 25 ++++-- .../impl/ws/server/MessageServerImpl.java | 10 ++- .../messaging/util/MessagingUtils.java | 89 +++++++++----------- .../infrastructure/threading/ThreadUtilities.java | 2 + .../distribution/infinispan/InfinispanManager.java | 88 ++------------------ .../locking/curator/CuratorLockManager.java | 2 + .../schema/avro/AvroObjectMapperFactory.java | 2 +- .../context/schema/avro/AvroSchemaHelper.java | 2 +- .../engine/engdep/EngDepMessageListener.java | 2 + .../service/engine/main/ApexEventMarshaller.java | 4 + .../service/engine/main/ApexEventUnmarshaller.java | 2 + .../service/engine/runtime/impl/EngineWorker.java | 2 + .../CarrierTechnologyParametersJSONAdapter.java | 7 +- .../EventProtocolParametersJSONAdapter.java | 3 +- 25 files changed, 244 insertions(+), 223 deletions(-) create mode 100644 auth/cli-editor/src/test/resources/model/empty_commands.json diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java index 4a2635efa..cb1a92eaf 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java @@ -78,7 +78,6 @@ public class ApexCLIEditorMain { // Read the command definitions try { commands = new JSONHandler().read(CLICommands.class, parameters.getMetadataStream()); - LOGGER.debug("found " + commands.getCommandSet().size() + " commands"); } catch (final Exception e) { LOGGER.error("start of Apex command line editor failed, error reading command metadata from " + parameters.getMetadataLocation()); @@ -88,18 +87,19 @@ public class ApexCLIEditorMain { } // The JSON processing returns null if there is an empty file - if (null == commands) { + if (commands == null || commands.getCommandSet().isEmpty()) { LOGGER.error("start of Apex command line editor failed, no commands found in " + parameters.getApexPropertiesLocation()); errorCount++; return; } + LOGGER.debug("found " + commands.getCommandSet().size() + " commands"); + // Read the Apex properties try { apexModelProperties = new JSONHandler().read(ApexModelProperties.class, parameters.getApexPropertiesStream()); - LOGGER.debug("model properties are: " + apexModelProperties.toString()); } catch (final Exception e) { LOGGER.error("start of Apex command line editor failed, error reading Apex model properties from " + parameters.getApexPropertiesLocation()); @@ -116,6 +116,8 @@ public class ApexCLIEditorMain { return; } + LOGGER.debug("model properties are: " + apexModelProperties.toString()); + // Find the system commands final Set systemCommandNodes = new TreeSet<>(); for (final CLICommand command : commands.getCommandSet()) { diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java index 43238d63d..4b8dbd23b 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java @@ -24,8 +24,12 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.utilities.TextFileUtils; @@ -35,6 +39,25 @@ import org.onap.policy.apex.model.utilities.TextFileUtils; public class TestCLIEditorEventsContext { // CHECKSTYLE:OFF: MagicNumber + private static final Path SRC_MAIN_FOLDER = Paths.get("src/main/resources/"); + private static final Path SRC_TEST_FOLDER = Paths.get("src/test/resources/"); + + private static final Path SUB_FOLDER = SRC_MAIN_FOLDER.resolve("examples/scripts/"); + + private static final String SPACES = "\\s+"; + private static final String EMPTY_STRING = ""; + + private static final Path APEX_AVRO_POLICY_FILE = SUB_FOLDER.resolve("TestPolicyAvroEventContext.apex"); + private static final Path APEX_JAVA_POLICY_FILE = SUB_FOLDER.resolve("TestPolicyJavaEventContext.apex"); + + private static final String FILE_NAME = "TestPolicyJavaEventsAndContext"; + private static final String JSON_FILE = FILE_NAME + ".json"; + private static final String LOG_FILE = FILE_NAME + ".log"; + + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + /** * Test java context model. * @@ -43,12 +66,12 @@ public class TestCLIEditorEventsContext { */ @Test public void testJavaContextModel() throws IOException, ApexModelException { - final File tempLogFile = File.createTempFile("TestPolicyJavaEventsAndContext", ".log"); - final File tempModelFile = File.createTempFile("TestPolicyJavaEventsAndContext", ".json"); - final String[] cliArgs = - new String[] {"-c", "src/main/resources/examples/scripts/TestPolicyJavaEventContext.apex", "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + final String[] cliArgs = new String[] {"-c", APEX_JAVA_POLICY_FILE.toString(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -58,14 +81,11 @@ public class TestCLIEditorEventsContext { final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); // As a sanity check, count the number of non white space characters in log and model files - final int logCharCount = logString.replaceAll("\\s+", "").length(); - final int modelCharCount = modelString.replaceAll("\\s+", "").length(); + final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); + final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); assertEquals(25911, logCharCount); assertEquals(46138, modelCharCount); - - tempLogFile.delete(); - tempModelFile.delete(); } /** @@ -76,12 +96,12 @@ public class TestCLIEditorEventsContext { */ @Test public void testAvroContextModel() throws IOException, ApexModelException { - final File tempLogFile = File.createTempFile("TestPolicyAvroEventsAndContext", ".log"); - final File tempModelFile = File.createTempFile("TestPolicyAvroEventsAndContext", ".json"); - final String[] cliArgs = - new String[] {"-c", "src/main/resources/examples/scripts/TestPolicyAvroEventContext.apex", "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + final String[] cliArgs = new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -91,13 +111,51 @@ public class TestCLIEditorEventsContext { final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); // As a sanity check, count the number of non white space characters in log and model files - final int logCharCount = logString.replaceAll("\\s+", "").length(); - final int modelCharCount = modelString.replaceAll("\\s+", "").length(); + final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); + final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); assertEquals(30315, logCharCount); assertEquals(52930, modelCharCount); - tempLogFile.delete(); - tempModelFile.delete(); } + + @Test + public void test_emptyMetadataCommandFileWithEmptyJsonTag_errorcountGreaterThanOne() throws IOException { + + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + final String modelFile = SRC_TEST_FOLDER.resolve("model").resolve("empty_commands.json").toString(); + final String apexPropertiesLocation = + SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString(); + + final String[] cliArgs = + new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", + tempModelFile.getAbsolutePath(), "-m", modelFile, "-a", apexPropertiesLocation}; + + final ApexCLIEditorMain objUnderTest = new ApexCLIEditorMain(cliArgs); + assertEquals(1, objUnderTest.getErrorCount()); + + } + + @Test + public void test_emptyMetadataCommandFile_errorcountGreaterThanOne() throws IOException { + + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + final File modelFile = temporaryFolder.newFile("empty_commands.json"); + + final String apexPropertiesLocation = + SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString(); + + final String[] cliArgs = new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath(), "-m", modelFile.getAbsolutePath(), + "-a", apexPropertiesLocation}; + + final ApexCLIEditorMain objUnderTest = new ApexCLIEditorMain(cliArgs); + assertEquals(1, objUnderTest.getErrorCount()); + + } + } diff --git a/auth/cli-editor/src/test/resources/model/empty_commands.json b/auth/cli-editor/src/test/resources/model/empty_commands.json new file mode 100644 index 000000000..49d1a202f --- /dev/null +++ b/auth/cli-editor/src/test/resources/model/empty_commands.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/context/context-test/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java b/context/context-test/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java index 6ffacbb6c..42e3e0978 100644 --- a/context/context-test/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java +++ b/context/context-test/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java @@ -138,14 +138,8 @@ public class ConcurrentContextThread implements Runnable { item = new TestContextItem003(0L); } lTypeAlbum.put("testValue", item); - } catch (final Exception exception) { - throw exception; } finally { - try { - lTypeAlbum.unlockForWriting("testValue"); - } catch (final ContextException contextException) { - throw contextException; - } + lTypeAlbum.unlockForWriting("testValue"); } } } diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java index c2a19a167..5fc7dc8c6 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java @@ -20,8 +20,6 @@ package org.onap.policy.apex.core.deployment; -import com.google.common.eventbus.Subscribe; - import java.net.URI; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -37,10 +35,13 @@ import org.onap.policy.apex.core.protocols.Message; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; +import com.google.common.eventbus.Subscribe; + /** - * The Class DeploymentClient handles the client side of an EngDep communication session with an Apex server. It runs a - * thread to handle message sending and session monitoring. It uses a sending queue to queue messages for sending by the - * client thread and a receiving queue to queue messages received from the Apex engine. + * The Class DeploymentClient handles the client side of an EngDep communication session with an + * Apex server. It runs a thread to handle message sending and session monitoring. It uses a sending + * queue to queue messages for sending by the client thread and a receiving queue to queue messages + * received from the Apex engine. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -90,7 +91,8 @@ public class DeploymentClient implements Runnable { thisThread.setName(DeploymentClient.class.getName() + "-" + host + ":" + port); try { - // Establish a connection to the Apex server for EngDep message communication over Web Sockets + // Establish a connection to the Apex server for EngDep message communication over Web + // Sockets service = factory.createClient(new URI("ws://" + host + ":" + port)); service.addMessageListener(new DeploymentClientListener()); @@ -101,7 +103,6 @@ public class DeploymentClient implements Runnable { LOGGER.error("engine<-->deployment client thread exception", e); return; } - // Loop forever, sending messages as they appear on the queue while (true) { try { @@ -110,6 +111,8 @@ public class DeploymentClient implements Runnable { } catch (final InterruptedException e) { // Message sending has been interrupted, we are finished LOGGER.debug("engine<-->deployment client interrupted"); + // restore the interrupt status + thisThread.interrupt(); break; } } @@ -169,10 +172,11 @@ public class DeploymentClient implements Runnable { } /** - * The listener interface for receiving deploymentClient events. The class that is interested in processing a - * deploymentClient event implements this interface, and the object created with that class is registered with a - * component using the component's {@code addDeploymentClientListener} method. When the deploymentClient event - * occurs, that object's appropriate method is invoked. + * The listener interface for receiving deploymentClient events. The class that is interested in + * processing a deploymentClient event implements this interface, and the object created with + * that class is registered with a component using the component's + * {@code addDeploymentClientListener} method. When the deploymentClient event occurs, that + * object's appropriate method is invoked. * * @see DeploymentClientEvent */ @@ -180,8 +184,9 @@ public class DeploymentClient implements Runnable { /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(org.onap.policy.apex.core. - * infrastructure.messaging.impl.ws.messageblock. MessageBlock) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(org.onap. + * policy.apex.core. infrastructure.messaging.impl.ws.messageblock. MessageBlock) */ @Subscribe @Override @@ -192,7 +197,9 @@ public class DeploymentClient implements Runnable { /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(java.lang.String) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(java.lang. + * String) */ @Override public void onMessage(final String messageString) { diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java index d954feaa3..11e870c9c 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java @@ -50,11 +50,12 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * The Class Deployer deploys an Apex model held as an XML file onto an Apex engine. It uses the EngDep protocol to - * communicate with the engine, with the EngDep protocol being carried on Java web sockets. + * The Class Deployer deploys an Apex model held as an XML file onto an Apex engine. It uses the + * EngDep protocol to communicate with the engine, with the EngDep protocol being carried on Java + * web sockets. * - * This deployer is a simple command line deployer that reads the communication parameters and the location of the XML - * model file as arguments. + * This deployer is a simple command line deployer that reads the communication parameters and the + * location of the XML model file as arguments. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -62,7 +63,8 @@ public class EngineServiceFacade { // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(EngineServiceFacade.class); - // The default message timeout and timeout increment (the amount of time between polls) in milliseconds + // The default message timeout and timeout increment (the amount of time between polls) in + // milliseconds private static final int CLIENT_START_WAIT_INTERVAL = 100; private static final int REPLY_MESSAGE_TIMEOUT_DEFAULT = 10000; private static final int REPLY_MESSAGE_TIMEOUT_INCREMENT = 100; @@ -100,7 +102,8 @@ public class EngineServiceFacade { try { LOGGER.debug("handshaking with server {}:{} . . .", hostName, port); - // Use the deployment client to handle the EngDep communication towards the Apex server. It runs a thread to + // Use the deployment client to handle the EngDep communication towards the Apex server. + // It runs a thread to // monitor the session and to send // messages client = new DeploymentClient(hostName, port); @@ -184,7 +187,8 @@ public class EngineServiceFacade { * * @param modelFileName the name of the model file containing the model to deploy * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing model + * @param force true if the model is to be applied even if it is incompatible with the existing + * model * @throws ApexException on Apex errors * @throws IOException on IO exceptions from the operating system */ @@ -215,7 +219,8 @@ public class EngineServiceFacade { * @param modelFileName the name of the model file containing the model to deploy * @param modelInputStream the stream that holds the Apex model * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing model + * @param force true if the model is to be applied even if it is incompatible with the existing + * model * @throws ApexException on model deployment errors */ public void deployModel(final String modelFileName, final InputStream modelInputStream, @@ -238,7 +243,8 @@ public class EngineServiceFacade { * * @param apexPolicyModel the name of the model to deploy * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing model + * @param force true if the model is to be applied even if it is incompatible with the existing + * model * @throws ApexException on model deployment errors */ public void deployModel(final AxPolicyModel apexPolicyModel, final boolean ignoreConflicts, final boolean force) @@ -436,6 +442,8 @@ public class EngineServiceFacade { try { receivedMessage = client.getReceiveQueue().poll(REPLY_MESSAGE_TIMEOUT_INCREMENT, TimeUnit.MILLISECONDS); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.warn("reception of response from server interrupted {}:{}", hostName, port, e); throw new ApexDeploymentException( "reception of response from server interrupted " + hostName + ':' + port, e); diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateOutput.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateOutput.java index 2274b7c23..aaec71b47 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateOutput.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateOutput.java @@ -34,7 +34,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput; import org.onap.policy.apex.model.utilities.Assertions; /** - * This class is the output of a state, and is used by the engine to decide what the next state for execution is. + * This class is the output of a state, and is used by the engine to decide what the next state for + * execution is. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -115,15 +116,11 @@ public class StateOutput { for (final Entry incomingFieldEntry : eventFieldMap.entrySet()) { final String fieldName = incomingFieldEntry.getKey(); final AxField fieldDef = incomingFieldDefinitionMap.get(fieldName); - try { - - // Check if this field is a field in the event - if (!outputEventDef.getFields().contains(fieldDef)) { - throw new StateMachineException( - "field \"" + fieldName + "\" does not exist on event \"" + outputEventDef.getID() + "\""); - } - } catch (final Exception e) { - e.printStackTrace(); + + // Check if this field is a field in the event + if (!outputEventDef.getFields().contains(fieldDef)) { + throw new StateMachineException( + "field \"" + fieldName + "\" does not exist on event \"" + outputEventDef.getID() + "\""); } // Set the value in the output event @@ -132,8 +129,8 @@ public class StateOutput { } /** - * This method copies any fields that exist on the input event that also exist on the output event if they are not - * set on the output event. + * This method copies any fields that exist on the input event that also exist on the output + * event if they are not set on the output event. * * @param incomingEvent The incoming event to copy from */ diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacade.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacade.java index 226f06ade..80d7e651b 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacade.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacade.java @@ -40,7 +40,7 @@ public class AxStateFacade { // CHECKSTYLE:OFF: checkstyle:visibilityModifier Logic has access to this field /** The full definition information for the state. */ - public AxState state; + public final AxState state; // CHECKSTYLE:ON: checkstyle:visibilityModifier diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacade.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacade.java index 015f3ae80..85bf96c8d 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacade.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacade.java @@ -46,7 +46,7 @@ public class AxTaskFacade { * The full definition of the task we are presenting a facade to, executing logic has full access to the task * definition. */ - public AxTask task; + public final AxTask task; // CHECKSTYLE:ON: checkstyle:visibilityModifier diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java index 2e5971142..874d4def1 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java @@ -70,7 +70,7 @@ public class StateFinalizerExecutionContext { * fields to determine what state output to select. Once a state finalizer has selected a state output, it must * marshal these fields so that they match the fields required for the event defined in the state output. */ - public Map fields; + public final Map fields; // A message specified in the logic private String message; diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java index 534bee8af..9d62a9f92 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java @@ -41,8 +41,8 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * The Class RawMessageHandler handles raw messages being received on a Java web socket and forwards the messages to the - * DataHandler instance that has subscribed to the RawMessageHandler instance. + * The Class RawMessageHandler handles raw messages being received on a Java web socket and forwards + * the messages to the DataHandler instance that has subscribed to the RawMessageHandler instance. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) * @param the generic type of message being received @@ -85,7 +85,8 @@ public class RawMessageHandler implements WebSocketMessageListener implements WebSocketMessageListener messageHolder = (MessageHolder) ois.readObject(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("message {} recieved from the client {} ", messageHolder.toString(), + LOGGER.debug("message {} recieved from the client {} ", messageHolder, messageHolder == null ? "Apex Engine " : messageHolder.getSenderHostAddress()); } @@ -111,7 +112,8 @@ public class RawMessageHandler implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener the generic type @@ -39,12 +39,13 @@ public class MessagingClient extends InternalMessageBusClient // The length of time to wait for a connection to a web socket server before aborting private static final int CONNECTION_TIMEOUT_TIME_MS = 3000; - // The length of time to wait before checking if a connection to a web socket server has worked or not + // The length of time to wait before checking if a connection to a web socket server has worked + // or not private static final int CONNECTION_TRY_INTERVAL_MS = 100; /** - * Constructor of this class, uses its {@link InternalMessageBusClient} superclass to set up the web socket and - * handle incoming message forwarding. + * Constructor of this class, uses its {@link InternalMessageBusClient} superclass to set up the + * web socket and handle incoming message forwarding. * * @param serverUri The URI of the service */ @@ -80,7 +81,11 @@ public class MessagingClient extends InternalMessageBusClient public void startConnection() { // Open the web socket final WebSocket connection = super.getConnection(); - if (connection != null && !connection.isOpen()) { + + if (connection == null) { + throw new IllegalStateException("Could not connect to the server"); + } + if (!connection.isOpen()) { connect(); } @@ -129,8 +134,9 @@ public class MessagingClient extends InternalMessageBusClient /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(org.onap.policy.apex.core. - * infrastructure. messaging.MessageHolder) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(org.onap.policy.apex + * .core. infrastructure. messaging.MessageHolder) */ @Override public void send(final MessageHolder commands) { @@ -142,7 +148,8 @@ public class MessagingClient extends InternalMessageBusClient /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(java.lang.String) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(java.lang.String) */ @Override public void send(final String messageString) { diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java index fc401576f..ee6e1a329 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java @@ -98,6 +98,8 @@ public class MessageServerImpl extends InternalMessageBusServer extends InternalMessageBusServer message) { @@ -134,7 +137,8 @@ public class MessageServerImpl extends InternalMessageBusServer, Runnable } } } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("message listener execution has been interrupted"); break; } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java index b4ba2ac3e..9904847aa 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java @@ -163,6 +163,8 @@ public class ApexEventMarshaller implements ApexEventListener, Runnable { try { queue.put(apexEvent); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.warn("Failed to queue the event: " + apexEvent, e); } } @@ -191,6 +193,8 @@ public class ApexEventMarshaller implements ApexEventListener, Runnable { LOGGER.trace("event sent : " + apexEvent.toString()); } } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("Thread interrupted, Reason {}", e.getMessage()); break; } catch (final Exception e) { diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java index a9385751e..7b4188ea1 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java @@ -276,6 +276,8 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { // Pass the event to the activator for forwarding to Apex engineServiceHandler.forwardEvent(apexEvent); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.warn("BatchProcessor thread interrupted, Reason {}", e.getMessage()); break; } catch (final Exception e) { diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java index 20f8aaf75..f74c0f47b 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java @@ -649,6 +649,8 @@ final class EngineWorker implements EngineService { try { event = eventProcessingQueue.take(); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("Engine {} processing interrupted ", engineWorkerKey); break; } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJSONAdapter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJSONAdapter.java index 5aa7d6455..e72a283cd 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJSONAdapter.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJSONAdapter.java @@ -124,9 +124,10 @@ public class CarrierTechnologyParametersJSONAdapter // Check the carrier technology parameter class if (carrierTechnologyParameterClassName == null || carrierTechnologyParameterClassName.length() == 0) { - final String errorMessage = - "carrier technology \"" + carrierTechnologyLabel + "\" parameter \"" + PARAMETER_CLASS_NAME - + "\" value \"" + classNameJsonPrimitive.getAsString() + "\" invalid in JSON file"; + final String errorMessage = "carrier technology \"" + carrierTechnologyLabel + "\" parameter \"" + + PARAMETER_CLASS_NAME + "\" value \"" + + (classNameJsonPrimitive != null ? classNameJsonPrimitive.getAsString() : "null") + + "\" invalid in JSON file"; LOGGER.warn(errorMessage); throw new ApexParameterRuntimeException(errorMessage); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJSONAdapter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJSONAdapter.java index c880756b3..1f33db6b8 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJSONAdapter.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJSONAdapter.java @@ -123,7 +123,8 @@ public class EventProtocolParametersJSONAdapter if (eventProtocolParameterClassName == null || eventProtocolParameterClassName.length() == 0) { final String errorMessage = "event protocol \"" + eventProtocolLabel + "\" parameter \"" + PARAMETER_CLASS_NAME + "\" value \"" - + classNameJsonPrimitive.getAsString() + "\" invalid in JSON file"; + + (classNameJsonPrimitive != null ? classNameJsonPrimitive.getAsString() : "null") + + "\" invalid in JSON file"; LOGGER.warn(errorMessage); throw new ApexParameterRuntimeException(errorMessage); } -- cgit 1.2.3-korg