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 bb62bc1)
  • Loading branch information
1azyman committed Jul 31, 2023
1 parent 052a754 commit 080d247
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ActionResult<Boolean> execute() throws Exception {
return new ActionResult<>(false, 3);
}

log.info("Pre-upgrade checks finished successfully");
return new ActionResult<>(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,21 +329,11 @@ private void writeValidationItem(Writer writer, PrismObject<?> object, UpgradeVa

items.add(object.toDebugName());

UpgradePhase phase = item.getPhase();
if (phase != null) {
items.add(phase);
}

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

UpgradeType type = item.getType();
if (type != null) {
items.add(type);
}

if (validationItem.getItemPath() != null) {
items.add(validationItem.getItemPath());
}
Expand All @@ -354,6 +344,7 @@ private void writeValidationItem(Writer writer, PrismObject<?> object, UpgradeVa
}

writer.write(StringUtils.join(items, " "));
writer.write("\n");
}

private String writeMessage(LocalizableMessage message) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import java.io.*;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.concurrent.BlockingQueue;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
Expand All @@ -22,9 +24,9 @@
import com.evolveum.midpoint.common.validator.EventResult;
import com.evolveum.midpoint.common.validator.LegacyValidator;
import com.evolveum.midpoint.ninja.action.BasicImportOptions;
import com.evolveum.midpoint.ninja.impl.Log;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.impl.NinjaException;
import com.evolveum.midpoint.ninja.impl.Log;
import com.evolveum.midpoint.ninja.util.OperationStatus;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContext;
Expand All @@ -42,7 +44,7 @@ public class ImportProducerWorker<T extends Containerable>

private final ObjectFilter filter;
private final boolean stopAfterFound;
private boolean continueOnInputError;
private final boolean continueOnInputError;

private String currentOid = null;
private boolean convertMissingType = false;
Expand All @@ -60,11 +62,32 @@ public ImportProducerWorker(

@Override
public void run() {
Log log = context.getLog();

operation.start();

try (InputStream input = openInputStream()) {
File inputFile = options.getInput();
try {
if (!inputFile.exists()) {
context.getLog().error("Input file '{}' doesn't exist", inputFile.getPath());
} else if (inputFile.isDirectory()) {
importDirectory(inputFile);
} else {
importFile(inputFile);
}
} finally {
markDone();

if (isWorkersDone()) {
if (!operation.isFinished()) {
operation.producerFinish();
}
}
}
}

private void importFile(File inputFile) {
Log log = context.getLog();

try (InputStream input = openInputStream(inputFile)) {
if (!options.isZip()) {
processStream(input);
} else {
Expand All @@ -83,24 +106,26 @@ public void run() {
processStream(zis);
}
}
} catch (IOException ex) {
log.error("Unexpected error occurred, reason: {}", ex, ex.getMessage());
} catch (NinjaException ex) {
log.error(ex.getMessage(), ex);
} finally {
markDone();
} catch (Exception ex) {
log.error("Unexpected error occurred", ex);
}
}

if (isWorkersDone()) {
if (!operation.isFinished()) {
operation.producerFinish();
}
private void importDirectory(File inputFile) {
Log log = context.getLog();

Collection<File> files = FileUtils.listFiles(inputFile, new String[] { "xml" }, true);
for (File file : files) {
try (InputStream is = new FileInputStream(file)) {
log.info("Processing file {}", file.getName());
processStream(is);
} catch (Exception ex) {
log.error("Unexpected error occurred", ex);
}
}
}

private InputStream openInputStream() throws IOException {
File input = options.getInput();

private InputStream openInputStream(File input) throws IOException {
InputStream is;
if (input != null) {
if (!input.exists()) {
Expand All @@ -115,7 +140,7 @@ private InputStream openInputStream() throws IOException {
return is;
}

private void processStream(InputStream input) throws IOException {
private void processStream(InputStream input) {
ApplicationContext appContext = context.getApplicationContext();
PrismContext prismContext = appContext.getBean(PrismContext.class);
MatchingRuleRegistry matchingRuleRegistry = appContext.getBean(MatchingRuleRegistry.class);
Expand Down

0 comments on commit 080d247

Please sign in to comment.