Skip to content

Commit

Permalink
MID-8842 copied ninja code to support-4.4 (matching 9cca323)
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jun 21, 2023
1 parent 11c14a4 commit 06d377f
Show file tree
Hide file tree
Showing 28 changed files with 459 additions and 545 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface MidpointConfiguration {

String USER_HOME_PROPERTY = "user.home";

String MIDPOINT_CONFIG_FILE_PROPERTY = "midpoint.configFile";

// Other commonly-used configuration properties
String MIDPOINT_NODE_ID_PROPERTY = "midpoint.nodeId";
String MIDPOINT_NODE_ID_SOURCE_PROPERTY = "midpoint.nodeIdSource";
Expand Down
9 changes: 1 addition & 8 deletions tools/ninja/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -205,14 +206,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>

<!-- TEST DEPENDENCIES -->
<dependency>
Expand Down
29 changes: 27 additions & 2 deletions tools/ninja/src/main/java/com/evolveum/midpoint/ninja/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;

import com.evolveum.midpoint.ninja.impl.ActionStateListener;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.fusesource.jansi.AnsiConsole;
Expand All @@ -30,12 +33,22 @@

public class Main {

public static void main(String[] args) {
new Main().run(args);
}

private ActionStateListener actionStateListener;

private PrintStream out = System.out;

private PrintStream err = System.err;

public static void main(String[] args) {
new Main().run(args);
public ActionStateListener getActionStateListener() {
return actionStateListener;
}

public void setActionStateListener(ActionStateListener actionStateListener) {
this.actionStateListener = actionStateListener;
}

public PrintStream getOut() {
Expand Down Expand Up @@ -105,9 +118,21 @@ protected <T> void run(String[] args) {
context = new NinjaContext(out, err, allOptions, action.getApplicationContextLevel(allOptions));

try {
if (actionStateListener != null) {
actionStateListener.onBeforeInit(context);
}

action.init(context, options);

if (actionStateListener != null) {
actionStateListener.onBeforeExecution(context);
}

action.execute();

if (actionStateListener != null) {
actionStateListener.onAfterExecution(context);
}
} finally {
action.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ public class RunSqlOptions {

public enum Mode {

/**
* This will create raw datasource from JDBC url/username/password. Midpoint home doesn't have to be defined.
*/
RAW(Collections.emptyList(), Collections.emptyList()),

/**
* This mode will set up datasource based on midpoint home config.xml pointing to midpoint repository.
*/
REPOSITORY(
List.of(new File(SCRIPTS_DIRECTORY, "postgres-new.sql"),
new File(SCRIPTS_DIRECTORY, "postgres-new-quartz.sql")),
List.of(new File(SCRIPTS_DIRECTORY, "postgres-new-upgrade.sql"))
),

/**
* This mode will set up datasource based on midpoint home config.xml pointing to midpoint audit database.
*/
AUDIT(
List.of(new File(SCRIPTS_DIRECTORY, "postgres-new-audit.sql")),
List.of(new File(SCRIPTS_DIRECTORY, "postgres-new-upgrade-audit.sql"))
Expand All @@ -45,7 +54,11 @@ public enum Mode {
public static final String P_JDBC_USERNAME_LONG = "--jdbc-username";
public static final String P_JDBC_PASSWORD_LONG = "--jdbc-password";
public static final String P_MODE = "--mode";

// todo there should be upgrade-repository and upgrade-audit
public static final String P_UPGRADE = "--upgrade";

// todo there should be create-repository and create-audit
public static final String P_CREATE = "--create";
public static final String P_RESULT = "--result";

Expand Down Expand Up @@ -78,8 +91,6 @@ public enum Mode {
@Parameter(names = { P_RESULT }, descriptionKey = "runSql.result")
private boolean result;

private File scriptsDirectory;

public List<File> getScripts() {
return scripts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum ReportStyle {
CSV
}

static class ReportStyleConverter extends EnumConverterValidator<ReportStyle> {
public static class ReportStyleConverter extends EnumConverterValidator<ReportStyle> {

public ReportStyleConverter() {
super(VerifyOptions.ReportStyle.class);
Expand All @@ -42,7 +42,7 @@ public enum VerificationCategory {
INCORRECT_OIDS
}

static class VerificationCategoryConverter extends EnumConverterValidator<VerificationCategory> {
public static class VerificationCategoryConverter extends EnumConverterValidator<VerificationCategory> {

public VerificationCategoryConverter() {
super(VerificationCategory.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.evolveum.midpoint.ninja.action.mining;

import static com.evolveum.midpoint.common.RoleMiningExportUtils.*;
import static com.evolveum.midpoint.repo.api.RepositoryService.LOGGER;
import static com.evolveum.midpoint.security.api.MidPointPrincipalManager.DOT_CLASS;

import java.io.IOException;
Expand All @@ -16,6 +15,10 @@
import java.util.concurrent.BlockingQueue;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.logging.Trace;

import com.evolveum.midpoint.util.logging.TraceManager;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -38,6 +41,8 @@

public class ExportMiningConsumerWorker extends AbstractWriterConsumerWorker<ExportMiningOptions, FocusType> {

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

OperationResult operationResult = new OperationResult(DOT_CLASS + "searchObjectByCondition");

private PrismSerializer<String> serializer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.evolveum.midpoint.ninja.action.upgrade;

import java.io.File;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;

Expand Down Expand Up @@ -52,7 +53,7 @@ public Void execute() throws Exception {
upgradeRepositoryOpts.setMode(RunSqlOptions.Mode.REPOSITORY);
upgradeRepositoryOpts.setScripts(RunSqlOptions.Mode.REPOSITORY.updateScripts.stream()
.map(f -> new File(installationDirectory, f.getPath()))
.toList());
.collect(Collectors.toList()));

RunSqlAction upgradeRepositoryAction = new RunSqlAction();
upgradeRepositoryAction.init(context, upgradeRepositoryOpts);
Expand All @@ -63,7 +64,7 @@ public Void execute() throws Exception {
upgradeAuditOpts.setMode(RunSqlOptions.Mode.AUDIT);
upgradeRepositoryOpts.setScripts(RunSqlOptions.Mode.AUDIT.updateScripts.stream()
.map(f -> new File(installationDirectory, f.getPath()))
.toList());
.collect(Collectors.toList()));

RunSqlAction upgradeAuditAction = new RunSqlAction();
upgradeAuditAction.init(context, upgradeAuditOpts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
package com.evolveum.midpoint.ninja.action.upgrade;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public interface UpgradeObjectProcessor<T extends ObjectType> {

// todo implement
// String getIdentifier();
String getIdentifier();

UpgradePhase getPhase();

<O extends ObjectType> boolean isApplicable(Class<O> type);
UpgradePriority getPriority();

UpgradeType getType();

boolean isApplicable(PrismObject<?> object, ItemPath path);

/**
* Updates object to correct form
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.evolveum.midpoint.ninja.action.upgrade.handler;

import com.evolveum.midpoint.ninja.action.upgrade.UpgradePhase;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;

public class AddRemoveAttributeValuesProcessor extends RemovedElementProcessor<ResourceType> {

@Override
public UpgradePhase getPhase() {
return UpgradePhase.BEFORE;
}

@Override
public <O extends ObjectType> boolean isApplicable(Class<O> type) {
return ResourceType.class.isAssignableFrom(type);
}
// @Override
// public UpgradePhase getPhase() {
// return UpgradePhase.BEFORE;
// }
//
// @Override
// public <O extends ObjectType> boolean isApplicable(PrismObject<O> object) {
// return ResourceType.class.isAssignableFrom(object.getCompileTimeClass());
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public abstract class RemovedElementProcessor<T extends ObjectType> implements UpgradeObjectProcessor<T> {
public abstract class RemovedElementProcessor<T extends ObjectType> {//implements UpgradeObjectProcessor<T> {

@Override
public boolean processObject(PrismObject<T> object, OperationResult result) {
return true;
}
// @Override
// public boolean processObject(PrismObject<T> object, OperationResult result) {
// return true;
// }
}

This file was deleted.

0 comments on commit 06d377f

Please sign in to comment.