for (Protos.Attribute attribute: offer.getAttributesList()) { attributeMap.put(attribute.getName(), attribute);
@Override public Collection<String> getKeys(Offer offer) { return offer.getAttributesList().stream() .map(AttributeStringUtils::toString) .collect(Collectors.toList()); } }
@Override public Collection<String> getKeys(Offer offer) { return offer.getAttributesList().stream() .map(proto -> AttributeStringUtils.toString(proto)) .filter(attribute -> attributeMatcher.matches(attribute)) .collect(Collectors.toList()); }
"Offer not sufficient for slave request:\n" + offer.getResourcesList().toString() + "\n" + offer.getAttributesList().toString() + "\nRequested for Jenkins slave:\n" + " cpus: " + requestedCpus + "\n" +
/** * Checks whether the cloud Mesos slave attributes match those from the Mesos offer. * * @param offer Mesos offer data object. * @return true if all the offer attributes match and false if not. */ private boolean slaveAttributesMatch(Offer offer, JSONObject slaveAttributes) { //Accept any and all Mesos slave offers by default. boolean slaveTypeMatch = true; //Collect the list of attributes from the offer as key-value pairs Map<String, String> attributesMap = new HashMap<String, String>(); for (Attribute attribute : offer.getAttributesList()) { attributesMap.put(attribute.getName(), attribute.getText().getValue()); } if (slaveAttributes != null && slaveAttributes.size() > 0) { //Iterate over the cloud attributes to see if they exist in the offer attributes list. Iterator iterator = slaveAttributes.keys(); while (iterator.hasNext()) { String key = (String) iterator.next(); //If there is a single absent attribute then we should reject this offer. if (!(attributesMap.containsKey(key) && attributesMap.get(key).toString().equals(slaveAttributes.getString(key)))) { slaveTypeMatch = false; break; } } } return slaveTypeMatch; }
/** * Stores the {@link Attribute}s from the provided {@link Offer}. * Any existing stored attributes are overwritten. */ public TaskLabelWriter setOfferAttributes(Offer launchOffer) { writer.put(LabelConstants.OFFER_ATTRIBUTES_LABEL, AttributeStringUtils.toString(launchOffer.getAttributesList())); return this; }
@Override protected String getKey(Offer offer) { for (Attribute attribute : offer.getAttributesList()) { if (attribute.getName().equalsIgnoreCase(attributeName)) { return AttributeStringUtils.toString(AttributeStringUtils.toValue(attribute)); } } return null; }