Search in sources :

Example 26 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class FoloAdminResource method getReport.

@ApiOperation("Alias of /{id}/record, returns the tracking record for the specified key")
@ApiResponses({ @ApiResponse(code = 404, message = "No such tracking record exists."), @ApiResponse(code = 200, message = "Tracking record", response = TrackedContentDTO.class) })
@Path("/{id}/report")
@GET
public Response getReport(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @Context final UriInfo uriInfo) {
    Response response;
    try {
        final String baseUrl = uriInfo.getBaseUriBuilder().path("api").build().toString();
        final TrackedContentDTO report = controller.renderReport(id, baseUrl);
        if (report == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else {
            response = responseHelper.formatOkResponseWithJsonEntity(report);
        }
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to serialize tracking report for: %s. Reason: %s", id, e.getMessage()), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 27 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class FoloAdminResource method recalculateRecord.

@ApiOperation("Recalculate sizes and checksums for every file listed in a tracking record.")
@ApiResponses({ @ApiResponse(code = 200, response = TrackedContentDTO.class, message = "Recalculated tracking report"), @ApiResponse(code = 404, message = "No such tracking record can be found") })
@GET
@Path("/{id}/record/recalculate")
public Response recalculateRecord(@ApiParam("User-assigned tracking session key") @PathParam("id") String id, @Context final UriInfo uriInfo) {
    Response response;
    try {
        final String baseUrl = uriInfo.getBaseUriBuilder().path("api").build().toString();
        final TrackedContentDTO report = controller.recalculateRecord(id, baseUrl);
        if (report == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else {
            response = responseHelper.formatOkResponseWithJsonEntity(report);
        }
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to serialize tracking report for: %s. Reason: %s", id, e.getMessage()), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 28 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class FoloAdminResource method sealRecord.

@ApiOperation("Seal the tracking record for the specified key, to prevent further content logging")
@ApiResponses({ @ApiResponse(code = 404, message = "No such tracking record exists."), @ApiResponse(code = 200, message = "Tracking record", response = TrackedContentDTO.class) })
@Path("/{id}/record")
@POST
public Response sealRecord(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @Context final UriInfo uriInfo) {
    final String baseUrl = uriInfo.getBaseUriBuilder().path("api").build().toString();
    TrackedContentDTO record = controller.seal(id, baseUrl);
    if (record == null) {
        return Response.status(Status.NOT_FOUND).build();
    } else {
        return Response.ok().build();
    }
}
Also used : TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 29 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class FoloAdminController method renderReport.

public TrackedContentDTO renderReport(final String id, final String apiBaseUrl) throws IndyWorkflowException {
    final TrackingKey tk = new TrackingKey(id);
    logger.debug("Retrieving tracking record for: {}", tk);
    final TrackedContentDTO record = constructContentDTO(recordManager.get(tk), apiBaseUrl);
    logger.debug("Got: {}", record);
    return record;
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Example 30 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class RetrievedPomInAlwaysOnTrackingReportTest method run.

@Test
public void run() throws Exception {
    final String testRepo = "test";
    final PomRef pom = loadPom("simple.pom", Collections.<String, String>emptyMap());
    final String url = server.formatUrl(testRepo, pom.path);
    server.expect(url, 200, pom.pom);
    final HttpGet get = new HttpGet(url);
    final CloseableHttpClient client = proxiedHttp();
    CloseableHttpResponse response = null;
    InputStream stream = null;
    try {
        response = client.execute(get, proxyContext(USER, PASS));
        assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
        stream = response.getEntity().getContent();
        final String resultingPom = IOUtils.toString(stream);
        assertThat(resultingPom, notNullValue());
        assertThat(resultingPom, equalTo(pom.pom));
    } finally {
        IOUtils.closeQuietly(stream);
        HttpResources.cleanupResources(get, response, client);
    }
    assertThat(this.client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(USER), equalTo(true));
    final TrackedContentDTO content = this.client.module(IndyFoloAdminClientModule.class).getRawTrackingContent(USER);
    assertThat(content, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = content.getDownloads();
    assertThat(downloads, notNullValue());
    // **/ Disabled behawior  because it is  affeecting  auditing  for folo records
    // assertThat( downloads.size(), equalTo( 1 ) );
    final TrackedContentEntryDTO entry = downloads.iterator().next();
    assertThat(entry, notNullValue());
    final String downloadPath = entry.getPath();
    assertThat(downloadPath, notNullValue());
    assertThat(downloadPath, equalTo("/test/" + pom.path));
// TODO: As new api format for "GET /folo/admin/track/record", these tests are deperacated, will keep for a while and remove later
// final String repoName = "httprox_127-0-0-1";
// final TrackedContentRecord record = this.client.module( IndyFoloAdminClientModule.class )
// .getRawTrackingRecord( USER );
// final Map<StoreKey, AffectedStoreRecord> affectedStores = record.getAffectedStores();
// assertThat( affectedStores, notNullValue() );
// assertThat( affectedStores.size(), equalTo( 1 ) );
// final AffectedStoreRecord storeRecord = affectedStores.get( new StoreKey( StoreType.remote, repoName ) );
// assertThat( storeRecord, notNullValue() );
// 
// final Set<String> downloads = storeRecord.getDownloadedPaths();
// assertThat( downloads, notNullValue() );
// assertThat( downloads.size(), equalTo( 1 ) );
// assertThat( downloads.iterator()
// .next(), equalTo( "/test/" + pom.path ) );
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Aggregations

TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)30 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)23 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)20 Test (org.junit.Test)19 InputStream (java.io.InputStream)15 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 StoreKey (org.commonjava.indy.model.core.StoreKey)10 ApiOperation (io.swagger.annotations.ApiOperation)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Path (javax.ws.rs.Path)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)5 ApiResponse (io.swagger.annotations.ApiResponse)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Response (javax.ws.rs.core.Response)4 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)4 File (java.io.File)3 GET (javax.ws.rs.GET)3 BytemanTest (org.commonjava.indy.ftest.core.category.BytemanTest)3 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)3