use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class ResourceProtectedEditor method initLayout.
protected void initLayout(final PageResourceWizard parentPage) {
WebMarkupContainer container = new WebMarkupContainer(ID_CONTAINER);
container.setOutputMarkupId(true);
add(container);
ListView repeater = new ListView<ResourceObjectPatternType>(ID_REPEATER, getModel()) {
@Override
protected void populateItem(final ListItem<ResourceObjectPatternType> item) {
WebMarkupContainer linkCont = new WebMarkupContainer(ID_ACCOUNT_LINK);
linkCont.setOutputMarkupId(true);
linkCont.add(new AttributeModifier("href", createCollapseItemId(item, true)));
item.add(linkCont);
Label accountLabel = new Label(ID_ACCOUNT_NAME, new IModel<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
ResourceObjectPatternType account = item.getModelObject();
sb.append("#").append(item.getIndex() + 1).append(" - ");
return sb.toString();
}
});
linkCont.add(accountLabel);
AjaxLink<Void> delete = new AjaxLink<Void>(ID_BUTTON_DELETE) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
deleteProtectedAccountPerformed(target, item);
}
};
parentPage.addEditingVisibleBehavior(delete);
linkCont.add(delete);
WebMarkupContainer accountBody = new WebMarkupContainer(ID_ACCOUNT_BODY);
accountBody.setOutputMarkupId(true);
accountBody.setMarkupId(createCollapseItemId(item, false).getObject());
if (changeState != ChangeState.SKIP) {
accountBody.add(new AttributeModifier("class", new IModel<String>() {
@Override
public String getObject() {
if (changeState == ChangeState.FIRST && item.getIndex() == 0) {
return "panel-collapse collapse in";
} else if (changeState == ChangeState.LAST && item.getIndex() == (getModelObject().size() - 1)) {
return "panel-collapse collapse in";
} else {
return "panel-collapse collapse";
}
}
}));
}
item.add(accountBody);
// TODO - maybe add some validator and auto-complete functionality?
TextField name = new TextField<>(ID_NAME, new PropertyModel<String>(item.getModel(), "name"));
name.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
parentPage.addEditingEnabledBehavior(name);
accountBody.add(name);
// TODO - maybe add some validator and auto-complete functionality?
TextField uid = new TextField<>(ID_UID, new PropertyModel<String>(item.getModel(), "uid"));
uid.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
parentPage.addEditingEnabledBehavior(uid);
accountBody.add(uid);
SearchFilterPanel searchFilterPanel = new SearchFilterPanel<>(ID_FILTER_EDITOR, new NonEmptyPropertyModel<>(item.getModel(), "filter"), parentPage.getReadOnlyModel());
accountBody.add(searchFilterPanel);
Label nameTooltip = new Label(ID_T_NAME);
nameTooltip.add(new InfoTooltipBehavior());
accountBody.add(nameTooltip);
Label uidTooltip = new Label(ID_T_UID);
uidTooltip.add(new InfoTooltipBehavior());
accountBody.add(uidTooltip);
Label filterTooltip = new Label(ID_T_FILTER);
filterTooltip.add(new InfoTooltipBehavior());
accountBody.add(filterTooltip);
}
};
repeater.setOutputMarkupId(true);
container.add(repeater);
AjaxLink<Void> add = new AjaxLink<Void>(ID_BUTTON_ADD) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
addProtectedAccountPerformed(target);
}
};
parentPage.addEditingVisibleBehavior(add);
add(add);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class ManualResourceTest method test110CloseCaseAndRecomputeWill.
/**
* Case is closed. The operation is complete.
*/
@Test
public void test110CloseCaseAndRecomputeWill() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = getTestOperationResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// WHEN
when();
CaseType caseBefore = getCase(willLastCaseOid);
display("Case before work item completion", caseBefore);
List<CaseWorkItemType> workItems = caseBefore.getWorkItem();
assertEquals("Wrong # of work items", 2, workItems.size());
assertEquals("Wrong assignees", new HashSet<>(Arrays.asList(USER_ADMINISTRATOR_OID, userJackOid)), workItems.stream().map(wi -> wi.getOriginalAssigneeRef().getOid()).collect(Collectors.toSet()));
Optional<CaseWorkItemType> adminWorkItem = workItems.stream().filter(wi -> USER_ADMINISTRATOR_OID.equals(wi.getOriginalAssigneeRef().getOid())).findAny();
assertTrue("no admin work item", adminWorkItem.isPresent());
caseManager.completeWorkItem(WorkItemId.of(adminWorkItem.get()), new AbstractWorkItemOutputType(prismContext).outcome(OperationResultStatusType.SUCCESS.value()), null, task, result);
accountWillCompletionTimestampStart = clock.currentTimeXMLGregorianCalendar();
// We need reconcile and not recompute here. We need to fetch the updated case status.
reconcileUser(userWillOid, task, result);
// THEN
then();
assertSuccess(result);
CaseType caseAfter = getCase(willLastCaseOid);
display("Case after work item completion", caseAfter);
accountWillCompletionTimestampEnd = clock.currentTimeXMLGregorianCalendar();
assertWillAfterCreateCaseClosed();
displayDumpable("dummy audit", dummyAuditService);
displayDumpable("dummy transport", dummyTransport);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class TestBucketingStatic method test210GetReleaseCompleteSequenceForWorkers.
/**
* Check a sequence of get / release / complete operations on coordinator + 5 worker tasks.
*/
@Test
public void test210GetReleaseCompleteSequenceForWorkers() throws Exception {
OperationResult result = createOperationResult();
// suspended
taskAdd(TASK_210_COORDINATOR, result);
// suspended
taskAdd(TASK_210_WORKER_1, result);
// suspended
taskAdd(TASK_210_WORKER_2, result);
// suspended
taskAdd(TASK_210_WORKER_3, result);
// suspended
taskAdd(TASK_210_WORKER_4, result);
// suspended
taskAdd(TASK_210_WORKER_5, result);
Task coordinator = taskManager.getTaskPlain(TASK_210_COORDINATOR.oid, result);
String oidC = TASK_210_COORDINATOR.oid;
String oidW1 = TASK_210_WORKER_1.oid;
String oidW2 = TASK_210_WORKER_2.oid;
String oidW3 = TASK_210_WORKER_3.oid;
String oidW4 = TASK_210_WORKER_4.oid;
String oidW5 = TASK_210_WORKER_5.oid;
when();
WorkBucketType bucket1 = getWorkBucket(coordinator, oidW1, result);
WorkBucketType bucket2 = getWorkBucket(coordinator, oidW2, result);
WorkBucketType bucket3 = getWorkBucket(coordinator, oidW3, result);
WorkBucketType bucket4 = getWorkBucket(coordinator, oidW4, result);
// should be the same as bucket4 (the same worker)
WorkBucketType bucket4a = getWorkBucket(coordinator, oidW4, result);
then();
displayValue("1st allocated bucket", bucket1);
displayValue("2nd allocated bucket", bucket2);
displayValue("3rd allocated bucket", bucket3);
displayValue("4th allocated bucket", bucket4);
displayValue("4+th allocated bucket", bucket4a);
coordinator.refresh(result);
displayDumpable("coordinator task after 4+1x allocation", coordinator);
assertNumericBucket(bucket1, null, 1, 0, 1);
assertNumericBucket(bucket2, null, 2, 1, 2);
assertNumericBucket(bucket3, null, 3, 2, 3);
assertNumericBucket(bucket4, null, 4, 3, 4);
assertNumericBucket(bucket4a, null, 4, 3, 4);
List<WorkBucketType> buckets = new ArrayList<>(getBuckets(coordinator));
sortBucketsBySequentialNumber(buckets);
assertEquals(4, buckets.size());
assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 1, 0, 1);
assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 2, 1, 2);
assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 3, 2, 3);
assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 4, 3, 4);
when("complete bucket #2");
bucketingManager.completeWorkBucket(oidC, oidW2, ActivityPath.empty(), 2, null, null, result);
then("complete bucket #2");
coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
displayDumpable("coordinator after completion of 2nd bucket", coordinator);
buckets = new ArrayList<>(getBuckets(coordinator));
sortBucketsBySequentialNumber(buckets);
assertEquals(4, buckets.size());
assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 1, 0, 1);
assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 2, 1, 2);
assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 3, 2, 3);
assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 4, 3, 4);
when("complete bucket #1");
bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 1, null, null, result);
WorkBucketType bucket = getWorkBucket(coordinator, oidW1, result);
then("complete bucket #1");
coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
displayDumpable("coordinator after completion of 1st bucket and fetching next one", coordinator);
assertNumericBucket(bucket, null, 5, 4, 5);
buckets = new ArrayList<>(getBuckets(coordinator));
sortBucketsBySequentialNumber(buckets);
assertEquals(4, buckets.size());
assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 2, 1, 2);
assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 3, 2, 3);
assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 4, 3, 4);
assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 5, 4, 5);
when("no more buckets");
WorkBucketType nothing = getWorkBucket(coordinator, oidW5, result);
then("no more buckets");
assertNull("Found bucket even if none should be found", nothing);
when("release bucket #4");
bucketingManager.releaseWorkBucket(oidC, oidW4, ActivityPath.empty(), 4, null, result);
then("release bucket #4");
coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
displayDumpable("coordinator after releasing of 4th bucket", coordinator);
buckets = new ArrayList<>(getBuckets(coordinator));
sortBucketsBySequentialNumber(buckets);
assertEquals(4, buckets.size());
assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 2, 1, 2);
assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 3, 2, 3);
assertNumericBucket(buckets.get(2), READY, 4, 3, 4);
assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 5, 4, 5);
when("complete bucket #3");
bucketingManager.completeWorkBucket(oidC, oidW3, ActivityPath.empty(), 3, null, null, result);
bucket = getWorkBucket(coordinator, oidW5, result);
then("complete bucket #3");
coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
displayDumpable("coordinator after completion of 3rd bucket and getting next one", coordinator);
assertNumericBucket(bucket, null, 4, 3, 4);
buckets = new ArrayList<>(getBuckets(coordinator));
sortBucketsBySequentialNumber(buckets);
assertEquals(3, buckets.size());
assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 3, 2, 3);
assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 4, 3, 4);
assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 5, 4, 5);
when("complete bucket #5");
bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 5, null, null, result);
taskManager.closeTask(oidW5, result);
then("complete bucket #5");
coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
displayDumpable("coordinator after completion of 5th bucket and closing worker5", coordinator);
buckets = new ArrayList<>(getOrCreateBuckets(coordinator.getWorkState().getActivity()));
assertEquals(2, buckets.size());
assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 4, 3, 4);
assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 5, 4, 5);
when("reclaiming mis-allocated bucket");
bucket = getWorkBucket(coordinator, oidW1, b -> b.withFreeBucketWaitTime(-1).withIsScavenger(true), result);
assertThat(bucket).isNotNull();
then("reclaiming mis-allocated bucket");
coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
displayDumpable("coordinator after reclaiming mis-allocated bucket", coordinator);
assertNumericBucket(bucket, null, 4, 3, 4);
buckets = new ArrayList<>(getBuckets(coordinator));
assertEquals(2, buckets.size());
assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 4, 3, 4);
assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 5, 4, 5);
when("complete bucket #4");
bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 4, null, null, result);
then("complete bucket #4");
coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
displayDumpable("coordinator after completion of 4th bucket", coordinator);
buckets = new ArrayList<>(getBuckets(coordinator));
assertEquals(1, buckets.size());
assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 5, 4, 5);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class AuditServiceProxy method completeRecord.
/**
* Complete the record with data that can be computed or discovered from the
* environment
*/
private void completeRecord(AuditEventRecord record, Task task, OperationResult result) {
LightweightIdentifier id = null;
if (record.getEventIdentifier() == null) {
id = lightweightIdentifierGenerator.generate();
record.setEventIdentifier(id.toString());
}
if (record.getTimestamp() == null) {
if (id == null) {
record.setTimestamp(System.currentTimeMillis());
} else {
// To be consistent with the ID
record.setTimestamp(id.getTimestamp());
}
}
if (record.getTaskIdentifier() == null && task != null) {
record.setTaskIdentifier(task.getTaskIdentifier());
}
if (record.getTaskOid() == null && task != null) {
if (task instanceof RunningTask) {
record.setTaskOid(((RunningTask) task).getRootTaskOid());
} else {
record.setTaskOid(task.getOid());
}
}
if (record.getChannel() == null && task != null) {
record.setChannel(task.getChannel());
}
if (record.getInitiatorRef() == null && task != null) {
PrismObject<? extends FocusType> taskOwner = task.getOwner(result);
record.setInitiator(taskOwner);
}
if (record.getNodeIdentifier() == null && taskManager != null) {
record.setNodeIdentifier(taskManager.getNodeId());
}
HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
if (connInfo == null && securityContextManager != null) {
connInfo = securityContextManager.getStoredConnectionInformation();
}
if (connInfo != null) {
if (record.getSessionIdentifier() == null) {
record.setSessionIdentifier(connInfo.getSessionId());
}
if (record.getRemoteHostAddress() == null) {
record.setRemoteHostAddress(connInfo.getRemoteHostAddress());
}
if (record.getHostIdentifier() == null) {
record.setHostIdentifier(connInfo.getLocalHostName());
}
}
if (record.getSessionIdentifier() == null && task != null) {
record.setSessionIdentifier(task.getTaskIdentifier());
}
for (ObjectDeltaOperation<? extends ObjectType> objectDeltaOperation : record.getDeltas()) {
ObjectDelta<? extends ObjectType> delta = objectDeltaOperation.getObjectDelta();
// currently this does not work as expected (retrieves all default items)
Collection<SelectorOptions<GetOperationOptions>> nameOnlyOptions = schemaService.getOperationOptionsBuilder().item(ObjectType.F_NAME).retrieve().build();
ObjectDeltaSchemaLevelUtil.NameResolver nameResolver = (objectClass, oid) -> {
if (record.getNonExistingReferencedObjects().contains(oid)) {
// save a useless getObject call plus associated warning (MID-5378)
return null;
}
if (repositoryService == null) {
LOGGER.warn("No repository, no OID resolution (for {})", oid);
return null;
}
LOGGER.warn("Unresolved object reference in delta being audited (for {}: {}) -- this might indicate " + "a performance problem, as these references are normally resolved using repository cache", objectClass.getSimpleName(), oid);
PrismObject<? extends ObjectType> object = repositoryService.getObject(objectClass, oid, nameOnlyOptions, new OperationResult(AuditServiceProxy.class.getName() + ".completeRecord.resolveName"));
return object.getName();
};
resolveNames(delta, nameResolver, prismContext);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class LiveSynchronizer method updateTokenValue.
private void updateTokenValue(LiveSyncCtx ctx, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, ConfigurationException, CommunicationException, ObjectAlreadyExistsException {
LiveSyncCapabilityType capability = ctx.context.getEffectiveCapability(LiveSyncCapabilityType.class);
boolean preciseTokenValue = capability != null && isTrue(capability.isPreciseTokenValue());
boolean isDryRun = ctx.isDryRun();
boolean updateTokenInDryRun = ctx.isUpdateLiveSyncTokenInDryRun();
LiveSyncToken initialToken = ctx.getInitialToken();
LiveSyncToken oldestTokenProcessed = ctx.oldestTokenWatcher.getOldestTokenProcessed();
LOGGER.trace("oldestTokenProcessed = {}, synchronization result = {}", oldestTokenProcessed, ctx.syncResult);
LiveSyncToken tokenToSet;
if (ctx.isPreview()) {
LOGGER.trace("Preview mode -> token will not be updated.");
tokenToSet = null;
} else if (isDryRun && !updateTokenInDryRun) {
LOGGER.trace("Dry run mode with updateTokenInDryRun=false -> token will not be updated.");
tokenToSet = null;
} else if (ctx.canRun() && ctx.syncResult.isAllChangesFetched() && ctx.syncResult.isAllFetchedChangesProcessed()) {
tokenToSet = ctx.finalToken != null ? ctx.finalToken : oldestTokenProcessed;
LOGGER.trace("All changes fetched and processed (positively acknowledged). " + "Task is not suspended. Updating token to {}", tokenToSet);
// Note that it is theoretically possible that tokenToSet is null here: it happens when no changes are fetched from
// the resource and the connector returns null from .sync() method. But in this case nothing wrong happens: the
// token in task will simply stay as it is. That's the correct behavior for such a case.
} else if (preciseTokenValue) {
LOGGER.trace("Processing is not complete but we can count on precise token values.");
tokenToSet = oldestTokenProcessed;
LOGGER.info("Capability of providing precise token values is present. Token in task is updated so the processing will " + "continue where it was stopped. New token value is '{}' (initial value was '{}')", SchemaDebugUtil.prettyPrint(tokenToSet), SchemaDebugUtil.prettyPrint(initialToken));
} else {
LOGGER.trace("Processing is not complete and we cannot count on precise token values. So we'll not update the token");
tokenToSet = null;
LOGGER.info("Capability of providing precise token values is NOT present. Token will not be updated so the " + "processing will restart from the beginning at next task run. So token value stays as it was: '{}'", SchemaDebugUtil.prettyPrint(initialToken));
}
if (tokenToSet != null) {
LOGGER.trace("Setting token value of {}", SchemaDebugUtil.prettyPrintLazily(tokenToSet));
ctx.tokenStorage.setToken(tokenToSet, result);
ctx.syncResult.setTokenUpdatedTo(tokenToSet);
}
}
Aggregations