/**
   * 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;
  }
예제 #2
0
 public static void convertConfigurationToManagedProperties(
     Map<String, ManagedProperty> managedProperties,
     Configuration configuration,
     ResourceType resourceType,
     Map<String, PropertySimple> customProps) {
   ConfigurationDefinition configDefinition = resourceType.getResourceConfigurationDefinition();
   Set<String> missingManagedPropertyNames = new HashSet<String>();
   for (Property property : configuration.getProperties()) {
     String propertyName = property.getName();
     ManagedProperty managedProperty = managedProperties.get(propertyName);
     PropertyDefinition propertyDefinition = configDefinition.get(propertyName);
     if (managedProperty == null) {
       // NOTE: We expect the Profile Service to always return templates that contain *all*
       // ManagedProperties
       //       that are defined for the ComponentType, so this is considered an error. We could
       // build a
       //       ManagedProperty from scratch based on only a PropertyDefinition anyway, since a
       // propDef could
       //       map to multiple different types of MetaValues (e.g. a PropertyList could
       // potentially map to
       //       either an ArrayValue or a CollectionValue).
       missingManagedPropertyNames.add(propertyName);
     } else {
       populateManagedPropertyFromProperty(
           property, propertyDefinition, managedProperty, customProps.get(propertyName));
     }
     if (!missingManagedPropertyNames.isEmpty())
       throw new IllegalStateException(
           "***** The following properties are defined in this plugin's "
               + "descriptor but have no corresponding ManagedProperties: "
               + missingManagedPropertyNames);
   }
   return;
 }
예제 #3
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);
    }
  }
  /**
   * Replace the existing property of a given type with a new property of a (possibly) different
   * type
   *
   * @param existingProperty the existing prop
   * @param newProperty the new prop that should replace the existing prop
   */
  private void replaceProperty(
      PropertyDefinition existingProperty, PropertyDefinition newProperty) {
    ConfigurationDefinition configDef = existingProperty.getConfigurationDefinition();

    // First take id from existing prop, and replace existing prop in the config def.
    newProperty.setId(existingProperty.getId());
    configDef.put(newProperty);

    entityManager.remove(existingProperty);
    entityManager.merge(configDef);
  }
예제 #5
0
  private ResourceType createResourceType() throws Exception {
    ResourceType resourceType =
        new ResourceType("RHQ Storage Node", "RHQStorage", ResourceCategory.SERVER, null);
    ConfigurationDefinition pluginConfigurationDefinition =
        new ConfigurationDefinition("config", null);
    pluginConfigurationDefinition.put(
        new PropertyDefinitionSimple("host", null, true, PropertySimpleType.STRING));
    resourceType.setPluginConfigurationDefinition(pluginConfigurationDefinition);
    getEntityManager().persist(resourceType);

    return resourceType;
  }
  static {
    DEFINITION.put(
        new PropertyDefinitionSimple("topLevelString", null, true, PropertySimpleType.STRING));
    DEFINITION.put(
        new PropertyDefinitionSimple("topLevelPassword", null, true, PropertySimpleType.PASSWORD));
    DEFINITION.put(
        new PropertyDefinitionList(
            "topLevelPasswordList",
            null,
            true,
            new PropertyDefinitionSimple("listPassword", null, true, PropertySimpleType.PASSWORD)));
    DEFINITION.put(
        new PropertyDefinitionList(
            "topLevelListOfMaps",
            null,
            true,
            new PropertyDefinitionMap(
                "mapWithPass",
                null,
                true,
                new PropertyDefinitionSimple("username", null, true, PropertySimpleType.STRING),
                new PropertyDefinitionSimple(
                    "password", null, true, PropertySimpleType.PASSWORD))));

    CONFIGURATION.put(new PropertySimple("topLevelString", "topLevelString"));
    CONFIGURATION.put(new PropertySimple("topLevelPassword", "topLevelPassword"));
    CONFIGURATION.put(
        new PropertyList(
            "topLevelPasswordList",
            new PropertySimple("listPassword", "0"),
            new PropertySimple("listPassword", "1")));
    CONFIGURATION.put(
        new PropertyList(
            "topLevelListOfMaps",
            new PropertyMap(
                "mapWithPass",
                new PropertySimple("username", "username"),
                new PropertySimple("password", "password"))));
  }
예제 #7
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;
 }
  private void assertVersion2(ResourceType resourceType) {
    PropertyDefinition prop;
    Set<String> seen =
        new HashSet<String>(2); // we use to this remember names of the things that we've seen

    assert resourceType.getChildSubCategories().size() == 1;
    assert resourceType.getChildSubCategories().get(0).getName().equals(SUBCAT);
    assert resourceType.getChildSubCategories().get(0).getDisplayName().equals(SUBCAT_DISPLAYNAME);

    seen.clear();
    ConfigurationDefinition pcDef = resourceType.getPluginConfigurationDefinition();
    assert pcDef.getGroupDefinitions().size() == 2;
    for (PropertyGroupDefinition group : pcDef.getGroupDefinitions()) {
      seen.add(group.getName());
      if (group.getName().equals(CHANGED_PC_GROUP)) {
        assert group.isDefaultHidden() == CHANGED_PC_GROUP_HIDDEN;
      } else if (group.getName().equals(NEW_PC_GROUP)) {
        assert group.isDefaultHidden() == NEW_PC_GROUP_HIDDEN;
      } else {
        assert false : "Unexpected group [" + group.getName() + "]:" + group;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    prop = pcDef.get(CHANGED_PC_PROP);
    assert prop != null;
    assert prop.getName().equals(CHANGED_PC_PROP);
    assert prop.isRequired() == CHANGED_PC_PROP_REQUIRED;
    assert prop.getPropertyGroupDefinition().getName().equals(CHANGED_PC_GROUP);
    prop = pcDef.get(NEW_PC_PROP);
    assert prop != null;
    assert prop.getName().equals(NEW_PC_PROP);
    assert prop.isRequired() == NEW_PC_PROP_REQUIRED;
    assert prop.getPropertyGroupDefinition().getName().equals(NEW_PC_GROUP);

    seen.clear();
    assert resourceType.getProcessScans().size() == 2;
    for (ProcessScan processScan : resourceType.getProcessScans()) {
      seen.add(processScan.getName());
      if (processScan.getName().equals(CHANGED_PROCESS_SCAN_NAME)) {
        assert processScan.getQuery().equals(CHANGED_PROCESS_SCAN_QUERY);
      } else if (processScan.getName().equals(NEW_PROCESS_SCAN_NAME)) {
        assert processScan.getQuery().equals(NEW_PROCESS_SCAN_QUERY);
      } else {
        assert false : "Unexpected process scan[" + processScan.getName() + "]:" + processScan;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    seen.clear();
    assert resourceType.getOperationDefinitions().size() == 2;
    for (OperationDefinition op : resourceType.getOperationDefinitions()) {
      seen.add(op.getName());
      if (op.getName().equals(CHANGED_OP_NAME)) {
        assert op.getTimeout().intValue() == CHANGED_OP_TIMEOUT;
        assert op.getDescription().equals(CHANGED_OP_DESC);
      } else if (op.getName().equals(NEW_OP_NAME)) {
        assert op.getTimeout().intValue() == NEW_OP_TIMEOUT;
        assert op.getDescription().equals(NEW_OP_DESC);
      } else {
        assert false : "Unexpected operation [" + op.getName() + "]:" + op;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    seen.clear();
    assert resourceType.getMetricDefinitions().size() == 3; // include built-in Availability metric
    for (MeasurementDefinition metric : resourceType.getMetricDefinitions()) {
      if (metric.getName().equals(MeasurementDefinition.AVAILABILITY_NAME)) {
        // expected, ignore
        continue;
      }

      seen.add(metric.getName());
      if (metric.getName().equals(CHANGED_METRIC_PROP)) {
        // even though our _v2 plugin set this to something different, our upgrade doesn't change it
        // because
        // we don't want to overwrite changes a user possibly made to the defaut interval (aka
        // metric template)
        assert metric.getDefaultInterval() == METRIC_DEFAULT_INTERVAL;
      } else if (metric.getName().equals(NEW_METRIC_PROP)) {
        assert metric.getDefaultInterval() == NEW_METRIC_DEFAULT_INTERVAL;
      } else {
        assert false : "Unexpected metric [" + metric.getName() + "]:" + metric;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    seen.clear();
    assert resourceType.getEventDefinitions().size() == 2;
    for (EventDefinition event : resourceType.getEventDefinitions()) {
      seen.add(event.getName());
      if (event.getName().equals(CHANGED_EVENT_NAME)) {
        assert event.getDescription().equals(CHANGED_EVENT_DESC);
      } else if (event.getName().equals(NEW_EVENT_NAME)) {
        assert event.getDescription().equals(NEW_EVENT_DESC);
      } else {
        assert false : "Unexpected event [" + event.getName() + "]:" + event;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    assert resourceType.getResourceConfigurationDefinition().getGroupDefinitions().size() == 0;
    prop = resourceType.getResourceConfigurationDefinition().get(CHANGED_RC_PROP);
    assert prop != null;
    assert prop.getName().equals(CHANGED_RC_PROP);
    assert prop.isRequired() == CHANGED_RC_PROP_REQUIRED;
    prop = resourceType.getResourceConfigurationDefinition().get(NEW_RC_PROP);
    assert prop != null;
    assert prop.getName().equals(NEW_RC_PROP);
    assert prop.isRequired() == NEW_RC_PROP_REQUIRED;

    seen.clear();
    assert resourceType.getDriftDefinitionTemplates().size() == 2;
    for (DriftDefinitionTemplate drift : resourceType.getDriftDefinitionTemplates()) {
      DriftDefinition def = drift.getTemplateDefinition();
      seen.add(def.getName());
      if (def.getName().equals(CHANGED_DRIFT_DEF_NAME)) {
        BaseDirectory driftBasedir = def.getBasedir();
        assert driftBasedir.getValueContext().equals(CHANGED_DRIFT_DEF_BASEDIR_CONTEXT);
        assert driftBasedir.getValueName().equals(CHANGED_DRIFT_DEF_BASEDIR_VALUE);
      } else if (def.getName().equals(NEW_DRIFT_DEF_NAME)) {
        BaseDirectory driftBasedir = def.getBasedir();
        assert driftBasedir.getValueContext().equals(NEW_DRIFT_DEF_BASEDIR_CONTEXT);
        assert driftBasedir.getValueName().equals(NEW_DRIFT_DEF_BASEDIR_VALUE);
      } else {
        assert false : "Unexpected drift def [" + def.getName() + "]:" + def;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    seen.clear();
    ResourceTypeBundleConfiguration bundle = resourceType.getResourceTypeBundleConfiguration();
    assert bundle.getBundleDestinationBaseDirectories().size() == 2;
    for (BundleDestinationBaseDirectory bundleBasedir :
        bundle.getBundleDestinationBaseDirectories()) {
      seen.add(bundleBasedir.getName());
      if (bundleBasedir.getName().equals(CHANGED_BUNDLE_TARGET_NAME)) {
        assert bundleBasedir.getValueContext().equals(CHANGED_BUNDLE_BASEDIR_CONTEXT);
        assert bundleBasedir.getValueName().equals(CHANGED_BUNDLE_BASEDIR_VALUE);
      } else if (bundleBasedir.getName().equals(NEW_BUNDLE_TARGET_NAME)) {
        assert bundleBasedir.getValueContext().equals(NEW_BUNDLE_BASEDIR_CONTEXT);
        assert bundleBasedir.getValueName().equals(NEW_BUNDLE_BASEDIR_VALUE);
      } else {
        assert false
            : "Unexpected bundle basedir [" + bundleBasedir.getName() + "]:" + bundleBasedir;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }
  }
  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;
  }
예제 #10
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));
  }
예제 #11
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));
  }
예제 #12
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;
 }
  static {
    INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    INSTANCE.put(createName(INSTANCE, false));
    INSTANCE.put(createDescription(INSTANCE));
    INSTANCE.put(createEnabled(INSTANCE));
    INSTANCE.put(createDriftHandlingMode(INSTANCE));
    INSTANCE.put(createInterval(INSTANCE));
    INSTANCE.put(createBasedir(INSTANCE, false));
    INSTANCE.put(createIncludes(INSTANCE, false));
    INSTANCE.put(createExcludes(INSTANCE, false));
    INSTANCE.put(createPinned(INSTANCE, false));
    INSTANCE.put(createAttached(INSTANCE, false));

    INSTANCE_FOR_EXISTING_CONFIGS.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    INSTANCE_FOR_EXISTING_CONFIGS.put(createName(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createDescription(INSTANCE_FOR_EXISTING_CONFIGS));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createEnabled(INSTANCE_FOR_EXISTING_CONFIGS));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createDriftHandlingMode(INSTANCE_FOR_EXISTING_CONFIGS));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createInterval(INSTANCE_FOR_EXISTING_CONFIGS));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createBasedir(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createIncludes(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createExcludes(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createExcludes(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createAttached(INSTANCE_FOR_EXISTING_CONFIGS, false));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createPinned(INSTANCE_FOR_EXISTING_CONFIGS, false));

    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createName(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, false));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createDescription(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createInterval(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createEnabled(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createDriftHandlingMode(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createBasedir(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createIncludes(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createExcludes(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createPinned(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createAttached(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));

    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.setConfigurationFormat(
        ConfigurationFormat.STRUCTURED);
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createName(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createDescription(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createInterval(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createEnabled(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createDriftHandlingMode(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createBasedir(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createIncludes(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createExcludes(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createPinned(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createAttached(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));

    NEW_TEMPLATE_INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    NEW_TEMPLATE_INSTANCE.put(createName(NEW_TEMPLATE_INSTANCE, false));
    NEW_TEMPLATE_INSTANCE.put(createDescription(NEW_TEMPLATE_INSTANCE));
    NEW_TEMPLATE_INSTANCE.put(createInterval(NEW_TEMPLATE_INSTANCE));
    NEW_TEMPLATE_INSTANCE.put(createEnabled(NEW_TEMPLATE_INSTANCE));
    NEW_TEMPLATE_INSTANCE.put(createDriftHandlingMode(NEW_TEMPLATE_INSTANCE));
    NEW_TEMPLATE_INSTANCE.put(createBasedir(NEW_TEMPLATE_INSTANCE, false));
    NEW_TEMPLATE_INSTANCE.put(createIncludes(NEW_TEMPLATE_INSTANCE, false));
    NEW_TEMPLATE_INSTANCE.put(createExcludes(NEW_TEMPLATE_INSTANCE, false));

    EXISTING_TEMPLATE_INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    EXISTING_TEMPLATE_INSTANCE.put(createName(EXISTING_TEMPLATE_INSTANCE, true));
    EXISTING_TEMPLATE_INSTANCE.put(createDescription(EXISTING_TEMPLATE_INSTANCE));
    EXISTING_TEMPLATE_INSTANCE.put(createInterval(EXISTING_TEMPLATE_INSTANCE));
    EXISTING_TEMPLATE_INSTANCE.put(createEnabled(EXISTING_TEMPLATE_INSTANCE));
    EXISTING_TEMPLATE_INSTANCE.put(createDriftHandlingMode(EXISTING_TEMPLATE_INSTANCE));
    EXISTING_TEMPLATE_INSTANCE.put(createBasedir(EXISTING_TEMPLATE_INSTANCE, true));
    EXISTING_TEMPLATE_INSTANCE.put(createIncludes(EXISTING_TEMPLATE_INSTANCE, true));
    EXISTING_TEMPLATE_INSTANCE.put(createExcludes(EXISTING_TEMPLATE_INSTANCE, true));

    NEW_PINNED_TEMPLATE_INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    NEW_PINNED_TEMPLATE_INSTANCE.put(createName(NEW_PINNED_TEMPLATE_INSTANCE, false));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createDescription(NEW_PINNED_TEMPLATE_INSTANCE));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createInterval(NEW_PINNED_TEMPLATE_INSTANCE));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createEnabled(NEW_PINNED_TEMPLATE_INSTANCE));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createDriftHandlingMode(NEW_PINNED_TEMPLATE_INSTANCE));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createBasedir(NEW_PINNED_TEMPLATE_INSTANCE, true));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createIncludes(NEW_PINNED_TEMPLATE_INSTANCE, true));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createExcludes(NEW_PINNED_TEMPLATE_INSTANCE, true));
  }
예제 #14
0
  @Override
  public void updateResourceConfiguration(
      final ConfigurationUpdateReport configurationUpdateReport) {
    ResourceType resourceType = context.getResourceType();
    ConfigurationDefinition configDef = resourceType.getResourceConfigurationDefinition();
    Configuration newConfig = configurationUpdateReport.getConfiguration();

    // remove special property being possibly sent from server in case EAP requires reload/restart
    newConfig.remove("__OOB");

    // 1. First of all, read the current configuration
    ConfigurationLoadDelegate readDelegate =
        new ConfigurationLoadDelegate(configDef, getASConnection(), address, includeRuntime);
    Configuration currentConfig;
    try {
      currentConfig = readDelegate.loadResourceConfiguration();
    } catch (Exception e) {
      getLog().error("Could not read current configuration before update", e);
      configurationUpdateReport.setStatus(FAILURE);
      configurationUpdateReport.setErrorMessage(
          "Could not read current configuration before update: " + ThrowableUtil.getRootMessage(e));
      return;
    }

    // 2. We will wrap all property-simple and connection properties changes in a composite
    // operation
    CompositeOperation updateOperation = new CompositeOperation();

    // 3. Capture property-simple changes
    Map<String, PropertySimple> newConfigSimpleProperties = newConfig.getSimpleProperties();
    Map<String, PropertySimple> currentConfigSimpleProperties = currentConfig.getSimpleProperties();

    Set<String> allSimplePropertyNames =
        new HashSet<String>(
            newConfigSimpleProperties.size() + currentConfigSimpleProperties.size());
    allSimplePropertyNames.addAll(newConfigSimpleProperties.keySet());
    allSimplePropertyNames.addAll(currentConfigSimpleProperties.keySet());
    // Read-only
    allSimplePropertyNames.remove(ENABLED_ATTRIBUTE);

    for (String simplePropertyName : allSimplePropertyNames) {
      PropertySimple newConfigPropertySimple = newConfigSimpleProperties.get(simplePropertyName);
      String newConfigPropertySimpleValue =
          newConfigPropertySimple == null ? null : newConfigPropertySimple.getStringValue();
      PropertySimple currentConfigPropertySimple =
          currentConfigSimpleProperties.get(simplePropertyName);
      String currentConfigPropertySimpleValue =
          currentConfigPropertySimple == null ? null : currentConfigPropertySimple.getStringValue();
      boolean canUnset = !UNSET_FORBIDDEN_ATTRIBUTES.contains(simplePropertyName);

      if (newConfigPropertySimpleValue == null) {
        if (currentConfigPropertySimpleValue != null) {
          String val;
          if (canUnset) {
            val = null;
          } else {
            val = configDef.getPropertyDefinitionSimple(simplePropertyName).getDefaultValue();
          }
          updateOperation.addStep(new WriteAttribute(getAddress(), simplePropertyName, val));
        }
      } else if (!newConfigPropertySimpleValue.equals(currentConfigPropertySimpleValue)) {
        updateOperation.addStep(
            new WriteAttribute(getAddress(), simplePropertyName, newConfigPropertySimpleValue));
      }
    }

    // 4. Capture connection property changes
    String connPropAttributeNameOnServer, connPropPluginConfigPropertyName, keyName;
    if (isXADatasourceResource(resourceType)) {
      connPropAttributeNameOnServer = "xa-datasource-properties";
      connPropPluginConfigPropertyName = XA_DATASOURCE_PROPERTIES_ATTRIBUTE;
      keyName = "key";
    } else {
      connPropAttributeNameOnServer = "connection-properties";
      connPropPluginConfigPropertyName = CONNECTION_PROPERTIES_ATTRIBUTE;
      keyName = "pname";
    }

    Map<String, String> newConfigConnectionProperties =
        getConnectionPropertiesAsMap(newConfig.getList(connPropPluginConfigPropertyName), keyName);
    Map<String, String> currentConfigConnectionProperties =
        getConnectionPropertiesAsMap(
            currentConfig.getList(connPropPluginConfigPropertyName), keyName);
    Set<String> allConnectionPropertyNames =
        new HashSet<String>(
            newConfigConnectionProperties.size() + currentConfigConnectionProperties.size());
    allConnectionPropertyNames.addAll(newConfigConnectionProperties.keySet());
    allConnectionPropertyNames.addAll(currentConfigConnectionProperties.keySet());

    for (String connectionPropertyName : allConnectionPropertyNames) {
      Address propertyAddress = new Address(getAddress());
      propertyAddress.add(connPropAttributeNameOnServer, connectionPropertyName);

      String newConfigConnectionPropertyValue =
          newConfigConnectionProperties.get(connectionPropertyName);
      String currentConfigConnectionPropertyValue =
          currentConfigConnectionProperties.get(connectionPropertyName);

      if (newConfigConnectionPropertyValue == null) {
        updateOperation.addStep(new Operation("remove", propertyAddress));
      } else if (currentConfigConnectionPropertyValue == null) {
        Operation addOperation = new Operation("add", propertyAddress);
        addOperation.addAdditionalProperty("value", newConfigConnectionPropertyValue);
        updateOperation.addStep(addOperation);
      } else if (!newConfigConnectionPropertyValue.equals(currentConfigConnectionPropertyValue)) {
        updateOperation.addStep(new Operation("remove", propertyAddress));
        Operation addOperation = new Operation("add", propertyAddress);
        addOperation.addAdditionalProperty("value", newConfigConnectionPropertyValue);
        updateOperation.addStep(addOperation);
      }
    }

    // 5. Update config if needed
    if (updateOperation.numberOfSteps() > 0) {
      Result res = getASConnection().execute(updateOperation);
      if (res.isSuccess()) {
        configurationUpdateReport.setStatus(SUCCESS);
      } else {
        configurationUpdateReport.setStatus(FAILURE);
        configurationUpdateReport.setErrorMessage(res.getFailureDescription());
      }
    } else {
      configurationUpdateReport.setStatus(NOCHANGE);
    }
  }
예제 #15
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;
  }