Example #1
0
  /**
   * TODO
   *
   * @param physicalNode TODO
   * @param physicalResourceRequirements TODO
   * @return TODO
   */
  private boolean checkPhysicalNodeSatisfied(
      PhysicalNode physicalNode,
      List<
              org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual
                  .network.rev151010.virtual.node.instance.PhysicalResourceRequirement>
          physicalResourceRequirements)
      throws VNMappingException {
    List<
            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical
                .network.rev151010.physical.node.instance.Attribute>
        attributes = physicalNode.getAttribute();
    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network
            .rev151010.physical.node.instance.Attribute
        attribute;

    for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network
            .rev151010.virtual.node.instance.PhysicalResourceRequirement
        physicalResourceRequirement : physicalResourceRequirements) {
      attribute =
          getPhysicalNodeAttribute(attributes, physicalResourceRequirement.getAttributeName());

      if (null == attribute) {
        return false;
      }

      if (!checkPhysicalNodeAttributeSatisfied(attribute, physicalResourceRequirement)) {
        return false;
      }
    }

    return true;
  }
Example #2
0
  /**
   * TODO
   *
   * @param attribute TODO
   * @param physicalResourceRequirement TODO
   * @return TODO
   */
  private boolean checkPhysicalNodeAttributeSatisfied(
      org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network
              .rev151010.physical.node.instance.Attribute
          attribute,
      org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network
              .rev151010.virtual.node.instance.PhysicalResourceRequirement
          physicalResourceRequirement)
      throws VNMappingException {
    ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();

    InstanceIdentifier<PhysicalNodeAttributeDefinition> physicalNodeAttributeDefinitionIid =
        InstanceIdentifier.builder(PhysicalNodeAttributeDefinitions.class)
            .child(
                PhysicalNodeAttributeDefinition.class,
                new PhysicalNodeAttributeDefinitionKey(attribute.getAttributeName()))
            .build();
    Optional<PhysicalNodeAttributeDefinition> result;

    try {
      result =
          readOnlyTransaction
              .read(LogicalDatastoreType.CONFIGURATION, physicalNodeAttributeDefinitionIid)
              .get();
    } catch (InterruptedException exception) {
      throw new VNMappingException(
          "Can not read the physical node attribute definition "
              + "with attribute name "
              + attribute.getAttributeName().getValue()
              + ".");
    } catch (ExecutionException exception) {
      throw new VNMappingException(
          "Can not read the physical node attribute definition "
              + "with attribute name "
              + attribute.getAttributeName().getValue()
              + ".");
    }

    if (!result.isPresent()) {
      throw new VNMappingException(
          "The physical node attribute definition with attribute name "
              + attribute.getAttributeName().getValue()
              + " does not exist.");
    }

    PhysicalNodeAttributeDefinition physicalNodeAttributeDefinition = result.get();
    List<AttributeMatchPatterns.AttributeMatchPattern> attributeMatchPatterns =
        physicalNodeAttributeDefinition.getAttributeMatchPatterns().getAttributeMatchPattern();
    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network
            .rev151010.virtual.node.instance.PhysicalResourceRequirement.AttributeMatchPattern
        attributeMatchPattern = physicalResourceRequirement.getAttributeMatchPattern();

    if (!checkAttributeMatchPatternSpecified(attributeMatchPatterns, attributeMatchPattern)) {
      throw new VNMappingException(
          "The attribute match pattern "
              + attributeMatchPattern
              + " is not specified in the physical node attribute definition "
              + "with attribute name "
              + attribute.getAttributeName().getValue()
              + ".");
    }

    switch (physicalNodeAttributeDefinition.getAttributeValueType()) {
      case String:
        return checkAttributeStringValueSatisfied(
            attribute.getAttributeValue().getStringValue(),
            physicalResourceRequirement.getAttributeValue().getStringValue(),
            attributeMatchPattern);

      case Int:
        return checkAttributeIntegerValueSatisfied(
            attribute.getAttributeValue().getIntValue(),
            physicalResourceRequirement.getAttributeValue().getIntValue(),
            attributeMatchPattern);

      case Range:
        return checkAttributeRangeValueSatisfied(
            attribute.getAttributeValue().getIntValue(),
            physicalResourceRequirement.getAttributeValue().getRangeValue(),
            attributeMatchPattern);

      default:
        throw new VNMappingException(
            "Unsupported physical node attribute value type "
                + physicalNodeAttributeDefinition.getAttributeValueType()
                + ".");
        //                break;
    }

    //        return false;
  }