From d16e2e37ecb47ff5f4331ed30e73a4b093a871c6 Mon Sep 17 00:00:00 2001 From: "Amir M. Mir" Date: Tue, 31 May 2022 17:42:13 +0200 Subject: [PATCH 1/7] Stop and restart the FASTEN plugins with a failed DB connection --- .../DebianLicenseFeederPlugin.java | 14 +++++++----- .../licensefeeder/LicenseFeederPlugin.java | 9 +++++--- .../metadataplugin/MetadataDBExtension.java | 22 ++++++++++++++++--- .../PythonLicenseFeederPlugin.java | 11 +++++----- .../VulnerabilityPackagesListener.java | 1 - .../VulnerabilityStatementsProcessor.java | 2 +- .../plugins/kafka/FastenKafkaPlugin.java | 9 ++++++++ 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/analyzer/debian-license-feeder/src/main/java/eu/fasten/analyzer/debianlicensefeeder/DebianLicenseFeederPlugin.java b/analyzer/debian-license-feeder/src/main/java/eu/fasten/analyzer/debianlicensefeeder/DebianLicenseFeederPlugin.java index 68f3198ff..636cca9eb 100644 --- a/analyzer/debian-license-feeder/src/main/java/eu/fasten/analyzer/debianlicensefeeder/DebianLicenseFeederPlugin.java +++ b/analyzer/debian-license-feeder/src/main/java/eu/fasten/analyzer/debianlicensefeeder/DebianLicenseFeederPlugin.java @@ -2,9 +2,6 @@ import eu.fasten.core.data.Constants; import eu.fasten.core.data.metadatadb.MetadataDao; -//This import should probably be different -import eu.fasten.core.maven.data.Revision; -import eu.fasten.core.plugins.AbstractKafkaPlugin; import eu.fasten.core.plugins.DBConnector; import eu.fasten.core.plugins.KafkaPlugin; import org.jooq.DSLContext; @@ -17,8 +14,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.Timestamp; -import java.util.*; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +//This import should probably be different public class DebianLicenseFeederPlugin extends Plugin { @@ -82,7 +84,7 @@ public void consume(String record) { } catch (Exception e) { // Fasten error-handling guidelines logger.error(e.getMessage(), e.getCause()); - setPluginError(e); + throw e; } } diff --git a/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java b/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java index f97848524..16135f7e8 100644 --- a/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java +++ b/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java @@ -3,7 +3,6 @@ import eu.fasten.core.data.Constants; import eu.fasten.core.data.metadatadb.MetadataDao; import eu.fasten.core.maven.data.Revision; -import eu.fasten.core.plugins.AbstractKafkaPlugin; import eu.fasten.core.plugins.DBConnector; import eu.fasten.core.plugins.KafkaPlugin; import org.jooq.DSLContext; @@ -17,7 +16,11 @@ import org.slf4j.LoggerFactory; import java.sql.Timestamp; -import java.util.*; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; public class LicenseFeederPlugin extends Plugin { @@ -74,7 +77,7 @@ public void consume(String record) { } catch (Exception e) { // Fasten error-handling guidelines logger.error(e.getMessage(), e.getCause()); - setPluginError(e); + throw e; } } diff --git a/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java b/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java index d6e9b3a1e..1e524f863 100644 --- a/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java +++ b/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java @@ -18,14 +18,18 @@ package eu.fasten.analyzer.metadataplugin; -import eu.fasten.core.data.*; +import eu.fasten.core.data.Constants; +import eu.fasten.core.data.PartialCCallGraph; +import eu.fasten.core.data.PartialCallGraph; +import eu.fasten.core.data.PartialJavaCallGraph; +import eu.fasten.core.data.PartialPythonCallGraph; import eu.fasten.core.data.callableindex.ExtendedGidGraph; -import eu.fasten.core.data.callableindex.GidGraph; import eu.fasten.core.data.metadatadb.MetadataDao; import eu.fasten.core.data.metadatadb.codegen.enums.Access; import eu.fasten.core.data.metadatadb.codegen.enums.CallableType; import eu.fasten.core.data.metadatadb.codegen.tables.records.CallSitesRecord; import eu.fasten.core.data.metadatadb.codegen.tables.records.CallablesRecord; +import eu.fasten.core.exceptions.UnrecoverableError; import eu.fasten.core.maven.utils.MavenUtilities; import eu.fasten.core.plugins.DBConnector; import eu.fasten.core.plugins.KafkaPlugin; @@ -49,7 +53,11 @@ import java.nio.file.Paths; import java.sql.BatchUpdateException; import java.sql.Timestamp; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; public abstract class MetadataDBExtension implements KafkaPlugin, DBConnector { @@ -166,6 +174,14 @@ public void consume(String record) { } }); } catch (Exception expected) { + if (expected instanceof DataAccessException) { + // The error codes starting with 57P0 are related to the DB connection issues. + // See https://www.postgresql.org/docs/current/errcodes-appendix.html + if (((DataAccessException) expected).sqlState().contains("57P0")) { + throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", + expected.getCause()); + } + } } transactionRestartCount++; } while (restartTransaction && !processedRecord diff --git a/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java b/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java index a79d47e97..2499541c0 100644 --- a/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java +++ b/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java @@ -2,8 +2,6 @@ import eu.fasten.core.data.Constants; import eu.fasten.core.data.metadatadb.MetadataDao; -import eu.fasten.core.maven.data.Revision; -import eu.fasten.core.plugins.AbstractKafkaPlugin; import eu.fasten.core.plugins.DBConnector; import eu.fasten.core.plugins.KafkaPlugin; import org.jooq.DSLContext; @@ -16,8 +14,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.Timestamp; -import java.util.*; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; public class PythonLicenseFeederPlugin extends Plugin { @@ -77,7 +78,7 @@ public void consume(String record) { } catch (Exception e) { // Fasten error-handling guidelines logger.error(e.getMessage(), e.getCause()); - setPluginError(e); + throw e; } } diff --git a/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java b/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java index c8ee44b3c..4e0fdeac0 100644 --- a/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java +++ b/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java @@ -128,7 +128,6 @@ public void consume(String record) { catch (Exception e) { var error = "Error processing package update: " + e; logger.error(error); - setPluginError(e); throw(e); } } diff --git a/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java b/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java index ae831e757..4a2ae7772 100644 --- a/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java +++ b/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java @@ -95,7 +95,7 @@ public void consume(String record) { lastProcessedVulnerability = v; } catch (Exception e) { logger.error("Error processing vulnerability statement: " + e); - setPluginError(e); + throw e; } } diff --git a/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java b/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java index fb082dcc6..e3e60cb09 100644 --- a/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java +++ b/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java @@ -35,6 +35,7 @@ import org.apache.kafka.common.PartitionInfo; import org.apache.kafka.common.TopicPartition; import org.apache.kafka.common.errors.WakeupException; +import org.jooq.exception.DataAccessException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -354,6 +355,14 @@ public void processRecord(ConsumerRecord record, ProcessingLane logger.error("Forced to stop the plug-in due to ", e); throw e; } catch (Exception e) { + if (e instanceof DataAccessException) { + // The error codes starting with 57P0 are related to the DB connection issues. + // See https://www.postgresql.org/docs/current/errcodes-appendix.html + if (((DataAccessException) e).sqlState().contains("57P0")) { + throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", + e.getCause()); + } + } logger.error("An error occurred in " + plugin.getClass().getCanonicalName(), e); plugin.setPluginError(e); } From 6948de169066492fdb8a24447d2a0d96d4af31cc Mon Sep 17 00:00:00 2001 From: "Amir M. Mir" Date: Wed, 1 Jun 2022 09:23:42 +0200 Subject: [PATCH 2/7] Handle `PSQLException` and a failed DB connection in `QualityAnalyzerPlugin` --- .../qualityanalyzer/QualityAnalyzerPlugin.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/analyzer/quality-analyzer/src/main/java/eu/fasten/analyzer/qualityanalyzer/QualityAnalyzerPlugin.java b/analyzer/quality-analyzer/src/main/java/eu/fasten/analyzer/qualityanalyzer/QualityAnalyzerPlugin.java index c8d076e7b..7e7a45604 100644 --- a/analyzer/quality-analyzer/src/main/java/eu/fasten/analyzer/qualityanalyzer/QualityAnalyzerPlugin.java +++ b/analyzer/quality-analyzer/src/main/java/eu/fasten/analyzer/qualityanalyzer/QualityAnalyzerPlugin.java @@ -20,6 +20,7 @@ import eu.fasten.analyzer.qualityanalyzer.data.QAConstants; import eu.fasten.core.data.Constants; +import eu.fasten.core.exceptions.UnrecoverableError; import eu.fasten.core.plugins.DBConnector; import eu.fasten.core.plugins.KafkaPlugin; import org.jooq.DSLContext; @@ -32,7 +33,11 @@ import org.slf4j.LoggerFactory; import java.sql.BatchUpdateException; -import java.util.*; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; public class QualityAnalyzerPlugin extends Plugin { @@ -105,6 +110,13 @@ public void consume(String kafkaMessage) { catch(DataAccessException e) { logger.info("Data access exception"); // Database connection error + // The error codes starting with 57P0 are related to the DB connection issues. + // See https://www.postgresql.org/docs/current/errcodes-appendix.html + if (e.sqlState().contains("57P0")) { + throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", + e.getCause()); + } + if (e.getCause() instanceof BatchUpdateException) { var exception = ((BatchUpdateException) e.getCause()) .getNextException(); From 0a9660ea827a5e3ec655401bc1118055a30eae80 Mon Sep 17 00:00:00 2001 From: "Amir M. Mir" Date: Wed, 1 Jun 2022 09:32:39 +0200 Subject: [PATCH 3/7] Avoid nested `instanceof` when catching `DataAccessException` --- .../metadataplugin/MetadataDBExtension.java | 16 ++++++++-------- .../server/plugins/kafka/FastenKafkaPlugin.java | 17 +++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java b/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java index 1e524f863..985ab0276 100644 --- a/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java +++ b/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java @@ -173,15 +173,15 @@ public void consume(String record) { setOutputPath(callgraph); } }); - } catch (Exception expected) { - if (expected instanceof DataAccessException) { - // The error codes starting with 57P0 are related to the DB connection issues. - // See https://www.postgresql.org/docs/current/errcodes-appendix.html - if (((DataAccessException) expected).sqlState().contains("57P0")) { - throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", - expected.getCause()); - } + } catch (DataAccessException e) { + // The error codes starting with 57P0 are related to the DB connection issues. + // See https://www.postgresql.org/docs/current/errcodes-appendix.html + if (e.sqlState().contains("57P0")) { + throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", + e.getCause()); } + } catch (Exception expected) { + } transactionRestartCount++; } while (restartTransaction && !processedRecord diff --git a/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java b/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java index e3e60cb09..a1c25c5bd 100644 --- a/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java +++ b/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java @@ -354,15 +354,16 @@ public void processRecord(ConsumerRecord record, ProcessingLane // therefore K8s will restart the plug-in. logger.error("Forced to stop the plug-in due to ", e); throw e; - } catch (Exception e) { - if (e instanceof DataAccessException) { - // The error codes starting with 57P0 are related to the DB connection issues. - // See https://www.postgresql.org/docs/current/errcodes-appendix.html - if (((DataAccessException) e).sqlState().contains("57P0")) { - throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", - e.getCause()); - } + + } catch (DataAccessException e) { + // The error codes starting with 57P0 are related to the DB connection issues. + // See https://www.postgresql.org/docs/current/errcodes-appendix.html + if (e.sqlState().contains("57P0")) { + throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", + e.getCause()); } + plugin.setPluginError(e); + } catch (Exception e) { logger.error("An error occurred in " + plugin.getClass().getCanonicalName(), e); plugin.setPluginError(e); } From 9c15656844aa7d68930933ba87c411e81b09f94c Mon Sep 17 00:00:00 2001 From: "Amir M. Mir" Date: Tue, 7 Jun 2022 18:36:46 +0200 Subject: [PATCH 4/7] Do NOT check SQL states when catching `DataAccessException` in the FASTEN server --- .../fasten/server/plugins/kafka/FastenKafkaPlugin.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java b/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java index a1c25c5bd..1c39b39b7 100644 --- a/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java +++ b/server/src/main/java/eu/fasten/server/plugins/kafka/FastenKafkaPlugin.java @@ -356,13 +356,9 @@ public void processRecord(ConsumerRecord record, ProcessingLane throw e; } catch (DataAccessException e) { - // The error codes starting with 57P0 are related to the DB connection issues. - // See https://www.postgresql.org/docs/current/errcodes-appendix.html - if (e.sqlState().contains("57P0")) { - throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", - e.getCause()); - } - plugin.setPluginError(e); + // Database-related errors + throw new UnrecoverableError("Could not connect to or query the Postgres DB and the plug-in should be stopped and restarted.", + e.getCause()); } catch (Exception e) { logger.error("An error occurred in " + plugin.getClass().getCanonicalName(), e); plugin.setPluginError(e); From b9dbc27c6b91895e7a28b43d985207bf883e22b7 Mon Sep 17 00:00:00 2001 From: "Amir M. Mir" Date: Wed, 8 Jun 2022 10:09:38 +0200 Subject: [PATCH 5/7] Do NOT check SQL states when catching `DataAccessException` in `MetadataDBExtension` --- .../analyzer/metadataplugin/MetadataDBExtension.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java b/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java index 985ab0276..659811a57 100644 --- a/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java +++ b/analyzer/metadata-plugin/src/main/java/eu/fasten/analyzer/metadataplugin/MetadataDBExtension.java @@ -174,16 +174,15 @@ public void consume(String record) { } }); } catch (DataAccessException e) { - // The error codes starting with 57P0 are related to the DB connection issues. - // See https://www.postgresql.org/docs/current/errcodes-appendix.html - if (e.sqlState().contains("57P0")) { - throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", + transactionRestartCount++; + if (transactionRestartCount >= Constants.transactionRestartLimit) { + throw new UnrecoverableError("Could not connect to or query the Postgres DB and the plug-in should be stopped and restarted.", e.getCause()); } } catch (Exception expected) { - + transactionRestartCount++; } - transactionRestartCount++; + } while (restartTransaction && !processedRecord && transactionRestartCount < Constants.transactionRestartLimit); } From e993558f522cdc6b57edb8c3bda9243709c3cd77 Mon Sep 17 00:00:00 2001 From: "Amir M. Mir" Date: Wed, 8 Jun 2022 10:11:19 +0200 Subject: [PATCH 6/7] Do NOT check SQL states when catching `DataAccessException` in `QualityAnalyzerPlugin` --- .../qualityanalyzer/QualityAnalyzerPlugin.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/analyzer/quality-analyzer/src/main/java/eu/fasten/analyzer/qualityanalyzer/QualityAnalyzerPlugin.java b/analyzer/quality-analyzer/src/main/java/eu/fasten/analyzer/qualityanalyzer/QualityAnalyzerPlugin.java index 7e7a45604..2d027fb16 100644 --- a/analyzer/quality-analyzer/src/main/java/eu/fasten/analyzer/qualityanalyzer/QualityAnalyzerPlugin.java +++ b/analyzer/quality-analyzer/src/main/java/eu/fasten/analyzer/qualityanalyzer/QualityAnalyzerPlugin.java @@ -101,19 +101,20 @@ public void consume(String kafkaMessage) { do { logger.info("Beginning of the transaction sequence"); setPluginError(null); + transactionRestartCount++; + try { recordId = utils.processJsonRecord(jsonRecord); - if(recordId == null) { + if (recordId == null) { throw new IllegalStateException("No callables matched"); } } - catch(DataAccessException e) { + // Database-related errors + catch (DataAccessException e) { logger.info("Data access exception"); - // Database connection error - // The error codes starting with 57P0 are related to the DB connection issues. - // See https://www.postgresql.org/docs/current/errcodes-appendix.html - if (e.sqlState().contains("57P0")) { - throw new UnrecoverableError("Could not connect to the Postgres DB and the plug-in should be stopped and restarted.", + + if (transactionRestartCount >= Constants.transactionRestartLimit) { + throw new UnrecoverableError("Could not connect to or query the Postgres DB and the plug-in should be stopped and restarted.", e.getCause()); } @@ -123,6 +124,7 @@ public void consume(String kafkaMessage) { setPluginError(exception); } + setPluginError(e); logger.info("Restarting transaction for '" + recordId + "'"); // It could be a deadlock, so restart transaction restartTransaction = true; @@ -148,8 +150,6 @@ public void consume(String kafkaMessage) { + "with callable id = " + recordId); } - transactionRestartCount++; - } while( restartTransaction && !processedRecord && transactionRestartCount < Constants.transactionRestartLimit ); } From 38106ebd45df7af76e651a8ecce949468cf45f48 Mon Sep 17 00:00:00 2001 From: "Amir M. Mir" Date: Wed, 8 Jun 2022 10:20:44 +0200 Subject: [PATCH 7/7] Do NOT catch `Exception` in the plugins as it's already handled by the FASTEN server --- .../licensefeeder/LicenseFeederPlugin.java | 33 +++++++---------- .../PythonLicenseFeederPlugin.java | 36 ++++++++----------- .../VulnerabilityPackagesListener.java | 32 +++++++---------- .../VulnerabilityStatementsProcessor.java | 11 ++---- 4 files changed, 42 insertions(+), 70 deletions(-) diff --git a/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java b/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java index 16135f7e8..6a5e343dc 100644 --- a/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java +++ b/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java @@ -55,30 +55,23 @@ public void setTopics(List consumeTopics) { @Override public void consume(String record) { - try { // Fasten error-handling guidelines + this.pluginError = null; - this.pluginError = null; + logger.info("License feeder started."); - logger.info("License feeder started."); + // Retrieving coordinates of the input record + Revision coordinates = extractMavenCoordinates(record); + logger.info("Input coordinates: " + coordinates + "."); - // Retrieving coordinates of the input record - Revision coordinates = extractMavenCoordinates(record); - logger.info("Input coordinates: " + coordinates + "."); - - // Inserting detected outbound into the database - var metadataDao = new MetadataDao(dslContext); - dslContext.transaction(transaction -> { - metadataDao.setContext(DSL.using(transaction)); - insertOutboundLicenses(coordinates, record, metadataDao); - insertFileLicenses(coordinates, record, metadataDao); - }); - - // TODO Inserting licenses in files + // Inserting detected outbound into the database + var metadataDao = new MetadataDao(dslContext); + dslContext.transaction(transaction -> { + metadataDao.setContext(DSL.using(transaction)); + insertOutboundLicenses(coordinates, record, metadataDao); + insertFileLicenses(coordinates, record, metadataDao); + }); - } catch (Exception e) { // Fasten error-handling guidelines - logger.error(e.getMessage(), e.getCause()); - throw e; - } + // TODO Inserting licenses in files } /** diff --git a/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java b/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java index 2499541c0..acfaffe04 100644 --- a/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java +++ b/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java @@ -54,32 +54,24 @@ public void setTopics(List consumeTopics) { @Override public void consume(String record) { - try { // Fasten error-handling guidelines + this.pluginError = null; - this.pluginError = null; + logger.info("License feeder started."); - logger.info("License feeder started."); + String packageName = extractPackageName(record); + String packageVersion = extractPackageVersion(record); + String sourcePath = extractSourcePath(record); - String packageName = extractPackageName(record); - String packageVersion = extractPackageVersion(record); - String sourcePath = extractSourcePath(record); + logger.info("Package name: " + packageName + "."); + logger.info("Package version: " + packageVersion + "."); - logger.info("Package name: " + packageName + "."); - logger.info("Package version: " + packageVersion + "."); - - // Inserting detected outbound into the database - var metadataDao = new MetadataDao(dslContext); - dslContext.transaction(transaction -> { - metadataDao.setContext(DSL.using(transaction)); - insertOutboundLicenses(packageName, packageVersion, record, metadataDao); - insertFileLicenses(packageName, packageVersion, sourcePath, record, metadataDao); - }); - - - } catch (Exception e) { // Fasten error-handling guidelines - logger.error(e.getMessage(), e.getCause()); - throw e; - } + // Inserting detected outbound into the database + var metadataDao = new MetadataDao(dslContext); + dslContext.transaction(transaction -> { + metadataDao.setContext(DSL.using(transaction)); + insertOutboundLicenses(packageName, packageVersion, record, metadataDao); + insertFileLicenses(packageName, packageVersion, sourcePath, record, metadataDao); + }); } protected String extractPackageName(String record) { diff --git a/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java b/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java index 4e0fdeac0..da12303c1 100644 --- a/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java +++ b/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java @@ -109,26 +109,18 @@ public void setTopics(List consumeTopics) { @Override public void consume(String record) { setPluginError(null); - try { - statementsProcessor.setDBConnection(contexts); - statementsProcessor.setFastenApiClient(fastenApiClient); - var jsonRecord = new JSONObject(record); - var payload = findPayload(jsonRecord); - if(payload != null) { - var ecosystem = payload.getString("forge"); - var packageName = getPackageName(payload); - var version = payload.getString("version"); - logger.info("Processing package update for forge \"" + ecosystem + "\": " + packageName + ":" + version); - statementsProcessor.updateNewPackageVersion(ecosystem, packageName, version); - } - else { - logger.error("Could not parse payload in message: " + record); - } - } - catch (Exception e) { - var error = "Error processing package update: " + e; - logger.error(error); - throw(e); + statementsProcessor.setDBConnection(contexts); + statementsProcessor.setFastenApiClient(fastenApiClient); + var jsonRecord = new JSONObject(record); + var payload = findPayload(jsonRecord); + if (payload != null) { + var ecosystem = payload.getString("forge"); + var packageName = getPackageName(payload); + var version = payload.getString("version"); + logger.info("Processing package update for forge \"" + ecosystem + "\": " + packageName + ":" + version); + statementsProcessor.updateNewPackageVersion(ecosystem, packageName, version); + } else { + logger.error("Could not parse payload in message: " + record); } } diff --git a/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java b/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java index 4a2ae7772..44b73f48d 100644 --- a/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java +++ b/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java @@ -89,14 +89,9 @@ public void setTopics(List consumeTopics) { @Override public void consume(String record) { this.pluginError = null; - try { - var v = updateVulnerability(record); - outputPath = baseOutputPath + File.separator + v.getId() + ".json"; - lastProcessedVulnerability = v; - } catch (Exception e) { - logger.error("Error processing vulnerability statement: " + e); - throw e; - } + var v = updateVulnerability(record); + outputPath = baseOutputPath + File.separator + v.getId() + ".json"; + lastProcessedVulnerability = v; } @Override