|
3 | 3 | import javax.inject.Inject;
|
4 | 4 | import javax.ws.rs.PUT;
|
5 | 5 | import javax.ws.rs.Path;
|
| 6 | +import javax.ws.rs.Produces; |
6 | 7 | import javax.ws.rs.QueryParam;
|
7 | 8 | import javax.ws.rs.core.Response;
|
8 | 9 |
|
9 | 10 | import org.eclipse.microprofile.metrics.MetricUnits;
|
10 |
| -import org.eclipse.microprofile.metrics.annotation.Counted; |
11 | 11 | import org.eclipse.microprofile.metrics.annotation.Timed;
|
12 | 12 | import org.eclipse.microprofile.openapi.annotations.tags.Tag;
|
13 | 13 |
|
14 | 14 | import com.redhat.labs.lodestar.service.MigrationService;
|
| 15 | +import org.slf4j.Logger; |
| 16 | +import org.slf4j.LoggerFactory; |
| 17 | + |
| 18 | +import java.util.List; |
15 | 19 |
|
16 | 20 | @Path("/api/migrate")
|
17 |
| -@Tag(name = "Migration", description = "Migratiion services") |
| 21 | +@Tag(name = "Migration", description = "Migration services") |
18 | 22 | public class MigrationResource {
|
| 23 | + private static final Logger LOGGER = LoggerFactory.getLogger(MigrationResource.class); |
19 | 24 |
|
20 | 25 | @Inject
|
21 | 26 | MigrationService migrationService;
|
22 | 27 |
|
23 | 28 | @PUT
|
24 |
| - @Counted(name = "migration", description = "How many migation requests have been invoked") |
25 | 29 | @Timed(name = "performedMigration", description = "How much time it takes to migrate", unit = MetricUnits.MILLISECONDS)
|
| 30 | + @Produces("application/json") |
26 | 31 | public Response migrate(@QueryParam(value = "participants") boolean migrateParticipants,
|
27 |
| - @QueryParam(value = "artifacts") boolean migrateArtifacts, |
28 |
| - @QueryParam(value = "uuids") boolean migrateUuids, @QueryParam(value = "hosting") boolean migrateHosting) { |
29 |
| - |
30 |
| - migrationService.migrate(migrateUuids, migrateParticipants, migrateArtifacts, migrateHosting); |
| 32 | + @QueryParam("artifacts") boolean migrateArtifacts, |
| 33 | + @QueryParam("projects") boolean migrateUuids, |
| 34 | + @QueryParam("hosting") boolean migrateHosting, |
| 35 | + @QueryParam("engagements") boolean migrateEngagements, |
| 36 | + @QueryParam("overwrite") boolean overwrite, |
| 37 | + @QueryParam("uuids") List<String> uuids) { |
| 38 | + |
| 39 | + try { |
| 40 | + migrationService.migrate(migrateUuids, migrateParticipants, migrateArtifacts, migrateHosting, migrateEngagements, |
| 41 | + overwrite, 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 | + } |
31 | 46 |
|
32 | 47 | return Response.ok().build();
|
33 | 48 |
|
|
0 commit comments