protected void assertProperty(String name, ManagedProperty property, ManagedProperty other) {
    assertNotNull(name, property);
    assertNotNull(name, other);

    assertEquals(name, property.getMetaType(), other.getMetaType());
    assertEquals(name, property.isMandatory(), other.isMandatory());
  }
Exemplo n.º 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);
   }
 }
 /**
  * Validate that there is only 1 DefaultDS ManagedComponent
  *
  * @throws Exception
  */
 public void testJTAComponentCount() throws Exception {
   ManagementView mgtView = getManagementView();
   ComponentType type = new ComponentType("MCBean", "JTA");
   Set<ManagedComponent> comps = mgtView.getComponentsForType(type);
   int count = comps.size();
   assertEquals("There is 1 MCBean:JTA ManagedComponent", 1, 1);
   ManagedComponent comp = comps.iterator().next();
   Map<String, ManagedProperty> props = comp.getProperties();
   for (ManagedProperty prop : props.values()) {
     log.info(prop + ", : " + prop.getValue());
   }
 }
  /**
   * Test adding a new no-tx-connection-factory deployment
   *
   * @throws Exception
   */
  public void testAddNoTxConnectionFactory() throws Exception {
    String jndiName = "TestNoTxCf";
    Map<String, MetaValue> propValues = new HashMap<String, MetaValue>();

    addCommonCfProperties(
        propValues, jndiName, "jms-ra.rar", "org.jboss.resource.adapter.jms.JmsConnectionFactory");

    Map<String, String> xaProps = new HashMap<String, String>();
    xaProps.put("SessionDefaultType", "javax.jms.Topic");
    xaProps.put("SessionDefaultType.type", "java.lang.String");
    xaProps.put("JmsProviderAdapterJNDI", "java:/DefaultJMSProvider");
    xaProps.put("JmsProviderAdapterJNDI.type", "java.lang.String");
    MetaValue metaValue = this.compositeValueMap(xaProps);
    propValues.put("config-property", metaValue);

    propValues.put(
        "config-property",
        new MapCompositeValueSupport(
            new HashMap<String, MetaValue>(), new MapCompositeMetaType(SimpleMetaType.STRING)));
    // todo: how to set the specific domain?
    // ApplicationManagedSecurityMetaData secDomain = new ApplicationManagedSecurityMetaData();
    // props.get("security-domain").setValue(secDomain);

    ComponentType compType = new ComponentType("ConnectionFactory", "NoTx");
    createComponentTest(
        "NoTxConnectionFactoryTemplate", propValues, "testNoTxCf", compType, jndiName);

    // Validate the config-property
    ManagementView mgtView = getManagementView();
    ManagedComponent dsMC = getManagedComponent(mgtView, compType, jndiName);
    ManagedProperty configProperty = dsMC.getProperty("config-property");
    assertNotNull(configProperty);
    MetaValue value = configProperty.getValue();
    assertTrue("MapCompositeMetaType", value.getMetaType() instanceof MapCompositeMetaType);

    MapCompositeValueSupport cValue = (MapCompositeValueSupport) value;
    cValue.put("testKey", new SimpleValueSupport(SimpleMetaType.STRING, "testValue"));

    mgtView.updateComponent(dsMC);

    mgtView = getManagementView();
    dsMC = getManagedComponent(mgtView, compType, jndiName);
    configProperty = dsMC.getProperty("config-property");
    assertNotNull(configProperty);
    cValue = (MapCompositeValueSupport) configProperty.getValue();
    assertNotNull(cValue.get("testKey"));
  }
  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);
    }
  }
  /**
   * Test adding a new tx-connection-factory deployment with xa enabled
   *
   * @throws Exception
   */
  public void testAddTxXAConnectionFactory() throws Exception {
    String jndiName = "TestTxCf";
    Map<String, MetaValue> propValues = new HashMap<String, MetaValue>();

    addCommonCfProperties(
        propValues, jndiName, "jms-ra.rar", "org.jboss.resource.adapter.jms.JmsConnectionFactory");

    Map<String, String> xaProps = new HashMap<String, String>();
    xaProps.put("SessionDefaultType", "javax.jms.Topic");
    xaProps.put("SessionDefaultType.type", "java.lang.String");
    xaProps.put("JmsProviderAdapterJNDI", "java:/DefaultJMSProvider");
    xaProps.put("JmsProviderAdapterJNDI.type", "java.lang.String");
    MetaValue metaValue = this.compositeValueMap(xaProps);

    propValues.put("config-property", metaValue);

    propValues.put("xa-transaction", SimpleValueSupport.wrap(Boolean.TRUE));
    propValues.put("xa-resource-timeout", SimpleValueSupport.wrap(new Integer(256)));
    propValues.put("interleaving", SimpleValueSupport.wrap(Boolean.TRUE));

    // todo: how to set the specific domain?
    // ApplicationManagedSecurityMetaData secDomain = new ApplicationManagedSecurityMetaData();
    // props.get("security-domain").setValue(secDomain);

    createComponentTest(
        "TxConnectionFactoryTemplate",
        propValues,
        "testTxXACf",
        new ComponentType("ConnectionFactory", "Tx"),
        jndiName);
    // Query the interleaving
    ManagementView mgtView = getManagementView();
    ComponentType type = new ComponentType("ConnectionFactory", "Tx");
    ManagedComponent txcf = mgtView.getComponent(jndiName, type);
    assertNotNull(txcf);
    ManagedProperty interleaving = txcf.getProperty("interleaving");
    assertNotNull("interleaving", interleaving);
    MetaValue interleavingMV = interleaving.getValue();
    assertNotNull("interleaving.value", interleavingMV);
    assertEquals(SimpleValueSupport.wrap(Boolean.TRUE), interleavingMV);
  }
Exemplo n.º 7
0
  private static void populateManagedPropertyFromProperty(
      Property property,
      PropertyDefinition propertyDefinition,
      @NotNull ManagedProperty managedProperty,
      @Nullable PropertySimple customProperty) {
    // See if there is a custom adapter defined for this property.
    PropertyAdapter propertyAdapter =
        PropertyAdapterFactory.getCustomPropertyAdapter(customProperty);

    MetaValue metaValue = managedProperty.getValue();
    if (metaValue != null) {
      LOG.trace(
          "Populating existing MetaValue of type "
              + metaValue.getMetaType()
              + " from RHQ property "
              + property
              + " with definition "
              + propertyDefinition
              + "...");
      if (propertyAdapter == null) {
        propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaValue);
      }
      propertyAdapter.populateMetaValueFromProperty(property, metaValue, propertyDefinition);
    } else {
      MetaType metaType = managedProperty.getMetaType();
      if (propertyAdapter == null) {
        propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaType);
      }
      LOG.trace(
          "Converting property "
              + property
              + " with definition "
              + propertyDefinition
              + " to MetaValue of type "
              + metaType
              + "...");
      metaValue = propertyAdapter.convertToMetaValue(property, propertyDefinition, metaType);
      managedProperty.setValue(metaValue);
    }
  }
  /**
   * Test adding a new hsql DataSource deployment
   *
   * @throws Exception
   */
  public void testAddXADataSource() throws Exception {
    String jndiName = "TestXaDs";
    Map<String, MetaValue> propValues = new HashMap<String, MetaValue>();

    addCommonDsProperties(propValues, jndiName, "jboss-xa-jdbc.rar", "javax.sql.DataSource");

    propValues.put("xa-datasource-class", SimpleValueSupport.wrap("org.hsqldb.jdbcDriver"));
    propValues.put("xa-resource-timeout", SimpleValueSupport.wrap(new Integer(256)));
    propValues.put("interleaving", SimpleValueSupport.wrap(true));

    HashMap<String, String> xaPropValues = new HashMap<String, String>();
    xaPropValues.put("URL", "jdbc:hsqldb");
    xaPropValues.put("User", "sa");
    xaPropValues.put("Password", "");

    // MetaValue metaValue = getMetaValueFactory().create(xaPropValues, getMapType());
    MetaValue metaValue = this.compositeValueMap(xaPropValues);
    propValues.put("xa-datasource-properties", metaValue);

    createComponentTest(
        "XADataSourceTemplate",
        propValues,
        "testXaDs",
        KnownComponentTypes.DataSourceTypes.XA.getType(),
        jndiName);

    // Query the interleaving
    ManagementView mgtView = getManagementView();
    ComponentType type = KnownComponentTypes.DataSourceTypes.XA.getType();
    ManagedComponent txcf = mgtView.getComponent(jndiName, type);
    assertNotNull(txcf);
    ManagedProperty interleaving = txcf.getProperty("interleaving");
    assertNotNull("interleaving", interleaving);
    MetaValue interleavingMV = interleaving.getValue();
    assertNotNull("interleaving.value", interleavingMV);
    assertEquals(
        "interleaving.value is true", SimpleValueSupport.wrap(Boolean.TRUE), interleavingMV);
  }
  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);
      }
    }
  }
Exemplo n.º 10
0
 protected void assertProperty(ManagedProperty property, MetaType metaType, MetaValue metaValue) {
   assertNotNull(property);
   assertEquals(property.getMetaType(), metaType);
   assertEquals(property.getValue(), metaValue);
 }
Exemplo n.º 11
0
 public static Configuration convertManagedObjectToConfiguration(
     Map<String, ManagedProperty> managedProperties,
     Map<String, PropertySimple> customProps,
     ResourceType resourceType) {
   Configuration config = new Configuration();
   ConfigurationDefinition configDef = resourceType.getResourceConfigurationDefinition();
   Map<String, PropertyDefinition> propDefs = configDef.getPropertyDefinitions();
   Set<String> propNames = managedProperties.keySet();
   for (String propName : propNames) {
     PropertyDefinition propertyDefinition = propDefs.get(propName);
     ManagedProperty managedProperty = managedProperties.get(propName);
     if (propertyDefinition == null) {
       if (!managedProperty.hasViewUse(ViewUse.STATISTIC))
         LOG.debug(
             resourceType
                 + " does not define a property corresponding to ManagedProperty '"
                 + propName
                 + "'.");
       continue;
     }
     if (managedProperty == null) {
       // This should never happen, but don't let it blow us up.
       LOG.error(
           "ManagedProperty '" + propName + "' has a null value in the ManagedProperties Map.");
       continue;
     }
     MetaValue metaValue = managedProperty.getValue();
     if (managedProperty.isRemoved() || metaValue == null) {
       // Don't even add a Property to the Configuration if the ManagedProperty is flagged as
       // removed or has a
       // null value.
       continue;
     }
     PropertySimple customProp = customProps.get(propName);
     PropertyAdapter propertyAdapter = PropertyAdapterFactory.getCustomPropertyAdapter(customProp);
     if (propertyAdapter == null) {
       propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaValue);
     }
     if (propertyAdapter == null) {
       LOG.error(
           "Unable to find a PropertyAdapter for ManagedProperty '"
               + propName
               + "' with MetaType ["
               + metaValue.getMetaType()
               + "] for ResourceType '"
               + resourceType.getName()
               + "'.");
       continue;
     }
     Property property;
     try {
       property = propertyAdapter.convertToProperty(metaValue, propertyDefinition);
     } catch (RuntimeException e) {
       throw new RuntimeException(
           "Failed to convert managed property "
               + managedProperty
               + " to RHQ property of type "
               + propertyDefinition
               + ".",
           e);
     }
     config.put(property);
   }
   return config;
 }