@Override public String getNodeName() { return getName(); }
public void setAccount(String deploymentName, String serviceIntegrationName, String accountName, AbstractCanaryAccount newAccount) { AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName); for (int i = 0; i < serviceIntegration.getAccounts().size(); i++) { AbstractCanaryAccount account = (AbstractCanaryAccount)serviceIntegration.getAccounts().get(i); if (account.getNodeName().equals(accountName)) { serviceIntegration.getAccounts().set(i, newAccount); return; } } throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Canary account \"" + accountName + "\" wasn't found").build()); }
public static String format(AbstractCanaryAccount account) { AnsiStoryBuilder resultBuilder = new AnsiStoryBuilder(); AnsiParagraphBuilder paragraph = resultBuilder.addParagraph(); paragraph.addSnippet(account.getNodeName().toUpperCase()).addStyle(AnsiStyle.BOLD); resultBuilder.addNewline(); paragraph = resultBuilder.addParagraph(); paragraph.addSnippet(account.toString()); return resultBuilder.toString(); }
@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(); } }
public void setAccount(String deploymentName, String serviceIntegrationName, String accountName, AbstractCanaryAccount newAccount) { AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName); for (int i = 0; i < serviceIntegration.getAccounts().size(); i++) { AbstractCanaryAccount account = (AbstractCanaryAccount)serviceIntegration.getAccounts().get(i); if (account.getNodeName().equals(accountName)) { serviceIntegration.getAccounts().set(i, newAccount); return; } } throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Canary account \"" + accountName + "\" wasn't found").build()); }
@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(); } }
@Override public String getNodeName() { return getName(); }
@Override public void validate(ConfigProblemSetBuilder p, AbstractCanaryAccount n) { super.validate(p, n); PrometheusCanaryAccount canaryAccount = (PrometheusCanaryAccount)n; DaemonTaskHandler.message("Validating " + n.getNodeName() + " with " + PrometheusCanaryAccountValidator.class.getSimpleName()); String usernamePasswordFile = canaryAccount.getUsernamePasswordFile(); if (StringUtils.isNotEmpty(usernamePasswordFile)) { String usernamePassword = ValidatingFileReader.contents(p, usernamePasswordFile); if (Strings.isNullOrEmpty(usernamePassword)) { p.addProblem(ERROR, "The supplied username password file does not exist or is empty.") .setRemediation("Supply a valid username password file."); } else if (!usernamePassword.contains(":")) { p.addProblem(ERROR, "The supplied username password file does not contain a ':'.") .setRemediation("Supply a username password file containing \"username:password\"."); } } } }
@Override public void validate(ConfigProblemSetBuilder p, AbstractCanaryAccount n) { if (n.getName() == null) { p.addProblem(Severity.FATAL, "Canary account name must be specified"); } else if (!Pattern.matches(namePattern, n.getName())) { p.addProblem(Severity.ERROR, "Canary account name must match pattern " + namePattern) .setRemediation("It must start and end with a lower-case character or number, and only contain lower-case characters, numbers, dashes, or underscores"); } } }
@Override public void validate(ConfigProblemSetBuilder p, AbstractCanaryAccount n) { super.validate(p, n); GoogleCanaryAccount canaryAccount = (GoogleCanaryAccount)n; DaemonTaskHandler.message("Validating " + n.getNodeName() + " with " + GoogleCanaryAccountValidator.class.getSimpleName()); GoogleNamedAccountCredentials credentials = canaryAccount.getNamedAccountCredentials(halyardVersion, p); if (credentials == null) { return; } try { Compute compute = credentials.getCompute(); compute.projects().get(canaryAccount.getProject()).execute(); } catch (IOException e) { p.addProblem(Severity.ERROR, "Failed to load project \"" + canaryAccount.getProject() + "\": " + e.getMessage() + "."); } } }
@Override public void validate(ConfigProblemSetBuilder p, AbstractCanaryAccount n) { if (n.getName() == null) { p.addProblem(Severity.FATAL, "Canary account name must be specified"); } else if (!Pattern.matches(namePattern, n.getName())) { p.addProblem(Severity.ERROR, "Canary account name must match pattern " + namePattern) .setRemediation("It must start and end with a lower-case character or number, and only contain lower-case characters, numbers, dashes, or underscores"); } } }
DaemonTaskHandler.message("Validating " + n.getNodeName() + " with " + GoogleCanaryAccountValidator.class.getSimpleName());
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()); } }
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()); } }
@RequestMapping(value = "/{serviceIntegrationName:.+}/accounts/", method = RequestMethod.POST) DaemonTask<Halconfig, Void> addCanaryAccount(@PathVariable String deploymentName, @PathVariable String serviceIntegrationName, @ModelAttribute ValidationSettings validationSettings, @RequestBody Object rawCanaryAccount) { AbstractCanaryAccount canaryAccount = objectMapper.convertValue( rawCanaryAccount, Canary.translateCanaryAccountType(serviceIntegrationName) ); return GenericUpdateRequest.<AbstractCanaryAccount>builder(halconfigParser) .stagePath(halconfigDirectoryStructure.getStagingPath(deploymentName)) .updater(c -> canaryAccountService.addAccount(deploymentName, serviceIntegrationName, c)) .validator(() -> canaryService.validateCanary(deploymentName)) .description("Add the " + canaryAccount.getName() + " canary account to " + serviceIntegrationName + " service integration") .build() .execute(validationSettings, canaryAccount); }
public AbstractCanaryAccount getCanaryAccount(String deploymentName, String serviceIntegrationName, String accountName) { AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName); List<AbstractCanaryAccount> matchingAccounts = (List<AbstractCanaryAccount>)serviceIntegration.getAccounts() .stream() .filter(a -> (((AbstractCanaryAccount)a).getName().equals(accountName))) .collect(Collectors.toList()); switch (matchingAccounts.size()) { case 0: throw new ConfigNotFoundException(new ConfigProblemBuilder( Severity.FATAL, "No account with name \"" + accountName + "\" was found") .setRemediation("Check if this account was defined in another service integration, or create a new one").build()); case 1: return matchingAccounts.get(0); default: throw new IllegalConfigException(new ConfigProblemBuilder( Severity.FATAL, "More than one account named \"" + accountName + "\" was found") .setRemediation("Manually delete/rename duplicate canary accounts with name \"" + accountName + "\" in your halconfig file").build()); } }
public AbstractCanaryAccount getCanaryAccount(String deploymentName, String serviceIntegrationName, String accountName) { AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName); List<AbstractCanaryAccount> matchingAccounts = (List<AbstractCanaryAccount>)serviceIntegration.getAccounts() .stream() .filter(a -> (((AbstractCanaryAccount)a).getName().equals(accountName))) .collect(Collectors.toList()); switch (matchingAccounts.size()) { case 0: throw new ConfigNotFoundException(new ConfigProblemBuilder( Severity.FATAL, "No account with name \"" + accountName + "\" was found") .setRemediation("Check if this account was defined in another service integration, or create a new one").build()); case 1: return matchingAccounts.get(0); default: throw new IllegalConfigException(new ConfigProblemBuilder( Severity.FATAL, "More than one account named \"" + accountName + "\" was found") .setRemediation("Manually delete/rename duplicate canary accounts with name \"" + accountName + "\" in your halconfig file").build()); } }
@Override protected void executeThis() { AbstractCanaryServiceIntegration serviceIntegration = CanaryUtils.getServiceIntegrationByName(null, getCurrentDeployment(), getServiceIntegration(), noValidate); List<AbstractCanaryAccount> accounts = serviceIntegration.getAccounts(); if (accounts.isEmpty()) { AnsiUi.success("No configured accounts for " + getServiceIntegration() + "."); } else { AnsiUi.success("Accounts for " + getServiceIntegration() + ":"); accounts.forEach(account -> AnsiUi.listItem(account.getName())); } } }
@Override protected void executeThis() { AbstractCanaryServiceIntegration serviceIntegration = CanaryUtils.getServiceIntegrationByName(null, getCurrentDeployment(), getServiceIntegration(), noValidate); List<AbstractCanaryAccount> accounts = serviceIntegration.getAccounts(); if (accounts.isEmpty()) { AnsiUi.success("No configured accounts for " + getServiceIntegration() + "."); } else { AnsiUi.success("Accounts for " + getServiceIntegration() + ":"); accounts.forEach(account -> AnsiUi.listItem(account.getName())); } } }