Search in sources :

Example 1 with TrackedContentEntryDTO

use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO 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 TrackedContentEntryDTO

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

the class FoloAdminController method constructContentEntryDTO.

private TrackedContentEntryDTO constructContentEntryDTO(final TrackedContentEntry entry, String apiBaseUrl) {
    if (entry == null) {
        return null;
    }
    TrackedContentEntryDTO entryDTO = new TrackedContentEntryDTO(entry.getStoreKey(), entry.getAccessChannel(), entry.getPath());
    try {
        entryDTO.setLocalUrl(UrlUtils.buildUrl(apiBaseUrl, "content", entryDTO.getStoreKey().getPackageType(), entryDTO.getStoreKey().getType().singularEndpointName(), entryDTO.getStoreKey().getName(), entryDTO.getPath()));
    } catch (MalformedURLException e) {
        logger.warn(String.format("Cannot formulate local URL!\n  Base URL: %s" + "\n  Store: %s\n  Path: %s\n  Record: %s\n  Reason: %s", apiBaseUrl, entry.getStoreKey(), entry.getPath(), entry.getTrackingKey(), e.getMessage()), e);
    }
    entryDTO.setOriginUrl(entry.getOriginUrl());
    entryDTO.setMd5(entry.getMd5());
    entryDTO.setSha1(entry.getSha1());
    entryDTO.setSha256(entry.getSha256());
    entryDTO.setSize(entry.getSize());
    entryDTO.setTimestamps(entry.getTimestamps());
    return entryDTO;
}
Also used : MalformedURLException(java.net.MalformedURLException) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO)

Example 3 with TrackedContentEntryDTO

use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO 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 4 with TrackedContentEntryDTO

use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO 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 5 with TrackedContentEntryDTO

use of org.commonjava.indy.folo.dto.TrackedContentEntryDTO 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)

Aggregations

TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)24 TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)23 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)19 Test (org.junit.Test)17 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 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)5 BytemanTest (org.commonjava.indy.ftest.core.category.BytemanTest)3 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1