Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Work on ITest-2 Failures:
Browse files Browse the repository at this point in the history
- More work around 1071330 which added caching and last-update
  logic around SystemSettings.  Adding an internal-only local SLSB
  method which allows write of readOnly system settings.  This is
  analogous to the one I added a few minutes ago for a single setting.
- Convert SynchronizationManagerbeanTest to use SystemSettings as opposed
  to the deprecated systemConfig API, and use the internal SLSB methods
  as needed.
(cherry picked from commit 5f29fcc)

Signed-off-by: Simeon Pinder <spinder@fulliautomatix.conchfritter.com>
  • Loading branch information
jshaughn authored and Simeon Pinder committed Jul 24, 2014
1 parent a3d6c31 commit 598ef99
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public void testFindGroupsForUser8BitAsciiChar() throws Throwable {
* Helper methods
---------------*/
private void setSystemSetting(final SystemSetting setting, final String value) throws Exception {
systemManager.setSystemSetting(setting, value);
systemManager.setAnySystemSetting(setting, value);
}

private void setLdapGroupFilter(String filter) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -60,6 +59,8 @@
import org.xml.sax.InputSource;

import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.common.composite.SystemSetting;
import org.rhq.core.domain.common.composite.SystemSettings;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.criteria.MeasurementDefinitionCriteria;
Expand Down Expand Up @@ -121,13 +122,13 @@ public class SynchronizationManagerBeanTest extends AbstractEJB3Test {
private static final String METRIC_NAME = "SynchronizationManagerBeanTest";

private static class TestData {
public Properties systemSettings;
public SystemSettings systemSettings;
public ResourceType fakeType;
public Resource fakePlatform;
public TestServerPluginService testServerPluginService;
}

//this can't be mocked out because the config sync machinery has to be able to
//this can't be mocked out because the config sync machinery has to be able to
//instantiate this class
public static class ImportConfigurationCheckingSynchronizer implements Synchronizer<NoSingleEntity, String> {

Expand Down Expand Up @@ -309,7 +310,7 @@ private void setup(boolean createExport) throws Exception {
//make sure the system manager is in sync w/ the db we just changed in dbsetup
systemManager.loadSystemConfigurationCache();

testData.systemSettings = systemManager.getSystemConfiguration(freshUser());
testData.systemSettings = systemManager.getUnmaskedSystemSettings(false);

if (createExport) {
export = synchronizationManager.exportAllSubsystems(freshUser());
Expand All @@ -320,7 +321,7 @@ private void tearDown() throws Exception {
try {
getTransactionManager().begin();
try {
LookupUtil.getSystemManager().setSystemConfiguration(freshUser(), testData.systemSettings, true);
LookupUtil.getSystemManager().setAnySystemSettings(testData.systemSettings, true, true);

EntityManager em = getEntityManager();

Expand Down Expand Up @@ -370,7 +371,7 @@ public void testImportWithDefaultConfiguration() throws Exception {
MeasurementDefinitionManagerLocal measurementDefinitionManager = LookupUtil
.getMeasurementDefinitionManager();

Properties beforeSystemSettings = systemManager.getSystemConfiguration(freshUser());
SystemSettings beforeSystemSettings = systemManager.getUnmaskedSystemSettings(false);
MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria();
criteria.setPageControl(PageControl.getUnlimitedInstance());
criteria.fetchResourceType(true);
Expand All @@ -383,7 +384,7 @@ public void testImportWithDefaultConfiguration() throws Exception {
//this is to work around BZ 735810
systemManager.loadSystemConfigurationCache();

Properties afterSystemSettings = systemManager.getSystemConfiguration(freshUser());
SystemSettings afterSystemSettings = systemManager.getUnmaskedSystemSettings(false);
List<MeasurementDefinition> afterMeasurementDefinitions = measurementDefinitionManager
.findMeasurementDefinitionsByCriteria(freshUser(), criteria);

Expand Down Expand Up @@ -419,9 +420,9 @@ public void testImportWithRedefinedConfigurationInExportFile() throws Exception

//now check that everything got imported according to the changed configuration
SystemManagerLocal systemManager = LookupUtil.getSystemManager();
Properties settings = systemManager.getSystemConfiguration(freshUser());
SystemSettings settings = systemManager.getUnmaskedSystemSettings(false);

assertEquals(settings.getProperty("CAM_BASE_URL"), "http://testing.domain:7080");
assertEquals(settings.get(SystemSetting.BASE_URL), "http://testing.domain:7080");

MeasurementDefinitionManagerLocal measurementDefinitionManager = LookupUtil
.getMeasurementDefinitionManager();
Expand Down Expand Up @@ -467,9 +468,9 @@ public void testManuallyPassedImportConfigurationHasPrecendenceOverTheInlinedOne
try {
//let's read the original values from the database, so that we know what to compare against
SystemManagerLocal systemManager = LookupUtil.getSystemManager();
Properties settings = systemManager.getSystemConfiguration(freshUser());
SystemSettings settings = systemManager.getUnmaskedSystemSettings(false);

String originalBaseUrl = settings.getProperty("CAM_BASE_URL");
String originalBaseUrl = settings.get(SystemSetting.BASE_URL);

MeasurementDefinitionManagerLocal measurementDefinitionManager = LookupUtil
.getMeasurementDefinitionManager();
Expand Down Expand Up @@ -506,9 +507,9 @@ public void testManuallyPassedImportConfigurationHasPrecendenceOverTheInlinedOne
}

//now check that we import using the manually create configurations, not the inlined ones
settings = systemManager.getSystemConfiguration(freshUser());
settings = systemManager.getUnmaskedSystemSettings(false);

assertEquals(settings.getProperty("CAM_BASE_URL"), originalBaseUrl);
assertEquals(settings.get(SystemSetting.BASE_URL), originalBaseUrl);

measurementDefinitionManager = LookupUtil.getMeasurementDefinitionManager();
distroNameDef = measurementDefinitionManager.findMeasurementDefinitionsByCriteria(freshUser(), crit).get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,18 @@ public SystemSettings getObfuscatedSystemSettings(boolean includePrivateSettings
@Override
@RequiredPermission(Permission.MANAGE_SETTINGS)
public void setSystemSettings(Subject subject, SystemSettings settings) {
setSystemSettings(removePrivateSettings(settings), false, false);
setAnySystemSettings(removePrivateSettings(settings), false, false);
}

@Override
public void setSystemSetting(SystemSetting setting, String value) {
public void setAnySystemSetting(SystemSetting setting, String value) {
if (SystemSetting.LAST_SYSTEM_CONFIG_UPDATE_TIME == setting) {
return;
}

SystemSettings settings = getUnmaskedSystemSettings(true);
settings.put(setting, value);
setSystemSettings(settings, true, true);
setAnySystemSettings(settings, true, true);
}

private SystemSettings removePrivateSettings(SystemSettings settings) {
Expand All @@ -287,10 +287,11 @@ public void setStorageClusterSettings(Subject subject, SystemSettings settings)
+ "only allows updating of storage cluster settings.");
}
}
setSystemSettings(settings, false, true);
setAnySystemSettings(settings, false, true);
}

private void setSystemSettings(SystemSettings settings, boolean skipValidation, boolean ignoreReadOnly) {
@Override
public void setAnySystemSettings(SystemSettings settings, boolean skipValidation, boolean ignoreReadOnly) {
// first, we need to get the current settings so we'll know if we need to persist or merge the new ones
@SuppressWarnings("unchecked")
List<SystemConfiguration> configs = entityManager.createNamedQuery(SystemConfiguration.QUERY_FIND_ALL)
Expand Down Expand Up @@ -482,7 +483,7 @@ public void setSystemConfiguration(Subject subject, Properties properties, boole

SystemSettings settings = SystemSettings.fromMap(map);

setSystemSettings(settings, skipValidation, false);
setAnySystemSettings(settings, skipValidation, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,17 @@ public interface SystemManagerLocal extends SystemManagerRemote {
* @param setting
* @param value
*/
void setSystemSetting(SystemSetting setting, String value);
void setAnySystemSetting(SystemSetting setting, String value);

/**
* Internal use only. Like {@link SystemManagerRemote#setSystemSettings(Subject, SystemSettings)} but can
* bypass validation and also ignore the readOnly constraint.
*
* @param settings
* @param skipValidation if true, skip validation
* @param ignoreReadOnly if true, ignore the readOnly constraint and set new values if supplied
* @param value
*/
void setAnySystemSettings(SystemSettings settings, boolean skipValidation, boolean ignoreReadOnly);

}

0 comments on commit 598ef99

Please sign in to comment.