Skip to content

Commit e21ba4f

Browse files
committed
reload and add engagement uuid
1 parent d954aba commit e21ba4f

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

deployment/values-dev.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ git:
1414
ref: master
1515

1616
db:
17-
mongodbServiceName: lodestar-backend-mongodb
17+
mongodbServiceName: lodestar-artifacts-mongodb
1818
mongodbUser: mongouser
1919
mongodbPassword: mongopassword
20-
mongodbDatabase: engagements
20+
mongodbDatabase: artifacts
2121
mongodbAdminPassword: mongoadminpassword
2222

2323
api:

src/main/java/com/redhat/labs/lodestar/service/ArtifactService.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,7 @@ public void purge() {
8080
* and inserts into the database.
8181
*/
8282
public void refresh() {
83-
84-
engagementRestClient.getAllEngagementProjects().stream().map(Engagement::getProjectId)
85-
.map(this::getArtifactsFromGitlabByProjectId).flatMap(Collection::stream)
86-
.forEach(a -> {
87-
88-
// set uuid if missing
89-
if (null == a.getUuid()) {
90-
a.setUuid(UUID.randomUUID().toString());
91-
}
92-
93-
// persist the artifact
94-
createOrUpdateArtifact(a);
95-
96-
});
97-
83+
engagementRestClient.getAllEngagementProjects().parallelStream().forEach(this::reloadFromGitlabByEngagement);
9884
}
9985

10086
/**
@@ -105,22 +91,38 @@ public void refresh() {
10591
* @param projectId
10692
* @return
10793
*/
108-
List<Artifact> getArtifactsFromGitlabByProjectId(long projectId) {
94+
void reloadFromGitlabByEngagement(Engagement engagement) {
95+
if(engagement.getUuid() == null) {
96+
LOGGER.error("Engagement found with no uuid. Check description of project {}", engagement.getProjectId());
97+
return;
98+
}
99+
109100
try {
110-
File file = gitlabRestClient.getFile(projectId, artifactsFile, defaultBranch);
101+
File file = gitlabRestClient.getFile(engagement.getProjectId(), artifactsFile, defaultBranch);
111102
if(null == file.getContent() || file.getContent().isBlank()) {
112-
LOGGER.error("NO FILE DATA FROM GITLAB FOR PROJECT {}. THIS SHALL NOT STAND", projectId);
113-
return Collections.emptyList();
103+
LOGGER.error("IMPOSSIBLE. NO FILE DATA FROM GITLAB FOR PROJECT {}. THIS SHALL NOT STAND", engagement.getProjectId());
104+
return;
114105
}
115106

116107
file.decodeFileAttributes();
117-
return Arrays.asList(jsonb.fromJson(file.getContent(), Artifact[].class));
108+
List<Artifact> artifacts = Arrays.asList(jsonb.fromJson(file.getContent(), Artifact[].class));
109+
110+
artifacts.forEach(a -> {
111+
a.setEngagementUuid(engagement.getUuid());
112+
// set uuid if missing
113+
if (null == a.getUuid()) {
114+
a.setUuid(UUID.randomUUID().toString());
115+
}
116+
117+
// persist the artifact
118+
createOrUpdateArtifact(a);
119+
});
118120

119121
} catch(WebApplicationException wae) {
120122
if(wae.getResponse().getStatus() != 404) {
121123
throw wae;
122124
}
123-
return Collections.emptyList();
125+
LOGGER.error("NO FILE DATA FROM GITLAB FOR PROJECT {}. THIS SHALL NOT STAND", engagement.getProjectId());
124126
}
125127
}
126128

0 commit comments

Comments
 (0)