/** * Erase url of removing node from the list of additional nodes of type = removingNode.getType() * of the configuration of puppet master, and return this list as row with comma-separated values. * For example: given: $additional_builders = * "http://builder2.example.com:8080/builder/internal/builder,http://builder3.example.com:8080/builder/internal/builder" * removingNode = new NodeConfig(BUILDER, "builder3.example.com") Result = * "http://builder2.example.com:8080/builder/internal/builder" * * @throws IllegalArgumentException if there is no removing node in the list of additional nodes * @throws IllegalStateException if additional nodes property isn't found in Codenvy config */ public String getValueWithoutNode(NodeConfig removingNode) throws IllegalArgumentException { String additionalNodesProperty = getPropertyNameBy(removingNode.getType()); List<String> nodesUrls = config.getAllValues(additionalNodesProperty); if (nodesUrls == null) { throw new IllegalStateException( format( "Additional nodes property '%s' isn't found in Codenvy config", additionalNodesProperty)); } String nodeUrl = getAdditionalNodeUrl(removingNode); if (!nodesUrls.contains(nodeUrl)) { throw new IllegalArgumentException( format("There is no node '%s' in the list of additional nodes", removingNode.getHost())); } nodesUrls.remove(nodeUrl); return on(',').skipNulls().join(nodesUrls); }
/** * Construct url of adding node, add it to the list of additional nodes of type = * addingNode.getType() of the configuration of puppet master, and return this list as row with * comma-separated values. For example: given: $additional_builders = * "http://builder2.example.com:8080/builder/internal/builder" addingNode = new * NodeConfig(BUILDER, "builder3.example.com") Result = * "http://builder2.example.com:8080/builder/internal/builder,http://builder3.example.com:8080/builder/internal/builder" * * @throws IllegalArgumentException if there is adding node in the list of additional nodes * @throws IllegalStateException if additional nodes property isn't found in Codenvy config */ public String getValueWithNode(NodeConfig addingNode) throws IllegalArgumentException, IllegalStateException { String additionalNodesProperty = getPropertyNameBy(addingNode.getType()); List<String> nodesUrls = config.getAllValues(additionalNodesProperty); if (nodesUrls == null) { throw new IllegalStateException( format( "Additional nodes property '%s' isn't found in Codenvy config", additionalNodesProperty)); } String nodeUrl = getAdditionalNodeUrl(addingNode); if (nodesUrls.contains(nodeUrl)) { throw new IllegalArgumentException( format("Node '%s' has been already used", addingNode.getHost())); } nodesUrls.add(nodeUrl); return on(',').skipNulls().join(nodesUrls); }
/** * @return for given additional node type: Map[{additionalNodesPropertyName}, {List<String> of * additionalNodesDns}] */ @Nullable public Map<String, List<String>> extractAdditionalNodesDns(NodeConfig.NodeType nodeType) { Map<String, List<String>> result = new HashMap<>(); String additionalNodesProperty = getPropertyNameBy(nodeType); List<String> nodesUrls = config.getAllValues(additionalNodesProperty); if (nodesUrls == null) { return null; } List<String> nodesDns = new ArrayList<>(); for (String nodeUrl : nodesUrls) { String nodeDns = getAdditionalNodeDns(nodeUrl); if (nodeDns != null) { nodesDns.add(nodeDns); } } result.put(additionalNodesProperty, nodesDns); return result; }