Search in sources :

Example 1 with TestRunScratchSpaceFactory

use of com.datastax.fallout.ops.TestRunScratchSpaceFactory in project fallout by datastax.

the class FalloutExecCommand method run.

private void run(Validator validator, FC configuration, Path testYamlPath, Map<String, Object> templateParams, Path credsYamlPath, Boolean useUniqueOutputDir, Path rootOutputDir) {
    final var testYaml = readString(testYamlPath);
    final var userCredentials = parseUserCredentials(validator, credsYamlPath);
    final var test = Test.createTest(userCredentials.owner.getEmail(), getNameWithoutExtension(testYamlPath), testYaml);
    final var testRun = test.createTestRun(templateParams);
    testRun.setCreatedAt(new Date());
    final var outputDir = useUniqueOutputDir ? rootOutputDir.resolve(Paths.get(testRun.getTestName(), testRun.getTestRunId().toString())) : rootOutputDir;
    if (Files.exists(outputDir) && (!Files.isDirectory(outputDir) || Exceptions.getUncheckedIO(() -> Files.list(outputDir).findAny().isPresent()))) {
        throw new UserError("%s should either not exist, or be an existing empty directory", outputDir);
    }
    final var loggers = new JobFileLoggers(outputDir, true, userCredentials);
    final var scratchSpace = new TestRunScratchSpaceFactory(outputDir).createGlobal();
    final var persistedTestRun = new AtomicallyPersistedTestRun(testRun, testRun_ -> writeTestRunJsonAtomically(testRun_, scratchSpace.getPath(), outputDir));
    final var stateStorage = new TestRunStateStorage(persistedTestRun, loggers.getShared(), () -> Exceptions.getUncheckedIO(() -> Artifacts.findTestRunArtifacts(outputDir)));
    final var testRunStatusUpdater = new TestRunAbortedStatusUpdater(stateStorage);
    testRunStatusUpdater.setCurrentState(TestRun.State.PREPARING_RUN);
    ActiveTestRun activeTestRun;
    try {
        try {
            activeTestRun = ActiveTestRunBuilder.create().withFalloutConfiguration(configuration).withTestDefinitionFromYaml(testRun.getExpandedDefinition()).withUserCredentials(userCredentials).withTestRunArtifactPath(outputDir).withTestRunStatusUpdater(testRunStatusUpdater).withLoggers(loggers).withTestRunScratchSpace(scratchSpace).withTestRunIdentifier(testRun.getTestRunIdentifier()).withTestRun(testRun).build();
        } catch (Exception e) {
            loggers.getShared().error("Exception building the ActiveTestRun", e);
            testRunStatusUpdater.markFailedWithReason(TestRun.State.FAILED);
            testRunStatusUpdater.markInactive(Optional.empty());
            throw e;
        }
        persistedTestRun.update(testRun_ -> testRun_.setResourceRequirements(activeTestRun.getResourceRequirements()));
        activeTestRun.run((message, ex) -> {
            System.err.printf("ERROR: %s\n%s", message, ex.getMessage());
        });
        // passing it to io.dropwizard.Application#onFatalError, which will call System.exit(1).
        if (stateStorage.getCurrentState() != TestRun.State.PASSED) {
            throw new TestRunFailedError();
        }
    } finally {
        ClojureShutdown.shutdown();
    }
}
Also used : JobFileLoggers(com.datastax.fallout.ops.JobFileLoggers) TestRunAbortedStatusUpdater(com.datastax.fallout.harness.TestRunAbortedStatusUpdater) TestRunScratchSpaceFactory(com.datastax.fallout.ops.TestRunScratchSpaceFactory) AtomicallyPersistedTestRun(com.datastax.fallout.runner.AtomicallyPersistedTestRun) ActiveTestRun(com.datastax.fallout.harness.ActiveTestRun) TestRunStateStorage(com.datastax.fallout.runner.TestRunStateStorage) Date(java.util.Date)

Example 2 with TestRunScratchSpaceFactory

use of com.datastax.fallout.ops.TestRunScratchSpaceFactory in project fallout by datastax.

the class FalloutValidateCommand method run.

private void run(Validator validator, FC configuration, Path testYamlPath, Map<String, Object> templateParams, Path credsYamlPath) {
    final var testYaml = readString(testYamlPath);
    final var userCredentials = parseUserCredentials(validator, credsYamlPath);
    final var test = Test.createTest(userCredentials.owner.getEmail(), getNameWithoutExtension(testYamlPath), testYaml);
    final var testRun = test.createTestRun(templateParams);
    testRun.setCreatedAt(new Date());
    final var loggers = new JobConsoleLoggers();
    final var outputDir = Exceptions.getUncheckedIO(() -> Files.createTempDirectory("fallout-validation"));
    final var scratchSpace = new TestRunScratchSpaceFactory(outputDir).createGlobal();
    final var stateStorage = new InMemoryTestRunStateStorage(TestRun.State.PREPARING_RUN);
    final var testRunStatusUpdater = new TestRunAbortedStatusUpdater(stateStorage);
    try {
        ActiveTestRunBuilder.create().withFalloutConfiguration(configuration).withTestDefinitionFromYaml(testRun.getExpandedDefinition()).withUserCredentials(userCredentials).withTestRunArtifactPath(outputDir).withTestRunStatusUpdater(testRunStatusUpdater).withLoggers(loggers).withTestRunScratchSpace(scratchSpace).withTestRunIdentifier(testRun.getTestRunIdentifier()).withTestRun(testRun).build();
    } finally {
        ClojureShutdown.shutdown();
        Exceptions.runUncheckedIO(() -> MoreFiles.deleteRecursively(outputDir, RecursiveDeleteOption.ALLOW_INSECURE));
    }
}
Also used : TestRunAbortedStatusUpdater(com.datastax.fallout.harness.TestRunAbortedStatusUpdater) InMemoryTestRunStateStorage(com.datastax.fallout.harness.InMemoryTestRunStateStorage) JobConsoleLoggers(com.datastax.fallout.ops.JobConsoleLoggers) TestRunScratchSpaceFactory(com.datastax.fallout.ops.TestRunScratchSpaceFactory) Date(java.util.Date)

Aggregations

TestRunAbortedStatusUpdater (com.datastax.fallout.harness.TestRunAbortedStatusUpdater)2 TestRunScratchSpaceFactory (com.datastax.fallout.ops.TestRunScratchSpaceFactory)2 Date (java.util.Date)2 ActiveTestRun (com.datastax.fallout.harness.ActiveTestRun)1 InMemoryTestRunStateStorage (com.datastax.fallout.harness.InMemoryTestRunStateStorage)1 JobConsoleLoggers (com.datastax.fallout.ops.JobConsoleLoggers)1 JobFileLoggers (com.datastax.fallout.ops.JobFileLoggers)1 AtomicallyPersistedTestRun (com.datastax.fallout.runner.AtomicallyPersistedTestRun)1 TestRunStateStorage (com.datastax.fallout.runner.TestRunStateStorage)1