Search in sources :

Example 1 with StoreKey

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);
            }
        }
    }
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 2 with StoreKey

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);
    }
}
Also used : ThreadContext(org.commonjava.cdi.util.weft.ThreadContext) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 3 with StoreKey

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);
    });
}
Also used : Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) HashSet(java.util.HashSet)

Example 4 with StoreKey

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;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) StoreKey(org.commonjava.indy.model.core.StoreKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 5 with StoreKey

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

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