org.apache.hadoop.yarn.util.resource.Resources.equals()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.apache.hadoop.yarn.util.resource.Resources.equals方法的一些代码示例,展示了Resources.equals的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.equals方法的具体详情如下:
包路径:org.apache.hadoop.yarn.util.resource.Resources
类名称:Resources
方法名:equals

Resources.equals介绍

暂无

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private static void addIfNeeded(TreeMap<Long, Resource> out, long time,
  Resource outRes) {
 if (out.isEmpty() || (out.lastEntry() != null && outRes == null)
   || (out.lastEntry().getValue() != null
     && !Resources.equals(out.lastEntry().getValue(), outRes))) {
  out.put(time, outRes);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private static NavigableMap<Long, Resource> negate(RLEOperator operator,
  NavigableMap<Long, Resource> a) throws PlanningException {
 TreeMap<Long, Resource> out = new TreeMap<Long, Resource>();
 for (Entry<Long, Resource> e : a.entrySet()) {
  Resource val = Resources.negate(e.getValue());
  // test for negative value and throws
  if (operator == RLEOperator.subtractTestNonNegative
    && (Resources.fitsIn(val, ZERO_RESOURCE)
      && !Resources.equals(val, ZERO_RESOURCE))) {
   throw new PlanningException(
     "RLESparseResourceAllocation: merge failed as the "
       + "resulting RLESparseResourceAllocation would be negative");
  }
  out.put(e.getKey(), val);
 }
 return out;
}

代码示例来源:origin: io.hops/hadoop-yarn-client

private void validateContainerResourceChangeRequest(
  ContainerId containerId, Resource original, Resource target) {
 Preconditions.checkArgument(containerId != null,
   "ContainerId cannot be null");
 Preconditions.checkArgument(original != null,
   "Original resource capability cannot be null");
 Preconditions.checkArgument(!Resources.equals(Resources.none(), original)
     && Resources.fitsIn(Resources.none(), original),
   "Original resource capability must be greater than 0");
 Preconditions.checkArgument(target != null,
   "Target resource capability cannot be null");
 Preconditions.checkArgument(!Resources.equals(Resources.none(), target)
     && Resources.fitsIn(Resources.none(), target),
   "Target resource capability must be greater than 0");
}

代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-common

@Override
public boolean equals(Object obj) {
 if (obj instanceof NodeLabel) {
  NodeLabel other = (NodeLabel) obj;
  return Resources.equals(resource, other.getResource())
    && StringUtils.equals(labelName, other.getLabelName())
    && (other.getNumActiveNMs() == numActiveNMs); 
 }
 return false;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-yarn-common

@Override
public boolean equals(Object obj) {
 if (obj instanceof NodeLabel) {
  NodeLabel other = (NodeLabel) obj;
  return Resources.equals(resource, other.getResource())
    && StringUtils.equals(labelName, other.getLabelName())
    && (other.getNumActiveNMs() == numActiveNMs); 
 }
 return false;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

@Override
public Resource getMaxShare() {
 Resource maxResource = maxShare.getResource(scheduler.getClusterResource());
 // Max resource should be greater than or equal to min resource
 Resource result = Resources.componentwiseMax(maxResource, minShare);
 if (!Resources.equals(maxResource, result)) {
  LOG.warn(String.format("Queue %s has max resources %s less than "
    + "min resources %s", getName(), maxResource, minShare));
 }
 return result;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-client

private void validateContainerResourceChangeRequest(
  ContainerUpdateType updateType, ContainerId containerId,
  Resource original, Resource target) {
 Preconditions.checkArgument(containerId != null,
   "ContainerId cannot be null");
 Preconditions.checkArgument(original != null,
   "Original resource capability cannot be null");
 Preconditions.checkArgument(!Resources.equals(Resources.none(), original)
     && Resources.fitsIn(Resources.none(), original),
   "Original resource capability must be greater than 0");
 Preconditions.checkArgument(target != null,
   "Target resource capability cannot be null");
 Preconditions.checkArgument(!Resources.equals(Resources.none(), target)
     && Resources.fitsIn(Resources.none(), target),
   "Target resource capability must be greater than 0");
 if (ContainerUpdateType.DECREASE_RESOURCE == updateType) {
  Preconditions.checkArgument(Resources.fitsIn(target, original),
    "Target resource capability must fit in Original capability");
 } else {
  Preconditions.checkArgument(Resources.fitsIn(original, target),
    "Target resource capability must be more than Original capability");
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

@Override
public Collection<FiCaSchedulerApp> getPreemptableApps(String queueName,
  String partition) {
 TempQueuePerPartition tq = context.getQueueByPartition(queueName,
   partition);
 List<FiCaSchedulerApp> apps = new ArrayList<FiCaSchedulerApp>();
 for (TempAppPerPartition tmpApp : tq.getApps()) {
  // If a lower priority app was not selected to get preempted, mark such
  // apps out from preemption candidate selection.
  if (Resources.equals(tmpApp.getActuallyToBePreempted(),
    Resources.none())) {
   continue;
  }
  apps.add(tmpApp.app);
 }
 return apps;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-common

@Override
public boolean equals(Object obj) {
 if (obj instanceof RMNodeLabel) {
  RMNodeLabel other = (RMNodeLabel) obj;
  return Resources.equals(getResource(), other.getResource())
    && StringUtils.equals(getLabelName(), other.getLabelName())
    && (other.getNumActiveNMs() == getNumActiveNMs());
 }
 return false;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-yarn-server-resourcemanager

@Override
public Resource assignContainer(FSSchedulerNode node) {
 Resource assigned = Resources.none();
 // If this queue is over its limit, reject
 if (!assignContainerPreCheck(node)) {
  return assigned;
 }
 Collections.sort(childQueues, policy.getComparator());
 for (FSQueue child : childQueues) {
  assigned = child.assignContainer(node);
  if (!Resources.equals(assigned, Resources.none())) {
   break;
  }
 }
 return assigned;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager

@Override
public Resource assignContainer(FSSchedulerNode node) {
 Resource assigned = Resources.none();
 // If this queue is over its limit, reject
 if (!assignContainerPreCheck(node)) {
  return assigned;
 }
 Collections.sort(childQueues, policy.getComparator());
 for (FSQueue child : childQueues) {
  assigned = child.assignContainer(node);
  if (!Resources.equals(assigned, Resources.none())) {
   break;
  }
 }
 return assigned;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private boolean check(ReservationAllocation alloc, long start, long end,
  int containers, int mem, int cores) {
 Resource expectedResources =
   Resource.newInstance(mem * containers, cores * containers);
 // Verify that all allocations in [start,end) equal containers * (mem,cores)
 for (long i = start; i < end; i++) {
  if (!Resources.equals(alloc.getResourcesAtTime(i), expectedResources)) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private boolean check(ReservationAllocation cs, long start, long end,
  int containers, int mem, int cores) {
 boolean res = true;
 for (long i = start; i < end; i++) {
  res = res
    && Resources.equals(cs.getResourcesAtTime(i),
      Resource.newInstance(mem * containers, cores * containers));
 }
 return res;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager

private boolean check(ReservationAllocation cs, long start, long end,
  int containers, int mem, int cores) {
 boolean res = true;
 for (long i = start; i < end; i++) {
  res = res
    && Resources.equals(cs.getResourcesAtTime(i),
      Resource.newInstance(mem * containers, cores * containers));
 }
 return res;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private boolean canAllocateMore(CSAssignment assignment, int offswitchCount,
  int assignedContainers) {
 // Current assignment shouldn't be empty
 if (assignment == null
     || Resources.equals(assignment.getResource(), Resources.none())) {
  return false;
 }
 // offswitch assignment should be under threshold
 if (offswitchCount >= offswitchPerHeartbeatLimit) {
  return false;
 }
 // And it should not be a reserved container
 if (assignment.getAssignmentInformation().getNumReservations() > 0) {
  return false;
 }
 // assignMultipleEnabled should be ON,
 // and assignedContainers should be under threshold
 return assignMultipleEnabled
   && (maxAssignPerHeartbeat == -1
     || assignedContainers < maxAssignPerHeartbeat);
}

代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager

@Test
public void testUpdateDemand() {
 conf.set(FairSchedulerConfiguration.ASSIGN_MULTIPLE, "false");
 resourceManager = new MockRM(conf);
 resourceManager.start();
 scheduler = (FairScheduler) resourceManager.getResourceScheduler();
 scheduler.allocConf = mock(AllocationConfiguration.class);
 String queueName = "root.queue1";
 when(scheduler.allocConf.getMaxResources(queueName)).thenReturn(maxResource);
 when(scheduler.allocConf.getMinResources(queueName)).thenReturn(Resources.none());
 FSLeafQueue schedulable = new FSLeafQueue(queueName, scheduler, null);
 FSAppAttempt app = mock(FSAppAttempt.class);
 Mockito.when(app.getDemand()).thenReturn(maxResource);
 schedulable.addAppSchedulable(app);
 schedulable.addAppSchedulable(app);
 schedulable.updateDemand();
 assertTrue("Demand is greater than max allowed ",
   Resources.equals(schedulable.getDemand(), maxResource));
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private void verifyNoContainerAllocated(CSAssignment assignment) {
 Assert.assertTrue(Resources.equals(assignment.getResource(),
   Resources.none()));
 Assert
   .assertTrue(assignment.getAssignmentInformation().getNumAllocations() == 0);
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

protected void checkAppConsumption(FSAppAttempt app, Resource resource)
  throws InterruptedException {
 for (int i = 0; i < SLEEP_RETRIES; i++) {
  if (Resources.equals(resource, app.getCurrentConsumption())) {
   break;
  } else {
   Thread.sleep(SLEEP_DURATION);
  }
 }
 // available resource
 Assert.assertEquals(resource.getMemorySize(),
   app.getCurrentConsumption().getMemorySize());
 Assert.assertEquals(resource.getVirtualCores(),
   app.getCurrentConsumption().getVirtualCores());
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

@Test
public void testUpdateDemand() {
 conf.set(FairSchedulerConfiguration.ASSIGN_MULTIPLE, "false");
 resourceManager = new MockRM(conf);
 resourceManager.start();
 scheduler = (FairScheduler) resourceManager.getResourceScheduler();
 String queueName = "root.queue1";
 FSLeafQueue schedulable = new FSLeafQueue(queueName, scheduler, null);
 schedulable.setMaxShare(new ConfigurableResource(maxResource));
 assertEquals(schedulable.getMetrics().getMaxApps(), Integer.MAX_VALUE);
 assertEquals(schedulable.getMetrics().getSchedulingPolicy(),
   SchedulingPolicy.DEFAULT_POLICY.getName());
 FSAppAttempt app = mock(FSAppAttempt.class);
 Mockito.when(app.getDemand()).thenReturn(maxResource);
 Mockito.when(app.getResourceUsage()).thenReturn(Resources.none());
 schedulable.addApp(app, true);
 schedulable.addApp(app, true);
 schedulable.updateDemand();
 assertTrue("Demand is greater than max allowed ",
   Resources.equals(schedulable.getDemand(), maxResource));
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

protected void validateEffectiveMinResource(CSQueue leafQueue,
  String label, Map<String, QueueEntitlement> expectedQueueEntitlements) {
 ManagedParentQueue parentQueue = (ManagedParentQueue) leafQueue.getParent();
 Resource resourceByLabel = mockRM.getRMContext().getNodeLabelManager().
   getResourceByLabel(label, cs.getClusterResource());
 Resource effMinCapacity = Resources.multiply(resourceByLabel,
   expectedQueueEntitlements.get(label).getCapacity() * parentQueue
     .getQueueCapacities().getAbsoluteCapacity(label));
 assertEquals(effMinCapacity, Resources.multiply(resourceByLabel,
   leafQueue.getQueueCapacities().getAbsoluteCapacity(label)));
 assertEquals(effMinCapacity, leafQueue.getEffectiveCapacity(label));
 if (leafQueue.getQueueCapacities().getAbsoluteCapacity(label) > 0) {
  assertTrue(Resources
    .greaterThan(cs.getResourceCalculator(), cs.getClusterResource(),
      effMinCapacity, Resources.none()));
 } else{
  assertTrue(Resources.equals(effMinCapacity, Resources.none()));
 }
}

相关文章