public void addAccount(String deploymentName, String serviceIntegrationName, AbstractCanaryAccount newCanaryAccount) { AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName); serviceIntegration.getAccounts().add(newCanaryAccount); }
@Override public String getNodeName() { return getName(); }
for (AbstractCanaryAccount account : (List<AbstractCanaryAccount>)svc.getAccounts()) { if (accounts.contains(account.getName())) { p.addProblem(Problem.Severity.FATAL, "Canary account \"" + account.getName() + "\" appears more than once.") .setRemediation("Change the name of the account in " + svc.getNodeName() + " service integration"); } else { accounts.add(account.getName());
@Override protected void executeThis() { String currentDeployment = getCurrentDeployment(); // Disable validation here, since we don't want an illegal config to prevent us from fixing it. Canary canary = new OperationHandler<Canary>() .setFailureMesssage("Failed to get canary.") .setOperation(Daemon.getCanary(currentDeployment, false)) .get(); int originalHash = canary.hashCode(); AbstractCanaryServiceIntegration canaryServiceIntegration = CanaryUtils.getServiceIntegrationByName(canary, currentDeployment, getName(), true); canaryServiceIntegration.setEnabled(isEnable()); if (originalHash == canary.hashCode()) { AnsiUi.failure("No changes supplied."); return; } new OperationHandler<Void>() .setSuccessMessage("Successfully " + indicativePastPerfectAction() + " canary analysis " + getName() + " service integration.") .setFailureMesssage("Failed to " + getCommandName() + " canary analysis " + getName() + " service integration.") .setOperation(Daemon.setCanary(currentDeployment, !noValidate, canary)) .get(); } }
for (AbstractCanaryAccount account : (List<AbstractCanaryAccount>)svc.getAccounts()) { if (accounts.contains(account.getName())) { p.addProblem(Problem.Severity.FATAL, "Canary account \"" + account.getName() + "\" appears more than once.") .setRemediation("Change the name of the account in " + svc.getNodeName() + " service integration"); } else { accounts.add(account.getName());
@Override protected void executeThis() { String currentDeployment = getCurrentDeployment(); // Disable validation here, since we don't want an illegal config to prevent us from fixing it. Canary canary = new OperationHandler<Canary>() .setFailureMesssage("Failed to get canary.") .setOperation(Daemon.getCanary(currentDeployment, false)) .get(); int originalHash = canary.hashCode(); AbstractCanaryServiceIntegration canaryServiceIntegration = CanaryUtils.getServiceIntegrationByName(canary, currentDeployment, getName(), true); canaryServiceIntegration.setEnabled(isEnable()); if (originalHash == canary.hashCode()) { AnsiUi.failure("No changes supplied."); return; } new OperationHandler<Void>() .setSuccessMessage("Successfully " + indicativePastPerfectAction() + " canary analysis " + getName() + " service integration.") .setFailureMesssage("Failed to " + getCommandName() + " canary analysis " + getName() + " service integration.") .setOperation(Daemon.setCanary(currentDeployment, !noValidate, canary)) .get(); } }
public void addAccount(String deploymentName, String serviceIntegrationName, AbstractCanaryAccount newCanaryAccount) { AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName); serviceIntegration.getAccounts().add(newCanaryAccount); }
@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()); }
private AbstractCanaryServiceIntegration getServiceIntegration(String deploymentName, String serviceIntegrationName) { Canary canary = canaryService.getCanary(deploymentName); return canary.getServiceIntegrations() .stream() .filter(s -> s.getName().equals(serviceIntegrationName)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Canary service integration " + serviceIntegrationName + " not found.")); }
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()); }
private AbstractCanaryServiceIntegration getServiceIntegration(String deploymentName, String serviceIntegrationName) { Canary canary = canaryService.getCanary(deploymentName); return canary.getServiceIntegrations() .stream() .filter(s -> s.getName().equals(serviceIntegrationName)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Canary service integration " + serviceIntegrationName + " not found.")); }
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 static AbstractCanaryServiceIntegration getServiceIntegrationByName(Canary canary, String currentDeployment, String serviceIntegrationName, boolean noValidate) { if (canary == null) { canary = new OperationHandler<Canary>() .setFailureMesssage("Failed to get canary.") .setOperation(Daemon.getCanary(currentDeployment, !noValidate)) .get(); } return canary.getServiceIntegrations() .stream() .filter(s -> s.getName().equals(serviceIntegrationName.toLowerCase())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Canary service integration " + serviceIntegrationName + " not found.")); } }
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 static AbstractCanaryServiceIntegration getServiceIntegrationByName(Canary canary, String currentDeployment, String serviceIntegrationName, boolean noValidate) { if (canary == null) { canary = new OperationHandler<Canary>() .setFailureMesssage("Failed to get canary.") .setOperation(Daemon.getCanary(currentDeployment, !noValidate)) .get(); } return canary.getServiceIntegrations() .stream() .filter(s -> s.getName().equals(serviceIntegrationName.toLowerCase())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Canary service integration " + serviceIntegrationName + " not found.")); } }
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())); } } }