Search in sources :

Example 41 with ArtifactStore

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

the class StoreAdminHandler method revalidateArtifactStore.

@ApiOperation("Revalidation of Artifact Stored on demand based on package, type and name")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repository was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/{name}/revalidate")
@POST
public Response revalidateArtifactStore(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name) {
    ArtifactStoreValidateData result = null;
    Response response;
    try {
        final StoreType st = StoreType.get(type);
        final StoreKey key = new StoreKey(packageType, st, name);
        final ArtifactStore store = adminController.get(key);
        logger.info("=> Returning repository: {}", store);
        // Validate this Store
        result = adminController.validateStore(store);
        logger.warn("=> Result from Validating Store: " + result);
        if (result == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else {
            response = responseHelper.formatOkResponseWithJsonEntity(result);
        }
    } catch (IndyDataException ide) {
        logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
        response = responseHelper.formatResponse(ide);
    } catch (MalformedURLException mue) {
        logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
        response = responseHelper.formatResponse(mue);
    } catch (IndyWorkflowException iwe) {
        logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
        response = responseHelper.formatResponse(iwe);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) MalformedURLException(java.net.MalformedURLException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 42 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore 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 43 with ArtifactStore

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

the class PrefetchManager method registerPrefetchStores.

public void registerPrefetchStores(@Observes final ArtifactStorePostUpdateEvent updateEvent) {
    if (config.isEnabled()) {
        logger.trace("Post update triggered for scheduling of prefetch: {}", updateEvent);
        final Collection<ArtifactStore> stores = updateEvent.getStores();
        boolean scheduled = false;
        for (ArtifactStore changedStore : stores) {
            if (changedStore.getType() == StoreType.remote) {
                ArtifactStore origStore = updateEvent.getOriginal(changedStore);
                final RemoteRepository changedRemote = (RemoteRepository) changedStore;
                final RemoteRepository origRemote = (RemoteRepository) origStore;
                final boolean remotePrefetchEnabled = (origRemote != null && !origRemote.getPrefetchPriority().equals(changedRemote.getPrefetchPriority())) && changedRemote.getPrefetchPriority() > 0;
                if (remotePrefetchEnabled) {
                    List<RescanablePath> paths = frontier.buildPaths(changedRemote, false);
                    logger.trace("Schedule resources: repo: {}, paths {}", changedRemote, paths);
                    frontier.scheduleRepo(changedRemote, paths);
                    scheduled = true;
                }
            }
        }
        if (scheduled) {
            triggerWorkers();
        }
    }
}
Also used : RescanablePath(org.commonjava.indy.subsys.prefetch.models.RescanablePath) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Example 44 with ArtifactStore

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

the class RepositoryDataManagerTCK method createTwoReposAndRetrieveAll.

@Test
public void createTwoReposAndRetrieveAll() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final RemoteRepository repo = new RemoteRepository("central", "http://repo1.maven.apache.org/maven2/");
    storeRemoteRepository(repo);
    final RemoteRepository repo2 = new RemoteRepository("test", "http://www.google.com");
    storeRemoteRepository(repo2);
    final List<RemoteRepository> repositories = manager.query().getAllRemoteRepositories(MAVEN_PKG_KEY);
    assertThat(repositories, notNullValue());
    assertThat(repositories.size(), equalTo(2));
    Collections.sort(repositories, new Comparator<RemoteRepository>() {

        @Override
        public int compare(final RemoteRepository r1, final RemoteRepository r2) {
            return r1.getName().compareTo(r2.getName());
        }
    });
    ArtifactStore r = repositories.get(0);
    assertThat(r.getName(), equalTo(repo.getName()));
    r = repositories.get(1);
    assertThat(r.getName(), equalTo(repo2.getName()));
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreDataManager(org.commonjava.indy.data.StoreDataManager) Test(org.junit.Test)

Example 45 with ArtifactStore

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

the class KojiRepairManager method repairPathMask.

public KojiRepairResult repairPathMask(KojiRepairRequest request, String user, boolean skipLock) throws KojiRepairException {
    KojiRepairResult ret = new KojiRepairResult(request);
    if (skipLock || opLock.tryLock()) {
        try {
            ArtifactStore store = getRequestedStore(request, ret);
            if (store == null) {
                return ret;
            }
            store = store.copyOf();
            StoreKey remoteKey = request.getSource();
            if (remoteKey.getType() == remote) {
                final String nvr = kojiUtils.getBuildNvr(remoteKey);
                if (nvr == null) {
                    String error = String.format("Not a koji store: %s", remoteKey);
                    return ret.withError(error);
                }
                try {
                    KojiSessionInfo session = null;
                    KojiBuildInfo build = kojiCachedClient.getBuildInfo(nvr, session);
                    List<KojiArchiveInfo> archives = kojiCachedClient.listArchivesForBuild(build.getId(), session);
                    ArtifactRef artifactRef = SimpleArtifactRef.parse(store.getMetadata(CREATION_TRIGGER_GAV));
                    if (artifactRef == null) {
                        String error = String.format("Koji remote repository: %s does not have %s metadata. Cannot retrieve accurate path masks.", remoteKey, CREATION_TRIGGER_GAV);
                        return ret.withError(error);
                    }
                    // set pathMaskPatterns using build output paths
                    Set<String> patterns = kojiPathFormatter.getPatterns(store.getKey(), artifactRef, archives, true);
                    logger.debug("For repo: {}, resetting path_mask_patterns to:\n\n{}\n\n", store.getKey(), patterns);
                    KojiRepairResult.RepairResult repairResult = new KojiRepairResult.RepairResult(remoteKey);
                    repairResult.withPropertyChange("path_mask_patterns", store.getPathMaskPatterns(), patterns);
                    ret.withResult(repairResult);
                    store.setPathMaskPatterns(patterns);
                    final ChangeSummary changeSummary = new ChangeSummary(user, "Repairing remote repository path masks to Koji build: " + build.getNvr());
                    storeManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
                } catch (KojiClientException e) {
                    String error = String.format("Cannot getBuildInfo: %s, error: %s", remoteKey, e);
                    logger.debug(error, e);
                    return ret.withError(error, e);
                } catch (IndyDataException e) {
                    String error = String.format("Failed to store changed remote repository: %s, error: %s", remoteKey, e);
                    logger.debug(error, e);
                    return ret.withError(error, e);
                }
            } else {
                String error = String.format("Not a remote koji repository: %s", remoteKey);
                return ret.withError(error);
            }
        } finally {
            if (!skipLock) {
                opLock.unlock();
            }
        }
    } else {
        throw new KojiRepairException("Koji repair manager is busy.");
    }
    return ret;
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) KojiClientException(com.redhat.red.build.koji.KojiClientException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)168 IndyDataException (org.commonjava.indy.data.IndyDataException)90 StoreKey (org.commonjava.indy.model.core.StoreKey)83 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)54 Logger (org.slf4j.Logger)45 ArrayList (java.util.ArrayList)43 Group (org.commonjava.indy.model.core.Group)42 StoreType (org.commonjava.indy.model.core.StoreType)38 Transfer (org.commonjava.maven.galley.model.Transfer)38 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)33 IOException (java.io.IOException)29 HashSet (java.util.HashSet)29 List (java.util.List)28 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)26 LoggerFactory (org.slf4j.LoggerFactory)25 StoreDataManager (org.commonjava.indy.data.StoreDataManager)24 Set (java.util.Set)23 Inject (javax.inject.Inject)22 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17