public Versions getVersions() { try { return profileRegistry.readVersions(); } catch (IOException e) { throw new HalException( new ConfigProblemBuilder(FATAL, "Could not load \"versions.yml\" from config bucket: " + e.getMessage() + ".").build()); } }
public ConfigProblemBuilder addProblem(Severity severity, String message, String field) { ConfigProblemBuilder problemBuilder = new ConfigProblemBuilder(severity, message); if (node != null) { problemBuilder.setNode(node); if (field != null && !field.isEmpty()) { problemBuilder.setOptions(node.fieldOptions(new ConfigProblemSetBuilder(context), field)); } } builders.add(problemBuilder); return problemBuilder; }
private BaseImage getBaseImage(NodeFilter filter, String baseImageName) { List<BaseImage> matchingBaseImages = lookupService.getMatchingNodesOfType(filter, BaseImage.class); switch (matchingBaseImages.size()) { case 0: throw new ConfigNotFoundException(new ConfigProblemBuilder( Severity.FATAL, "No base image with name \"" + baseImageName + "\" was found") .setRemediation("Check if this base image was defined in another provider, or create a new one").build()); case 1: return matchingBaseImages.get(0); default: throw new IllegalConfigException(new ConfigProblemBuilder( Severity.FATAL, "More than one base image named \"" + baseImageName + "\" was found") .setRemediation("Manually delete/rename duplicate base images with name \"" + baseImageName + "\" in your halconfig file").build()); } }
public static String contents(ConfigProblemSetBuilder ps, String path) { String noAccessRemediation = "Halyard is running as user " + System.getProperty("user.name") + ". Make sure that user can read the requested file."; try { return IOUtils.toString(new FileInputStream(path)); } catch (FileNotFoundException e) { ConfigProblemBuilder problemBuilder = ps.addProblem(Problem.Severity.FATAL, "Cannot find provided path: " + e.getMessage() + "."); if (e.getMessage().contains("denied")) { problemBuilder.setRemediation(noAccessRemediation); } return null; } catch (IOException e) { ConfigProblemBuilder problemBuilder = ps.addProblem(Problem.Severity.FATAL, "Failed to read path \"" + path + "\": " + e.getMessage() + "."); if (e.getMessage().contains("denied")) { problemBuilder.setRemediation(noAccessRemediation); } return null; } } }
public ConfigProblemSetBuilder extend(HalException e) { e.getProblems() .getProblems() .forEach(p -> addProblem(p.getSeverity(), p.getMessage()) .setOptions(p.getOptions()) .setRemediation(p.getRemediation()) ); return this; }
public static String contents(ConfigProblemSetBuilder ps, String path) { String noAccessRemediation = "Halyard is running as user " + System.getProperty("user.name") + ". Make sure that user can read the requested file."; try { return IOUtils.toString(new FileInputStream(path)); } catch (FileNotFoundException e) { ConfigProblemBuilder problemBuilder = ps.addProblem(Problem.Severity.FATAL, "Cannot find provided path: " + e.getMessage() + "."); if (e.getMessage().contains("denied")) { problemBuilder.setRemediation(noAccessRemediation); } return null; } catch (IOException e) { ConfigProblemBuilder problemBuilder = ps.addProblem(Problem.Severity.FATAL, "Failed to read path \"" + path + "\": " + e.getMessage() + "."); if (e.getMessage().contains("denied")) { problemBuilder.setRemediation(noAccessRemediation); } return null; } } }
public ConfigProblemSetBuilder extend(HalException e) { e.getProblems() .getProblems() .forEach(p -> addProblem(p.getSeverity(), p.getMessage()) .setOptions(p.getOptions()) .setRemediation(p.getRemediation()) ); return this; }
public void setArtifactTemplate(String deploymentName, String artifactTemplateName, ArtifactTemplate newArtifactTemplate) { List<ArtifactTemplate> artifactTemplates = getAllArtifactTemplates(deploymentName); for (int i = 0; i < artifactTemplates.size(); i++) { if (artifactTemplates.get(i).getNodeName().equals(artifactTemplateName)) { artifactTemplates.set(i, newArtifactTemplate); return; } } throw new HalException(new ConfigProblemBuilder(Problem.Severity.FATAL, "Artifact template \"" + artifactTemplateName + "\" wasn't found").build()); }
private Cluster getCluster(NodeFilter filter, String clusterName) { List<Cluster> matchingClusters = lookupService.getMatchingNodesOfType(filter, Cluster.class); switch (matchingClusters.size()) { case 0: throw new ConfigNotFoundException(new ConfigProblemBuilder( Problem.Severity.FATAL, "No cluster with name \"" + clusterName + "\" was found") .setRemediation("Check if this cluster was defined in another provider, or create a new one").build()); case 1: return matchingClusters.get(0); default: throw new IllegalConfigException(new ConfigProblemBuilder( Problem.Severity.FATAL, "More than one cluster named \"" + clusterName + "\" was found") .setRemediation("Manually delete/rename duplicate clusters with name \"" + clusterName + "\" in your halconfig file").build()); } }
public ConfigProblemBuilder addProblem(Severity severity, String message, String field) { ConfigProblemBuilder problemBuilder = new ConfigProblemBuilder(severity, message); if (node != null) { problemBuilder.setNode(node); if (field != null && !field.isEmpty()) { problemBuilder.setOptions(node.fieldOptions(new ConfigProblemSetBuilder(context), field)); } } builders.add(problemBuilder); return problemBuilder; }
@Override public void validate(ConfigProblemSetBuilder p, DeploymentConfiguration n) { String timezone = n.getTimezone(); if (Arrays.stream(TimeZone.getAvailableIDs()).noneMatch(t -> t.equals(timezone))) { p.addProblem(Problem.Severity.ERROR, "Timezone " + timezone + " does not match any known canonical timezone ID") .setRemediation("Pick a timezone from those listed here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones"); } }
accountClusters.removeAll(definedClusters); accountClusters.forEach(c -> problems.addProblem(ERROR, "Cluster \"" + c.toString() + "\" not defined for provider") .setRemediation("Add cluster to the provider or remove from the account") .setOptions(Lists.newArrayList(definedClusters))); problems.addProblem(ERROR, "Account contains duplicate credentials for cluster \"" + c.getName() + "\" and user id \"" + c.getUid() + "\".").setRemediation("Remove the duplicate credentials"); } else { credentials.add(key); problems.addProblem(WARNING, "Account has no password or service key. Unless the cluster has security disabled this may be an error") .setRemediation("Add a password or service key."); .setRemediation("Remove either the password or service key."); .setRemediation("Supply a valid service key file.");
public String getCurrentDeployment() { String result = getConfig().getCurrentDeployment(); if (result == null || result.isEmpty()) { throw new IllegalConfigException( new ConfigProblemBuilder(Severity.FATAL, "No deployment has been set").build() ); } return result; }
private ArtifactAccount getArtifactAccount(NodeFilter filter, String accountName) { List<ArtifactAccount> matchingArtifactAccounts = lookupService.getMatchingNodesOfType(filter, ArtifactAccount.class); switch (matchingArtifactAccounts.size()) { case 0: throw new ConfigNotFoundException(new ConfigProblemBuilder( Severity.FATAL, "No account with name \"" + accountName + "\" was found") .setRemediation("Check if this artifact account was defined in another provider, or create a new one").build()); case 1: return matchingArtifactAccounts.get(0); default: throw new IllegalConfigException(new ConfigProblemBuilder( Severity.FATAL, "More than one account named \"" + accountName + "\" was found") .setRemediation("Manually delete/rename duplicate artifact accounts with name \"" + accountName + "\" in your halconfig file").build()); } }
@Override public void validate(ConfigProblemSetBuilder p, DeploymentConfiguration n) { String timezone = n.getTimezone(); if (Arrays.stream(TimeZone.getAvailableIDs()).noneMatch(t -> t.equals(timezone))) { p.addProblem(Problem.Severity.ERROR, "Timezone " + timezone + " does not match any known canonical timezone ID") .setRemediation("Pick a timezone from those listed here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones"); } }
accountClusters.removeAll(definedClusters); accountClusters.forEach(c -> problems.addProblem(ERROR, "Cluster \"" + c.toString() + "\" not defined for provider") .setRemediation("Add cluster to the provider or remove from the account") .setOptions(Lists.newArrayList(definedClusters))); problems.addProblem(ERROR, "Account contains duplicate credentials for cluster \"" + c.getName() + "\" and user id \"" + c.getUid() + "\".").setRemediation("Remove the duplicate credentials"); } else { credentials.add(key); problems.addProblem(WARNING, "Account has no password or service key. Unless the cluster has security disabled this may be an error") .setRemediation("Add a password or service key."); .setRemediation("Remove either the password or service key."); .setRemediation("Supply a valid service key file.");
public String getCurrentDeployment() { String result = getConfig().getCurrentDeployment(); if (result == null || result.isEmpty()) { throw new IllegalConfigException( new ConfigProblemBuilder(Severity.FATAL, "No deployment has been set").build() ); } return result; }
private Master getMaster(NodeFilter filter, String masterName) { List<Master> matchingMasters = lookupService.getMatchingNodesOfType(filter, Master.class); switch (matchingMasters.size()) { case 0: throw new ConfigNotFoundException(new ConfigProblemBuilder( Severity.FATAL, "No master with name \"" + masterName + "\" was found") .setRemediation("Check if this master was defined in another Continuous Integration service, or create a new one").build()); case 1: return matchingMasters.get(0); default: throw new IllegalConfigException(new ConfigProblemBuilder( Severity.FATAL, "More than one master named \"" + masterName + "\" was found") .setRemediation("Manually delete/rename duplicate masters with name \"" + masterName + "\" in your halconfig file").build()); } }
private void validateGitDeployment(ConfigProblemSetBuilder p, DeploymentEnvironment n) { if (StringUtils.isEmpty(n.getGitConfig().getOriginUser())) { p.addProblem(Problem.Severity.FATAL, "A git origin user must be supplied when deploying from git.") .setRemediation("Your github username is recommended."); } if (StringUtils.isEmpty(n.getGitConfig().getUpstreamUser())) { p.addProblem(Problem.Severity.FATAL, "A git upstream user must be supplied when deploying from git.") .setRemediation("The user 'spinnaker' is recommended (unless you have a fork maintained by the org you develop under)."); } }
public ParseConfigException(IllegalArgumentException e) { Problem problem = new ConfigProblemBuilder(Problem.Severity.FATAL, "Could not translate your halconfig: " + e.getMessage()).build(); getProblems().add(problem); } }