Search in sources :

Example 6 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class StoreFileThenDownloadThenUploadAndVerifyInTrackingReportTest method sealAndCheck.

void sealAndCheck(String trackingId) throws IndyClientException {
    // seal
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    // check report
    final TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Example 7 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class DuplicateStoreAndVerifyTrackedRecordTest method run.

@Test
public void run() throws Exception {
    final IndyFoloContentClientModule content = client.module(IndyFoloContentClientModule.class);
    final IndyFoloAdminClientModule admin = client.module(IndyFoloAdminClientModule.class);
    final String trackingId = newName();
    final byte[] b = ("This is a test: " + System.nanoTime()).getBytes();
    final InputStream stream = new ByteArrayInputStream(b);
    // 30
    System.out.println(">>> " + b.length);
    final byte[] b2 = ("This is another test: " + System.nanoTime()).getBytes();
    final InputStream stream2 = new ByteArrayInputStream(b2);
    // 36
    System.out.println(">>> " + b2.length);
    System.out.println(">>> store stream");
    content.store(trackingId, storeKey, path, stream);
    System.out.println(">>> store stream 2");
    PathInfo store = content.store(trackingId, storeKey, path, stream2);
    System.out.println(">>> Store content length: " + store.getContentLength());
    boolean b1 = admin.sealTrackingRecord(trackingId);
    System.out.println(">>>  seal tracking record: " + b1);
    TrackedContentDTO report = admin.getTrackingReport(trackingId);
    Set<TrackedContentEntryDTO> uploads = report.getUploads();
    uploads.forEach(et -> {
        System.out.println(">>> md5: " + et.getMd5() + ", size=" + et.getSize());
        System.out.println(">>> B2: " + b2.length);
        System.out.println(">>> B2 long: " + (long) b2.length);
        assertThat("Mismatched size for: " + et.getPath(), et.getSize(), equalTo((long) b2.length));
    });
}
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) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 8 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class RemoveFilesInTrackingReportTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
    final String a = "/path/to/1/foo-1.jar";
    final String b = "/path/to/2/foo-2.jar";
    final String c = "/path/to/3/foo-3.jar";
    for (String path : Arrays.asList(a, b)) {
        client.module(IndyFoloContentClientModule.class).store(trackingId, hosted, STORE, path, stream);
    }
    StoreKey key = new StoreKey(PKG_TYPE_MAVEN, hosted, STORE);
    client.content().store(key, c, stream);
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    boolean exists;
    for (String path : Arrays.asList(a, b)) {
        exists = client.content().exists(key, path);
        assertThat("The file does not exists.", exists, equalTo(true));
    }
    exists = client.content().exists(key, c);
    assertThat("The file does not exists.", exists, equalTo(true));
    BatchDeleteRequest request = new BatchDeleteRequest();
    request.setStoreKey(key);
    request.setTrackingID(trackingId);
    adminModule.deleteFilesFromStoreByTrackingID(request);
    for (String path : Arrays.asList(a, b)) {
        exists = client.content().exists(key, path);
        assertThat("The file is not removed.", exists, equalTo(false));
    }
    exists = client.content().exists(key, c);
    assertThat("The file does not exists.", exists, equalTo(true));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) BatchDeleteRequest(org.commonjava.indy.model.core.BatchDeleteRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) AbstractTrackingReportTest(org.commonjava.indy.folo.ftest.report.AbstractTrackingReportTest)

Example 9 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class FoloBackupListenerTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
    final String path = "/path/to/foo.class";
    client.module(IndyFoloContentClientModule.class).store(trackingId, hosted, STORE, path, stream);
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    final TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
    final TrackedContentEntryDTO entry = uploads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(hosted, STORE)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(hosted, STORE, path)));
    assertThat(entry.getOriginUrl(), nullValue());
    // /////////////////////////////////////////////////////////////////////////////
    // the above are copied from StoreFileAndVerifyInTrackingReportTest
    // next, we check the backup dir contains two files, one from startup action, the other is just added
    // **/
    // File f1 = new File( dataDir, FOLO_DIR + "/" + BAK_DIR +"/sealed/" + trackingId );
    // assertTrue( f1.exists() );
    File f2 = new File(dataDir, FOLO_DIR + "/" + BAK_DIR + "/sealed");
    assertDumped(f2);
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) StoreKey(org.commonjava.indy.model.core.StoreKey) File(java.io.File) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 10 with IndyFoloAdminClientModule

use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.

the class ExportAndImportTrackingReportTest method run.

@Test
public void run() throws Exception {
    String[] ret = retrieveAndSeal(repoId, path1, "This is a test.");
    String trackingId_1 = ret[0];
    ret = retrieveAndSeal(repoId, path2, "This is a another test.");
    String trackingId_2 = ret[0];
    IndyFoloAdminClientModule adminClientModule = client.module(IndyFoloAdminClientModule.class);
    InputStream stream = adminClientModule.exportTrackingReportZip();
    // check the folo-sealed.zip exists under data/folo/
    File zipFile = new File(dataDir, FOLO_DIR + "/" + FOLO_SEALED_ZIP);
    assertTrue(zipFile.exists());
    // FileUtils.copyFile(zipFile, new File("/tmp/" + FOLO_SEALED_ZIP));
    // to bytes
    byte[] bytes;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    copy(stream, baos);
    bytes = baos.toByteArray();
    stream.close();
    // read to a list
    final List<TrackedContent> list = new ArrayList<>();
    readZipInputStreamAnd(new ByteArrayInputStream(bytes), (record) -> list.add(record));
// **/ Disabled behavour because we need to keep audit logs
// check
// final List<String> trackingIds = check( list );
// assertTrue( trackingIds.contains( trackingId_1 ) );
// assertTrue( trackingIds.contains( trackingId_2 ) );
// clear all
// trackingIds.forEach( id ->
// {
// try
// {
// adminClientModule.clearTrackingRecord( id );
// }
// catch ( IndyClientException e )
// {
// e.printStackTrace();
// }
// } );
// **/ Disabled behavour because we need to keep audit logs
// 
// check ids are cleaned
// TrackingIdsDTO idsDTO = adminClientModule.getTrackingIds( FOLO_TYPE_SEALED );
// assertNull( idsDTO );
// import
// adminClientModule.importTrackingReportZip( new ByteArrayInputStream( bytes ) );
// check again
// idsDTO = adminClientModule.getTrackingIds( FOLO_TYPE_SEALED );
// checkIdsDTO( idsDTO, trackingIds, adminClientModule );
// **
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) Test(org.junit.Test)

Aggregations

IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)11 Test (org.junit.Test)9 InputStream (java.io.InputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)7 TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)7 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)7 StoreKey (org.commonjava.indy.model.core.StoreKey)4 File (java.io.File)3 ArrayList (java.util.ArrayList)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)1 TrackingIdsDTO (org.commonjava.indy.folo.dto.TrackingIdsDTO)1 AbstractFoloContentManagementTest (org.commonjava.indy.folo.ftest.content.AbstractFoloContentManagementTest)1 AbstractTrackingReportTest (org.commonjava.indy.folo.ftest.report.AbstractTrackingReportTest)1 TrackedContent (org.commonjava.indy.folo.model.TrackedContent)1