Skip to content

Commit

Permalink
Migrate sysconfig application to CacheRegistry
Browse files Browse the repository at this point in the history
Application of system configuration changes is now centrally managed
via SystemConfigurationChangeApplier class. Also, the application
of changes is triggered using clusterwide cache invalidation mechanism.

Some issues remain, see MID-4886.
  • Loading branch information
mederly committed Sep 12, 2018
1 parent 41f95c6 commit 7dcbaa5
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 333 deletions.
Expand Up @@ -50,13 +50,12 @@ public class LoggingConfigurationManager {

public static final String AUDIT_LOGGER_NAME = "com.evolveum.midpoint.audit.log";

final static Trace LOGGER = TraceManager.getTrace(LoggingConfigurationManager.class);
private final static Trace LOGGER = TraceManager.getTrace(LoggingConfigurationManager.class);

private static final String REQUEST_FILTER_LOGGER_CLASS_NAME = "com.evolveum.midpoint.web.util.MidPointProfilingServletFilter";
private static final String PROFILING_ASPECT_LOGGER = "com.evolveum.midpoint.util.aspect.ProfilingDataManager";
private static final String IDM_PROFILE_APPENDER = "IDM_LOG";

public static final String SYSTEM_CONFIGURATION_SKIP_REPOSITORY_LOGGING_SETTINGS = "skipRepositoryLoggingSettings";
private static final String LOGBACK_CONSOLE_XML_RESOURCE = "logback-console.xml";

private static String currentlyUsedVersion = null;
Expand Down
Expand Up @@ -96,7 +96,7 @@ public QName normalizeRelation(QName relation) {
}

@Override
public void applyRelationConfiguration(SystemConfigurationType systemConfiguration) {
public void applyRelationsConfiguration(SystemConfigurationType systemConfiguration) {
}

@Override
Expand Down
Expand Up @@ -140,7 +140,7 @@ default boolean isOwner(QName relation) {
* This method should be called whenever midPoint determines that the relations definition in system configuration might
* have been changed.
*/
void applyRelationConfiguration(SystemConfigurationType systemConfiguration);
void applyRelationsConfiguration(SystemConfigurationType systemConfiguration);

/**
* Returns aliases of a relation. Currently these are:
Expand Down
Expand Up @@ -51,7 +51,7 @@ public class RelationRegistryImpl implements RelationRegistry {
private IndexedRelationDefinitions indexedRelationDefinitions = createAndIndexRelationDefinitions(null);

@Override
public void applyRelationConfiguration(SystemConfigurationType systemConfiguration) {
public void applyRelationsConfiguration(SystemConfigurationType systemConfiguration) {
RoleManagementConfigurationType roleManagement = systemConfiguration != null ? systemConfiguration.getRoleManagement() : null;
RelationsDefinitionType relationsDef = roleManagement != null ? roleManagement.getRelations() : null;
LOGGER.info("Applying relation configuration ({} entries)", relationsDef != null ? relationsDef.getRelation().size() : 0);
Expand Down
Expand Up @@ -72,7 +72,7 @@ public void addListener() {
@Override
public <O extends ObjectType> void invalidateCache(Class<O> type, String oid) {

if (!FunctionLibraryType.class.equals(type)) {
if (!FunctionLibraryType.class.equals(type) && !SystemConfigurationType.class.equals(type)) {
LOGGER.trace("Type {} not yet supported for cache clearance. Skipping.", type);
return;
}
Expand Down
Expand Up @@ -1611,12 +1611,9 @@ public void postInit(OperationResult parentResult) {
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ModelController.class);

try {
SecurityUtil.setRemoteHostAddressHeaders(ObjectTypeUtil.asObjectable(systemObjectCache.getSystemConfiguration(result)));
} catch (SchemaException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't set 'forwardedFor' headers because system configuration couldn't be read", e);
}

try {
// Repository service itself might have been initialized.
// But there are situations (e.g. in tests or after factory reset) in which only this method is called.
// So let's be conservative and rather execute repository postInit twice than zero times.
cacheRepositoryService.postInit(result);
} catch (SchemaException e) {
result.recordFatalError(e);
Expand Down

This file was deleted.

@@ -0,0 +1,30 @@
/*
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.model.impl.controller;

import com.evolveum.midpoint.repo.api.SystemConfigurationChangeApplier;
import com.evolveum.midpoint.schema.result.OperationResult;

/**
* @author mederly
*/
public class DummySystemConfigurationChangeApplierImpl implements SystemConfigurationChangeApplier {

@Override
public void applySystemConfiguration(boolean ignoreVersion, boolean allowNotFound, OperationResult result) {
}
}
Expand Up @@ -43,4 +43,8 @@
<import resource="ctx-audit.xml"/>
<import resource="ctx-security.xml"/>
<import resource="ctx-common.xml"/>

<!-- Repository is not here but we need this bean -->
<bean id="dummySystemConfigurationChangeApplier" class="com.evolveum.midpoint.model.impl.controller.DummySystemConfigurationChangeApplierImpl"/>

</beans>
Expand Up @@ -570,7 +570,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Except
"looks like the previous test haven't cleaned it up", e);
}
if (configuration != null) {
relationRegistry.applyRelationConfiguration(configuration.asObjectable());
relationRegistry.applyRelationsConfiguration(configuration.asObjectable());
}

// Users
Expand Down
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.repo.api;

import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.SchemaException;

/**
* @author mederly
*/
public interface SystemConfigurationChangeApplier {

void applySystemConfiguration(boolean ignoreVersion, boolean allowNotFound, OperationResult result) throws SchemaException;

}
Expand Up @@ -20,6 +20,7 @@

import javax.annotation.PostConstruct;

import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.evolveum.midpoint.repo.api.CacheDispatcher;
Expand All @@ -39,7 +40,6 @@ public void registerListener() {
dispatcher.registerCacheListener(this);
}


public void registerCacheableService(Cacheable cacheableService) {
cacheableServices.add(cacheableService);
}
Expand All @@ -56,8 +56,7 @@ public void clearAllCaches() {

@Override
public <O extends ObjectType> void invalidateCache(Class<O> type, String oid) {

if (FunctionLibraryType.class.equals(type)) {
if (FunctionLibraryType.class.equals(type) || SystemConfigurationType.class.equals(type)) {
clearAllCaches();
}
}
Expand Down

0 comments on commit 7dcbaa5

Please sign in to comment.