/** * get the configurable delay value from the DB according to given key */ private long getConfigurableDelay(String configurableDelayKeyName) { ConfigValues configDelay = ConfigValues.valueOf(configurableDelayKeyName); return Config.<Integer> getValue(configDelay).longValue(); }
public static Set<String> getValidFenceAgentTypes(String clusterCompatibilityVersion) { return new HashSet<>(Arrays.asList(FenceConfigHelper.getFenceConfigurationValue( ConfigValues.VdsFenceType.name(), clusterCompatibilityVersion).split(COMMA))); } }
@Override @SuppressWarnings("unchecked") public <T> Map<String, T> getValuesForAllVersions(ConfigValues configValue) { return (Map<String, T>) _vdcOptionCache.get(configValue.toString()); }
@Override public <T> T getValue(ConfigValues name, String version) { Map<String, T> values = getValuesForAllVersions(name); if (valueExists(name, version)) { return values.get(version); } throw new IllegalArgumentException(name.toString() + " has no value for version: " + version); }
public static String getFenceConfigurationValue(String key, String version) { init(); String returnValue = null; String customReturnValue = null; ConfigValues value = ConfigValues.valueOf(key); ConfigValues customValue = ConfigValues.valueOf(getCustomKey(key)); returnValue = Config.getValue(value, version); customReturnValue = Config.getValue(customValue, ConfigCommon.defaultConfigurationVersion); return merge(key, returnValue, customReturnValue); }
/** * handles agent mapping, get the real agent for a given agent name * * @param agent * the agent name * @return string , the agent real name to be used */ public static String getRealAgent(String agent) { String agentMapping = FenceConfigHelper.getFenceConfigurationValue(ConfigValues.FenceAgentMapping.name(), ConfigCommon.defaultConfigurationVersion); String realAgent = agent; // result has the format [<agent>=<real agent>[,]]* String[] settings = agentMapping.split(Pattern.quote(COMMA), -1); if (settings.length > 0) { for (String setting : settings) { // get the <agent>=<real agent> pair String[] pair = setting.split(Pattern.quote(EQUAL), -1); if (pair.length == 2) { if (agent.equalsIgnoreCase(pair[0])) { realAgent = pair[1]; break; } } } } return realAgent; }
@Test public void testKeysAreRealConfigValues() { Set<String> badKeys = new HashSet<>(); Iterator<String> keyIter = pc.getKeys(); while (keyIter.hasNext()) { String key = keyIter.next(); String confValueName = key.split("\\.")[0]; try { ConfigValues.valueOf(confValueName); } catch (IllegalArgumentException e) { badKeys.add(confValueName); } } assertThat(String.format("Found keys in %s that don't have corresponding ConfigValues", PROPERTIES_PATH), badKeys, empty()); } }
/** * Caches the fence agents options mapping. Mapping are stored in the following format <!-- * <agent>:{var=value}{[,]var=value}*; --> for example : * alom:secure=secure,port=ipport;apc:secure=secure,port=ipport,slot=port */ private void cacheFenceAgentsOptionMapping() { String localFenceOptionMapping = FenceConfigHelper.getFenceConfigurationValue(ConfigValues.VdsFenceOptionMapping.name(), version); String[] agentsOptionsStr = localFenceOptionMapping.split(Pattern.quote(SEMICOLON), -1); for (String agentOptionsStr : agentsOptionsStr) { String[] parts = agentOptionsStr.split(Pattern.quote(COLON), -1); if (parts.length == 2) { String agent = parts[0]; Map<String, String> agentOptions = new HashMap<>(); // check for empty options if (StringUtils.isNotEmpty(parts[1])) { String[] options = parts[1].split(Pattern.quote(COMMA), -1); for (String option : options) { String[] optionKeyVal = option.split(Pattern.quote(EQUAL), -1); agentOptions.put(optionKeyVal[0], optionKeyVal[1]); // add mapped keys to special params fenceSpecialParams.add(optionKeyVal[1]); } } fenceOptionMapping.put(agent, agentOptions); } else { log.error(MAPPING_FORMAT_ERROR, agentOptionsStr); break; } } }
@Override public SystemOption get() { ConfigValues config; try { config = ConfigValues.valueOf(id); } catch (IllegalArgumentException ex) { throw new WebApplicationException(Response.Status.NOT_FOUND); } GetSystemOptionParameters parameters = new GetSystemOptionParameters(config); String version = ParametersHelper.getParameter(httpHeaders, uriInfo, VERSION); if (version != null && !version.isEmpty()) { parameters.setOptionVersion(version); } QueryReturnValue result = runQuery(QueryType.GetSystemOption, parameters); if (result.getReturnValue() == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } return LinkHelper.addLinks(SystemOptionsMapper.map(result.getReturnValue(), id)); } }
String agentDefaultParams = (architectureType != null && architectureType == ArchitectureType.ppc64) FenceConfigHelper.getFenceConfigurationValue(ConfigValues.FenceAgentDefaultParamsForPPC.name(), ConfigCommon.defaultConfigurationVersion) FenceConfigHelper.getFenceConfigurationValue(ConfigValues.FenceAgentDefaultParams.name(), ConfigCommon.defaultConfigurationVersion); StringBuilder realOptions = new StringBuilder(fenceOptions);
delay = data.getLongValue(SchedulerUtilBaseImpl.FIXED_DELAY_VALUE); } else { ConfigValues configDelay = ConfigValues.valueOf(configValueName); delay = Config.<Integer> getValue(configDelay).longValue();
@ParameterizedTest @MethodSource public void validateFenceAgentMappingConfig(String fenceAgentMapping, boolean expectedResult) { assertEquals(expectedResult, validator.validate(ConfigValues.FenceAgentMapping.name(), fenceAgentMapping).isOk()); }
result = getValue(ConfigValues.valueOf(realName), ConfigCommon.defaultConfigurationVersion);
@ParameterizedTest @MethodSource public void validateVdsFenceOptionMappingConfig(String vdsFenceOptionMapping, boolean expectedResult) { assertEquals(expectedResult, validator.validate(ConfigValues.VdsFenceOptionMapping.name(), vdsFenceOptionMapping).isOk()); }
@ParameterizedTest @MethodSource public void validateFenceAgentDefaultParamsConfig(String fenceAgentDefault, boolean expectedResult) { assertEquals(expectedResult, validator.validate(ConfigValues.FenceAgentDefaultParams.name(), fenceAgentDefault).isOk()); }
@ParameterizedTest @MethodSource public void validateVdsFenceTypeConfig(String vdsFenceType, boolean expectedResult) { assertEquals(expectedResult, validator.validate(ConfigValues.VdsFenceType.name(), vdsFenceType).isOk()); }
@ParameterizedTest @MethodSource public void validateRanges(String values, boolean expectedResult) { assertEquals(expectedResult, validator.validate(ConfigKeyFactory.getInstance().generateBlankConfigKey(ConfigValues.DefaultMTU.name(), "Mtu"), values) .isOk()); }