Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/forgot-user…
Browse files Browse the repository at this point in the history
…name

* origin/master:
  adding log for exceprion of oidc auth module
  MID-8842 ninja - misc fixes around distribution upgrade objects
  MID-8842 ninja - misc fixes around distribution upgrade
  MID-8842 ninja - misc fixes around distribution upgrade
  • Loading branch information
katkav committed Jul 31, 2023
2 parents 2a05e15 + 04d5f77 commit 7b434ed
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public boolean isApplicable(PrismObject<?> object, ItemPath path) {
public boolean process(PrismObject<ObjectType> object, ItemPath path) {
return false;
}

@Override
public String upgradeDescription(PrismObject<ObjectType> object, ItemPath path) {
return "Matching of personas by subtype values is not supported anymore. Any such use should be migrated to the use of archetypes.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static OidcClientModuleWebSecurityConfiguration buildInternal(OidcAuthen
try {
builder = ClientRegistrations.fromOidcIssuerLocation(openIdProvider.getIssuerUri());
} catch (Exception e) {
LOGGER.debug("Couldn't create oidc client builder by issuer uri.");
LOGGER.debug("Couldn't create oidc client builder by issuer uri: " + openIdProvider.getIssuerUri(), e);
}

Assert.hasText(client.getRegistrationId(), "registrationId cannot be empty");
Expand Down Expand Up @@ -108,7 +108,7 @@ private static OidcClientModuleWebSecurityConfiguration buildInternal(OidcAuthen
String clientSecret = protector.decryptString(client.getClientSecret());
builder.clientSecret(clientSecret);
} catch (EncryptionException e) {
LOGGER.error("Couldn't obtain clear string for client secret");
LOGGER.error("Couldn't obtain clear string for client secret", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void processObject(RepositoryService repository, T object) throws Except

OperationResult opResult = new OperationResult("Modify object");
try {
ObjectDelta<?> delta = cloned.diff(prismObject);
ObjectDelta<?> delta = prismObject.diff(cloned);
Collection<? extends ItemDelta<?, ?>> modifications = delta.getModifications();
RepoModifyOptions opts = modifications.isEmpty() ? RepoModifyOptions.createForceReindex() : new RepoModifyOptions();

Expand All @@ -90,9 +90,11 @@ private void processObject(RepositoryService repository, T object) throws Except
} finally {
opResult.computeStatusIfUnknown();

log.error(
"Modification of '{} ({})' didn't finished with success\n{}",
object.getName(), object.getOid(), opResult.shortDump());
if (!opResult.isSuccess()) {
log.error(
"Modification of '{} ({})' didn't finished with success\n{}",
object.getName(), object.getOid(), opResult.debugDumpLazily());
}
}
}
}
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 Expand Up @@ -120,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 @@ -330,22 +326,12 @@ private void writeValidationItem(Writer writer, PrismObject<?> object, UpgradeVa
writer.append("INFO ");
}

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);
}
items.add(getObjectDisplayName(object));

if (validationItem.getItemPath() != null) {
items.add(validationItem.getItemPath());
Expand All @@ -357,9 +343,22 @@ private void writeValidationItem(Writer writer, PrismObject<?> object, UpgradeVa
}

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

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) throws IOException {
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
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 7b434ed

Please sign in to comment.