use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class FoloAdminController method addTransfers.
private void addTransfers(final Set<TrackedContentEntry> entries, final List<Transfer> items, final String trackingId, final Set<String> seenPaths) throws IndyWorkflowException {
if (entries != null && !entries.isEmpty()) {
for (final TrackedContentEntry entry : entries) {
final String path = entry.getPath();
if (path == null || seenPaths.contains(path)) {
continue;
}
final StoreKey sk = entry.getStoreKey();
Transfer transfer = contentManager.getTransfer(sk, path, TransferOperation.DOWNLOAD);
if (transfer == null) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.warn("While creating Folo repo zip for: {}, cannot find: {} in: {}", trackingId, path, sk);
} else {
seenPaths.add(path);
items.add(transfer);
}
}
}
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class ContentIndexActions method clearMergedPath.
public void clearMergedPath(ArtifactStore originatingStore, Set<Group> groups, String path) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Clearing merged path: {} from indexes of: {} (triggered by: {})", path, groups, originatingStore);
StoreKey key = originatingStore.getKey();
ThreadContext context = ThreadContext.getContext(true);
context.put(ORIGIN_KEY, key);
try {
// the only time a group will have local storage of the path is when it has been merged
// ...in which case we should try to delete it.
indexManager.clearIndexedPathFrom(path, groups, null);
} finally {
context.remove(ORIGIN_KEY);
}
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class ContentIndexManager method indexPathInStores.
/**
* When we store or retrieve content, index it for faster reference next time.
*/
public void indexPathInStores(String path, StoreKey originKey, StoreKey... topKeys) {
IndexedStorePath origin = new IndexedStorePath(originKey, path);
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Indexing path: {} in: {}", path, originKey);
contentIndex.put(origin, origin);
Set<StoreKey> keySet = new HashSet<>(Arrays.asList(topKeys));
keySet.forEach((key) -> {
IndexedStorePath isp = new IndexedStorePath(key, originKey, path);
logger.trace("Indexing path: {} in: {} via member: {}", path, key, originKey);
contentIndex.put(isp, origin);
});
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class AutoProxCalculatorResource method eval.
@ApiOperation(value = "Calculate the effects of referencing a store with the given type and name to determine what AutoProx will auto-create", response = AutoProxCalculation.class)
@ApiResponse(code = 200, message = "Result of calculation")
@Path("/{packageType}/{type: (hosted|group|remote)}/{name}")
@GET
@Produces(ApplicationContent.application_json)
public Response eval(@PathParam("packageType") final String packageType, @PathParam("type") final String type, @PathParam("name") final String remoteName) {
Response response = checkEnabled();
if (response != null) {
return response;
}
try {
StoreKey key = new StoreKey(packageType, StoreType.get(type), remoteName);
final AutoProxCalculation calc = controller.eval(key);
response = formatOkResponseWithJsonEntity(serializer.writeValueAsString(calc == null ? Collections.singletonMap("error", "Nothing was created") : calc));
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to create demo RemoteRepository for: '%s'. Reason: %s", remoteName, e.getMessage()), e);
response = formatResponse(e);
} catch (final JsonProcessingException e) {
logger.error(String.format("Failed to create demo RemoteRepository for: '%s'. Reason: %s", remoteName, e.getMessage()), e);
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.model.core.StoreKey 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));
}
Aggregations