protected CreateChildContainerOptions.Builder createAutoScaleOptions( AutoScaleRequest request, FabricService fabricService) { CreateChildContainerOptions.Builder builder = CreateChildContainerOptions.builder(); Container[] containers = fabricService.getContainers(); if (containers != null) { List<String> containerIds = Containers.rootContainerIds(containers); // allow the requirements to customise which root to use... if (containerIds.isEmpty()) { throw new IllegalStateException("No root containers are available!"); } String rootContainer = null; if (containerIds.size() == 1) { rootContainer = containerIds.get(0); } else { rootContainer = chooseRootContainer(request, containerIds); } if (Strings.isNullOrBlank(rootContainer)) { throw new IllegalStateException( "Could not choose a root container from the possible IDs: " + containerIds + " with requirements: " + getChildScalingRequirements(request)); } else { builder = builder.parent(rootContainer); } } String zookeeperUrl = fabricService.getZookeeperUrl(); String zookeeperPassword = fabricService.getZookeeperPassword(); return builder .jmxUser("admin") .jmxPassword(zookeeperPassword) .zookeeperUrl(zookeeperUrl) .zookeeperPassword(zookeeperPassword); }
/** * Creates the environment variables for the given container options using the profiles specified * in the options to figure out what environment variables to use. */ public static Map<String, String> getEnvironmentVariables( FabricService service, CreateContainerBasicOptions options) { Set<String> profileIds = options.getProfiles(); String versionId = options.getVersion(); String zookeeperUrl = service.getZookeeperUrl(); String zookeeperUser = service.getZooKeeperUser(); String zookeeperPasswordRaw = service.getZookeeperPassword(); String zookeeperPassword = zookeeperPasswordRaw; if (zookeeperPassword != null) { zookeeperPassword = PasswordEncoder.encode(zookeeperPassword); } String localIp = service.getCurrentContainer().getLocalIp(); if (!Strings.isNullOrBlank(localIp)) { int idx = zookeeperUrl.lastIndexOf(':'); if (idx > 0) { localIp += zookeeperUrl.substring(idx); } zookeeperUrl = localIp; } Map<String, String> envVarsOverlay = Profiles.getOverlayConfiguration( service, profileIds, versionId, EnvironmentVariables.ENVIRONMENT_VARIABLES_PID); String containerName = options.getName(); envVarsOverlay.put(EnvironmentVariables.KARAF_NAME, containerName); envVarsOverlay.put(EnvironmentVariables.CONTAINER_NAME, containerName); if (!options.isEnsembleServer()) { if (!envVarsOverlay.containsKey(EnvironmentVariables.ZOOKEEPER_URL)) { envVarsOverlay.put(EnvironmentVariables.ZOOKEEPER_URL, zookeeperUrl); } if (!envVarsOverlay.containsKey(EnvironmentVariables.ZOOKEEPER_USER)) { envVarsOverlay.put(EnvironmentVariables.ZOOKEEPER_USER, zookeeperUser); } if (!envVarsOverlay.containsKey(EnvironmentVariables.ZOOKEEPER_PASSWORD)) { envVarsOverlay.put(EnvironmentVariables.ZOOKEEPER_PASSWORD, zookeeperPassword); } if (!envVarsOverlay.containsKey(EnvironmentVariables.ZOOKEEPER_PASSWORD_RAW)) { envVarsOverlay.put(EnvironmentVariables.ZOOKEEPER_PASSWORD_RAW, zookeeperPasswordRaw); } if (!envVarsOverlay.containsKey(EnvironmentVariables.ZOOKEEPER_PASSWORD_ENCODE)) { String zkPasswordEncode = System.getProperty("zookeeper.password.encode", "true"); envVarsOverlay.put(EnvironmentVariables.ZOOKEEPER_PASSWORD_ENCODE, zkPasswordEncode); } } return envVarsOverlay; }