Skip to content

Commit

Permalink
feat(show vespa version): show vespa version (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
eoctodolphin authored May 22, 2024
1 parent 25f3188 commit b69816b
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 19 deletions.
29 changes: 29 additions & 0 deletions src/main/java/com/vispana/api/model/VespaVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.vispana.api.model;

public record VespaVersion(long major, long minor, long patch) {

public static VespaVersion fromString(String version) {

// Vespa use semantic versioning major.minor.patch
var parts = version.split("\\.");
if (parts.length != 3) {
throw new RuntimeException(
String.format("Failed to parse vespa semantic version: %s", version));
}

try {
new VespaVersion(
Long.parseLong(parts[0]), Long.parseLong(parts[1]), Long.parseLong(parts[2]));
} catch (NumberFormatException e) {
throw new RuntimeException(
String.format("Failed to parse vespa version numbers: %s", version), e);
}
return new VespaVersion(
Long.parseLong(parts[0]), Long.parseLong(parts[1]), Long.parseLong(parts[2]));
}

@Override
public String toString() {
return major + "." + minor + "." + patch;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/vispana/api/model/VispanaRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public record VispanaRoot(
ConfigNodes config,
ContainerNodes container,
ContentNodes content,
ApplicationPackage applicationPackage) {}
ApplicationPackage applicationPackage,
VespaVersion vespaVersion) {}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public VispanaRoot vespaState(String configHost) {
var containerNodes = containerFork.get();
var contentNodes = contentFork.get();

return new VispanaRoot(configNodes, containerNodes, contentNodes, appPackage);
return new VispanaRoot(configNodes, containerNodes, contentNodes, appPackage, vespaVersion);
} catch (Throwable t) {
// Since this application is not meant to be exposed outside a perimeter, jut throw
// the exception to ease debugging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static java.util.stream.Collectors.groupingBy;

import com.vispana.api.model.Host;
import com.vispana.api.model.VespaVersion;
import com.vispana.api.model.apppackage.ApplicationPackage;
import com.vispana.api.model.content.ContentCluster;
import com.vispana.api.model.content.ContentData;
Expand Down Expand Up @@ -38,7 +39,7 @@ public class ContentAssembler {

public static ContentNodes assemble(
String configHost,
String vespaVersion,
VespaVersion vespaVersion,
Map<String, MetricsNode> vespaMetrics,
String appUrl,
ApplicationPackage appPackage) {
Expand Down Expand Up @@ -153,24 +154,13 @@ private static List<String> fetchSchemas(String configHost, String clusterName)
private static List<Node> fetchDispatcherData(
String configHost,
String clusterName,
String vespaVersion,
VespaVersion vespaVersion,
final ApplicationPackage appPackage) {

String[] version = vespaVersion.split("\\.");

// Assume semantic versioning major.minor.patch
if (version.length != 3) {
throw new RuntimeException("Failed to parse vespa version");
}

int majorVersion = Integer.parseInt(version[0]);
int minorVersion = Integer.parseInt(version[1]);

if (majorVersion == 7) {
if (vespaVersion.major() == 7) {
var dispatcherUrl =
configHost + "/config/v1/vespa.config.search.dispatch/" + clusterName + "/search";
return requestGet(dispatcherUrl, SearchDispatchSchema.class).getNode();
} else if (majorVersion == 8 && minorVersion < 323) {
} else if (vespaVersion.major() == 8 && vespaVersion.minor() < 323) {
var dispatcherUrl =
configHost
+ "/config/v2/tenant/default/application/default/vespa.config.search.dispatch-nodes/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import static com.vispana.vespa.state.helpers.Request.requestGet;

import com.vispana.api.model.VespaVersion;
import com.vispana.client.vespa.model.ConfigModelSchema;

public class VespaVersionFetcher {

// this API might be useful to get which container is queryable
public static String fetch(String configHost) {
public static VespaVersion fetch(String configHost) {
var url = configHost + "/config/v2/tenant/default/application/default/cloud.config.model";
return requestGet(url, ConfigModelSchema.class).getVespaVersion();
String vespaVersion = requestGet(url, ConfigModelSchema.class).getVespaVersion();
return VespaVersion.fromString(vespaVersion);
}
}
3 changes: 3 additions & 0 deletions src/main/js/routes/apppackage/app-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function AppPackage() {
<p><span
className="text-yellow-400">Generation:</span> {vespaState.applicationPackage.appPackageGeneration}
</p>
<p><span
className="text-yellow-400">Version:</span> {`${vespaState.vespaVersion.major}.${vespaState.vespaVersion.minor}.${vespaState.vespaVersion.patch}`}
</p>
</div>
})

Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/vispana/api/model/VespaVersionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.vispana.api.model;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class VespaVersionTest {

@Test
void fromString() {
var version = VespaVersion.fromString("7.1.0");
assertEquals(7, version.major());
assertEquals(1, version.minor());
assertEquals(0, version.patch());
assertEquals("7.1.0", version.toString());
}

@Test
void fromStringThrowsOnInvalidVersion() {
assertThrows(RuntimeException.class, () -> VespaVersion.fromString("7.1"));
assertThrows(RuntimeException.class, () -> VespaVersion.fromString("8.323.a"));
}
}

0 comments on commit b69816b

Please sign in to comment.