Skip to content

Commit

Permalink
Applying full text indexing (and logging) configuration earlier in th…
Browse files Browse the repository at this point in the history
…e startup sequence. Other minor tweaks.

(cherry picked from commit 0e6d8c2)
  • Loading branch information
mederly committed Feb 28, 2017
1 parent cebe0dc commit 42a8fd7
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 69 deletions.
Expand Up @@ -40,10 +40,10 @@ public void setModel(ModelService model) {
public void init() {
LOGGER.info("Model post initialization.");

OperationResult mainResult = new OperationResult("Model Post Initialisation");
OperationResult mainResult = new OperationResult("Model Post Initialization");
try {
model.postInit(mainResult);
LOGGER.info("Model post initialization finished successful.");
LOGGER.info("Model post initialization finished successfully.");
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Model post initialization failed", ex);
mainResult.recordFatalError("Model post initialization failed.", ex);
Expand Down
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2010-2017 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.init;

import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import org.jetbrains.annotations.NotNull;

/**
* @author mederly
*/
public class RepoInitialSetup {

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

@NotNull private RepositoryService repositoryService;

public RepoInitialSetup(@NotNull RepositoryService repositoryService) {
this.repositoryService = repositoryService;
}

public void init() {
LOGGER.info("Repository post initialization.");

OperationResult result = new OperationResult(RepoInitialSetup.class.getName() + ".init");
try {
repositoryService.postInit(result);
LOGGER.info("Repository post initialization finished successfully.");
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Repository post initialization failed", ex);
result.recordFatalError("Repository post initialization failed.", ex);
} finally {
result.computeStatus("Repository post initialization failed.");
}
}
}
4 changes: 4 additions & 0 deletions gui/admin-gui/src/main/webapp/WEB-INF/ctx-init.xml
Expand Up @@ -25,6 +25,10 @@
<bean name="infraInitialSetup" class="com.evolveum.midpoint.init.InfraInitialSetup" init-method="init">
</bean>

<bean id="repoInitialSetup" class="com.evolveum.midpoint.init.RepoInitialSetup" init-method="init">
<constructor-arg name="repositoryService" ref="repositoryService"/>
</bean>

<bean id="initialDataImport" class="com.evolveum.midpoint.init.InitialDataImport" init-method="init"
scope="singleton">
<property name="model" ref="modelController"/>
Expand Down
Expand Up @@ -161,17 +161,11 @@ public class ModelController implements ModelService, TaskService, WorkflowServi
@Autowired(required = true)
private ChangeExecutor changeExecutor;

@Autowired(required = true)
SystemConfigurationHandler systemConfigurationHandler;

@Autowired(required = true)
private AuditService auditService;

@Autowired(required = true)
private SecurityEnforcer securityEnforcer;

@Autowired(required = true)
private AuthenticationEvaluator authenticationEvaluator;

@Autowired(required = true)
private UserProfileService userProfileService;
Expand Down Expand Up @@ -1673,19 +1667,7 @@ public void postInit(OperationResult parentResult) {
securityEnforcer.setUserProfileService(userProfileService);
// TODO: initialize repository

PrismObject<SystemConfigurationType> systemConfiguration;
try {
systemConfiguration = objectResolver.getSystemConfiguration(result);
systemConfigurationHandler.postInit(systemConfiguration, result);
} catch (ObjectNotFoundException e) {
String message = "No system configuration found, skipping application of initial system settings";
LOGGER.error(message + ": " + e.getMessage(), e);
result.recordWarning(message, e);
} catch (SchemaException e) {
String message = "Schema error in system configuration, skipping application of initial system settings";
LOGGER.error(message + ": " + e.getMessage(), e);
result.recordWarning(message, e);
}
// repository (including logging config) is initialized in its own method

taskManager.postInit(result);

Expand Down
Expand Up @@ -65,29 +65,11 @@ public class SystemConfigurationHandler implements ChangeHook {
@Qualifier("cacheRepositoryService")
private transient RepositoryService cacheRepositoryService;

@Autowired
private MidpointConfiguration startupConfiguration;

@PostConstruct
public void init() {
hookRegistry.registerChangeHook(HOOK_URI, this);
}

public void postInit(PrismObject<SystemConfigurationType> systemConfiguration, OperationResult parentResult) {
SystemConfigurationHolder.setCurrentConfiguration(systemConfiguration.asObjectable());

Configuration systemConfigFromFile = startupConfiguration.getConfiguration(MidpointConfiguration.SYSTEM_CONFIGURATION_SECTION);
if (systemConfigFromFile != null && systemConfigFromFile
.getBoolean(LoggingConfigurationManager.SYSTEM_CONFIGURATION_SKIP_REPOSITORY_LOGGING_SETTINGS, false)) {
LOGGER.warn("Skipping application of repository logging configuration because {}=true", LoggingConfigurationManager.SYSTEM_CONFIGURATION_SKIP_REPOSITORY_LOGGING_SETTINGS);
} else {
LoggingConfigurationType loggingConfig = ProfilingConfigurationManager.checkSystemProfilingConfiguration(systemConfiguration);
applyLoggingConfiguration(loggingConfig, systemConfiguration.asObjectable().getVersion(), parentResult);
}

cacheRepositoryService.applyFullTextSearchConfiguration(systemConfiguration.asObjectable().getFullTextSearch());
}

private void applyLoggingConfiguration(LoggingConfigurationType loggingConfig, String version, OperationResult parentResult) {
if (loggingConfig != null) {
LoggingConfigurationManager.configure(loggingConfig, version, parentResult);
Expand Down
Expand Up @@ -605,4 +605,6 @@ <O extends ObjectType> boolean selectorMatches(ObjectSelectorType objectSelector
void applyFullTextSearchConfiguration(FullTextSearchConfigurationType fullTextSearch);

FullTextSearchConfigurationType getFullTextSearchConfiguration();

void postInit(OperationResult result) throws SchemaException;
}
Expand Up @@ -445,4 +445,9 @@ public void applyFullTextSearchConfiguration(FullTextSearchConfigurationType ful
public FullTextSearchConfigurationType getFullTextSearchConfiguration() {
return repository.getFullTextSearchConfiguration();
}

@Override
public void postInit(OperationResult result) throws SchemaException {
repository.postInit(result);
}
}
Expand Up @@ -16,6 +16,10 @@

package com.evolveum.midpoint.repo.sql;

import com.evolveum.midpoint.common.LoggingConfigurationManager;
import com.evolveum.midpoint.common.ProfilingConfigurationManager;
import com.evolveum.midpoint.common.SystemConfigurationHolder;
import com.evolveum.midpoint.common.configuration.api.MidpointConfiguration;
import com.evolveum.midpoint.common.crypto.CryptoUtil;
import com.evolveum.midpoint.prism.ConsistencyCheckScope;
import com.evolveum.midpoint.prism.Containerable;
Expand Down Expand Up @@ -55,6 +59,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.Validate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
Expand Down Expand Up @@ -101,23 +106,13 @@ public class SqlRepositoryServiceImpl extends SqlBaseService implements Reposito
private static final String DETAILS_HIBERNATE_DIALECT = "hibernateDialect";
private static final String DETAILS_HIBERNATE_HBM_2_DDL = "hibernateHbm2ddl";

@Autowired
private SequenceHelper sequenceHelper;

@Autowired
private ObjectRetriever objectRetriever;

@Autowired
private ObjectUpdater objectUpdater;

@Autowired
private OrgClosureManager closureManager;

@Autowired
private BaseHelper baseHelper;

@Autowired
private MatchingRuleRegistry matchingRuleRegistry;
@Autowired private SequenceHelper sequenceHelper;
@Autowired private ObjectRetriever objectRetriever;
@Autowired private ObjectUpdater objectUpdater;
@Autowired private OrgClosureManager closureManager;
@Autowired private BaseHelper baseHelper;
@Autowired private MatchingRuleRegistry matchingRuleRegistry;
@Autowired private MidpointConfiguration midpointConfiguration;

private FullTextSearchConfigurationType fullTextSearchConfiguration;

Expand Down Expand Up @@ -1012,4 +1007,33 @@ public void applyFullTextSearchConfiguration(FullTextSearchConfigurationType ful
public FullTextSearchConfigurationType getFullTextSearchConfiguration() {
return fullTextSearchConfiguration;
}

@Override
public void postInit(OperationResult result) throws SchemaException {

SystemConfigurationType systemConfiguration;
try {
systemConfiguration = getObject(SystemConfigurationType.class,
SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, result).asObjectable();
} catch (ObjectNotFoundException e) {
// ok, no problem e.g. for tests or initial startup
LOGGER.debug("System configuration not found, exiting postInit method.");
return;
}

SystemConfigurationHolder.setCurrentConfiguration(systemConfiguration);

Configuration systemConfigFromFile = midpointConfiguration.getConfiguration(MidpointConfiguration.SYSTEM_CONFIGURATION_SECTION);
if (systemConfigFromFile != null && systemConfigFromFile
.getBoolean(LoggingConfigurationManager.SYSTEM_CONFIGURATION_SKIP_REPOSITORY_LOGGING_SETTINGS, false)) {
LOGGER.warn("Skipping application of repository logging configuration because {}=true", LoggingConfigurationManager.SYSTEM_CONFIGURATION_SKIP_REPOSITORY_LOGGING_SETTINGS);
} else {
LoggingConfigurationType loggingConfig = ProfilingConfigurationManager.checkSystemProfilingConfiguration(
systemConfiguration.asPrismObject());
if (loggingConfig != null) {
LoggingConfigurationManager.configure(loggingConfig, systemConfiguration.getVersion(), result);
}
}
applyFullTextSearchConfiguration(systemConfiguration.getFullTextSearch());
}
}
Expand Up @@ -51,8 +51,7 @@
*/
@Entity
@IdClass(RObjectTextInfoId.class)
@Table(name = TABLE_NAME, indexes = {
@Index(name = "iTextInfoOid", columnList = COLUMN_OWNER_OID)})
@Table(name = TABLE_NAME)
public class RObjectTextInfo implements Serializable {

private static final Trace LOGGER = TraceManager.getTrace(RObjectTextInfo.class);
Expand All @@ -76,7 +75,7 @@ public RObjectTextInfo(RObject owner, String text) {
this.text = text;
}

@ForeignKey(name = "fk_reference_owner")
@ForeignKey(name = "fk_object_text_info_owner")
@MapsId("owner")
@ManyToOne(fetch = FetchType.LAZY)
@NotQueryable
Expand Down Expand Up @@ -167,7 +166,7 @@ public static <T extends ObjectType> Set<RObjectTextInfo> createItemsSet(@NotNul
}
}

List<String> allWords = new ArrayList<>();
List<String> allWords = new ArrayList<>(); // not a (hash) set in order to preserve order
for (PrismValue value : values) {
if (value == null) {
continue;
Expand Down Expand Up @@ -237,7 +236,9 @@ private static void append(List<String> allWords, String text, PrismContext pris
String[] words = StringUtils.split(normalized);
for (String word : words) {
if (StringUtils.isNotBlank(word)) {
allWords.add(word);
if (!allWords.contains(word)) {
allWords.add(word);
}
}
}
}
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


public class RepositoryFactory implements ApplicationContextAware, RuntimeConfiguration {

private static final String REPOSITORY_CONFIGURATION = "midpoint.repository";
Expand All @@ -45,7 +44,7 @@ public class RepositoryFactory implements ApplicationContextAware, RuntimeConfig
MidpointConfiguration midpointConfiguration;
@Autowired
private PrismContext prismContext;
//Repository factory
//Repository factory
private RepositoryServiceFactory factory;
private RepositoryServiceFactory cacheFactory;
//Repository services
Expand Down Expand Up @@ -113,14 +112,11 @@ public synchronized RepositoryService getRepositoryService() {
try {
LOGGER.debug("Creating repository service using factory {}", factory);
repositoryService = factory.getRepositoryService();
} catch (RepositoryServiceFactoryException ex) {
LoggingUtils.logException(LOGGER, "Failed to get repository service from factory " + factory, ex);
throw new SystemException("Failed to get repository service from factory " + factory, ex);
} catch (RuntimeException ex) {
LoggingUtils.logException(LOGGER, "Failed to get repository service from factory " + factory, ex);
} catch (RepositoryServiceFactoryException | RuntimeException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Failed to get repository service from factory " + factory, ex);
throw new SystemException("Failed to get repository service from factory " + factory, ex);
} catch (Error ex) {
LoggingUtils.logException(LOGGER, "Failed to get repository service from factory " + factory, ex);
LoggingUtils.logUnexpectedException(LOGGER, "Failed to get repository service from factory " + factory, ex);
throw ex;
}
}
Expand Down Expand Up @@ -154,4 +150,5 @@ public synchronized RepositoryService getCacheRepositoryService() {
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}

}

0 comments on commit 42a8fd7

Please sign in to comment.