2021-08-01 14:27:44 -07:00
|
|
|
/*
|
2021-12-01 12:46:28 +05:30
|
|
|
* Copyright 2021 Collate
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2021-08-01 14:27:44 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-09-14 23:14:02 -07:00
|
|
|
package org.openmetadata.service;
|
2021-08-01 14:27:44 -07:00
|
|
|
|
2021-10-21 21:13:27 -07:00
|
|
|
import io.dropwizard.Application;
|
2022-01-11 10:13:49 -08:00
|
|
|
import io.dropwizard.configuration.EnvironmentVariableSubstitutor;
|
|
|
|
import io.dropwizard.configuration.SubstitutingSourceProvider;
|
2022-08-25 19:07:44 +05:30
|
|
|
import io.dropwizard.db.DataSourceFactory;
|
2021-08-01 14:27:44 -07:00
|
|
|
import io.dropwizard.health.conf.HealthConfiguration;
|
|
|
|
import io.dropwizard.health.core.HealthCheckBundle;
|
2021-10-20 14:21:24 -07:00
|
|
|
import io.dropwizard.jdbi3.JdbiFactory;
|
2021-08-01 14:27:44 -07:00
|
|
|
import io.dropwizard.jersey.errors.EarlyEofExceptionMapper;
|
|
|
|
import io.dropwizard.jersey.errors.LoggingExceptionMapper;
|
2021-10-21 21:13:27 -07:00
|
|
|
import io.dropwizard.jersey.jackson.JsonProcessingExceptionMapper;
|
2021-08-01 14:27:44 -07:00
|
|
|
import io.dropwizard.lifecycle.Managed;
|
|
|
|
import io.dropwizard.server.DefaultServerFactory;
|
|
|
|
import io.dropwizard.setup.Bootstrap;
|
|
|
|
import io.dropwizard.setup.Environment;
|
|
|
|
import io.federecio.dropwizard.swagger.SwaggerBundle;
|
|
|
|
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration;
|
2022-05-27 03:09:13 -07:00
|
|
|
import io.github.maksymdolgykh.dropwizard.micrometer.MicrometerHttpFilter;
|
2022-06-15 10:14:47 +05:30
|
|
|
import io.socket.engineio.server.EngineIoServerOptions;
|
|
|
|
import io.socket.engineio.server.JettyWebSocketHandler;
|
2022-01-09 21:04:10 -08:00
|
|
|
import java.io.IOException;
|
2021-12-16 07:13:50 -08:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2022-01-09 21:04:10 -08:00
|
|
|
import java.time.temporal.ChronoUnit;
|
2022-05-27 03:09:13 -07:00
|
|
|
import java.util.EnumSet;
|
2022-02-01 08:31:34 +01:00
|
|
|
import java.util.Optional;
|
2022-10-21 20:49:41 -07:00
|
|
|
import javax.naming.ConfigurationException;
|
2022-05-27 03:09:13 -07:00
|
|
|
import javax.servlet.DispatcherType;
|
|
|
|
import javax.servlet.FilterRegistration;
|
2022-06-15 10:14:47 +05:30
|
|
|
import javax.servlet.ServletException;
|
2021-12-16 07:13:50 -08:00
|
|
|
import javax.ws.rs.container.ContainerRequestFilter;
|
|
|
|
import javax.ws.rs.container.ContainerResponseFilter;
|
|
|
|
import javax.ws.rs.core.Response;
|
2021-08-01 14:27:44 -07:00
|
|
|
import lombok.SneakyThrows;
|
2022-01-20 02:06:48 +05:30
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2021-08-01 14:27:44 -07:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2022-06-15 10:14:47 +05:30
|
|
|
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
2021-08-01 14:27:44 -07:00
|
|
|
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
2022-06-15 10:14:47 +05:30
|
|
|
import org.eclipse.jetty.servlet.FilterHolder;
|
|
|
|
import org.eclipse.jetty.servlet.ServletHolder;
|
|
|
|
import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
|
2021-08-01 14:27:44 -07:00
|
|
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
|
|
|
import org.glassfish.jersey.server.ServerProperties;
|
2021-10-21 21:13:27 -07:00
|
|
|
import org.jdbi.v3.core.Jdbi;
|
2022-01-09 21:04:10 -08:00
|
|
|
import org.jdbi.v3.core.statement.SqlLogger;
|
|
|
|
import org.jdbi.v3.core.statement.StatementContext;
|
2022-04-27 18:58:44 +01:00
|
|
|
import org.jdbi.v3.sqlobject.SqlObjects;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.schema.api.security.AuthenticationConfiguration;
|
|
|
|
import org.openmetadata.schema.api.security.AuthorizerConfiguration;
|
|
|
|
import org.openmetadata.service.elasticsearch.ElasticSearchEventPublisher;
|
|
|
|
import org.openmetadata.service.events.EventFilter;
|
|
|
|
import org.openmetadata.service.events.EventPubSub;
|
|
|
|
import org.openmetadata.service.exception.CatalogGenericExceptionMapper;
|
|
|
|
import org.openmetadata.service.exception.ConstraintViolationExceptionMapper;
|
|
|
|
import org.openmetadata.service.exception.JsonMappingExceptionMapper;
|
|
|
|
import org.openmetadata.service.fernet.Fernet;
|
2022-09-28 22:55:00 +05:30
|
|
|
import org.openmetadata.service.jdbi3.CollectionDAO;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.service.jdbi3.locator.ConnectionAwareAnnotationSqlLocator;
|
|
|
|
import org.openmetadata.service.migration.Migration;
|
|
|
|
import org.openmetadata.service.migration.MigrationConfiguration;
|
2022-11-28 17:45:18 +01:00
|
|
|
import org.openmetadata.service.monitoring.EventMonitor;
|
|
|
|
import org.openmetadata.service.monitoring.EventMonitorFactory;
|
|
|
|
import org.openmetadata.service.monitoring.EventMonitorPublisher;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.service.resources.CollectionRegistry;
|
|
|
|
import org.openmetadata.service.secrets.SecretsManager;
|
|
|
|
import org.openmetadata.service.secrets.SecretsManagerFactory;
|
2022-11-14 13:48:50 +01:00
|
|
|
import org.openmetadata.service.secrets.SecretsManagerUpdateService;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.service.security.Authorizer;
|
|
|
|
import org.openmetadata.service.security.NoopAuthorizer;
|
|
|
|
import org.openmetadata.service.security.NoopFilter;
|
2022-10-27 22:56:20 +05:30
|
|
|
import org.openmetadata.service.security.auth.AuthenticatorHandler;
|
|
|
|
import org.openmetadata.service.security.auth.BasicAuthenticator;
|
|
|
|
import org.openmetadata.service.security.auth.LdapAuthenticator;
|
|
|
|
import org.openmetadata.service.security.auth.NoopAuthenticator;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.service.security.jwt.JWTTokenGenerator;
|
|
|
|
import org.openmetadata.service.socket.FeedServlet;
|
2023-01-03 23:13:22 +05:30
|
|
|
import org.openmetadata.service.socket.OpenMetadataAssetServlet;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.service.socket.SocketAddressFilter;
|
|
|
|
import org.openmetadata.service.socket.WebSocketManager;
|
2022-09-19 11:38:45 +05:30
|
|
|
import org.openmetadata.service.util.EmailUtil;
|
2022-11-29 19:37:29 +01:00
|
|
|
import org.openmetadata.service.util.MicrometerBundleSingleton;
|
2021-08-01 14:27:44 -07:00
|
|
|
|
2021-12-16 07:13:50 -08:00
|
|
|
/** Main catalog application */
|
2022-01-20 02:06:48 +05:30
|
|
|
@Slf4j
|
2022-09-17 11:35:45 -07:00
|
|
|
public class OpenMetadataApplication extends Application<OpenMetadataApplicationConfig> {
|
2021-12-29 11:37:47 -08:00
|
|
|
private Authorizer authorizer;
|
2021-12-16 07:13:50 -08:00
|
|
|
|
2022-10-27 22:56:20 +05:30
|
|
|
private AuthenticatorHandler authenticatorHandler;
|
|
|
|
|
2021-08-01 14:27:44 -07:00
|
|
|
@Override
|
2022-09-17 11:35:45 -07:00
|
|
|
public void run(OpenMetadataApplicationConfig catalogConfig, Environment environment)
|
2021-12-16 07:13:50 -08:00
|
|
|
throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException,
|
2022-10-21 20:49:41 -07:00
|
|
|
InvocationTargetException, IOException, ConfigurationException {
|
|
|
|
validateConfiguration(catalogConfig);
|
|
|
|
|
2022-09-19 11:38:45 +05:30
|
|
|
// init email Util for handling
|
2022-11-23 00:54:20 -08:00
|
|
|
EmailUtil.initialize(catalogConfig);
|
2022-08-25 19:07:44 +05:30
|
|
|
final Jdbi jdbi = createAndSetupJDBI(environment, catalogConfig.getDataSourceFactory());
|
2022-07-13 20:49:27 +02:00
|
|
|
final SecretsManager secretsManager =
|
2022-08-09 09:00:43 +02:00
|
|
|
SecretsManagerFactory.createSecretsManager(
|
|
|
|
catalogConfig.getSecretsManagerConfiguration(), catalogConfig.getClusterName());
|
2022-07-13 20:49:27 +02:00
|
|
|
|
2022-02-08 09:50:39 +01:00
|
|
|
// Configure the Fernet instance
|
|
|
|
Fernet.getInstance().setFernetKey(catalogConfig);
|
|
|
|
|
2022-05-05 03:02:33 -07:00
|
|
|
// Instantiate JWT Token Generator
|
|
|
|
JWTTokenGenerator.getInstance().init(catalogConfig.getJwtTokenConfiguration());
|
|
|
|
|
2022-04-27 18:58:44 +01:00
|
|
|
// Set the Database type for choosing correct queries from annotations
|
|
|
|
jdbi.getConfig(SqlObjects.class)
|
|
|
|
.setSqlLocator(new ConnectionAwareAnnotationSqlLocator(catalogConfig.getDataSourceFactory().getDriverClass()));
|
|
|
|
|
2022-02-01 08:31:34 +01:00
|
|
|
// Validate flyway Migrations
|
|
|
|
validateMigrations(jdbi, catalogConfig.getMigrationConfiguration());
|
|
|
|
|
2021-08-01 14:27:44 -07:00
|
|
|
// Register Authorizer
|
2022-04-13 23:55:35 -07:00
|
|
|
registerAuthorizer(catalogConfig, environment);
|
2021-08-01 14:27:44 -07:00
|
|
|
|
2022-10-27 22:56:20 +05:30
|
|
|
// Register Authenticator
|
2022-12-16 16:14:40 -08:00
|
|
|
registerAuthenticator(catalogConfig);
|
2022-10-27 22:56:20 +05:30
|
|
|
|
2021-08-01 14:27:44 -07:00
|
|
|
// Unregister dropwizard default exception mappers
|
|
|
|
((DefaultServerFactory) catalogConfig.getServerFactory()).setRegisterDefaultExceptionMappers(false);
|
2021-10-04 21:06:29 -07:00
|
|
|
environment.jersey().property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, true);
|
2021-08-01 14:27:44 -07:00
|
|
|
environment.jersey().register(MultiPartFeature.class);
|
|
|
|
environment.jersey().register(CatalogGenericExceptionMapper.class);
|
|
|
|
|
|
|
|
// Override constraint violation mapper to catch Json validation errors
|
|
|
|
environment.jersey().register(new ConstraintViolationExceptionMapper());
|
|
|
|
|
|
|
|
// Restore dropwizard default exception mappers
|
2021-10-04 21:06:29 -07:00
|
|
|
environment.jersey().register(new LoggingExceptionMapper<>() {});
|
2021-08-01 14:27:44 -07:00
|
|
|
environment.jersey().register(new JsonProcessingExceptionMapper(true));
|
|
|
|
environment.jersey().register(new EarlyEofExceptionMapper());
|
2021-10-04 21:06:29 -07:00
|
|
|
environment.jersey().register(JsonMappingExceptionMapper.class);
|
2022-05-27 03:09:13 -07:00
|
|
|
environment.healthChecks().register("OpenMetadataServerHealthCheck", new OpenMetadataServerHealthCheck());
|
2022-07-28 23:45:12 +05:30
|
|
|
// start event hub before registering publishers
|
|
|
|
EventPubSub.start();
|
|
|
|
|
2022-10-10 23:32:48 -07:00
|
|
|
registerResources(catalogConfig, environment, jdbi);
|
2021-08-03 22:40:42 -07:00
|
|
|
|
|
|
|
// Register Event Handler
|
|
|
|
registerEventFilter(catalogConfig, environment, jdbi);
|
2021-12-23 20:10:38 -08:00
|
|
|
environment.lifecycle().manage(new ManagedShutdown());
|
2022-01-12 16:35:27 -08:00
|
|
|
// Register Event publishers
|
2022-09-28 22:55:00 +05:30
|
|
|
registerEventPublisher(catalogConfig, jdbi);
|
2022-05-27 03:09:13 -07:00
|
|
|
|
2022-11-14 13:48:50 +01:00
|
|
|
// update entities secrets if required
|
|
|
|
new SecretsManagerUpdateService(secretsManager, catalogConfig.getClusterName()).updateEntities();
|
|
|
|
|
2022-04-23 19:17:20 -07:00
|
|
|
// start authorizer after event publishers
|
|
|
|
// authorizer creates admin/bot users, ES publisher should start before to index users created by authorizer
|
2022-09-26 14:56:24 +02:00
|
|
|
authorizer.init(catalogConfig, jdbi);
|
2022-10-27 22:56:20 +05:30
|
|
|
|
|
|
|
// authenticationHandler Handles auth related activities
|
|
|
|
authenticatorHandler.init(catalogConfig, jdbi);
|
|
|
|
|
2022-05-27 03:09:13 -07:00
|
|
|
FilterRegistration.Dynamic micrometerFilter =
|
|
|
|
environment.servlets().addFilter("MicrometerHttpFilter", new MicrometerHttpFilter());
|
|
|
|
micrometerFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
|
2023-01-03 23:13:22 +05:30
|
|
|
|
2022-10-21 20:49:41 -07:00
|
|
|
initializeWebsockets(catalogConfig, environment);
|
2023-01-03 23:13:22 +05:30
|
|
|
|
|
|
|
// Handle Asset Using Servlet
|
|
|
|
OpenMetadataAssetServlet assetServlet = new OpenMetadataAssetServlet("/assets", "/", "index.html");
|
|
|
|
String pathPattern = "/" + '*';
|
|
|
|
environment.servlets().addServlet("static", assetServlet).addMapping(pathPattern);
|
2021-08-01 14:27:44 -07:00
|
|
|
}
|
|
|
|
|
2022-08-25 19:07:44 +05:30
|
|
|
private Jdbi createAndSetupJDBI(Environment environment, DataSourceFactory dbFactory) {
|
|
|
|
Jdbi jdbi = new JdbiFactory().build(environment, dbFactory, "database");
|
|
|
|
SqlLogger sqlLogger =
|
|
|
|
new SqlLogger() {
|
2023-01-17 11:34:29 -08:00
|
|
|
@Override
|
|
|
|
public void logBeforeExecution(StatementContext context) {
|
|
|
|
LOG.debug("sql {}, parameters {}", context.getRenderedSql(), context.getBinding());
|
|
|
|
}
|
|
|
|
|
2022-08-25 19:07:44 +05:30
|
|
|
@Override
|
|
|
|
public void logAfterExecution(StatementContext context) {
|
|
|
|
LOG.debug(
|
|
|
|
"sql {}, parameters {}, timeTaken {} ms",
|
|
|
|
context.getRenderedSql(),
|
|
|
|
context.getBinding(),
|
|
|
|
context.getElapsedTime(ChronoUnit.MILLIS));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
|
jdbi.setSqlLogger(sqlLogger);
|
|
|
|
}
|
|
|
|
// Set the Database type for choosing correct queries from annotations
|
|
|
|
jdbi.getConfig(SqlObjects.class).setSqlLocator(new ConnectionAwareAnnotationSqlLocator(dbFactory.getDriverClass()));
|
|
|
|
|
|
|
|
return jdbi;
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:27:44 -07:00
|
|
|
@SneakyThrows
|
|
|
|
@Override
|
2022-09-17 11:35:45 -07:00
|
|
|
public void initialize(Bootstrap<OpenMetadataApplicationConfig> bootstrap) {
|
2022-01-11 10:13:49 -08:00
|
|
|
bootstrap.setConfigurationSourceProvider(
|
|
|
|
new SubstitutingSourceProvider(
|
|
|
|
bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));
|
2021-12-16 07:13:50 -08:00
|
|
|
bootstrap.addBundle(
|
|
|
|
new SwaggerBundle<>() {
|
|
|
|
@Override
|
2022-09-17 11:35:45 -07:00
|
|
|
protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(
|
|
|
|
OpenMetadataApplicationConfig catalogConfig) {
|
2021-12-16 07:13:50 -08:00
|
|
|
return catalogConfig.getSwaggerBundleConfig();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
bootstrap.addBundle(
|
|
|
|
new HealthCheckBundle<>() {
|
|
|
|
@Override
|
2022-09-17 11:35:45 -07:00
|
|
|
protected HealthConfiguration getHealthConfiguration(final OpenMetadataApplicationConfig configuration) {
|
2021-12-16 07:13:50 -08:00
|
|
|
return configuration.getHealthConfiguration();
|
|
|
|
}
|
|
|
|
});
|
2022-11-29 19:37:29 +01:00
|
|
|
bootstrap.addBundle(MicrometerBundleSingleton.getInstance());
|
2021-08-01 14:27:44 -07:00
|
|
|
super.initialize(bootstrap);
|
|
|
|
}
|
|
|
|
|
2022-02-01 08:31:34 +01:00
|
|
|
private void validateMigrations(Jdbi jdbi, MigrationConfiguration conf) throws IOException {
|
|
|
|
LOG.info("Validating Flyway migrations");
|
|
|
|
Optional<String> lastMigrated = Migration.lastMigrated(jdbi);
|
|
|
|
String maxMigration = Migration.lastMigrationFile(conf);
|
|
|
|
|
|
|
|
if (lastMigrated.isEmpty()) {
|
2022-04-27 18:58:44 +01:00
|
|
|
throw new IllegalStateException(
|
|
|
|
"Could not validate Flyway migrations in the database. Make sure you have run `./bootstrap/bootstrap_storage.sh migrate-all` at least once.");
|
2022-02-01 08:31:34 +01:00
|
|
|
}
|
|
|
|
if (lastMigrated.get().compareTo(maxMigration) < 0) {
|
2022-04-27 18:58:44 +01:00
|
|
|
throw new IllegalStateException(
|
|
|
|
"There are pending migrations to be run on the database."
|
2022-02-01 08:31:34 +01:00
|
|
|
+ " Please backup your data and run `./bootstrap/bootstrap_storage.sh migrate-all`."
|
|
|
|
+ " You can find more information on upgrading OpenMetadata at"
|
2022-08-29 19:38:54 +05:30
|
|
|
+ " https://docs.open-metadata.org/deployment/upgrade ");
|
2022-02-01 08:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 20:49:41 -07:00
|
|
|
private void validateConfiguration(OpenMetadataApplicationConfig catalogConfig) throws ConfigurationException {
|
|
|
|
if (catalogConfig.getAuthorizerConfiguration().getBotPrincipals() != null) {
|
|
|
|
throw new ConfigurationException(
|
|
|
|
"'botPrincipals' configuration is deprecated. Please remove it from "
|
|
|
|
+ "'openmetadata.yaml and restart the server");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-17 11:35:45 -07:00
|
|
|
private void registerAuthorizer(OpenMetadataApplicationConfig catalogConfig, Environment environment)
|
2021-12-16 07:13:50 -08:00
|
|
|
throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException,
|
2022-04-17 21:49:10 -07:00
|
|
|
InstantiationException {
|
2021-08-01 14:27:44 -07:00
|
|
|
AuthorizerConfiguration authorizerConf = catalogConfig.getAuthorizerConfiguration();
|
|
|
|
AuthenticationConfiguration authenticationConfiguration = catalogConfig.getAuthenticationConfiguration();
|
2022-06-15 10:14:47 +05:30
|
|
|
// to authenticate request while opening websocket connections
|
2021-08-01 14:27:44 -07:00
|
|
|
if (authorizerConf != null) {
|
2022-05-22 15:28:55 -07:00
|
|
|
authorizer =
|
|
|
|
Class.forName(authorizerConf.getClassName()).asSubclass(Authorizer.class).getConstructor().newInstance();
|
2021-08-01 14:27:44 -07:00
|
|
|
String filterClazzName = authorizerConf.getContainerRequestFilter();
|
|
|
|
ContainerRequestFilter filter;
|
2022-02-28 05:34:39 -08:00
|
|
|
if (!StringUtils.isEmpty(filterClazzName)) {
|
2021-12-16 07:13:50 -08:00
|
|
|
filter =
|
2022-05-22 15:28:55 -07:00
|
|
|
Class.forName(filterClazzName)
|
|
|
|
.asSubclass(ContainerRequestFilter.class)
|
2023-02-02 20:19:32 +05:30
|
|
|
.getConstructor(AuthenticationConfiguration.class, AuthorizerConfiguration.class)
|
|
|
|
.newInstance(authenticationConfiguration, authorizerConf);
|
2022-02-28 05:34:39 -08:00
|
|
|
LOG.info("Registering ContainerRequestFilter: {}", filter.getClass().getCanonicalName());
|
|
|
|
environment.jersey().register(filter);
|
2021-08-01 14:27:44 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG.info("Authorizer config not set, setting noop authorizer");
|
2022-05-22 15:28:55 -07:00
|
|
|
authorizer = new NoopAuthorizer();
|
2023-02-02 20:19:32 +05:30
|
|
|
ContainerRequestFilter filter = new NoopFilter(authenticationConfiguration, null);
|
2021-08-01 14:27:44 -07:00
|
|
|
environment.jersey().register(filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-16 16:14:40 -08:00
|
|
|
private void registerAuthenticator(OpenMetadataApplicationConfig catalogConfig) {
|
2022-10-27 22:56:20 +05:30
|
|
|
AuthenticationConfiguration authenticationConfiguration = catalogConfig.getAuthenticationConfiguration();
|
|
|
|
switch (authenticationConfiguration.getProvider()) {
|
|
|
|
case "basic":
|
|
|
|
authenticatorHandler = new BasicAuthenticator();
|
|
|
|
break;
|
|
|
|
case "ldap":
|
|
|
|
authenticatorHandler = new LdapAuthenticator();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// For all other types, google, okta etc. auth is handled externally
|
|
|
|
authenticatorHandler = new NoopAuthenticator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-17 11:35:45 -07:00
|
|
|
private void registerEventFilter(OpenMetadataApplicationConfig catalogConfig, Environment environment, Jdbi jdbi) {
|
2021-08-11 14:54:13 -07:00
|
|
|
if (catalogConfig.getEventHandlerConfiguration() != null) {
|
|
|
|
ContainerResponseFilter eventFilter = new EventFilter(catalogConfig, jdbi);
|
|
|
|
environment.jersey().register(eventFilter);
|
|
|
|
}
|
2021-08-03 22:40:42 -07:00
|
|
|
}
|
|
|
|
|
2022-09-28 22:55:00 +05:30
|
|
|
private void registerEventPublisher(OpenMetadataApplicationConfig openMetadataApplicationConfig, Jdbi jdbi) {
|
2022-01-12 16:35:27 -08:00
|
|
|
// register ElasticSearch Event publisher
|
2022-09-17 11:35:45 -07:00
|
|
|
if (openMetadataApplicationConfig.getElasticSearchConfiguration() != null) {
|
2022-01-12 16:35:27 -08:00
|
|
|
ElasticSearchEventPublisher elasticSearchEventPublisher =
|
2022-09-28 22:55:00 +05:30
|
|
|
new ElasticSearchEventPublisher(
|
|
|
|
openMetadataApplicationConfig.getElasticSearchConfiguration(), jdbi.onDemand(CollectionDAO.class));
|
2022-01-12 16:35:27 -08:00
|
|
|
EventPubSub.addEventHandler(elasticSearchEventPublisher);
|
|
|
|
}
|
2022-11-28 17:45:18 +01:00
|
|
|
|
|
|
|
if (openMetadataApplicationConfig.getEventMonitorConfiguration() != null) {
|
|
|
|
final EventMonitor eventMonitor =
|
|
|
|
EventMonitorFactory.createEventMonitor(
|
|
|
|
openMetadataApplicationConfig.getEventMonitorConfiguration(),
|
|
|
|
openMetadataApplicationConfig.getClusterName());
|
|
|
|
EventMonitorPublisher eventMonitorPublisher =
|
|
|
|
new EventMonitorPublisher(openMetadataApplicationConfig.getEventMonitorConfiguration(), eventMonitor);
|
|
|
|
EventPubSub.addEventHandler(eventMonitorPublisher);
|
|
|
|
}
|
2022-01-12 16:35:27 -08:00
|
|
|
}
|
|
|
|
|
2022-10-10 23:32:48 -07:00
|
|
|
private void registerResources(OpenMetadataApplicationConfig config, Environment environment, Jdbi jdbi) {
|
2022-10-27 22:56:20 +05:30
|
|
|
CollectionRegistry.getInstance().registerResources(jdbi, environment, config, authorizer, authenticatorHandler);
|
2021-08-01 14:27:44 -07:00
|
|
|
environment.jersey().register(new JsonPatchProvider());
|
|
|
|
ErrorPageErrorHandler eph = new ErrorPageErrorHandler();
|
|
|
|
eph.addErrorPage(Response.Status.NOT_FOUND.getStatusCode(), "/");
|
|
|
|
environment.getApplicationContext().setErrorHandler(eph);
|
|
|
|
}
|
|
|
|
|
2022-10-21 20:49:41 -07:00
|
|
|
private void initializeWebsockets(OpenMetadataApplicationConfig catalogConfig, Environment environment) {
|
2022-06-27 16:40:31 +05:30
|
|
|
SocketAddressFilter socketAddressFilter;
|
2022-07-01 19:53:59 +03:00
|
|
|
String pathSpec = "/api/v1/push/feed/*";
|
2022-06-27 16:40:31 +05:30
|
|
|
if (catalogConfig.getAuthorizerConfiguration() != null) {
|
|
|
|
socketAddressFilter =
|
|
|
|
new SocketAddressFilter(
|
2023-02-02 20:19:32 +05:30
|
|
|
catalogConfig.getAuthenticationConfiguration(), catalogConfig.getAuthorizerConfiguration());
|
2022-06-27 16:40:31 +05:30
|
|
|
} else {
|
|
|
|
socketAddressFilter = new SocketAddressFilter();
|
|
|
|
}
|
|
|
|
|
2022-06-15 10:14:47 +05:30
|
|
|
EngineIoServerOptions eioOptions = EngineIoServerOptions.newFromDefault();
|
|
|
|
eioOptions.setAllowedCorsOrigins(null);
|
|
|
|
WebSocketManager.WebSocketManagerBuilder.build(eioOptions);
|
|
|
|
environment.getApplicationContext().setContextPath("/");
|
2022-06-27 16:40:31 +05:30
|
|
|
environment
|
|
|
|
.getApplicationContext()
|
2022-07-01 19:53:59 +03:00
|
|
|
.addFilter(new FilterHolder(socketAddressFilter), pathSpec, EnumSet.of(DispatcherType.REQUEST));
|
|
|
|
environment.getApplicationContext().addServlet(new ServletHolder(new FeedServlet()), pathSpec);
|
2022-06-15 10:14:47 +05:30
|
|
|
// Upgrade connection to websocket from Http
|
|
|
|
try {
|
|
|
|
WebSocketUpgradeFilter webSocketUpgradeFilter =
|
|
|
|
WebSocketUpgradeFilter.configureContext(environment.getApplicationContext());
|
|
|
|
webSocketUpgradeFilter.addMapping(
|
2022-07-01 19:53:59 +03:00
|
|
|
new ServletPathSpec(pathSpec),
|
2022-06-15 10:14:47 +05:30
|
|
|
(servletUpgradeRequest, servletUpgradeResponse) ->
|
|
|
|
new JettyWebSocketHandler(WebSocketManager.getInstance().getEngineIoServer()));
|
|
|
|
} catch (ServletException ex) {
|
2022-06-27 16:40:31 +05:30
|
|
|
LOG.error("Websocket Upgrade Filter error : " + ex.getMessage());
|
2022-06-15 10:14:47 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:27:44 -07:00
|
|
|
public static void main(String[] args) throws Exception {
|
2022-10-26 18:24:40 +05:30
|
|
|
OpenMetadataApplication openMetadataApplication = new OpenMetadataApplication();
|
|
|
|
openMetadataApplication.run(args);
|
2021-08-01 14:27:44 -07:00
|
|
|
}
|
2021-12-23 20:10:38 -08:00
|
|
|
|
2022-02-23 20:40:25 -08:00
|
|
|
public static class ManagedShutdown implements Managed {
|
2021-12-23 20:10:38 -08:00
|
|
|
|
|
|
|
@Override
|
2022-05-22 15:28:55 -07:00
|
|
|
public void start() {
|
2022-01-09 21:03:50 -08:00
|
|
|
LOG.info("Starting the application");
|
2021-12-23 20:10:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-05-22 15:28:55 -07:00
|
|
|
public void stop() throws InterruptedException {
|
2021-12-23 20:10:38 -08:00
|
|
|
EventPubSub.shutdown();
|
2022-01-09 21:03:50 -08:00
|
|
|
LOG.info("Stopping the application");
|
2021-12-23 20:10:38 -08:00
|
|
|
}
|
|
|
|
}
|
2021-08-01 14:27:44 -07:00
|
|
|
}
|