Skip to content

Commit

Permalink
Add graceful group deletion in I2 scenario
Browse files Browse the repository at this point in the history
Org that is deleted from Grouper is put into "archiving" lifecycle
state. Such groups are gracefully removed using special scavenger task.

Also added input/output lens context debug dump to all click and
projector component traces (maybe temporarily).
  • Loading branch information
mederly committed Oct 11, 2019
1 parent c7d5d1d commit 23a6f2b
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 36 deletions.
Expand Up @@ -813,6 +813,26 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="inputLensContextText" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Lens (model) context at input (text dump).
</xsd:documentation>
<xsd:appinfo>
<a:since>4.0.1</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="outputLensContextText" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Lens (model) context at output (text dump).
</xsd:documentation>
<xsd:appinfo>
<a:since>4.0.1</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down
Expand Up @@ -2235,7 +2235,7 @@
for activation in these hardcoded states ("undefined" for active and deprecated
states, "archived" for archived state, "disabled" for all other states). To turn off this default behaviour
those hardcoded lifecycle states need to be explicitly defined in the state model
and the forcedActivationStatus property shoule be left undefined.
and the forcedActivationStatus property should be left undefined.
</p>
</xsd:documentation>
<xsd:appinfo>
Expand All @@ -2249,10 +2249,10 @@
<xsd:documentation>
<p>
There are cases when you need to force midpoint thinks that user has assigned some
role. The assignemnt actually doesn't exist but there is a need to preted as it does.
role. The assignment actually doesn't exist but there is a need to pretend as it does.
This can be used e.g. for post-authentication flow. The user has assigned all business,
application, etc. roles but we don't want to consider these roles during his
post-authentication proces. Instead, we want to pretend he has "temporary" role assigned
post-authentication process. Instead, we want to pretend he has "temporary" role assigned
which allows him to perform post-authentication.
</p>
</xsd:documentation>
Expand Down Expand Up @@ -2340,10 +2340,10 @@
<xsd:documentation>
<p>
There are cases when you need to force midpoint thinks that user has assigned some
role. The assignemnt actually doesn't exist but there is a need to preted as it does.
role. The assignment actually doesn't exist but there is a need to pretend as it does.
This can be used e.g. for post-authentication flow. The user has assigned all business,
application, etc. roles but we don't want to consider these roles during his
post-authentication proces. Instead, we want to pretend he has "temporary" role assigned
post-authentication process. Instead, we want to pretend he has "temporary" role assigned
which allows him to perform post-authentication.
</p>
</xsd:documentation>
Expand Down
Expand Up @@ -266,10 +266,7 @@ private <F extends ObjectType> boolean startTracingIfRequested(LensContext<F> co
private <F extends ObjectType> ClockworkRunTraceType recordTraceAtStart(LensContext<F> context, Task task,
OperationResult result) throws SchemaException {
ClockworkRunTraceType trace = new ClockworkRunTraceType(prismContext);
TracingLevelType level = result.getTracingLevel(trace.getClass());
if (level.ordinal() >= TracingLevelType.MINIMAL.ordinal()) {
trace.getText().add(context.debugDump()); // todo
}
trace.setInputLensContextText(context.debugDump());
trace.setInputLensContext(context.toLensContextType(getExportTypeTraceOrReduced(trace, result)));
result.addTrace(trace);
return trace;
Expand All @@ -278,6 +275,7 @@ private <F extends ObjectType> ClockworkRunTraceType recordTraceAtStart(LensCont
private <F extends ObjectType> void recordTraceAtEnd(LensContext<F> context, ClockworkRunTraceType trace,
OperationResult result) throws SchemaException {
if (trace != null) {
trace.setOutputLensContextText(context.debugDump());
trace.setOutputLensContext(context.toLensContextType(getExportTypeTraceOrReduced(trace, result)));
if (context.getFocusContext() != null) { // todo reconsider this
PrismObject<F> objectAny = context.getFocusContext().getObjectAny();
Expand Down Expand Up @@ -537,6 +535,9 @@ public <F extends ObjectType> HookOperationMode click(LensContext<F> context, Ta
ClockworkClickTraceType trace;
if (result.isTraced()) {
trace = new ClockworkClickTraceType(prismContext);
if (result.isTracingNormal(ClockworkClickTraceType.class)) {
trace.setInputLensContextText(context.debugDump());
}
trace.setInputLensContext(context.toLensContextType(getExportType(trace, result)));
result.getTraces().add(trace);
} else {
Expand Down Expand Up @@ -627,6 +628,9 @@ public <F extends ObjectType> HookOperationMode click(LensContext<F> context, Ta
throw e;
} finally {
if (trace != null) {
if (result.isTracingNormal(ClockworkClickTraceType.class)) {
trace.setOutputLensContextText(context.debugDump());
}
trace.setOutputLensContext(context.toLensContextType(getExportType(trace, result)));
}
result.computeStatusIfUnknown();
Expand Down
Expand Up @@ -195,6 +195,9 @@ public void partialExecute(String baseComponentName, ProjectorComponentRunnable
ProjectorComponentTraceType trace;
if (result.isTraced()) {
trace = new ProjectorComponentTraceType();
if (result.isTracingNormal(ProjectorComponentTraceType.class)) {
trace.setInputLensContextText(context.debugDump());
}
trace.setInputLensContext(context.toLensContextType(getExportType(trace, result)));
result.addTrace(trace);
} else {
Expand All @@ -215,6 +218,9 @@ public void partialExecute(String baseComponentName, ProjectorComponentRunnable
} finally {
result.computeStatusIfUnknown();
if (trace != null) {
if (result.isTracingNormal(ProjectorComponentTraceType.class)) {
trace.setOutputLensContextText(context.debugDump());
}
trace.setOutputLensContext(context.toLensContextType(getExportType(trace, result)));
}
if (clockworkInspector != null) {
Expand Down
Expand Up @@ -107,6 +107,9 @@ public <F extends ObjectType> void load(LensContext<F> context, String activityD
ProjectorComponentTraceType trace;
if (result.isTraced()) {
trace = new ProjectorComponentTraceType(prismContext);
if (result.isTracingNormal(ProjectorComponentTraceType.class)) {
trace.setInputLensContextText(context.debugDump());
}
trace.setInputLensContext(context.toLensContextType(getExportType(trace, result)));
result.addTrace(trace);
} else {
Expand Down Expand Up @@ -194,6 +197,9 @@ public <F extends ObjectType> void load(LensContext<F> context, String activityD
throw e;
} finally {
if (trace != null) {
if (result.isTracingNormal(ProjectorComponentTraceType.class)) {
trace.setOutputLensContextText(context.debugDump());
}
trace.setOutputLensContext(context.toLensContextType(getExportType(trace, result)));
}
}
Expand Down Expand Up @@ -327,6 +333,9 @@ public <O extends ObjectType> void determineFocusContext(LensContext<O> context,
FocusLoadedTraceType trace;
if (result.isTraced()) {
trace = new FocusLoadedTraceType();
if (result.isTracingNormal(FocusLoadedTraceType.class)) {
trace.setInputLensContextText(context.debugDump());
}
trace.setInputLensContext(context.toLensContextType(getExportType(trace, result)));
result.addTrace(trace);
} else {
Expand Down Expand Up @@ -392,6 +401,9 @@ public <O extends ObjectType> void determineFocusContext(LensContext<O> context,
throw t;
} finally {
if (trace != null) {
if (result.isTracingNormal(FocusLoadedTraceType.class)) {
trace.setOutputLensContextText(context.debugDump());
}
trace.setOutputLensContext(context.toLensContextType(getExportType(trace, result)));
}
result.computeStatusIfUnknown();
Expand Down Expand Up @@ -1444,6 +1456,9 @@ public <F extends ObjectType> void loadFullShadow(LensContext<F> context, LensPr
FullShadowLoadedTraceType trace;
if (result.isTraced()) {
trace = new FullShadowLoadedTraceType(prismContext);
if (result.isTracingNormal(FullShadowLoadedTraceType.class)) {
trace.setInputLensContextText(context.debugDump());
}
trace.setInputLensContext(context.toLensContextType(getExportType(trace, result)));
result.addTrace(trace);
} else {
Expand Down Expand Up @@ -1512,6 +1527,9 @@ public <F extends ObjectType> void loadFullShadow(LensContext<F> context, LensPr
throw t;
} finally {
if (trace != null) {
if (result.isTracingNormal(FullShadowLoadedTraceType.class)) {
trace.setOutputLensContextText(context.debugDump());
}
trace.setOutputLensContext(context.toLensContextType(getExportType(trace, result)));
}
result.computeStatusIfUnknown();
Expand Down
Expand Up @@ -3588,25 +3588,33 @@ protected void restartTask(String taskOid) throws CommonException {
LOGGER.warn("Sleep interrupted: {}", e.getMessage(), e);
}

final OperationResult result = new OperationResult(AbstractIntegrationTest.class+".restartTask");
Task task = taskManager.getTaskWithResult(taskOid, result);
LOGGER.info("Restarting task {}", taskOid);
if (task.getExecutionStatus() == TaskExecutionStatus.SUSPENDED) {
LOGGER.debug("Task {} is suspended, resuming it", task);
taskManager.resumeTask(task, result);
} else if (task.getExecutionStatus() == TaskExecutionStatus.CLOSED) {
LOGGER.debug("Task {} is closed, scheduling it to run now", task);
taskManager.scheduleTasksNow(singleton(taskOid), result);
} else if (task.getExecutionStatus() == TaskExecutionStatus.RUNNABLE) {
if (taskManager.getLocallyRunningTaskByIdentifier(task.getTaskIdentifier()) != null) {
// Task is really executing. Let's wait until it finishes; hopefully it won't start again (TODO)
LOGGER.debug("Task {} is running, waiting while it finishes before restarting", task);
waitForTaskFinish(taskOid, false);
OperationResult result = createSubresult("restartTask");
try {
Task task = taskManager.getTaskWithResult(taskOid, result);
LOGGER.info("Restarting task {}", taskOid);
if (task.getExecutionStatus() == TaskExecutionStatus.SUSPENDED) {
LOGGER.debug("Task {} is suspended, resuming it", task);
taskManager.resumeTask(task, result);
} else if (task.getExecutionStatus() == TaskExecutionStatus.CLOSED) {
LOGGER.debug("Task {} is closed, scheduling it to run now", task);
taskManager.scheduleTasksNow(singleton(taskOid), result);
} else if (task.getExecutionStatus() == TaskExecutionStatus.RUNNABLE) {
if (taskManager.getLocallyRunningTaskByIdentifier(task.getTaskIdentifier()) != null) {
// Task is really executing. Let's wait until it finishes; hopefully it won't start again (TODO)
LOGGER.debug("Task {} is running, waiting while it finishes before restarting", task);
waitForTaskFinish(taskOid, false);
}
LOGGER.debug("Task {} is finished, scheduling it to run now", task);
taskManager.scheduleTasksNow(singleton(taskOid), result);
} else {
throw new IllegalStateException(
"Task " + task + " cannot be restarted, because its state is: " + task.getExecutionStatus());
}
LOGGER.debug("Task {} is finished, scheduling it to run now", task);
taskManager.scheduleTasksNow(singleton(taskOid), result);
} else {
throw new IllegalStateException("Task " + task + " cannot be restarted, because its state is: " + task.getExecutionStatus());
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}

Expand Down
Expand Up @@ -331,6 +331,18 @@ protected Task getOrCreateTask(String methodName) {
}
}

protected OperationResult createSubresult(String methodName) {
String className = this.getClass().getName();
MidpointTestMethodContext ctx = MidpointTestMethodContext.get();
OperationResult parent;
if (ctx != null) {
parent = ctx.getResult();
} else {
parent = new OperationResult(className + ".parent");
}
return parent.createSubresult(className + "." + methodName);
}

protected OperationResult getResult() {
MidpointTestMethodContext ctx = MidpointTestMethodContext.get();
if (ctx != null) {
Expand Down

0 comments on commit 23a6f2b

Please sign in to comment.