/** * Creates a name for a new container given the current list of containers and the profile name. * For a profile of "foo" then this method tries to create a name of the form "foo1" or "foo2" * based on how many containers there are and if the name already exists. */ public static String createContainerName(Container[] containers, String profile, String scheme, NameValidator nameValidator) { Map<String, Container> map = new HashMap<String, Container>(); for (Container container : containers) { map.put(container.getId(), container); } String postFix = "." + scheme; String namePrefix = profile; if (namePrefix.endsWith(postFix)) { namePrefix = namePrefix.substring(0, namePrefix.length() - postFix.length()); } // lets filter out non-alpha namePrefix = filterOutNonAlphaNumerics(namePrefix); List<Container> profileContainers = containersForProfile(containers, profile); int idx = profileContainers.size(); while (true) { String name = namePrefix + Integer.toString(++idx); if (!map.containsKey(name) && nameValidator.isValid(name)) { return name; } } }
/** * Creates a name for a new container given the current list of containers and the profile name. * For a profile of "foo" then this method tries to create a name of the form "foo1" or "foo2" * based on how many containers there are and if the name already exists. */ public static String createAutoScaleContainerName(Container[] containers, String profile, String scheme, NameValidator nameValidator) { Map<String, Container> map = new HashMap<String, Container>(); for (Container container : containers) { map.put(container.getId(), container); } String postFix = "." + scheme; String namePrefix = profile; if (namePrefix.endsWith(postFix)) { namePrefix = namePrefix.substring(0, namePrefix.length() - postFix.length()); } // lets filter out non-alpha namePrefix = filterOutNonAlphaNumerics(namePrefix); namePrefix = "auto_"+namePrefix; List<Container> profileContainers = containersForProfile(containers, profile); int idx = profileContainers.size(); while (true) { String name = namePrefix + Integer.toString(++idx); if (!map.containsKey(name) && nameValidator.isValid(name)) { return name; } } }