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 Feb 12, 2018
2 parents 5022507 + 566243f commit 3f10d3c
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 17 deletions.
Expand Up @@ -141,8 +141,8 @@ public abstract class AbstractGroupingManualResourceTest extends AbstractManualR
protected static final File TASK_PROPAGATION_MANUAL_GROUPING_FILE = new File(TEST_DIR, "task-propagation-manual-grouping.xml");
protected static final String TASK_PROPAGATION_MANUAL_GROUPING_OID = "b84a2c46-f0b5-11e7-baff-d35c2f14080f";

protected static final File TASK_PROPAGATION_SEMI_MANUAL_GROUPING_FILE = new File(TEST_DIR, "task-propagation-semi-manual-grouping.xml");
protected static final String TASK_PROPAGATION_SEMI_MANUAL_GROUPING_OID = "01db4542-f224-11e7-8833-bbe6634814e7";
protected static final File TASK_PROPAGATION_MULTI_FILE = new File(TEST_DIR, "task-propagation-multi.xml");
protected static final String TASK_PROPAGATION_MULTI_OID = "01db4542-f224-11e7-8833-bbe6634814e7";

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

Expand Down
Expand Up @@ -83,12 +83,12 @@ protected File getRoleTwoFile() {

@Override
protected String getPropagationTaskOid() {
return TASK_PROPAGATION_SEMI_MANUAL_GROUPING_OID;
return TASK_PROPAGATION_MULTI_OID;
}

@Override
protected File getPropagationTaskFile() {
return TASK_PROPAGATION_SEMI_MANUAL_GROUPING_FILE;
return TASK_PROPAGATION_MULTI_FILE;
}

@Override
Expand Down
1 change: 1 addition & 0 deletions model/model-intest/src/test/resources/logback-test.xml
Expand Up @@ -83,6 +83,7 @@
<logger name="com.evolveum.midpoint.provisioning.impl.ResourceManager" level="DEBUG" />
<logger name="com.evolveum.midpoint.provisioning.impl.ShadowCache" level="DEBUG" />
<logger name="com.evolveum.midpoint.provisioning.impl.ShadowManager" level="DEBUG" />
<logger name="com.evolveum.midpoint.provisioning.impl.task" level="DEBUG" />
<logger name="com.evolveum.midpoint.provisioning.consistency" level="DEBUG" />
<logger name="com.evolveum.midpoint.expression" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression" level="DEBUG" />
Expand Down
Expand Up @@ -24,10 +24,15 @@
xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:rext="http://midpoint.evolveum.com/xml/ns/samples/resource">

<name>Semi-Manual Grouping CSV Resource</name>

<extension>
<rext:provisioning>propagated</rext:provisioning>
</extension>

<connectorRef type="ConnectorType">
<filter>
<q:equal>
Expand Down
Expand Up @@ -14,20 +14,32 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!-- MID-4440 -->

<task oid="01db4542-f224-11e7-8833-bbe6634814e7"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:rext="http://midpoint.evolveum.com/xml/ns/samples/resource">

<name>Propagation: Grouping Semi Manual Resource</name>
<name>Propagation: propagated provisioning resources</name>

<taskIdentifier>01db4542-f224-11e7-8833-bbe6634814e7</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

<handlerUri>http://midpoint.evolveum.com/xml/ns/public/provisioning/task/propagation/handler-3</handlerUri>
<objectRef oid="9eddca88-f222-11e7-98dc-cb6e4b08800c" type="ResourceType"/> <!-- Semi Manual Grouping -->
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/provisioning/task/propagation/multi-handler-3</handlerUri>
<objectRef type="ResourceType">
<filter>
<q:equal>
<q:path>extension/provisioning</q:path>
<q:value>propagated</q:value>
</q:equal>
</filter>
</objectRef>

<recurrence>single</recurrence>

</task>
42 changes: 42 additions & 0 deletions model/model-intest/src/test/resources/schema/resource.xsd
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!--
~ 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<xsd:schema elementFormDefault="qualified"
targetNamespace="http://midpoint.evolveum.com/xml/ns/samples/resource"
xmlns:tns="http://midpoint.evolveum.com/xml/ns/samples/resource"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:a="http://prism.evolveum.com/xml/ns/public/annotation-3"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:complexType name="ResourceTypeExtensionType">
<xsd:annotation>
<xsd:appinfo>
<a:extension ref="c:ResourceType"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="provisioning" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<a:indexed>true</a:indexed>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>
@@ -0,0 +1,89 @@
/**
* Copyright (c) 2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.provisioning.impl.task;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.provisioning.impl.ShadowCache;
import com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException;
import com.evolveum.midpoint.repo.api.PreconditionViolationException;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.task.AbstractSearchIterativeResultHandler;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

/**
* @author semancik
*
*/
public class MultiPropagationResultHandler extends AbstractSearchIterativeResultHandler<ResourceType> {

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

private final RepositoryService repositoryService;
private final ShadowCache shadowCache;

public MultiPropagationResultHandler(Task coordinatorTask, String taskOperationPrefix, TaskManager taskManager, RepositoryService repositoryService, ShadowCache shadowCache) {
super(coordinatorTask, taskOperationPrefix, "propagation", "multipropagation", taskManager);
this.repositoryService = repositoryService;
this.shadowCache = shadowCache;
}

@Override
protected boolean handleObject(PrismObject<ResourceType> resource, Task workerTask, OperationResult taskResult)
throws CommonException, PreconditionViolationException {

LOGGER.trace("Propagating provisioning operations on {}", resource);
ObjectQuery query = new ObjectQuery();
ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, resource.getPrismContext())
.item(ShadowType.F_RESOURCE_REF).ref(resource.getOid())
.and()
.exists(ShadowType.F_PENDING_OPERATION)
.buildFilter();
query.setFilter(filter);

ResultHandler<ShadowType> handler =
(shadow, result) -> {
propagateShadowOperations(resource, shadow, workerTask, result);
return true;
};

repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, false, taskResult);

LOGGER.trace("Propagation of {} done", resource);

return true;
}

protected void propagateShadowOperations(PrismObject<ResourceType> resource, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) {
try {
shadowCache.propagateOperations(resource, shadow, workerTask, result);
} catch (CommonException | GenericFrameworkException e) {
throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
}
}

}
@@ -0,0 +1,125 @@
/**
* Copyright (c) 2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.provisioning.impl.task;

import java.util.List;

import javax.annotation.PostConstruct;

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

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.provisioning.impl.ShadowCache;
import com.evolveum.midpoint.provisioning.impl.ShadowCacheFactory;
import com.evolveum.midpoint.repo.common.task.AbstractSearchIterativeTaskHandler;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskCategory;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.task.api.TaskRunResult;
import com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
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.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

/**
* Task handler for provisioning propagation of many resources.
*
* The search in this task handler is somehow reversed. The task is searching for resources
* and then the task internally looks for pending changes.
*
* Here we assume that there will be large number of resources, but there will be much smaller
* number of changes.
*
* @author Radovan Semancik
*
*/
@Component
public class MultiPropagationTaskHandler extends AbstractSearchIterativeTaskHandler<ResourceType, MultiPropagationResultHandler> {

public static final String HANDLER_URI = SchemaConstants.NS_PROVISIONING_TASK + "/propagation/multi-handler-3";

// WARNING! This task handler is efficiently singleton!
// It is a spring bean and it is supposed to handle all search task instances
// Therefore it must not have task-specific fields. It can only contain fields specific to
// all tasks of a specified type

@Autowired private TaskManager taskManager;
@Autowired private ShadowCacheFactory shadowCacheFactory;

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

public MultiPropagationTaskHandler() {
super("Provisioning propagation (multi)", OperationConstants.PROVISIONING_PROPAGATION);
setLogFinishInfo(true);
setPreserveStatistics(false);
setEnableSynchronizationStatistics(false);
}

@PostConstruct
private void initialize() {
taskManager.registerHandler(HANDLER_URI, this);
}

@Override
protected MultiPropagationResultHandler createHandler(TaskRunResult runResult, Task coordinatorTask,
OperationResult opResult) {

ShadowCache shadowCache = shadowCacheFactory.getShadowCache(ShadowCacheFactory.Mode.STANDARD);
MultiPropagationResultHandler handler = new MultiPropagationResultHandler(coordinatorTask, getTaskOperationPrefix(), taskManager, repositoryService, shadowCache);
return handler;
}

@Override
public String getCategoryName(Task task) {
return TaskCategory.SYSTEM;
}

@Override
public List<String> getCategoryNames() {
return null;
}

@Override
protected ObjectQuery createQuery(MultiPropagationResultHandler handler, TaskRunResult runResult, Task coordinatorTask,
OperationResult opResult) throws SchemaException {
ObjectQuery objectQuery = createQueryFromTask(handler, runResult, coordinatorTask, opResult);
LOGGER.trace("Resource query: {}", objectQuery);
return objectQuery;

}

@Override
protected Class<? extends ObjectType> getType(Task task) {
return ResourceType.class;
}

}
Expand Up @@ -51,8 +51,11 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

/**
* @author semancik
*
* Task handler for provisioning propagation of one resource.
*
* We assume that there will be few resources with a lot of changes each.
*
* @author Radovan Semancik
*/
@Component
public class PropagationTaskHandler extends AbstractSearchIterativeTaskHandler<ShadowType, PropagationResultHandler> {
Expand Down Expand Up @@ -112,17 +115,14 @@ public List<String> getCategoryNames() {
}

@Override
protected ObjectQuery createQuery(PropagationResultHandler handler, TaskRunResult runResult, Task task,
protected ObjectQuery createQuery(PropagationResultHandler handler, TaskRunResult runResult, Task coordinatorTask,
OperationResult opResult) throws SchemaException {
ObjectQuery query = new ObjectQuery();
ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, prismContext)
.item(ShadowType.F_RESOURCE_REF).ref(handler.getResource().getOid())
.and()
.exists(ShadowType.F_PENDING_OPERATION)
.buildFilter();
// ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, prismContext)
// .exists(ShadowType.F_PENDING_OPERATION)
// .buildFilter();

query.setFilter(filter);
return query;
Expand Down

0 comments on commit 3f10d3c

Please sign in to comment.