Skip to content

Commit

Permalink
Added helpful user information to ninja upgrade actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Aug 13, 2023
1 parent c1a9acd commit 12b1cfe
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ protected Callable<VerifyResult> createConsumer(BlockingQueue<ObjectType> queue,
@Override
public VerifyResult execute() throws Exception {
VerifyResult result;
if (options.getOutput() != null) {
log.info("Verification report will be saved to '{}'", options.getOutput().getPath());
} else if (context.isUserMode()) {
log.warn("Consider using '-o verify-output.csv' option for CSV output with upgradability status of deprecated items.");
log.warn("It is recommended to review this report and actions for proper upgrade procedure.");
}
if (!options.getFiles().isEmpty()) {
result = verifyFiles();
} else {
Expand All @@ -76,9 +82,18 @@ public VerifyResult execute() throws Exception {
if (options.getOutput() != null) {
log.info("Verification report saved to '{}'", options.getOutput().getPath());


if (Objects.equals(VerifyOptions.ReportStyle.CSV, options.getReportStyle())) {
log.info("XML dump with delta for each item saved to '{}'", options.getOutput().getPath() + VerificationReporter.DELTA_FILE_NAME_SUFFIX);
}

// FIXME: ADD links (do not display in batch mode)
// FIXME: Could We could try to infer script name?
if (context.isUserMode()) {
log.info("Please see documentation for use of verification report in upgrade process and modify it accordingly.");
log.info("After you reviewed verification report and marked changes to skip you can continue upgrade process "
+ "with running 'ninja.sh upgrade-objects --verification-file \"{}\"'", options.getOutput().getPath());
}
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public ActionResult<Void> execute() throws Exception {
File tempDirectory = options.getTempDirectory() != null ?
options.getTempDirectory() : new File(FileUtils.getTempDirectory(), UpgradeConstants.UPGRADE_TEMP_DIRECTORY);


FileUtils.forceMkdir(tempDirectory);
// FIXME: Should we log pre-upgrade checks

// pre-upgrade checks
if (!options.isSkipPreCheck()) {
Expand Down Expand Up @@ -81,9 +83,11 @@ public ActionResult<Void> execute() throws Exception {
File distributionDirectory = downloadResult.getDistributionDirectory();

// upgrade repository
log.info("Starting repository database structure upgrade");
runUpgradeSql(RunSqlOptions.Mode.REPOSITORY, distributionDirectory);

// upgrade audit
log.info("Starting audit database structure upgrade");
runUpgradeSql(RunSqlOptions.Mode.AUDIT, distributionDirectory);

// upgrade installation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;

import com.evolveum.midpoint.schema.result.OperationResult;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
Expand Down Expand Up @@ -137,6 +139,10 @@ public String getOperationName() {
private Map<UUID, Set<SkipUpgradeItem>> loadVerificationFile() throws IOException {
File verification = options.getVerification();
if (verification == null || !verification.exists() || !verification.isFile()) {
// FIXME: Add log explanation, what is happening
if (context.isUserMode()) {
log.warn("Upgrade objects started without verification report, all neccessary non-manual changes will be accepted.");
}
return Collections.emptyMap();
}

Expand Down Expand Up @@ -191,4 +197,14 @@ protected Callable<Void> createConsumer(BlockingQueue<ObjectType> queue, Operati
return null;
};
}

protected void handleResultOnFinish(OperationStatus operation, String finishMessage) {
super.handleResultOnFinish(operation, finishMessage);
OperationResult result = operation.getResult();
if (result.isAcceptable() && context.isUserMode()) {
log.info("Objects were successfully upgraded.");
log.info("If you want to continue to continue with upgrade, please run:"
+ "ninja.sh upgrade-distribution.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ public boolean isVerbose() {
return base.isVerbose();
}

public boolean isBatchMode() {
BaseOptions base = getOptions(BaseOptions.class);
return base.isBatchMode();
}

public boolean isUserMode() {
// TODO: Maybe we should better distinguish between user interactive mode and script mode
return !isBatchMode();
}

public Charset getCharset() {
BaseOptions base = getOptions(BaseOptions.class);
String charset = base.getCharset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static void setBatchMode(boolean batchMode) {
Ansi.setEnabled(!batchMode);
}

public static boolean isBatchMode() {
return Ansi.isEnabled();
}

public static String formatActionStartMessage(Action action) {
String operation = action.getOperationName();
return Ansi.ansi().a("Starting ").fgGreen().a(operation).reset().toString();
Expand Down Expand Up @@ -75,6 +79,10 @@ public static String formatLogMessage(LogLevel level, String msg) {
.toString();
}

public static String formatCommand(String message) {
return Ansi.ansi().fgBright(Ansi.Color.WHITE).a(message).reset().toString();
}

/**
* Technically removes two lines, since {@Log.info} adds new line at the end of the message
*/
Expand Down

0 comments on commit 12b1cfe

Please sign in to comment.