Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.
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
5 changes: 4 additions & 1 deletion DAQAggregator_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,7 @@ persistence.flashlist.format = json
#
logfile = /tmp/daqaggregator.log
comment = Test
sortpriority = 1
sortpriority = 1

# network domain to shorten/expand hostnames
network.domain = .cms
4 changes: 4 additions & 0 deletions src/main/java/rcms/utilities/daqaggregator/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import rcms.utilities.daqaggregator.datasource.FlashlistConfigurationReader;
import rcms.utilities.daqaggregator.datasource.FlashlistType;
import rcms.utilities.daqaggregator.datasource.LiveAccessServiceExplorer;
import rcms.utilities.daqaggregator.mappers.helper.ContextHelper;

public class Application {

Expand All @@ -36,6 +37,9 @@ public static Application get() {
public static void initialize(String propertiesFile) {
instance = new Application(propertiesFile);
checkRequiredSettings();

ContextHelper.setNetworkSuffix(instance.getProp(Settings.NETWORK_DOMAIN));

configureFlashlists();

/*
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/rcms/utilities/daqaggregator/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ public enum Settings {
PERSISTENCE_SNAPSHOT_DIR("persistence.snapshot.dir"),
PERSISTENCE_FLASHLIST_FORMAT("persistence.flashlist.format"),
PERSISTENCE_SNAPSHOT_FORMAT("persistence.snapshot.format"),
PERSISTENCE_LIMIT("persistence.flashlist.explore.start"), ;
PERSISTENCE_LIMIT("persistence.flashlist.explore.start"),

// network domain
NETWORK_DOMAIN("network.domain", true),
;

private Settings(String key, boolean required) {
this.key = key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public String generateId(Object forPojo) {
BU bu = (BU) forPojo;

String buHostname = bu.getHostname();
buHostname = ContextHelper.removeSuffixFromHostname(buHostname, ".cms");
buHostname = ContextHelper.removeNetworkSuffix(buHostname);

StringBuilder sb = new StringBuilder(prefix.length() + buHostname.length());

Expand Down Expand Up @@ -224,7 +224,7 @@ public String generateId(Object forPojo) {
RU ru = (RU) forPojo;

String ruHostname = ru.getHostname();
ruHostname = ContextHelper.removeSuffixFromHostname(ruHostname, ".cms");
ruHostname = ContextHelper.removeNetworkSuffix(ruHostname);

StringBuilder sb = new StringBuilder(prefix.length() + ruHostname.length());

Expand Down Expand Up @@ -276,7 +276,7 @@ public String generateId(Object forPojo) {
FRLPc frlpc = (FRLPc) forPojo;

String frlpcHostname = frlpc.getHostname();
frlpcHostname = ContextHelper.removeSuffixFromHostname(frlpcHostname, ".cms");
frlpcHostname = ContextHelper.removeNetworkSuffix(frlpcHostname);

StringBuilder sb = new StringBuilder(prefix.length() + frlpcHostname.length());

Expand Down Expand Up @@ -537,7 +537,7 @@ public String generateId(Object forPojo) {
FMMApplication fmmapp = (FMMApplication) forPojo;

String fmmappHostname = fmmapp.getHostname();
fmmappHostname = ContextHelper.removeSuffixFromHostname(fmmappHostname, ".cms");
fmmappHostname = ContextHelper.removeNetworkSuffix(fmmappHostname);

StringBuilder sb = new StringBuilder(prefix.length() + fmmappHostname.length());

Expand Down Expand Up @@ -647,7 +647,7 @@ public String generateId(Object forPojo) {
String fedBuilderName = sfb.getFedBuilder().getName();
String ttcpName = sfb.getTtcPartition().getName();
String frlpcHostname = sfb.getFrlPc() != null ? sfb.getFrlPc().getHostname() : "-";
frlpcHostname = ContextHelper.removeSuffixFromHostname(frlpcHostname, ".cms");
frlpcHostname = ContextHelper.removeNetworkSuffix(frlpcHostname);

StringBuilder sb = new StringBuilder(prefix.length() + fedBuilderName.length() + delimiter.length() + ttcpName.length() + delimiter.length() + frlpcHostname.length());

Expand Down Expand Up @@ -707,7 +707,7 @@ public String generateId(Object forPojo) {
String frlGeoslot = String.valueOf(frl.getGeoSlot());

String frlpcHostname = frl.getFrlPc().getHostname();
frlpcHostname = ContextHelper.removeSuffixFromHostname(frlpcHostname, ".cms");
frlpcHostname = ContextHelper.removeNetworkSuffix(frlpcHostname);

StringBuilder sb = new StringBuilder(prefix.length() + frlGeoslot.length() + delimiter.length() + frlpcHostname.length());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public String generateId(Object forPojo) {
BU bu = (BU) forPojo;

String buHostname = bu.getHostname();
buHostname = ContextHelper.removeSuffixFromHostname(buHostname, ".cms");
buHostname = ContextHelper.removeNetworkSuffix(buHostname);

StringBuilder sb = new StringBuilder(prefix.length() + buHostname.length());

Expand Down Expand Up @@ -219,7 +219,7 @@ public String generateId(Object forPojo) {
RU ru = (RU) forPojo;

String ruHostname = ru.getHostname();
ruHostname = ContextHelper.removeSuffixFromHostname(ruHostname, ".cms");
ruHostname = ContextHelper.removeNetworkSuffix(ruHostname);

StringBuilder sb = new StringBuilder(prefix.length() + ruHostname.length());

Expand Down Expand Up @@ -272,7 +272,7 @@ public String generateId(Object forPojo) {
FRLPc frlpc = (FRLPc) forPojo;

String frlpcHostname = frlpc.getHostname();
frlpcHostname = ContextHelper.removeSuffixFromHostname(frlpcHostname, ".cms");
frlpcHostname = ContextHelper.removeNetworkSuffix(frlpcHostname);

StringBuilder sb = new StringBuilder(prefix.length() + frlpcHostname.length());

Expand Down Expand Up @@ -533,7 +533,7 @@ public String generateId(Object forPojo) {
FMMApplication fmmapp = (FMMApplication) forPojo;

String fmmappHostname = fmmapp.getHostname();
fmmappHostname = ContextHelper.removeSuffixFromHostname(fmmappHostname, ".cms");
fmmappHostname = ContextHelper.removeNetworkSuffix(fmmappHostname);

StringBuilder sb = new StringBuilder(prefix.length() + fmmappHostname.length());

Expand Down Expand Up @@ -643,7 +643,7 @@ public String generateId(Object forPojo) {
String fedBuilderName = sfb.getFedBuilder().getName();
String ttcpName = sfb.getTtcPartition().getName();
String frlpcHostname = sfb.getFrlPc() != null ? sfb.getFrlPc().getHostname() : "-";
frlpcHostname = ContextHelper.removeSuffixFromHostname(frlpcHostname, ".cms");
frlpcHostname = ContextHelper.removeNetworkSuffix(frlpcHostname);

StringBuilder sb = new StringBuilder(prefix.length() + fedBuilderName.length() + delimiter.length() + ttcpName.length() + delimiter.length() + frlpcHostname.length());

Expand Down Expand Up @@ -703,7 +703,7 @@ public String generateId(Object forPojo) {
String frlGeoslot = String.valueOf(frl.getGeoSlot());

String frlpcHostname = frl.getFrlPc().getHostname();
frlpcHostname = ContextHelper.removeSuffixFromHostname(frlpcHostname, ".cms");
frlpcHostname = ContextHelper.removeNetworkSuffix(frlpcHostname);

StringBuilder sb = new StringBuilder(prefix.length() + frlGeoslot.length() + delimiter.length() + frlpcHostname.length());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import rcms.utilities.daqaggregator.data.TCDSPartitionInfo;
import rcms.utilities.daqaggregator.data.TTCPartition;
import rcms.utilities.daqaggregator.datasource.TCDSFMInfoRetriever;
import rcms.utilities.daqaggregator.mappers.helper.ContextHelper;
import rcms.utilities.hwcfg.HardwareConfigurationException;
import rcms.utilities.hwcfg.dp.DAQPartition;
import rcms.utilities.hwcfg.dp.DAQPartitionStructureExtractor.HalfFMM;
Expand Down Expand Up @@ -385,6 +386,8 @@ private TCDSPartitionInfo getTCDSInfo(DAQPartition dp, String ttcpName) {

TCDSPartitionInfo tcdsPartitionInfo = new TCDSPartitionInfo();

final String networkSuffix = ContextHelper.getNetworkSuffix();

if (ttcpName.toLowerCase().startsWith("cpm")||
ttcpName.toLowerCase().startsWith("lpm")
||ttcpName.toLowerCase().startsWith("dvcpm")||
Expand All @@ -398,7 +401,7 @@ private TCDSPartitionInfo getTCDSInfo(DAQPartition dp, String ttcpName) {

if(tcdsFmInfoRetriever.isInfoAvailable()){
String pmUrl = tcdsFmInfoRetriever.getTcdsfm_pmContext().toLowerCase();
pmUrl = pmUrl.split("//|.cms")[1];
pmUrl = pmUrl.split("//|" + networkSuffix)[1];

if (!pmUrl.endsWith("-pri")){
//hack to make it work before the suffix integration in tcdsfm and also afterwards
Expand All @@ -414,7 +417,7 @@ private TCDSPartitionInfo getTCDSInfo(DAQPartition dp, String ttcpName) {
for (Entry<Integer, TCDSPartitionManager> ePm: eTrig.getValue().getPMs().entrySet()){

String hwcfg_PmHostname = ePm.getValue().getHostName().toLowerCase();
hwcfg_PmHostname = hwcfg_PmHostname.split(".cms")[0];
hwcfg_PmHostname = hwcfg_PmHostname.split(networkSuffix)[0];
String hwcfg_pmService = ePm.getValue().getServiceName().toLowerCase();

if (pmUrl.equalsIgnoreCase(hwcfg_PmHostname)&&pmService.equalsIgnoreCase(hwcfg_pmService)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class ContextHelper {

private static final Logger logger = Logger.getLogger(ContextHelper.class);

/** network suffix including dot at the beginning */
private static String networkSuffix = null;

public static Integer getPortFromContext(String context) {
String hostname = new String(context);
String portString;
Expand Down Expand Up @@ -44,8 +47,8 @@ public static String getHostnameFromContext(String context) {
if (hostname.contains(":")) {
hostname = hostname.substring(0, hostname.indexOf(":"));
}
if (!hostname.endsWith(".cms")) {
hostname = hostname + ".cms";
if (!hostname.endsWith(networkSuffix)) {
hostname = hostname + networkSuffix;
}
return hostname;
}
Expand Down Expand Up @@ -74,4 +77,30 @@ public static String removeSuffixFromHostname(String hostname, String suffix) {
}

}

/** checks if the given host name ends with the network domain
* (which is configured application wide) and if yes, removes
* it. Otherwise returns the hostname unchanged.
*/
public static String removeNetworkSuffix(String hostname) {
return removeSuffixFromHostname(hostname, networkSuffix);
}

/** @return the network suffix including the leading dot. */
public static String getNetworkSuffix() {
return networkSuffix;
}

public static void setNetworkSuffix(String networkSuffix) {

// ensure lower case
networkSuffix = networkSuffix.toLowerCase();

if (! networkSuffix.startsWith(".")) {
networkSuffix = "." + networkSuffix;
}

ContextHelper.networkSuffix = networkSuffix;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import rcms.utilities.daqaggregator.data.TCDSTriggerRates;
import rcms.utilities.daqaggregator.mappers.MappingManager;
import rcms.utilities.daqaggregator.mappers.MappingReporter;
import rcms.utilities.daqaggregator.mappers.helper.ContextHelper;
import rcms.utilities.daqaggregator.persistence.PersistenceFormat;
import rcms.utilities.hwcfg.HardwareConfigurationException;
import rcms.utilities.hwcfg.InvalidNodeTypeException;
Expand Down Expand Up @@ -83,6 +84,8 @@ private DAQ runDispatch(String flashlistDir, boolean forceIgnoreAutomaticSession
String filter1 = prop.getProperty(Settings.SESSION_L0FILTER1.getKey());
String filter2 = prop.getProperty(Settings.SESSION_L0FILTER2.getKey());

ContextHelper.setNetworkSuffix(prop.getProperty(Settings.NETWORK_DOMAIN.getKey()));

// connect to the hardware database
hardwareConnector.initialize(prop);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
package rcms.utilities.daqaggregator.mappers.helper;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class ContextHelperTest {

@BeforeClass
public static void setup() {
ContextHelper.setNetworkSuffix(".tld");
}

@Test
public void hostnameSimpleTest() {
String actual = ContextHelper.getHostnameFromContext("abc.cms:123");
Assert.assertEquals("abc.cms", actual);
String actual = ContextHelper.getHostnameFromContext("abc.tld:123");
Assert.assertEquals("abc.tld", actual);
}

@Test
public void hostnameProtocolHttpTest() {
String actual = ContextHelper.getHostnameFromContext("http://abc.cms:123");
Assert.assertEquals("abc.cms", actual);
String actual = ContextHelper.getHostnameFromContext("http://abc.tld:123");
Assert.assertEquals("abc.tld", actual);
}

@Test
public void hostnameProtocolHttpsTest() {
String actual = ContextHelper.getHostnameFromContext("https://abc.cms:123");
Assert.assertEquals("abc.cms", actual);
String actual = ContextHelper.getHostnameFromContext("https://abc.tld:123");
Assert.assertEquals("abc.tld", actual);
}

@Test
public void portTest() {
int actual = ContextHelper.getPortFromContext("https://abc.cms:123");
int actual = ContextHelper.getPortFromContext("https://abc.tld:123");
Assert.assertEquals(123, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.BeforeClass;

import rcms.utilities.daqaggregator.data.FED;
import rcms.utilities.daqaggregator.data.FMM;
import rcms.utilities.daqaggregator.data.FMMApplication;
import rcms.utilities.daqaggregator.datasource.Flashlist;
import rcms.utilities.daqaggregator.datasource.FlashlistType;
import rcms.utilities.daqaggregator.mappers.helper.ContextHelper;

public class TcdsTtsPiMatcherTest {

final JsonNodeFactory factory = JsonNodeFactory.instance;

@BeforeClass
public static void setup() {
ContextHelper.setNetworkSuffix(".tld");
}

@Test
public void testNonSessionContextFlaslhist() {

Expand All @@ -31,8 +38,8 @@ public void testNonSessionContextFlaslhist() {
ArrayNode rowsNode = factory.arrayNode();
Collection<FED> objects = new ArrayList<>();

appendTestDataToFlashlist(1, rowsNode, "http://a.cms:1000", "service1", 1);
objects.add(generateTestFed(1, "a.cms", 1000, "service1", 1));
appendTestDataToFlashlist(1, rowsNode, "http://a.tld:1000", "service1", 1);
objects.add(generateTestFed(1, "a.tld", 1000, "service1", 1));

testFlashlist.setRowsNode(rowsNode);
Map<FED, JsonNode> a = sut.match(testFlashlist, objects);
Expand Down
Loading