Skip to content

Commit

Permalink
fixing MID-4802
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Oct 10, 2018
1 parent 3b701df commit 867429a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 17 deletions.
Expand Up @@ -65,6 +65,7 @@
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

Expand Down Expand Up @@ -518,15 +519,21 @@ public Object run() {

});



InitialDataImport initialDataImport = new InitialDataImport();
initialDataImport.setModel(getModelService());
initialDataImport.setTaskManager(getTaskManager());
initialDataImport.setPrismContext(getPrismContext());
initialDataImport.setConfiguration(getMidpointConfiguration());
initialDataImport.init();


// getModelInteractionService().refreshPrincipal(SystemObjectsType.USER_ADMINISTRATOR.value());

getModelService().shutdown();

getModelService().postInit(result);


} catch (Exception ex) {
result.recomputeStatus();
Expand Down
Expand Up @@ -678,6 +678,11 @@ public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, Task ta
* up.
*/
void postInit(OperationResult parentResult);

/**
* shutdown model and lower system components
*/
public void shutdown();

/**
* TODO
Expand Down
Expand Up @@ -48,6 +48,7 @@
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
Expand All @@ -72,7 +73,7 @@ public void addListener() {
@Override
public <O extends ObjectType> void invalidateCache(Class<O> type, String oid) {

if (!FunctionLibraryType.class.equals(type) && !SystemConfigurationType.class.equals(type)) {
if (!FunctionLibraryType.class.equals(type) && !SystemConfigurationType.class.equals(type) && !ConnectorType.class.equals(type)) {
LOGGER.trace("Type {} not yet supported for cache clearance. Skipping.", type);
return;
}
Expand Down
Expand Up @@ -1636,6 +1636,18 @@ public void postInit(OperationResult parentResult) {
result.cleanupResult();
}

@Override
public void shutdown() {

enterModelMethod();

provisioning.shutdown();

// taskManager.shutdown();

exitModelMethod();
}

@Override
public <T extends ObjectType> CompareResultType compareObject(PrismObject<T> provided,
Collection<SelectorOptions<GetOperationOptions>> rawReadOptions, ModelCompareOptions compareOptions,
Expand Down
Expand Up @@ -25,6 +25,8 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.annotation.PostConstruct;

import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import org.apache.commons.lang.StringUtils;
Expand All @@ -43,6 +45,8 @@
import com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance;
import com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.CacheRegistry;
import com.evolveum.midpoint.repo.common.Cacheable;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
Expand Down Expand Up @@ -76,20 +80,23 @@
*
*/
@Component
public class ConnectorManager {
public class ConnectorManager implements Cacheable {

private static final String USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA = ConnectorManager.class.getName()+".parsedSchema";

@Autowired
@Qualifier("cacheRepositoryService")
private RepositoryService repositoryService;

@Autowired(required = true)
ApplicationContext springContext;

@Autowired(required = true)
private PrismContext prismContext;

@Autowired ApplicationContext springContext;
@Autowired private PrismContext prismContext;
@Autowired CacheRegistry cacheRegistry;

@PostConstruct
public void register() {
cacheRegistry.registerCacheableService(this);
}

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

private Collection<ConnectorFactory> connectorFactories;
Expand Down Expand Up @@ -582,10 +589,14 @@ public void connectorFrameworkSelfTest(OperationResult parentTestResult, Task ta
}
}

public void shutdown() {
public void dispose() {
for (Entry<ConfiguredConnectorCacheKey, ConfiguredConnectorInstanceEntry> connectorInstanceCacheEntry: connectorInstanceCache.entrySet()) {
connectorInstanceCacheEntry.getValue().connectorInstance.dispose();
}
}

public void shutdown() {
dispose();
if (connectorFactories != null) {
// Skip this in the very rare case that we are shutting down before we were fully
// initialized. This should not happen under normal circumstances.
Expand All @@ -602,4 +613,11 @@ private interface ConnectorFactoryConsumer {
void process(ConnectorFactory connectorFactory) throws CommunicationException;
}

@Override
public void clearCache() {
dispose();
connectorInstanceCache = new ConcurrentHashMap<>();
connectorTypeCache = new ConcurrentHashMap<>();
}

}
Expand Up @@ -25,6 +25,7 @@
import org.springframework.stereotype.Component;
import com.evolveum.midpoint.repo.api.CacheDispatcher;
import com.evolveum.midpoint.repo.api.CacheListener;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

Expand All @@ -48,17 +49,17 @@ public List<Cacheable> getCacheableServices() {
return cacheableServices;
}

public void clearAllCaches() {
for (Cacheable cacheableService : cacheableServices) {
cacheableService.clearCache();
}
}

@Override
public <O extends ObjectType> void invalidateCache(Class<O> type, String oid) {
if (FunctionLibraryType.class.equals(type) || SystemConfigurationType.class.equals(type)) {
if (FunctionLibraryType.class.equals(type) || SystemConfigurationType.class.equals(type) || ConnectorType.class.equals(type)) {
clearAllCaches();
}
}

public void clearAllCaches() {
for (Cacheable cacheableService : cacheableServices) {
cacheableService.clearCache();
}
}
}

0 comments on commit 867429a

Please sign in to comment.