示例#1
0
  @Override
  @SuppressWarnings({"unchecked", "rawtypes"})
  public List<Constraint> extractConstraintsFromEnv(Map env) {
    List<Constraint> constraints = new ArrayList<Constraint>();
    if (env != null) {
      Set<String> affinityDefinitions = env.keySet();
      for (String affinityDef : affinityDefinitions) {
        if (affinityDef == null) {
          continue;
        }

        if (affinityDef.startsWith(ContainerAffinityConstraint.ENV_HEADER_AFFINITY_CONTAINER)) {
          affinityDef =
              affinityDef.substring(
                  ContainerAffinityConstraint.ENV_HEADER_AFFINITY_CONTAINER.length());
          AffinityConstraintDefinition def =
              extractAffinitionConstraintDefinitionFromEnv(affinityDef);
          if (def != null && !StringUtils.isEmpty(def.getValue())) {
            constraints.add(new ContainerAffinityConstraint(def, objectManager, instanceDao));
          }

        } else if (affinityDef.startsWith(HostAffinityConstraint.ENV_HEADER_AFFINITY_HOST_LABEL)) {
          affinityDef =
              affinityDef.substring(HostAffinityConstraint.ENV_HEADER_AFFINITY_HOST_LABEL.length());
          AffinityConstraintDefinition def =
              extractAffinitionConstraintDefinitionFromEnv(affinityDef);
          if (def != null && !StringUtils.isEmpty(def.getKey())) {
            constraints.add(new HostAffinityConstraint(def, allocatorDao));
          }

        } else if (affinityDef.startsWith(
            ContainerLabelAffinityConstraint.ENV_HEADER_AFFINITY_CONTAINER_LABEL)) {
          affinityDef =
              affinityDef.substring(
                  ContainerLabelAffinityConstraint.ENV_HEADER_AFFINITY_CONTAINER_LABEL.length());
          AffinityConstraintDefinition def =
              extractAffinitionConstraintDefinitionFromEnv(affinityDef);
          if (def != null && !StringUtils.isEmpty(def.getKey())) {
            constraints.add(new ContainerLabelAffinityConstraint(def, allocatorDao));
          }
        }
      }
    }
    return constraints;
  }
示例#2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private List<LockDefinition> extractAllocationLockDefinitionsFromEnv(Map env) {
    List<LockDefinition> constraints = new ArrayList<LockDefinition>();
    if (env != null) {
      Set<String> affinityDefinitions = env.keySet();
      for (String affinityDef : affinityDefinitions) {
        if (affinityDef == null) {
          continue;
        }

        if (affinityDef.startsWith(ContainerAffinityConstraint.ENV_HEADER_AFFINITY_CONTAINER)) {
          affinityDef =
              affinityDef.substring(
                  ContainerAffinityConstraint.ENV_HEADER_AFFINITY_CONTAINER.length());
          AffinityConstraintDefinition def =
              extractAffinitionConstraintDefinitionFromEnv(affinityDef);
          if (def != null && !StringUtils.isEmpty(def.getValue())) {
            constraints.add(
                new AllocateConstraintLock(AllocateConstraintLock.Type.AFFINITY, def.getValue()));
          }

        } else if (affinityDef.startsWith(
            ContainerLabelAffinityConstraint.ENV_HEADER_AFFINITY_CONTAINER_LABEL)) {
          affinityDef =
              affinityDef.substring(
                  ContainerLabelAffinityConstraint.ENV_HEADER_AFFINITY_CONTAINER_LABEL.length());
          AffinityConstraintDefinition def =
              extractAffinitionConstraintDefinitionFromEnv(affinityDef);
          if (def != null && !StringUtils.isEmpty(def.getKey())) {
            constraints.add(
                new AllocateConstraintLock(AllocateConstraintLock.Type.AFFINITY, def.getValue()));
          }
        }
      }
    }
    return constraints;
  }