protected void assertTemplateInfo(DeploymentTemplateInfo info, ManagedObject mo) {
    List<String> processed = new ArrayList<String>();
    for (ManagedProperty property : info.getProperties().values()) {
      //
      String propertyName = property.getName();

      // exclude
      if (getExcludes().contains(propertyName)) continue;
      //
      ManagedProperty other = mo.getProperty(propertyName);
      assertProperty(propertyName, property, other);

      log.debug("property: " + propertyName);
    }

    for (ManagedProperty other : info.getProperties().values()) {
      String otherName = other.getName();
      if (processed.contains(otherName)) continue;

      // exclude
      if (getExcludes().contains(otherName)) continue;

      ManagedProperty reference = mo.getProperty(otherName);
      if (isDebug() && reference == null) {
        log.debug("Does not exist in runtime MO: " + otherName);
        continue;
      }

      assertNotNull(otherName + " is included in the MO", reference);

      ManagementProperty annotation = null;
      if (reference.getAnnotations() != null) {
        annotation =
            (ManagementProperty) reference.getAnnotations().get(ManagementProperty.class.getName());
      } else {
        PropertyInfo propertyInfo = reference.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
        annotation =
            (ManagementProperty) propertyInfo.getAnnotation(ManagementProperty.class.getName());
      }
      if (isDebug() && annotation == null) {
        log.debug("@ManagedProperty not present: " + otherName);
        continue;
      }
      assertNotNull(otherName + " annotation present", annotation);

      if (isDebug() && annotation.includeInTemplate() == false) {
        log.error("includeInTemplate == true " + otherName);
        continue;
      }

      assertTrue(otherName + " includeInTemplate", annotation.includeInTemplate());
      assertProperty(otherName, other, reference);
    }
  }
Beispiel #2
0
 public static void convertMetricValuesToMeasurement(
     MeasurementReport report,
     ManagedProperty metricProperty,
     MeasurementScheduleRequest request,
     ResourceType resourceType,
     String deploymentName) {
   String metricName = metricProperty.getName();
   MetaType type = metricProperty.getMetaType();
   MetaValue value = metricProperty.getValue();
   if (value != null) {
     MeasurementAdapter measurementAdapter =
         MeasurementAdapterFactory.getMeasurementPropertyAdapter(type);
     MeasurementDefinition measurementDefinition =
         ResourceTypeUtils.getMeasurementDefinition(resourceType, metricName);
     if (measurementDefinition != null) {
       measurementAdapter.setMeasurementData(report, value, request, measurementDefinition);
     }
   } else {
     LOG.debug(
         "Unable to obtain metric data for resource: "
             + deploymentName
             + " metric: "
             + metricName);
   }
 }
  protected void createComponentTest(
      String templateName,
      Map<String, MetaValue> propValues,
      String deploymentName,
      ComponentType componentType,
      String componentName)
      throws Exception {
    ManagementView mgtView = getManagementView();
    DeploymentTemplateInfo dsInfo = mgtView.getTemplate(templateName);
    assertNotNull("template " + templateName + " found", dsInfo);
    Map<String, ManagedProperty> props = dsInfo.getProperties();

    for (String propName : propValues.keySet()) {
      ManagedProperty prop = props.get(propName);
      // If the property does not exist on the template we don't set it
      if (prop == null) continue;

      log.debug("template property before: " + prop.getName() + "," + prop.getValue());
      assertNotNull("property " + propName + " found in template " + templateName, prop);
      prop.setValue(propValues.get(propName));
      log.debug("template property after: " + prop.getName() + "," + prop.getValue());
    }

    // Assert map composite
    if (dsInfo.getProperties().get("config-property") != null)
      assertTrue(
          dsInfo.getProperties().get("config-property").getMetaType()
              instanceof MapCompositeMetaType);

    mgtView.applyTemplate(deploymentName, dsInfo);

    // reload the view
    activeView = null;
    mgtView = getManagementView();
    ManagedComponent dsMC = getManagedComponent(mgtView, componentType, componentName);
    assertNotNull(dsMC);

    Set<String> mcPropNames = new HashSet<String>(dsMC.getPropertyNames());
    for (String propName : propValues.keySet()) {
      ManagedProperty prop = dsMC.getProperty(propName);
      log.debug("Checking: " + propName);
      assertNotNull(propName, prop);
      Object propValue = prop.getValue();
      Object expectedValue = propValues.get(propName);
      if (propValue instanceof MetaValue) {
        if (prop.getMetaType().isComposite()) {
          // TODO / FIXME - compare composites
          log.warn("Not checking composite: " + propValue);
        } else {
          // Compare the MetaValues
          assertEquals(prop.getName(), expectedValue, propValue);
        }
      } else if (propValue != null) {
        fail(prop.getName() + " is not a MetaValue: " + propValue);
      }

      mcPropNames.remove(propName);
    }

    if (!mcPropNames.isEmpty()) {
      log.warn(getName() + "> untested properties: " + mcPropNames);
      for (String propName : mcPropNames) {
        ManagedProperty prop = dsMC.getProperty(propName);
        log.info(prop);
      }
    }
  }