예제 #1
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);
    }
  }
  /**
   * Removes PropertyDefinition items from the configuration
   *
   * @param newConfigDef new configuration being merged into the existing one
   * @param existingConfigDef existing persisted configuration
   * @param existingProperties list of existing properties to inspect for potential removal
   */
  private ConfigurationDefinition removeNoLongerUsedProperties(
      ConfigurationDefinition newConfigDef,
      ConfigurationDefinition existingConfigDef,
      List<PropertyDefinition> existingProperties) {

    List<PropertyDefinition> propDefsToDelete = new ArrayList<PropertyDefinition>();
    for (PropertyDefinition existingPropDef : existingProperties) {
      PropertyDefinition newPropDef = newConfigDef.get(existingPropDef.getName());
      if (newPropDef == null) {
        // not in new configuration
        propDefsToDelete.add(existingPropDef);
      }
    }

    if (!propDefsToDelete.isEmpty()) {
      log.debug(
          "Deleting obsolete props from configDef ["
              + existingConfigDef
              + "]: "
              + propDefsToDelete);
      for (PropertyDefinition propDef : propDefsToDelete) {
        existingConfigDef.getPropertyDefinitions().remove(propDef.getName());
        existingProperties.remove(propDef); // does not operate on original list!!
      }
      existingConfigDef = entityManager.merge(existingConfigDef);
    }

    return existingConfigDef;
  }
예제 #3
0
 /**
  * Takes the Configuration parameter object and converts it into a MetaValue array, which can them
  * be passed in with the invoke method to the ProfileService to fire the operation of a resource.
  *
  * @param managedOperation Operation that will be fired and stores the parameter types for the
  *     operation
  * @param parameters set of Parameter Values that the OperationFacet sent to the Component
  * @param operationDefinition the RHQ operation definition
  * @return MetaValue[] array of MetaValues representing the parameters; if there are no
  *     parameters, an empty array will be returned
  */
 @NotNull
 public static MetaValue[] convertOperationsParametersToMetaValues(
     @NotNull ManagedOperation managedOperation,
     @NotNull Configuration parameters,
     @NotNull OperationDefinition operationDefinition) {
   ConfigurationDefinition paramsConfigDef =
       operationDefinition.getParametersConfigurationDefinition();
   if (paramsConfigDef == null) return new MetaValue[0];
   ManagedParameter[] managedParams =
       managedOperation.getParameters(); // this is guaranteed to be non-null
   Map<String, PropertyDefinition> paramPropDefs = paramsConfigDef.getPropertyDefinitions();
   MetaValue[] paramMetaValues = new MetaValue[managedParams.length];
   for (int i = 0; i < managedParams.length; i++) {
     ManagedParameter managedParam = managedParams[i];
     String paramName = managedParam.getName();
     Property paramProp = parameters.get(paramName);
     PropertyDefinition paramPropDef = paramPropDefs.get(paramName);
     MetaType metaType = managedParam.getMetaType();
     PropertyAdapter propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaType);
     LOG.trace(
         "Converting RHQ operation param property "
             + paramProp
             + " with definition "
             + paramPropDef
             + " to MetaValue of type "
             + metaType
             + "...");
     MetaValue paramMetaValue =
         propertyAdapter.convertToMetaValue(paramProp, paramPropDef, metaType);
     // NOTE: There's no need to set the value on the ManagedParameter, since the invoke() API
     // takes an array of
     //       MetaValues.
     paramMetaValues[i] = paramMetaValue;
   }
   return paramMetaValues;
 }
  public ConfigurationDefinitionUpdateReport updateConfigurationDefinition(
      ConfigurationDefinition newDefinition, ConfigurationDefinition existingDefinition) {

    ConfigurationDefinitionUpdateReport updateReport =
        new ConfigurationDefinitionUpdateReport(existingDefinition);

    /*
     * handle grouped and ungrouped properties separately. for ungrouped, we don't need to care about the group, but
     * for the grouped ones we need to start at group level and then look at the properties. This is done below.
     *
     * First look at the ungrouped ones.
     */

    List<PropertyDefinition> existingPropertyDefinitions =
        existingDefinition.getNonGroupedProperties();
    List<PropertyDefinition> newPropertyDefinitions = newDefinition.getNonGroupedProperties();
    if (existingPropertyDefinitions != null) {
      for (PropertyDefinition newProperty : newPropertyDefinitions) {
        PropertyDefinition existingProp = existingDefinition.get(newProperty.getName());
        if (existingProp != null) {
          log.debug("Updating nonGrouped property [" + existingProp + "]");

          updatePropertyDefinition(existingProp, newProperty);
          updateReport.addUpdatedPropertyDefinition(newProperty);
        } else {
          log.debug("Adding nonGrouped property [" + newProperty + "]");

          existingDefinition.put(newProperty);
          updateReport.addNewPropertyDefinition(newProperty);
        }
      }

      existingDefinition =
          removeNoLongerUsedProperties(
              newDefinition, existingDefinition, existingPropertyDefinitions);

    } else {
      // TODO what if existingDefinitions is null?
      // we probably don't run in here, as the initial persisting is done
      // somewhere else.
    }

    /*
     * Now update / delete contained groups We need to be careful here, as groups are present in PropertyDefinition
     * as "backlink" from PropertyDefinition to group
     */
    List<PropertyGroupDefinition> existingGroups = existingDefinition.getGroupDefinitions();
    List<PropertyGroupDefinition> newGroups = newDefinition.getGroupDefinitions();

    List<PropertyGroupDefinition> toPersist = missingInFirstList(existingGroups, newGroups);
    List<PropertyGroupDefinition> toDelete = missingInFirstList(newGroups, existingGroups);
    List<PropertyGroupDefinition> toUpdate = intersection(existingGroups, newGroups);

    // delete groups no longer present
    for (PropertyGroupDefinition group : toDelete) {
      List<PropertyDefinition> groupedDefinitions =
          existingDefinition.getPropertiesInGroup(group.getName());

      // first look for contained stuff
      for (PropertyDefinition def : groupedDefinitions) {
        log.debug("Removing property [" + def + "] from group [" + group + "]");

        existingPropertyDefinitions.remove(def);
        existingDefinition.getPropertyDefinitions().remove(def.getName());
        def.setPropertyGroupDefinition(null);
        entityManager.remove(def);
      }

      // then remove the definition itself
      log.debug("Removing group [" + group + "]");

      existingGroups.remove(group);
      entityManager.remove(group);
    }

    // update existing groups that stay
    for (PropertyGroupDefinition group : toUpdate) {
      String groupName = group.getName();

      List<PropertyDefinition> newGroupedDefinitions =
          newDefinition.getPropertiesInGroup(groupName);
      for (PropertyDefinition nDef : newGroupedDefinitions) {
        PropertyDefinition existingProperty =
            existingDefinition.getPropertyDefinitions().get(nDef.getName());
        if (existingProperty != null) {
          log.debug("Updating property [" + nDef + "] in group [" + group + "]");

          updatePropertyDefinition(existingProperty, nDef);
          updateReport.addUpdatedPropertyDefinition(nDef);

        } else {
          log.debug("Adding property [" + nDef + "] to group [" + group + "]");

          existingDefinition.put(nDef);
          updateReport.addNewPropertyDefinition(nDef);
        }
      }

      // delete outdated properties of this group
      existingDefinition =
          removeNoLongerUsedProperties(
              newDefinition,
              existingDefinition,
              existingDefinition.getPropertiesInGroup(groupName));
    }

    // persist new groups
    for (PropertyGroupDefinition group : toPersist) {

      // First persist a new group definition and then link the properties to it
      log.debug("Persisting new group [" + group + "]");

      entityManager.persist(group);
      existingGroups.add(group); // iterating over this does not update the underlying crap

      List<PropertyDefinition> defs = newDefinition.getPropertiesInGroup(group.getName());
      Map<String, PropertyDefinition> exPDefs = existingDefinition.getPropertyDefinitions();
      for (PropertyDefinition def : defs) {
        entityManager.persist(def);
        def.setPropertyGroupDefinition(group);
        def.setConfigurationDefinition(existingDefinition);

        if (!exPDefs.containsKey(def.getName())) {
          updateReport.addNewPropertyDefinition(def);
        }

        exPDefs.put(def.getName(), def);
      }
    }

    /*
     * Now work on the templates.
     */
    Map<String, ConfigurationTemplate> existingTemplates = existingDefinition.getTemplates();
    Map<String, ConfigurationTemplate> newTemplates = newDefinition.getTemplates();
    List<String> toRemove = new ArrayList<String>();
    List<String> templatesToUpdate = new ArrayList<String>();

    for (String name : existingTemplates.keySet()) {
      if (newTemplates.containsKey(name)) {
        templatesToUpdate.add(name);
      } else {
        toRemove.add(name);
      }
    }

    for (String name : toRemove) {
      log.debug("Removing template [" + name + "]");

      ConfigurationTemplate template = existingTemplates.remove(name);
      entityManager.remove(template);
    }

    for (String name : templatesToUpdate) {
      log.debug("Updating template [" + name + "]");

      updateTemplate(existingDefinition.getTemplate(name), newTemplates.get(name));
    }

    for (String name : newTemplates.keySet()) {
      // add completely new templates
      if (!existingTemplates.containsKey(name)) {
        log.debug("Adding template [" + name + "]");

        ConfigurationTemplate newTemplate = newTemplates.get(name);

        // we need to set a valid configurationDefinition, where we will live on.
        newTemplate.setConfigurationDefinition(existingDefinition);

        entityManager.persist(newTemplate);
        existingTemplates.put(name, newTemplate);
      }
    }

    return updateReport;
  }
예제 #5
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Test
  public void loadResourceConfigurationWithType() throws Exception {
    // tell the method story as it happens: mock or create dependencies and configure
    // those dependencies to get the method under test to completion.
    ResourceContext mockResourceContext = mock(ResourceContext.class);

    ResourceType mockResourceType = mock(ResourceType.class);
    when(mockResourceContext.getResourceType()).thenReturn(mockResourceType);

    ConfigurationDefinition mockConfigurationDefinition = mock(ConfigurationDefinition.class);
    when(mockResourceType.getResourceConfigurationDefinition())
        .thenReturn(mockConfigurationDefinition);

    ConfigurationTemplate mockConfigurationTemplate = mock(ConfigurationTemplate.class);
    when(mockConfigurationDefinition.getDefaultTemplate()).thenReturn(mockConfigurationTemplate);

    Configuration mockConfiguration = mock(Configuration.class);
    when(mockConfigurationTemplate.getConfiguration()).thenReturn(mockConfiguration);

    Property mockProperty = mock(Property.class);
    when(mockConfiguration.get(eq("__type"))).thenReturn(mockProperty);

    Map<String, PropertyDefinition> mockMap = (Map<String, PropertyDefinition>) mock(Map.class);
    when(mockConfigurationDefinition.getPropertyDefinitions()).thenReturn(mockMap);

    ConfigurationLoadDelegate mockConfigurationLoadDelegate = mock(ConfigurationLoadDelegate.class);
    PowerMockito.whenNew(ConfigurationLoadDelegate.class)
        .withParameterTypes(ConfigurationDefinition.class, ASConnection.class, Address.class)
        .withArguments(
            any(ConfigurationDefinition.class), any(ASConnection.class), any(Address.class))
        .thenReturn(mockConfigurationLoadDelegate);

    when(mockConfigurationLoadDelegate.loadResourceConfiguration()).thenReturn(mockConfiguration);

    PropertySimple pathPropertySimple = new PropertySimple("path", "abc=def,xyz=test1");
    when(mockConfiguration.get(eq("path"))).thenReturn(pathPropertySimple);
    when(mockResourceContext.getPluginConfiguration()).thenReturn(mockConfiguration);

    ASConnection mockASConnection = mock(ASConnection.class);

    PropertySimple typePropertySimple = new PropertySimple("__type", "xyz");
    PowerMockito.whenNew(PropertySimple.class)
        .withParameterTypes(String.class, Object.class)
        .withArguments(eq("__type"), eq("xyz"))
        .thenReturn(typePropertySimple);

    // create object to test and inject required dependencies
    TemplatedComponent objectUnderTest = new TemplatedComponent();

    objectUnderTest.context = mockResourceContext;
    objectUnderTest.testConnection = mockASConnection;

    // run code under test
    Configuration result = objectUnderTest.loadResourceConfiguration();

    // verify the results (Assert and mock verification)
    Assert.assertEquals(result, mockConfiguration);

    verify(mockMap, times(1)).remove(eq("__type"));
    verify(mockConfiguration, times(1)).get(eq("__type"));
    verify(mockConfiguration, never()).get(eq("__name"));
    verify(mockConfiguration, times(1)).get(eq("path"));
    verify(mockConfiguration, times(1)).put(eq(typePropertySimple));

    PowerMockito.verifyNew(PropertySimple.class).withArguments(eq("__type"), eq("xyz"));
    PowerMockito.verifyNew(ConfigurationLoadDelegate.class)
        .withArguments(
            any(ConfigurationDefinition.class), eq(mockASConnection), any(Address.class));
  }
예제 #6
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Test
  public void updateResourceConfigurationWithName() throws Exception {
    // tell the method story as it happens: mock or create dependencies and configure
    // those dependencies to get the method under test to completion.
    ResourceContext mockResourceContext = mock(ResourceContext.class);

    ResourceType mockResourceType = mock(ResourceType.class);
    when(mockResourceContext.getResourceType()).thenReturn(mockResourceType);

    ConfigurationDefinition mockConfigurationDefinition = mock(ConfigurationDefinition.class);
    when(mockResourceType.getResourceConfigurationDefinition())
        .thenReturn(mockConfigurationDefinition);

    ConfigurationDefinition mockConfigurationDefinitionCopy = mock(ConfigurationDefinition.class);
    when(mockConfigurationDefinition.copy()).thenReturn(mockConfigurationDefinitionCopy);

    ConfigurationTemplate mockConfigurationTemplate = mock(ConfigurationTemplate.class);
    when(mockConfigurationDefinitionCopy.getDefaultTemplate())
        .thenReturn(mockConfigurationTemplate);

    Configuration mockConfiguration = mock(Configuration.class);
    when(mockConfigurationTemplate.getConfiguration()).thenReturn(mockConfiguration);

    Property mockProperty = mock(Property.class);
    when(mockConfiguration.get(eq("__type"))).thenReturn(null);
    when(mockConfiguration.get(eq("__name"))).thenReturn(mockProperty);

    Map<String, PropertyDefinition> mockMap = (Map<String, PropertyDefinition>) mock(Map.class);
    when(mockConfigurationDefinitionCopy.getPropertyDefinitions()).thenReturn(mockMap);

    ConfigurationUpdateReport mockReport = mock(ConfigurationUpdateReport.class);
    when(mockReport.getConfiguration()).thenReturn(mockConfiguration);

    ConfigurationWriteDelegate mockConfigurationWriteDelegate =
        mock(ConfigurationWriteDelegate.class);
    PowerMockito.whenNew(ConfigurationWriteDelegate.class)
        .withParameterTypes(ConfigurationDefinition.class, ASConnection.class, Address.class)
        .withArguments(
            any(ConfigurationDefinition.class), any(ASConnection.class), any(Address.class))
        .thenReturn(mockConfigurationWriteDelegate);

    ASConnection mockASConnection = mock(ASConnection.class);
    when(mockASConnection.execute(any(ReadResource.class))).thenReturn(new Result());

    // create object to test and inject required dependencies
    TemplatedComponent objectUnderTest = new TemplatedComponent();

    objectUnderTest.context = mockResourceContext;
    objectUnderTest.testConnection = mockASConnection;

    // run code under test
    objectUnderTest.updateResourceConfiguration(mockReport);

    // verify the results (Assert and mock verification)
    verify(mockMap, times(1)).remove(eq("__name"));
    verify(mockConfiguration, times(1)).get(eq("__type"));
    verify(mockConfiguration, times(1)).get(eq("__name"));
    verify(mockConfiguration, times(1)).remove(eq("__name"));

    PowerMockito.verifyNew(ConfigurationWriteDelegate.class)
        .withArguments(
            any(ConfigurationDefinition.class), eq(mockASConnection), any(Address.class));
  }
예제 #7
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;
 }
예제 #8
0
  /**
   * This returns the metadata describing the system settings.
   *
   * @param config the current configuration settings from the server. Some values will be converted
   *     to the types the definition will expect - for example, the JAAS setting will not be "LDAP"
   *     or "JDBC" as the server would know it, rather the value will be "true" or "false" (i.e. is
   *     ldap enabled or not?)
   * @param driftPlugins the set of drift server plugins that are currently deployed
   * @return system settings config def
   */
  private ConfigurationDefinition getSystemSettingsDefinition(
      Configuration config, Map<String, String> driftPlugins) {
    ConfigurationDefinition def =
        new ConfigurationDefinition("sysset", MSG.view_adminConfig_systemSettings());

    ///////////////////////////////////
    // General Configuration Properties

    PropertyGroupDefinition generalGroup = new PropertyGroupDefinition("general");
    generalGroup.setDisplayName(MSG.view_admin_systemSettings_group_general());
    generalGroup.setDefaultHidden(false);
    generalGroup.setOrder(0);

    PropertyDefinitionSimple baseUrl =
        new PropertyDefinitionSimple(
            Constant.BaseURL,
            MSG.view_admin_systemSettings_BaseURL_desc(),
            true,
            PropertySimpleType.STRING);
    baseUrl.setDisplayName(MSG.view_admin_systemSettings_BaseURL_name());
    baseUrl.setPropertyGroupDefinition(generalGroup);
    baseUrl.setDefaultValue("http://localhost:7080");
    def.put(baseUrl);

    PropertyDefinitionSimple agentMaxQuietTimeAllowed =
        new PropertyDefinitionSimple(
            Constant.AgentMaxQuietTimeAllowed,
            MSG.view_admin_systemSettings_AgentMaxQuietTimeAllowed_desc(),
            true,
            PropertySimpleType.INTEGER);
    agentMaxQuietTimeAllowed.setDisplayName(
        MSG.view_admin_systemSettings_AgentMaxQuietTimeAllowed_name());
    agentMaxQuietTimeAllowed.setPropertyGroupDefinition(generalGroup);
    agentMaxQuietTimeAllowed.addConstraints(
        new IntegerRangeConstraint(
            Long.valueOf(2),
            null)); // don't allow less than 2m since it will cause too many false backfills
    agentMaxQuietTimeAllowed.setDefaultValue("15");
    def.put(agentMaxQuietTimeAllowed);

    PropertyDefinitionSimple enableAgentAutoUpdate =
        new PropertyDefinitionSimple(
            Constant.EnableAgentAutoUpdate,
            MSG.view_admin_systemSettings_EnableAgentAutoUpdate_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    enableAgentAutoUpdate.setDisplayName(
        MSG.view_admin_systemSettings_EnableAgentAutoUpdate_name());
    enableAgentAutoUpdate.setPropertyGroupDefinition(generalGroup);
    enableAgentAutoUpdate.setDefaultValue("true");
    def.put(enableAgentAutoUpdate);

    PropertyDefinitionSimple enableDebugMode =
        new PropertyDefinitionSimple(
            Constant.EnableDebugMode,
            MSG.view_admin_systemSettings_EnableDebugMode_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    enableDebugMode.setDisplayName(MSG.view_admin_systemSettings_EnableDebugMode_name());
    enableDebugMode.setPropertyGroupDefinition(generalGroup);
    enableDebugMode.setDefaultValue("false");
    def.put(enableDebugMode);

    PropertyDefinitionSimple enableExperimentalFeatures =
        new PropertyDefinitionSimple(
            Constant.EnableExperimentalFeatures,
            MSG.view_admin_systemSettings_EnableExperimentalFeatures_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    enableExperimentalFeatures.setDisplayName(
        MSG.view_admin_systemSettings_EnableExperimentalFeatures_name());
    enableExperimentalFeatures.setPropertyGroupDefinition(generalGroup);
    enableExperimentalFeatures.setDefaultValue("false");
    def.put(enableExperimentalFeatures);

    ////////////////////////////////////////
    // Data Manager Configuration Properties

    PropertyGroupDefinition dataManagerGroup = new PropertyGroupDefinition("datamanager");
    dataManagerGroup.setDisplayName(MSG.view_admin_systemSettings_group_dataMgr());
    dataManagerGroup.setDefaultHidden(false);
    dataManagerGroup.setOrder(1);

    PropertyDefinitionSimple dataMaintenance =
        new PropertyDefinitionSimple(
            Constant.DataMaintenance,
            MSG.view_admin_systemSettings_DataMaintenance_desc(),
            true,
            PropertySimpleType.INTEGER);
    dataMaintenance.setDisplayName(MSG.view_admin_systemSettings_DataMaintenance_name());
    dataMaintenance.setPropertyGroupDefinition(dataManagerGroup);
    dataMaintenance.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    dataMaintenance.setDefaultValue("1");
    def.put(dataMaintenance);

    PropertyDefinitionSimple availabilityPurge =
        new PropertyDefinitionSimple(
            Constant.AvailabilityPurge,
            MSG.view_admin_systemSettings_AvailabilityPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    availabilityPurge.setDisplayName(MSG.view_admin_systemSettings_AvailabilityPurge_name());
    availabilityPurge.setPropertyGroupDefinition(dataManagerGroup);
    availabilityPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    availabilityPurge.setDefaultValue("365");
    def.put(availabilityPurge);

    PropertyDefinitionSimple alertPurge =
        new PropertyDefinitionSimple(
            Constant.AlertPurge,
            MSG.view_admin_systemSettings_AlertPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    alertPurge.setDisplayName(MSG.view_admin_systemSettings_AlertPurge_name());
    alertPurge.setPropertyGroupDefinition(dataManagerGroup);
    alertPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    alertPurge.setDefaultValue("31");
    def.put(alertPurge);

    PropertyDefinitionSimple traitPurge =
        new PropertyDefinitionSimple(
            Constant.TraitPurge,
            MSG.view_admin_systemSettings_TraitPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    traitPurge.setDisplayName(MSG.view_admin_systemSettings_TraitPurge_name());
    traitPurge.setPropertyGroupDefinition(dataManagerGroup);
    traitPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    traitPurge.setDefaultValue("365");
    def.put(traitPurge);

    PropertyDefinitionSimple rtDataPurge =
        new PropertyDefinitionSimple(
            Constant.RtDataPurge,
            MSG.view_admin_systemSettings_RtDataPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    rtDataPurge.setDisplayName(MSG.view_admin_systemSettings_RtDataPurge_name());
    rtDataPurge.setPropertyGroupDefinition(dataManagerGroup);
    rtDataPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    rtDataPurge.setDefaultValue("31");
    def.put(rtDataPurge);

    PropertyDefinitionSimple eventPurge =
        new PropertyDefinitionSimple(
            Constant.EventPurge,
            MSG.view_admin_systemSettings_EventPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    eventPurge.setDisplayName(MSG.view_admin_systemSettings_EventPurge_name());
    eventPurge.setPropertyGroupDefinition(dataManagerGroup);
    eventPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    eventPurge.setDefaultValue("14");
    def.put(eventPurge);

    PropertyDefinitionSimple driftFilePurge =
        new PropertyDefinitionSimple(
            Constant.DriftFilePurge,
            MSG.view_admin_systemSettings_DriftFilePurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    driftFilePurge.setDisplayName(MSG.view_admin_systemSettings_DriftFilePurge_name());
    driftFilePurge.setPropertyGroupDefinition(dataManagerGroup);
    driftFilePurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    driftFilePurge.setDefaultValue("31");
    def.put(driftFilePurge);

    PropertyDefinitionSimple dataReindex =
        new PropertyDefinitionSimple(
            Constant.DataReindex,
            MSG.view_admin_systemSettings_DataReindex_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    dataReindex.setDisplayName(MSG.view_admin_systemSettings_DataReindex_name());
    dataReindex.setPropertyGroupDefinition(dataManagerGroup);
    dataReindex.setDefaultValue("true");
    def.put(dataReindex);

    //////////////////////////////////////////////
    // Automatic Baseline Configuration Properties

    PropertyGroupDefinition baselineGroup = new PropertyGroupDefinition("baseline");
    baselineGroup.setDisplayName(MSG.view_admin_systemSettings_group_baseline());
    baselineGroup.setDefaultHidden(false);
    baselineGroup.setOrder(2);

    PropertyDefinitionSimple baselineFrequency =
        new PropertyDefinitionSimple(
            Constant.BaselineFrequency,
            MSG.view_admin_systemSettings_BaselineFrequency_desc(),
            true,
            PropertySimpleType.INTEGER);
    baselineFrequency.setDisplayName(MSG.view_admin_systemSettings_BaselineFrequency_name());
    baselineFrequency.setPropertyGroupDefinition(baselineGroup);
    baselineFrequency.addConstraints(new IntegerRangeConstraint(Long.valueOf(0), null));
    baselineFrequency.setDefaultValue("3");
    def.put(baselineFrequency);

    PropertyDefinitionSimple baselineDataSet =
        new PropertyDefinitionSimple(
            Constant.BaselineDataSet,
            MSG.view_admin_systemSettings_BaselineDataSet_desc(),
            true,
            PropertySimpleType.INTEGER);
    baselineDataSet.setDisplayName(MSG.view_admin_systemSettings_BaselineDataSet_name());
    baselineDataSet.setPropertyGroupDefinition(baselineGroup);
    baselineDataSet.addConstraints(
        new IntegerRangeConstraint(
            Long.valueOf(1),
            Long.valueOf(14))); // can't do more than 14 days since our raw tables don't hold more
    baselineDataSet.setDefaultValue("7");
    def.put(baselineDataSet);

    ////////////////////////////////
    // LDAP Configuration Properties

    PropertyGroupDefinition ldapGroup = new PropertyGroupDefinition("ldap");
    ldapGroup.setDisplayName(MSG.view_admin_systemSettings_group_ldap());
    ldapGroup.setDefaultHidden(
        !Boolean.parseBoolean(
            config.getSimpleValue(Constant.JAASProvider, "false"))); // show if LDAP is in use
    ldapGroup.setOrder(3);

    PropertyDefinitionSimple jaasProvider =
        new PropertyDefinitionSimple(
            Constant.JAASProvider,
            MSG.view_admin_systemSettings_JAASProvider_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    jaasProvider.setDisplayName(MSG.view_admin_systemSettings_JAASProvider_name());
    jaasProvider.setPropertyGroupDefinition(ldapGroup);
    jaasProvider.setDefaultValue("false");
    def.put(jaasProvider);

    PropertyDefinitionSimple ldapUrl =
        new PropertyDefinitionSimple(
            Constant.LDAPUrl,
            MSG.view_admin_systemSettings_LDAPUrl_desc(),
            true,
            PropertySimpleType.STRING);
    ldapUrl.setDisplayName(MSG.view_admin_systemSettings_LDAPUrl_name());
    ldapUrl.setPropertyGroupDefinition(ldapGroup);
    ldapUrl.setDefaultValue("ldap://localhost");
    def.put(ldapUrl);

    PropertyDefinitionSimple ldapProtocol =
        new PropertyDefinitionSimple(
            Constant.LDAPProtocol,
            MSG.view_admin_systemSettings_LDAPProtocol_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    ldapProtocol.setDisplayName(MSG.view_admin_systemSettings_LDAPProtocol_name());
    ldapProtocol.setPropertyGroupDefinition(ldapGroup);
    ldapProtocol.setDefaultValue("false");
    def.put(ldapProtocol);

    PropertyDefinitionSimple ldapLoginProperty =
        new PropertyDefinitionSimple(
            Constant.LDAPLoginProperty,
            MSG.view_admin_systemSettings_LDAPLoginProperty_desc(),
            false,
            PropertySimpleType.STRING);
    ldapLoginProperty.setDisplayName(MSG.view_admin_systemSettings_LDAPLoginProperty_name());
    ldapLoginProperty.setPropertyGroupDefinition(ldapGroup);
    ldapLoginProperty.setDefaultValue("cn");
    def.put(ldapLoginProperty);

    PropertyDefinitionSimple ldapFilter =
        new PropertyDefinitionSimple(
            Constant.LDAPFilter,
            MSG.view_admin_systemSettings_LDAPFilter_desc(),
            false,
            PropertySimpleType.STRING);
    ldapFilter.setDisplayName(MSG.view_admin_systemSettings_LDAPFilter_name());
    ldapFilter.setPropertyGroupDefinition(ldapGroup);
    ldapFilter.setDefaultValue("");
    def.put(ldapFilter);

    PropertyDefinitionSimple ldapGroupFilter =
        new PropertyDefinitionSimple(
            Constant.LDAPGroupFilter,
            MSG.view_admin_systemSettings_LDAPGroupFilter_desc(),
            false,
            PropertySimpleType.STRING);
    ldapGroupFilter.setDisplayName(MSG.view_admin_systemSettings_LDAPGroupFilter_name());
    ldapGroupFilter.setPropertyGroupDefinition(ldapGroup);
    ldapGroupFilter.setDefaultValue("rhqadmin");
    def.put(ldapGroupFilter);

    PropertyDefinitionSimple ldapGroupMember =
        new PropertyDefinitionSimple(
            Constant.LDAPGroupMember,
            MSG.view_admin_systemSettings_LDAPGroupMember_desc(),
            false,
            PropertySimpleType.STRING);
    ldapGroupMember.setDisplayName(MSG.view_admin_systemSettings_LDAPGroupMember_name());
    ldapGroupMember.setPropertyGroupDefinition(ldapGroup);
    ldapGroupMember.setDefaultValue("");
    def.put(ldapGroupMember);

    PropertyDefinitionSimple ldapBaseDN =
        new PropertyDefinitionSimple(
            Constant.LDAPBaseDN,
            MSG.view_admin_systemSettings_LDAPBaseDN_desc(),
            false,
            PropertySimpleType.STRING);
    ldapBaseDN.setDisplayName(MSG.view_admin_systemSettings_LDAPBaseDN_name());
    ldapBaseDN.setPropertyGroupDefinition(ldapGroup);
    ldapBaseDN.setDefaultValue("o=RedHat,c=US");
    def.put(ldapBaseDN);

    PropertyDefinitionSimple ldapBindDN =
        new PropertyDefinitionSimple(
            Constant.LDAPBindDN,
            MSG.view_admin_systemSettings_LDAPBindDN_desc(),
            false,
            PropertySimpleType.STRING);
    ldapBindDN.setDisplayName(MSG.view_admin_systemSettings_LDAPBindDN_name());
    ldapBindDN.setPropertyGroupDefinition(ldapGroup);
    ldapBindDN.setDefaultValue("");
    def.put(ldapBindDN);

    PropertyDefinitionSimple ldapBindPW =
        new PropertyDefinitionSimple(
            Constant.LDAPBindPW,
            MSG.view_admin_systemSettings_LDAPBindPW_desc(),
            false,
            PropertySimpleType.PASSWORD);
    ldapBindPW.setDisplayName(MSG.view_admin_systemSettings_LDAPBindPW_name());
    ldapBindPW.setPropertyGroupDefinition(ldapGroup);
    ldapBindPW.setDefaultValue("");
    def.put(ldapBindPW);

    ///////////////////////////////////////////
    // Drift Server Configuration Properties //
    ///////////////////////////////////////////
    PropertyGroupDefinition driftGroup = new PropertyGroupDefinition("drift");
    driftGroup.setDisplayName(MSG.view_admin_systemSettings_group_drift());
    driftGroup.setOrder(4);
    driftGroup.setDefaultHidden(false);

    PropertyDefinitionSimple activeDriftServer =
        new PropertyDefinitionSimple(
            Constant.ACTIVE_DRIFT_PLUGIN,
            MSG.view_admin_systemSettings_ActiveDriftServerPlugin_desc(),
            true,
            PropertySimpleType.STRING);
    activeDriftServer.setDisplayName(MSG.view_admin_systemSettings_ActiveDriftServerPlugin_name());
    activeDriftServer.setPropertyGroupDefinition(driftGroup);

    List<PropertyDefinitionEnumeration> options = new ArrayList<PropertyDefinitionEnumeration>();
    for (Map.Entry<String, String> entry : driftPlugins.entrySet()) {
      options.add(new PropertyDefinitionEnumeration(entry.getValue(), entry.getKey()));
    }

    activeDriftServer.setEnumeratedValues(options, false);

    def.put(activeDriftServer);

    //
    // if the config is missing any properties for which we have defaults, set them to their
    // defaults
    //
    Map<String, PropertyDefinition> allDefinitions = def.getPropertyDefinitions();
    for (Map.Entry<String, PropertyDefinition> defEntry : allDefinitions.entrySet()) {
      String propertyName = defEntry.getKey();
      PropertyDefinition propertyDef = defEntry.getValue();
      if (config.get(propertyName) == null) {
        if (propertyDef instanceof PropertyDefinitionSimple
            && ((PropertyDefinitionSimple) propertyDef).getDefaultValue() != null) {
          config.put(
              new PropertySimple(
                  propertyName, ((PropertyDefinitionSimple) propertyDef).getDefaultValue()));
        }
      }
    }

    return def;
  }