Search in sources :

Example 6 with TrackedContentDTO

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

the class AbstractCacheReportTest method doRealTest.

protected void doRealTest() throws Exception {
    final String trackingId = newName();
    final String path = "org/commonjava/commonjava/2/commonjava-2.pom";
    final InputStream result = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, CENTRAL, path);
    assertThat(result, notNullValue());
    result.close();
    assertThat(client.module(IndyFoloAdminClientModule.class).initReport(trackingId), equalTo(true));
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final TrackedContentEntryDTO entry = report.getDownloads().iterator().next();
    doDeletion(entry.getStoreKey(), path);
    final String filePath = String.format("%s/var/lib/indy/storage/%s-%s/%s", fixture.getBootOptions().getIndyHome(), remote.name(), CENTRAL, path);
    final File pomFile = new File(filePath);
    assertThat("File should be deleted", pomFile.exists(), equalTo(false));
    final TrackedContentDTO reportAgain = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    assertThat(reportAgain, equalTo(report));
    final TrackedContentEntryDTO entryAgain = report.getDownloads().iterator().next();
    assertThat(entryAgain, equalTo(entry));
    assertThat(entryAgain.getSha1(), equalTo(entry.getSha1()));
    assertThat(entryAgain.getSha256(), equalTo(entry.getSha256()));
    assertThat(entryAgain.getMd5(), equalTo(entry.getMd5()));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) File(java.io.File) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Example 7 with TrackedContentDTO

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

the class InitTrackingRecordThenPullEmptyRecordTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    assertThat(client.module(IndyFoloAdminClientModule.class).initReport(trackingId), equalTo(true));
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    assertThat(report, notNullValue());
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 8 with TrackedContentDTO

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

the class FoloAdminResource method getRecord.

@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}/record")
@GET
public Response getRecord(@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 record = controller.getRecord(id, baseUrl);
        if (record == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else {
            response = formatOkResponseWithJsonEntity(record, objectMapper);
        }
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to retrieve tracking report for: %s. Reason: %s", id, 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) 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 9 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());
    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)

Example 10 with TrackedContentDTO

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

the class StoreOneTrackedAndVerifyUrlInReportTest method storeOneFileAndVerifyItInParentDirectoryListing.

@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final String root = "/path/to/";
    final String path = root + "foo.txt";
    final String trackingId = "tracker";
    content.store(trackingId, hosted, STORE, path, stream);
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = admin.getTrackingReport(trackingId);
    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    for (final TrackedContentEntryDTO upload : uploads) {
        final String uploadPath = upload.getPath();
        final String localUrl = client.content().contentUrl(hosted, STORE, uploadPath);
        assertThat("Incorrect local URL for upload: '" + uploadPath + "'", upload.getLocalUrl(), equalTo(localUrl));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Aggregations

TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)24 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)18 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)17 Test (org.junit.Test)15 InputStream (java.io.InputStream)13 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 StoreKey (org.commonjava.indy.model.core.StoreKey)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)6 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Path (javax.ws.rs.Path)4 ApiResponse (io.swagger.annotations.ApiResponse)3 GET (javax.ws.rs.GET)3 Response (javax.ws.rs.core.Response)3 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)3 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)3 BytemanTest (org.commonjava.indy.ftest.core.category.BytemanTest)3 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)3