Search in sources :

Example 56 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class SetBackSettingsResource method delete.

@ApiOperation("DELETE the settings.xml simulation corresponding to the specified Indy group/repository")
@ApiResponses({ @ApiResponse(code = 400, message = "Requested repository is hosted on Indy and cannot be simulated via settings.xml"), @ApiResponse(code = 404, message = "No such repository or group, or the settings.xml has not been generated."), @ApiResponse(code = 204, message = "Deletion succeeded") })
@Path("/{type: (remote|group)}/{name}")
@DELETE
public Response delete(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String t, @PathParam("name") final String n) {
    final StoreType type = StoreType.get(t);
    if (StoreType.hosted == type) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Response response;
    final StoreKey key = new StoreKey(type, n);
    try {
        final boolean found = controller.deleteSetBackSettings(key);
        if (found) {
            response = Response.status(Status.NO_CONTENT).build();
        } else {
            response = Response.status(Status.NOT_FOUND).build();
        }
    } catch (final IndyWorkflowException e) {
        response = ResponseUtils.formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 57 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class IndyLocationResolver method resolve.

@Override
public Location resolve(final String spec) throws TransferException {
    ArtifactStore store;
    try {
        final StoreKey source = StoreKey.fromString(spec);
        if (source == null) {
            throw new TransferException("Failed to parse StoreKey (format: '[remote|hosted|group]:name') from: '%s'.");
        }
        store = dataManager.getArtifactStore(source);
    } catch (final IndyDataException e) {
        throw new TransferException("Cannot find ArtifactStore to match source key: %s. Reason: %s", e, spec, e.getMessage());
    }
    if (store == null) {
        throw new TransferException("Cannot find ArtifactStore to match source key: %s.", spec);
    }
    final KeyedLocation location = LocationUtils.toLocation(store);
    logger.debug("resolved source location: '{}' to: '{}'", spec, location);
    return location;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) TransferException(org.commonjava.maven.galley.TransferException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 58 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class SettingsSubStore method getSettingsTemplate.

private synchronized SettingsTemplate getSettingsTemplate(final URIMatcher matcher) throws WebdavException {
    final StoreKey key = matcher.getStoreKey();
    ArtifactStore store;
    try {
        store = indy.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve artifact store: %s. Reason: %s", key, e.getMessage()), e);
        throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
    }
    if (store == null) {
        throw new WebdavException("Cannot retrieve ArtifactStore: " + key);
    }
    StorageAdvice advice;
    try {
        advice = advisor.getStorageAdvice(store);
    } catch (final DotMavenException e) {
        logger.error(String.format("Failed to retrieve storage advice for: %s. Reason: %s", key, e.getMessage()), e);
        throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
    }
    return new SettingsTemplate(key, advice, requestInfo, templatingEngine);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) SettingsTemplate(org.commonjava.indy.dotmaven.util.SettingsTemplate) WebdavException(net.sf.webdav.exceptions.WebdavException) StoreKey(org.commonjava.indy.model.core.StoreKey) DotMavenException(org.commonjava.indy.dotmaven.DotMavenException)

Example 59 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class RetrieveFileAndVerifyInTrackingReportTest method run.

@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) Test(org.junit.Test)

Example 60 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class RetrieveFileFromGroupAndVerifyInTrackingReportTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    final String repoId = "repo";
    final String groupId = "group";
    final String path = "/path/to/foo.class";
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).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);
    Group g = new Group(groupId, rr.getKey());
    g = client.stores().create(g, "Adding test group", Group.class);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, group, groupId, 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)));
    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 : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) 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) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) Test(org.junit.Test)

Aggregations

StoreKey (org.commonjava.indy.model.core.StoreKey)186 Test (org.junit.Test)92 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)40 StoreType (org.commonjava.indy.model.core.StoreType)39 InputStream (java.io.InputStream)33 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)32 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)31 IndyDataException (org.commonjava.indy.data.IndyDataException)30 Group (org.commonjava.indy.model.core.Group)29 Transfer (org.commonjava.maven.galley.model.Transfer)27 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)24 Response (javax.ws.rs.core.Response)23 IOException (java.io.IOException)22 Logger (org.slf4j.Logger)21 ApiOperation (io.swagger.annotations.ApiOperation)20 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)19 ApiResponse (io.swagger.annotations.ApiResponse)18 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)18