use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.READY 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.READY in project midpoint by Evolveum.
the class ScheduleNowHelper method scheduleCoordinatorAndWorkersNow.
public void scheduleCoordinatorAndWorkersNow(String coordinatorOid, OperationResult result) throws SchemaException, ObjectNotFoundException {
TaskQuartzImpl coordinatorTask = taskRetriever.getTaskPlain(coordinatorOid, result);
TaskSchedulingStateType state = coordinatorTask.getSchedulingState();
switch(state) {
case CLOSED:
case READY:
// hoping that the task handler will do what is needed (i.e. recreate or restart workers)
scheduleTaskNow(coordinatorTask, result);
break;
case WAITING:
// this means that workers are either busy (runnable) or are suspended; administrator should do something with that
String msg1 = "Coordinator " + coordinatorTask + " cannot be run now, because it is in WAITING scheduling state. " + "Please check and resolve state of its worker tasks.";
LOGGER.error(msg1);
result.recordFatalError(msg1);
break;
case SUSPENDED:
String msg2 = "Coordinator " + coordinatorTask + " cannot be run now, because it is in SUSPENDED state. " + "Please use appropriate method to schedule its execution.";
LOGGER.error(msg2);
result.recordFatalError(msg2);
break;
default:
throw new IllegalStateException("Coordinator " + coordinatorTask + " is in unsupported state: " + state);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.READY in project midpoint by Evolveum.
the class WebComponentUtil method createMenuItemsFromActions.
@NotNull
public static List<InlineMenuItem> createMenuItemsFromActions(@NotNull List<GuiActionType> actions, String operation, PageBase pageBase, @NotNull Supplier<Collection<? extends ObjectType>> selectedObjectsSupplier) {
List<InlineMenuItem> menuItems = new ArrayList<>();
actions.forEach(action -> {
if (action.getTaskTemplateRef() == null) {
return;
}
String templateOid = action.getTaskTemplateRef().getOid();
if (StringUtils.isEmpty(templateOid)) {
return;
}
String label = action.getDisplay() != null && PolyStringUtils.isNotEmpty(action.getDisplay().getLabel()) ? action.getDisplay().getLabel().getOrig() : action.getName();
menuItems.add(new InlineMenuItem(Model.of(label)) {
private static final long serialVersionUID = 1L;
@Override
public InlineMenuItemAction initAction() {
return new ColumnMenuAction<SelectableBean<ObjectType>>() {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
OperationResult result = new OperationResult(operation);
try {
Collection<String> oids;
if (getRowModel() != null) {
oids = Collections.singletonList(getRowModel().getObject().getValue().getOid());
} else {
oids = CollectionUtils.emptyIfNull(selectedObjectsSupplier.get()).stream().filter(o -> o.getOid() != null).map(o -> o.getOid()).collect(Collectors.toSet());
}
if (!oids.isEmpty()) {
@NotNull Item<PrismValue, ItemDefinition> extensionQuery = prepareExtensionValues(oids);
MidPointPrincipal principal = pageBase.getPrincipal();
if (principal == null) {
throw new SecurityViolationException("No current user");
}
TaskType newTask = pageBase.getModelService().getObject(TaskType.class, templateOid, createCollection(createExecutionPhase()), pageBase.createSimpleTask(operation), result).asObjectable();
newTask.setName(PolyStringType.fromOrig(newTask.getName().getOrig() + " " + (int) (Math.random() * 10000)));
newTask.setOid(null);
newTask.setTaskIdentifier(null);
newTask.setOwnerRef(createObjectRef(principal.getFocus()));
newTask.setExecutionState(RUNNABLE);
newTask.setSchedulingState(READY);
newTask.asPrismObject().getOrCreateExtension().add(extensionQuery);
ObjectSetBasedWorkDefinitionType workDef = ObjectSetUtil.getObjectSetDefinitionFromTask(newTask);
QueryType query = (QueryType) extensionQuery.getRealValue();
ObjectSetType objectSet = workDef.getObjects();
if (objectSet == null) {
objectSet = new ObjectSetType();
objectSet.setType(ObjectType.COMPLEX_TYPE);
}
objectSet.setQuery(query);
workDef.setObjects(objectSet);
ObjectDelta<TaskType> delta = DeltaFactory.Object.createAddDelta(newTask.asPrismObject());
Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = saveTask(delta, result, pageBase);
String newTaskOid = ObjectDeltaOperation.findAddDeltaOid(executedChanges, newTask.asPrismObject());
newTask.setOid(newTaskOid);
newTask.setTaskIdentifier(newTaskOid);
result.setInProgress();
result.setBackgroundTaskOid(newTask.getOid());
} else {
result.recordWarning(pageBase.createStringResource("WebComponentUtil.message.createMenuItemsFromActions.warning").getString());
}
} catch (Exception ex) {
result.recordFatalError(result.getOperation(), ex);
target.add(pageBase.getFeedbackPanel());
} finally {
pageBase.showResult(result);
target.add(pageBase.getFeedbackPanel());
}
}
};
}
/**
* Extension values are task-dependent. Therefore, in the future we will probably make
* this behaviour configurable. For the time being we assume that the task template will be
* of "iterative task handler" type and so it will expect mext:objectQuery extension property.
*
* FIXME
*/
@NotNull
private Item<PrismValue, ItemDefinition> prepareExtensionValues(Collection<String> oids) throws SchemaException {
PrismContext prismContext = pageBase.getPrismContext();
ObjectQuery objectQuery = prismContext.queryFor(ObjectType.class).id(oids.toArray(new String[0])).build();
QueryType queryBean = pageBase.getQueryConverter().createQueryType(objectQuery);
PrismContainerDefinition<?> extDef = PrismContext.get().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(TaskType.class).findContainerDefinition(TaskType.F_EXTENSION);
ItemDefinition<Item<PrismValue, ItemDefinition>> def = extDef != null ? extDef.findItemDefinition(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY) : null;
if (def == null) {
throw new SchemaException("No definition of " + SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY + " in the extension");
}
Item<PrismValue, ItemDefinition> extensionItem = def.instantiate();
extensionItem.add(prismContext.itemFactory().createValue(queryBean));
return extensionItem;
}
});
});
return menuItems;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.READY in project midpoint by Evolveum.
the class ValuePolicyProcessor method cardinalityCounter.
/**
* Count cardinality
*/
private Map<Integer, List<String>> cardinalityCounter(Map<StringLimitType, List<String>> lims, List<String> password, Boolean skipMatchedLims, boolean uniquenessReached, OperationResult op) {
HashMap<String, Integer> counter = new HashMap<>();
for (Map.Entry<StringLimitType, List<String>> entry : lims.entrySet()) {
final StringLimitType key = entry.getKey();
int counterKey = 1;
List<String> chars = entry.getValue();
int i;
if (password != null) {
i = charIntersectionCounter(entry.getValue(), password);
} else {
i = 0;
}
// If max is exceed then error unable to continue
if (key.getMaxOccurs() != null && i > key.getMaxOccurs()) {
OperationResult o = new OperationResult("Limitation check :" + key.getDescription());
o.recordFatalError("Exceeded maximal value for this limitation. " + i + ">" + key.getMaxOccurs());
op.addSubresult(o);
return null;
// if max is all ready reached or skip enabled for minimal skip
// counting
} else if (key.getMaxOccurs() != null && i == key.getMaxOccurs()) {
continue;
// other cases minimum is not reached
} else if ((key.getMinOccurs() == null || i >= key.getMinOccurs()) && !skipMatchedLims) {
continue;
}
for (String s : chars) {
if (null == password || !password.contains(s) || uniquenessReached) {
counter.put(s, counterKey);
}
}
// TODO this is suspicious
counterKey++;
}
// If need to remove disabled chars (already reached limitations)
if (password != null) {
for (Map.Entry<StringLimitType, List<String>> entry : lims.entrySet()) {
StringLimitType l = entry.getKey();
int i = charIntersectionCounter(entry.getValue(), password);
if (l.getMaxOccurs() != null && i > l.getMaxOccurs()) {
OperationResult o = new OperationResult("Limitation check :" + l.getDescription());
o.recordFatalError("Exceeded maximal value for this limitation. " + i + ">" + l.getMaxOccurs());
op.addSubresult(o);
return null;
} else if (l.getMaxOccurs() != null && i == l.getMaxOccurs()) {
// limitation matched remove all used chars
LOGGER.trace("Skip " + l.getDescription());
for (String charToRemove : entry.getValue()) {
counter.remove(charToRemove);
}
}
}
}
// Transpose to better format
Map<Integer, List<String>> ret = new HashMap<>();
for (Map.Entry<String, Integer> entry : counter.entrySet()) {
// if not there initialize
ret.computeIfAbsent(entry.getValue(), k -> new ArrayList<>());
ret.get(entry.getValue()).add(entry.getKey());
}
return ret;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.READY in project midpoint by Evolveum.
the class LoggingConfigurationManager method prepareConfiguration.
private static String prepareConfiguration(LoggingConfigurationType config) throws SchemaException {
if (null == config) {
throw new IllegalArgumentException("Configuration can't be null");
}
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sb.append("<configuration scan=\"false\" debug=\"true\">\n");
//find and configure ALL logger and bring it to top of turbo stack
for (SubSystemLoggerConfigurationType ss : config.getSubSystemLogger()) {
if ("ALL".contentEquals(ss.getComponent().name())) {
defineTurbo(sb, ss);
}
}
//Generate subsystem logging quickstep
for (SubSystemLoggerConfigurationType ss : config.getSubSystemLogger()) {
if (null == ss.getComponent() || null == ss.getLevel()) {
LOGGER.error("Subsystem ({}) or level ({})is null", ss.getComponent(), ss.getLevel());
continue;
}
//skip disabled subsystem logger
if ("OFF".equals(ss.getLevel().name())) {
continue;
}
//All ready defined above
if ("ALL".contentEquals(ss.getComponent().name())) {
continue;
}
defineTurbo(sb, ss);
}
//Generate appenders configuration
for (AppenderConfigurationType appender : config.getAppender()) {
prepareAppenderConfiguration(sb, appender, config);
}
//define root appender if defined
if (!StringUtils.isEmpty(config.getRootLoggerAppender())) {
sb.append("\t<root level=\"");
sb.append(config.getRootLoggerLevel());
sb.append("\">\n");
sb.append("\t\t<appender-ref ref=\"");
sb.append(config.getRootLoggerAppender());
sb.append("\" />\n");
sb.append("\t</root>\n");
}
//Generate class based loggers
for (ClassLoggerConfigurationType logger : config.getClassLogger()) {
sb.append("\t<logger name=\"");
sb.append(logger.getPackage());
sb.append("\" level=\"");
sb.append(logger.getLevel());
sb.append("\"");
//if logger specific appender is defined
if (null != logger.getAppender() && !logger.getAppender().isEmpty()) {
sb.append(" additivity=\"false\">\n");
for (String appenderName : logger.getAppender()) {
sb.append("\t\t<appender-ref ref=\"");
sb.append(appenderName);
sb.append("\"/>");
}
sb.append("\t</logger>\n");
} else {
sb.append("/>\n");
}
}
generateAuditingLogConfig(config.getAuditing(), sb);
if (null != config.getAdvanced()) {
for (Object item : config.getAdvanced().getContent()) {
sb.append(item.toString());
sb.append("\n");
}
}
// LevelChangePropagator to propagate log level changes to JUL
// this keeps us from performance impact of disable JUL logging statements
// WARNING: if deployed in Tomcat then this propagates only to the JUL loggers in current classloader.
// It means that ICF connector loggers are not affected by this
// MAGIC: moved to the end of the "file" as suggested in http://jira.qos.ch/browse/LOGBACK-740
sb.append("\t<contextListener class=\"ch.qos.logback.classic.jul.LevelChangePropagator\">\n");
sb.append("\t\t<resetJUL>true</resetJUL>\n");
sb.append("\t</contextListener>\n");
sb.append("</configuration>");
return sb.toString();
}
Aggregations