Skip to content

Commit

Permalink
MID-8842 upgrade steps/action/options skeleton code
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed May 18, 2023
1 parent f2b0e9e commit a2b3440
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public DatabaseSchemaStep(UpgradeStepsContext context) {
this.context = context;
}

@Override
public String getIdentifier() {
return "databaseSchema";
}

@Override
public Void execute() throws Exception {
// 1/ initialize DB connection, using midpoint home?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public void setVersion(String version) {
this.version = version;
}

@Override
public String getIdentifier() {
return "downloadDistribution";
}

@Override
public DownloadDistributionStepResult execute() throws IOException {
DistributionManager manager = new DistributionManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class UpgradeAction extends Action<UpgradeOptions> {

private static final Class<? extends UpgradeStep>[] STEPS = new Class[] {
// todo upgrade initial objects, also all other objecst that can be upgraded before midpoint version/DB/midpoint home was upgraded
VersionCheckStep.class,
DownloadDistributionStep.class,
DatabaseSchemaStep.class,
UpgradeMidpointHomeStep.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import org.apache.commons.io.FileUtils;

public class UpgradeMidpointHomeStep {
public class UpgradeMidpointHomeStep implements UpgradeStep<Void> {

private static final String VAR_DIRECTORY = "var";

Expand All @@ -22,10 +22,17 @@ public UpgradeMidpointHomeStep(UpgradeMidpointHomeStepOptions options) {
this.options = options;
}

public void execute() throws Exception {
@Override
public String getIdentifier() {
return "upgradeMidpointHome";
}

public Void execute() throws Exception {
downloadDistributionFile();

upgradeMidpointHome();

return null;
}

private void downloadDistributionFile() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,32 @@

package com.evolveum.midpoint.ninja.action.upgrade;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;

import java.io.File;

@Parameters(resourceBundle = "messages", commandDescriptionKey = "upgrade")
public class UpgradeOptions {

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

public static final String P_ABORT_LONG = "--abort";

public static final String P_SKIP_STEP = "--skip-step";

public static final String P_STEP_LONG = "--step";

@Parameter(names = {P_ABORT_LONG}, descriptionKey = "upgrade.abort")
private Boolean abort;

@Parameter(names = {P_TEMP_DIR_LONG}, descriptionKey = "upgrade.tempDir")
private File tempDirectory;

@Parameter(names = {P_STEP_LONG}, descriptionKey = "upgrade.step")
private String step;

public Boolean getAbort() {
return abort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@

public interface UpgradeStep<R> {

String getIdentifier();

R execute() throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.ninja.action.upgrade;

public class VersionCheckResult {

private String currentVersion;

public String currentVersion() {
return currentVersion;
}

public VersionCheckResult currentVersion(String currentVersion) {
this.currentVersion = currentVersion;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.ninja.action.upgrade;

public class VersionCheckStep implements UpgradeStep<VersionCheckResult> {

@Override
public String getIdentifier() {
return "versionCheck";
}

@Override
public VersionCheckResult execute() throws Exception {
String version = "";
// todo implement midPoint version check
return new VersionCheckResult()
.currentVersion(version);
}
}
5 changes: 5 additions & 0 deletions tools/ninja/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ base.psn.trimWhitespace=PolyString normalizer trim whitespace
base.psn.lowercase=PolyString normalizer lowercase
upgrade=Run midPoint upgrade procedure
verify.createReport=Create CSV report from verification process
upgrade.abort=Abort upgrade, cleans local files created by ninja during upgrade process. \
After aborting, upgrade process can be restarted. This doesn't do any rollback in midPoint.
upgrade.tempDir=Temp directory. By default, JVM temp directory is used.
# todo doc
upgrade.step=Step
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static void main(String[] args) {
// "-f", "<inOid xmlns=\"http://prism.evolveum.com/xml/ns/public/query-3\"><value>00000000-0000-0000-0000-000000000002</value></inOid>");

input = "-m /Users/lazyman/Work/monoted/git/evolveum/midpoint/_mess/midpoint-home verify --create-report".split(" ");
input = "-h upgrade".split(" ");

Main.main(input);
}
Expand Down

0 comments on commit a2b3440

Please sign in to comment.