org.apache.flink.mesos.Utils Java Examples

The following examples show how to use org.apache.flink.mesos.Utils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Offer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	return "Offer{" +
		"offer=" + offer +
		", resources='" + Utils.toString(resources) + '\'' +
		", hostname='" + hostname + '\'' +
		", vmID='" + vmID + '\'' +
		", attributeMap=" + attributeMap +
		", offeredTime=" + offeredTime +
		'}';
}
 
Example #2
Source File: Offer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	return "Offer{" +
		"offer=" + offer +
		", resources='" + Utils.toString(resources) + '\'' +
		", hostname='" + hostname + '\'' +
		", vmID='" + vmID + '\'' +
		", attributeMap=" + attributeMap +
		", offeredTime=" + offeredTime +
		'}';
}
 
Example #3
Source File: Offer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	return "Offer{" +
		"offer=" + offer +
		", resources='" + Utils.toString(resources) + '\'' +
		", hostname='" + hostname + '\'' +
		", vmID='" + vmID + '\'' +
		", attributeMap=" + attributeMap +
		", offeredTime=" + offeredTime +
		'}';
}
 
Example #4
Source File: MesosResourceAllocation.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Takes some amount of scalar resources (e.g. cpus, mem).
 *
 * @param amount the (approximate) amount to take from the available quantity.
 * @param roles the roles to accept
 */
public List<Protos.Resource> takeScalar(String resourceName, double amount, Set<String> roles) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocating {} {}", amount, resourceName);
	}

	List<Protos.Resource> result = new ArrayList<>(1);
	for (ListIterator<Protos.Resource> i = resources.listIterator(); i.hasNext();) {
		if (amount <= EPSILON) {
			break;
		}

		// take from next available scalar resource that is unreserved or reserved for an applicable role
		Protos.Resource available = i.next();
		if (!resourceName.equals(available.getName()) || !available.hasScalar()) {
			continue;
		}
		if (!UNRESERVED_ROLE.equals(available.getRole()) && !roles.contains(available.getRole())) {
			continue;
		}

		double amountToTake = Math.min(available.getScalar().getValue(), amount);
		Protos.Resource taken = available.toBuilder().setScalar(Protos.Value.Scalar.newBuilder().setValue(amountToTake)).build();
		amount -= amountToTake;
		result.add(taken);
		if (LOG.isDebugEnabled()) {
			LOG.debug("Taking {} from {}", amountToTake, Utils.toString(available));
		}

		// keep remaining amount (if any)
		double remaining = available.getScalar().getValue() - taken.getScalar().getValue();
		if (remaining > EPSILON) {
			i.set(available.toBuilder().setScalar(Protos.Value.Scalar.newBuilder().setValue(remaining)).build());
		}
		else {
			i.remove();
		}
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocated: {}, unsatisfied: {}", Utils.toString(result), amount);
	}
	return result;
}
 
Example #5
Source File: MesosResourceAllocation.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Takes some amount of range resources (e.g. ports).
 *
 * @param amount the number of values to take from the available range(s).
 * @param roles the roles to accept
 */
public List<Protos.Resource> takeRanges(String resourceName, int amount, Set<String> roles) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocating {} {}", amount, resourceName);
	}

	List<Protos.Resource> result = new ArrayList<>(1);
	for (ListIterator<Protos.Resource> i = resources.listIterator(); i.hasNext();) {
		if (amount <= 0) {
			break;
		}

		// take from next available range resource that is unreserved or reserved for an applicable role
		Protos.Resource available = i.next();
		if (!resourceName.equals(available.getName()) || !available.hasRanges()) {
			continue;
		}
		if (!UNRESERVED_ROLE.equals(available.getRole()) && !roles.contains(available.getRole())) {
			continue;
		}

		List<Protos.Value.Range> takenRanges = new ArrayList<>();
		List<Protos.Value.Range> remainingRanges = new ArrayList<>(available.getRanges().getRangeList());
		for (ListIterator<Protos.Value.Range> j = remainingRanges.listIterator(); j.hasNext();) {
			if (amount <= 0) {
				break;
			}

			// take from next available range (note: ranges are inclusive)
			Protos.Value.Range availableRange = j.next();
			long amountToTake = Math.min(availableRange.getEnd() - availableRange.getBegin() + 1, amount);
			Protos.Value.Range takenRange = availableRange.toBuilder().setEnd(availableRange.getBegin() + amountToTake - 1).build();
			amount -= amountToTake;
			takenRanges.add(takenRange);

			// keep remaining range (if any)
			long remaining = availableRange.getEnd() - takenRange.getEnd();
			if (remaining > 0) {
				j.set(availableRange.toBuilder().setBegin(takenRange.getEnd() + 1).build());
			}
			else {
				j.remove();
			}
		}
		Protos.Resource taken = available.toBuilder().setRanges(Protos.Value.Ranges.newBuilder().addAllRange(takenRanges)).build();
		if (LOG.isDebugEnabled()) {
			LOG.debug("Taking {} from {}", Utils.toString(taken.getRanges()), Utils.toString(available));
		}
		result.add(taken);

		// keep remaining ranges (if any)
		if (remainingRanges.size() > 0) {
			i.set(available.toBuilder().setRanges(Protos.Value.Ranges.newBuilder().addAllRange(remainingRanges)).build());
		}
		else {
			i.remove();
		}
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocated: {}, unsatisfied: {}", Utils.toString(result), amount);
	}
	return result;
}
 
Example #6
Source File: MesosResourceAllocation.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return "MesosResourceAllocation{" +
		"resources=" + Utils.toString(resources) +
		'}';
}
 
Example #7
Source File: MesosResourceAllocation.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Takes some amount of scalar resources (e.g. cpus, mem).
 *
 * @param amount the (approximate) amount to take from the available quantity.
 * @param roles the roles to accept
 */
public List<Protos.Resource> takeScalar(String resourceName, double amount, Set<String> roles) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocating {} {}", amount, resourceName);
	}

	List<Protos.Resource> result = new ArrayList<>(1);
	for (ListIterator<Protos.Resource> i = resources.listIterator(); i.hasNext();) {
		if (amount <= EPSILON) {
			break;
		}

		// take from next available scalar resource that is unreserved or reserved for an applicable role
		Protos.Resource available = i.next();
		if (!resourceName.equals(available.getName()) || !available.hasScalar()) {
			continue;
		}
		if (!UNRESERVED_ROLE.equals(available.getRole()) && !roles.contains(available.getRole())) {
			continue;
		}

		double amountToTake = Math.min(available.getScalar().getValue(), amount);
		Protos.Resource taken = available.toBuilder().setScalar(Protos.Value.Scalar.newBuilder().setValue(amountToTake)).build();
		amount -= amountToTake;
		result.add(taken);
		if (LOG.isDebugEnabled()) {
			LOG.debug("Taking {} from {}", amountToTake, Utils.toString(available));
		}

		// keep remaining amount (if any)
		double remaining = available.getScalar().getValue() - taken.getScalar().getValue();
		if (remaining > EPSILON) {
			i.set(available.toBuilder().setScalar(Protos.Value.Scalar.newBuilder().setValue(remaining)).build());
		}
		else {
			i.remove();
		}
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocated: {}, unsatisfied: {}", Utils.toString(result), amount);
	}
	return result;
}
 
Example #8
Source File: MesosResourceAllocation.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Takes some amount of range resources (e.g. ports).
 *
 * @param amount the number of values to take from the available range(s).
 * @param roles the roles to accept
 */
public List<Protos.Resource> takeRanges(String resourceName, int amount, Set<String> roles) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocating {} {}", amount, resourceName);
	}

	List<Protos.Resource> result = new ArrayList<>(1);
	for (ListIterator<Protos.Resource> i = resources.listIterator(); i.hasNext();) {
		if (amount <= 0) {
			break;
		}

		// take from next available range resource that is unreserved or reserved for an applicable role
		Protos.Resource available = i.next();
		if (!resourceName.equals(available.getName()) || !available.hasRanges()) {
			continue;
		}
		if (!UNRESERVED_ROLE.equals(available.getRole()) && !roles.contains(available.getRole())) {
			continue;
		}

		List<Protos.Value.Range> takenRanges = new ArrayList<>();
		List<Protos.Value.Range> remainingRanges = new ArrayList<>(available.getRanges().getRangeList());
		for (ListIterator<Protos.Value.Range> j = remainingRanges.listIterator(); j.hasNext();) {
			if (amount <= 0) {
				break;
			}

			// take from next available range (note: ranges are inclusive)
			Protos.Value.Range availableRange = j.next();
			long amountToTake = Math.min(availableRange.getEnd() - availableRange.getBegin() + 1, amount);
			Protos.Value.Range takenRange = availableRange.toBuilder().setEnd(availableRange.getBegin() + amountToTake - 1).build();
			amount -= amountToTake;
			takenRanges.add(takenRange);

			// keep remaining range (if any)
			long remaining = availableRange.getEnd() - takenRange.getEnd();
			if (remaining > 0) {
				j.set(availableRange.toBuilder().setBegin(takenRange.getEnd() + 1).build());
			}
			else {
				j.remove();
			}
		}
		Protos.Resource taken = available.toBuilder().setRanges(Protos.Value.Ranges.newBuilder().addAllRange(takenRanges)).build();
		if (LOG.isDebugEnabled()) {
			LOG.debug("Taking {} from {}", Utils.toString(taken.getRanges()), Utils.toString(available));
		}
		result.add(taken);

		// keep remaining ranges (if any)
		if (remainingRanges.size() > 0) {
			i.set(available.toBuilder().setRanges(Protos.Value.Ranges.newBuilder().addAllRange(remainingRanges)).build());
		}
		else {
			i.remove();
		}
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocated: {}, unsatisfied: {}", Utils.toString(result), amount);
	}
	return result;
}
 
Example #9
Source File: MesosResourceAllocation.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return "MesosResourceAllocation{" +
		"resources=" + Utils.toString(resources) +
		'}';
}
 
Example #10
Source File: MesosResourceAllocation.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Takes some amount of scalar resources (e.g. cpus, mem).
 *
 * @param amount the (approximate) amount to take from the available quantity.
 * @param roles the roles to accept
 */
public List<Protos.Resource> takeScalar(String resourceName, double amount, Set<String> roles) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocating {} {}", amount, resourceName);
	}

	List<Protos.Resource> result = new ArrayList<>(1);
	for (ListIterator<Protos.Resource> i = resources.listIterator(); i.hasNext();) {
		if (amount <= EPSILON) {
			break;
		}

		// take from next available scalar resource that is unreserved or reserved for an applicable role
		Protos.Resource available = i.next();
		if (!resourceName.equals(available.getName()) || !available.hasScalar()) {
			continue;
		}
		if (!UNRESERVED_ROLE.equals(available.getRole()) && !roles.contains(available.getRole())) {
			continue;
		}

		double amountToTake = Math.min(available.getScalar().getValue(), amount);
		Protos.Resource taken = available.toBuilder().setScalar(Protos.Value.Scalar.newBuilder().setValue(amountToTake)).build();
		amount -= amountToTake;
		result.add(taken);
		if (LOG.isDebugEnabled()) {
			LOG.debug("Taking {} from {}", amountToTake, Utils.toString(available));
		}

		// keep remaining amount (if any)
		double remaining = available.getScalar().getValue() - taken.getScalar().getValue();
		if (remaining > EPSILON) {
			i.set(available.toBuilder().setScalar(Protos.Value.Scalar.newBuilder().setValue(remaining)).build());
		}
		else {
			i.remove();
		}
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocated: {}, unsatisfied: {}", Utils.toString(result), amount);
	}
	return result;
}
 
Example #11
Source File: MesosResourceAllocation.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Takes some amount of range resources (e.g. ports).
 *
 * @param amount the number of values to take from the available range(s).
 * @param roles the roles to accept
 */
public List<Protos.Resource> takeRanges(String resourceName, int amount, Set<String> roles) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocating {} {}", amount, resourceName);
	}

	List<Protos.Resource> result = new ArrayList<>(1);
	for (ListIterator<Protos.Resource> i = resources.listIterator(); i.hasNext();) {
		if (amount <= 0) {
			break;
		}

		// take from next available range resource that is unreserved or reserved for an applicable role
		Protos.Resource available = i.next();
		if (!resourceName.equals(available.getName()) || !available.hasRanges()) {
			continue;
		}
		if (!UNRESERVED_ROLE.equals(available.getRole()) && !roles.contains(available.getRole())) {
			continue;
		}

		List<Protos.Value.Range> takenRanges = new ArrayList<>();
		List<Protos.Value.Range> remainingRanges = new ArrayList<>(available.getRanges().getRangeList());
		for (ListIterator<Protos.Value.Range> j = remainingRanges.listIterator(); j.hasNext();) {
			if (amount <= 0) {
				break;
			}

			// take from next available range (note: ranges are inclusive)
			Protos.Value.Range availableRange = j.next();
			long amountToTake = Math.min(availableRange.getEnd() - availableRange.getBegin() + 1, amount);
			Protos.Value.Range takenRange = availableRange.toBuilder().setEnd(availableRange.getBegin() + amountToTake - 1).build();
			amount -= amountToTake;
			takenRanges.add(takenRange);

			// keep remaining range (if any)
			long remaining = availableRange.getEnd() - takenRange.getEnd();
			if (remaining > 0) {
				j.set(availableRange.toBuilder().setBegin(takenRange.getEnd() + 1).build());
			}
			else {
				j.remove();
			}
		}
		Protos.Resource taken = available.toBuilder().setRanges(Protos.Value.Ranges.newBuilder().addAllRange(takenRanges)).build();
		if (LOG.isDebugEnabled()) {
			LOG.debug("Taking {} from {}", Utils.toString(taken.getRanges()), Utils.toString(available));
		}
		result.add(taken);

		// keep remaining ranges (if any)
		if (remainingRanges.size() > 0) {
			i.set(available.toBuilder().setRanges(Protos.Value.Ranges.newBuilder().addAllRange(remainingRanges)).build());
		}
		else {
			i.remove();
		}
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("Allocated: {}, unsatisfied: {}", Utils.toString(result), amount);
	}
	return result;
}
 
Example #12
Source File: MesosResourceAllocation.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return "MesosResourceAllocation{" +
		"resources=" + Utils.toString(resources) +
		'}';
}