本文整理汇总了Java中org.apache.mesos.Protos.Resource.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.Builder方法的具体用法?Java Resource.Builder怎么用?Java Resource.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mesos.Protos.Resource
的用法示例。
在下文中一共展示了Resource.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildPortRanges
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
public static Resource buildPortRanges(String... ranges) {
Resource.Builder resources = Resource.newBuilder()
.setType(Type.RANGES)
.setName(MesosUtils.PORTS);
Ranges.Builder rangesBuilder = Ranges.newBuilder();
for (String range : ranges) {
String[] split = range.split("\\:");
rangesBuilder.addRange(
Range.newBuilder()
.setBegin(Long.parseLong(split[0]))
.setEnd(Long.parseLong(split[1])));
}
resources.setRanges(rangesBuilder);
return resources.build();
}
示例2: subtractResources
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
public static List<Resource> subtractResources(List<Resource> resources, List<Resource> subtract) {
List<Resource> remaining = Lists.newArrayListWithCapacity(resources.size());
for (Resource resource : resources) {
Optional<Resource> matched = getMatchingResource(resource, subtract);
if (!matched.isPresent()) {
remaining.add(resource.toBuilder().clone().build());
} else {
Resource.Builder resourceBuilder = resource.toBuilder().clone();
if (resource.hasScalar()) {
resourceBuilder.setScalar(resource.toBuilder().getScalarBuilder().setValue(resource.getScalar().getValue() - matched.get().getScalar().getValue()).build());
} else if (resource.hasRanges()) {
resourceBuilder.setRanges(subtractRanges(resource.getRanges(), matched.get().getRanges()));
} else {
throw new IllegalStateException(String.format("Can't subtract non-scalar or range resources %s", resource));
}
remaining.add(resourceBuilder.build());
}
}
return remaining;
}
示例3: setValue
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
private static Resource.Builder setValue(Resource.Builder builder, Value value) {
builder.setType(value.getType());
switch (value.getType()) {
case SCALAR:
builder.setScalar(value.getScalar());
return builder;
case RANGES:
builder.setRanges(value.getRanges());
return builder;
case SET:
builder.setSet(value.getSet());
return builder;
default:
throw new IllegalArgumentException(String.format("Unsupported spec value type: %s", value.getType()));
}
}
示例4: freeAtomicResource
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void freeAtomicResource(MesosResource mesosResource) {
Resource.Builder resBuilder = Resource.newBuilder(mesosResource.getResource());
resBuilder.clearReservation();
resBuilder.setRole(Constants.ANY_ROLE);
if (resBuilder.hasDisk()) {
Resource.DiskInfo.Builder diskBuilder = Resource.DiskInfo.newBuilder(resBuilder.getDisk());
diskBuilder.clearPersistence();
diskBuilder.clearVolume();
resBuilder.setDisk(diskBuilder.build());
}
Resource releasedResource = resBuilder.build();
List<MesosResource> resList = unreservedAtomicPool.get(mesosResource.getName());
if (resList == null) {
resList = new ArrayList<MesosResource>();
}
resList.add(new MesosResource(releasedResource));
unreservedAtomicPool.put(mesosResource.getName(), resList);
}
示例5: getReservedResource
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
/**
* The resource passed in is the fully completed Resource which will be launched. This may include volume/disk
* information which is not appropriate for the RESERVE operation. It is filtered out here.
*/
private static Resource getReservedResource(Resource resource) {
// The resource passed in is the fully completed Resource which will be launched. This may include volume/disk
// information which is not appropriate for the RESERVE operation. It is filtered out here.
Resource.Builder resBuilder = Resource.newBuilder(resource);
if (resBuilder.hasDisk() && resBuilder.getDisk().hasSource()) {
// Mount volume: Copy disk, but without 'persistence' nor 'volume' fields
resBuilder.setDisk(DiskInfo.newBuilder(resBuilder.getDisk())
.clearPersistence()
.clearVolume());
} else {
// Root volume: Clear the disk.
resBuilder.clearDisk();
}
resBuilder.clearRevocable();
return resBuilder.build();
}
示例6: UnreserveOfferRecommendation
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
public UnreserveOfferRecommendation(Offer offer, Resource resource) {
this.offer = offer;
Resource.Builder resourceBuilder = resource.toBuilder();
// If non-root disk resource, we want to clear ALL fields except for the field indicating the disk source.
if (resource.hasDisk() && resource.getDisk().hasSource()) {
resource = resourceBuilder.setDisk(
Resource.DiskInfo.newBuilder()
.setSource(resource.getDisk().getSource()))
.build();
} else {
resource = resourceBuilder.clearDisk().clearRevocable().build();
}
this.operation = Operation.newBuilder()
.setType(Operation.Type.UNRESERVE)
.setUnreserve(Operation.Unreserve.newBuilder()
.addAllResources(Arrays.asList(resource)))
.build();
this.resource = resource;
}
示例7: create
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
public static AcceptedOffer create(
Offer offer,
ResourceSlot taskSlot,
ResourceSlot executorSlot,
Set<Integer> selectedPorts,
TierInfo tierInfo) throws Resources.InsufficientResourcesException {
List<Resource> reservedFirst = ImmutableList.<Resource>builder()
.addAll(Iterables.filter(offer.getResourcesList(), RESERVED))
.addAll(Iterables.filter(offer.getResourcesList(), NOT_RESERVED))
.build();
boolean revocable = tierInfo.isRevocable();
List<Resource.Builder> cpuResources = filterToBuilders(
reservedFirst,
ResourceType.CPUS.getMesosName(),
revocable ? Resources.REVOCABLE : Resources.NON_REVOCABLE);
List<Resource.Builder> memResources = filterToBuilderNonRevocable(
reservedFirst, ResourceType.RAM_MB.getMesosName());
List<Resource.Builder> diskResources = filterToBuilderNonRevocable(
reservedFirst, ResourceType.DISK_MB.getMesosName());
List<Resource.Builder> portsResources = filterToBuilderNonRevocable(
reservedFirst, ResourceType.PORTS.getMesosName());
List<Resource> taskResources = ImmutableList.<Resource>builder()
.addAll(allocateScalarType(cpuResources, taskSlot.getNumCpus(), revocable))
.addAll(allocateScalarType(memResources, taskSlot.getRam().as(Data.MB), false))
.addAll(allocateScalarType(diskResources, taskSlot.getDisk().as(Data.MB), false))
.addAll(allocateRangeType(portsResources, selectedPorts))
.build();
List<Resource> executorResources = ImmutableList.<Resource>builder()
.addAll(allocateScalarType(cpuResources, executorSlot.getNumCpus(), revocable))
.addAll(allocateScalarType(memResources, executorSlot.getRam().as(Data.MB), false))
.addAll(allocateScalarType(diskResources, executorSlot.getDisk().as(Data.MB), false))
.build();
return new AcceptedOffer(taskResources, executorResources);
}
示例8: allocateRangeType
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
private static List<Resource> allocateRangeType(
List<Resource.Builder> from,
Set<Integer> valueSet) throws Resources.InsufficientResourcesException {
Set<Integer> leftOver = Sets.newHashSet(valueSet);
ImmutableList.Builder<Resource> result = ImmutableList.<Resource>builder();
for (Resource.Builder r : from) {
Set<Integer> fromResource = Sets.newHashSet(Iterables.concat(
Iterables.transform(r.getRanges().getRangeList(), Resources.RANGE_TO_MEMBERS)));
Set<Integer> available = Sets.newHashSet(Sets.intersection(leftOver, fromResource));
if (available.isEmpty()) {
continue;
}
Resource newResource = makeMesosRangeResource(r.build(), available);
result.add(newResource);
leftOver.removeAll(available);
if (leftOver.isEmpty()) {
break;
}
}
if (!leftOver.isEmpty()) {
// NOTE: this will not happen as long as Veto logic from TaskAssigner.maybeAssign is
// consistent.
// Maybe we should consider implementing resource veto with this class to ensure that.
throw new Resources.InsufficientResourcesException(
"Insufficient resource for range type when allocating from offer");
}
return result.build();
}
示例9: allocateScalarType
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
private static List<Resource> allocateScalarType(
List<Resource.Builder> from,
double amount,
boolean revocable) throws Resources.InsufficientResourcesException {
double remaining = amount;
ImmutableList.Builder<Resource> result = ImmutableList.builder();
for (Resource.Builder r : from) {
if (nearZero(remaining)) {
break;
}
final double available = r.getScalar().getValue();
if (nearZero(available)) {
// Skip resource slot that is already used up.
continue;
}
final double used = Math.min(remaining, available);
remaining -= used;
Resource.Builder newResource =
Resource.newBuilder(r.build())
.setScalar(Protos.Value.Scalar.newBuilder().setValue(used).build());
if (revocable) {
newResource.setRevocable(Resource.RevocableInfo.newBuilder());
}
result.add(newResource.build());
r.getScalarBuilder().setValue(available - used);
}
if (!nearZero(remaining)) {
// NOTE: this will not happen as long as Veto logic from TaskAssigner.maybeAssign is
// consistent.
// Maybe we should consider implementing resource veto with this class to ensure that.
throw new Resources.InsufficientResourcesException(
"Insufficient resource when allocating from offer");
}
return result.build();
}
示例10: filterToBuilders
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
private static List<Resource.Builder> filterToBuilders(
List<Resource> resources,
String name,
Predicate<Resource> additionalFilter) {
return FluentIterable.from(resources)
.filter(e -> e.getName().equals(name))
.filter(additionalFilter)
.transform(Resource::toBuilder)
.toList();
}
示例11: makePortResource
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
private static Resource makePortResource(Optional<String> role, Integer... values) {
Resource.Builder prototype = Resource.newBuilder()
.setType(Protos.Value.Type.RANGES)
.setName(PORTS.getMesosName());
if (role.isPresent()) {
prototype.setRole(role.get());
}
return AcceptedOffer.makeMesosRangeResource(prototype.build(), ImmutableSet.copyOf(values));
}
示例12: makeScalar
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
private static Resource makeScalar(
String name, Optional<String> role, boolean revocable, double value) {
Resource.Builder resource = Resource.newBuilder()
.setName(name)
.setType(Protos.Value.Type.SCALAR)
.setScalar(Protos.Value.Scalar.newBuilder().setValue(value));
if (role.isPresent()) {
resource.setRole(role.get());
}
if (revocable) {
resource.setRevocable(Resource.RevocableInfo.getDefaultInstance());
}
return resource.build();
}
示例13: consumeReservableMerged
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
public Optional<MesosResource> consumeReservableMerged(String name, Value desiredValue, String preReservedRole) {
Map<String, Value> pool = reservableMergedPoolByRole.get(preReservedRole);
if (pool == null) {
logger.info("No unreserved resources available for role '{}'. Reservable roles are: {}",
preReservedRole, reservableMergedPoolByRole.keySet());
return Optional.empty();
}
Value availableValue = pool.get(name);
if (sufficientValue(desiredValue, availableValue)) {
pool.put(name, ValueUtils.subtract(availableValue, desiredValue));
reservableMergedPoolByRole.put(preReservedRole, pool);
Resource.Builder builder = ResourceBuilder.fromUnreservedValue(name, desiredValue).build().toBuilder();
if (Capabilities.getInstance().supportsPreReservedResources() &&
!preReservedRole.equals(Constants.ANY_ROLE)) {
builder.addReservations(
Resource.ReservationInfo.newBuilder()
.setRole(preReservedRole)
.setType(Resource.ReservationInfo.Type.STATIC));
}
return Optional.of(new MesosResource(builder.build()));
} else {
if (availableValue == null) {
logger.info("Offer lacks any unreserved {} resources for role {}", name, preReservedRole);
} else {
logger.info("Offered quantity of {} for role {} is insufficient: desired {}, offered {}",
name,
preReservedRole,
TextFormat.shortDebugString(desiredValue),
TextFormat.shortDebugString(availableValue));
}
return Optional.empty();
}
}
示例14: addResource
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
/**
* Minimum to keep required field errors away.
*/
public static void addResource(Offer.Builder o, String name, String role) {
Resource.Builder b = o.addResourcesBuilder().setType(Value.Type.RANGES).setName(name);
if (role != null) {
b.setRole(role);
}
}
示例15: filterToBuilderNonRevocable
import org.apache.mesos.Protos.Resource; //导入方法依赖的package包/类
private static List<Resource.Builder> filterToBuilderNonRevocable(
List<Resource> resources,
String name) {
return filterToBuilders(resources, name, Resources.NON_REVOCABLE);
}