Java Code Examples for org.apache.mesos.Protos.Offer#getResourcesList()

The following examples show how to use org.apache.mesos.Protos.Offer#getResourcesList() . 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: MesosSchedulerCallbackHandler.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private boolean validateOfferResources(Offer offer) {
    for (Protos.Resource resource : offer.getResourcesList()) {
        if ("cpus".equals(resource.getName())) {
            final double cpus = resource.getScalar().getValue();
            if (cpus < 0.1) {
                logMesosCallbackInfo("Declining offer: %s due to too few CPUs in offer from %s: %s", offer.getId().getValue(), offer.getHostname(), cpus);
                return false;
            }
        } else if ("mem".equals(resource.getName())) {
            double memoryMB = resource.getScalar().getValue();
            if (memoryMB < 1) {
                logMesosCallbackInfo("Declining offer: %s due to too few memory in offer from %s: %s", offer.getId().getValue(), offer.getHostname(), memoryMB);
                return false;
            }
        }
    }
    return true;
}
 
Example 2
Source File: BdsMesosScheduler.java    From BigDataScript with Apache License 2.0 6 votes vote down vote up
/**
 * Convert offer to hostResources
 */
HostResources parseOffer(Offer offer) {
	HostResources hr = new HostResources();

	hr.setMem(0);
	hr.setCpus(0);

	for (Resource r : offer.getResourcesList()) {
		String resourceName = r.getName();
		int value = (int) r.getScalar().getValue();

		switch (resourceName) {
		case OFFER_MEM:
			hr.setMem(MB * value);
			break;
		case OFFER_CPUS:
			hr.setCpus(value);
			break;
		}
	}

	return hr;
}
 
Example 3
Source File: MesosResourcePool.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
private static Collection<MesosResource> getMesosResources(Offer offer, Optional<String> role) {
  Collection<MesosResource> mesosResources = new ArrayList<MesosResource>();
  for (Resource resource : offer.getResourcesList()) {
    if (consumableResource(role, resource)) {
      mesosResources.add(new MesosResource(resource));
    }
  }

  return mesosResources;
}
 
Example 4
Source File: REEFScheduler.java    From reef with Apache License 2.0 5 votes vote down vote up
private int getMemory(final Offer offer) {
  for (final Resource resource : offer.getResourcesList()) {
    if (resource.getName().equals("mem")) {
      return (int)resource.getScalar().getValue();
    }
  }
  return 0;
}
 
Example 5
Source File: REEFScheduler.java    From reef with Apache License 2.0 5 votes vote down vote up
private int getCpu(final Offer offer) {
  for (final Resource resource : offer.getResourcesList()) {
    if (resource.getName().equals("cpus")) {
      return (int)resource.getScalar().getValue();
    }
  }
  return 0;
}
 
Example 6
Source File: ResourceMesosScheduler.java    From oodt with Apache License 2.0 5 votes vote down vote up
/**
 * Checks all offers against jobs in order, assigning jobs to offers until each offer is full,
 * or all jobs are gone.
 * @param offers - offers to assign jobs to.
 * @return List of <JobSpec,TaskInfo,Offer> tuples (assigned to each other).
 */
private List<JobSet> getJobAssignmentsJobs(List<Offer> offers) {
    List<JobSet> list = new LinkedList<JobSet>();
    for (Offer offer : offers)
    {
        double cpus = 0.0, mem = 0.0;
        //Get the resources offered from this offer
        for (Resource resc : offer.getResourcesList()) {
            if (resc.getName().equals("cpus"))
                cpus += resc.getScalar().getValue();
            if (resc.getName().equals("mem"))
                mem += resc.getScalar().getValue();
        }
        //Search for enough jobs to fill the offer
        for (int i = 0;i < queue.getSize();i++)
        {
            try {
                JobSpec job = queue.getNextJob();
                double load = job.getJob().getLoadValue();
                //Check if enough resources
                if (cpus < load || mem < load*1024)
                {
                    queue.requeueJob(job);
                    continue;
                }
                cpus -= load;
                mem -= 1024*load;
                JobSet tmp = new JobSet(job,getTaskInfo(job,offer),offer);
                list.add(tmp);
                //Not enough left, optimise and stop looking for jobs
                if (cpus < 0.5 || mem <= 512.0)
                    break;
            } catch (JobQueueException e) {throw new RuntimeException(e);}
        }
        //Optimization: break when no jobs
        if (queue.getSize() == 0)
            break;
    }
    return list;
}
 
Example 7
Source File: MyriadScheduler.java    From myriad with Apache License 2.0 4 votes vote down vote up
private boolean matches(Offer offer, NMProfile profile) {
	double cpus = -1;
	double mem = -1;

	for (Resource resource : offer.getResourcesList()) {
		if (resource.getName().equals("cpus")) {
			if (resource.getType().equals(Value.Type.SCALAR)) {
				cpus = resource.getScalar().getValue();
			} else {
				LOGGER.error("Cpus resource was not a scalar: {}", resource
						.getType().toString());
			}
		} else if (resource.getName().equals("mem")) {
			if (resource.getType().equals(Value.Type.SCALAR)) {
				mem = resource.getScalar().getValue();
			} else {
				LOGGER.error("Mem resource was not a scalar: {}", resource
						.getType().toString());
			}
		} else if (resource.getName().equals("disk")) {
			LOGGER.warn("Ignoring disk resources from offer");
		} else if (resource.getName().equals("ports")) {
			LOGGER.info("Ignoring ports resources from offer");
		} else {
			LOGGER.warn("Ignoring unknown resource type: {}",
					resource.getName());
		}
	}

	if (cpus < 0)
		LOGGER.error("No cpus resource present");
	if (mem < 0)
		LOGGER.error("No mem resource present");

	Map<String, String> requestAttributes = new HashMap<String, String>();

	if (profile.getCpus() <= cpus
			&& profile.getMemory() <= mem
			&& SchedulerUtils.isMatchSlaveAttributes(offer,
					requestAttributes)) {
		return true;
	} else {
		LOGGER.info("Offer not sufficient for profile: " + profile);
		return false;
	}
}