@NotNull private static List<ContainerNode> getContainerNodes(ContainerRoot model, List<String> targetNodes) { List<ContainerNode> nodes = new ArrayList<>(); if (targetNodes.get(0).equals("*")) { // select all nodes in the model nodes.addAll(model.getNodes()); } else { // specific node ContainerNode node = model.findNodesByID(targetNodes.get(0)); if (node != null) { nodes.add(node); } else { throw new KevScriptError("Unable to find node instance \"" + targetNodes.get(0) + "\". Move failed"); } } return nodes; }
public static String interpret(final IAST<Type> node, final Map<String, String> ctxVars) { IAST<Type> ctxVar = node.getChildren().get(0); String key = ctxVar.childrenAsString(); String value = ctxVars.get(key); if (value == null) { throw new KevScriptError("Missing value for context variable %"+ctxVar.childrenAsString()+"%"); } return value; } }
groups.add(group); } else { throw new KevScriptError("Unable to find group instance \""+groupList.get(0)+"\". Detach failed"); throw new KevScriptError("Detach target path is invalid ("+groupList.toString()+")"); throw new KevScriptError("Unable to detach node instance \""+instancePath.get(0)+"\". Instance does not exist"); throw new KevScriptError("\""+instancePath.toString()+"\" is not a valid detach path for a node");
private static void apply(Instance leftH, ContainerNode targetNode) { if (leftH instanceof ComponentInstance) { targetNode.addComponents((ComponentInstance) leftH); } else { if (leftH instanceof ContainerNode) { targetNode.addHosts((ContainerNode) leftH); } else { throw new KevScriptError("\""+leftH.getName()+"\" is not a node instance nor a component. Move failed"); } } } }
groups.add(group); } else { throw new KevScriptError("Unable to find group instance \""+groupList.get(0)+"\". Attach failed"); throw new KevScriptError("Attach target path is invalid ("+groupList.toString()+")"); throw new KevScriptError("Unable to attach node instance \""+instancePath.get(0)+"\". Instance does not exist"); throw new KevScriptError("\""+instancePath.toString()+"\" is not a valid attach path for a node");
@Override public void executeFromStream(final InputStream script, final ContainerRoot model, HashMap<String, String> ctxVars) throws Exception { if (ctxVars == null) { ctxVars = new HashMap<>(); } // override ctxVar with System.props (ie. -DctxVar.foo=bar // -DctxVar.port=4242) Properties props = System.getProperties(); for (String propName : props.stringPropertyNames()) { String[] splitted = propName.split("\\."); if (splitted[0].equals("ctxVar")) { Log.debug("Adding ctxVar {}={}", splitted[1], System.getProperty(propName)); ctxVars.put(splitted[1], System.getProperty(propName)); } } String kevs = new Scanner(script).useDelimiter("\\A").next(); final ParseResult<Type> parserResult = parser.parse(new InputBuffer(kevs.toCharArray())); final IAST<Type> ast = parserResult.getAST(); if (ast != null) { for (IAST<Type> stmt : ast.getChildren()) { Interpreter.interpret(stmt.getChildren().get(0), model, ctxVars, resolver); } } else { throw new KevScriptError(parserResult.getError().toString()); } }
targets = getContainerNodes(model, targetNodes); } else { throw new KevScriptError("Move target path is invalid (" + targetNodes.toString() + ")"); if (instancePath.size() == 1) { if (instancePath.get(0).equals("*")) { throw new KevScriptError("Wilcard \"*\" cannot be used for nodes. Move failed"); } else { throw new KevScriptError("Unable to move node instance \""+ instancePath.get(0)+"\". Instance does not exist"); throw new KevScriptError("\""+instancePath.toString()+"\" is not a valid move path for an instance");
List<KMFContainer> parentNodes = model.select("nodes[" + nodeName + "]"); if (parentNodes.isEmpty()){ throw new KevScriptError("Unable to find node " + componentName + " in model"); List<KMFContainer> cis = parentNode.select("components[" + componentName + "]"); if (cis.isEmpty()){ throw new KevScriptError("Unable to find component \"" + componentName + "\" in node \"" + parentNode.getName() + "\""); throw new KevScriptError("Bad name to resolve ports : " + node.toString()); throw new KevScriptError("No port resolved from : " + node.toString());
public static void interpret(IAST<Type> stmt, ContainerRoot model, Map<String, String> ctxVars, KevoreeRegistryResolver resolver) throws Exception { TypeFQN fqn = TypeDefExpr.interpret(stmt.getChildren().get(1), ctxVars); TypeDefinition td = resolver.resolve(fqn, model); if (td == null) { throw new KevScriptError("Unable to find TypeDefinition \"" + fqn.toString() + "\" in model"); } else { final IAST<Type> instanceNames = stmt.getChildren().get(0); if (instanceNames.getType().equals(Type.NameList)) { for (final IAST<Type> name : instanceNames.getChildren()) { apply(td, name, model, ctxVars); } } else { apply(td, instanceNames, model, ctxVars); } } }
public static void interpret(IAST<Type> stmt, ContainerRoot model, Map<String, String> ctxVars) { final IAST<Type> leftHandNetwork = stmt.getChildren().get(0); if (leftHandNetwork.getChildren().size() != 3) { throw new KevScriptError("Network must be: network nodeName.propertyType.interfaceName IP"); } else { final String nodeName = leftHandNetwork.getChildren().get(0).childrenAsString(); final ContainerNode networkTargetNode = model.findNodesByID(nodeName); if (networkTargetNode == null) { throw new KevScriptError("Node not found for name " + nodeName);
instance.setName(newNodeName); if (model.findNodesByID(newNodeName) != null) { throw new KevScriptError("Node already exist for name : " + newNodeName); final ContainerNode parentNode = model.findNodesByID(parentNodeName); if (parentNode == null) { throw new KevScriptError("Node not exist for name : " + parentNodeName); final ContainerNode parentNode = model.findNodesByID(nodeName); if (parentNode == null) { throw new KevScriptError( "Unable to find a node named: " + nodeName); } else { throw new KevScriptError("Bad component name (must be nodeName.componentName) : " + name.toString()); i = instance; } else { throw new KevScriptError("Bad channel name : " + name.toString()); i = instance; } else { throw new KevScriptError("Bad group name : " + name.toString());
throw new KevScriptError("Bad kevs.dictionary value description"); .findAttributesByID(propName); if (dicAtt == null) { throw new KevScriptError( "Param does not exist in type " + target.getName() + " -> " + propName); } else { .findAttributesByID(propName); if (dicAtt == null) { throw new KevScriptError( "Param does not existe in type " + target.getName() + " -> " + propName); } else { if (!dicAtt.getFragmentDependant()) { throw new KevScriptError( "Dictionary Attribute is not fragment dependent " + dicAtt.getName());