-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(content data for vespa version >=8.323.45): content data for vesp…
…a version >=8.323.45 (#76) * Use appPackage to create content nodes * Ignore jenv * Ignore jenv * Clean * Remove jenv
- Loading branch information
1 parent
9dff0b9
commit 25f3188
Showing
18 changed files
with
449 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ package-lock.json | |
org.eclipse.* | ||
settings.json | ||
.DS_Store | ||
.java-version |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/vispana/api/model/apppackage/Content.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,17 @@ | ||
package com.vispana.api.model.apppackage; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import java.util.List; | ||
|
||
public class Content { | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
private String id; | ||
|
||
@JacksonXmlProperty(localName = "group") | ||
private TopGroup topGroup; | ||
|
||
protected List<Group> getContentGroups() { | ||
return topGroup != null ? topGroup.getGroups() : List.of(); | ||
} | ||
} |
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,30 @@ | ||
package com.vispana.api.model.apppackage; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import java.util.List; | ||
|
||
public class Group { | ||
|
||
@JacksonXmlProperty(localName = "name", isAttribute = true) | ||
private String name; | ||
|
||
@JacksonXmlProperty(localName = "distribution-key", isAttribute = true) | ||
private String distributionKey; | ||
|
||
@JacksonXmlElementWrapper(useWrapping = false) | ||
@JacksonXmlProperty(localName = "node") | ||
List<Node> nodes; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDistributionKey() { | ||
return distributionKey; | ||
} | ||
|
||
public List<Node> getNodes() { | ||
return nodes != null ? nodes : List.of(); | ||
} | ||
} |
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 com.vispana.api.model.apppackage; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
|
||
public class Host { | ||
|
||
@JacksonXmlProperty(localName = "name", isAttribute = true) | ||
private String name; | ||
|
||
@JacksonXmlProperty(localName = "alias") | ||
private String alias; | ||
|
||
// getters and setters | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getAlias() { | ||
return alias; | ||
} | ||
} |
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,29 @@ | ||
package com.vispana.api.model.apppackage; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@JacksonXmlRootElement(localName = "hosts") | ||
public class Hosts { | ||
@JacksonXmlElementWrapper(useWrapping = false) | ||
@JacksonXmlProperty(localName = "host") | ||
List<Host> hosts; | ||
|
||
public static Hosts fromXml(String xml) { | ||
XmlMapper xmlMapper = new XmlMapper(); | ||
|
||
try { | ||
return xmlMapper.readValue(xml, Hosts.class); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to parse Hosts xml", e); | ||
} | ||
} | ||
|
||
public List<Host> getHosts() { | ||
return hosts == null ? List.of() : hosts.stream().toList(); | ||
} | ||
} |
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,20 @@ | ||
package com.vispana.api.model.apppackage; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
|
||
public class Node { | ||
|
||
@JacksonXmlProperty(localName = "hostalias", isAttribute = true) | ||
private String hostAlias; | ||
|
||
@JacksonXmlProperty(localName = "distribution-key", isAttribute = true) | ||
private String distributionKey; | ||
|
||
public String getHostAlias() { | ||
return hostAlias; | ||
} | ||
|
||
public String getDistributionKey() { | ||
return distributionKey; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/vispana/api/model/apppackage/Services.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,31 @@ | ||
package com.vispana.api.model.apppackage; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@JacksonXmlRootElement(localName = "services") | ||
public class Services { | ||
|
||
@JacksonXmlProperty(localName = "content") | ||
private Content content; | ||
|
||
public static Services fromXml(String xml) { | ||
XmlMapper xmlMapper = new XmlMapper(); | ||
// To ignore parts off service xml that we don't need | ||
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
|
||
try { | ||
return xmlMapper.readValue(xml, Services.class); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to parse Services xml", e); | ||
} | ||
} | ||
|
||
public List<Group> getContentGroups() { | ||
return content != null ? content.getContentGroups() : List.of(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/vispana/api/model/apppackage/TopGroup.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,19 @@ | ||
package com.vispana.api.model.apppackage; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import java.util.List; | ||
|
||
public class TopGroup { | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
private String name; | ||
|
||
@JacksonXmlElementWrapper(useWrapping = false) | ||
@JacksonXmlProperty(localName = "group") | ||
List<Group> groups; | ||
|
||
public List<Group> getGroups() { | ||
return groups; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/main/java/com/vispana/vespa/state/helpers/ContentNodesExtractor.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,41 @@ | ||
package com.vispana.vespa.state.helpers; | ||
|
||
import com.vispana.api.model.apppackage.ApplicationPackage; | ||
import com.vispana.api.model.apppackage.Hosts; | ||
import com.vispana.api.model.apppackage.Services; | ||
import com.vispana.client.vespa.model.content.Node; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ContentNodesExtractor { | ||
public static final long DEFAULT_RPC_ADMIN_PORT = 19103L; | ||
|
||
public static List<Node> contentNodesFromAppPackage(final ApplicationPackage appPackage) { | ||
Services services = Services.fromXml(appPackage.servicesContent()); | ||
Hosts hosts = Hosts.fromXml(appPackage.hostsContent()); | ||
|
||
return services.getContentGroups().stream() | ||
.flatMap(group -> group.getNodes().stream().map(n -> createNode(group, n, hosts))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static Node createNode( | ||
final com.vispana.api.model.apppackage.Group group, | ||
final com.vispana.api.model.apppackage.Node appPackNode, | ||
final Hosts hosts) { | ||
Node node = new Node(); | ||
node.setPort(DEFAULT_RPC_ADMIN_PORT); | ||
node.setKey(Long.parseLong(appPackNode.getDistributionKey())); | ||
node.setGroup(Long.parseLong(group.getDistributionKey())); | ||
|
||
String hostAlias = appPackNode.getHostAlias(); | ||
String hostName = | ||
hosts.getHosts().stream() | ||
.filter(host -> hostAlias.equals(host.getAlias())) | ||
.map(com.vispana.api.model.apppackage.Host::getName) | ||
.findFirst() | ||
.orElseThrow(() -> new RuntimeException("Failed to find host for alias: " + hostAlias)); | ||
node.setHost(hostName); | ||
return node; | ||
} | ||
} |
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,29 @@ | ||
package com.vispana; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import org.apache.commons.io.FileUtils; | ||
|
||
public class Helper { | ||
|
||
public static String defaultHostsXmlString() { | ||
ClassLoader loader = Helper.class.getClassLoader(); | ||
File file = new File(loader.getResource("xml/hosts.xml").getFile()); | ||
try { | ||
return FileUtils.readFileToString(file, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static String defaultServicesXmlString() { | ||
ClassLoader loader = Helper.class.getClassLoader(); | ||
File file = new File(loader.getResource("xml/services.xml").getFile()); | ||
try { | ||
return FileUtils.readFileToString(file, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.