Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle PSQLException in the FASTEN server and MetadataDBExtension #466

Merged
merged 7 commits into from
Jun 8, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
mir-am marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -166,6 +174,14 @@ public void consume(String record) {
}
});
} catch (Exception expected) {
if (expected instanceof DataAccessException) {
mir-am marked this conversation as resolved.
Show resolved Hide resolved
// 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")) {
proksch marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -354,6 +355,14 @@ public void processRecord(ConsumerRecord<String, String> record, ProcessingLane
logger.error("Forced to stop the plug-in due to ", e);
throw e;
} catch (Exception e) {
if (e instanceof DataAccessException) {
mir-am marked this conversation as resolved.
Show resolved Hide resolved
// 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);
}
Expand Down