Search in sources :

Example 1 with ApplicationStartupException

use of io.micronaut.runtime.exceptions.ApplicationStartupException in project micronaut-core by micronaut-projects.

the class MessagingApplication method start.

@Override
public MessagingApplication start() {
    ApplicationContext applicationContext = getApplicationContext();
    if (applicationContext != null && !applicationContext.isRunning()) {
        try {
            applicationContext.start();
            applicationContext.publishEvent(new ApplicationStartupEvent(this));
        } catch (Throwable e) {
            throw new ApplicationStartupException("Error starting messaging server: " + e.getMessage(), e);
        }
    }
    return this;
}
Also used : ApplicationStartupEvent(io.micronaut.runtime.event.ApplicationStartupEvent) ApplicationContext(io.micronaut.context.ApplicationContext) ApplicationStartupException(io.micronaut.runtime.exceptions.ApplicationStartupException)

Example 2 with ApplicationStartupException

use of io.micronaut.runtime.exceptions.ApplicationStartupException in project micronaut-liquibase by micronaut-projects.

the class LiquibaseMigrationRunner method migrate.

/**
 * Performs liquibase update for the given data datasource and configuration.
 *
 * @param config     The {@link LiquibaseConfigurationProperties}
 * @param dataSource The {@link DataSource}
 */
private void migrate(LiquibaseConfigurationProperties config, DataSource dataSource) {
    Connection connection;
    try {
        connection = dataSource.getConnection();
    } catch (SQLException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Migration failed! Could not connect to the datasource.", e);
        }
        throw new ApplicationStartupException("Migration failed! Could not connect to the datasource.", e);
    }
    Liquibase liquibase = null;
    try {
        liquibase = createLiquibase(connection, config);
        generateRollbackFile(liquibase, config);
        performUpdate(liquibase, config);
    } catch (LiquibaseException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Migration failed! Liquibase encountered an exception.", e);
        }
        throw new ApplicationStartupException("Migration failed! Liquibase encountered an exception.", e);
    } finally {
        Database database = null;
        if (liquibase != null) {
            database = liquibase.getDatabase();
        }
        if (database != null) {
            try {
                database.close();
            } catch (DatabaseException e) {
                if (LOG.isWarnEnabled()) {
                    LOG.warn("Error closing the connection after the migration.", e);
                }
            }
        }
    }
}
Also used : Liquibase(liquibase.Liquibase) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseConnection(liquibase.database.DatabaseConnection) OfflineConnection(liquibase.database.OfflineConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) Database(liquibase.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) ApplicationStartupException(io.micronaut.runtime.exceptions.ApplicationStartupException) DatabaseException(liquibase.exception.DatabaseException)

Example 3 with ApplicationStartupException

use of io.micronaut.runtime.exceptions.ApplicationStartupException in project micronaut-grpc by micronaut-projects.

the class GrpcEmbeddedServer method start.

@Override
public EmbeddedServer start() {
    if (running.compareAndSet(false, true)) {
        try {
            server.start();
            eventPublisher.publishEvent(new ServerStartupEvent(this));
            getApplicationConfiguration().getName().ifPresent(id -> {
                Map<String, String> metadata = new LinkedHashMap<>();
                if (computeInstanceMetadataResolver != null) {
                    final Optional<ComputeInstanceMetadata> cim = computeInstanceMetadataResolver.resolve(applicationContext.getEnvironment());
                    cim.ifPresent(computeInstanceMetadata -> metadata.putAll(computeInstanceMetadata.getMetadata()));
                }
                this.serviceInstance = new GrpcServerInstance(this, id, getURI(), metadata, metadataContributors, grpcConfiguration);
                applicationContext.publishEvent(new ServiceReadyEvent(serviceInstance));
            });
        } catch (IOException e) {
            throw new ApplicationStartupException("Unable to start GRPC server: " + e.getMessage(), e);
        }
    }
    return this;
}
Also used : ServiceReadyEvent(io.micronaut.discovery.event.ServiceReadyEvent) IOException(java.io.IOException) ServerStartupEvent(io.micronaut.runtime.server.event.ServerStartupEvent) ApplicationStartupException(io.micronaut.runtime.exceptions.ApplicationStartupException) ComputeInstanceMetadata(io.micronaut.discovery.cloud.ComputeInstanceMetadata) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ApplicationStartupException (io.micronaut.runtime.exceptions.ApplicationStartupException)3 ApplicationContext (io.micronaut.context.ApplicationContext)1 ComputeInstanceMetadata (io.micronaut.discovery.cloud.ComputeInstanceMetadata)1 ServiceReadyEvent (io.micronaut.discovery.event.ServiceReadyEvent)1 ApplicationStartupEvent (io.micronaut.runtime.event.ApplicationStartupEvent)1 ServerStartupEvent (io.micronaut.runtime.server.event.ServerStartupEvent)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 LinkedHashMap (java.util.LinkedHashMap)1 Liquibase (liquibase.Liquibase)1 Database (liquibase.database.Database)1 DatabaseConnection (liquibase.database.DatabaseConnection)1 OfflineConnection (liquibase.database.OfflineConnection)1 JdbcConnection (liquibase.database.jvm.JdbcConnection)1 DatabaseException (liquibase.exception.DatabaseException)1 LiquibaseException (liquibase.exception.LiquibaseException)1