Skip to content

Commit

Permalink
[JBEAP-27367] Improve logging when performing rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob committed Jul 22, 2024
1 parent ad928d3 commit b54f5ca
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,12 @@ default String featurePackDoesNotSupportCustomization(String featurePackName) {
default String featurePackRequiresLicense(String featurePackName) {
return format(bundle.getString("prospero.features.add.required_licences"), featurePackName);
}

default String candidateApplyRollbackSuccess() {
return bundle.getString("prospero.candidate.apply.error.rolled_back.desc");
}

default String candidateApplyRollbackFailure(Path backup) {
return format(bundle.getString("prospero.candidate.apply.error.rollback_error.desc"), backup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.wildfly.channel.ChannelMetadataCoordinate;
import org.wildfly.channel.Repository;
import org.wildfly.prospero.api.ArtifactUtils;
import org.wildfly.prospero.api.exceptions.ApplyCandidateException;
import org.wildfly.prospero.api.exceptions.ArtifactResolutionException;
import org.wildfly.prospero.api.exceptions.ChannelDefinitionException;
import org.wildfly.prospero.api.exceptions.MetadataException;
Expand Down Expand Up @@ -104,6 +105,16 @@ public int handleExecutionException(Exception ex, CommandLine commandLine, Comma
if (ex.getCause() != null && (ex.getCause() instanceof MarkedYAMLException || ex.getCause() instanceof JsonMappingException)) {
console.error(ex.getCause().getLocalizedMessage());
}
} else if (ex instanceof ApplyCandidateException) {
ApplyCandidateException ace = (ApplyCandidateException) ex;
console.error(System.lineSeparator() + ace.getMessage());

if (ace.isRollbackSuccessful()) {
console.error(System.lineSeparator() + CliMessages.MESSAGES.candidateApplyRollbackSuccess());
} else {
console.error(System.lineSeparator() + CliMessages.MESSAGES.candidateApplyRollbackFailure(ace.getBackupPath()));
}

} else {
console.error(CliMessages.MESSAGES.errorHeader(ex.getLocalizedMessage()));
}
Expand Down
3 changes: 3 additions & 0 deletions prospero-cli/src/main/resources/UsageMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,6 @@ prospero.changes.diff.channel=channel
prospero.changes.diff.features_changes=Installed features changes

prospero.changes.conflict.header=Conflicting changes detected in the update:

prospero.candidate.apply.error.rolled_back.desc=The incomplete update changes have been rolled back. Please resolve above error and try to perform update again.
prospero.candidate.apply.error.rollback_error.desc=Unable to restore the incomplete update changes. The server might have been left in a corrupted state, please check the backup of the server at %s.
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,7 @@ default IllegalArgumentException invalidInstallationDir(Path path, List<Path> mi

@Message(id = 271, value = "Unable to evaluate symbolic link %s.")
RuntimeException unableToEvaluateSymbolicLink(Path symlink, @Cause IOException e);

@Message(id = 272, value = "Failed to apply the candidate changes due to: %s")
String failedToApplyCandidate(String reason);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.wildfly.prospero.api.InstallationMetadata;
import org.wildfly.prospero.api.MavenOptions;
import org.wildfly.prospero.api.SavedState;
import org.wildfly.prospero.api.exceptions.ApplyCandidateException;
import org.wildfly.prospero.api.exceptions.InvalidUpdateCandidateException;
import org.wildfly.prospero.api.exceptions.MetadataException;
import org.wildfly.prospero.api.exceptions.OperationException;
Expand Down Expand Up @@ -205,16 +206,20 @@ public List<FileConflict> applyUpdate(Type operation) throws ProvisioningExcepti
backup.close();
return conflicts;
} catch (IOException ex) {
boolean backupRestored = false;
try {
if (backup != null) {
backup.restore();
// remove close the backup if the restore was successful. If there were any errors, we want to keep the backup untouched.
backup.close();
backupRestored = true;
}
} catch (IOException e) {
ProsperoLogger.ROOT_LOGGER.error("Unable to restore the server from a backup, preserving the backup.", e);
}
throw new ProvisioningException("Unable to apply the candidate changes.", ex);
final String msg = ex.getLocalizedMessage() == null ? ex.getMessage() : ex.getLocalizedMessage();
throw new ApplyCandidateException(ProsperoLogger.ROOT_LOGGER.failedToApplyCandidate(msg),
backupRestored, installationDir.resolve(ApplyStageBackup.BACKUP_FOLDER), ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.prospero.api.exceptions;

import java.nio.file.Path;

public class ApplyCandidateException extends OperationException {

private final boolean rollbackSuccessful;
private final Path backupPath;

public ApplyCandidateException(String msg, boolean rollbackSuccessful, Path backupPath, Throwable e) {
super(msg, e);
this.rollbackSuccessful = rollbackSuccessful;
this.backupPath = backupPath;
}

public boolean isRollbackSuccessful() {
return rollbackSuccessful;
}

public Path getBackupPath() {
return backupPath;
}
}

0 comments on commit b54f5ca

Please sign in to comment.