Search in sources :

Example 1 with ProblemSet

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet in project halyard by spinnaker.

the class DaemonTaskHandler method reduceChildren.

public static <U, T> DaemonResponse<U> reduceChildren(U base, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner) {
    DaemonTask task = getTask();
    if (task != null) {
        U responseBody = base;
        ProblemSet problemSet = new ProblemSet();
        DaemonResponse<U> response = new DaemonResponse<>(responseBody, problemSet);
        return (DaemonResponse) task.getChildren().stream().reduce(response, (o, t) -> {
            DaemonResponse<U> collector = (DaemonResponse<U>) o;
            DaemonTask child = (DaemonTask) t;
            DaemonResponse<T> childResponse;
            try {
                childResponse = task.reapChild(child);
            } catch (InterruptedException e) {
                throw new DaemonTaskInterrupted("Interrupted during reap", e);
            }
            DaemonTask.State state = child.getState();
            if (!state.isTerminal()) {
                throw new IllegalStateException("Child task " + child + " reaped but non-terminal.");
            }
            switch(state) {
                case FAILED:
                    throw new HalException(childResponse.getProblemSet().getProblems());
                case INTERRUPTED:
                    task.interrupt();
                    throw new DaemonTaskInterrupted(child.getFatalError());
                case TIMED_OUT:
                    task.timeout();
                    throw new DaemonTaskInterrupted("Child task timed out");
                case SUCCEEDED:
                    break;
                default:
                    throw new IllegalStateException("Unknown terminal state " + state);
            }
            collector.getProblemSet().addAll(childResponse.getProblemSet());
            collector.setResponseBody(accumulator.apply(collector.getResponseBody(), childResponse.getResponseBody()));
            return collector;
        }, (Object o1, Object o2) -> {
            DaemonResponse<U> r1 = (DaemonResponse<U>) o1;
            DaemonResponse<U> r2 = (DaemonResponse<U>) o2;
            r1.setResponseBody(combiner.apply(r1.getResponseBody(), r2.getResponseBody()));
            r1.getProblemSet().addAll(r2.getProblemSet());
            return r1;
        });
    } else {
        throw new IllegalStateException("You must be running a DaemonTask to reduce child tasks");
    }
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) JobExecutor(com.netflix.spinnaker.halyard.core.job.v1.JobExecutor) BiFunction(java.util.function.BiFunction) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) DaemonLocalJobExecutor(com.netflix.spinnaker.halyard.core.job.v1.DaemonLocalJobExecutor) Supplier(java.util.function.Supplier) BinaryOperator(java.util.function.BinaryOperator) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)

Example 2 with ProblemSet

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet in project halyard by spinnaker.

the class ArtifactProviderController method setEnabled.

@RequestMapping(value = "/{providerName:.+}/enabled", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setEnabled(@PathVariable String deploymentName, @PathVariable String providerName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody boolean enabled) {
    UpdateRequestBuilder builder = new UpdateRequestBuilder();
    builder.setUpdate(() -> providerService.setEnabled(deploymentName, providerName, enabled));
    builder.setSeverity(severity);
    Supplier<ProblemSet> doValidate = ProblemSet::new;
    if (validate) {
        doValidate = () -> providerService.validateArtifactProvider(deploymentName, providerName);
    }
    builder.setValidate(doValidate);
    builder.setRevert(() -> halconfigParser.undoChanges());
    builder.setSave(() -> halconfigParser.saveConfig());
    return DaemonTaskHandler.submitTask(builder::build, "Edit the " + providerName + " provider");
}
Also used : UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ProblemSet

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet in project halyard by spinnaker.

the class BakeryController method setBakeryDefaults.

@RequestMapping(value = "/defaults/", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setBakeryDefaults(@PathVariable String deploymentName, @PathVariable String providerName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawBakeryDefaults) {
    BakeryDefaults bakeryDefaults = objectMapper.convertValue(rawBakeryDefaults, Providers.translateBakeryDefaultsType(providerName));
    UpdateRequestBuilder builder = new UpdateRequestBuilder();
    Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
    builder.setStage(() -> bakeryDefaults.stageLocalFiles(configPath));
    builder.setUpdate(() -> bakeryService.setBakeryDefaults(deploymentName, providerName, bakeryDefaults));
    builder.setSeverity(severity);
    Supplier<ProblemSet> doValidate = ProblemSet::new;
    if (validate) {
        doValidate = () -> bakeryService.validateBakeryDefaults(deploymentName, providerName);
    }
    builder.setValidate(doValidate);
    builder.setRevert(() -> halconfigParser.undoChanges());
    builder.setSave(() -> halconfigParser.saveConfig());
    builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
    return DaemonTaskHandler.submitTask(builder::build, "Edit " + providerName + " bakery defaults");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) BakeryDefaults(com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ProblemSet

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet in project halyard by spinnaker.

the class BakeryController method setBaseImage.

@RequestMapping(value = "/defaults/baseImage/{baseImageId:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setBaseImage(@PathVariable String deploymentName, @PathVariable String providerName, @PathVariable String baseImageId, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawBaseImage) {
    BaseImage baseImage = objectMapper.convertValue(rawBaseImage, Providers.translateBaseImageType(providerName));
    UpdateRequestBuilder builder = new UpdateRequestBuilder();
    Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
    builder.setStage(() -> baseImage.stageLocalFiles(configPath));
    builder.setUpdate(() -> bakeryService.setBaseImage(deploymentName, providerName, baseImageId, baseImage));
    builder.setSeverity(severity);
    Supplier<ProblemSet> doValidate = ProblemSet::new;
    if (validate) {
        doValidate = () -> bakeryService.validateBaseImage(deploymentName, providerName, baseImage.getBaseImage().getId());
    }
    builder.setValidate(doValidate);
    builder.setRevert(() -> halconfigParser.undoChanges());
    builder.setSave(() -> halconfigParser.saveConfig());
    builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
    return DaemonTaskHandler.submitTask(builder::build, "Edit " + baseImageId + " base image");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) BaseImage(com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ProblemSet

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet in project halyard by spinnaker.

the class CiController method setEnabled.

@RequestMapping(value = "/{ciName:.+}/enabled", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setEnabled(@PathVariable String deploymentName, @PathVariable String ciName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody boolean enabled) {
    UpdateRequestBuilder builder = new UpdateRequestBuilder();
    builder.setUpdate(() -> ciService.setEnabled(deploymentName, ciName, enabled));
    builder.setSeverity(severity);
    Supplier<ProblemSet> doValidate = ProblemSet::new;
    if (validate) {
        doValidate = () -> ciService.validateCi(deploymentName, ciName);
    }
    builder.setValidate(doValidate);
    builder.setRevert(() -> halconfigParser.undoChanges());
    builder.setSave(() -> halconfigParser.saveConfig());
    return DaemonTaskHandler.submitTask(builder::build, "Edit " + ciName + " settings");
}
Also used : UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)54 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)50 Path (java.nio.file.Path)37 DaemonResponse (com.netflix.spinnaker.halyard.core.DaemonResponse)3 AbstractCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount)2 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)2 ArtifactAccount (com.netflix.spinnaker.halyard.config.model.v1.node.ArtifactAccount)2 BaseImage (com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage)2 Cluster (com.netflix.spinnaker.halyard.config.model.v1.node.Cluster)2 Master (com.netflix.spinnaker.halyard.config.model.v1.node.Master)2 Subscription (com.netflix.spinnaker.halyard.config.model.v1.node.Subscription)2 ApiSecurity (com.netflix.spinnaker.halyard.config.model.v1.security.ApiSecurity)2 UiSecurity (com.netflix.spinnaker.halyard.config.model.v1.security.UiSecurity)2 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)2 Canary (com.netflix.spinnaker.halyard.config.model.v1.canary.Canary)1 ArtifactProvider (com.netflix.spinnaker.halyard.config.model.v1.node.ArtifactProvider)1 BakeryDefaults (com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 DeploymentEnvironment (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment)1