/**
   * 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"));
  }
Exemple #2
0
  public static void convertManagedOperationResults(
      ManagedOperation operation,
      MetaValue resultMetaValue,
      Configuration complexResults,
      OperationDefinition operationDefinition) {
    ConfigurationDefinition resultConfigDef =
        operationDefinition.getResultsConfigurationDefinition();
    // Don't return any results if we have no definition with which to display them
    if (resultConfigDef == null || resultConfigDef.getPropertyDefinitions().isEmpty()) {
      if (resultMetaValue != null) {
        LOG.error(
            "Plugin error: Operation ["
                + operationDefinition.getName()
                + "] is defined as returning no results, but it returned non-null results: "
                + resultMetaValue.toString());
      }
      return;
    } else {
      Map<String, PropertyDefinition> resultPropDefs = resultConfigDef.getPropertyDefinitions();
      // There should and must be only one property definition to map to the results from the
      // Profile Service,
      // otherwise there will be a huge mismatch.
      if (resultPropDefs.size() > 1)
        LOG.error(
            "Operation ["
                + operationDefinition.getName()
                + "] is defined with multiple result properties: "
                + resultPropDefs.values());

      PropertyDefinition resultPropDef = resultPropDefs.values().iterator().next();

      // Don't return any results, if the actual result object is null.
      if (resultMetaValue == null) {
        // Check if result is required or not, and if it is, log an error.
        if (resultPropDef.isRequired()) {
          LOG.error(
              "Plugin error: Operation ["
                  + operationDefinition.getName()
                  + "] is defined as returning a required result, but it returned null.");
        }
        return;
      }

      MetaType resultMetaType = operation.getReturnType();
      if (!MetaTypeUtils.instanceOf(resultMetaValue, resultMetaType))
        LOG.debug(
            "Profile Service Error: Result type ("
                + resultMetaType
                + ") of ["
                + operation.getName()
                + "] ManagedOperation does not match the type of the value returned by invoke() ("
                + resultMetaValue
                + ").");

      PropertyAdapter propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(resultMetaValue);
      Property resultProp = propertyAdapter.convertToProperty(resultMetaValue, resultPropDef);
      complexResults.put(resultProp);
    }
  }
Exemple #3
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);
    }
  }
Exemple #4
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;
 }