Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration backup/restore in online mode #145

Merged
merged 1 commit into from
Nov 16, 2016

Conversation

mchoma
Copy link
Collaborator

@mchoma mchoma commented Nov 14, 2016

The ConfigurationFileBackup set of offline commands facilitate taking a backup of the server configuration and later restoring it. It would be very useful to have the same possibility in the online mode, e.g. using the existing snapshot function.

* destroy command does nothing.
* </p>
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line.

public void apply(OnlineCommandContext occ) throws CommandFailedException, IOException, CliException {
if (SnapshotBackup.this.snapshotName != null) {
throw new CommandFailedException("Snapshot was already backed up as "
+ SnapshotBackup.this.snapshotName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Snapshot was already taken: " + SnapshotBackup.this.snapshotName

snapshot = modelNodeResult.stringValue();
}
// returns absolute path, but we need just the name of snapshot
snapshot = snapshot.substring(snapshot.lastIndexOf(File.separator) + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using File.separator here accurate? What happens if I'm running on Linux and the server is on Windows?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea how to handle this properly? Thing is snapshotName as value of --server-config parameter for reload could not be absolute path.
Note, File.separator is already used in AddModule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well file names on Windows can contain neither / nor \. So if the string contains /, it obviously isn't Windows and you can split on /, otherwise you split on \.

Re AddModule: this command only makes sense when running on the same system as the server. That doesn't apply in this situation.

@@ -0,0 +1,5 @@
package org.wildfly.extras.creaper.test;

/** Category marker for tests that require WildFly and can't run with AS7. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is clearly copy & paste from WildFlyTests. Please update.

@@ -28,12 +28,16 @@
<version.wildfly10>10.0.0.Final</version.wildfly10>
<version.wildfly10.core>2.0.10.Final</version.wildfly10.core>
<version.wildfly10.arquillian>1.1.0.Alpha1</version.wildfly10.arquillian>
<version.wildfly11>11.0.0.Alpha1-SNAPSHOT</version.wildfly11>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snapshot dependencies are bad. No idea how to fix this...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be replaced with <version.wildfly11>11.0.0.Alpha1</version.wildfly11>.
It will be first valid public value. It can lead user to realize what is going on here. Better than SNAPSHOT, which looks like a bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, OK, but at least add a comment. Something like:

<!-- doesn't exist yet; update when there's a public release of WildFly 11 -->
<version.wildfly11>11.0.0.Alpha1</version.wildfly11>

And a similar comment to the wildfly11 profile.


@Before
public void connect() throws IOException {
client = getManagementClient();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the getManagementClient method used elsewhere? I can only see that it's used here, in which case please inline it.

}

@Test
public void correctUsage() throws CommandFailedException, IOException, OperationException, InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restoreTwice is apparently also correct usage, so we'll need to update the names.

import com.google.common.base.Strings;

/**
* Provides a pair of online commands to backup and then restore the snapshot.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be reworded. We're not backing up and then restoring the snapshot. We're backing up and then restoring application server configuration, and we're using the snapshot features to do so. I'd suggest:

Provides a pair of online commands to backup and then restore application server configuration while the server is running. Backup consists of taking a snapshot, restore then means reloading the server from the snapshot.

* Provides a pair of online commands to backup and then restore the snapshot.
* <p>
* The {@code backup} command must be applied before {@code restore}, and
* {@code backup} can be applied once. If any one of these rules is violated, an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads weird. I'd suggest: The {@code backup} command must be applied before {@code restore}, {@code backup} can be applied once, and then {@code restore} can be applied many times.

* @param snapshotAbsolutePath Absolute path to snapshot
* @return name of snapshot
*/
private String getSnapshotName(String snapshotAbsolutePath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the first line of the method body, I'd expect a comment along the lines of Windows file names can't contain /, so if there's a / in the full path, it's not Windows.

@Ladicek
Copy link
Contributor

Ladicek commented Nov 14, 2016

OK, looks mostly good. When you fix the one last thing, please also squash.

@mchoma mchoma force-pushed the issue12_backup_restore_online branch from 1c3a8af to af7d435 Compare November 14, 2016 13:46
@mchoma
Copy link
Collaborator Author

mchoma commented Nov 15, 2016

PR now contains just squashed commit.

public void apply(OnlineCommandContext occ) throws CommandFailedException, IOException, InterruptedException,
TimeoutException {
if (SnapshotBackup.this.snapshotName == null) {
throw new CommandFailedException("There's no snapshot backup to restore");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, one more! :-) There's no snapshot to restore

<!-- doesn't exist yet; update when there's a public release of WildFly 11 -->
<version.wildfly11>11.0.0.Alpha1</version.wildfly11>
<version.wildfly11.core>3.0.0.Alpha10</version.wildfly11.core>
<version.wildfly11.arquillian>2.0.0.Final</version.wildfly11.arquillian>

<managementPort.as7>9999</managementPort.as7>
<managementPort.wildfly>9990</managementPort.wildfly>

<ignoredCategory.as7>org.wildfly.extras.creaper.test.WildFlyTests</ignoredCategory.as7>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm thinking... should this line also contain WildFly11Tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no, because SnapshotBackupTest is declared as Category {WildFlyTests, WildFly11Tests}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the WildFly11Tests category is meant as a "subset" of WildFlyTests? And everytime a test is in category WildFly11Tests, it also has to be in category WildFlyTests? That kinda sorta makes sense, but should be at least documented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added comment to WildFly11Tests.

@mchoma mchoma force-pushed the issue12_backup_restore_online branch 2 times, most recently from 621e113 to aa5f06b Compare November 16, 2016 06:18
Copy link
Contributor

@Ladicek Ladicek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is the last thing :-)

// returns absolute path, but we need just the name of snapshot
String snapshotName = getSnapshotName(snapshotAbsolutePath);
if (Strings.isNullOrEmpty(snapshotAbsolutePath)) {
throw new CommandFailedException("Unable to take snapshot");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, here's an idea: if the :take-snapshot operation fails, we're silently dropping the error message. That's bad. If there's one, it should be added to this exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into the code, I believe execute() should take care of that - if result is failed throws exception. Now it seems to me this check is unnecessary. Also unnecessary is if (modelNodeResult.isSuccess() WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnlineManagementClient.execute won't throw in case of an error. However, you can do ModelNodeResult.assertSuccess(), which would be enough in this case IMHO.

@mchoma mchoma force-pushed the issue12_backup_restore_online branch from aa5f06b to aa7663a Compare November 16, 2016 10:10
@Ladicek Ladicek self-assigned this Nov 16, 2016
@Ladicek Ladicek added this to the 1.6.0 milestone Nov 16, 2016
@Ladicek
Copy link
Contributor

Ladicek commented Nov 16, 2016

Could you please remove the [14] from the commit message? I'll merge then.

@mchoma mchoma changed the title [14] Configuration backup/restore in online mode Configuration backup/restore in online mode Nov 16, 2016
@mchoma
Copy link
Collaborator Author

mchoma commented Nov 16, 2016

Done

@Ladicek
Copy link
Contributor

Ladicek commented Nov 16, 2016

Not really, you only renamed the PR :-)

@mchoma mchoma force-pushed the issue12_backup_restore_online branch from aa7663a to d5a591f Compare November 16, 2016 12:27
@mchoma
Copy link
Collaborator Author

mchoma commented Nov 16, 2016

Done

@Ladicek Ladicek merged commit d2c17b5 into wildfly-extras:master Nov 16, 2016
@mchoma
Copy link
Collaborator Author

mchoma commented Nov 16, 2016

I can't believe that :O

@Ladicek
Copy link
Contributor

Ladicek commented Nov 16, 2016

I'd like to point out that there were PRs that took more than a month to merge. Compared to that, this one was pretty fast ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants