Skip to content

Commit

Permalink
Merge pull request #139 from mcanoy/hosting
Browse files Browse the repository at this point in the history
Hosting and Region
  • Loading branch information
mcanoy authored Aug 9, 2021
2 parents 7a6d4cc + 7d640b5 commit a472dc3
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public class Artifact extends EngagementAttribute {
private String description;
private String type;
private String linkAddress;
private String region; //migration support - not available in v1

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class EngagementUser {
private String role;

private boolean reset;
private String region;

@JsonbTransient
public boolean isReset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public class HostingEnvironment extends EngagementAttribute {
private String environmentName;

private String ocpClusterSize;

private String region;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class MigrationResource {
@Timed(name = "performedMigration", description = "How much time it takes to migrate", unit = MetricUnits.MILLISECONDS)
public Response migrate(@QueryParam(value = "participants") boolean migrateParticipants,
@QueryParam(value = "artifacts") boolean migrateArtifacts,
@QueryParam(value = "uuids") boolean migrateUuids) {
@QueryParam(value = "uuids") boolean migrateUuids, @QueryParam(value = "hosting") boolean migrateHosting) {

migrationService.migrate(migrateUuids, migrateParticipants, migrateArtifacts);
migrationService.migrate(migrateUuids, migrateParticipants, migrateArtifacts, migrateHosting);

return Response.ok().build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Optional;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;
Expand All @@ -18,17 +17,18 @@
import com.redhat.labs.lodestar.models.Artifact;
import com.redhat.labs.lodestar.models.Engagement;
import com.redhat.labs.lodestar.models.EngagementUser;
import com.redhat.labs.lodestar.models.HostingEnvironment;
import com.redhat.labs.lodestar.models.gitlab.File;
import com.redhat.labs.lodestar.models.gitlab.Project;

import io.quarkus.runtime.StartupEvent;

@ApplicationScoped
public class MigrationService {
private static final Logger LOGGER = LoggerFactory.getLogger(MigrationService.class);

private static final String PARTICIPANT_JSON = "participants.json";
private static final String ARTIFACT_JSON = "artifacts.json";
private static final String ENGAGEMENT_DIR = "engagement/";
private static final String PARTICIPANT_JSON = ENGAGEMENT_DIR + "participants.json";
private static final String ARTIFACT_JSON = ENGAGEMENT_DIR + "artifacts.json";
private static final String HOSTING_JSON = ENGAGEMENT_DIR + "hosting.json";

@Inject
EngagementService engagementService;
Expand Down Expand Up @@ -60,7 +60,7 @@ public class MigrationService {
* The migration is idempotent so no harm in rerunning. It will only update
* engagements that haven't been migrated.
*/
public void migrate(boolean migrateUuids, boolean migrateParticipants, boolean migrateArtifacts) {
public void migrate(boolean migrateUuids, boolean migrateParticipants, boolean migrateArtifacts, boolean migrateHosting) {
if(migrateUuids) {
LOGGER.info("Start Migrate uuids: {}", migrateUuids);
migrateUuids();
Expand All @@ -78,6 +78,12 @@ public void migrate(boolean migrateUuids, boolean migrateParticipants, boolean m
migrateArtifacts();
LOGGER.info("End Migrate artifacts");
}

if(migrateHosting) {
LOGGER.info("Start Migrate hosting");
migrateHosting();
LOGGER.info("End Migrate hosting");
}
}

/**
Expand Down Expand Up @@ -120,11 +126,17 @@ private void migrateArtifacts() {

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

}

private void migrateHosting() {
getAllEngagements().values().parallelStream().forEach(this::migrateHostingToGitlab);
}

/**
* Get All engagements. This is run by migrate users and uuids so only run once if both are active
* @return
Expand Down Expand Up @@ -156,10 +168,18 @@ private void addToMap(Engagement engagement) {
private void migrateParticipantsToGitlab(Engagement engagement) {

List<EngagementUser> participants = engagement.getEngagementUsers() == null ? Collections.emptyList() : engagement.getEngagementUsers();
participants.forEach(p -> p.setRegion(engagement.getRegion()));
String content = json.toJson(participants);
migrateToGitlab(engagement, content, PARTICIPANT_JSON, participants.size());
}

private void migrateHostingToGitlab(Engagement engagement) {
List<HostingEnvironment> hosting = engagement.getHostingEnvironments() == null ? Collections.emptyList() : engagement.getHostingEnvironments();
hosting.forEach(h -> h.setRegion(engagement.getRegion()));
String content = json.toJson(hosting);
migrateToGitlab(engagement, content, HOSTING_JSON, hosting.size());
}

/**
* This will write the user json to gitlab. Should you wish to rollback or redo you could add this code
* fileService.deleteFile(engagement.getProjectId(), userJson);
Expand Down
Binary file added src/main/resources/META-INF/branding/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
145 changes: 145 additions & 0 deletions src/main/resources/META-INF/resources/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico"/>
<title>Lodestar Participants - 1.0.0-SNAPSHOT</title>
<style>
h1, h2, h3, h4, h5, h6 {
margin-bottom: 0.5rem;
font-weight: 400;
line-height: 1.5;
}

h1 {
font-size: 2.5rem;
}

h2 {
font-size: 2rem
}

h3 {
font-size: 1.75rem

}

h4 {
font-size: 1.5rem
}

h5 {
font-size: 1.25rem
}

h6 {
font-size: 1rem
}

.lead {
font-weight: 300;
font-size: 2rem;
}

.banner {
font-size: 2.7rem;
margin: 0;
padding: 2rem 1rem;
background-color: #0d1c2c;
color: white;
}

body {
margin: 0;
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";
}

code {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 87.5%;
color: #e83e8c;
word-break: break-word;
}

.left-column {
padding: .75rem;
max-width: 75%;
min-width: 55%;
}

.right-column {
padding: .75rem;
max-width: 25%;
}

.container {
display: flex;
width: 100%;
}

li {
margin: 0.75rem;
}

.right-section {
margin-left: 1rem;
padding-left: 0.5rem;
}

.right-section h3 {
padding-top: 0;
font-weight: 200;
}

.right-section ul {
border-left: 0.3rem solid #71aeef;
list-style-type: none;
padding-left: 0;
}

.example-code {
border-left: 0.3rem solid #71aeef;
padding-left: 10px;
}

.example-code h3 {
font-weight: 200;
}
</style>
</head>
<body>

<div class="banner lead">
LodeStar Participants API
</div>

<div class="container">
<div class="left-column">
<p class="lead"> This provides api endpoints for LodeStar to communicate with git for all engagement info.</p>

<ul>
<li><a href="/q/swagger-ui/">Swagger UI</a> </li>
<li>Quarkus now ships with a <a href="/q/dev/">Dev UI</a> (available in dev mode only)</li>
</ul>

</div>
<div class="right-column">
<div class="right-section">
<h3>Application</h3>
<ul>
<li>GroupId: <code>com.redhat.labs.lodestar</code></li>
<li>ArtifactId: <code>lodestar-participants</code></li>
<li>Version: <code>1.0.0-SNAPSHOT</code></li>
<li>Quarkus Version: <code>1.13.7.Final</code></li>
</ul>
</div>
<div class="right-section">
<h3>Selected extensions guides</h3>
<ul>
<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>
</ul>
</div>
</div>
</div>
</body>
</html>
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ commit.default.author=Otto Mayshin
commit.default.branch=master
config.reload=${CONFIG_RELOAD:false}

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

# engagements
engagements.repository.id=${ENGAGEMENTS_REPOSITORY_ID:2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MigrationResourceTest {
void testGetHookFileSuccess() {

given().when().put("/api/migrate").then().statusCode(200);
given().queryParam("participants", true).queryParam("uuid", true).queryParam("artifacts", true).when()
.put("/api/migrate").then().statusCode(200);
given().queryParam("participants", true).queryParam("uuid", true).queryParam("artifacts", true)
.queryParam("hosting", true).when().put("/api/migrate").then().statusCode(200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MigrationServiceTest {
@Inject
MigrationService migrationService;

static ProjectService mockPS;
static ProjectService projectServiceMock;

static FileService fileServiceMock;

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

mockPS = Mockito.mock(ProjectService.class);
Mockito.when(mockPS.getProjectsByGroup(2, true)).thenReturn(projects);
QuarkusMock.installMockForType(mockPS, ProjectService.class);
projectServiceMock = Mockito.mock(ProjectService.class);
Mockito.when(projectServiceMock.getProjectsByGroup(2, true)).thenReturn(projects);
QuarkusMock.installMockForType(projectServiceMock, ProjectService.class);

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

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

@Test
void migrate() {
migrationService.migrate(false, false, false);
migrationService.migrate(false, false, false, false);

Mockito.verify(mockPS, Mockito.never()).updateProject(Mockito.any());
Mockito.verify(fileServiceMock, Mockito.never()).createFile(Mockito.anyInt(), Mockito.eq("participants.json"), Mockito.any(File.class));
Mockito.verify(projectServiceMock, Mockito.never()).updateProject(Mockito.any());
Mockito.verify(fileServiceMock, Mockito.never()).createFile(Mockito.anyInt(), Mockito.eq("engagement/participants.json"), Mockito.any(File.class));

migrationService.migrate(true, true, true);
migrationService.migrate(true, true, true, true);

Mockito.verify(mockPS, Mockito.times(2)).updateProject(Mockito.any());
Mockito.verify(fileServiceMock, Mockito.times(2)).createFile(Mockito.anyInt(), Mockito.eq("participants.json"), Mockito.any(File.class));
Mockito.verify(projectServiceMock, Mockito.times(2)).updateProject(Mockito.any());
Mockito.verify(fileServiceMock, Mockito.times(2)).createFile(Mockito.anyInt(), Mockito.eq("engagement/hosting.json"), Mockito.any(File.class));
Mockito.verify(fileServiceMock, Mockito.times(2)).createFile(Mockito.anyInt(), Mockito.eq("engagement/participants.json"), Mockito.any(File.class));
}


Expand Down

0 comments on commit a472dc3

Please sign in to comment.