Skip to content

Commit

Permalink
Support for explosive volatility (MID-3727)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Feb 15, 2017
1 parent f789e90 commit eacec78
Show file tree
Hide file tree
Showing 20 changed files with 347 additions and 103 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 Evolveum
* 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.
Expand Down Expand Up @@ -58,6 +58,7 @@ public class DummyConfiguration extends AbstractConfiguration {
private boolean addConnectorStateAttributes = false;
private boolean supportReturnDefaultAttributes = false; // used e.g. for livesync vs. auxiliary object classes test
private boolean requireNameHint = false;
private boolean monsterized = false;

/**
* Defines name of the dummy resource instance. There may be several dummy resource running in
Expand Down Expand Up @@ -352,6 +353,15 @@ public boolean isRequireNameHint() {
public void setRequireNameHint(boolean requireNameHint) {
this.requireNameHint = requireNameHint;
}

@ConfigurationProperty
public boolean isMonsterized() {
return monsterized;
}

public void setMonsterized(boolean monsterized) {
this.monsterized = monsterized;
}

/**
* {@inheritDoc}
Expand Down
Expand Up @@ -157,13 +157,9 @@ public void init(Configuration configuration) {
if (uselessGuardedString == null) {
resource.setUselessGuardedString(null);
} else {
uselessGuardedString.access(new GuardedString.Accessor() {
@Override
public void access(char[] chars) {
resource.setUselessGuardedString(new String(chars));
}
});
uselessGuardedString.access(chars -> resource.setUselessGuardedString(new String(chars)));
}
resource.setMonsterization(this.configuration.isMonsterized());

resource.connect();

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 Evolveum
* 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.
Expand Down Expand Up @@ -228,6 +228,15 @@ private void addAttributeValue(String attrName, Set<Object> currentValues, Objec
}
}

if (resource != null && resource.isMonsterization() && DummyResource.VALUE_MONSTER.equals(valueToAdd)) {
Iterator<Object> iterator = currentValues.iterator();
while (iterator.hasNext()) {
if (DummyResource.VALUE_COOKIE.equals(iterator.next())) {
iterator.remove();
}
}
}

Set<Object> valuesToCheck = new HashSet<Object>();
valuesToCheck.addAll(currentValues);
valuesToCheck.add(valueToAdd);
Expand Down
Expand Up @@ -100,6 +100,20 @@ public class DummyResource implements DebugDumpable {
private int groupMembersReadCount = 0;
private Collection<String> forbiddenNames;

/**
* There is a monster that loves to eat cookies.
* If value "monster" is added to an attribute that
* contain the "cookie" value, the monster will
* eat that cookie. Then is goes to sleep. If more
* cookies are added then the monster will not
* eat them.
* MID-3727
*/
private boolean monsterization = false;

public static final String VALUE_MONSTER = "monster";
public static final String VALUE_COOKIE = "cookie";

private BreakMode schemaBreakMode = BreakMode.NONE;
private BreakMode getBreakMode = BreakMode.NONE;
private BreakMode addBreakMode = BreakMode.NONE;
Expand Down Expand Up @@ -333,6 +347,14 @@ public void setForbiddenNames(Collection<String> forbiddenNames) {
this.forbiddenNames = forbiddenNames;
}

public boolean isMonsterization() {
return monsterization;
}

public void setMonsterization(boolean monsterization) {
this.monsterization = monsterization;
}

public int getConnectionCount() {
return connectionCount;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 Evolveum
* 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.
Expand Down Expand Up @@ -275,6 +275,11 @@ public ObjectClassComplexTypeDefinition getObjectClassDefinition() {
public ResourceObjectReferenceType getBaseContext() {
return structuralObjectClassDefinition.getBaseContext();
}

@Override
public ResourceObjectVolatilityType getVolatility() {
return structuralObjectClassDefinition.getVolatility();
}

@Override
public List<MappingType> getPasswordInbound() {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 Evolveum
* 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.
Expand Down Expand Up @@ -584,6 +584,11 @@ public ResourceObjectReferenceType getBaseContext() {
return refinedObjectClassDefinition.getBaseContext();
}

@Override
public ResourceObjectVolatilityType getVolatility() {
return refinedObjectClassDefinition.getVolatility();
}

@Override
public Class getTypeClassIfKnown() {
return refinedObjectClassDefinition.getTypeClassIfKnown();
Expand Down
Expand Up @@ -129,6 +129,8 @@ default Collection<RefinedAssociationDefinition> getEntitlementAssociationDefini
ResourceObjectReferenceType getBaseContext();

String getHumanReadableName();

ResourceObjectVolatilityType getVolatility();
//endregion


Expand Down
Expand Up @@ -312,6 +312,14 @@ public ShadowKindType getKind() {
public void setKind(ShadowKindType kind) {
this.kind = kind;
}

@Override
public ResourceObjectVolatilityType getVolatility() {
if (schemaHandlingObjectTypeDefinitionType == null) {
return null;
}
return schemaHandlingObjectTypeDefinitionType.getVolatility();
}

//endregion

Expand Down
Expand Up @@ -4362,6 +4362,22 @@
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="explosive">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="EXPLOSIVE"/>
</xsd:appinfo>
<xsd:documentation>
The object can change in insane ways as a reaction to changes made by midPoint.
E.g. the attribute that was modified by midPoint can be modified in a different way
by the resource (this sometimes happen for nested groups). There is no way how to
handle such a volatile behavior other than to re-read the account and re-run
reconciliation after every change that midPoint does.
This really brutal solution. It is quite inefficient. But it may be the only option
to reliably manage data in some resources.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

Expand Down
Expand Up @@ -581,6 +581,19 @@ public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(fin
for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
executedDeltas.addAll(projectionContext.getExecutedDeltas());
}

if (context.hasExplosiveProjection()) {
PrismObject<? extends ObjectType> focus = context.getFocusContext().getObjectAny();

LOGGER.debug("Recomputing {} because there was explosive projection", focus);

LensContext<? extends ObjectType> recomputeContext = contextFactory.createRecomputeContext(focus, task, result);
recomputeContext.setDoReconciliationForAllProjections(true);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Recomputing {}, context:\n{}", focus, recomputeContext.debugDump());
}
clockwork.run(recomputeContext, task, result);
}

cleanupOperationResult(result);

Expand Down Expand Up @@ -675,10 +688,12 @@ public <F extends ObjectType> void recompute(Class<F> type, String oid, Task tas
Utils.clearRequestee(task);
PrismObject<F> focus = objectResolver.getObject(type, oid, null, task, result).asPrismContainer();

LOGGER.trace("Recomputing {}", focus);
LOGGER.debug("Recomputing {}", focus);

LensContext<F> syncContext = contextFactory.createRecomputeContext(focus, task, result);
LOGGER.trace("Recomputing {}, context:\n{}", focus, syncContext.debugDump());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Recomputing {}, context:\n{}", focus, syncContext.debugDump());
}
clockwork.run(syncContext, task, result);

result.computeStatus();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* 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.
Expand Down Expand Up @@ -1148,4 +1148,13 @@ public void addConflictingProjectionContext(LensProjectionContext conflictingCon
public void clearConflictingProjectionContexts() {
conflictingProjectionContexts.clear();
}

public boolean hasExplosiveProjection() throws SchemaException {
for (LensProjectionContext projectionContext: projectionContexts) {
if (projectionContext.getVolatility() == ResourceObjectVolatilityType.EXPLOSIVE) {
return true;
}
}
return false;
}
}
Expand Up @@ -1394,4 +1394,12 @@ public String getResourceOid() {
return null;
}
}

public ResourceObjectVolatilityType getVolatility() throws SchemaException {
RefinedObjectClassDefinition structuralObjectClassDefinition = getStructuralObjectClassDefinition();
if (structuralObjectClassDefinition == null) {
return null;
}
return structuralObjectClassDefinition.getVolatility();
}
}
Expand Up @@ -294,7 +294,7 @@ public void notifyChange(ResourceObjectShadowChangeDescription change, Task task
}
subResult.recordSuccess();
eventInfo.record(task);
LOGGER.debug("SYNCHRONIZATION: DONE (dry run) for {}", object);
LOGGER.debug("SYNCHRONIZATION: DONE (dry run/unrelated) for {}", object);
return;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 Evolveum
* 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.
Expand Down Expand Up @@ -139,7 +139,7 @@ public void initSystem(Task initTask, OperationResult initResult)
throws Exception {
super.initSystem(initTask, initResult);

initDummyResource(RESOURCE_DUMMY_CIRCUS_NAME, RESOURCE_DUMMY_CIRCUS_FILE, RESOURCE_DUMMY_CIRCUS_OID, null, initTask, initResult);
initDummyResource(RESOURCE_DUMMY_CIRCUS_NAME, RESOURCE_DUMMY_CIRCUS_FILE, RESOURCE_DUMMY_CIRCUS_OID, initTask, initResult);

dummyResourceCtlRed.addAccount(ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", "Monkey Island");

Expand Down

0 comments on commit eacec78

Please sign in to comment.