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;
}
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;
}
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);
}
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));
}
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));
}
Aggregations