From 40bd91d884660f821909dfa6de742deb104d927e Mon Sep 17 00:00:00 2001 From: Dylan Mulligan Date: Wed, 22 Nov 2023 23:12:05 -0500 Subject: [PATCH 1/5] Remove redundant catch blocks --- .../src/main/java/edu/rit/se/nvip/ReconcilerMain.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/reconciler/src/main/java/edu/rit/se/nvip/ReconcilerMain.java b/reconciler/src/main/java/edu/rit/se/nvip/ReconcilerMain.java index 5be9a8d1..fa8e6c59 100644 --- a/reconciler/src/main/java/edu/rit/se/nvip/ReconcilerMain.java +++ b/reconciler/src/main/java/edu/rit/se/nvip/ReconcilerMain.java @@ -72,14 +72,8 @@ public static void main(String[] args) throws Exception { ReconcilerController rc = new ReconcilerController(DatabaseHelper.getInstance(), filterHandler, reconciler, nvdController, mitreController); - try{ - Messenger messenger = new Messenger(connectionFactory, inputQueueName, outputQueueName, rc); - messenger.run(); - } catch (TimeoutException e) { - logger.error("Error occurred while sending the Reconciler message to RabbitMQ: {}", e.getMessage()); - } catch (IOException e) { - logger.error(e.getMessage()); - } + Messenger messenger = new Messenger(connectionFactory, inputQueueName, outputQueueName, rc); + messenger.run(); // case "dev": // final Set devJobs = new HashSet<>(); // devJobs.add("CVE-2023-2825"); From af7239a6ec8f4b915d02622e2b465a4b14736b5f Mon Sep 17 00:00:00 2001 From: Dylan Mulligan Date: Fri, 24 Nov 2023 15:32:35 -0500 Subject: [PATCH 2/5] Fixed resource usage and added stack trace print --- .../src/main/java/edu/rit/se/nvip/messenger/Messenger.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reconciler/src/main/java/edu/rit/se/nvip/messenger/Messenger.java b/reconciler/src/main/java/edu/rit/se/nvip/messenger/Messenger.java index 618d580b..032f5913 100644 --- a/reconciler/src/main/java/edu/rit/se/nvip/messenger/Messenger.java +++ b/reconciler/src/main/java/edu/rit/se/nvip/messenger/Messenger.java @@ -88,8 +88,9 @@ public void run(){ } logger.info("Waiting for jobs from Crawler..."); - try(Connection connection = factory.newConnection(); - Channel channel = connection.createChannel()){ + try { + Connection connection = factory.newConnection(); + Channel channel = connection.createChannel(); channel.queueDeclare(inputQueue, true, false, false, null); channel.queueDeclare(outputQueue, true, false, false, null); @@ -118,6 +119,7 @@ public void run(){ logger.error("Error occurred while sending the Reconciler message to RabbitMQ: {}", e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); + e.printStackTrace(); } } From 466deb0e176d2b3da22b6cd3c9494e61e823960d Mon Sep 17 00:00:00 2001 From: Dylan Mulligan Date: Fri, 24 Nov 2023 23:08:41 -0500 Subject: [PATCH 3/5] Added try/catch to stop reconciler throwing 403 and crashing --- .../main/java/edu/rit/se/nvip/messenger/Messenger.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/reconciler/src/main/java/edu/rit/se/nvip/messenger/Messenger.java b/reconciler/src/main/java/edu/rit/se/nvip/messenger/Messenger.java index 032f5913..af0b0a7b 100644 --- a/reconciler/src/main/java/edu/rit/se/nvip/messenger/Messenger.java +++ b/reconciler/src/main/java/edu/rit/se/nvip/messenger/Messenger.java @@ -109,9 +109,12 @@ public void run(){ throw new RuntimeException(e); } }); - rc.characterizeCves(reconciledVulns); - rc.updateTimeGaps(reconciledVulns); - rc.createRunStats(reconciledVulns); + try { rc.characterizeCves(reconciledVulns); } + catch (Exception e) { logger.error(e.toString()); } + try { rc.updateTimeGaps(reconciledVulns); } + catch (Exception e) { logger.error(e.toString()); } + try { rc.createRunStats(reconciledVulns); } + catch (Exception e) { logger.error(e.toString()); } }; channel.basicConsume(inputQueue, true, deliverCallback, consumerTag -> { }); From d25d2b19027a52de52d7e16e9ed8f45452aeb1a2 Mon Sep 17 00:00:00 2001 From: Dylan Mulligan Date: Tue, 28 Nov 2023 14:40:03 -0500 Subject: [PATCH 4/5] Set rabbit queues to noWait to prevent communication errors --- .../src/main/java/messenger/Messenger.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/productnameextractor/src/main/java/messenger/Messenger.java b/productnameextractor/src/main/java/messenger/Messenger.java index 7851c6d2..0dfd4b41 100644 --- a/productnameextractor/src/main/java/messenger/Messenger.java +++ b/productnameextractor/src/main/java/messenger/Messenger.java @@ -82,10 +82,13 @@ public void run() { Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); - // TODO: Needed? - channel.queueDeclare(inputQueue, true, false, false, null); - channel.queueDeclare(patchFinderOutputQueue, true, false, false, null); - channel.queueDeclare(fixFinderOutputQueue, true, false, false, null); + channel.queueDeclareNoWait(inputQueue, true, false, false, null); + channel.queueDeclareNoWait(patchFinderOutputQueue, true, false, false, null); + channel.queueDeclareNoWait(fixFinderOutputQueue, true, false, false, null); + // TODO: Remove when queue issue is resolved (errors thrown likely when producer does not receive info from consumer) +// channel.queueDeclare(inputQueue, true, false, false, null); +// channel.queueDeclare(patchFinderOutputQueue, true, false, false, null); +// channel.queueDeclare(fixFinderOutputQueue, true, false, false, null); channel.basicConsume(inputQueue, false, new DefaultConsumer(channel) { @Override From 1e0b1321c44e4be2f56c0e8750354519845c6ba8 Mon Sep 17 00:00:00 2001 From: Dylan Mulligan Date: Tue, 28 Nov 2023 14:40:19 -0500 Subject: [PATCH 5/5] Improve logging --- .../src/main/java/dictionary/ProductDictionary.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/productnameextractor/src/main/java/dictionary/ProductDictionary.java b/productnameextractor/src/main/java/dictionary/ProductDictionary.java index 0cc4e603..f4c5ef26 100644 --- a/productnameextractor/src/main/java/dictionary/ProductDictionary.java +++ b/productnameextractor/src/main/java/dictionary/ProductDictionary.java @@ -120,10 +120,11 @@ public static void initializeProductDict(){ final long timeSinceLastFullPull = Duration.between(productDictLastCompilationDate, Instant.now()).getSeconds(); final long timeSinceLastRefresh = Duration.between(productDictLastRefreshDate, Instant.now()).getSeconds(); - logger.info("Successfully read {} products from file '{}' ({} day(s) old)", + logger.info("Successfully read {} products from file '{}' ({} day(s) since refresh, {} day(s) since full query)", productDict.size(), - productDictName, - Math.floor((float) timeSinceLastRefresh / 3600 / 24 * 10) / 10 // seconds -> hours + productDictPath, + Math.floor((float) timeSinceLastRefresh / 3600 / 24 * 10) / 10, // seconds -> hours + Math.floor((float) timeSinceLastFullPull / 3600 / 24 * 10) / 10 // seconds -> hours ); // Update dictionary as needed