Search in sources :

Example 6 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class Main method main.

public static void main(String[] args) throws Exception {
    try {
        Console console = JCommander.getConsole();
        ResourceBundle cliBundle = PropertyResourceBundle.getBundle("CliMessages");
        final CliConfig cliConfig = new CliConfig();
        JCommander jCommander = new JCommander(cliConfig, cliBundle, args);
        jCommander.setColumnSize(Integer.MAX_VALUE);
        if (cliConfig.isVersion()) {
            BuildProperties buildProperties = new DefaultBuildProperties();
            console.println(buildProperties.getFullVersion());
            System.exit(0);
        }
        if (cliConfig.isHelp()) {
            jCommander.usage();
            System.exit(0);
        }
        if (cliConfig.isHelpParam()) {
            console.println(cliBundle.getString("cli.help-param-header"));
            ConfigUtils.printParamDescriptionFromConfigSchema(Config.class, cliBundle, console, 0);
            System.exit(0);
        }
        cliConfig.addParams();
        final Config config = CliConfigUtils.readConfig(cliConfig);
        if (cliConfig.isPrintConfig()) {
            ConfigUtils.printYamlConfig(config, console);
            System.exit(0);
        }
        if (cliConfig.isPrintXmlConfig()) {
            ConfigUtils.printXmlConfig(config, console);
            System.exit(0);
        }
        if (cliConfig.isPrintParam()) {
            JsonNode jsonNode = ConfigUtils.getParam(config, cliConfig.getPrintParamPath());
            if (jsonNode != null) {
                console.print(jsonNode.asText());
            }
            System.exit(0);
        }
        configureLogger(cliConfig, config);
        config.getBackend().getBackendImplementation().accept(new BackendImplementationVisitor() {

            @Override
            public void visit(AbstractDerby value) {
                parseToropassFile(value);
            }

            @Override
            public void visit(AbstractPostgres value) {
                parseToropassFile(value);
            }

            public void parseToropassFile(BackendPasswordConfig value) {
                try {
                    ConfigUtils.parseToropassFile(value);
                } catch (Exception ex) {
                    throw new SystemException(ex);
                }
            }
        });
        AbstractReplication replication = config.getReplication();
        if (replication.getAuth().getUser() != null) {
            HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
            ConfigUtils.parseMongopassFile(new MongoPasswordConfig() {

                @Override
                public void setPassword(String password) {
                    replication.getAuth().setPassword(password);
                }

                @Override
                public String getUser() {
                    return replication.getAuth().getUser();
                }

                @Override
                public Integer getPort() {
                    return syncSource.getPort();
                }

                @Override
                public String getPassword() {
                    return replication.getAuth().getPassword();
                }

                @Override
                public String getMongopassFile() {
                    return config.getReplication().getMongopassFile();
                }

                @Override
                public String getHost() {
                    return syncSource.getHostText();
                }

                @Override
                public String getDatabase() {
                    return replication.getAuth().getSource();
                }
            });
        }
        if (config.getBackend().isLike(AbstractPostgres.class)) {
            AbstractPostgres postgres = config.getBackend().as(AbstractPostgres.class);
            if (cliConfig.isAskForPassword()) {
                console.print("Type database user " + postgres.getUser() + "'s password:");
                postgres.setPassword(readPwd());
            }
            if (postgres.getPassword() == null) {
                throw new SystemException("No password provided for database user " + postgres.getUser() + ".\n\n" + "Please add following line to file " + postgres.getToropassFile() + ":\n" + postgres.getHost() + ":" + postgres.getPort() + ":" + postgres.getDatabase() + ":" + postgres.getUser() + ":<password>\n" + "Replace <password> for database user " + postgres.getUser() + "'s password");
            }
        }
        try {
            Clock clock = Clock.systemDefaultZone();
            Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

                @Override
                @SuppressFBWarnings(value = "DM_EXIT", justification = "Since is really hard to stop cleanly all threads when an OOME is thrown we must " + "exit to avoid no more action is performed that could lead to an unespected " + "state")
                public void uncaughtException(Thread t, Throwable e) {
                    if (e instanceof OutOfMemoryError) {
                        try {
                            LOGGER.error("Fatal out of memory: " + e.getLocalizedMessage(), e);
                        } finally {
                            System.exit(1);
                        }
                    }
                }
            });
            Service stampedeService = StampedeBootstrap.createStampedeService(config, clock);
            stampedeService.startAsync();
            stampedeService.awaitTerminated();
            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                stampedeService.stopAsync();
                stampedeService.awaitTerminated();
            }));
        } catch (CreationException ex) {
            ex.getErrorMessages().stream().forEach(m -> {
                if (m.getCause() != null) {
                    LOGGER.error(m.getCause().getMessage());
                } else {
                    LOGGER.error(m.getMessage());
                }
            });
            LogManager.shutdown();
            System.exit(1);
        }
    } catch (Throwable ex) {
        LOGGER.debug("Fatal error on initialization", ex);
        Throwable rootCause = Throwables.getRootCause(ex);
        String causeMessage = rootCause.getMessage();
        LogManager.shutdown();
        JCommander.getConsole().println("Fatal error while ToroDB was starting: " + causeMessage);
        System.exit(1);
    }
}
Also used : UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) Config(com.torodb.stampede.config.model.Config) AbstractPostgres(com.torodb.packaging.config.model.backend.postgres.AbstractPostgres) BackendImplementationVisitor(com.torodb.packaging.config.visitor.BackendImplementationVisitor) DefaultBuildProperties(com.torodb.packaging.DefaultBuildProperties) ConfigUtils(com.torodb.packaging.config.util.ConfigUtils) ResourceBundle(java.util.ResourceBundle) AbstractReplication(com.torodb.packaging.config.model.protocol.mongo.AbstractReplication) JsonNode(com.fasterxml.jackson.databind.JsonNode) MongoPasswordConfig(com.torodb.packaging.config.model.protocol.mongo.MongoPasswordConfig) Charsets(com.google.common.base.Charsets) BackendPasswordConfig(com.torodb.packaging.config.model.backend.BackendPasswordConfig) JCommander(com.beust.jcommander.JCommander) Throwables(com.google.common.base.Throwables) PropertyResourceBundle(java.util.PropertyResourceBundle) IOException(java.io.IOException) Console(com.beust.jcommander.internal.Console) HostAndPort(com.google.common.net.HostAndPort) Service(com.google.common.util.concurrent.Service) SystemException(com.torodb.core.exceptions.SystemException) CreationException(com.google.inject.CreationException) Logger(org.apache.logging.log4j.Logger) BuildProperties(com.torodb.core.BuildProperties) AbstractDerby(com.torodb.packaging.config.model.backend.derby.AbstractDerby) Clock(java.time.Clock) Log4jUtils(com.torodb.packaging.util.Log4jUtils) LogManager(org.apache.logging.log4j.LogManager) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) InputStream(java.io.InputStream) Config(com.torodb.stampede.config.model.Config) MongoPasswordConfig(com.torodb.packaging.config.model.protocol.mongo.MongoPasswordConfig) BackendPasswordConfig(com.torodb.packaging.config.model.backend.BackendPasswordConfig) BackendImplementationVisitor(com.torodb.packaging.config.visitor.BackendImplementationVisitor) MongoPasswordConfig(com.torodb.packaging.config.model.protocol.mongo.MongoPasswordConfig) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) DefaultBuildProperties(com.torodb.packaging.DefaultBuildProperties) JsonNode(com.fasterxml.jackson.databind.JsonNode) Clock(java.time.Clock) HostAndPort(com.google.common.net.HostAndPort) SystemException(com.torodb.core.exceptions.SystemException) JCommander(com.beust.jcommander.JCommander) Console(com.beust.jcommander.internal.Console) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) Service(com.google.common.util.concurrent.Service) CreationException(com.google.inject.CreationException) AbstractReplication(com.torodb.packaging.config.model.protocol.mongo.AbstractReplication) AbstractPostgres(com.torodb.packaging.config.model.backend.postgres.AbstractPostgres) IOException(java.io.IOException) SystemException(com.torodb.core.exceptions.SystemException) CreationException(com.google.inject.CreationException) DefaultBuildProperties(com.torodb.packaging.DefaultBuildProperties) BuildProperties(com.torodb.core.BuildProperties) ResourceBundle(java.util.ResourceBundle) PropertyResourceBundle(java.util.PropertyResourceBundle) AbstractDerby(com.torodb.packaging.config.model.backend.derby.AbstractDerby) BackendPasswordConfig(com.torodb.packaging.config.model.backend.BackendPasswordConfig)

Example 7 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class SqlWriteTorodTransaction method dropIndex.

@SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", justification = "Findbugs thinks MutableMetaCollection#removeMetaIndexByName" + "has no side effect")
@Override
public boolean dropIndex(String dbName, String colName, String indexName) {
    MutableMetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        return false;
    }
    MutableMetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        return false;
    }
    MetaIndex index = col.getMetaIndexByName(indexName);
    if (index == null) {
        return false;
    }
    col.removeMetaIndexByName(indexName);
    getInternalTransaction().getBackendTransaction().dropIndex(db, col, index);
    return true;
}
Also used : MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class AbstractReadInterface method getCollectionResultSets.

@Override
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a DocPartResult. It's iterated and closed in caller code")
public List<DocPartResult> getCollectionResultSets(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCollection, Collection<Integer> dids) throws SQLException {
    ArrayList<DocPartResult> result = new ArrayList<>();
    Connection connection = dsl.configuration().connectionProvider().acquire();
    try {
        Iterator<? extends MetaDocPart> metaDocPartIterator = metaCollection.streamContainedMetaDocParts().sorted(TableRefComparator.MetaDocPart.DESC).iterator();
        while (metaDocPartIterator.hasNext()) {
            MetaDocPart metaDocPart = metaDocPartIterator.next();
            String statament = getDocPartStatament(metaDatabase, metaDocPart, dids);
            PreparedStatement preparedStatement = connection.prepareStatement(statament);
            result.add(new ResultSetDocPartResult(metaDataReadInterface, dataTypeProvider, errorHandler, metaDocPart, preparedStatement.executeQuery(), sqlHelper));
        }
    } finally {
        dsl.configuration().connectionProvider().release(connection);
    }
    return result;
}
Also used : ResultSetDocPartResult(com.torodb.backend.d2r.ResultSetDocPartResult) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSetDocPartResult(com.torodb.backend.d2r.ResultSetDocPartResult) DocPartResult(com.torodb.core.d2r.DocPartResult) PreparedStatement(java.sql.PreparedStatement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 9 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class AbstractReadInterface method getAllCollectionDids.

@Override
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
public Cursor<Integer> getAllCollectionDids(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCollection) throws SQLException {
    MetaDocPart rootDocPart = metaCollection.getMetaDocPartByTableRef(tableRefFactory.createRoot());
    if (rootDocPart == null) {
        return new EmptyCursor<>();
    }
    String statement = getReadAllCollectionDidsStatement(metaDatabase.getIdentifier(), rootDocPart.getIdentifier());
    Connection connection = dsl.configuration().connectionProvider().acquire();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(statement);
        return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
    } finally {
        dsl.configuration().connectionProvider().release(connection);
    }
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) EmptyCursor(com.torodb.core.cursors.EmptyCursor) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 10 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class MvccMetainfoRepository method startMerge.

@Override
@Nonnull
@SuppressFBWarnings(value = { "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "UL_UNRELEASED_LOCK" })
public MergerStage startMerge(MutableMetaSnapshot newSnapshot) throws UnmergeableException {
    LOGGER.trace("Trying to create a {}", MvccMergerStage.class);
    MergerStage mergeStage = null;
    if (newSnapshot.hasChanged()) {
        lock.writeLock().lock();
        try {
            mergeStage = new MvccMergerStage(newSnapshot, lock.writeLock());
            LOGGER.trace("{} created", MvccMergerStage.class);
        } finally {
            if (mergeStage == null) {
                LOGGER.error("Error while trying to create a {}", MvccMergerStage.class);
                lock.writeLock().unlock();
            }
        }
    } else {
        mergeStage = noChangeMergeStage;
    }
    assert mergeStage != null;
    return mergeStage;
}
Also used : MergerStage(com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)142 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)20 JPanel (javax.swing.JPanel)14 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)13 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)13 FlowLayout (java.awt.FlowLayout)8 BoxLayout (javax.swing.BoxLayout)7 Location (jmri.jmrit.operations.locations.Location)7 Dimension (java.awt.Dimension)5 FileOutputStream (java.io.FileOutputStream)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 Iterator (java.util.Iterator)5 JScrollPane (javax.swing.JScrollPane)5 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 Entry (java.util.Map.Entry)4