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

Commit

Permalink
Stop loading artifacts when deleting runs, fix potential NullPointerE…
Browse files Browse the repository at this point in the history
…xception (#271)

* Stop loading artifacts when deleting runs, fix potential NPE when discarding runs, unit tests

Signed-off-by: Eamonn Mansour <[email protected]>

* Disable gradle cache

Signed-off-by: Eamonn Mansour <[email protected]>

---------

Signed-off-by: Eamonn Mansour <[email protected]>
  • Loading branch information
eamansour authored Sep 10, 2024
1 parent dd63250 commit 57fa314
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.9
cache-disabled: true

- name: Build Extensions source code with gradle
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private Path getRunArtifactPath(TestStructureCouchdb ts) throws CouchdbRasExcept

ArrayList<IRunResult> runs = new ArrayList<>();

HttpGet httpGet = requestFactory.getHttpGetRequest(store.getCouchdbUri() + "/galasa_run/_all_docs");
HttpGet httpGet = requestFactory.getHttpGetRequest(store.getCouchdbUri() + "/" + CouchdbRasStore.RUNS_DB + "/_all_docs");

try (CloseableHttpResponse response = store.getHttpClient().execute(httpGet)) {
StatusLine statusLine = response.getStatusLine();
Expand Down Expand Up @@ -183,8 +183,19 @@ private Path getRunArtifactPath(TestStructureCouchdb ts) throws CouchdbRasExcept
return runs;
}

private CouchdbRunResult fetchRun(String id) throws ParseException, IOException, CouchdbRasException {
HttpGet httpGet = requestFactory.getHttpGetRequest(store.getCouchdbUri() + "/galasa_run/" + id);
private CouchdbRunResult fetchRun(String id) throws ParseException, IOException, ResultArchiveStoreException {
CouchdbRunResult runResult = fetchRunWithoutArtifacts(id);
TestStructureCouchdb testStructure = (TestStructureCouchdb) runResult.getTestStructure();

// Populate the run's artifacts filesystem
Path runArtifactPath = getRunArtifactPath(testStructure);

runResult = new CouchdbRunResult(store, testStructure, runArtifactPath);
return runResult;
}

private CouchdbRunResult fetchRunWithoutArtifacts(String id) throws ParseException, IOException, CouchdbRasException {
HttpGet httpGet = requestFactory.getHttpGetRequest(store.getCouchdbUri() + "/" + CouchdbRasStore.RUNS_DB + "/" + id);

try (CloseableHttpResponse response = store.getHttpClient().execute(httpGet)) {
StatusLine statusLine = response.getStatusLine();
Expand All @@ -196,10 +207,8 @@ private CouchdbRunResult fetchRun(String id) throws ParseException, IOException,
String responseEntity = EntityUtils.toString(entity);
TestStructureCouchdb ts = store.getGson().fromJson(responseEntity, TestStructureCouchdb.class);

Path runArtifactPath = getRunArtifactPath(ts);

// *** Add this run to the results
CouchdbRunResult cdbrr = new CouchdbRunResult(store, ts, runArtifactPath);
CouchdbRunResult cdbrr = new CouchdbRunResult(store, ts, createFileSystemProvider().getRoot());
return cdbrr;
}
}
Expand All @@ -209,7 +218,7 @@ private CouchdbRunResult fetchRun(String id) throws ParseException, IOException,
ArrayList<String> requestors = new ArrayList<>();

HttpGet httpGet = requestFactory.getHttpGetRequest(
store.getCouchdbUri() + "/galasa_run/_design/docs/_view/requestors-view?group=true");
store.getCouchdbUri() + "/" + CouchdbRasStore.RUNS_DB + "/_design/docs/_view/requestors-view?group=true");

try (CloseableHttpResponse response = store.getHttpClient().execute(httpGet)) {
StatusLine statusLine = response.getStatusLine();
Expand Down Expand Up @@ -241,7 +250,7 @@ private CouchdbRunResult fetchRun(String id) throws ParseException, IOException,
ArrayList<String> results = new ArrayList<>();

HttpGet httpGet = requestFactory.getHttpGetRequest(
store.getCouchdbUri() + "/galasa_run/_design/docs/_view/result-view?group=true");
store.getCouchdbUri() + "/" + CouchdbRasStore.RUNS_DB + "/_design/docs/_view/result-view?group=true");

try (CloseableHttpResponse response = store.getHttpClient().execute(httpGet)) {
StatusLine statusLine = response.getStatusLine();
Expand Down Expand Up @@ -278,7 +287,7 @@ private CouchdbRunResult fetchRun(String id) throws ParseException, IOException,
ArrayList<RasTestClass> tests = new ArrayList<>();

HttpGet httpGet = requestFactory.getHttpGetRequest(
store.getCouchdbUri() + "/galasa_run/_design/docs/_view/bundle-testnames-view?group=true");
store.getCouchdbUri() + "/" + CouchdbRasStore.RUNS_DB + "/_design/docs/_view/bundle-testnames-view?group=true");

try (CloseableHttpResponse response = store.getHttpClient().execute(httpGet)) {
StatusLine statusLine = response.getStatusLine();
Expand Down Expand Up @@ -326,7 +335,7 @@ private CouchdbRunResult fetchRun(String id) throws ParseException, IOException,
public @NotNull RasRunResultPage getRunsPage(int maxResults, RasSortField primarySort, String pageToken, @NotNull IRasSearchCriteria... searchCriterias)
throws ResultArchiveStoreException {

HttpPost httpPost = requestFactory.getHttpPostRequest(store.getCouchdbUri() + "/galasa_run/_find");
HttpPost httpPost = requestFactory.getHttpPostRequest(store.getCouchdbUri() + "/" + CouchdbRasStore.RUNS_DB + "/_find");

Find find = new Find();
find.selector = buildGetRunsQuery(searchCriterias);
Expand Down Expand Up @@ -409,7 +418,7 @@ private JsonArray buildQuerySortJson(@NotNull RasSortField primarySort) {

ArrayList<IRunResult> runs = new ArrayList<>();

HttpPost httpPost = requestFactory.getHttpPostRequest(store.getCouchdbUri() + "/galasa_run/_find");
HttpPost httpPost = requestFactory.getHttpPostRequest(store.getCouchdbUri() + "/" + CouchdbRasStore.RUNS_DB + "/_find");

Find find = new Find();
find.selector = buildGetRunsQuery(searchCriterias);
Expand All @@ -435,35 +444,43 @@ private JsonArray buildQuerySortJson(@NotNull RasSortField primarySort) {

public void discardRun(String id) throws ResultArchiveStoreException {
try {
CouchdbRunResult run = fetchRun(id);
TestStructureCouchdb testStructure = (TestStructureCouchdb) run.getTestStructure();

discardRunLogs(testStructure.getLogRecordIds());
discardRunArtifacts(testStructure.getArtifactRecordIds());

discardRecord("galasa_run", id);
CouchdbRunResult run = fetchRunWithoutArtifacts(id);
if (run == null) {
logger.info("Run with ID " + id + " does not exist or has already been discarded");
} else {
TestStructureCouchdb testStructure = (TestStructureCouchdb) run.getTestStructure();

discardRunLogs(testStructure.getLogRecordIds());
discardRunArtifacts(testStructure.getArtifactRecordIds());

discardRecord(CouchdbRasStore.RUNS_DB, id, testStructure._rev);
}
} catch (CouchdbRasException | ParseException | IOException e) {
throw new ResultArchiveStoreException("Failed to discard run: " + id, e);
}
}

private void discardRunLogs(List<String> ids) throws ResultArchiveStoreException {
for (String id : ids) {
discardRecord("galasa_log", id);
discardRecord(CouchdbRasStore.LOG_DB, id);
}
}

private void discardRunArtifacts(List<String> ids) throws ResultArchiveStoreException {
for (String id : ids) {
discardRecord("galasa_artifacts", id);
discardRecord(CouchdbRasStore.ARTIFACTS_DB, id);
}
}

private void discardRecord(String databaseName, String id) throws ResultArchiveStoreException {
discardRecord(databaseName, id, getRevision(databaseName, id));
}

private void discardRecord(String databaseName, String id, String revision) throws ResultArchiveStoreException {
URIBuilder builder;
try {
builder = new URIBuilder(store.getCouchdbUri() + "/" + databaseName + "/" + id);
builder.addParameter("rev", getRevision(databaseName, id));
builder.addParameter("rev", revision);

HttpDelete httpDelete = requestFactory.getHttpDeleteRequest(builder.build().toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public class CouchdbRasStore extends CouchdbStore implements IResultArchiveStore
private static final String COUCHDB_AUTH_ENV_VAR = "GALASA_RAS_TOKEN";
private static final String COUCHDB_AUTH_TYPE = "Basic";

private static final String ARTIFACTS_DB = "galasa_artifacts";
private static final String RUNS_DB = "galasa_run";
private static final String LOG_DB = "galasa_log";
public static final String ARTIFACTS_DB = "galasa_artifacts";
public static final String RUNS_DB = "galasa_run";
public static final String LOG_DB = "galasa_log";

private final Log logger ;

Expand Down
Loading

0 comments on commit 57fa314

Please sign in to comment.