forked from wildfly-extras/prospero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wildfly-extras#648] Extend channels versions operation to identify a…
…ctive and inactive channels
- Loading branch information
Showing
5 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
prospero-common/src/main/java/org/wildfly/prospero/actions/ChannelStatusAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.wildfly.prospero.actions; | ||
|
||
import org.jboss.galleon.ProvisioningException; | ||
import org.wildfly.channel.Channel; | ||
import org.wildfly.channel.ChannelManifest; | ||
import org.wildfly.channel.ChannelManifestMapper; | ||
import org.wildfly.channel.ChannelSession; | ||
import org.wildfly.channel.MavenArtifact; | ||
import org.wildfly.channel.MavenCoordinate; | ||
import org.wildfly.channel.Stream; | ||
import org.wildfly.prospero.api.ChannelVersions; | ||
import org.wildfly.prospero.api.InstallationMetadata; | ||
import org.wildfly.prospero.api.MavenOptions; | ||
import org.wildfly.prospero.api.exceptions.OperationException; | ||
import org.wildfly.prospero.galleon.GalleonEnvironment; | ||
import org.wildfly.prospero.metadata.ManifestVersionRecord; | ||
import org.wildfly.prospero.wfchannel.MavenSessionManager; | ||
|
||
import java.net.MalformedURLException; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class ChannelStatusAction { | ||
|
||
|
||
private final InstallationMetadata installationMetadata; | ||
private final ChannelSession channelSession; | ||
|
||
public ChannelStatusAction(Path installation) throws OperationException, ProvisioningException { | ||
this.installationMetadata = InstallationMetadata.loadInstallation(installation); | ||
final List<Channel> channels = installationMetadata.getProsperoConfig().getChannels(); | ||
final MavenSessionManager msm = new MavenSessionManager(MavenOptions.DEFAULT_OPTIONS); | ||
final GalleonEnvironment env = GalleonEnvironment.builder(installation, channels, msm, true).build(); | ||
this.channelSession = env.getChannelSession(); | ||
} | ||
|
||
public List<ChannelVersions> getChannelsStatus() throws MalformedURLException { | ||
final ChannelManifest installedManifest = this.installationMetadata.getManifest(); | ||
|
||
final Optional<ManifestVersionRecord> manifestVersions = this.installationMetadata.getManifestVersions(); | ||
if (manifestVersions.isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
final List<Channel> channels = this.installationMetadata.getProsperoConfig().getChannels(); | ||
|
||
|
||
final List<ChannelVersions> channelVersions = new ArrayList<>(); | ||
for (ManifestVersionRecord.MavenManifest mavenManifest : manifestVersions.get().getMavenManifests()) { | ||
Channel channel = mapToChannel(mavenManifest, channels); | ||
|
||
// resolve this manifest | ||
final MavenArtifact artifact = channelSession.resolveDirectMavenArtifact(mavenManifest.getGroupId(), mavenManifest.getArtifactId(), "yaml", "manifest", mavenManifest.getVersion()); | ||
|
||
final ChannelManifest manifest = ChannelManifestMapper.from(artifact.getFile().toURI().toURL()); | ||
|
||
ChannelVersions.Status status = ChannelVersions.Status.NONE; | ||
boolean found = false; | ||
for (Stream stream : manifest.getStreams()) { | ||
final Optional<Stream> installedArtifact = installedManifest.findStreamFor(stream.getGroupId(), stream.getArtifactId()); | ||
if (installedArtifact.isEmpty()) { | ||
continue; | ||
} | ||
|
||
if (!installedArtifact.get().getVersion().equals(stream.getVersion())) { | ||
if (status != ChannelVersions.Status.NONE) { | ||
status = ChannelVersions.Status.PARTIAL; | ||
} | ||
found = true; | ||
} else { | ||
if (status != ChannelVersions.Status.PARTIAL) { | ||
status = ChannelVersions.Status.FULL; | ||
} | ||
} | ||
} | ||
if (status == ChannelVersions.Status.FULL && found) { | ||
status = ChannelVersions.Status.PARTIAL; | ||
} | ||
channelVersions.add(new ChannelVersions(channel==null?"":channel.getName(), mavenManifest.getGroupId() + ":" + mavenManifest.getArtifactId(), mavenManifest.getVersion(), status)); | ||
} | ||
|
||
return channelVersions; | ||
} | ||
|
||
private Channel mapToChannel(ManifestVersionRecord.MavenManifest mavenManifest, List<Channel> channels) { | ||
for (Channel channel : channels) { | ||
if (channel.getManifestCoordinate() == null || channel.getManifestCoordinate().getMaven() == null) { | ||
return null; | ||
} | ||
|
||
final MavenCoordinate mavenCoord = channel.getManifestCoordinate().getMaven(); | ||
if (mavenCoord.getGroupId().equals(mavenManifest.getGroupId()) && mavenCoord.getArtifactId().equals(mavenManifest.getArtifactId())) { | ||
return channel; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
prospero-common/src/main/java/org/wildfly/prospero/api/ChannelVersions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.wildfly.prospero.api; | ||
|
||
public class ChannelVersions { | ||
|
||
private final String mavenCoord; | ||
|
||
public enum Status {FULL, PARTIAL, NONE, UNKNOWN} | ||
private String name; | ||
private String version; | ||
private Status status; | ||
|
||
public ChannelVersions(String name, String mavenCoord, String version, Status status) { | ||
this.name = name; | ||
this.version = version; | ||
this.status = status; | ||
this.mavenCoord = mavenCoord; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public Status getStatus() { | ||
return status; | ||
} | ||
|
||
public String getMavenCoord() { | ||
return mavenCoord; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ChannelVersions{" + | ||
"name='" + name + '\'' + | ||
", version='" + version + '\'' + | ||
", status=" + status + | ||
'}'; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
prospero-common/src/test/java/org/wildfly/prospero/actions/ChannelStatusActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.wildfly.prospero.actions; | ||
|
||
import org.junit.Test; | ||
import org.wildfly.prospero.api.ChannelVersions; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
|
||
public class ChannelStatusActionTest { | ||
|
||
@Test | ||
public void testMe() throws Exception { | ||
final ChannelStatusAction channelStatusAction = new ChannelStatusAction(Path.of("/Users/spyrkob/workspaces/set/prospero/tmp/JBEAP-26936/server")); | ||
|
||
final List<ChannelVersions> channelsStatus = channelStatusAction.getChannelsStatus(); | ||
|
||
channelsStatus.forEach(System.out::println); | ||
} | ||
|
||
} |