Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Set overrides in DSS as a single property, refactor code for submitting runs #654

Merged
merged 6 commits into from
Oct 7, 2024
Merged
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
@@ -14,14 +14,13 @@
import java.time.temporal.ChronoUnit;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Map.Entry;

import javax.validation.constraints.NotNull;

import dev.galasa.ResultArchiveStoreContentType;
import dev.galasa.framework.beans.Property;
import dev.galasa.framework.internal.runner.ITestRunnerEventsProducer;
import dev.galasa.framework.spi.AbstractManager;
import dev.galasa.framework.spi.ConfigurationPropertyStoreException;
import dev.galasa.framework.spi.DynamicStatusStoreException;
import dev.galasa.framework.spi.FrameworkException;
import dev.galasa.framework.spi.IConfigurationPropertyStoreService;
@@ -33,6 +32,7 @@
import dev.galasa.framework.spi.ResultArchiveStoreException;
import dev.galasa.framework.spi.teststructure.TestStructure;
import dev.galasa.framework.spi.utils.DssUtils;
import dev.galasa.framework.spi.utils.GalasaGson;

public class BaseTestRunner {

@@ -61,6 +61,8 @@ public class BaseTestRunner {

protected Properties overrideProperties;

private static final GalasaGson gson = new GalasaGson();

protected void init(ITestRunnerDataProvider dataProvider) throws TestRunException {
this.run = dataProvider.getRun() ;
this.framework = dataProvider.getFramework();
@@ -166,12 +168,15 @@ private void loadOverrideProperties(Properties overrideProperties,
IDynamicStatusStoreService dss) throws TestRunException {
//*** Load the overrides if present
try {
String prefix = "run." + run.getName() + ".override.";
Map<String, String> runOverrides = dss.getPrefix(prefix);
for(Entry<String, String> entry : runOverrides.entrySet()) {
String key = entry.getKey().substring(prefix.length());
String value = entry.getValue();
overrideProperties.put(key, value);
// The overrides DSS property contains a JSON array of overrides in the form:
// dss.framework.run.X.overrides=[{ "key1": "value1" }, { "key2", "value2" }]
String runOverridesProp = "run." + run.getName() + ".overrides";
String runOverrides = dss.get(runOverridesProp);
if (runOverrides != null && !runOverrides.isBlank()) {
Property[] properties = gson.fromJson(runOverrides, Property[].class);
for (Property override : properties) {
overrideProperties.put(override.getKey(), override.getValue());
}
}
} catch(Exception e) {
throw new TestRunException("Problem loading overrides from the run properties", e);
Original file line number Diff line number Diff line change
@@ -8,13 +8,15 @@
import java.io.IOException;
import java.net.*;
import java.util.*;
import java.util.Map.Entry;
import java.nio.file.*;
import javax.validation.constraints.NotNull;
import org.apache.commons.logging.*;
import org.osgi.framework.*;

import dev.galasa.framework.beans.Property;
import dev.galasa.framework.spi.*;
import dev.galasa.framework.spi.creds.*;
import dev.galasa.framework.spi.utils.GalasaGson;

public class FrameworkInitialisation implements IFrameworkInitialisation {

@@ -35,6 +37,7 @@ public class FrameworkInitialisation implements IFrameworkInitialisation {

private String galasaHome;

private static final GalasaGson gson = new GalasaGson();

public FrameworkInitialisation(
Properties bootstrapProperties,
@@ -144,18 +147,24 @@ public FrameworkInitialisation(
// *** If this is a test run, add the overrides from the run dss properties to
// these overrides
if (testrun) {
String prefix = "run." + framework.getTestRunName() + ".override.";
int len = prefix.length();
loadOverridePropertiesFromDss(overrideProperties);
}
}

Map<String, String> runOverrides = this.dssFramework.getPrefix(prefix);
for (Entry<String, String> override : runOverrides.entrySet()) {
String key = override.getKey().substring(len);
private void loadOverridePropertiesFromDss(Properties overrideProperties) throws DynamicStatusStoreException {
// The overrides DSS property contains a JSON array of overrides in the form:
// dss.framework.run.X.overrides=[{ "key1": "value1" }, { "key2", "value2" }]
String runOverridesProp = "run." + framework.getTestRunName() + ".overrides";
String runOverrides = this.dssFramework.get(runOverridesProp);
if (runOverrides != null && !runOverrides.isBlank()) {
Property[] properties = gson.fromJson(runOverrides, Property[].class);
for (Property override : properties) {
String key = override.getKey();
String value = override.getValue();

if (logger.isTraceEnabled()) {
logger.trace("Setting run override " + key + "=" + value);
}
overrideProperties.put(override.getKey(), override.getValue());
overrideProperties.put(key, value);
}
}
}
Loading