Search in sources :

Example 1 with Canary

use of com.netflix.spinnaker.halyard.config.model.v1.canary.Canary in project halyard by spinnaker.

the class AbstractEditCanaryAccountCommand method executeThis.

@Override
protected void executeThis() {
    String accountName = getAccountName();
    String serviceIntegration = getServiceIntegration();
    String currentDeployment = getCurrentDeployment();
    // Disable validation here, since we don't want an illegal config to prevent us from fixing it.
    AbstractCanaryAccount account = new OperationHandler<AbstractCanaryAccount>().setFailureMesssage("Failed to get canary account " + accountName + " for service integration " + serviceIntegration + ".").setOperation(Daemon.getCanaryAccount(currentDeployment, serviceIntegration.toLowerCase(), accountName, false)).get();
    int originaHash = account.hashCode();
    account = editAccount((T) account);
    if (originaHash == account.hashCode()) {
        AnsiUi.failure("No changes supplied.");
        return;
    }
    new OperationHandler<Void>().setFailureMesssage("Failed to edit canary account " + accountName + " for service integration " + serviceIntegration + ".").setSuccessMessage("Successfully edited canary account " + accountName + " for service integration " + serviceIntegration + ".").setOperation(Daemon.setCanaryAccount(currentDeployment, serviceIntegration.toLowerCase(), accountName, !noValidate, account)).get();
}
Also used : AbstractCanaryAccount(com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 2 with Canary

use of com.netflix.spinnaker.halyard.config.model.v1.canary.Canary in project halyard by spinnaker.

the class CanaryController method setCanaryAccount.

@RequestMapping(value = "/{serviceIntegrationName:.+}/accounts/account/{accountName:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setCanaryAccount(@PathVariable String deploymentName, @PathVariable String serviceIntegrationName, @PathVariable String accountName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawCanaryAccount) {
    AbstractCanaryAccount canaryAccount = objectMapper.convertValue(rawCanaryAccount, Canary.translateCanaryAccountType(serviceIntegrationName));
    UpdateRequestBuilder builder = new UpdateRequestBuilder();
    Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
    builder.setStage(() -> canaryAccount.stageLocalFiles(configPath));
    builder.setUpdate(() -> canaryAccountService.setAccount(deploymentName, serviceIntegrationName, accountName, canaryAccount));
    builder.setSeverity(severity);
    Supplier<ProblemSet> doValidate = ProblemSet::new;
    if (validate) {
        doValidate = () -> canaryService.validateCanary(deploymentName);
    }
    builder.setValidate(doValidate);
    builder.setRevert(() -> halconfigParser.undoChanges());
    builder.setSave(() -> halconfigParser.saveConfig());
    builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
    return DaemonTaskHandler.submitTask(builder::build, "Edit the " + accountName + " canary account");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) AbstractCanaryAccount(com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Canary

use of com.netflix.spinnaker.halyard.config.model.v1.canary.Canary in project halyard by spinnaker.

the class CanaryController method addCanaryAccount.

@RequestMapping(value = "/{serviceIntegrationName:.+}/accounts/", method = RequestMethod.POST)
DaemonTask<Halconfig, Void> addCanaryAccount(@PathVariable String deploymentName, @PathVariable String serviceIntegrationName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawCanaryAccount) {
    AbstractCanaryAccount canaryAccount = objectMapper.convertValue(rawCanaryAccount, Canary.translateCanaryAccountType(serviceIntegrationName));
    UpdateRequestBuilder builder = new UpdateRequestBuilder();
    Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
    builder.setStage(() -> canaryAccount.stageLocalFiles(configPath));
    builder.setSeverity(severity);
    builder.setUpdate(() -> canaryAccountService.addAccount(deploymentName, serviceIntegrationName, canaryAccount));
    Supplier<ProblemSet> doValidate = ProblemSet::new;
    if (validate) {
        doValidate = () -> canaryService.validateCanary(deploymentName);
    }
    builder.setValidate(doValidate);
    builder.setRevert(() -> halconfigParser.undoChanges());
    builder.setSave(() -> halconfigParser.saveConfig());
    builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
    return DaemonTaskHandler.submitTask(builder::build, "Add the " + canaryAccount.getName() + " canary account to " + serviceIntegrationName + " service integration");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) AbstractCanaryAccount(com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Canary

use of com.netflix.spinnaker.halyard.config.model.v1.canary.Canary in project halyard by spinnaker.

the class CanaryController method setCanary.

@RequestMapping(value = "/", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setCanary(@PathVariable String deploymentName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawCanary) {
    Canary canary = objectMapper.convertValue(rawCanary, Canary.class);
    UpdateRequestBuilder builder = new UpdateRequestBuilder();
    Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
    builder.setStage(() -> canary.stageLocalFiles(configPath));
    builder.setSeverity(severity);
    builder.setUpdate(() -> canaryService.setCanary(deploymentName, canary));
    builder.setValidate(ProblemSet::new);
    if (validate) {
        builder.setValidate(() -> canaryService.validateCanary(deploymentName));
    }
    builder.setRevert(() -> halconfigParser.undoChanges());
    builder.setSave(() -> halconfigParser.saveConfig());
    builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
    return DaemonTaskHandler.submitTask(builder::build, "Edit canary analysis settings");
}
Also used : Path(java.nio.file.Path) Canary(com.netflix.spinnaker.halyard.config.model.v1.canary.Canary) 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 5 with Canary

use of com.netflix.spinnaker.halyard.config.model.v1.canary.Canary in project halyard by spinnaker.

the class CanaryAccountService method deleteAccount.

public void deleteAccount(String deploymentName, String serviceIntegrationName, String accountName) {
    AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName);
    boolean removed = serviceIntegration.getAccounts().removeIf(account -> ((AbstractCanaryAccount) account).getName().equals(accountName));
    if (!removed) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Canary account \"" + accountName + "\" wasn't found").build());
    }
}
Also used : AbstractCanaryServiceIntegration(com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryServiceIntegration) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) AbstractCanaryAccount(com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount)

Aggregations

Canary (com.netflix.spinnaker.halyard.config.model.v1.canary.Canary)10 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)7 AbstractCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount)6 AbstractCanaryServiceIntegration (com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryServiceIntegration)3 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)3 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)3 Path (java.nio.file.Path)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 AwsCanaryServiceIntegration (com.netflix.spinnaker.halyard.config.model.v1.canary.aws.AwsCanaryServiceIntegration)2 GoogleCanaryServiceIntegration (com.netflix.spinnaker.halyard.config.model.v1.canary.google.GoogleCanaryServiceIntegration)2 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)2 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)1 IllegalConfigException (com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException)1 AwsCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.aws.AwsCanaryAccount)1 DatadogCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.datadog.DatadogCanaryAccount)1 GoogleCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.google.GoogleCanaryAccount)1 PrometheusCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.prometheus.PrometheusCanaryAccount)1 PrometheusCanaryServiceIntegration (com.netflix.spinnaker.halyard.config.model.v1.canary.prometheus.PrometheusCanaryServiceIntegration)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 Features (com.netflix.spinnaker.halyard.config.model.v1.node.Features)1