Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 8, 2022
2 parents f65dcde + 5d58f81 commit 4ec2501
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private IModel<String> getAlreadyAssignedIconTitleModel(AssignmentEditorDto dto)
for (QName relation : assignedRelations) {
RelationDefinitionType def = ObjectTypeUtil.findRelationDefinition(defs, relation);
String relationLabel;
if (def == null || def.getCategory() == null || def.getDisplay().getLabel() == null){
if (def == null || def.getDisplay() == null || def.getDisplay().getLabel() == null){
relationLabel = relation.getLocalPart();
} else {
relationLabel = createStringResource(def.getDisplay().getLabel()).getString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3389,11 +3389,15 @@ public void timeout() {
}

// We assume the task is runnable/running.
// Uses heartbeat method to determine the progress; so the progress may not be reflected in the repo after returning
// from this method.
@Experimental
protected Task waitForTaskProgress(String taskOid, long progressToReach, int timeout, OperationResult waitResult) throws Exception {
return waitForTaskProgress(taskOid, progressToReach, null, timeout, (int) DEFAULT_TASK_SLEEP_TIME, waitResult);
}

// Uses heartbeat method to determine the progress; so the progress may not be reflected in the repo after returning
// from this method.
@Experimental
protected Task waitForTaskProgress(String taskOid, long progressToReach, CheckedProducer<Boolean> extraTest,
int timeout, int sleepTime, OperationResult waitResult) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
/*
* Copyright (c) 2010-2017 Evolveum and contributors
* Copyright (C) 2010-2022 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.notifications.impl.notifiers;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.model.api.context.ModelElementContext;
import com.evolveum.midpoint.notifications.api.events.ModelEvent;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

@Component
public class AccountActivationNotifier extends ConfirmationNotifier<AccountActivationNotifierType> {
Expand Down Expand Up @@ -104,7 +102,7 @@ protected String getBody(ModelEvent event, AccountActivationNotifierType configu
resource = modelService.getObject(ResourceType.class, resourceOid, null, task, result);
} catch (ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException
| ExpressionEvaluationException | SchemaException e) {
getLogger().error("Could't get Resource with oid " + resourceOid, e);
getLogger().error("Couldn't get Resource with oid " + resourceOid, e);
throw new SystemException("Couldn't get resource " + resourceOid, e);
}
body.append(StringUtils.isNotBlank(resource.getDisplayName()) ? resource.getDisplayName() : resource.getName());
Expand All @@ -115,7 +113,7 @@ protected String getBody(ModelEvent event, AccountActivationNotifierType configu
}
for (Object att : shadow.getAttributes().asPrismContainerValue().getItems()) {
if (att instanceof ResourceAttribute) {
ResourceAttribute attribute = (ResourceAttribute) att;
ResourceAttribute<?> attribute = (ResourceAttribute<?>) att;
body.append(" - ").append(attribute.getDisplayName()).append(": ");
if (attribute.isSingleValue()) {
body.append(attribute.getRealValue()).append("\n");
Expand All @@ -142,7 +140,7 @@ private String getRequestorDisplayName(ObjectType requester) {
if (requester.asPrismObject().getDisplayName() != null) {
name = requester.asPrismObject().getDisplayName();
}
if (requester instanceof UserType){
if (requester instanceof UserType) {
if (((UserType) requester).getFullName() != null) {
name = ((UserType) requester).getFullName().getOrig();
}
Expand All @@ -151,7 +149,7 @@ private String getRequestorDisplayName(ObjectType requester) {
}

private List<ShadowType> getShadowsToActivate(ModelEvent modelEvent) {
Collection<? extends ModelElementContext> projectionContexts = modelEvent.getProjectionContexts();
Collection<? extends ModelElementContext<?>> projectionContexts = modelEvent.getProjectionContexts();
return getMidpointFunctions().getShadowsToActivate(projectionContexts);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.io.File;
import javax.annotation.PreDestroy;

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

import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
Expand All @@ -26,10 +28,6 @@
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.testing.story.AbstractStoryTest;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

/**
* Complex testing of asynchronous provisioning and updating.
Expand All @@ -49,10 +47,9 @@ public class TestAsyncProvisioning extends AbstractStoryTest {
private static final TestResource<TaskType> TASK_ASYNC_UPDATE_MULTI = new TestResource<>(TEST_DIR, "task-async-update-multi.xml", "c1f5a293-9fc9-4ab4-b497-de8605ee7dc6");
private static final TestResource<TaskType> TASK_RECOMPUTE_MULTI = new TestResource<>(TEST_DIR, "task-recompute-multi.xml", "8b21b493-c85e-4a77-800f-a9063d1cfe8c");

protected EmbeddedActiveMQ embeddedBroker;
private EmbeddedActiveMQ embeddedBroker;

private PrismObject<ResourceType> resourceOutbound;
private PrismObject<ResourceType> resourceInbound;

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
Expand All @@ -61,7 +58,11 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
startEmbeddedBroker();

resourceOutbound = importAndGetObjectFromFile(ResourceType.class, RESOURCE_ASYNC_OUTBOUND.file, RESOURCE_ASYNC_OUTBOUND.oid, initTask, initResult);
resourceInbound = importAndGetObjectFromFile(ResourceType.class, RESOURCE_ASYNC_INBOUND.file, RESOURCE_ASYNC_INBOUND.oid, initTask, initResult);
importAndGetObjectFromFile(ResourceType.class, RESOURCE_ASYNC_INBOUND.file, RESOURCE_ASYNC_INBOUND.oid, initTask, initResult);

// We have to test the resource before async update task is started. See MID-7721.
assertSuccess(modelService.testResource(RESOURCE_ASYNC_OUTBOUND.oid, initTask));
assertSuccess(modelService.testResource(RESOURCE_ASYNC_INBOUND.oid, initTask));

addObject(TASK_ASYNC_UPDATE, initTask, initResult);
}
Expand All @@ -82,37 +83,37 @@ protected File getSystemConfigurationFile() {
return SYSTEM_CONFIGURATION_FILE;
}

@Test
public void test000Sanity() throws Exception {
Task task = getTestTask();

assertSuccess(modelService.testResource(RESOURCE_ASYNC_OUTBOUND.oid, task));
assertSuccess(modelService.testResource(RESOURCE_ASYNC_INBOUND.oid, task));
}

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

UserType jim = new UserType(prismContext)
UserType jim = new UserType()
.name("jim")
.fullName("Jim Beam")
.assignment(
createAssignmentWithConstruction(
resourceOutbound, ShadowKindType.ACCOUNT, SchemaConstants.INTENT_DEFAULT, prismContext));

when();
when("object is added and the addition is processed by the async update task");
addObject(jim.asPrismObject(), task, result);

waitForTaskProgress(TASK_ASYNC_UPDATE.oid, 1, 30000, result);

then();
then("task should be (still) ready");
assertTask(TASK_ASYNC_UPDATE.oid, "update task after")
.display()
// Checking for MID-7721 (though test connection is now done before starting the task, so this shouldn't fail)
.assertSchedulingState(TaskSchedulingStateType.READY);

and("'original' user should have the 'outbound' link");
assertSuccess(result);
assertUserAfter(jim.getOid())
.assertAssignments(1)
.assertLiveLinks(1);

and("'mirrored' user should be created");
assertUserAfterByUsername("_jim")
.assertAssignments(0)
.assertLiveLinks(1)
Expand Down Expand Up @@ -178,7 +179,7 @@ public void test200AddManyUsers() throws Exception {

int users = 30;
for (int i = 0; i < users; i++) {
UserType user = new UserType(prismContext)
UserType user = new UserType()
.name(String.format("user-%06d", i))
.fullName(String.format("User %06d", i))
.assignment(
Expand Down
32 changes: 14 additions & 18 deletions testing/story/src/test/resources/async/task-async-update-multi.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
<!--
~ Copyright (c) 2019 Evolveum and contributors
~ Copyright (C) 2010-2022 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<task xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
oid="c1f5a293-9fc9-4ab4-b497-de8605ee7dc6">
<task xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" oid="c1f5a293-9fc9-4ab4-b497-de8605ee7dc6">
<name>Async update multithreaded</name>
<extension xmlns:mext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3">
<mext:workerThreads>3</mext:workerThreads>
</extension>
<ownerRef oid="00000000-0000-0000-0000-000000000002" type="UserType"/>
<executionState>runnable</executionState>
<category>AsynchronousUpdate</category>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/async-update/handler-3</handlerUri>
<objectRef oid="6628a329-4b29-4f3a-9339-8fa12c59c38f" type="ResourceType"/>
<recurrence>single</recurrence>
<binding>loose</binding>
<threadStopAction>restart</threadStopAction>
<activity>
<work>
<asynchronousUpdate>
<updatedResourceObjects>
<resourceRef oid="6628a329-4b29-4f3a-9339-8fa12c59c38f"/>
</updatedResourceObjects>
</asynchronousUpdate>
</work>
<distribution>
<workerThreads>3</workerThreads>
</distribution>
</activity>
</task>
29 changes: 11 additions & 18 deletions testing/story/src/test/resources/async/task-async-update.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
<!--
~ Copyright (c) 2019 Evolveum and contributors
~ Copyright (C) 2010-2022 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<task xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
oid="2041e429-8ca9-4f80-a38f-1e3359627e39">
<task xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" oid="2041e429-8ca9-4f80-a38f-1e3359627e39">
<name>Async update</name>
<extension xmlns:mext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3">
<!-- ... -->
</extension>
<ownerRef oid="00000000-0000-0000-0000-000000000002" type="UserType"/>
<executionState>runnable</executionState>
<category>AsynchronousUpdate</category>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/async-update/handler-3</handlerUri>
<objectRef oid="6628a329-4b29-4f3a-9339-8fa12c59c38f" type="ResourceType"/>
<recurrence>single</recurrence>
<binding>loose</binding>
<threadStopAction>restart</threadStopAction>
<activity>
<work>
<asynchronousUpdate>
<updatedResourceObjects>
<resourceRef oid="6628a329-4b29-4f3a-9339-8fa12c59c38f"/>
</updatedResourceObjects>
</asynchronousUpdate>
</work>
</activity>
</task>

0 comments on commit 4ec2501

Please sign in to comment.