@Test public void testWithAttribs() throws IOException { Configuration conf = new PropertiesConfiguration(); conf.setProperty("puppet.nginx.module", "git: conf.setProperty("nginx.server.hostname", "foohost"); CreateSitePpAndApplyRoles nginx = new CreateSitePpAndApplyRoles(ImmutableSet.of("nginx::server"), ImmutableSet.of(new Cluster.Instance( new Credentials("dummy", "dummy"), Sets.newHashSet("puppet:nginx::server"), "127.0.0.1", "127.0.0.1", "id-1", null)), conf); assertEquals(CharStreams.toString(Resources.newReaderSupplier(Resources.getResource("nginx-with-attribs.txt"), Charsets.UTF_8)), nginx.render(OsFamily.UNIX)); }
@Override public String render(OsFamily arg0) { Boolean isHiera = config.getBoolean(PUPPET_HIERA_CLASSES, false); Builder<Statement> statements = ImmutableList.<Statement> builder(); statements.add(Statements.rm(SITE_PP_FILE_LOCATION)); statements.add(Statements.rm(CONF_PP_FILE_LOCATION)); statements.add(Statements.rm(HIERA_COMMON_FILE_LOCATION)); Builder<String> sitePp = ImmutableList.<String> builder(); Map<String, Set<String>> puppetRoles = Maps.newHashMap(); for (Cluster.Instance instance : instances) { for (String role : instance.getRoles()) { int firstColon = role.indexOf(':'); if (firstColon != -1 && role.substring(0, firstColon).equals(PUPPET)) { String puppetClass = role.substring(firstColon + 1); if (!puppetRoles.containsKey(puppetClass)) { puppetRoles.put(puppetClass, Sets.<String>newHashSet()); } puppetRoles.get(puppetClass).add(instance.getPrivateIp()); } } } Builder<String> confPp = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confPp.add(puppetClass + "," + Joiner.on(',').join(puppetRoles.get(puppetClass))); } Builder<String> confHiera = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confHiera.add(puppetClass + ":\n - " + Joiner.on("\n - ").join(puppetRoles.get(puppetClass))); } sitePp.add("$extlookup_datadir='/etc/puppet/manifests/extdata'"); sitePp.add("$extlookup_precedence = ['common']"); sitePp.add("node default {"); for (String role : roles) { String manifestAttribPrefix = role.replaceAll(":+", "."); Configuration manifestProps = new PropertiesConfiguration(); for (@SuppressWarnings("unchecked") Iterator<String> it = config.getKeys(manifestAttribPrefix); it.hasNext();) { String key = it.next(); manifestProps.setProperty(key, config.getProperty(key)); } Manifest roleManifest = getManifestForClusterSpecAndRole(role, manifestProps); if (isHiera) { sitePp.add("include " + roleManifest.getName()); confHiera.add(roleManifest.getHiera()); } else { sitePp.add(roleManifest.toString()); } } sitePp.add("}"); if (isHiera) { Builder<String> confPuppetHiera = ImmutableList.<String> builder(); confPuppetHiera.add("---", ":backends:", " - yaml", ":yaml:", " :datadir: /etc/puppet/hieradata", ":hierarchy:", " - common"); statements.add(createOrOverwriteFile(HIERA_CONF_FILE_LOCATION, confPuppetHiera.build())); statements.add(exec("mkdir -p /etc/puppet/hieradata")); } statements.add(createOrOverwriteFile(HIERA_COMMON_FILE_LOCATION, confHiera.build())); statements.add(createOrOverwriteFile(CONF_PP_FILE_LOCATION, confPp.build())); statements.add(createOrOverwriteFile(SITE_PP_FILE_LOCATION, sitePp.build())); statements.add(exec("puppet apply " + SITE_PP_FILE_LOCATION)); return new StatementList(statements.build()).render(arg0); }
CreateSitePpAndApplyRoles implements Statement { @Override public String render(OsFamily arg0) { Boolean isHiera = config.getBoolean(PUPPET_HIERA_CLASSES, false); Builder<Statement> statements = ImmutableList.<Statement> builder(); statements.add(Statements.rm(SITE_PP_FILE_LOCATION)); statements.add(Statements.rm(CONF_PP_FILE_LOCATION)); statements.add(Statements.rm(HIERA_COMMON_FILE_LOCATION)); Builder<String> sitePp = ImmutableList.<String> builder(); Map<String, Set<String>> puppetRoles = Maps.newHashMap(); for (Cluster.Instance instance : instances) { for (String role : instance.getRoles()) { int firstColon = role.indexOf(':'); if (firstColon != -1 && role.substring(0, firstColon).equals(PUPPET)) { String puppetClass = role.substring(firstColon + 1); if (!puppetRoles.containsKey(puppetClass)) { puppetRoles.put(puppetClass, Sets.<String>newHashSet()); } puppetRoles.get(puppetClass).add(instance.getPrivateIp()); } } } Builder<String> confPp = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confPp.add(puppetClass + "," + Joiner.on(',').join(puppetRoles.get(puppetClass))); } Builder<String> confHiera = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confHiera.add(puppetClass + ":\n - " + Joiner.on("\n - ").join(puppetRoles.get(puppetClass))); } sitePp.add("$extlookup_datadir='/etc/puppet/manifests/extdata'"); sitePp.add("$extlookup_precedence = ['common']"); sitePp.add("node default {"); for (String role : roles) { String manifestAttribPrefix = role.replaceAll(":+", "."); Configuration manifestProps = new PropertiesConfiguration(); for (@SuppressWarnings("unchecked") Iterator<String> it = config.getKeys(manifestAttribPrefix); it.hasNext();) { String key = it.next(); manifestProps.setProperty(key, config.getProperty(key)); } Manifest roleManifest = getManifestForClusterSpecAndRole(role, manifestProps); if (isHiera) { sitePp.add("include " + roleManifest.getName()); confHiera.add(roleManifest.getHiera()); } else { sitePp.add(roleManifest.toString()); } } sitePp.add("}"); if (isHiera) { Builder<String> confPuppetHiera = ImmutableList.<String> builder(); confPuppetHiera.add("---", ":backends:", " - yaml", ":yaml:", " :datadir: /etc/puppet/hieradata", ":hierarchy:", " - common"); statements.add(createOrOverwriteFile(HIERA_CONF_FILE_LOCATION, confPuppetHiera.build())); statements.add(exec("mkdir -p /etc/puppet/hieradata")); } statements.add(createOrOverwriteFile(HIERA_COMMON_FILE_LOCATION, confHiera.build())); statements.add(createOrOverwriteFile(CONF_PP_FILE_LOCATION, confPp.build())); statements.add(createOrOverwriteFile(SITE_PP_FILE_LOCATION, sitePp.build())); statements.add(exec("puppet apply " + SITE_PP_FILE_LOCATION)); return new StatementList(statements.build()).render(arg0); } }
CreateSitePpAndApplyRoles implements Statement { @Override public String render(OsFamily arg0) { Boolean isHiera = config.getBoolean(PUPPET_HIERA_CLASSES, false); Builder<Statement> statements = ImmutableList.<Statement> builder(); statements.add(Statements.rm(SITE_PP_FILE_LOCATION)); statements.add(Statements.rm(CONF_PP_FILE_LOCATION)); statements.add(Statements.rm(HIERA_COMMON_FILE_LOCATION)); Builder<String> sitePp = ImmutableList.<String> builder(); Map<String, Set<String>> puppetRoles = Maps.newHashMap(); for (Cluster.Instance instance : instances) { for (String role : instance.getRoles()) { int firstColon = role.indexOf(':'); if (firstColon != -1 && role.substring(0, firstColon).equals(PUPPET)) { String puppetClass = role.substring(firstColon + 1); if (!puppetRoles.containsKey(puppetClass)) { puppetRoles.put(puppetClass, Sets.<String>newHashSet()); } puppetRoles.get(puppetClass).add(instance.getPrivateIp()); } } } Builder<String> confPp = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confPp.add(puppetClass + "," + Joiner.on(',').join(puppetRoles.get(puppetClass))); } Builder<String> confHiera = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confHiera.add(puppetClass + ":\n - " + Joiner.on("\n - ").join(puppetRoles.get(puppetClass))); } sitePp.add("$extlookup_datadir='/etc/puppet/manifests/extdata'"); sitePp.add("$extlookup_precedence = ['common']"); sitePp.add("node default {"); for (String role : roles) { String manifestAttribPrefix = role.replaceAll(":+", "."); Configuration manifestProps = new PropertiesConfiguration(); for (@SuppressWarnings("unchecked") Iterator<String> it = config.getKeys(manifestAttribPrefix); it.hasNext();) { String key = it.next(); manifestProps.setProperty(key, config.getProperty(key)); } Manifest roleManifest = getManifestForClusterSpecAndRole(role, manifestProps); if (isHiera) { sitePp.add("include " + roleManifest.getName()); confHiera.add(roleManifest.getHiera()); } else { sitePp.add(roleManifest.toString()); } } sitePp.add("}"); if (isHiera) { Builder<String> confPuppetHiera = ImmutableList.<String> builder(); confPuppetHiera.add("---", ":backends:", " - yaml", ":yaml:", " :datadir: /etc/puppet/hieradata", ":hierarchy:", " - common"); statements.add(createOrOverwriteFile(HIERA_CONF_FILE_LOCATION, confPuppetHiera.build())); statements.add(exec("mkdir -p /etc/puppet/hieradata")); } statements.add(createOrOverwriteFile(HIERA_COMMON_FILE_LOCATION, confHiera.build())); statements.add(createOrOverwriteFile(CONF_PP_FILE_LOCATION, confPp.build())); statements.add(createOrOverwriteFile(SITE_PP_FILE_LOCATION, sitePp.build())); statements.add(exec("puppet apply " + SITE_PP_FILE_LOCATION)); return new StatementList(statements.build()).render(arg0); } CreateSitePpAndApplyRoles(Iterable<String> roles, Iterable<Cluster.Instance> instances, Configuration config); }
CreateSitePpAndApplyRoles implements Statement { @Override public String render(OsFamily arg0) { Boolean isHiera = config.getBoolean(PUPPET_HIERA_CLASSES, false); Builder<Statement> statements = ImmutableList.<Statement> builder(); statements.add(Statements.rm(SITE_PP_FILE_LOCATION)); statements.add(Statements.rm(CONF_PP_FILE_LOCATION)); statements.add(Statements.rm(HIERA_COMMON_FILE_LOCATION)); Builder<String> sitePp = ImmutableList.<String> builder(); Map<String, Set<String>> puppetRoles = Maps.newHashMap(); for (Cluster.Instance instance : instances) { for (String role : instance.getRoles()) { int firstColon = role.indexOf(':'); if (firstColon != -1 && role.substring(0, firstColon).equals(PUPPET)) { String puppetClass = role.substring(firstColon + 1); if (!puppetRoles.containsKey(puppetClass)) { puppetRoles.put(puppetClass, Sets.<String>newHashSet()); } puppetRoles.get(puppetClass).add(instance.getPrivateIp()); } } } Builder<String> confPp = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confPp.add(puppetClass + "," + Joiner.on(',').join(puppetRoles.get(puppetClass))); } Builder<String> confHiera = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confHiera.add(puppetClass + ":\n - " + Joiner.on("\n - ").join(puppetRoles.get(puppetClass))); } sitePp.add("$extlookup_datadir='/etc/puppet/manifests/extdata'"); sitePp.add("$extlookup_precedence = ['common']"); sitePp.add("node default {"); for (String role : roles) { String manifestAttribPrefix = role.replaceAll(":+", "."); Configuration manifestProps = new PropertiesConfiguration(); for (@SuppressWarnings("unchecked") Iterator<String> it = config.getKeys(manifestAttribPrefix); it.hasNext();) { String key = it.next(); manifestProps.setProperty(key, config.getProperty(key)); } Manifest roleManifest = getManifestForClusterSpecAndRole(role, manifestProps); if (isHiera) { sitePp.add("include " + roleManifest.getName()); confHiera.add(roleManifest.getHiera()); } else { sitePp.add(roleManifest.toString()); } } sitePp.add("}"); if (isHiera) { Builder<String> confPuppetHiera = ImmutableList.<String> builder(); confPuppetHiera.add("---", ":backends:", " - yaml", ":yaml:", " :datadir: /etc/puppet/hieradata", ":hierarchy:", " - common"); statements.add(createOrOverwriteFile(HIERA_CONF_FILE_LOCATION, confPuppetHiera.build())); statements.add(exec("mkdir -p /etc/puppet/hieradata")); } statements.add(createOrOverwriteFile(HIERA_COMMON_FILE_LOCATION, confHiera.build())); statements.add(createOrOverwriteFile(CONF_PP_FILE_LOCATION, confPp.build())); statements.add(createOrOverwriteFile(SITE_PP_FILE_LOCATION, sitePp.build())); statements.add(exec("puppet apply " + SITE_PP_FILE_LOCATION)); return new StatementList(statements.build()).render(arg0); } CreateSitePpAndApplyRoles(Iterable<String> roles, Iterable<Cluster.Instance> instances, Configuration config); @Override Iterable<String> functionDependencies(OsFamily arg0); @Override String render(OsFamily arg0); }
CreateSitePpAndApplyRoles implements Statement { @Override public String render(OsFamily arg0) { Boolean isHiera = config.getBoolean(PUPPET_HIERA_CLASSES, false); Builder<Statement> statements = ImmutableList.<Statement> builder(); statements.add(Statements.rm(SITE_PP_FILE_LOCATION)); statements.add(Statements.rm(CONF_PP_FILE_LOCATION)); statements.add(Statements.rm(HIERA_COMMON_FILE_LOCATION)); Builder<String> sitePp = ImmutableList.<String> builder(); Map<String, Set<String>> puppetRoles = Maps.newHashMap(); for (Cluster.Instance instance : instances) { for (String role : instance.getRoles()) { int firstColon = role.indexOf(':'); if (firstColon != -1 && role.substring(0, firstColon).equals(PUPPET)) { String puppetClass = role.substring(firstColon + 1); if (!puppetRoles.containsKey(puppetClass)) { puppetRoles.put(puppetClass, Sets.<String>newHashSet()); } puppetRoles.get(puppetClass).add(instance.getPrivateIp()); } } } Builder<String> confPp = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confPp.add(puppetClass + "," + Joiner.on(',').join(puppetRoles.get(puppetClass))); } Builder<String> confHiera = ImmutableList.<String> builder(); for (String puppetClass : puppetRoles.keySet()) { confHiera.add(puppetClass + ":\n - " + Joiner.on("\n - ").join(puppetRoles.get(puppetClass))); } sitePp.add("$extlookup_datadir='/etc/puppet/manifests/extdata'"); sitePp.add("$extlookup_precedence = ['common']"); sitePp.add("node default {"); for (String role : roles) { String manifestAttribPrefix = role.replaceAll(":+", "."); Configuration manifestProps = new PropertiesConfiguration(); for (@SuppressWarnings("unchecked") Iterator<String> it = config.getKeys(manifestAttribPrefix); it.hasNext();) { String key = it.next(); manifestProps.setProperty(key, config.getProperty(key)); } Manifest roleManifest = getManifestForClusterSpecAndRole(role, manifestProps); if (isHiera) { sitePp.add("include " + roleManifest.getName()); confHiera.add(roleManifest.getHiera()); } else { sitePp.add(roleManifest.toString()); } } sitePp.add("}"); if (isHiera) { Builder<String> confPuppetHiera = ImmutableList.<String> builder(); confPuppetHiera.add("---", ":backends:", " - yaml", ":yaml:", " :datadir: /etc/puppet/hieradata", ":hierarchy:", " - common"); statements.add(createOrOverwriteFile(HIERA_CONF_FILE_LOCATION, confPuppetHiera.build())); statements.add(exec("mkdir -p /etc/puppet/hieradata")); } statements.add(createOrOverwriteFile(HIERA_COMMON_FILE_LOCATION, confHiera.build())); statements.add(createOrOverwriteFile(CONF_PP_FILE_LOCATION, confPp.build())); statements.add(createOrOverwriteFile(SITE_PP_FILE_LOCATION, sitePp.build())); statements.add(exec("puppet apply " + SITE_PP_FILE_LOCATION)); return new StatementList(statements.build()).render(arg0); } CreateSitePpAndApplyRoles(Iterable<String> roles, Iterable<Cluster.Instance> instances, Configuration config); @Override Iterable<String> functionDependencies(OsFamily arg0); @Override String render(OsFamily arg0);  }