Skip to content

Commit

Permalink
MID-8842 ninja - upgrade objects, skipped object counting fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Aug 30, 2023
1 parent d8cc465 commit 0446299
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public VerifyResult execute() throws Exception {

log.info("");
log.info(
"Verification finished. {}, {}, {} optional issues found",
"Verification finished. {}, {} and {} optional issues found",
ConsoleFormat.formatMessageWithErrorParameters("{} critical", result.getCriticalCount()),
ConsoleFormat.formatMessageWithWarningParameters("{} necessary", result.getNecessaryCount()),
result.getOptionalCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ public UpgradeObjectHandler(
* @param <O> type of object
* @return true if object was changed
*/
public <O extends ObjectType> boolean execute(PrismObject<O> object) throws Exception {
public <O extends ObjectType> UpgradeObjectResult execute(PrismObject<O> object) throws Exception {
final PrismContext prismContext = context.getPrismContext();

ObjectUpgradeValidator validator = new ObjectUpgradeValidator(prismContext);
validator.showAllWarnings();
UpgradeValidationResult result = validator.validate(object);
if (!result.hasChanges()) {
return false;
return UpgradeObjectResult.NO_CHANGES;
}

List<UpgradeValidationItem> applicableItems = filterApplicableItems(object.getOid(), result.getItems());
if (applicableItems.isEmpty()) {
return false;
return UpgradeObjectResult.SKIPPED;
}

// applicable items can't be applied by using delta from each item on object - deltas might
Expand All @@ -78,7 +78,7 @@ public <O extends ObjectType> boolean execute(PrismObject<O> object) throws Exce
processor.process(object, path);
}

return true;
return UpgradeObjectResult.UPDATED;
}

private List<UpgradeValidationItem> filterApplicableItems(String oid, List<UpgradeValidationItem> items) {
Expand Down Expand Up @@ -111,7 +111,9 @@ private List<UpgradeValidationItem> filterApplicableItems(String oid, List<Upgra

Set<SkipUpgradeItem> skipItems = skipUpgradeItems.getOrDefault(UUID.fromString(oid), new HashSet<>());
for (SkipUpgradeItem skipItem : skipItems) {
if (Objects.equals(skipItem.getPath(), path.toString())) {
if (Objects.equals(skipItem.getPath(), path.toString())
&& Objects.equals(skipItem.getIdentifier(), item.getIdentifier())) {

return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,10 @@
package com.evolveum.midpoint.ninja.action.upgrade;

import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.validator.UpgradePhase;
import com.evolveum.midpoint.schema.validator.UpgradePriority;
import com.evolveum.midpoint.schema.validator.UpgradeType;
public enum UpgradeObjectResult {

public class UpgradeObjectResult {
NO_CHANGES,

private boolean changed;
SKIPPED,

private String identifier;

private UpgradePhase phase;

private UpgradePriority priority;

private UpgradeType type;

private ObjectDelta<?> delta;

public boolean isChanged() {
return changed;
}

public void setChanged(boolean changed) {
this.changed = changed;
}

public ObjectDelta<?> getDelta() {
return delta;
}

public void setDelta(ObjectDelta<?> delta) {
this.delta = delta;
}

public String getIdentifier() {
return identifier;
}

public void setIdentifier(String identifier) {
this.identifier = identifier;
}

public UpgradePhase getPhase() {
return phase;
}

public void setPhase(UpgradePhase phase) {
this.phase = phase;
}

public UpgradePriority getPriority() {
return priority;
}

public void setPriority(UpgradePriority priority) {
this.priority = priority;
}

public UpgradeType getType() {
return type;
}

public void setType(UpgradeType type) {
this.type = type;
}
UPDATED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ private void processObject(RepositoryService repository, T object) throws Except

PrismObject cloned = prismObject.clone();
UpgradeObjectHandler executor = new UpgradeObjectHandler(options, context, skipUpgradeForOids);
boolean changed = executor.execute(cloned);
if (!changed) {
return;
UpgradeObjectResult result = executor.execute(cloned);
switch (result) {
case SKIPPED:
operation.incrementSkipped();
case NO_CHANGES:
return;
case UPDATED:
// we'll continue processing
}

OperationResult opResult = new OperationResult("Modify object");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;

import com.evolveum.midpoint.ninja.action.upgrade.UpgradeObjectResult;
import com.evolveum.midpoint.schema.result.OperationResult;

import org.apache.commons.csv.CSVFormat;
Expand Down Expand Up @@ -103,8 +104,8 @@ private void upgradeFile(File file) {
try {
UpgradeObjectHandler executor = new UpgradeObjectHandler(options, context, skipUpgradeItems);
for (PrismObject object : objects) {
boolean changedOne = executor.execute(object);
if (changedOne) {
UpgradeObjectResult result = executor.execute(object);
if (result == UpgradeObjectResult.UPDATED) {
changed = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ public static boolean isBatchMode() {
}

public static String formatMessageWithErrorParameters(String message, Object... parameters) {
return formatMessageWithParameter(message, parameters, Color.ERROR);
return formatMessageWithParameters(message, parameters, Color.ERROR);
}

public static String formatMessageWithWarningParameters(String message, Object... parameters) {
return formatMessageWithParameter(message, parameters, Color.WARN);
return formatMessageWithParameters(message, parameters, Color.WARN);
}

public static String formatMessageWithInfoParameters(String message, Object... parameters) {
return formatMessageWithParameter(message, parameters, Color.INFO);
return formatMessageWithParameters(message, parameters, Color.INFO);
}

public static String formatMessageWithParameter(String message, Object[] parameters, Color level) {
public static String formatMessageWithParameters(String message, Object[] parameters, Color level) {
String[] formatted = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
formatted[i] = Ansi.ansi().fgBright(level.color).a(parameters[i]).reset().toString();
Expand Down

0 comments on commit 0446299

Please sign in to comment.