Skip to content

Commit

Permalink
MID-8842 ninja - misc fixes around distribution upgrade
Browse files Browse the repository at this point in the history
(cherry picked from commit 4a00595)
  • Loading branch information
1azyman committed Jul 31, 2023
1 parent a73862f commit ada7138
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ private boolean checkNodesVersion(RepositoryService repository) throws SchemaExc

String version = versions.iterator().next();
if (!Objects.equals(version, UpgradeConstants.SUPPORTED_VERSION)) {
log.error(ConsoleFormat.formatErrorMessageWithParameter(
"There are midPoint nodes with versions {} that doesn't match supported version for upgrade (" +
UpgradeConstants.SUPPORTED_VERSION + ")", Arrays.toString(versions.toArray())));
log.error(
"There are midPoint nodes with versions " + Arrays.toString(versions.toArray())
+ " that doesn't match supported version for upgrade (" + UpgradeConstants.SUPPORTED_VERSION + ")");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public ActionResult<Void> execute() throws Exception {
DownloadDistributionOptions downloadOpts = new DownloadDistributionOptions();
downloadOpts.setTempDirectory(tempDirectory);
downloadOpts.setDistributionArchive(options.getDistributionArchive());
downloadOpts.setDistributionVersion(options.getDistributionVersion());

DownloadDistributionAction downloadAction = new DownloadDistributionAction();
downloadAction.init(context, downloadOpts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;

import com.evolveum.midpoint.ninja.action.upgrade.UpgradeConstants;

@Parameters(resourceBundle = "messages", commandDescriptionKey = "upgradeDistribution")
public class UpgradeDistributionOptions {

public static final String P_TEMP_DIR_LONG = "--temp-directory";

public static final String P_DISTRIBUTION_ARCHIVE = "--distribution-archive";

public static final String P_DISTRIBUTION_VERSION = "--distribution-version";
public static final String P_BACKUP_MIDPOINT_DIRECTORY = "--backup-midpoint-directory";

public static final String P_INSTALLATION_DIRECTORY = "--installation-directory";
Expand Down Expand Up @@ -45,6 +47,9 @@ public class UpgradeDistributionOptions {
@Parameter(names = { P_SKIP_PRE_CHECK }, descriptionKey = "upgradeDistribution.skipPreCheck")
private boolean skipPreCheck;

@Parameter(names = { P_DISTRIBUTION_VERSION }, descriptionKey = "upgradeDistribution.distributionVersion", hidden = true)
private String distributionVersion = UpgradeConstants.SUPPORTED_VERSION_TARGET;

public File getTempDirectory() {
return tempDirectory;
}
Expand Down Expand Up @@ -108,4 +113,12 @@ public boolean isSkipPreCheck() {
public void setSkipPreCheck(boolean skipPreCheck) {
this.skipPreCheck = skipPreCheck;
}

public String getDistributionVersion() {
return distributionVersion;
}

public void setDistributionVersion(String distributionVersion) {
this.distributionVersion = distributionVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public VerificationReporter(@NotNull VerifyOptions options, @NotNull PrismContex
this.log = log;
}

public boolean isCreateDeltaFile() {
return createDeltaFile;
}

public void setCreateDeltaFile(boolean createDeltaFile) {
this.createDeltaFile = createDeltaFile;
}
Expand Down Expand Up @@ -327,13 +323,13 @@ private void writeValidationItem(Writer writer, PrismObject<?> object, UpgradeVa
writer.append("INFO ");
}

items.add(object.toDebugName());

UpgradePriority priority = item.getPriority();
if (priority != null) {
items.add(priority);
}

items.add(getObjectDisplayName(object));

if (validationItem.getItemPath() != null) {
items.add(validationItem.getItemPath());
}
Expand All @@ -347,7 +343,19 @@ private void writeValidationItem(Writer writer, PrismObject<?> object, UpgradeVa
writer.write("\n");
}

private String writeMessage(LocalizableMessage message) throws IOException {
private String getObjectDisplayName(PrismObject<?> object) {
StringBuilder sb = new StringBuilder();
sb.append(object.getName());
sb.append(" (");
sb.append(object.getOid());
sb.append(", ");
sb.append(object.getCompileTimeClass().getSimpleName());
sb.append(")");

return sb.toString();
}

private String writeMessage(LocalizableMessage message) {
if (message == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.evolveum.midpoint.ninja.util.OperationStatus;
import com.evolveum.midpoint.util.exception.SchemaException;

import org.apache.commons.io.IOUtils;

/**
* Created by Viliam Repan (lazyman).
*/
Expand All @@ -36,7 +38,10 @@ public void run() {

init();

try (Writer writer = createWriter()) {
Writer writer = null;
try {
writer = createWriter();

while (!shouldConsumerStop()) {
T object = null;
try {
Expand All @@ -61,6 +66,11 @@ public void run() {
} catch (NinjaException ex) {
log.error(ex.getMessage(), ex);
} finally {
if (options.getOutput() != null) {
// we don't want to close stdout, e.g. only if we were writing to file
IOUtils.closeQuietly(writer);
}

markDone();

if (isWorkersDone()) {
Expand Down

0 comments on commit ada7138

Please sign in to comment.