protected Map<String, Set<NodeAttribute>> getNodeToAttributesMap( NodesToAttributesMappingRequest request) { List<NodeToAttributes> attributes = request.getNodesToAttributes(); Map<String, Set<NodeAttribute>> nodeToAttrMap = new HashMap<>(); attributes.forEach((v) -> nodeToAttrMap .put(v.getNode(), new HashSet<>(v.getNodeAttributes()))); return nodeToAttrMap; } }
public static NodeToAttributes newInstance(String node, List<NodeAttribute> attributes) { NodeToAttributes nodeIdToAttributes = Records.newRecord(NodeToAttributes.class); nodeIdToAttributes.setNode(node); nodeIdToAttributes.setNodeAttributes(attributes); return nodeIdToAttributes; }
@Override public List<NodeToAttributes> getNodeToAttributes(Set<String> prefix) { try { readLock.lock(); List<NodeToAttributes> nodeToAttributes = new ArrayList<>(); nodeCollections.forEach((k, v) -> { List<NodeAttribute> attrs; if (prefix == null || prefix.isEmpty()) { attrs = new ArrayList<>(v.getAttributes().keySet()); } else { attrs = new ArrayList<>(); for (Entry<NodeAttribute, AttributeValue> nodeAttr : v.attributes .entrySet()) { if (prefix.contains( nodeAttr.getKey().getAttributeKey().getAttributePrefix())) { attrs.add(nodeAttr.getKey()); } } } nodeToAttributes.add(NodeToAttributes.newInstance(k, attrs)); }); return nodeToAttributes; } finally { readLock.unlock(); } }
.put(node, NodeToAttributes.newInstance(node, attributesList));
NodeToAttributes other = (NodeToAttributes) obj; if (getNodeAttributes() == null) { if (other.getNodeAttributes() != null) { return false; } else if (!getNodeAttributes().containsAll(other.getNodeAttributes())) { return false; if (other.getNode() != null) { return false; } else if (!getNode().equals(other.getNode())) { return false;
protected void handleStoreEvent(NodeAttributesStoreEvent event) { List<NodeToAttributes> mappingList = new ArrayList<>(); Map<String, Map<NodeAttribute, AttributeValue>> nodeToAttr = event.getNodeAttributeMappingList(); nodeToAttr.forEach((k, v) -> mappingList .add(NodeToAttributes.newInstance(k, new ArrayList<>(v.keySet())))); try { switch (event.getOperation()) { case REPLACE: store.replaceNodeAttributes(mappingList); break; case ADD: store.addNodeAttributes(mappingList); break; case REMOVE: store.removeNodeAttributes(mappingList); break; default: LOG.warn("Unsupported operation"); } } catch (IOException e) { LOG.error("Failed to store attribute modification to storage"); throw new YarnRuntimeException(e); } }
List<String> invalidNodes = new ArrayList<>(); for (NodeToAttributes nodeToAttributes : nodesToAttributesMapping) { String node = nodeToAttributes.getNode(); if (!validateForInvalidNode(node, failOnUnknownNodes)) { invalidNodes.add(node); continue; List<NodeAttribute> nodeAttributes = nodeToAttributes.getNodeAttributes(); if (!nodeAttributes.stream() .allMatch(nodeAttribute -> NodeAttribute.PREFIX_CENTRALIZED
NodesToAttributesMappingRequest .newInstance(AttributeMappingOperationType.ADD, ImmutableList.of(NodeToAttributes.newInstance("host1", ImmutableList.of(NodeAttribute.newInstance( NodeAttribute.PREFIX_CENTRALIZED, "x", NodesToAttributesMappingRequest .newInstance(AttributeMappingOperationType.REMOVE, ImmutableList.of(NodeToAttributes.newInstance("host4", ImmutableList.of(NodeAttribute.newInstance( NodeAttribute.PREFIX_CENTRALIZED, "x", NodesToAttributesMappingRequest .newInstance(AttributeMappingOperationType.ADD, ImmutableList.of(NodeToAttributes.newInstance("host5", ImmutableList.of(NodeAttribute.newInstance( NodeAttribute.PREFIX_CENTRALIZED, "x", NodesToAttributesMappingRequest .newInstance(AttributeMappingOperationType.ADD, ImmutableList.of( NodeToAttributes.newInstance("host4:8889", ImmutableList.of(NodeAttribute.newInstance( NodeAttribute.PREFIX_CENTRALIZED, "x", NodeAttributeType.STRING, "dfasdf"))), NodeToAttributes.newInstance("host2:8889", ImmutableList.of(NodeAttribute.newInstance( NodeAttribute.PREFIX_CENTRALIZED, "x", NodesToAttributesMappingRequest