Search in sources :

Example 6 with User

use of com.datastax.fallout.service.core.User in project fallout by datastax.

the class FalloutServerlessCommand method parseUserCredentials.

protected UserCredentialsFactory.UserCredentials parseUserCredentials(Validator validator, Path credsYamlPath) {
    final var objectMapper = JacksonUtils.getYamlObjectMapper();
    final User user;
    try {
        user = objectMapper.readValue(readString(credsYamlPath), User.class);
    } catch (JsonProcessingException e) {
        throw new UserError("Couldn't read user credentials from '%s': %s", credsYamlPath, e.getMessage());
    }
    final var errors = validator.validate(user);
    if (!errors.isEmpty()) {
        throw new UserError("User credentials in '%s' are not valid:\n  %s", credsYamlPath, errors.stream().map(error -> String.format("%s %s", error.getPropertyPath(), error.getMessage())).collect(Collectors.joining("\n  ")));
    }
    return new UserCredentialsFactory.UserCredentials(user, Optional.empty());
}
Also used : User(com.datastax.fallout.service.core.User) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with User

use of com.datastax.fallout.service.core.User in project fallout by datastax.

the class EnsembleFalloutTest method createActiveTestRunBuilder.

public ActiveTestRunBuilder createActiveTestRunBuilder() {
    User testUser = getTestUser();
    UserCredentials userCredentials = new UserCredentials(testUser, Optional.empty());
    // secret is needed for example yamls to be valid
    testUser.addGenericSecret("MY_ASTRA_TOKEN", "dummy_astra_token");
    JobFileLoggers loggers = new JobFileLoggers(testRunArtifactPath(), true, userCredentials);
    return ActiveTestRunBuilder.create().withTestRunScratchSpace(persistentTestScratchSpace()).withTestRunArtifactPath(testRunArtifactPath()).withTestRunIdentifier(Fakes.TEST_RUN_IDENTIFIER).withLoggers(loggers).withFalloutConfiguration(falloutConfiguration()).withTestRunStatusUpdater(new TestRunAbortedStatusUpdater(new InMemoryTestRunStateStorage(TestRun.State.CREATED))).withUserCredentials(userCredentials).withCommandExecutor(new Java8LocalCommandExecutor()).destroyEnsembleAfterTest(true);
}
Also used : JobFileLoggers(com.datastax.fallout.ops.JobFileLoggers) User(com.datastax.fallout.service.core.User) Java8LocalCommandExecutor(com.datastax.fallout.ops.commands.Java8LocalCommandExecutor) UserCredentials(com.datastax.fallout.runner.UserCredentialsFactory.UserCredentials)

Example 8 with User

use of com.datastax.fallout.service.core.User in project fallout by datastax.

the class TestResource method searchTestsApi.

@GET
@Path("/search")
@Timed
@Produces(MediaType.APPLICATION_JSON)
public List<Test> searchTestsApi(@Auth User user, @QueryParam("testName") String testName, @QueryParam("owner") String owner, @QueryParam("tags") List<String> tags, @QueryParam("created") String created) {
    if (tags == null)
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
    Date dateCreated = (created == null) ? null : Date.from(LocalDate.parse(created).atStartOfDay(ZoneId.systemDefault()).toInstant());
    List<Test> result = testDAO.getTestsFromTag(tags);
    result = result.stream().filter(t -> testName == null || t.getName().equals(testName)).filter(t -> owner == null || t.getOwner().equals(owner)).filter(t -> dateCreated == null || t.getCreatedAt().after(dateCreated)).toList();
    return result;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) Date(java.util.Date) BiFunction(java.util.function.BiFunction) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) TestRunUtils(com.datastax.fallout.util.TestRunUtils) Test(com.datastax.fallout.service.core.Test) LinkedTests(com.datastax.fallout.service.views.LinkedTests) TestRun(com.datastax.fallout.service.core.TestRun) NGINX_DIRECT_ARTIFACTS_LOCATION(com.datastax.fallout.service.cli.GenerateNginxConf.NginxConfParams.NGINX_DIRECT_ARTIFACTS_LOCATION) DeletedTest(com.datastax.fallout.service.core.DeletedTest) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) QueuingTestRunner(com.datastax.fallout.runner.QueuingTestRunner) ZipEntry(java.util.zip.ZipEntry) PerformanceReportDAO(com.datastax.fallout.service.db.PerformanceReportDAO) ResourceUtils(com.datastax.fallout.util.ResourceUtils) DELETE(javax.ws.rs.DELETE) MainView(com.datastax.fallout.service.views.MainView) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) StandardOpenOption(java.nio.file.StandardOpenOption) FalloutView.uriFor(com.datastax.fallout.service.views.FalloutView.uriFor) Set(java.util.Set) StreamingOutput(javax.ws.rs.core.StreamingOutput) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Objects(java.util.Objects) Timed(com.codahale.metrics.annotation.Timed) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) TestDAO(com.datastax.fallout.service.db.TestDAO) Response(javax.ws.rs.core.Response) LocalDate(java.time.LocalDate) WebApplicationException(javax.ws.rs.WebApplicationException) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) Pattern(java.util.regex.Pattern) LinkedTestRuns(com.datastax.fallout.service.views.LinkedTestRuns) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) ZipOutputStream(java.util.zip.ZipOutputStream) PathParam(javax.ws.rs.PathParam) User(com.datastax.fallout.service.core.User) GET(javax.ws.rs.GET) EMAIL_PATTERN(com.datastax.fallout.service.resources.server.AccountResource.EMAIL_PATTERN) DeletedTestRun(com.datastax.fallout.service.core.DeletedTestRun) Exceptions(com.datastax.fallout.util.Exceptions) Auth(io.dropwizard.auth.Auth) HashMap(java.util.HashMap) Artifacts(com.datastax.fallout.runner.Artifacts) Function(java.util.function.Function) Supplier(java.util.function.Supplier) FalloutView(com.datastax.fallout.service.views.FalloutView) ArrayList(java.util.ArrayList) InvalidConfigurationException(com.datastax.fallout.exceptions.InvalidConfigurationException) HashSet(java.util.HashSet) BiPredicate(java.util.function.BiPredicate) TestDefinition(com.datastax.fallout.harness.TestDefinition) Api(io.swagger.annotations.Api) ActiveTestRunFactory(com.datastax.fallout.runner.ActiveTestRunFactory) HasPermissions(com.datastax.fallout.service.core.HasPermissions) OutputStream(java.io.OutputStream) UserGroupMapper(com.datastax.fallout.service.db.UserGroupMapper) TableDisplayOption(com.datastax.fallout.service.views.LinkedTestRuns.TableDisplayOption) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Files(java.nio.file.Files) FalloutConfiguration(com.datastax.fallout.service.FalloutConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) UserCredentialsFactory(com.datastax.fallout.runner.UserCredentialsFactory) PerformanceReport(com.datastax.fallout.service.core.PerformanceReport) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) ReadOnlyTestRun(com.datastax.fallout.service.core.ReadOnlyTestRun) TestRunDAO(com.datastax.fallout.service.db.TestRunDAO) Paths(java.nio.file.Paths) YamlUtils.loadYaml(com.datastax.fallout.util.YamlUtils.loadYaml) PUT(javax.ws.rs.PUT) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TestCompletionNotification(com.datastax.fallout.service.core.TestCompletionNotification) Comparator(java.util.Comparator) Collections(java.util.Collections) WebApplicationException(javax.ws.rs.WebApplicationException) Test(com.datastax.fallout.service.core.Test) DeletedTest(com.datastax.fallout.service.core.DeletedTest) Date(java.util.Date) LocalDate(java.time.LocalDate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 9 with User

use of com.datastax.fallout.service.core.User in project fallout by datastax.

the class FalloutServiceBase method getAuthFilters.

private List<AuthFilter<String, User>> getAuthFilters(FC conf, UserDAO userDAO) {
    List<AuthFilter<String, User>> filters = new ArrayList<>();
    // This will only be applied to methods/classes annotated with RolesAllowed
    final Authorizer<User> adminAuthorizer = (user, role) -> user.isAdmin() && role.equals("ADMIN");
    AuthFilter<String, User> oauthCredentialAuthFilter = new OAuthCredentialAuthFilter.Builder<User>().setAuthenticator(new FalloutTokenAuthenticator(userDAO, OAUTH_REALM)).setAuthorizer(adminAuthorizer).setPrefix(OAUTH_BEARER_TOKEN_TYPE).setRealm(OAUTH_REALM).buildAuthFilter();
    filters.add(oauthCredentialAuthFilter);
    AuthFilter<String, User> uiAuthFilter;
    if (conf.getAuthenticationMode() == FalloutConfiguration.AuthenticationMode.SINGLE_USER) {
        if (conf.getAdminUserCreds().isEmpty()) {
            throw new RuntimeException(String.format("Cannot use %s authentication mode without specifying %s in the environment", FalloutConfiguration.AuthenticationMode.SINGLE_USER, FalloutConfiguration.ADMIN_CREDS_ENV_VAR));
        }
        uiAuthFilter = new SingleUserAuthFilter(() -> userDAO.getUser(conf.getAdminUserCreds().get().email()));
    } else {
        uiAuthFilter = new FalloutCookieAuthFilter.Builder().setAuthenticator(new FalloutTokenAuthenticator(userDAO, COOKIE_NAME)).setAuthorizer(adminAuthorizer).setPrefix(OAUTH_BEARER_TOKEN_TYPE).setRealm(OAUTH_REALM).buildAuthFilter();
    }
    filters.add(uiAuthFilter);
    return filters;
}
Also used : RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler) SwaggerBundleConfiguration(io.federecio.dropwizard.swagger.SwaggerBundleConfiguration) JacksonUtils(com.datastax.fallout.util.JacksonUtils) AuthValueFactoryProvider(io.dropwizard.auth.AuthValueFactoryProvider) Map(java.util.Map) RolesAllowedDynamicFeature(org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature) AbortableRunnableExecutorFactory(com.datastax.fallout.runner.AbortableRunnableExecutorFactory) QueuingTestRunner(com.datastax.fallout.runner.QueuingTestRunner) Path(java.nio.file.Path) ResourceReservationLocks(com.datastax.fallout.runner.ResourceReservationLocks) EnumSet(java.util.EnumSet) Duration(com.datastax.fallout.util.Duration) LocalCommandExecutor(com.datastax.fallout.ops.commands.LocalCommandExecutor) MainView(com.datastax.fallout.service.views.MainView) RewriteRegexRule(org.eclipse.jetty.rewrite.handler.RewriteRegexRule) LocalizationMessages(org.glassfish.jersey.server.internal.LocalizationMessages) NginxArtifactServlet(com.datastax.fallout.service.artifacts.NginxArtifactServlet) Verify(com.google.common.base.Verify) SingleUserAuthFilter(com.datastax.fallout.service.auth.SingleUserAuthFilter) Servlet(javax.servlet.Servlet) UserCredentials(com.datastax.fallout.runner.UserCredentialsFactory.UserCredentials) Set(java.util.Set) ScopedLogger(com.datastax.fallout.util.ScopedLogger) DefaultServerFactory(io.dropwizard.server.DefaultServerFactory) RunnableExecutorFactory(com.datastax.fallout.runner.RunnableExecutorFactory) FalloutTokenAuthenticator(com.datastax.fallout.service.auth.FalloutTokenAuthenticator) HtmlMailUserMessenger(com.datastax.fallout.util.HtmlMailUserMessenger) CheckCommand(io.dropwizard.cli.CheckCommand) FalloutExecCommand(com.datastax.fallout.service.cli.FalloutExecCommand) CommonProperties(org.glassfish.jersey.CommonProperties) User(com.datastax.fallout.service.core.User) FreemarkerViewRenderer(io.dropwizard.views.freemarker.FreemarkerViewRenderer) Bootstrap(io.dropwizard.setup.Bootstrap) ComponentFactory(com.datastax.fallout.util.component_discovery.ComponentFactory) ServerSentEvents(com.datastax.fallout.service.resources.ServerSentEvents) Exceptions(com.datastax.fallout.util.Exceptions) LiveResource(com.datastax.fallout.service.resources.server.LiveResource) TestResource(com.datastax.fallout.service.resources.server.TestResource) Supplier(java.util.function.Supplier) ViewBundle(io.dropwizard.views.ViewBundle) FalloutVersion(com.datastax.fallout.FalloutVersion) ArrayList(java.util.ArrayList) QueueMetricsManager(com.datastax.fallout.service.db.QueueMetricsManager) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ClojureShutdown(com.datastax.fallout.harness.ClojureShutdown) DelegatingExecutorFactory(com.datastax.fallout.runner.DelegatingExecutorFactory) Environment(io.dropwizard.setup.Environment) UserGroupMapper(com.datastax.fallout.service.db.UserGroupMapper) ArtifactScrubber(com.datastax.fallout.service.artifacts.ArtifactScrubber) ReadOnlyTestRun(com.datastax.fallout.service.core.ReadOnlyTestRun) AccountResource(com.datastax.fallout.service.resources.server.AccountResource) CassandraDriverManager(com.datastax.fallout.service.db.CassandraDriverManager) Paths(java.nio.file.Paths) ForkJoinPool(java.util.concurrent.ForkJoinPool) RunnerResource(com.datastax.fallout.service.resources.runner.RunnerResource) UserMessenger(com.datastax.fallout.util.UserMessenger) PersistentPendingQueue(com.datastax.fallout.runner.queue.PersistentPendingQueue) SecurityUtil(com.datastax.fallout.service.auth.SecurityUtil) HomeResource(com.datastax.fallout.service.resources.server.HomeResource) FinishedTestRunUserNotifier(com.datastax.fallout.util.FinishedTestRunUserNotifier) TestRun(com.datastax.fallout.service.core.TestRun) IllegalStateExceptionMapper(io.dropwizard.jersey.errors.IllegalStateExceptionMapper) RedirectRegexRule(org.eclipse.jetty.rewrite.handler.RedirectRegexRule) Ensemble(com.datastax.fallout.ops.Ensemble) URI(java.net.URI) ComponentResource(com.datastax.fallout.service.resources.server.ComponentResource) PerformanceReportDAO(com.datastax.fallout.service.db.PerformanceReportDAO) Authorizer(io.dropwizard.auth.Authorizer) UserDAO(com.datastax.fallout.service.db.UserDAO) Application(io.dropwizard.Application) Cassandra(com.datastax.fallout.service.cli.Cassandra) FalloutStandaloneCommand(com.datastax.fallout.service.cli.FalloutStandaloneCommand) FalloutCookieAuthFilter(com.datastax.fallout.service.auth.FalloutCookieAuthFilter) SwaggerBundle(io.federecio.dropwizard.swagger.SwaggerBundle) ArtifactUsageAdminTask(com.datastax.fallout.service.artifacts.ArtifactUsageAdminTask) ThreadedRunnableExecutorFactory(com.datastax.fallout.runner.ThreadedRunnableExecutorFactory) MustacheViewRendererWithoutTemplatingErrors(com.datastax.fallout.util.MustacheViewRendererWithoutTemplatingErrors) AssetsBundle(io.dropwizard.assets.AssetsBundle) List(java.util.List) AuthFilter(io.dropwizard.auth.AuthFilter) TestDAO(com.datastax.fallout.service.db.TestDAO) Response(javax.ws.rs.core.Response) NamedThreadFactory(com.datastax.fallout.util.NamedThreadFactory) Managed(io.dropwizard.lifecycle.Managed) HashedWheelTimer(io.netty.util.HashedWheelTimer) Optional(java.util.Optional) ChainedAuthFilter(io.dropwizard.auth.chained.ChainedAuthFilter) ArtifactCompressorAdminTask(com.datastax.fallout.service.artifacts.ArtifactCompressorAdminTask) OAuthCredentialAuthFilter(io.dropwizard.auth.oauth.OAuthCredentialAuthFilter) GenerateNginxConf(com.datastax.fallout.service.cli.GenerateNginxConf) ServerMode(com.datastax.fallout.service.FalloutConfiguration.ServerMode) ServletRegistration(javax.servlet.ServletRegistration) CommandExecutor(com.datastax.fallout.ops.commands.CommandExecutor) Client(javax.ws.rs.client.Client) AuthDynamicFeature(io.dropwizard.auth.AuthDynamicFeature) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) SchemaMode(com.datastax.fallout.service.db.CassandraDriverManager.SchemaMode) ActiveTestRun(com.datastax.fallout.harness.ActiveTestRun) FalloutQueueCommand(com.datastax.fallout.service.cli.FalloutQueueCommand) ArtifactCompressor(com.datastax.fallout.service.artifacts.ArtifactCompressor) ActiveTestRunFactory(com.datastax.fallout.runner.ActiveTestRunFactory) IntSupplier(java.util.function.IntSupplier) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) FalloutRunnerCommand(com.datastax.fallout.service.cli.FalloutRunnerCommand) FileUtils(com.datastax.fallout.util.FileUtils) SlackUserMessenger(com.datastax.fallout.util.SlackUserMessenger) AdminResource(com.datastax.fallout.service.resources.server.AdminResource) ReentrantLock(java.util.concurrent.locks.ReentrantLock) JettyArtifactServlet(com.datastax.fallout.service.artifacts.JettyArtifactServlet) TestRunReaper(com.datastax.fallout.service.core.TestRunReaper) DelegatingRunnableExecutorFactory(com.datastax.fallout.runner.DelegatingRunnableExecutorFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UserCredentialsFactory(com.datastax.fallout.runner.UserCredentialsFactory) TestRunStatusUpdatePublisher(com.datastax.fallout.harness.TestRunStatusUpdatePublisher) AutoCloseableManager(io.dropwizard.lifecycle.AutoCloseableManager) DirectTestRunner(com.datastax.fallout.runner.DirectTestRunner) Consumer(java.util.function.Consumer) ArtifactWatcher(com.datastax.fallout.service.artifacts.ArtifactWatcher) TestRunDAO(com.datastax.fallout.service.db.TestRunDAO) JobLoggersFactory(com.datastax.fallout.runner.JobLoggersFactory) StatusResource(com.datastax.fallout.service.resources.server.StatusResource) DispatcherType(javax.servlet.DispatcherType) PerformanceToolResource(com.datastax.fallout.service.resources.server.PerformanceToolResource) WebTarget(javax.ws.rs.client.WebTarget) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FalloutValidateCommand(com.datastax.fallout.service.cli.FalloutValidateCommand) User(com.datastax.fallout.service.core.User) FalloutTokenAuthenticator(com.datastax.fallout.service.auth.FalloutTokenAuthenticator) SingleUserAuthFilter(com.datastax.fallout.service.auth.SingleUserAuthFilter) ArrayList(java.util.ArrayList) SingleUserAuthFilter(com.datastax.fallout.service.auth.SingleUserAuthFilter) FalloutCookieAuthFilter(com.datastax.fallout.service.auth.FalloutCookieAuthFilter) AuthFilter(io.dropwizard.auth.AuthFilter) ChainedAuthFilter(io.dropwizard.auth.chained.ChainedAuthFilter) OAuthCredentialAuthFilter(io.dropwizard.auth.oauth.OAuthCredentialAuthFilter) OAuthCredentialAuthFilter(io.dropwizard.auth.oauth.OAuthCredentialAuthFilter)

Example 10 with User

use of com.datastax.fallout.service.core.User in project fallout by datastax.

the class FalloutServiceBase method runServer.

private void runServer(FC conf, Environment environment, CreateAbortableTestRunExecutorFactory createTestRunExecutorFactory, SchemaMode schemaMode) throws Exception {
    final LifecycleManager m = new LifecycleManager(environment);
    final ResourceReservationLocks resourceReservationLocks = new ResourceReservationLocks();
    cassandraDriverManager = m.manage(new CassandraDriverManager(conf.getCassandraHost(), conf.getCassandraPort(), conf.getKeyspace(), schemaMode, preCreateSchemaCallback));
    SecurityUtil securityUtil = new SecurityUtil(conf.getSecureRandomAlgorithm());
    final var userGroupMapper = createUserGroupMapper();
    UserDAO userDAO = m.manage(new UserDAO(cassandraDriverManager, securityUtil, conf.getAdminUserCreds(), userGroupMapper));
    TestRunDAO testRunDAO = m.manage(new TestRunDAO(cassandraDriverManager));
    TestDAO testDAO = m.manage(new TestDAO(cassandraDriverManager, testRunDAO));
    PerformanceReportDAO reportDAO = m.manage(new PerformanceReportDAO(cassandraDriverManager));
    ActiveTestRunFactory activeTestRunFactory = createActiveTestRunFactory(conf);
    UserMessenger mailer = HtmlMailUserMessenger.create(conf);
    UserCredentialsFactory userCredentialsFactory = (testRun) -> {
        User user = userDAO.getUser(testRun.getOwner());
        if (user == null) {
            throw new RuntimeException(String.format("Couldn't find User with email '%s'", testRun.getOwner()));
        }
        return new UserCredentials(user, userDAO.getCIUserByUser(user));
    };
    QueuingTestRunner testRunner = m.manageStartOnly(new QueuingTestRunner(testRunDAO::update, testDAO::updateLastRunAt, new PersistentPendingQueue(testRunDAO::getQueued), userCredentialsFactory, createTestRunExecutorFactory.create(conf, m, mailer, testDAO, testRunDAO, activeTestRunFactory), testRun -> activeTestRunFactory.getResourceRequirements(testRun, userCredentialsFactory), resourceReservationLocks, conf.getResourceLimits(), conf.getStartPaused()));
    // monitor queue metrics
    QueueMetricsManager.registerMetrics(environment.metrics(), testRunDAO);
    runningTestRunsCount = testRunner::getRunningTestRunsCount;
    // Make sure the performance_reports dir exists
    FileUtils.createDirs(Paths.get(conf.getArtifactPath(), "performance_reports"));
    final HashedWheelTimer timer = m.manage(new HashedWheelTimer(new NamedThreadFactory("ServiceTimer")), HashedWheelTimer::stop);
    Path artifactPath = Paths.get(conf.getArtifactPath());
    final var runningTaskLock = new ReentrantLock();
    ArtifactScrubber artifactScrubber = m.manage(new ArtifactScrubber(conf.getStartPaused(), timer, runningTaskLock, Duration.hours(0), Duration.hours(24), artifactPath, testRunDAO, userDAO));
    ArtifactCompressor artifactCompressor = m.manage(new ArtifactCompressor(conf.getStartPaused(), timer, runningTaskLock, Duration.hours(12), Duration.hours(24), artifactPath, testRunDAO, testDAO));
    TestRunReaper testRunReaper = m.manage(new TestRunReaper(conf.getStartPaused(), timer, runningTaskLock, Duration.hours(18), Duration.days(7), testRunDAO, reportDAO, testDAO, mailer, SlackUserMessenger.create(conf.getSlackToken(), m.manage(FalloutClientBuilder.forComponent(SlackUserMessenger.class).build(), Client::close)), conf.getExternalUrl()));
    QueueAdminTask queueAdminTask = new QueueAdminTask(testRunner, List.of(artifactScrubber, artifactCompressor, testRunReaper));
    environment.admin().addTask(queueAdminTask);
    final var artifactUsageAdminTask = new ArtifactUsageAdminTask(testRunDAO);
    environment.admin().addTask(artifactUsageAdminTask);
    environment.admin().addTask(new ArtifactCompressorAdminTask(artifactCompressor));
    environment.admin().addTask(new ShutdownTask(this::shutdown));
    truncateTrailingSlashesInUrls(conf);
    final RewriteHandler rewriteHandler = new RewriteHandler();
    conf.getServerFactory().insertHandler(rewriteHandler);
    addArtifactServlet(conf, environment, rewriteHandler);
    // Add CORS headers so that fallout API can be consumed from other than the main URL
    // The `CrossOriginFilter` comes with the required default settings: allow any origin
    environment.servlets().addFilter("CORS", CrossOriginFilter.class).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
    // Register our exception mappers: note that we must use concrete (i.e. non-generic) classes, otherwise
    // the convoluted exception mapping code in Jersey will fail with an HTTP 500 error.
    // Dropwizard registers several helpful exception mappers on server start in its ExceptionMapperBinder; one of
    // these provides a helper logging method for detecting a particular developer error when POSTing
    // forms.  Unfortunately, this intercepts _all_ IllegalStateExceptions.  We insert our IllegalStateException
    // mapper here to pre-empt it, whilest keeping the helper logic.
    environment.jersey().register(new FalloutExceptionMapper<IllegalStateException>() {

        private final IllegalStateExceptionMapper dropWizardIllegalStateExceptionMapper = new IllegalStateExceptionMapper();

        /**
         * If the helper code in {@link IllegalStateExceptionMapper} applies, use that
         */
        @Override
        public Response toResponse(IllegalStateException exception) {
            if (LocalizationMessages.FORM_PARAM_CONTENT_TYPE_ERROR().equals(exception.getMessage())) {
                return dropWizardIllegalStateExceptionMapper.toResponse(exception);
            }
            return super.toResponse(exception);
        }
    });
    // This is our default exception mapper.
    environment.jersey().register(new FalloutExceptionMapper<>() {
    });
    environment.jersey().register(new AuthDynamicFeature(new ChainedAuthFilter(getAuthFilters(conf, userDAO))));
    // Enable @RolesAllowed annotations
    environment.jersey().register(new RolesAllowedDynamicFeature());
    // If you want to use @Auth to inject a custom Principal type into your resource
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
    final ComponentResource componentResource = new ComponentResource(conf, componentFactory);
    MainView mainView = new MainView(componentResource.getComponentTypes(), testRunner, addVersionedAssetsRewriteRule(rewriteHandler), conf::hideDisplayedEmailDomains);
    componentResource.setMainView(mainView);
    CommandExecutor commandExecutor = new LocalCommandExecutor();
    environment.jersey().register(new StatusResource(testRunner));
    environment.jersey().register(new HomeResource(conf, userDAO, testRunDAO, testRunner, conf.getResourceLimits(), mainView, userGroupMapper));
    environment.jersey().register(new AdminResource(testRunner, queueAdminTask, artifactUsageAdminTask, mainView));
    environment.jersey().register(new AccountResource(userDAO, conf, mailer, mainView, securityUtil, userGroupMapper));
    environment.jersey().register(new TestResource(conf, testDAO, testRunDAO, activeTestRunFactory, userCredentialsFactory, reportDAO, testRunner, mainView, userGroupMapper));
    environment.jersey().register(componentResource);
    environment.jersey().register(new PerformanceToolResource(testDAO, testRunDAO, reportDAO, conf.getArtifactPath(), mainView, userGroupMapper));
    registerOptionalResources(conf, environment, testRunDAO, commandExecutor);
    // Using SSE (which is what LiveResource uses) doesn't work unless we prevent the
    // GZIP output filter from flushing-on-demand (if we don't do this, data is queued up until the
    // GZIP implementation decides it's a good time to flush: see java.util.zip.Deflater#SYNC_FLUSH).
    ((DefaultServerWithHandlerFactory) conf.getServerFactory()).getGzipFilterFactory().setSyncFlush(true);
    final ArtifactWatcher artifactWatcher = new ArtifactWatcher(Paths.get(conf.getArtifactPath()), timer, conf.getArtifactWatcherCoalescingIntervalSeconds());
    environment.lifecycle().manage(artifactWatcher);
    final ServerSentEvents serverSentEvents = m.manageStartOnly(new ServerSentEvents(timer, conf.getServerSentEventsHeartBeatIntervalSeconds()));
    environment.jersey().register(new LiveResource(testRunDAO, artifactWatcher, serverSentEvents));
    setShutdownHandler(environment, testRunner, serverSentEvents);
}
Also used : RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler) SwaggerBundleConfiguration(io.federecio.dropwizard.swagger.SwaggerBundleConfiguration) JacksonUtils(com.datastax.fallout.util.JacksonUtils) AuthValueFactoryProvider(io.dropwizard.auth.AuthValueFactoryProvider) Map(java.util.Map) RolesAllowedDynamicFeature(org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature) AbortableRunnableExecutorFactory(com.datastax.fallout.runner.AbortableRunnableExecutorFactory) QueuingTestRunner(com.datastax.fallout.runner.QueuingTestRunner) Path(java.nio.file.Path) ResourceReservationLocks(com.datastax.fallout.runner.ResourceReservationLocks) EnumSet(java.util.EnumSet) Duration(com.datastax.fallout.util.Duration) LocalCommandExecutor(com.datastax.fallout.ops.commands.LocalCommandExecutor) MainView(com.datastax.fallout.service.views.MainView) RewriteRegexRule(org.eclipse.jetty.rewrite.handler.RewriteRegexRule) LocalizationMessages(org.glassfish.jersey.server.internal.LocalizationMessages) NginxArtifactServlet(com.datastax.fallout.service.artifacts.NginxArtifactServlet) Verify(com.google.common.base.Verify) SingleUserAuthFilter(com.datastax.fallout.service.auth.SingleUserAuthFilter) Servlet(javax.servlet.Servlet) UserCredentials(com.datastax.fallout.runner.UserCredentialsFactory.UserCredentials) Set(java.util.Set) ScopedLogger(com.datastax.fallout.util.ScopedLogger) DefaultServerFactory(io.dropwizard.server.DefaultServerFactory) RunnableExecutorFactory(com.datastax.fallout.runner.RunnableExecutorFactory) FalloutTokenAuthenticator(com.datastax.fallout.service.auth.FalloutTokenAuthenticator) HtmlMailUserMessenger(com.datastax.fallout.util.HtmlMailUserMessenger) CheckCommand(io.dropwizard.cli.CheckCommand) FalloutExecCommand(com.datastax.fallout.service.cli.FalloutExecCommand) CommonProperties(org.glassfish.jersey.CommonProperties) User(com.datastax.fallout.service.core.User) FreemarkerViewRenderer(io.dropwizard.views.freemarker.FreemarkerViewRenderer) Bootstrap(io.dropwizard.setup.Bootstrap) ComponentFactory(com.datastax.fallout.util.component_discovery.ComponentFactory) ServerSentEvents(com.datastax.fallout.service.resources.ServerSentEvents) Exceptions(com.datastax.fallout.util.Exceptions) LiveResource(com.datastax.fallout.service.resources.server.LiveResource) TestResource(com.datastax.fallout.service.resources.server.TestResource) Supplier(java.util.function.Supplier) ViewBundle(io.dropwizard.views.ViewBundle) FalloutVersion(com.datastax.fallout.FalloutVersion) ArrayList(java.util.ArrayList) QueueMetricsManager(com.datastax.fallout.service.db.QueueMetricsManager) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ClojureShutdown(com.datastax.fallout.harness.ClojureShutdown) DelegatingExecutorFactory(com.datastax.fallout.runner.DelegatingExecutorFactory) Environment(io.dropwizard.setup.Environment) UserGroupMapper(com.datastax.fallout.service.db.UserGroupMapper) ArtifactScrubber(com.datastax.fallout.service.artifacts.ArtifactScrubber) ReadOnlyTestRun(com.datastax.fallout.service.core.ReadOnlyTestRun) AccountResource(com.datastax.fallout.service.resources.server.AccountResource) CassandraDriverManager(com.datastax.fallout.service.db.CassandraDriverManager) Paths(java.nio.file.Paths) ForkJoinPool(java.util.concurrent.ForkJoinPool) RunnerResource(com.datastax.fallout.service.resources.runner.RunnerResource) UserMessenger(com.datastax.fallout.util.UserMessenger) PersistentPendingQueue(com.datastax.fallout.runner.queue.PersistentPendingQueue) SecurityUtil(com.datastax.fallout.service.auth.SecurityUtil) HomeResource(com.datastax.fallout.service.resources.server.HomeResource) FinishedTestRunUserNotifier(com.datastax.fallout.util.FinishedTestRunUserNotifier) TestRun(com.datastax.fallout.service.core.TestRun) IllegalStateExceptionMapper(io.dropwizard.jersey.errors.IllegalStateExceptionMapper) RedirectRegexRule(org.eclipse.jetty.rewrite.handler.RedirectRegexRule) Ensemble(com.datastax.fallout.ops.Ensemble) URI(java.net.URI) ComponentResource(com.datastax.fallout.service.resources.server.ComponentResource) PerformanceReportDAO(com.datastax.fallout.service.db.PerformanceReportDAO) Authorizer(io.dropwizard.auth.Authorizer) UserDAO(com.datastax.fallout.service.db.UserDAO) Application(io.dropwizard.Application) Cassandra(com.datastax.fallout.service.cli.Cassandra) FalloutStandaloneCommand(com.datastax.fallout.service.cli.FalloutStandaloneCommand) FalloutCookieAuthFilter(com.datastax.fallout.service.auth.FalloutCookieAuthFilter) SwaggerBundle(io.federecio.dropwizard.swagger.SwaggerBundle) ArtifactUsageAdminTask(com.datastax.fallout.service.artifacts.ArtifactUsageAdminTask) ThreadedRunnableExecutorFactory(com.datastax.fallout.runner.ThreadedRunnableExecutorFactory) MustacheViewRendererWithoutTemplatingErrors(com.datastax.fallout.util.MustacheViewRendererWithoutTemplatingErrors) AssetsBundle(io.dropwizard.assets.AssetsBundle) List(java.util.List) AuthFilter(io.dropwizard.auth.AuthFilter) TestDAO(com.datastax.fallout.service.db.TestDAO) Response(javax.ws.rs.core.Response) NamedThreadFactory(com.datastax.fallout.util.NamedThreadFactory) Managed(io.dropwizard.lifecycle.Managed) HashedWheelTimer(io.netty.util.HashedWheelTimer) Optional(java.util.Optional) ChainedAuthFilter(io.dropwizard.auth.chained.ChainedAuthFilter) ArtifactCompressorAdminTask(com.datastax.fallout.service.artifacts.ArtifactCompressorAdminTask) OAuthCredentialAuthFilter(io.dropwizard.auth.oauth.OAuthCredentialAuthFilter) GenerateNginxConf(com.datastax.fallout.service.cli.GenerateNginxConf) ServerMode(com.datastax.fallout.service.FalloutConfiguration.ServerMode) ServletRegistration(javax.servlet.ServletRegistration) CommandExecutor(com.datastax.fallout.ops.commands.CommandExecutor) Client(javax.ws.rs.client.Client) AuthDynamicFeature(io.dropwizard.auth.AuthDynamicFeature) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) SchemaMode(com.datastax.fallout.service.db.CassandraDriverManager.SchemaMode) ActiveTestRun(com.datastax.fallout.harness.ActiveTestRun) FalloutQueueCommand(com.datastax.fallout.service.cli.FalloutQueueCommand) ArtifactCompressor(com.datastax.fallout.service.artifacts.ArtifactCompressor) ActiveTestRunFactory(com.datastax.fallout.runner.ActiveTestRunFactory) IntSupplier(java.util.function.IntSupplier) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) FalloutRunnerCommand(com.datastax.fallout.service.cli.FalloutRunnerCommand) FileUtils(com.datastax.fallout.util.FileUtils) SlackUserMessenger(com.datastax.fallout.util.SlackUserMessenger) AdminResource(com.datastax.fallout.service.resources.server.AdminResource) ReentrantLock(java.util.concurrent.locks.ReentrantLock) JettyArtifactServlet(com.datastax.fallout.service.artifacts.JettyArtifactServlet) TestRunReaper(com.datastax.fallout.service.core.TestRunReaper) DelegatingRunnableExecutorFactory(com.datastax.fallout.runner.DelegatingRunnableExecutorFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UserCredentialsFactory(com.datastax.fallout.runner.UserCredentialsFactory) TestRunStatusUpdatePublisher(com.datastax.fallout.harness.TestRunStatusUpdatePublisher) AutoCloseableManager(io.dropwizard.lifecycle.AutoCloseableManager) DirectTestRunner(com.datastax.fallout.runner.DirectTestRunner) Consumer(java.util.function.Consumer) ArtifactWatcher(com.datastax.fallout.service.artifacts.ArtifactWatcher) TestRunDAO(com.datastax.fallout.service.db.TestRunDAO) JobLoggersFactory(com.datastax.fallout.runner.JobLoggersFactory) StatusResource(com.datastax.fallout.service.resources.server.StatusResource) DispatcherType(javax.servlet.DispatcherType) PerformanceToolResource(com.datastax.fallout.service.resources.server.PerformanceToolResource) WebTarget(javax.ws.rs.client.WebTarget) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FalloutValidateCommand(com.datastax.fallout.service.cli.FalloutValidateCommand) LocalCommandExecutor(com.datastax.fallout.ops.commands.LocalCommandExecutor) CommandExecutor(com.datastax.fallout.ops.commands.CommandExecutor) AuthValueFactoryProvider(io.dropwizard.auth.AuthValueFactoryProvider) RolesAllowedDynamicFeature(org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature) ArtifactScrubber(com.datastax.fallout.service.artifacts.ArtifactScrubber) ComponentResource(com.datastax.fallout.service.resources.server.ComponentResource) PerformanceReportDAO(com.datastax.fallout.service.db.PerformanceReportDAO) ChainedAuthFilter(io.dropwizard.auth.chained.ChainedAuthFilter) ArtifactWatcher(com.datastax.fallout.service.artifacts.ArtifactWatcher) CassandraDriverManager(com.datastax.fallout.service.db.CassandraDriverManager) ArtifactCompressorAdminTask(com.datastax.fallout.service.artifacts.ArtifactCompressorAdminTask) DispatcherType(javax.servlet.DispatcherType) AuthDynamicFeature(io.dropwizard.auth.AuthDynamicFeature) RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler) ReentrantLock(java.util.concurrent.locks.ReentrantLock) LocalCommandExecutor(com.datastax.fallout.ops.commands.LocalCommandExecutor) NamedThreadFactory(com.datastax.fallout.util.NamedThreadFactory) SlackUserMessenger(com.datastax.fallout.util.SlackUserMessenger) HashedWheelTimer(io.netty.util.HashedWheelTimer) TestRunReaper(com.datastax.fallout.service.core.TestRunReaper) UserCredentialsFactory(com.datastax.fallout.runner.UserCredentialsFactory) IllegalStateExceptionMapper(io.dropwizard.jersey.errors.IllegalStateExceptionMapper) ArtifactCompressor(com.datastax.fallout.service.artifacts.ArtifactCompressor) ArtifactUsageAdminTask(com.datastax.fallout.service.artifacts.ArtifactUsageAdminTask) User(com.datastax.fallout.service.core.User) MainView(com.datastax.fallout.service.views.MainView) HomeResource(com.datastax.fallout.service.resources.server.HomeResource) AdminResource(com.datastax.fallout.service.resources.server.AdminResource) StatusResource(com.datastax.fallout.service.resources.server.StatusResource) PerformanceToolResource(com.datastax.fallout.service.resources.server.PerformanceToolResource) LiveResource(com.datastax.fallout.service.resources.server.LiveResource) ActiveTestRunFactory(com.datastax.fallout.runner.ActiveTestRunFactory) UserDAO(com.datastax.fallout.service.db.UserDAO) ServerSentEvents(com.datastax.fallout.service.resources.ServerSentEvents) Path(java.nio.file.Path) QueuingTestRunner(com.datastax.fallout.runner.QueuingTestRunner) PersistentPendingQueue(com.datastax.fallout.runner.queue.PersistentPendingQueue) TestResource(com.datastax.fallout.service.resources.server.TestResource) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) TestDAO(com.datastax.fallout.service.db.TestDAO) Response(javax.ws.rs.core.Response) AccountResource(com.datastax.fallout.service.resources.server.AccountResource) ResourceReservationLocks(com.datastax.fallout.runner.ResourceReservationLocks) SecurityUtil(com.datastax.fallout.service.auth.SecurityUtil) UserCredentials(com.datastax.fallout.runner.UserCredentialsFactory.UserCredentials) TestRunDAO(com.datastax.fallout.service.db.TestRunDAO) HtmlMailUserMessenger(com.datastax.fallout.util.HtmlMailUserMessenger) UserMessenger(com.datastax.fallout.util.UserMessenger) SlackUserMessenger(com.datastax.fallout.util.SlackUserMessenger)

Aggregations

User (com.datastax.fallout.service.core.User)13 POST (javax.ws.rs.POST)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 Timed (com.codahale.metrics.annotation.Timed)5 ReadOnlyTestRun (com.datastax.fallout.service.core.ReadOnlyTestRun)4 TestRun (com.datastax.fallout.service.core.TestRun)4 PerformanceReportDAO (com.datastax.fallout.service.db.PerformanceReportDAO)4 TestDAO (com.datastax.fallout.service.db.TestDAO)4 TestRunDAO (com.datastax.fallout.service.db.TestRunDAO)4 UserGroupMapper (com.datastax.fallout.service.db.UserGroupMapper)4 MainView (com.datastax.fallout.service.views.MainView)4 URI (java.net.URI)4 Paths (java.nio.file.Paths)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Set (java.util.Set)4