Search in sources :

Example 31 with StoreKey

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

the class TimeoutEventListener method onFileAccessEvent.

public void onFileAccessEvent(@Observes final FileAccessEvent event) {
    // TODO: handle this stuff in Weft somehow...
    Map original = MDC.getCopyOfContextMap();
    try {
        MDC.setContextMap(event.getMDCMap());
        final StoreKey key = getKey(event);
        if (key != null) {
            final Transfer transfer = event.getTransfer();
            final StoreType type = key.getType();
            if (type == StoreType.hosted) {
                try {
                    scheduleManager.setSnapshotTimeouts(key, transfer.getPath());
                } catch (final IndySchedulerException e) {
                    logger.error("Failed to set snapshot timeouts related to: " + transfer, e);
                }
            } else if (type == StoreType.remote) {
                SpecialPathInfo info = specialPathManager.getSpecialPathInfo(transfer);
                if (info == null || !info.isMetadata()) {
                    logger.debug("Accessed resource {} timeout will be reset.", transfer);
                    try {
                        scheduleManager.setProxyTimeouts(key, transfer.getPath());
                    } catch (final IndySchedulerException e) {
                        logger.error("Failed to set proxy-cache timeouts related to: " + transfer, e);
                    }
                } else {
                    logger.debug("Accessed resource {} is metadata. NOT rescheduling timeout!", transfer);
                }
            }
        }
    } finally {
        if (original != null && !original.isEmpty()) {
            MDC.setContextMap(original);
        } else {
            MDC.setContextMap(Collections.emptyMap());
        }
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Transfer(org.commonjava.maven.galley.model.Transfer) Map(java.util.Map) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 32 with StoreKey

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

the class SuccessiveRetrievalWithRemoteRepoDeletionBetweenTest method run.

@Test
public void run() throws Exception {
    final String testRepo = "test";
    final PomRef pom = loadPom("simple.pom", Collections.<String, String>emptyMap());
    final String url = server.formatUrl(testRepo, pom.path);
    server.expect(url, 200, pom.pom);
    Stream.of(1, 2).forEach((currentTry) -> {
        CloseableHttpResponse response = null;
        InputStream stream = null;
        final HttpGet get = new HttpGet(url);
        CloseableHttpClient httpClient = null;
        try {
            httpClient = proxiedHttp();
            response = httpClient.execute(get);
            stream = response.getEntity().getContent();
            final String resultingPom = IOUtils.toString(stream);
            assertThat(currentTry + ": retrieved POM was null!", resultingPom, notNullValue());
            assertThat(currentTry + ": retrieved POM contains wrong content!", resultingPom, equalTo(pom.pom));
        } catch (Exception e) {
            e.printStackTrace();
            fail(currentTry + ": Failed to retrieve file: " + url);
        } finally {
            IOUtils.closeQuietly(stream);
            HttpResources.cleanupResources(get, response, httpClient);
        }
        try {
            client.stores().delete(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, REMOTE_NAME), "Deleting for pass: " + currentTry);
        } catch (IndyClientException e) {
            fail("Failed to delete remote repo: " + REMOTE_NAME);
        }
    });
    final RemoteRepository remoteRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, REMOTE_NAME), RemoteRepository.class);
    assertThat(remoteRepo, nullValue());
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyClientException(org.commonjava.indy.client.core.IndyClientException) Test(org.junit.Test)

Example 33 with StoreKey

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

the class ImpliedRepoClientModule method setStoresImpliedBy.

public void setStoresImpliedBy(final ArtifactStore store, final List<StoreKey> implied, final String changelog) throws IndyClientException {
    final List<ArtifactStore> stores = new ArrayList<>();
    for (final StoreKey storeKey : implied) {
        final ArtifactStore is = getClient().stores().load(storeKey.getType(), storeKey.getName(), storeKey.getType().getStoreClass());
        if (is == null) {
            throw new IndyClientException("No such store: %s. Cannot add to the implied-store list for: %s", storeKey, store.getKey());
        }
        stores.add(is);
    }
    try {
        metadataManager.addImpliedMetadata(store, stores);
    } catch (final ImpliedReposException e) {
        throw new IndyClientException("Failed to set implied-store metadata: %s", e, e.getMessage());
    }
    stores.add(store);
    for (final ArtifactStore toSave : stores) {
        logger.info("Updating implied-store metadata in: {} triggered by adding implications to: {}", toSave.getKey(), store.getKey());
        getClient().stores().update(toSave, changelog);
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Example 34 with StoreKey

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

the class ImpliedRepoMaintainer method updateImpliedStores.

// FIXME: How to tell whether a repo that is implied by other repos was added manually??? 
// That, vs. just left there after the repo that implied it was removed???
// We cannot currently remove formerly implied repos because we can't distinguish between the above states.
public void updateImpliedStores(@Observes final ArtifactStorePreUpdateEvent event) {
    if (!storeManager.isStarted()) {
        return;
    }
    if (!config.isEnabled()) {
        logger.debug("Implied-repository processing is not enabled.");
        return;
    }
    try {
        // TODO: Update for changes map.
        final Map<StoreKey, ArtifactStore> currentStores = mapStores(event);
        for (final ArtifactStore store : event) {
            logger.debug("Processing store: {} for implied repo metadata", store);
            processStore(store, currentStores);
        }
    } catch (Throwable error) {
        Logger logger = LoggerFactory.getLogger(getClass());
        logger.error(String.format("Implied-repository maintenance failed: %s", error.getMessage()), error);
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 35 with StoreKey

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

the class ImpliedRepositoryDetector method updateExistingGroups.

private boolean updateExistingGroups(final ImplicationsJob job) {
    final StoreKey key = job.store.getKey();
    boolean anyChanged = false;
    try {
        final Set<Group> groups = storeManager.query().packageType(MAVEN_PKG_KEY).getGroupsContaining(key);
        if (groups != null) {
            logger.debug("{} groups contain: {}\n  {}", groups.size(), key, new JoinString("\n  ", groups));
            final String message = String.format("Adding repositories implied by: %s\n\n  %s", key, StringUtils.join(job.implied, "\n  "));
            final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, message);
            for (final Group g : groups) {
                Group group = g.copyOf();
                boolean changed = false;
                for (final ArtifactStore implied : job.implied) {
                    boolean groupChanged = group.addConstituent(implied);
                    changed = groupChanged || changed;
                    logger.debug("After attempting to add: {} to group: {}, changed status is: {}", implied, group, changed);
                }
                if (changed) {
                    storeManager.storeArtifactStore(group, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_REPOS, job.implied));
                }
                anyChanged = changed || anyChanged;
            }
        }
    } catch (final IndyDataException e) {
        logger.error("Failed to lookup groups containing: " + key, e);
    }
    return anyChanged;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

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