Esempio n. 1
0
  private void loadScalingOrders(final IaasProvider iaas, final OMElement iaasElt) {
    // set scale up order
    Iterator<?> it =
        iaasElt.getChildrenWithName(new QName(CloudControllerConstants.SCALE_UP_ORDER_ELEMENT));

    if (it.hasNext()) {
      OMElement scaleUpOrderElt = (OMElement) it.next();

      try {
        iaas.setScaleUpOrder(Integer.parseInt(scaleUpOrderElt.getText()));
      } catch (NumberFormatException e) {
        String msg =
            CloudControllerConstants.SCALE_UP_ORDER_ELEMENT
                + " element contained"
                + " in "
                + xmlSource
                + ""
                + " has a value which is not an Integer value.";
        handleException(msg, e);
      }
    }

    if (it.hasNext()) {
      log.warn(
          xmlSource
              + " contains more than one "
              + CloudControllerConstants.SCALE_UP_ORDER_ELEMENT
              + " elements!"
              + " Elements other than the first will be neglected.");
    }

    if (iaas.getScaleUpOrder() == -1) {
      String msg =
          "Essential '"
              + CloudControllerConstants.SCALE_UP_ORDER_ELEMENT
              + "' element"
              + " has not specified in "
              + xmlSource;
      handleException(msg);
    }

    // set scale down order
    it = iaasElt.getChildrenWithName(new QName(CloudControllerConstants.SCALE_DOWN_ORDER_ELEMENT));

    if (it.hasNext()) {
      OMElement scaleDownElt = (OMElement) it.next();

      try {
        iaas.setScaleDownOrder(Integer.parseInt(scaleDownElt.getText()));
      } catch (NumberFormatException e) {
        String msg =
            CloudControllerConstants.SCALE_DOWN_ORDER_ELEMENT
                + " element contained"
                + " in "
                + xmlSource
                + ""
                + " has a value which is not an Integer value.";
        handleException(msg, e);
      }
    }

    if (it.hasNext()) {
      log.warn(
          xmlSource
              + " contains more than one "
              + CloudControllerConstants.SCALE_DOWN_ORDER_ELEMENT
              + " elements!"
              + " Elements other than the first will be neglected.");
    }

    if (iaas.getScaleDownOrder() == -1) {
      String msg =
          "Essential '"
              + CloudControllerConstants.SCALE_DOWN_ORDER_ELEMENT
              + "' element"
              + " has not specified in "
              + xmlSource;
      handleException(msg);
    }
  }