Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.vispana.api.model.apppackage;

import java.util.List;
import java.util.Map;

// Application package
public record ApplicationPackage(
String appPackageGeneration, String servicesContent, String hostsContent) {}
String appPackageGeneration,
String servicesContent,
String hostsContent,
List<String> modelsContent,
Map<String, String> queryProfilesContent,
Map<String, String> queryProfileTypesContent) {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import com.vispana.api.model.apppackage.ApplicationPackage;
import com.vispana.client.vespa.model.ApplicationSchema;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AppPackageAssembler {

Expand All @@ -13,7 +16,91 @@ public static ApplicationPackage assemble(String appUrl) {
var hostContent = requestGetWithDefaultValue(appUrl + "/content/hosts.xml", String.class, "");
var servicesContent = requestGet(appUrl + "/content/services.xml", String.class);

List<String> modelsContent =
requestGetWithDefaultValue(appUrl + "/content/models/", List.class, List.of());

// Parse JSON array and extract model names
if (modelsContent.isEmpty()) {
modelsContent = List.of();
} else {
try {
modelsContent =
modelsContent.stream()
.map(
fullUrl -> {
// Subtract filename from URL
int lastSlashIndex = fullUrl.lastIndexOf('/');
return lastSlashIndex >= 0 ? fullUrl.substring(lastSlashIndex + 1) : fullUrl;
})
.toList();
} catch (Exception e) {
// Handle JSON parsing error - return empty list or throw exception
modelsContent = List.of("Error parsing models");
}
}

Map<String, String> queryProfilesContent = new HashMap<String, String>();
List<String> queryProfileNames =
requestGetWithDefaultValue(
appUrl + "/content/search/query-profiles/", List.class, List.of());
if (!queryProfileNames.isEmpty()) {
try {
queryProfileNames =
queryProfileNames.stream()
.map(
fullUrl -> {
// Subtract filename from URL
int lastSlashIndex = fullUrl.lastIndexOf('/');
return lastSlashIndex >= 0 ? fullUrl.substring(lastSlashIndex + 1) : fullUrl;
})
.filter(name -> name.endsWith(".xml"))
.toList();
for (String queryProfileName : queryProfileNames) {
queryProfilesContent.put(
queryProfileName,
requestGetWithDefaultValue(
appUrl + "/content/search/query-profiles/" + queryProfileName, String.class, ""));
}
} catch (Exception e) {
queryProfilesContent = Map.of("Error", "Error parsing query profiles");
}
}

Map<String, String> queryProfileTypesContent = new HashMap<String, String>();
List<String> queryProfileTypeNames =
requestGetWithDefaultValue(
appUrl + "/content/search/query-profiles/types/", List.class, List.of());
if (!queryProfileTypeNames.isEmpty()) {
try {
queryProfileTypeNames =
queryProfileTypeNames.stream()
.map(
fullUrl -> {
// Subtract filename from URL
int lastSlashIndex = fullUrl.lastIndexOf('/');
return lastSlashIndex >= 0 ? fullUrl.substring(lastSlashIndex + 1) : fullUrl;
})
.filter(name -> name.endsWith(".xml"))
.toList();
for (String queryProfileTypeName : queryProfileTypeNames) {
queryProfileTypesContent.put(
queryProfileTypeName,
requestGetWithDefaultValue(
appUrl + "/content/search/query-profiles/types/" + queryProfileTypeName,
String.class,
""));
}
} catch (Exception e) {
queryProfileTypesContent = Map.of("Error", "Error parsing query profile types");
}
}

return new ApplicationPackage(
appSchema.getGeneration().toString(), servicesContent, hostContent);
appSchema.getGeneration().toString(),
servicesContent,
hostContent,
modelsContent,
queryProfilesContent,
queryProfileTypesContent);
}
}
54 changes: 54 additions & 0 deletions src/main/js/routes/apppackage/app-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,60 @@ function AppPackage() {
})
}

// possibly add models
let modelsContent = vespaState.applicationPackage.modelsContent;
if (modelsContent.length > 0) {
tabsContent.push({
"tabName": "models",
"payload": JSON.stringify(modelsContent, null, 2),
"contentType": "json"
})
}

// possibly add query-profiles with their XML content
let queryProfilesContent = vespaState.applicationPackage.queryProfilesContent;
// queryProfilesContent is a Map<String, String>
if (Object.keys(queryProfilesContent).length > 0) {
// Create a combined payload with all query profile XML contents
const combinedQueryProfiles = Object.entries(queryProfilesContent)
.map(([profileName, content]) => {
if (content) {
return `<!-- ${profileName} -->\n${content}`;
} else {
return `<!-- ${profileName} -->\n<!-- Error loading query profile -->`;
}
})
.join('\n\n');

tabsContent.push({
"tabName": "query-profiles",
"payload": combinedQueryProfiles,
"contentType": "xml"
})
}

// possibly add query-profile-types with their XML content
let queryProfileTypesContent = vespaState.applicationPackage.queryProfileTypesContent;
// queryProfileTypesContent is a Map<String, String>
if (Object.keys(queryProfileTypesContent).length > 0) {
// Create a combined payload with all query profile type XML contents
const combinedQueryProfileTypes = Object.entries(queryProfileTypesContent)
.map(([profileTypeName, content]) => {
if (content) {
return `<!-- ${profileTypeName} -->\n${content}`;
} else {
return `<!-- ${profileTypeName} -->\n<!-- Error loading query profile type -->`;
}
})
.join('\n\n');

tabsContent.push({
"tabName": "query-profile-types",
"payload": combinedQueryProfileTypes,
"contentType": "xml"
})
}

// add the schemas
tabsContent.push(...schemas)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.vispana.api.model.apppackage.ApplicationPackage;
import com.vispana.client.vespa.model.content.Node;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;

class ContentNodesExtractorTest {
Expand All @@ -17,7 +18,8 @@ void contentNodesFromAppPackageForMultiGroup() {
String hostsXmlString = defaultHostsXmlString();
String servicesXmlString = defaultServicesXmlString();
ApplicationPackage applicationPackage =
new ApplicationPackage("1", servicesXmlString, hostsXmlString);
new ApplicationPackage(
"1", servicesXmlString, hostsXmlString, List.of(), Map.of(), Map.of());
List<Node> nodes =
ContentNodesExtractor.contentNodesFromAppPackage(applicationPackage, "config.host.name");

Expand All @@ -38,7 +40,8 @@ void contentNodesFromAppPackageForSingleGroup() {
String hostsXmlString = defaultHostsXmlString();
String servicesXmlString = Helper.servicesXmlString("xml/services-single-group.xml");
ApplicationPackage applicationPackage =
new ApplicationPackage("1", servicesXmlString, hostsXmlString);
new ApplicationPackage(
"1", servicesXmlString, hostsXmlString, List.of(), Map.of(), Map.of());
List<Node> nodes =
ContentNodesExtractor.contentNodesFromAppPackage(applicationPackage, "config.host.name");

Expand All @@ -60,7 +63,8 @@ void contentNodesFromAppPackageForSingleGroupSingleHost() {
String servicesXmlString =
Helper.servicesXmlString("xml/services-single-group-single-host.xml");
ApplicationPackage applicationPackage =
new ApplicationPackage("1", servicesXmlString, hostsXmlString);
new ApplicationPackage(
"1", servicesXmlString, hostsXmlString, List.of(), Map.of(), Map.of());
List<Node> nodes =
ContentNodesExtractor.contentNodesFromAppPackage(applicationPackage, "config.host.name");

Expand All @@ -77,7 +81,8 @@ void contentNodesFromAppPackageForNoGroup() {
String hostsXmlString = defaultHostsXmlString();
String servicesXmlString = Helper.servicesXmlString("xml/services-no-group.xml");
ApplicationPackage applicationPackage =
new ApplicationPackage("1", servicesXmlString, hostsXmlString);
new ApplicationPackage(
"1", servicesXmlString, hostsXmlString, List.of(), Map.of(), Map.of());
List<Node> nodes =
ContentNodesExtractor.contentNodesFromAppPackage(applicationPackage, "config.host.name");

Expand All @@ -98,7 +103,8 @@ void contentNodesFromAppPackageForSingleHost() {
String hostsXmlString = ""; // Single host does not require hosts.xml
String servicesXmlString = Helper.servicesXmlString("xml/services-single-host.xml");
ApplicationPackage applicationPackage =
new ApplicationPackage("1", servicesXmlString, hostsXmlString);
new ApplicationPackage(
"1", servicesXmlString, hostsXmlString, List.of(), Map.of(), Map.of());
List<Node> nodes =
ContentNodesExtractor.contentNodesFromAppPackage(applicationPackage, "config.host.name");

Expand Down