Search in sources :

Example 21 with PathsPromoteResult

use of org.commonjava.indy.promote.model.PathsPromoteResult in project indy by Commonjava.

the class PromoteResource method resumePaths.

@ApiOperation("RESUME promotion of paths from a source repository into a target repository/group (subject to validation), presumably after a previous failure condition has been corrected.")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON result from previous attempt, specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteResult")
@Path("/paths/resume")
@POST
@Consumes(ApplicationContent.application_json)
public Response resumePaths(@Context final HttpServletRequest request) {
    PathsPromoteResult result = null;
    Response response = null;
    try {
        result = mapper.readValue(request.getInputStream(), PathsPromoteResult.class);
    } catch (final IOException e) {
        response = formatResponse(e, "Failed to read DTO from request body.");
    }
    if (response != null) {
        return response;
    }
    try {
        result = manager.resumePathsPromote(result);
        // TODO: Amend response status code based on presence of error? This would have consequences for client API...
        response = formatOkResponseWithJsonEntity(result, mapper);
    } catch (PromotionException | IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) PromotionException(org.commonjava.indy.promote.data.PromotionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) ApiResponse(io.swagger.annotations.ApiResponse)

Example 22 with PathsPromoteResult

use of org.commonjava.indy.promote.model.PathsPromoteResult in project indy by Commonjava.

the class PromoteResource method rollbackPaths.

@ApiOperation("Rollback promotion of any completed paths to a source repository from a target repository/group.")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON result from previous attempt, specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteResult")
@Path("/paths/rollback")
@POST
@Consumes(ApplicationContent.application_json)
public Response rollbackPaths(@Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
    PathsPromoteResult result = null;
    Response response = null;
    try {
        result = mapper.readValue(request.getInputStream(), PathsPromoteResult.class);
    } catch (final IOException e) {
        response = formatResponse(e, "Failed to read DTO from request body.");
    }
    if (response != null) {
        return response;
    }
    try {
        result = manager.rollbackPathsPromote(result);
        // TODO: Amend response status code based on presence of error? This would have consequences for client API...
        response = formatOkResponseWithJsonEntity(result, mapper);
    } catch (PromotionException | IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) PromotionException(org.commonjava.indy.promote.data.PromotionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) ApiResponse(io.swagger.annotations.ApiResponse)

Example 23 with PathsPromoteResult

use of org.commonjava.indy.promote.model.PathsPromoteResult in project indy by Commonjava.

the class RollbackTwoArtifactsTest method run.

@Test
public void run() throws Exception {
    PathsPromoteResult result = client.module(IndyPromoteClientModule.class).promoteByPath(new PathsPromoteRequest(source.getKey(), target.getKey()));
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    Set<String> pending = result.getPendingPaths();
    assertThat(pending == null || pending.isEmpty(), equalTo(true));
    Set<String> completed = result.getCompletedPaths();
    assertThat(completed, notNullValue());
    assertThat(completed.size(), equalTo(2));
    assertThat(result.getError(), nullValue());
    result = client.module(IndyPromoteClientModule.class).rollbackPathPromote(result);
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    completed = result.getCompletedPaths();
    assertThat(completed == null || completed.isEmpty(), equalTo(true));
    pending = result.getPendingPaths();
    assertThat(pending, notNullValue());
    assertThat(pending.size(), equalTo(2));
    assertThat(result.getError(), nullValue());
    assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(false));
    assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(false));
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) Test(org.junit.Test)

Aggregations

PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)23 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)18 Test (org.junit.Test)14 Transfer (org.commonjava.maven.galley.model.Transfer)10 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)7 HostedRepository (org.commonjava.indy.model.core.HostedRepository)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 StoreKey (org.commonjava.indy.model.core.StoreKey)5 IndyPromoteClientModule (org.commonjava.indy.promote.client.IndyPromoteClientModule)5 HashSet (java.util.HashSet)4 ValidationResult (org.commonjava.indy.promote.model.ValidationResult)4 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponse (io.swagger.annotations.ApiResponse)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3