@Override public String getNodeName() { return getName(); }
@Override public String getNodeName() { return getName(); }
@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) { 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"); } } }
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())); } } }