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");
}
}
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");
}
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");
}
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");
}
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");
}
Aggregations