Skip to content

Commit 9d9be2e

Browse files
committed
add hosting migration. json now in engagement folder. add region capability to artifacts
1 parent 45aef62 commit 9d9be2e

File tree

9 files changed

+190
-21
lines changed

9 files changed

+190
-21
lines changed

src/main/java/com/redhat/labs/lodestar/models/Artifact.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ public class Artifact extends EngagementAttribute {
1717
private String description;
1818
private String type;
1919
private String linkAddress;
20+
private String region; //migration support - not available in v1
2021

2122
}

src/main/java/com/redhat/labs/lodestar/resource/MigrationResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public class MigrationResource {
2525
@Timed(name = "performedMigration", description = "How much time it takes to migrate", unit = MetricUnits.MILLISECONDS)
2626
public Response migrate(@QueryParam(value = "participants") boolean migrateParticipants,
2727
@QueryParam(value = "artifacts") boolean migrateArtifacts,
28-
@QueryParam(value = "uuids") boolean migrateUuids) {
28+
@QueryParam(value = "uuids") boolean migrateUuids, @QueryParam(value = "hosting") boolean migrateHosting) {
2929

30-
migrationService.migrate(migrateUuids, migrateParticipants, migrateArtifacts);
30+
migrationService.migrate(migrateUuids, migrateParticipants, migrateArtifacts, migrateHosting);
3131

3232
return Response.ok().build();
3333

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Optional;
88

99
import javax.enterprise.context.ApplicationScoped;
10-
import javax.enterprise.event.Observes;
1110
import javax.inject.Inject;
1211

1312
import org.eclipse.microprofile.config.inject.ConfigProperty;
@@ -18,17 +17,18 @@
1817
import com.redhat.labs.lodestar.models.Artifact;
1918
import com.redhat.labs.lodestar.models.Engagement;
2019
import com.redhat.labs.lodestar.models.EngagementUser;
20+
import com.redhat.labs.lodestar.models.HostingEnvironment;
2121
import com.redhat.labs.lodestar.models.gitlab.File;
2222
import com.redhat.labs.lodestar.models.gitlab.Project;
2323

24-
import io.quarkus.runtime.StartupEvent;
25-
2624
@ApplicationScoped
2725
public class MigrationService {
2826
private static final Logger LOGGER = LoggerFactory.getLogger(MigrationService.class);
2927

30-
private static final String PARTICIPANT_JSON = "participants.json";
31-
private static final String ARTIFACT_JSON = "artifacts.json";
28+
private static final String ENGAGEMENT_DIR = "engagement/";
29+
private static final String PARTICIPANT_JSON = ENGAGEMENT_DIR + "participants.json";
30+
private static final String ARTIFACT_JSON = ENGAGEMENT_DIR + "artifacts.json";
31+
private static final String HOSTING_JSON = ENGAGEMENT_DIR + "hosting.json";
3232

3333
@Inject
3434
EngagementService engagementService;
@@ -60,7 +60,7 @@ public class MigrationService {
6060
* The migration is idempotent so no harm in rerunning. It will only update
6161
* engagements that haven't been migrated.
6262
*/
63-
public void migrate(boolean migrateUuids, boolean migrateParticipants, boolean migrateArtifacts) {
63+
public void migrate(boolean migrateUuids, boolean migrateParticipants, boolean migrateArtifacts, boolean migrateHosting) {
6464
if(migrateUuids) {
6565
LOGGER.info("Start Migrate uuids: {}", migrateUuids);
6666
migrateUuids();
@@ -78,6 +78,12 @@ public void migrate(boolean migrateUuids, boolean migrateParticipants, boolean m
7878
migrateArtifacts();
7979
LOGGER.info("End Migrate artifacts");
8080
}
81+
82+
if(migrateHosting) {
83+
LOGGER.info("Start Migrate hosting");
84+
migrateHosting();
85+
LOGGER.info("End Migrate hosting");
86+
}
8187
}
8288

8389
/**
@@ -120,11 +126,17 @@ private void migrateArtifacts() {
120126

121127
private void migrateArtifactsToGitlab(Engagement engagement) {
122128
List<Artifact> artifacts = engagement.getArtifacts() == null ? Collections.emptyList() : engagement.getArtifacts();
129+
artifacts.forEach(a -> a.setRegion(engagement.getRegion()));
123130
String content = json.toJson(artifacts);
131+
LOGGER.debug(content);
124132
migrateToGitlab(engagement, content, ARTIFACT_JSON, artifacts.size());
125133

126134
}
127135

136+
private void migrateHosting() {
137+
getAllEngagements().values().parallelStream().forEach(this::migrateHostingToGitlab);
138+
}
139+
128140
/**
129141
* Get All engagements. This is run by migrate users and uuids so only run once if both are active
130142
* @return
@@ -160,6 +172,12 @@ private void migrateParticipantsToGitlab(Engagement engagement) {
160172
migrateToGitlab(engagement, content, PARTICIPANT_JSON, participants.size());
161173
}
162174

175+
private void migrateHostingToGitlab(Engagement engagement) {
176+
List<HostingEnvironment> hosting = engagement.getHostingEnvironments() == null ? Collections.emptyList() : engagement.getHostingEnvironments();
177+
String content = json.toJson(hosting);
178+
migrateToGitlab(engagement, content, HOSTING_JSON, hosting.size());
179+
}
180+
163181
/**
164182
* This will write the user json to gitlab. Should you wish to rollback or redo you could add this code
165183
* fileService.deleteFile(engagement.getProjectId(), userJson);
3.59 KB
Loading
15 KB
Binary file not shown.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="icon" href="/favicon.ico"/>
6+
<title>Lodestar Participants - 1.0.0-SNAPSHOT</title>
7+
<style>
8+
h1, h2, h3, h4, h5, h6 {
9+
margin-bottom: 0.5rem;
10+
font-weight: 400;
11+
line-height: 1.5;
12+
}
13+
14+
h1 {
15+
font-size: 2.5rem;
16+
}
17+
18+
h2 {
19+
font-size: 2rem
20+
}
21+
22+
h3 {
23+
font-size: 1.75rem
24+
25+
}
26+
27+
h4 {
28+
font-size: 1.5rem
29+
}
30+
31+
h5 {
32+
font-size: 1.25rem
33+
}
34+
35+
h6 {
36+
font-size: 1rem
37+
}
38+
39+
.lead {
40+
font-weight: 300;
41+
font-size: 2rem;
42+
}
43+
44+
.banner {
45+
font-size: 2.7rem;
46+
margin: 0;
47+
padding: 2rem 1rem;
48+
background-color: #0d1c2c;
49+
color: white;
50+
}
51+
52+
body {
53+
margin: 0;
54+
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
55+
}
56+
57+
code {
58+
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
59+
font-size: 87.5%;
60+
color: #e83e8c;
61+
word-break: break-word;
62+
}
63+
64+
.left-column {
65+
padding: .75rem;
66+
max-width: 75%;
67+
min-width: 55%;
68+
}
69+
70+
.right-column {
71+
padding: .75rem;
72+
max-width: 25%;
73+
}
74+
75+
.container {
76+
display: flex;
77+
width: 100%;
78+
}
79+
80+
li {
81+
margin: 0.75rem;
82+
}
83+
84+
.right-section {
85+
margin-left: 1rem;
86+
padding-left: 0.5rem;
87+
}
88+
89+
.right-section h3 {
90+
padding-top: 0;
91+
font-weight: 200;
92+
}
93+
94+
.right-section ul {
95+
border-left: 0.3rem solid #71aeef;
96+
list-style-type: none;
97+
padding-left: 0;
98+
}
99+
100+
.example-code {
101+
border-left: 0.3rem solid #71aeef;
102+
padding-left: 10px;
103+
}
104+
105+
.example-code h3 {
106+
font-weight: 200;
107+
}
108+
</style>
109+
</head>
110+
<body>
111+
112+
<div class="banner lead">
113+
LodeStar Participants API
114+
</div>
115+
116+
<div class="container">
117+
<div class="left-column">
118+
<p class="lead"> This provides api endpoints for LodeStar to communicate with git for all engagement info.</p>
119+
120+
<ul>
121+
<li><a href="/q/swagger-ui/">Swagger UI</a> </li>
122+
<li>Quarkus now ships with a <a href="/q/dev/">Dev UI</a> (available in dev mode only)</li>
123+
</ul>
124+
125+
</div>
126+
<div class="right-column">
127+
<div class="right-section">
128+
<h3>Application</h3>
129+
<ul>
130+
<li>GroupId: <code>com.redhat.labs.lodestar</code></li>
131+
<li>ArtifactId: <code>lodestar-participants</code></li>
132+
<li>Version: <code>1.0.0-SNAPSHOT</code></li>
133+
<li>Quarkus Version: <code>1.13.7.Final</code></li>
134+
</ul>
135+
</div>
136+
<div class="right-section">
137+
<h3>Selected extensions guides</h3>
138+
<ul>
139+
<li title="REST endpoint framework implementing JAX-RS and more"><a href="https://quarkus.io/guides/rest-json" target="_blank">RESTEasy JAX-RS guide</a></li>
140+
</ul>
141+
</div>
142+
</div>
143+
</div>
144+
</body>
145+
</html>

src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ commit.default.author=Otto Mayshin
3737
commit.default.branch=master
3838
config.reload=${CONFIG_RELOAD:false}
3939

40+
mp.openapi.extensions.smallrye.info.title=LodeStar Git API
41+
mp.openapi.extensions.smallrye.info.version=${GIT_API_GIT_COMMIT:1.0}
42+
quarkus.swagger-ui.theme=flattop
4043

4144
# engagements
4245
engagements.repository.id=${ENGAGEMENTS_REPOSITORY_ID:2}

src/test/java/com/redhat/labs/lodestar/resource/MigrationResourceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class MigrationResourceTest {
1212
void testGetHookFileSuccess() {
1313

1414
given().when().put("/api/migrate").then().statusCode(200);
15-
given().queryParam("participants", true).queryParam("uuid", true).queryParam("artifacts", true).when()
16-
.put("/api/migrate").then().statusCode(200);
15+
given().queryParam("participants", true).queryParam("uuid", true).queryParam("artifacts", true)
16+
.queryParam("hosting", true).when().put("/api/migrate").then().statusCode(200);
1717
}
1818
}

src/test/java/com/redhat/labs/lodestar/service/MigrationServiceTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class MigrationServiceTest {
2525
@Inject
2626
MigrationService migrationService;
2727

28-
static ProjectService mockPS;
28+
static ProjectService projectServiceMock;
2929

3030
static FileService fileServiceMock;
3131

@@ -60,12 +60,13 @@ public static void setup() {
6060
e = Engagement.builder().uuid("d4").projectId(4).engagementUsers(engagementUsers).artifacts(artifacts).build();
6161
allEngagements.add(e);
6262

63-
mockPS = Mockito.mock(ProjectService.class);
64-
Mockito.when(mockPS.getProjectsByGroup(2, true)).thenReturn(projects);
65-
QuarkusMock.installMockForType(mockPS, ProjectService.class);
63+
projectServiceMock = Mockito.mock(ProjectService.class);
64+
Mockito.when(projectServiceMock.getProjectsByGroup(2, true)).thenReturn(projects);
65+
QuarkusMock.installMockForType(projectServiceMock, ProjectService.class);
6666

6767
fileServiceMock = Mockito.mock(FileService.class);
68-
Mockito.when(fileServiceMock.getFile(4, "participants.json")).thenReturn(Optional.of(File.builder().build()));
68+
Mockito.when(fileServiceMock.getFile(4, "engagement/participants.json")).thenReturn(Optional.of(File.builder().build()));
69+
Mockito.when(fileServiceMock.getFile(4, "engagement/hosting.json")).thenReturn(Optional.of(File.builder().build()));
6970
QuarkusMock.installMockForType(fileServiceMock, FileService.class);
7071

7172
EngagementService mockES = Mockito.mock(EngagementService.class);
@@ -75,15 +76,16 @@ public static void setup() {
7576

7677
@Test
7778
void migrate() {
78-
migrationService.migrate(false, false, false);
79+
migrationService.migrate(false, false, false, false);
7980

80-
Mockito.verify(mockPS, Mockito.never()).updateProject(Mockito.any());
81-
Mockito.verify(fileServiceMock, Mockito.never()).createFile(Mockito.anyInt(), Mockito.eq("participants.json"), Mockito.any(File.class));
81+
Mockito.verify(projectServiceMock, Mockito.never()).updateProject(Mockito.any());
82+
Mockito.verify(fileServiceMock, Mockito.never()).createFile(Mockito.anyInt(), Mockito.eq("engagement/participants.json"), Mockito.any(File.class));
8283

83-
migrationService.migrate(true, true, true);
84+
migrationService.migrate(true, true, true, true);
8485

85-
Mockito.verify(mockPS, Mockito.times(2)).updateProject(Mockito.any());
86-
Mockito.verify(fileServiceMock, Mockito.times(2)).createFile(Mockito.anyInt(), Mockito.eq("participants.json"), Mockito.any(File.class));
86+
Mockito.verify(projectServiceMock, Mockito.times(2)).updateProject(Mockito.any());
87+
Mockito.verify(fileServiceMock, Mockito.times(2)).createFile(Mockito.anyInt(), Mockito.eq("engagement/hosting.json"), Mockito.any(File.class));
88+
Mockito.verify(fileServiceMock, Mockito.times(2)).createFile(Mockito.anyInt(), Mockito.eq("engagement/participants.json"), Mockito.any(File.class));
8789
}
8890

8991

0 commit comments

Comments
 (0)