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;
}
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);
}
}
}
}
}
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;
}
Aggregations