Java Code Examples for org.apache.mesos.v1.Protos#Offer
The following examples show how to use
org.apache.mesos.v1.Protos#Offer .
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: SingularityOfferHolder.java From Singularity with Apache License 2.0 | 6 votes |
public SingularityOfferHolder( List<Protos.Offer> offers, int taskSizeHint, String rackId, String slaveId, String hostname, Map<String, String> textAttributes, Map<String, String> reservedSlaveAttributes ) { this.rackId = rackId; this.slaveId = slaveId; this.hostname = hostname; this.offers = offers; this.roles = MesosUtils.getRoles(offers.get(0)); this.acceptedTasks = Lists.newArrayListWithExpectedSize(taskSizeHint); this.currentResources = offers.size() > 1 ? MesosUtils.combineResources( offers.stream().map(Protos.Offer::getResourcesList).collect(Collectors.toList()) ) : offers.get(0).getResourcesList(); this.sanitizedHost = JavaUtils.getReplaceHyphensWithUnderscores(hostname); this.sanitizedRackId = JavaUtils.getReplaceHyphensWithUnderscores(rackId); this.textAttributes = textAttributes; this.reservedSlaveAttributes = reservedSlaveAttributes; }
Example 2
Source File: TaskAssignerImpl.java From attic-aurora with Apache License 2.0 | 6 votes |
private Protos.TaskInfo assign( MutableStoreProvider storeProvider, Protos.Offer offer, String taskId, boolean revocable) { String host = offer.getHostname(); IAssignedTask assigned = stateManager.assignTask( storeProvider, taskId, host, offer.getAgentId(), task -> mapAndAssignResources(offer, task)); LOG.info( "Offer on agent {} (id {}) is being assigned task for {}.", host, offer.getAgentId().getValue(), taskId); return taskFactory.createFrom(assigned, offer, revocable); }
Example 3
Source File: Offers.java From attic-aurora with Apache License 2.0 | 6 votes |
/** * Builds a set of {@link HostOffer} for the current configuration. * * @param hostAttributes Host attributes to initialize offers from. * @return Set of offers. */ Set<HostOffer> build(Set<IHostAttributes> hostAttributes) { ImmutableSet.Builder<HostOffer> offers = ImmutableSet.builder(); int id = 0; for (IHostAttributes attributes : hostAttributes) { Protos.Offer offer = Protos.Offer.newBuilder() .addAllResources(ImmutableSet.of( makeScalar(CPUS, cpu), makeScalar(RAM_MB, ram.as(Data.MB)), makeScalar(DISK_MB, disk.as(Data.MB)), makeRange( PORTS, IntStream.range(1, ports).boxed().collect(Collectors.toSet())))) .setId(Protos.OfferID.newBuilder().setValue(String.format(OFFER_ID_FORMAT, id++))) .setFrameworkId(Protos.FrameworkID.newBuilder().setValue(FRAMEWORK_ID)) .setAgentId(Protos.AgentID.newBuilder().setValue(attributes.getSlaveId())) .setHostname(String.format(attributes.getHost())) .build(); offers.add(new HostOffer(offer, attributes)); } return offers.build(); }
Example 4
Source File: AcceptedOfferTest.java From attic-aurora with Apache License 2.0 | 6 votes |
private void runAllocateSingleRole(Optional<String> role, boolean revocable) { Protos.Offer offer = offer( mesosScalar(CPUS, TOTAL_BAG.valueOf(CPUS), revocable), mesosScalar(RAM_MB, TOTAL_BAG.valueOf(RAM_MB), false), mesosScalar(DISK_MB, TOTAL_BAG.valueOf(DISK_MB), false), mesosRange(PORTS, role, TASK_PORTS)); AcceptedOffer offerAllocation = AcceptedOffer.create(offer, TASK, EXECUTOR_BAG, revocable); ResourceBag bag = bagFromResources(TASK.getTask().getResources()); Set<Resource> taskResources = ImmutableSet.<Resource>builder() .add(mesosScalar(CPUS, bag.valueOf(CPUS), revocable)) .add(mesosScalar(RAM_MB, bag.valueOf(RAM_MB), false)) .add(mesosScalar(DISK_MB, bag.valueOf(DISK_MB), false)) .add(mesosRange(PORTS, role, TASK_PORTS)) .build(); assertEquals(taskResources, ImmutableSet.copyOf(offerAllocation.getTaskResources())); Set<Resource> executorResources = ImmutableSet.<Resource>builder() .add(mesosScalar(CPUS, EXECUTOR_BAG.valueOf(CPUS), revocable)) .add(mesosScalar(RAM_MB, EXECUTOR_BAG.valueOf(RAM_MB), false)) .add(mesosScalar(DISK_MB, EXECUTOR_BAG.valueOf(DISK_MB), false)) .build(); assertEquals(executorResources, ImmutableSet.copyOf(offerAllocation.getExecutorResources())); }
Example 5
Source File: SchedulerService.java From Juice with GNU General Public License v3.0 | 5 votes |
private static Map<String, Set<String>> generatorFacts(@NotNull Protos.Offer offer, Set<String> attributes) { Map<String, Set<String>> facts = Maps.newHashMap(); // add host if (StringUtils.isNotBlank(offer.getHostname())) { facts.put(Constraints.FIELD.HOSTNAME.getField(), Sets.newHashSet()); facts.get(Constraints.FIELD.HOSTNAME.getField()).add(offer.getHostname()); } // add attr if (null != attributes && !attributes.isEmpty()) { facts.put(Constraints.FIELD.RACK_ID.getField(), Sets.newHashSet()); facts.get(Constraints.FIELD.RACK_ID.getField()).addAll(attributes); } return facts; }
Example 6
Source File: TaskAssignerImpl.java From attic-aurora with Apache License 2.0 | 5 votes |
@VisibleForTesting IAssignedTask mapAndAssignResources(Protos.Offer offer, IAssignedTask task) { IAssignedTask assigned = task; for (ResourceType type : ResourceManager.getTaskResourceTypes(assigned)) { if (type.getMapper().isPresent()) { assigned = type.getMapper().get().mapAndAssign(offer, assigned); } } return assigned; }
Example 7
Source File: AttributeStore.java From attic-aurora with Apache License 2.0 | 5 votes |
/** * Merges the attributes from an offer, applying the default maintenance mode. * * @param store Store to fetch the existing maintenance mode for this host. * @param offer Offer to merge. * @return attributes from {@code offer} and the existing (or default) maintenance mode. */ public static IHostAttributes mergeOffer(AttributeStore store, Protos.Offer offer) { IHostAttributes fromOffer = Conversions.getAttributes(offer); MaintenanceMode mode = store.getHostAttributes(fromOffer.getHost()) .map(IHostAttributes::getMode) .orElse(MaintenanceMode.NONE); return IHostAttributes.build(fromOffer.newBuilder().setMode(mode)); }
Example 8
Source File: PortMapperTest.java From attic-aurora with Apache License 2.0 | 5 votes |
@Test public void testPortRangeAbundance() { Protos.Offer offer = offer(mesosRange(PORTS, 1, 2, 3, 4, 5)); assertEquals( 1, PORT_MAPPER.mapAndAssign(offer, makeTask("id", JOB).getAssignedTask()) .getAssignedPorts().size()); }
Example 9
Source File: PortMapperTest.java From attic-aurora with Apache License 2.0 | 5 votes |
@Test public void testPortRangeExact() { Protos.Offer offer = offer(mesosRange(PORTS, 1)); assertEquals( 1, PORT_MAPPER.mapAndAssign(offer, makeTask("id", JOB).getAssignedTask()) .getAssignedPorts().size()); }
Example 10
Source File: ResourceTestUtil.java From attic-aurora with Apache License 2.0 | 5 votes |
public static Protos.Offer offer(String agentId, Protos.Resource... resources) { return Protos.Offer.newBuilder() .setId(Protos.OfferID.newBuilder().setValue("offer-id-" + agentId)) .setFrameworkId(Protos.FrameworkID.newBuilder().setValue("framework-id")) .setAgentId(Protos.AgentID.newBuilder().setValue(agentId)) .setHostname("hostname") .addAllResources(ImmutableSet.copyOf(resources)).build(); }
Example 11
Source File: AcceptedOfferTest.java From attic-aurora with Apache License 2.0 | 5 votes |
private void runMultipleRoles(boolean revocable) { ResourceBag bag = bagFromResources(TASK.getTask().getResources()); Protos.Offer offer = offer( // Make cpus come from two roles. mesosScalar(CPUS, TEST_ROLE, revocable, EXECUTOR_BAG.valueOf(CPUS)), mesosScalar(CPUS, ABSENT_ROLE, revocable, bag.valueOf(CPUS)), // Make ram come from default role mesosScalar(RAM_MB, ABSENT_ROLE, false, TOTAL_BAG.valueOf(RAM_MB)), // Make disk come from non-default role. mesosScalar(DISK_MB, TEST_ROLE, false, TOTAL_BAG.valueOf(DISK_MB)), mesosRange(PORTS, TEST_ROLE, TASK_PORTS)); AcceptedOffer offerAllocation = AcceptedOffer.create(offer, TASK, EXECUTOR_BAG, revocable); Set<Resource> taskSet = ImmutableSet.<Resource>builder() .add(mesosScalar(CPUS, TEST_ROLE, revocable, EXECUTOR_BAG.valueOf(CPUS))) .add(mesosScalar( CPUS, ABSENT_ROLE, revocable, bag.subtract(EXECUTOR_BAG).valueOf(CPUS))) .add(mesosScalar(RAM_MB, ABSENT_ROLE, false, bag.valueOf(RAM_MB))) .add(mesosScalar(DISK_MB, TEST_ROLE, false, bag.valueOf(DISK_MB))) .add(mesosRange(PORTS, TEST_ROLE, TASK_PORTS)) .build(); assertEquals(taskSet, ImmutableSet.copyOf(offerAllocation.getTaskResources())); Set<Resource> executorSet = ImmutableSet.<Resource>builder() .add(mesosScalar(CPUS, ABSENT_ROLE, revocable, EXECUTOR_BAG.valueOf(CPUS))) .add(mesosScalar(RAM_MB, ABSENT_ROLE, false, EXECUTOR_BAG.valueOf(RAM_MB))) .add(mesosScalar(DISK_MB, TEST_ROLE, false, EXECUTOR_BAG.valueOf(DISK_MB))) .build(); assertEquals(executorSet, ImmutableSet.copyOf(offerAllocation.getExecutorResources())); }
Example 12
Source File: SingularityOfferHolder.java From Singularity with Apache License 2.0 | 4 votes |
public List<Protos.Offer> getOffers() { return offers; }
Example 13
Source File: ProtosConversion.java From attic-aurora with Apache License 2.0 | 4 votes |
public static Protos.Offer convert(org.apache.mesos.Protos.Offer o) { return convert(o, Protos.Offer.newBuilder()); }
Example 14
Source File: ProtosConversion.java From attic-aurora with Apache License 2.0 | 4 votes |
public static org.apache.mesos.Protos.Offer convert(Protos.Offer f) { return convert(f, org.apache.mesos.Protos.Offer.newBuilder()); }
Example 15
Source File: ResourceTestUtil.java From attic-aurora with Apache License 2.0 | 4 votes |
public static Protos.Offer offer(Protos.Resource... resources) { return offer("slave-id", resources); }