private static <COMPONENT extends ChainedComponent> COMPONENT getComponentOrThrow( ComponentRegistry<COMPONENT> registry, ComponentSpecification specification) { COMPONENT component = registry.getComponent(specification); if (component == null) { throw new ConfigurationRuntimeException("No such component '" + specification + "'"); } return component; }
private void verifyLegalOperation(Element currElem) { String operation = currElem.getAttribute("operation"); if (! operation.equalsIgnoreCase("append")) throw new ConfigurationRuntimeException("The only supported array operation is 'append', got '" + operation + "' at XML node '" + XML.getNodePath(currElem, " > ") + "'."); }
protected Map<String, Object> getChildren() { HashMap<String, Object> ret = new LinkedHashMap<String, Object>(); Field fields[] = getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); Object fieldValue; try { fieldValue = field.get(this); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException(e); } if (fieldValue instanceof Node || fieldValue instanceof NodeVector<?> || fieldValue instanceof Map<?,?>) ret.put(field.getName(), fieldValue); } return ret; }
/** * This method is meant for internal use in the configuration * system. Overrides Object.clone(). * * @return a new instance similar to this object. */ @Override protected Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { throw new ConfigurationRuntimeException(e); } }
/** * Returns a {@link ConfigInstance} of right type for given key using reflection * * @param cKey a ConfigKey * @return a {@link ConfigInstance} or null if not available in classpath */ @SuppressWarnings("unchecked") private static Class<? extends ConfigInstance> getConfigClass(ConfigDefinitionKey cKey, ClassLoader instanceLoader) { String className = createClassName(cKey.getName()); String fullClassName = packageName(cKey) + "." + className; Class<?> clazz; try { clazz = instanceLoader != null ? instanceLoader.loadClass(fullClassName) : Class.forName(fullClassName); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Could not find config class for key " + cKey, e); } if (! ConfigInstance.class.isAssignableFrom(clazz)) { throw new ConfigurationRuntimeException(fullClassName + " is not a ConfigInstance subclass, can not produce config for " + cKey); } return (Class<? extends ConfigInstance>) clazz; }
public static ConfigDefinitionKey parseConfigName(Element configE) { if (!configE.getNodeName().equals("config")) { throw new ConfigurationRuntimeException("The root element must be 'config', but was '" + configE.getNodeName() + "'."); throw new ConfigurationRuntimeException ("The 'config' element must have a 'name' attribute that matches the name of the config definition."); throw new ConfigurationRuntimeException("The config name '" + xmlName + "' contains illegal characters. Only names with the pattern " + namePattern.toString() + " are legal."); throw new ConfigurationRuntimeException("The config namespace '" + xmlNamespace + "' contains illegal characters. Only namespaces with the pattern " + namespacePattern.toString() + " are legal.");
/** * Resolves this config key into a correctly typed ConfigInstance using the given config builder. * FIXME: Make private once config overrides are deprecated.? * * @param key a ConfigKey * @param builder a ConfigBuilder to create the instance from. * @param targetDef the def to use * @return the config instance or null of no producer for this found in model */ static ConfigInstance resolveToInstance(ConfigKey<?> key, ConfigBuilder builder, InnerCNode targetDef) { ConfigDefinitionKey defKey = new ConfigDefinitionKey(key); try { if (targetDef != null) applyDef(builder, targetDef); Class<? extends ConfigInstance> clazz = getConfigClass(defKey, builder.getClass().getClassLoader()); return clazz.getConstructor(builder.getClass()).newInstance(builder); } catch (Exception e) { throw new ConfigurationRuntimeException(e); } }
i = clazz.getDeclaredConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new ConfigurationRuntimeException(e); throw new ConfigurationRuntimeException(fullClassName + " is not a ConfigInstance.Builder, can not produce config for the name '" + key.getName() + "'.");
private ComponentGraph createComponentsGraph(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs, long generation, Injector fallbackInjector) { previousConfigGeneration = generation; ComponentGraph graph = new ComponentGraph(generation); ComponentsConfig componentsConfig = getConfig(componentsConfigKey, configsIncludingBootstrapConfigs); if (componentsConfig == null) { throw new ConfigurationRuntimeException("The set of all configs does not include a valid 'components' config. Config set: " + configsIncludingBootstrapConfigs.keySet()); } addNodes(componentsConfig, graph); injectNodes(componentsConfig, graph); graph.complete(fallbackInjector); return graph; }
/** * Parse leaf value in an xml tree */ private void parseLeaf(Element element, ConfigPayloadBuilder payloadBuilder, String parentName) { String name = extractName(element); String value = XML.getValue(element); if (value == null) { throw new ConfigurationRuntimeException("Element '" + name + "' must have either children or a value"); } if (element.hasAttribute("index")) { // Check for legacy (pre Vespa 6) usage throw new IllegalArgumentException("The 'index' attribute on config elements is not supported - use <item>"); } else if (element.hasAttribute("operation")) { // leaf array, currently the only supported operation is 'append' verifyLegalOperation(element); ConfigPayloadBuilder.Array a = payloadBuilder.getArray(name); a.append(value); } else if ("item".equals(name)) { if (parentName == null) throw new ConfigurationRuntimeException("<item> is a reserved keyword for array and map elements"); if (element.hasAttribute("key")) { payloadBuilder.getMap(parentName).put(element.getAttribute("key"), value); } else { payloadBuilder.getArray(parentName).append(value); } } else { // leaf scalar, e.g. <intVal>3</intVal> payloadBuilder.setField(name, value); } }
/** * Adds the values and children (recursively) in the given xml element to the given {@link ConfigPayloadBuilder}. * @param currElem The element representing a config parameter. * @param payloadBuilder The builder to use when adding elements. */ private void parseElement(Element currElem, ConfigPayloadBuilder payloadBuilder, String parentName) { List<Element> children = XML.getChildren(currElem); try { if (children.isEmpty()) { parseLeaf(currElem, payloadBuilder, parentName); } else { parseComplex(currElem, children, payloadBuilder, parentName); } } catch (Exception exception) { throw new ConfigurationRuntimeException("Error parsing element at " + XML.getNodePath(currElem, " > ") + ": " + Exceptions.toMessageString(exception)); } }
private static <COMPONENT extends ChainedComponent> void instantiateChains( ComponentRegistry<Chain<COMPONENT>> chainRegistry, ChainsModel model, ComponentRegistry<COMPONENT> allComponents) { for (ChainSpecification chain : model.allChainsFlattened()) { try { Chain<COMPONENT> componentChain = new Chain<>(chain.componentId, resolveComponents(chain.componentReferences, allComponents), chain.phases()); chainRegistry.register(chain.componentId, componentChain); } catch (Exception e) { throw new ConfigurationRuntimeException("Invalid chain '" + chain.componentId + "'", e); } } }
throw new ConfigurationRuntimeException("<item> is a reserved keyword for array and map elements");