Search in sources :

Example 1 with TrackedContentDTO

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

the class FoloAdminController method constructContentDTO.

private TrackedContentDTO constructContentDTO(final TrackedContent content, final String baseUrl) {
    if (content == null) {
        return null;
    }
    final Set<TrackedContentEntryDTO> uploads = new TreeSet<>();
    for (TrackedContentEntry entry : content.getUploads()) {
        uploads.add(constructContentEntryDTO(entry, baseUrl));
    }
    final Set<TrackedContentEntryDTO> downloads = new TreeSet<>();
    for (TrackedContentEntry entry : content.getDownloads()) {
        downloads.add(constructContentEntryDTO(entry, baseUrl));
    }
    return new TrackedContentDTO(content.getKey(), uploads, downloads);
}
Also used : TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) TreeSet(java.util.TreeSet) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Example 2 with TrackedContentDTO

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

the class UseChecksumFromTransferDecoratorForTrackingRecordTest method run.

@BMRules(rules = { @BMRule(name = "setup_metadata_countdown", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "<init>", targetLocation = "ENTRY", action = "System.out.println(\"SETUP COUNTDOWN\"); createCountDown(\"COUNTDOWN\", 1);"), @BMRule(name = "prevent_successive_metadata_additions", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "addMetadata", targetLocation = "ENTRY", binding = "path:String = $1.getPath();", condition = "path.endsWith(\"path/to/foo.class\") && countDown(\"COUNTDOWN\")", action = "System.out.println(\"RETURN NULL\"); return null;") })
@Test
public void run() throws Exception {
    final String trackingId = newName();
    final String repoId = "repo";
    final String path = "/path/to/foo.class";
    final InputStream stream = new ByteArrayInputStream("This is a test with the same content each time.".getBytes());
    server.expect(server.formatUrl(repoId, path), 200, stream);
    RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId));
    rr = client.stores().create(rr, "adding test remote", RemoteRepository.class);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path);
    IOUtils.copy(in, baos);
    in.close();
    final byte[] bytes = baos.toByteArray();
    final String md5 = md5Hex(bytes);
    final String sha256 = sha256Hex(bytes);
    assertThat(md5, equalTo(DigestUtils.md5Hex(bytes)));
    assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes)));
    waitForEventPropagation();
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    final TrackedContentEntryDTO entry = downloads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path)));
    assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path)));
    assertThat(entry.getMd5(), equalTo(md5));
    assertThat(entry.getSha256(), equalTo(sha256));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) BytemanTest(org.commonjava.indy.ftest.core.category.BytemanTest) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 3 with TrackedContentDTO

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

the class RetrievedPomInSuffixTrackingReportTest 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(TRACKING_ID), equalTo(true));
    final TrackedContentDTO content = this.client.module(IndyFoloAdminClientModule.class).getRawTrackingContent(TRACKING_ID);
    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 );
// assertThat( record, notNullValue() );
// 
// 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 4 with TrackedContentDTO

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

the class ExportAndImportTrackingReportTest method checkIdsDTO.

static void checkIdsDTO(TrackingIdsDTO idsDTO, List<String> expectedIds, IndyFoloAdminClientModule adminClientModule) {
    // **/ Disabled behawior  because it is  affeecting  auditing  for folo records
    // Set<String> sealed = idsDTO.getSealed();
    // assertTrue( sealed.containsAll( expectedIds ) );
    // assertEquals( 2, sealed.stream().distinct().collect(Collectors.toSet()).size() );
    final List<Exception> ex = new ArrayList<>();
    idsDTO.getSealed().forEach((id) -> {
        try {
            TrackedContentDTO report = adminClientModule.getTrackingReport(id);
            assertNotNull(report);
            System.out.println(">>>> " + report.getKey() + ", " + report.getDownloads());
            assertTrue(expectedIds.contains(report.getKey().getId()));
            assertTrue(!report.getDownloads().isEmpty());
            // **/ Disabled behawior  because it is  affeecting  auditing  for folo records
            // assertEquals( 1, report.getDownloads().size() );
            List<TrackedContentEntryDTO> list = new ArrayList(report.getDownloads());
            TrackedContentEntryDTO entryDTO = list.get(0);
            assertTrue(entryDTO.getPath().contains(path1) || entryDTO.getPath().contains(path2));
            assertTrue(entryDTO.getStoreKey().getName().equals(repoId));
        } catch (IndyClientException e) {
            ex.add(e);
        }
    });
    assertTrue(ex.isEmpty());
}
Also used : TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) ArrayList(java.util.ArrayList) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IndyClientException(org.commonjava.indy.client.core.IndyClientException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Example 5 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)

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