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

Persist manifest name and expose it via SPI #481

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<version.org.jboss.xnio>3.8.10.Final</version.org.jboss.xnio>
<version.org.wildfly.common>1.6.0.Final</version.org.wildfly.common>
<version.org.wildfly.galleon-plugins>6.4.3.Final</version.org.wildfly.galleon-plugins>
<version.org.wildfly.installation-manager>1.0.1.Final</version.org.wildfly.installation-manager>
<version.org.wildfly.installation-manager>1.0.2.Final</version.org.wildfly.installation-manager>
<version.org.wildfly.maven.plugins.licenses-plugin>2.3.1.Final</version.org.wildfly.maven.plugins.licenses-plugin>
<version.org.mockito>5.3.0</version.org.mockito>
<version.org.slf4j>2.0.7</version.org.slf4j>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static CommandLine createCommandLine(CliConsole console, String[] args, A
channelCmd.addSubcommand(new ChannelAddCommand(console, actionFactory));
channelCmd.addSubcommand(new ChannelRemoveCommand(console, actionFactory));
channelCmd.addSubcommand(new ChannelCommand.ChannelListCommand(console, actionFactory));
channelCmd.addSubcommand(new ChannelCommand.ChannelVersionCommand(console, actionFactory));
channelCmd.addSubcommand(new ChannelInitializeCommand(console, actionFactory));
channelCmd.addSubcommand(new ChannelPromoteCommand(console, actionFactory));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,8 @@ default String quitGenerating() {
default String metadataExistsAlready(Path path, String distName) {
return format(bundle.getString("prospero.update.subscribe.meta.exists"), path, distName);
}

default String serverVersionsHeader() {
return bundle.getString("prospero.channels.versions.header");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.wildfly.prospero.cli.CliMessages;
import org.wildfly.prospero.cli.ReturnCodes;
import org.wildfly.prospero.cli.printers.ChannelPrinter;
import org.wildfly.prospero.metadata.ManifestVersionRecord;
import picocli.CommandLine;

@CommandLine.Command(name = CliConstants.Commands.CHANNEL)
Expand Down Expand Up @@ -78,5 +79,46 @@ public Integer call() throws Exception {
}
}

@CommandLine.Command(name = CliConstants.Commands.VERSIONS)
public static class ChannelVersionCommand extends AbstractCommand {

protected static final String PREFIX = " * ";
@CommandLine.Option(names = CliConstants.DIR)
private Optional<Path> directory;

public ChannelVersionCommand(CliConsole console, ActionFactory actionFactory) {
super(console, actionFactory);
}

@Override
public Integer call() throws Exception {
final Path installationDir = determineInstallationDirectory(directory);

console.println(CliMessages.MESSAGES.serverVersionsHeader());
try (MetadataAction metadataAction = actionFactory.metadataActions(installationDir)) {
final ManifestVersionRecord channelVersions = metadataAction.getChannelVersions();
for (ManifestVersionRecord.MavenManifest mavenManifest : channelVersions.getMavenManifests()) {
if (mavenManifest.getDescription() != null) {
console.println(PREFIX + mavenManifest.getDescription());
} else {
console.println(PREFIX + buildManifestGav(mavenManifest));
}
}
for (ManifestVersionRecord.UrlManifest urlManifest : channelVersions.getUrlManifests()) {
if (urlManifest.getDescription() != null) {
console.println(PREFIX + urlManifest.getDescription());
} else {
console.println(PREFIX + String.format("%s [%s]", urlManifest.getUrl(), urlManifest.getHash()));
}
}
}
return ReturnCodes.SUCCESS;
}

private static String buildManifestGav(ManifestVersionRecord.MavenManifest mavenManifest) {
return String.format("%s:%s [%s]", mavenManifest.getGroupId(), mavenManifest.getArtifactId(), mavenManifest.getVersion());
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ private CliConstants() {
*/
public static final class Commands {


private Commands() {
}

Expand Down Expand Up @@ -59,6 +58,7 @@ private Commands() {
public static final String APPLY = "apply";
public static final String PRINT_LICENSES = "print-licenses";
public static final String SUBSCRIBE = "subscribe";
protected static final String VERSIONS = "versions";
}

// Parameter and option labels:
Expand Down
2 changes: 2 additions & 0 deletions prospero-cli/src/main/resources/UsageMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ${prospero.dist.name}.channel.list.usage.header = Lists the channels used by t
${prospero.dist.name}.channel.remove.usage.header = Unsubscribes the installation from a channel.
${prospero.dist.name}.channel.initialize.usage.header = Add a custom channel to be used by the server
${prospero.dist.name}.channel.promote.usage.header = Promote a bundle of artifacts to a custom repository
${prospero.dist.name}.channel.versions.usage.header = Displays currently used versions of manifests from registered channels.

${prospero.dist.name}.clone.usage.header = Exports installation details required to recreate a server.
${prospero.dist.name}.clone.export.usage.header = Exports the installation details that can be used to recreate a server.
Expand Down Expand Up @@ -299,6 +300,7 @@ prospero.export.done=Export complete

prospero.channels.list.header=Server %s is subscribed to following channels:%n
prospero.channels.add.header=Subscribing %s to channel %s%n
prospero.channels.versions.header=Installed server components:
prospero.channels.added=Channel '%s' added.
prospero.channels.remove.header=Unsubscribing %s from channel %s%n
prospero.channels.removed=Channel '%s' removed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public void testListInvalidInstallationDir() {
.getMessage()));
}

@Test
public void testVersionInvalidInstallationDir() {
int exitCode = commandLine.execute(CliConstants.Commands.CHANNEL, CliConstants.Commands.VERSIONS);

Assert.assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode);
assertTrue(getErrorOutput().contains(CliMessages.MESSAGES.invalidInstallationDir(ChannelCommand.currentDir())
.getMessage()));
}

@Test
public void testAddEmptyRepository() {
int exitCode = commandLine.execute(CliConstants.Commands.CHANNEL, CliConstants.Commands.ADD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.wildfly.prospero.ProsperoLogger;
import org.wildfly.prospero.api.InstallationMetadata;
import org.wildfly.prospero.api.exceptions.MetadataException;
import org.wildfly.prospero.metadata.ManifestVersionRecord;
import org.wildfly.prospero.model.ProsperoConfig;

/**
Expand Down Expand Up @@ -90,6 +91,10 @@ public List<Channel> getChannels() throws MetadataException {
return new ArrayList<>(installationMetadata.getProsperoConfig().getChannels());
}

public ManifestVersionRecord getChannelVersions() {
return installationMetadata.getManifestVersions().orElse(new ManifestVersionRecord());
}

@Override
public void close() {
this.installationMetadata.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public void updateProsperoConfig(ProsperoConfig config) throws MetadataException
gitStorage.recordConfigChange();
}

public Optional<ManifestVersionRecord> getManifestVersions() throws IOException {
public Optional<ManifestVersionRecord> getManifestVersions() {
return manifestVersion;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.wildfly.installationmanager.ChannelChange;
import org.wildfly.installationmanager.HistoryResult;
import org.wildfly.installationmanager.InstallationChanges;
import org.wildfly.installationmanager.ManifestVersion;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.OperationNotAvailableException;
import org.wildfly.installationmanager.Repository;
Expand All @@ -21,6 +22,7 @@
import org.wildfly.prospero.actions.UpdateAction;
import org.wildfly.prospero.api.MavenOptions.Builder;
import org.wildfly.prospero.galleon.GalleonCallbackAdapter;
import org.wildfly.prospero.metadata.ManifestVersionRecord;
import org.wildfly.prospero.spi.internal.CliProvider;
import org.wildfly.prospero.api.SavedState;
import org.wildfly.prospero.api.exceptions.MetadataException;
Expand All @@ -41,6 +43,7 @@
import java.util.ServiceLoader;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ProsperoInstallationManager implements InstallationManager {

Expand Down Expand Up @@ -215,6 +218,20 @@ public String generateApplyRevertCommand(Path scriptHome, Path candidatePath, Os
return escape(scriptHome.resolve(cliProvider.getScriptName(shell))) + " " + cliProvider.getApplyRevertCommand(installationDir, candidatePath);
}

@Override
public Collection<ManifestVersion> getInstalledVersions() throws MetadataException {
try (MetadataAction metadataAction = actionFactory.getMetadataAction()) {
final ManifestVersionRecord versionRecord = metadataAction.getChannelVersions();
return Stream.concat(
versionRecord.getMavenManifests().stream()
.map(m->new ManifestVersion(m.getGroupId()+":"+m.getArtifactId(), m.getDescription(), m.getVersion(), ManifestVersion.Type.MAVEN)),
versionRecord.getUrlManifests().stream()
.map(m->new ManifestVersion(m.getUrl(), m.getDescription(), m.getHash(), ManifestVersion.Type.URL))
)
.collect(Collectors.toList());
}
}

private String escape(Path absolutePath) {
return "\"" + absolutePath.toString() + "\"";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -33,19 +34,35 @@
import java.util.List;
import java.util.Optional;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ManifestVersionRecord {

protected static final String SCHEMA_100 = "1.0.0";
protected static final String DEFAULT_SCHEMA = SCHEMA_100;

@JsonIgnoreProperties(ignoreUnknown = true)
public static class MavenManifest {

private final String description;
private String groupId;
private String artifactId;
private String version;

@Deprecated
public MavenManifest(String groupId,
String artifactId,
String version) {
this(groupId, artifactId, version, null);
}

public MavenManifest(@JsonProperty("groupId") String groupId,
@JsonProperty("artifactId") String artifactId,
@JsonProperty("version") String version) {
@JsonProperty("version") String version,
@JsonProperty(value = "description", required = false) String description) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should that be called "name", rather then "description"? It looks to be equivalent with manifest "name" from the wildfly-channel lib, while there is also "description" in the wildfly-channel lib that would be easy to confuse with this field.

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 wanted to separate where the data is coming from in the manifest YAML from the field in record YAML, in case we decide to use a different manifest in the future. But yeah that's a bit confusing, I don't mind changing that to "name"

this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.description = description;
}

public String getGroupId() {
Expand All @@ -59,20 +76,37 @@ public String getArtifactId() {
public String getVersion() {
return version;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public String getDescription() {
return description;
}

@JsonIgnore
public String getSummary() {
return String.format("[%s:%s::%s]", groupId, artifactId, version);
}

}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class UrlManifest {

private String url;
private String hash;
public UrlManifest(@JsonProperty("url") String url, @JsonProperty("hash") String hash) {
private String description;

@Deprecated
public UrlManifest(String url, String hash) {
this.url = url;
this.hash = hash;
this.description = null;
}

public UrlManifest(@JsonProperty("url") String url, @JsonProperty("hash") String hash, @JsonProperty("description") String description) {
this.url = url;
this.hash = hash;
this.description = description;
}

public String getUrl() {
Expand All @@ -83,13 +117,19 @@ public String getHash() {
return hash;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public String getDescription() {
return description;
}

@JsonIgnore
public String getSummary() {
return String.format("[%s::%s]", url, hash);
}

}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class NoManifest {

private List<String> repos;
Expand All @@ -114,21 +154,26 @@ public String getSummary() {
}

}

private String schemaVersion;
private List<MavenManifest> mavenManifests = new ArrayList<>();

private List<UrlManifest> urlManifests = new ArrayList<>();
private List<NoManifest> noManifests = new ArrayList<>();

@JsonCreator
public ManifestVersionRecord(@JsonProperty("maven") List<MavenManifest> mavenManifests,
public ManifestVersionRecord(@JsonProperty("schemaVersion") String schemaVersion,
@JsonProperty("maven") List<MavenManifest> mavenManifests,
@JsonProperty("url") List<UrlManifest> urlManifests,
@JsonProperty("open") List<NoManifest> noManifests) {
this.schemaVersion = schemaVersion;
this.mavenManifests = mavenManifests==null?Collections.emptyList():mavenManifests;
this.urlManifests = urlManifests==null?Collections.emptyList():urlManifests;
this.noManifests = noManifests==null?Collections.emptyList():noManifests;
}

public ManifestVersionRecord() {
this.schemaVersion = DEFAULT_SCHEMA;
}

@JsonProperty("maven")
Expand All @@ -149,6 +194,10 @@ public List<NoManifest> getOpenManifests() {
return noManifests;
}

public String getSchemaVersion() {
return schemaVersion;
}

public void addManifest(MavenManifest manifest) {
mavenManifests.add(manifest);
}
Expand Down
Loading
Loading