Skip to content

Commit

Permalink
MID-8842 upgrade objects step implementation started
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed May 30, 2023
1 parent 118eae4 commit 758392c
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ConsoleProgressListener implements ProgressListener {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
if (done) {
System.out.println(Ansi.ansi().eraseLine().fgGreen().a("Download complete").reset());
System.out.println(Ansi.ansi().cursorUpLine().eraseLine().fgGreen().a("Download complete").reset());
return;
}

Expand All @@ -37,7 +37,7 @@ public void update(long bytesRead, long contentLength, boolean done) {

double newProgress = (double) (100 * bytesRead) / contentLength;
if (newProgress - progress > 1) {
System.out.print(Ansi.ansi().eraseLine(Ansi.Erase.ALL).a("Progress: ").fgBlue().a(FORMAT.format(newProgress) + "%\n").reset());
System.out.println(Ansi.ansi().cursorUpLine().eraseLine(Ansi.Erase.ALL).a("Progress: ").fgBlue().a(FORMAT.format(newProgress)).a("%").reset());

progress = newProgress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public class DistributionManager {

private static final String DOWNLOAD_URL = "https://download.evolveum.com/midpoint/";

private static final String LATEST_VERSION = "latest";

private static final String LATEST_VERSION_NUMBER = "SNAPSHOT";
public static final String LATEST_VERSION = "latest";

private File tempDirectory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class UpgradeAction extends Action<UpgradeOptions> {
// VerifyStep.class,
// UpgradeObjectsBeforeShutdownStep.class, // todo upgrade initial objects, also all other objects that can be upgraded before midpoint version/DB/midpoint home was upgraded
DownloadDistributionStep.class,
DatabaseSchemaStep.class,
// DatabaseSchemaStep.class,
// UpgradeMidpointInstallationStep.class,
// UpgradeObjectsAfterShutdownStep.class, // todo upgrade initial objects, also all other objects (changes that had to be done after DB upgrade)
// todo what if recomputation/reconciliation/whatever task is needed?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class UpgradeOptions {

public static final String P_VERIFY_THREADS = "--verify-threads";

public static final String P_UPGRADE_THREADS = "--upgrade-threads";

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

Expand All @@ -51,6 +53,9 @@ public class UpgradeOptions {
@Parameter(names = { P_VERIFY_THREADS }, descriptionKey = "upgrade.verifyThreads", validateWith = PositiveInteger.class)
private int verifyThreads = 1;

@Parameter(names = { P_UPGRADE_THREADS }, descriptionKey = "upgrade.upgradeThreads", validateWith = PositiveInteger.class)
private int upgradeThreads = 1;

public Boolean isAbort() {
return abort;
}
Expand Down Expand Up @@ -78,4 +83,8 @@ public File getInstallationDirectory() {
public int getVerifyThreads() {
return verifyThreads;
}

public int getUpgradeThreads() {
return upgradeThreads;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
package com.evolveum.midpoint.ninja.action.upgrade.handler;

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

public class UpgradeObjectHandler {
public interface UpgradeObjectHandler {

public void handleObject(PrismObject<?> object) {
UpgradePhase getPhase();

}
boolean isApplicable(String version);

void handleObject(PrismObject<?> object, OperationResult result);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.evolveum.midpoint.ninja.action.upgrade.handler;

public enum UpgradePhase {

BEFORE, AFTER;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.evolveum.midpoint.ninja.action.upgrade.step;

import com.evolveum.midpoint.ninja.action.upgrade.StepResult;
import com.evolveum.midpoint.ninja.action.upgrade.UpgradeStepsContext;

import org.jetbrains.annotations.NotNull;

public class UpgradeObjectsAfterShutdownStep extends UpgradeObjectsStep {

public UpgradeObjectsAfterShutdownStep(@NotNull UpgradeStepsContext context) {
super(context);
}

@Override
public String getIdentifier() {
return "upgradeObjectsAfterShutdown";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.evolveum.midpoint.ninja.action.upgrade.step;

import com.evolveum.midpoint.ninja.action.upgrade.StepResult;
import com.evolveum.midpoint.ninja.action.upgrade.UpgradeStepsContext;

import org.jetbrains.annotations.NotNull;

public class UpgradeObjectsBeforeShutdownStep extends UpgradeObjectsStep {

public UpgradeObjectsBeforeShutdownStep(@NotNull UpgradeStepsContext context) {
super(context);
}

@Override
public String getIdentifier() {
return "upgradeObjectsBeforeShutdown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,30 @@

import com.evolveum.midpoint.ninja.action.upgrade.StepResult;
import com.evolveum.midpoint.ninja.action.upgrade.UpgradeStep;
import com.evolveum.midpoint.ninja.action.upgrade.UpgradeStepsContext;

import org.jetbrains.annotations.NotNull;

import java.io.File;

public abstract class UpgradeObjectsStep implements UpgradeStep<StepResult> {

private final UpgradeStepsContext context;

public UpgradeObjectsStep(@NotNull UpgradeStepsContext context) {
this.context = context;
}

@Override
public StepResult execute() throws Exception {
final VerifyResult verifyResult = context.getResult(VerifyResult.class);

final File output = verifyResult.getOutput();

// todo load CSV, only OIDs + state (whether to update)
// go through all oids that need to be updated
// if csv not available go through all

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.evolveum.midpoint.ninja.action.upgrade.step;

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

import java.io.File;

public class VerifyResult implements StepResult {

private File output;

public File getOutput() {
return output;
}
}
12 changes: 11 additions & 1 deletion tools/ninja/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@
-->

<configuration>

<!--<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>./ninja.log</file>
<encoder>
<pattern>%date [%thread] %-5level \(%logger{46}\): %message%n</pattern>
</encoder>
</appender>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date [%thread] %-5level \(%logger{46}\): %message%n</pattern>
</layout>
</appender>-->
</configuration>
1 change: 1 addition & 0 deletions tools/ninja/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ upgrade.distributionArchive=Distribution archive file. This can be used to skip
upgrade.backupMidpointDirectory=Backup midPoint home directory.
upgrade.installationDirectory=MidPoint installation directory.
upgrade.verifyThreads=Number of threads to use to verify objects in midPoint.
upgrade.upgradeThreads=Number of threads to use when updating objects during upgrade.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

import java.io.File;

import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.evolveum.midpoint.ninja.action.upgrade.ConsoleProgressListener;
import com.evolveum.midpoint.ninja.action.upgrade.DistributionManager;
import com.evolveum.midpoint.ninja.action.upgrade.ProgressListener;
import com.evolveum.midpoint.util.logging.Trace;
Expand All @@ -24,30 +24,60 @@ public class DistributionManagerTest {

private static final Trace LOGGER = TraceManager.getTrace(DistributionManagerTest.class);

@Test(enabled = false)
public void downloadLTS() throws Exception {
@BeforeClass
public void beforeClass() {
AnsiConsole.systemInstall();
}

@AfterClass
public void afterClass() {
AnsiConsole.systemUninstall();
}

@Test(enabled = false)
public void downloadSpecificVersion() throws Exception {
downloadAndAssert("4.7");
}

@Test(enabled = false)
public void downloadLatest() throws Exception {
downloadAndAssert(DistributionManager.LATEST_VERSION);
}

final ProgressListener listener = new ConsoleProgressListener();
private void downloadAndAssert(String version) throws Exception {
final TestProgressListener listener = new TestProgressListener();

File file = new DistributionManager(new File("./target")).downloadDistribution("4.4.4", listener);
File file = new DistributionManager(new File("./target")).downloadDistribution(version, listener);
AssertJUnit.assertTrue(file.exists());
AssertJUnit.assertTrue(file.length() > 0);
AssertJUnit.assertEquals(listener.contentLength, file.length());

LOGGER.info("File size: " + file.length());
LOGGER.info("File path: " + file.getAbsolutePath());

AnsiConsole.systemUninstall();
}

@Test(enabled = false)
public void testJANSI() {
AnsiConsole.systemInstall();
private static class TestProgressListener implements ProgressListener {

System.out.println(Ansi.ansi().fgBlue().a("Start").reset());
for (int i = 0; i < 10; i++) {
System.out.println(Ansi.ansi().eraseLine(Ansi.Erase.ALL).fgGreen().a(i).reset());
}
System.out.println(Ansi.ansi().fgRed().a("Complete").reset());
private long contentLength;

AnsiConsole.systemUninstall();
private boolean done;

@Override
public void update(long bytesRead, long contentLength, boolean done) {
AssertJUnit.assertFalse("Already done, shouldn't happen", this.done);

if (this.contentLength == 0) {
AssertJUnit.assertTrue("Content length is zero", contentLength > 0);
this.contentLength = contentLength;
return;
}

if (!this.done && done) {
this.done = true;
}

AssertJUnit.assertEquals("Content length doesn't match", this.contentLength, contentLength);
this.done = done;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.evolveum.midpoint.ninja.upgrade;

import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;
import org.testng.annotations.Test;

public class JansiTest {

@Test//(enabled = false)
public void testJANSI() throws Exception{
AnsiConsole.systemInstall();

// System.out.print(Ansi.ansi().a("vilko\n"));
// System.out.print(Ansi.ansi().cursorUpLine().eraseLine());
// System.out.print(Ansi.ansi().a("janko\n"));

System.out.println(Ansi.ansi().fgBlue().a("Start").reset());
for (int i = 0; i < 10; i++) {
System.out.println(Ansi.ansi().cursorUpLine().eraseLine(Ansi.Erase.ALL).fgGreen().a(i).reset());
Thread.sleep(500);
}
System.out.println(Ansi.ansi().fgRed().a("Complete").reset());

AnsiConsole.systemUninstall();
}
}

0 comments on commit 758392c

Please sign in to comment.