Skip to content

Commit

Permalink
Merge branch 'tmp/node-as-assignment-holder'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/MidPointApplication.java
  • Loading branch information
mederly committed Jun 18, 2020
2 parents 4b81831 + 4c35919 commit c6aad3a
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 56 deletions.
Expand Up @@ -14,6 +14,8 @@
import javax.servlet.ServletContext;
import javax.xml.datatype.Duration;

import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import org.apache.commons.configuration2.Configuration;
import org.apache.wicket.*;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
Expand Down
Expand Up @@ -2105,7 +2105,7 @@
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ObjectType">
<xsd:extension base="tns:AssignmentHolderType">
<xsd:sequence>
<xsd:element name="nodeIdentifier" type="xsd:string">
<xsd:annotation>
Expand Down
5 changes: 0 additions & 5 deletions model/model-common/pom.xml
Expand Up @@ -80,11 +80,6 @@
<artifactId>repo-api</artifactId>
<version>4.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>repo-cache</artifactId>
<version>4.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>task-api</artifactId>
Expand Down
Expand Up @@ -12,7 +12,7 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.repo.api.Cacheable;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SearchResultList;
Expand Down
Expand Up @@ -21,7 +21,7 @@
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.api.Cacheable;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException;
Expand Down
Expand Up @@ -12,7 +12,7 @@
import com.evolveum.midpoint.repo.api.Cacheable;
import com.evolveum.midpoint.repo.api.DeleteObjectResult;
import com.evolveum.midpoint.repo.cache.invalidation.RepositoryCacheInvalidationDetails;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType;
Expand All @@ -38,14 +38,14 @@ public class TriggerCreatorGlobalState implements Cacheable {
private static final Trace LOGGER = TraceManager.getTrace(TriggerCreatorGlobalState.class);
private static final Trace LOGGER_CONTENT = TraceManager.getTrace(TriggerCreatorGlobalState.class.getName() + ".content");

private AtomicLong lastExpirationCleanup = new AtomicLong(0L);
private final AtomicLong lastExpirationCleanup = new AtomicLong(0L);

private static final long EXPIRATION_INTERVAL = 10000L;

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

private Map<TriggerHolderSpecification, CreatedTrigger> state = new ConcurrentHashMap<>();
private final Map<TriggerHolderSpecification, CreatedTrigger> state = new ConcurrentHashMap<>();

synchronized CreatedTrigger getLastCreatedTrigger(TriggerHolderSpecification key) {
return state.get(key);
Expand Down
Expand Up @@ -1496,7 +1496,7 @@ private <T extends ObjectType, F extends ObjectType> void executeModification(Ob
if (TaskType.class.isAssignableFrom(objectTypeClass)) {
taskManager.modifyTask(delta.getOid(), delta.getModifications(), result);
} else if (NodeType.class.isAssignableFrom(objectTypeClass)) {
throw new UnsupportedOperationException("NodeType is not modifiable using model interface");
cacheRepositoryService.modifyObject(NodeType.class, delta.getOid(), delta.getModifications(), result);
} else if (ObjectTypes.isClassManagedByProvisioning(objectTypeClass)) {
ProvisioningOperationOptions provisioningOptions = getProvisioningOptions(context, options,
(PrismObject<ShadowType>) objectContext.getObjectCurrent(), (ObjectDelta<ShadowType>) delta);
Expand Down
Expand Up @@ -11,8 +11,9 @@

import java.io.File;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.xml.transform.dom.DOMSource;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;

import org.springframework.test.annotation.DirtiesContext;
Expand All @@ -23,19 +24,22 @@

import com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest;
import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.RepositoryDiag;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.SystemException;
Expand All @@ -53,6 +57,8 @@ public class TestMisc extends AbstractInitializedModelIntegrationTest {
protected static final File ROLE_SHIP_FILE = new File(TEST_DIR, "role-ship.xml");
protected static final String ROLE_SHIP_OID = "bbd19b9a-d511-11e7-8bf7-cfecde275e59";

private static final TestResource<ArchetypeType> ARCHETYPE_NODE_GROUP_GUI = new TestResource<>(TEST_DIR, "archetype-node-group-gui.xml", "05b6933a-b7fc-4543-b8fa-fd8b278ff9ee");

protected static final File RESOURCE_SCRIPTY_FILE = new File(TEST_DIR, "resource-dummy-scripty.xml");
protected static final String RESOURCE_SCRIPTY_OID = "399f5308-0447-11e8-91e9-a7f9c4100ffb";
protected static final String RESOURCE_DUMMY_SCRIPTY_NAME = "scripty";
Expand All @@ -75,6 +81,7 @@ public void initSystem(Task initTask, OperationResult initResult)
RESOURCE_SCRIPTY_FILE, RESOURCE_SCRIPTY_OID, initTask, initResult);

importObjectFromFile(ROLE_SHIP_FILE);
repoAdd(ARCHETYPE_NODE_GROUP_GUI, initResult);
}

@Test
Expand Down Expand Up @@ -590,4 +597,30 @@ public void test602jackUnssigndRoleShip() throws Exception {
assertLinks(userAfter, 0);
}

@Test
public void test700AddNodeArchetype() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
given();

when();
NodeType localNode = taskManager.getLocalNode();
ObjectDelta<NodeType> delta = deltaFor(NodeType.class)
.item(NodeType.F_ASSIGNMENT)
.add(ObjectTypeUtil.createAssignmentTo(ARCHETYPE_NODE_GROUP_GUI.oid, ObjectTypes.ARCHETYPE, prismContext))
.asObjectDelta(localNode.getOid());

executeChanges(delta, null, task, result);

then();
assertObject(NodeType.class, localNode.getOid(), "after")
.display()
.assertArchetypeRef(ARCHETYPE_NODE_GROUP_GUI.oid);

Set<String> localNodeGroups = taskManager.getLocalNodeGroups().stream()
.map(ObjectReferenceType::getOid)
.collect(Collectors.toSet());
assertThat(localNodeGroups).as("local node groups")
.containsExactlyInAnyOrder(ARCHETYPE_NODE_GROUP_GUI.oid);
}
}
@@ -0,0 +1,11 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<archetype xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="05b6933a-b7fc-4543-b8fa-fd8b278ff9ee">
<name>node-group-gui</name>
</archetype>
Expand Up @@ -29,6 +29,8 @@

import com.evolveum.midpoint.model.api.util.ReferenceResolver;

import com.evolveum.midpoint.test.asserter.prism.PrismObjectAsserter;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.mutable.MutableInt;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -5851,6 +5853,16 @@ protected UserAsserter<Void> assertUser(String oid, String message) throws Objec
.assertOid(oid);
}

protected <O extends ObjectType> PrismObjectAsserter<O, Void> assertObject(Class<O> clazz, String oid, String message) throws SchemaException, ObjectNotFoundException, ConfigurationException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
PrismObject<O> object = modelService.getObject(clazz, oid, null, getTestTask(), getTestOperationResult());
return assertObject(object, message)
.assertOid();
}

protected <O extends ObjectType> PrismObjectAsserter<O, Void> assertObject(PrismObject<O> object, String message) {
return PrismObjectAsserter.forObject(object, message);
}

protected TaskAsserter<Void> assertTask(String taskOid, String message) throws SchemaException, ObjectNotFoundException {
Task task = taskManager.getTaskWithResult(taskOid, getTestOperationResult());
return assertTask(task, message);
Expand Down
Expand Up @@ -41,7 +41,7 @@
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.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.repo.api.Cacheable;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.internals.InternalCounters;
Expand Down
Expand Up @@ -11,7 +11,7 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.repo.api.Cacheable;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.schema.internals.InternalMonitor;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.caching.CachePerformanceCollector;
Expand Down
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2010-2018 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.repo.api;

import com.evolveum.midpoint.xml.ns._public.common.common_3.CachesStateInformationType;

/**
* Registry of all local cacheable services.
*/
public interface CacheRegistry {

void registerCacheableService(Cacheable cacheableService);

void unregisterCacheableService(Cacheable cacheableService);

CachesStateInformationType getStateInformation();

void dumpContent();
}
Expand Up @@ -18,7 +18,7 @@
import com.evolveum.midpoint.repo.cache.handlers.*;
import com.evolveum.midpoint.repo.cache.local.LocalRepoCacheCollection;
import com.evolveum.midpoint.repo.cache.invalidation.Invalidator;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Expand Up @@ -18,7 +18,7 @@
import com.evolveum.midpoint.repo.cache.global.GlobalQueryCache;
import com.evolveum.midpoint.repo.cache.global.GlobalVersionCache;
import com.evolveum.midpoint.repo.cache.invalidation.Invalidator;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.schema.cache.CacheConfigurationManager;

/**
Expand Down
Expand Up @@ -20,7 +20,7 @@
import com.evolveum.midpoint.repo.cache.local.LocalQueryCache;
import com.evolveum.midpoint.repo.cache.local.LocalVersionCache;
import com.evolveum.midpoint.repo.cache.local.QueryKey;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.cache.CacheConfigurationManager;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down
Expand Up @@ -11,6 +11,8 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import com.evolveum.midpoint.repo.api.CacheRegistry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -28,8 +30,8 @@
* Note that this class resides in repo-cache module almost by accident and perhaps should
* be moved to a more appropriate place.
*/
@Component
public class CacheRegistry implements CacheListener {
@Component("cacheRegistry")
public class CacheRegistryImpl implements CacheListener, CacheRegistry {

private final List<Cacheable> cacheableServices = new ArrayList<>();

Expand All @@ -46,12 +48,14 @@ public void unregisterListener() {
dispatcher.unregisterCacheListener(this);
}

@Override
public synchronized void registerCacheableService(Cacheable cacheableService) {
if (!cacheableServices.contains(cacheableService)) {
cacheableServices.add(cacheableService);
}
}

@Override
public synchronized void unregisterCacheableService(Cacheable cacheableService) {
cacheableServices.remove(cacheableService);
}
Expand All @@ -66,12 +70,14 @@ public <O extends ObjectType> void invalidate(Class<O> type, String oid, boolean
}
}

@Override
public CachesStateInformationType getStateInformation() {
CachesStateInformationType rv = new CachesStateInformationType(prismContext);
cacheableServices.forEach(cacheable -> rv.getEntry().addAll(cacheable.getStateInformation()));
return rv;
}

@Override
public void dumpContent() {
cacheableServices.forEach(Cacheable::dumpContent);
}
Expand Down
Expand Up @@ -10,7 +10,7 @@
import com.evolveum.midpoint.CacheInvalidationContext;
import com.evolveum.midpoint.repo.api.Cacheable;
import com.evolveum.midpoint.repo.api.SystemConfigurationChangeDispatcher;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down
Expand Up @@ -20,7 +20,7 @@
import com.evolveum.midpoint.common.LocalizationService;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.repo.api.Cacheable;
import com.evolveum.midpoint.repo.cache.registry.CacheRegistry;
import com.evolveum.midpoint.repo.api.CacheRegistry;
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.schema.expression.ExpressionProfile;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down
Expand Up @@ -72,12 +72,12 @@ public O getObjectable() {
return object.asObjectable();
}

public static <O extends ObjectType> PrismObjectAsserter<O,Void> forObject(PrismObject<O> shadow) {
return new PrismObjectAsserter<>(shadow);
public static <O extends ObjectType> PrismObjectAsserter<O,Void> forObject(PrismObject<O> object) {
return new PrismObjectAsserter<>(object);
}

public static <O extends ObjectType> PrismObjectAsserter<O,Void> forObject(PrismObject<O> shadow, String details) {
return new PrismObjectAsserter<>(shadow, details);
public static <O extends ObjectType> PrismObjectAsserter<O,Void> forObject(PrismObject<O> object, String details) {
return new PrismObjectAsserter<>(object, details);
}

public PrismObjectAsserter<O,RA> assertOid() {
Expand Down
Expand Up @@ -824,4 +824,12 @@ String recordTaskThreadsDump(String taskOid, String cause, OperationResult paren
* @return true if this node has recently checked in. It might be starting or up.
*/
boolean isCheckingIn(NodeType node);

/**
* @return Collection of node groups that the current cluster node belongs to.
*
* The collection is unmodifiable. Groups are represented by abstract roles.
* (Current implementation uses node archetypes to keep this information.)
*/
Collection<ObjectReferenceType> getLocalNodeGroups();
}

0 comments on commit c6aad3a

Please sign in to comment.