org.apache.hadoop.yarn.api.records.Resource.getResourceInformation()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(104)

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

Resource.getResourceInformation介绍

[英]Get ResourceInformation for a specified resource from a given index.
[中]从给定索引中获取指定资源的ResourceInformation。

代码示例

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

@Override
public ResourceInformation getResourceInformation(String resource)
  throws ResourceNotFoundException {
 ResourceInformation ri;
 try {
  ri = super.getResourceInformation(resource);
 } catch (ResourceNotFoundException e) {
  // Retry once to reinitialize resource information.
  initResourceMap();
  try {
   return super.getResourceInformation(resource);
  } catch (ResourceNotFoundException ee) {
   throw ee;
  }
 }
 return ri;
}

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

@Override
public ResourceInformation getResourceInformation(String resource) {
 initResources();
 return super.getResourceInformation(resource);
}

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

@Override
public float ratio(Resource a, Resource b) {
 float ratio = 0.0f;
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  ResourceInformation aResourceInformation = a.getResourceInformation(i);
  ResourceInformation bResourceInformation = b.getResourceInformation(i);
  float tmp = (float) aResourceInformation.getValue()
    / (float) bResourceInformation.getValue();
  ratio = ratio > tmp ? ratio : tmp;
 }
 return ratio;
}

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

@Override
public boolean fitsIn(Resource smaller, Resource bigger) {
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  ResourceInformation sResourceInformation = smaller
    .getResourceInformation(i);
  ResourceInformation bResourceInformation = bigger
    .getResourceInformation(i);
  if (sResourceInformation.getValue() > bResourceInformation.getValue()) {
   return false;
  }
 }
 return true;
}

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

@Override
public void setResourceInformation(String resource,
  ResourceInformation resourceInformation) {
 maybeInitBuilder();
 if (resource == null || resourceInformation == null) {
  throw new IllegalArgumentException(
    "resource and/or resourceInformation cannot be null");
 }
 ResourceInformation storedResourceInfo = super.getResourceInformation(
   resource);
 ResourceInformation.copy(resourceInformation, storedResourceInfo);
}

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

@Override
public boolean isAnyMajorResourceZeroOrNegative(Resource resource) {
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  ResourceInformation resourceInformation = resource.getResourceInformation(
    i);
  if (resourceInformation.getValue() <= 0L) {
   return true;
  }
 }
 return false;
}

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

@Override
 public boolean isAnyMajorResourceAboveZero(Resource resource) {
  int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
  for (int i = 0; i < maxLength; i++) {
   ResourceInformation resourceInformation = resource.getResourceInformation(
     i);
   if (resourceInformation.getValue() > 0) {
    return true;
   }
  }
  return false;
 }
}

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

@Override
public long computeAvailableContainers(Resource available,
  Resource required) {
 long min = Long.MAX_VALUE;
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  ResourceInformation availableResource = available
    .getResourceInformation(i);
  ResourceInformation requiredResource = required.getResourceInformation(i);
  if (requiredResource.getValue() != 0) {
   long tmp = availableResource.getValue() / requiredResource.getValue();
   min = min < tmp ? min : tmp;
  }
 }
 return min > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) min;
}

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

private static Map<String, ResourceInformation> getZeroResources(
  Resource resource) {
 Map<String, ResourceInformation> resourceInformations = Maps.newHashMap();
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  ResourceInformation resourceInformation =
    resource.getResourceInformation(i);
  if (resourceInformation.getValue() == 0L) {
   resourceInformations.put(resourceInformation.getName(),
     resourceInformation);
  }
 }
 return resourceInformations;
}

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

public static Resource addTo(Resource lhs, Resource rhs) {
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  try {
   ResourceInformation rhsValue = rhs.getResourceInformation(i);
   ResourceInformation lhsValue = lhs.getResourceInformation(i);
   lhs.setResourceValue(i, lhsValue.getValue() + rhsValue.getValue());
  } catch (ResourceNotFoundException ye) {
   LOG.warn("Resource is missing:" + ye.getMessage());
   continue;
  }
 }
 return lhs;
}

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

public static Resource subtractFrom(Resource lhs, Resource rhs) {
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  try {
   ResourceInformation rhsValue = rhs.getResourceInformation(i);
   ResourceInformation lhsValue = lhs.getResourceInformation(i);
   lhs.setResourceValue(i, lhsValue.getValue() - rhsValue.getValue());
  } catch (ResourceNotFoundException ye) {
   LOG.warn("Resource is missing:" + ye.getMessage());
   continue;
  }
 }
 return lhs;
}

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

public static Resource multiplyTo(Resource lhs, double by) {
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  try {
   ResourceInformation lhsValue = lhs.getResourceInformation(i);
   lhs.setResourceValue(i, (long) (lhsValue.getValue() * by));
  } catch (ResourceNotFoundException ye) {
   LOG.warn("Resource is missing:" + ye.getMessage());
   continue;
  }
 }
 return lhs;
}

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

/**
 * Get the value for a specified resource. No information about the units is
 * returned.
 *
 * @param resource name of the resource
 * @return the value for the resource
 */
@Public
@InterfaceStability.Unstable
public long getResourceValue(String resource) {
 return getResourceInformation(resource).getValue();
}

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

@Override
public Resource multiplyAndNormalizeUp(Resource r, double[] by,
  Resource stepFactor) {
 Resource ret = Resource.newInstance(r);
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  ResourceInformation rResourceInformation = r.getResourceInformation(i);
  ResourceInformation stepFactorResourceInformation = stepFactor
    .getResourceInformation(i);
  long rValue = rResourceInformation.getValue();
  long stepFactorValue = stepFactorResourceInformation.getValue();
  ret.setResourceValue(i, ResourceCalculator
    .roundUp((long) Math.ceil(rValue * by[i]), stepFactorValue));
 }
 return ret;
}

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

public static Resource multiplyAndRoundDown(Resource lhs, double by) {
 Resource out = clone(lhs);
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  try {
   ResourceInformation lhsValue = lhs.getResourceInformation(i);
   out.setResourceValue(i, (long) (lhsValue.getValue() * by));
  } catch (ResourceNotFoundException ye) {
   LOG.warn("Resource is missing:" + ye.getMessage());
   continue;
  }
 }
 return out;
}

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

public Resource divideAndCeil(Resource numerator, long denominator) {
 Resource ret = Resource.newInstance(numerator);
 int maxLength = ResourceUtils.getNumberOfKnownResourceTypes();
 for (int i = 0; i < maxLength; i++) {
  ResourceInformation resourceInformation = ret.getResourceInformation(i);
  resourceInformation
    .setValue(divideAndCeil(resourceInformation.getValue(), denominator));
 }
 return ret;
}

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

@Test
public void testGetVirtualCores() {
 Resource res = new ResourcePBImpl();
 long vcores = Integer.MAX_VALUE + 1L;
 res.getResourceInformation("vcores").setValue(vcores);
 assertEquals("No need to cast if both are long", vcores,
   res.getResourceInformation("vcores").getValue());
 assertEquals("Cast to Integer.MAX_VALUE if the long is greater than "
   + "Integer.MAX_VALUE", Integer.MAX_VALUE, res.getVirtualCores());
}

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

@Test
public void testEmptyResourcePBInit() throws Exception {
 Resource res = new ResourcePBImpl();
 // Assert to check it sets resource value and unit to default.
 Assert.assertEquals(0, res.getMemorySize());
 Assert.assertEquals(ResourceInformation.MEMORY_MB.getUnits(),
   res.getResourceInformation(ResourceInformation.MEMORY_MB.getName())
     .getUnits());
 Assert.assertEquals(ResourceInformation.VCORES.getUnits(),
   res.getResourceInformation(ResourceInformation.VCORES.getName())
     .getUnits());
}

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

@Test
public void testCreateResourceWithSameLongValue() throws Exception {
 unsetExtraResourceType();
 setupExtraResourceType();
 Resource res = Resources.createResourceWithSameValue(11L);
 assertEquals(11L, res.getMemorySize());
 assertEquals(11, res.getVirtualCores());
 assertEquals(11L, res.getResourceInformation(EXTRA_RESOURCE_TYPE).getValue());
}

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

@Test
public void testCreateResourceWithSameIntValue() throws Exception {
 unsetExtraResourceType();
 setupExtraResourceType();
 Resource res = Resources.createResourceWithSameValue(11);
 assertEquals(11, res.getMemorySize());
 assertEquals(11, res.getVirtualCores());
 assertEquals(11, res.getResourceInformation(EXTRA_RESOURCE_TYPE).getValue());
}

相关文章