Skip to content

Commit 3489a1b

Browse files
authored
add migration api (#173)
1 parent 0dcaa98 commit 3489a1b

File tree

5 files changed

+79
-6
lines changed

5 files changed

+79
-6
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import javax.ws.rs.core.UriInfo;
2727

2828
import com.redhat.labs.lodestar.model.EngagementUserSummary;
29-
import com.redhat.labs.lodestar.service.ActivityService;
3029
import com.redhat.labs.lodestar.service.ParticipantService;
3130
import org.eclipse.microprofile.jwt.JsonWebToken;
3231
import org.eclipse.microprofile.openapi.annotations.Operation;
@@ -71,9 +70,6 @@ public class EngagementResource {
7170

7271
@Inject
7372
EngagementService engagementService;
74-
75-
@Inject
76-
ActivityService activityService;
7773

7874
@Inject
7975
ConfigService configService;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.redhat.labs.lodestar.resource;
2+
3+
import com.redhat.labs.lodestar.rest.client.GitApiApiClient;
4+
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement;
5+
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
6+
import org.eclipse.microprofile.rest.client.inject.RestClient;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
import javax.inject.Inject;
11+
import javax.ws.rs.PUT;
12+
import javax.ws.rs.Path;
13+
import javax.ws.rs.Produces;
14+
import javax.ws.rs.QueryParam;
15+
import javax.ws.rs.core.Response;
16+
import java.util.List;
17+
18+
@Path("/engagements/migrate")
19+
@Tag(name = "Migration", description = "Migration services")
20+
public class MigrationResource {
21+
private static final Logger LOGGER = LoggerFactory.getLogger(MigrationResource.class);
22+
23+
@Inject
24+
@RestClient
25+
GitApiApiClient migrationApiClient;
26+
27+
@PUT
28+
@SecurityRequirement(name = "jwt")
29+
@Produces("application/json")
30+
public Response migrate(@QueryParam(value = "participants") boolean migrateParticipants,
31+
@QueryParam("artifacts") boolean migrateArtifacts,
32+
@QueryParam("projects") boolean migrateUuids,
33+
@QueryParam("hosting") boolean migrateHosting,
34+
@QueryParam("engagements") boolean migrateEngagements,
35+
@QueryParam("overwrite") boolean overwrite,
36+
@QueryParam("dryRun") boolean dryRun,
37+
@QueryParam("uuids") List<String> uuids) {
38+
39+
try {
40+
migrationApiClient.migrate(migrateUuids, migrateParticipants, migrateArtifacts, migrateHosting, migrateEngagements,
41+
overwrite, dryRun, uuids);
42+
} catch (Exception ex) {
43+
LOGGER.error("Migration did not complete successfully", ex);
44+
return Response.status(Response.Status.BAD_REQUEST).entity("{ \"message\": \"Migration did not complete successfully\"}").build();
45+
}
46+
47+
return Response.ok().build();
48+
}
49+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.redhat.labs.lodestar.rest.client;
2+
3+
import com.redhat.labs.lodestar.exception.mapper.ServiceResponseMapper;
4+
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
5+
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
6+
7+
import javax.enterprise.context.ApplicationScoped;
8+
import javax.ws.rs.*;
9+
import javax.ws.rs.core.Response;
10+
import java.util.List;
11+
12+
@ApplicationScoped
13+
@RegisterRestClient(configKey = "lodestar.git.api")
14+
@RegisterProvider(value = ServiceResponseMapper.class, priority = 50)
15+
@Produces("application/json")
16+
@Consumes("application/json")
17+
@Path("/api/migrate")
18+
public interface GitApiApiClient {
19+
20+
@PUT
21+
Response migrate(@QueryParam(value = "participants") boolean migrateParticipants,
22+
@QueryParam("artifacts") boolean migrateArtifacts,
23+
@QueryParam("projects") boolean migrateUuids,
24+
@QueryParam("hosting") boolean migrateHosting,
25+
@QueryParam("engagements") boolean migrateEngagements,
26+
@QueryParam("overwrite") boolean overwrite,
27+
@QueryParam("dryRun") boolean dryRun,
28+
@QueryParam("uuids") List<String> uuids);
29+
}

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ quarkus.cache.caffeine.rbac-cache.expire-after-write=600S
4949
# Quarkus build properties
5050
quarkus.package.type=uber-jar
5151

52-
lodestar.git.api/mp-rest/url=${GITLAB_API_URL:http://lodestar-git-api:8080}
52+
lodestar.git.api/mp-rest/url=${GIT_API_URL:http://lodestar-git-api:8080}
5353
lodestar.status.api/mp-rest/url=${STATUS_API_URL:http://lodestar-status:8080}
5454
lodestar.config.api/mp-rest/url=${CONFIG_API_URL:http://lodestar-config:8080}
5555
lodestar.activity.api/mp-rest/url=${ACTIVITY_API_URL:http://lodestar-activity:8080}

src/test/resources/application.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ event.max.retries=2
3636
event.retry.delay.factor=1
3737
# git api
3838

39-
lodestar.git.api/mp-rest/url=${LODESTAR_GITLAB_API_URL:http://lodestar-git-api:8080}
4039
lodestar.status.api/mp-rest/url=${LODESTAR_STATUS_API_URL:http://lodestar-status:8080}
4140
lodestar.config.api/mp-rest/url=${LODESTAR_CONFIG_API_URL:http://lodestar-config:8080}
4241
lodestar.activity.api/mp-rest/url=${LODESTAR_ACTIVITY_API_URL:http://lodestar-activity:8080}

0 commit comments

Comments
 (0)