private ConfigValues loadConfigValues(File file) { ConfigValues configValues = new ConfigValues(); try { configValues.setRaw(new String(Files.readAllBytes(file.toPath()), "UTF-8")); } catch (IOException e) { throw new SkipperException("Could read values file " + file.getAbsoluteFile(), e); } return configValues; }
public ConfigValues getConfigValues() { if (configValues == null) { return new ConfigValues(); } else { return configValues; } }
public ConfigValues getConfigValues() { if (configValues == null) { return new ConfigValues(); } else { return configValues; } }
private ConfigValues loadConfigValues(File file) { ConfigValues configValues = new ConfigValues(); try { configValues.setRaw(new String(Files.readAllBytes(file.toPath()), "UTF-8")); } catch (IOException e) { throw new SkipperException("Could read values file " + file.getAbsoluteFile(), e); } return configValues; }
installProperties.setPlatformName(platformName); installProperties.setReleaseName(streamName); installProperties.setConfigValues(new ConfigValues()); installRequest.setInstallProperties(installProperties); Release release = null;
@PostLoad public void afterLoad() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { this.pkg = mapper.readValue(this.pkgJsonString, Package.class); this.configValues = new ConfigValues(); if (this.configValuesString != null && StringUtils.hasText(configValuesString)) { this.configValues.setRaw(this.configValuesString); } } catch (IOException e) { throw new SkipperException("Error processing config values", e); } } }
installProperties.setPlatformName(platformName); installProperties.setReleaseName(streamName); installProperties.setConfigValues(new ConfigValues()); installRequest.setInstallProperties(installProperties); Release release = null;
private Map<String, Object> getConfigValuesAsMap(ConfigValues configValues) { Yaml yaml = new Yaml(); if (StringUtils.hasText(configValues.getRaw())) { Object data = yaml.load(configValues.getRaw()); if (data instanceof Map) { return (Map<String, Object>) yaml.load(configValues.getRaw()); } else { throw new SkipperException("Was expecting override values to produce a Map, instead got class = " + data.getClass() + "overrideValues.getRaw() = " + configValues.getRaw()); } } return null; }
@PostLoad public void afterLoad() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { this.pkg = mapper.readValue(this.pkgJsonString, Package.class); this.configValues = new ConfigValues(); if (this.configValuesString != null && StringUtils.hasText(configValuesString)) { this.configValues.setRaw(this.configValuesString); } } catch (IOException e) { throw new SkipperException("Error processing config values", e); } } }
private Map<String, Object> getConfigValuesAsMap(ConfigValues configValues) { Yaml yaml = new Yaml(); if (StringUtils.hasText(configValues.getRaw())) { Object data = yaml.load(configValues.getRaw()); if (data instanceof Map) { return (Map<String, Object>) yaml.load(configValues.getRaw()); } else { throw new SkipperException("Was expecting override values to produce a Map, instead got class = " + data.getClass() + "overrideValues.getRaw() = " + configValues.getRaw()); } } return null; }
private InstallProperties getInstallProperties(String releaseName, String platformName, File yamlFile, String propertiesToOverride) throws IOException { InstallProperties installProperties = new InstallProperties(); if (StringUtils.hasText(releaseName)) { installProperties.setReleaseName(releaseName); } // There is a 'default' value for platformName installProperties.setPlatformName(platformName); String configValuesYML = YmlUtils.getYamlConfigValues(yamlFile, propertiesToOverride); if (StringUtils.hasText(configValuesYML)) { ConfigValues configValues = new ConfigValues(); configValues.setRaw(configValuesYML); installProperties.setConfigValues(configValues); } return installProperties; }
private static Map<String, Object> convertConfigValuesToMap(Package pkg) { Yaml yaml = new Yaml(); Map<String, Object> currentPackageValueMap = new TreeMap<>(); if (pkg.getConfigValues() != null && StringUtils.hasText(pkg.getConfigValues().getRaw())) { currentPackageValueMap = (Map<String, Object>) yaml.load(pkg.getConfigValues().getRaw()); } if (currentPackageValueMap == null) { currentPackageValueMap = new TreeMap<>(); } return currentPackageValueMap; }
private Release updateReplacingReleaseConfigValues(Release targetRelease, Release replacingRelease) { Map<String, Object> targetConfigValueMap = getConfigValuesAsMap(targetRelease.getConfigValues()); Map<String, Object> replacingRelaseConfigValueMap = getConfigValuesAsMap(replacingRelease.getConfigValues()); if (targetConfigValueMap != null && replacingRelaseConfigValueMap != null) { ConfigValueUtils.merge(targetConfigValueMap, replacingRelaseConfigValueMap); DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setPrettyFlow(true); Yaml yaml = new Yaml(dumperOptions); ConfigValues mergedConfigValues = new ConfigValues(); mergedConfigValues.setRaw(yaml.dump(targetConfigValueMap)); replacingRelease.setConfigValues(mergedConfigValues); } return replacingRelease; }
private static Map<String, Object> convertConfigValuesToMap(Package pkg) { Yaml yaml = new Yaml(); Map<String, Object> currentPackageValueMap = new TreeMap<>(); if (pkg.getConfigValues() != null && StringUtils.hasText(pkg.getConfigValues().getRaw())) { currentPackageValueMap = (Map<String, Object>) yaml.load(pkg.getConfigValues().getRaw()); } if (currentPackageValueMap == null) { currentPackageValueMap = new TreeMap<>(); } return currentPackageValueMap; }
private Release updateReplacingReleaseConfigValues(Release targetRelease, Release replacingRelease) { Map<String, Object> targetConfigValueMap = getConfigValuesAsMap(targetRelease.getConfigValues()); Map<String, Object> replacingRelaseConfigValueMap = getConfigValuesAsMap(replacingRelease.getConfigValues()); if (targetConfigValueMap != null && replacingRelaseConfigValueMap != null) { ConfigValueUtils.merge(targetConfigValueMap, replacingRelaseConfigValueMap); DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setPrettyFlow(true); Yaml yaml = new Yaml(dumperOptions); ConfigValues mergedConfigValues = new ConfigValues(); mergedConfigValues.setRaw(yaml.dump(targetConfigValueMap)); replacingRelease.setConfigValues(mergedConfigValues); } return replacingRelease; }
Map<String, Object> mergedValues; if (StringUtils.hasText(overrideValues.getRaw())) { Object data = yaml.load(overrideValues.getRaw()); if (data instanceof Map) { Map<String, Object> overrideMap = (Map<String, Object>) yaml.load(overrideValues.getRaw()); mergedValues = mergeOverrideMap(pkg, overrideMap); data.getClass() + "overrideValues.getRaw() = " + overrideValues.getRaw());
/** * Update the stream identified by the PackageIdentifier and runtime configuration values. * @param streamName the name of the stream to upgrade * @param packageIdentifier the name of the package in skipper * @param configYml the YML formatted configuration values to use when upgrading * @param force the flag to indicate if the stream update is forced even if there are no differences from the existing stream * @param appNames the app names to update * @return release the upgraded release */ public Release upgradeStream(String streamName, PackageIdentifier packageIdentifier, String configYml, boolean force, List<String> appNames) { UpgradeRequest upgradeRequest = new UpgradeRequest(); upgradeRequest.setPackageIdentifier(packageIdentifier); UpgradeProperties upgradeProperties = new UpgradeProperties(); ConfigValues configValues = new ConfigValues(); configValues.setRaw(configYml); upgradeProperties.setConfigValues(configValues); upgradeProperties.setReleaseName(streamName); upgradeRequest.setUpgradeProperties(upgradeProperties); upgradeRequest.setForce(force); upgradeRequest.setAppNames(appNames); return this.skipperClient.upgrade(upgradeRequest); }
Map<String, Object> mergedValues; if (StringUtils.hasText(overrideValues.getRaw())) { Object data = yaml.load(overrideValues.getRaw()); if (data instanceof Map) { Map<String, Object> overrideMap = (Map<String, Object>) yaml.load(overrideValues.getRaw()); mergedValues = mergeOverrideMap(pkg, overrideMap); data.getClass() + "overrideValues.getRaw() = " + overrideValues.getRaw());