Search in sources :

Example 1 with CheckResourcesResult

use of com.datastax.fallout.runner.CheckResourcesResult in project fallout by datastax.

the class ActiveTestRunTransitionTest method nodeGroupBuilder.

private NodeGroupBuilder nodeGroupBuilder(Optional<NodeGroup.State> launchState, CheckResourcesResult createResult) {
    WritablePropertyGroup pg = new WritablePropertyGroup();
    launchState.ifPresent(ls -> pg.put(FalloutPropertySpecs.launchRunLevelPropertySpec.name(), ls));
    return NodeGroupBuilder.create().withProvisioner(new FakeProvisioner() {

        @Override
        protected CheckResourcesResult createImpl(NodeGroup nodeGroup) {
            return createResult;
        }
    }).withConfigurationManager(new FakeConfigurationManager()).withPropertyGroup(pg).withNodeCount(1).withName(NODE_GROUP_NAME);
}
Also used : FakeProvisioner(com.datastax.fallout.components.fakes.FakeProvisioner) CheckResourcesResult(com.datastax.fallout.runner.CheckResourcesResult) WritablePropertyGroup(com.datastax.fallout.ops.WritablePropertyGroup) FakeConfigurationManager(com.datastax.fallout.components.fakes.FakeConfigurationManager) NodeGroup(com.datastax.fallout.ops.NodeGroup)

Example 2 with CheckResourcesResult

use of com.datastax.fallout.runner.CheckResourcesResult in project fallout by datastax.

the class ActiveTestRun method transitionEnsembleStateUpwards.

private CheckResourcesResult transitionEnsembleStateUpwards(Optional<NodeGroup.State> maximumState, TestRun.State testRunState, String stage) {
    CheckResourcesResult transitionResult = CheckResourcesResult.FAILED;
    setTestRunState(testRunState);
    try {
        transitionResult = transitionEnsembleStateUpwards(maximumState);
        failTestIfCheckResourcesDidNotSucceed(transitionResult, stage);
    } catch (Exception e) {
        failTest("Error " + stage + " ensemble for test run", e);
    }
    return transitionResult;
}
Also used : CheckResourcesResult(com.datastax.fallout.runner.CheckResourcesResult) InvalidConfigurationException(com.datastax.fallout.exceptions.InvalidConfigurationException) IOException(java.io.IOException)

Example 3 with CheckResourcesResult

use of com.datastax.fallout.runner.CheckResourcesResult in project fallout by datastax.

the class ActiveTestRun method transitionEnsembleStateUpwards.

private CheckResourcesResult transitionEnsembleStateUpwards(Optional<NodeGroup.State> maximumState) {
    List<CompletableFuture<CheckResourcesResult>> futures = new ArrayList<>();
    for (NodeGroup nodeGroup : ensemble.getUniqueNodeGroupInstances()) {
        NodeGroup.State requiredState = FalloutPropertySpecs.launchRunLevelPropertySpec.value(nodeGroup);
        requiredState = NodeGroup.State.values()[Math.min(maximumState.orElse(requiredState).ordinal(), requiredState.ordinal())];
        futures.add(nodeGroup.transitionStateIfUpwards(requiredState));
    }
    CompletableFuture.allOf(futures.toArray(new CompletableFuture[] {})).join();
    return futures.stream().map(CompletableFuture::join).reduce(CheckResourcesResult.AVAILABLE, CheckResourcesResult::worstCase);
}
Also used : CheckResourcesResult(com.datastax.fallout.runner.CheckResourcesResult) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) NodeGroup(com.datastax.fallout.ops.NodeGroup)

Example 4 with CheckResourcesResult

use of com.datastax.fallout.runner.CheckResourcesResult in project fallout by datastax.

the class ActiveTestRun method doSetup.

private CheckResourcesResult doSetup() {
    try {
        logger.info("Setting up ensemble before beginning jepsen test");
        if (!ensemble.createAllLocalFiles()) {
            return CheckResourcesResult.FAILED;
        }
        // Check states and kick off any post-check-state actions.
        final List<CompletableFuture<Boolean>> postCheckStateActions = ensemble.getUniqueNodeGroupInstances().stream().map(NodeGroup::checkState).map(CompletableFuture::join).map(postCheckStateAction -> CompletableFuture.supplyAsync(postCheckStateAction::getAsBoolean)).toList();
        return transitionEnsembleStateUpwards(Optional.of(NodeGroup.State.RESERVED), TestRun.State.RESERVING_RESOURCES, "reserving").ifSuccessful(() -> transitionEnsembleStateUpwards(Optional.of(NodeGroup.State.CREATED), TestRun.State.ACQUIRING_RESOURCES, "acquiring")).ifSuccessful(() -> transitionEnsembleStateUpwards(Optional.of(NodeGroup.State.STARTED_SERVICES_CONFIGURED), TestRun.State.SETTING_UP, "setting up")).ifSuccessful(() -> CheckResourcesResult.fromWasSuccessful(postSetupHook.apply(ensemble))).ifSuccessful(() -> CheckResourcesResult.fromWasSuccessful(Utils.waitForAll(postCheckStateActions, logger, "post check-state actions"))).ifSuccessful(() -> transitionEnsembleStateUpwards(Optional.empty(), TestRun.State.SETTING_UP, "setting up"));
    } finally {
        // Summarize ensemble info to aid post-hoc debugging
        String downloadPath = testRunArtifactPath.toAbsolutePath().toString();
        Path ensembleSummary = Paths.get(downloadPath, "ensemble-summary.json");
        HashMap<String, Object> ensembleInfo = new HashMap<>();
        DebugInfoProvidingComponent.InfoConsumer infoConsumer = ensembleInfo::put;
        infoConsumer.accept("fallout_version", FalloutVersion.getVersion());
        ensemble.summarizeInfo(infoConsumer);
        try {
            ObjectWriter writer = new ObjectMapper().writerWithDefaultPrettyPrinter();
            writer.writeValue(ensembleSummary.toFile(), ensembleInfo);
        } catch (IOException e) {
            logger.warn("Error writing summaryInfo to file", e);
        }
    }
}
Also used : MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestRunScratchSpace(com.datastax.fallout.ops.TestRunScratchSpaceFactory.TestRunScratchSpace) CheckResourcesResult(com.datastax.fallout.runner.CheckResourcesResult) TestRun(com.datastax.fallout.service.core.TestRun) Function(java.util.function.Function) Supplier(java.util.function.Supplier) FalloutVersion(com.datastax.fallout.FalloutVersion) ArrayList(java.util.ArrayList) InvalidConfigurationException(com.datastax.fallout.exceptions.InvalidConfigurationException) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Ensemble(com.datastax.fallout.ops.Ensemble) ResourceRequirement(com.datastax.fallout.ops.ResourceRequirement) Path(java.nio.file.Path) DebugInfoProvidingComponent(com.datastax.fallout.ops.DebugInfoProvidingComponent) Provider(com.datastax.fallout.ops.Provider) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Utils(com.datastax.fallout.ops.Utils) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) FalloutPropertySpecs(com.datastax.fallout.ops.FalloutPropertySpecs) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Optional(java.util.Optional) NodeGroup(com.datastax.fallout.ops.NodeGroup) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PropertySpec(com.datastax.fallout.ops.PropertySpec) Path(java.nio.file.Path) HashMap(java.util.HashMap) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) DebugInfoProvidingComponent(com.datastax.fallout.ops.DebugInfoProvidingComponent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

CheckResourcesResult (com.datastax.fallout.runner.CheckResourcesResult)4 NodeGroup (com.datastax.fallout.ops.NodeGroup)3 InvalidConfigurationException (com.datastax.fallout.exceptions.InvalidConfigurationException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 FalloutVersion (com.datastax.fallout.FalloutVersion)1 FakeConfigurationManager (com.datastax.fallout.components.fakes.FakeConfigurationManager)1 FakeProvisioner (com.datastax.fallout.components.fakes.FakeProvisioner)1 DebugInfoProvidingComponent (com.datastax.fallout.ops.DebugInfoProvidingComponent)1 Ensemble (com.datastax.fallout.ops.Ensemble)1 FalloutPropertySpecs (com.datastax.fallout.ops.FalloutPropertySpecs)1 PropertySpec (com.datastax.fallout.ops.PropertySpec)1 Provider (com.datastax.fallout.ops.Provider)1 ResourceRequirement (com.datastax.fallout.ops.ResourceRequirement)1 TestRunScratchSpace (com.datastax.fallout.ops.TestRunScratchSpaceFactory.TestRunScratchSpace)1 Utils (com.datastax.fallout.ops.Utils)1 WritablePropertyGroup (com.datastax.fallout.ops.WritablePropertyGroup)1 TestRun (com.datastax.fallout.service.core.TestRun)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1