Search in sources :

Example 81 with ArtifactStore

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

the class ReplicationController method getRemoteStores.

// FIXME: Find a better solution to the passed-in generic deserialization problem...erasure is a mother...
private List<? extends ArtifactStore> getRemoteStores(final ReplicationDTO dto) throws IndyWorkflowException {
    final String apiUrl = dto.getApiUrl();
    String remotesUrl = null;
    String groupsUrl = null;
    String hostedUrl = null;
    try {
        remotesUrl = buildUrl(apiUrl, "/admin/remotes");
        groupsUrl = buildUrl(apiUrl, "/admin/groups");
        hostedUrl = buildUrl(apiUrl, "/admin/hosted");
    } catch (final MalformedURLException e) {
        throw new IndyWorkflowException("Failed to construct store definition-retrieval URL from api-base: {}. Reason: {}", e, apiUrl, e.getMessage());
    }
    //        logger.info( "\n\n\n\n\n[AutoProx] Checking URL: {} from:", new Throwable(), url );
    final List<ArtifactStore> result = new ArrayList<ArtifactStore>();
    addStoresFrom(result, remotesUrl, dto, RemoteRepository.class);
    addStoresFrom(result, groupsUrl, dto, Group.class);
    addStoresFrom(result, hostedUrl, dto, HostedRepository.class);
    return result;
}
Also used : MalformedURLException(java.net.MalformedURLException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList)

Example 82 with ArtifactStore

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

the class ReplicationController method replicate.

public Set<StoreKey> replicate(final ReplicationDTO dto, final String user) throws IndyWorkflowException {
    final ReplicationRepositoryCreator creator = createRepoCreator();
    if (creator == null) {
        throw new IndyWorkflowException(500, "Cannot replicate; ReplicationRepositoryCreator could not be instantiated.");
    }
    try {
        dto.validate();
    } catch (final IndyException e) {
        throw new IndyWorkflowException("Invalid replication request DTO: %s", e, e.getMessage());
    }
    List<? extends ArtifactStore> remoteStores = null;
    List<EndpointView> remoteEndpoints = null;
    final boolean overwrite = dto.isOverwrite();
    final Set<StoreKey> replicated = new HashSet<StoreKey>();
    for (final ReplicationAction action : dto) {
        if (action == null) {
            continue;
        }
        logger.info("Processing replication action:\n\n  {}\n\nin DTO: {}\n\n", action, dto);
        final String include = action.getInclude();
        final String exclude = action.getExclude();
        try {
            if (action.getType() == ActionType.PROXY) {
                if (remoteEndpoints == null) {
                    remoteEndpoints = getEndpoints(dto);
                }
                for (final EndpointView view : remoteEndpoints) {
                    final String key = "remote-" + view.getType() + "_" + view.getName();
                    if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
                        final StoreKey sk = new StoreKey(StoreType.remote, key);
                        if (overwrite || !data.hasArtifactStore(sk)) {
                            RemoteRepository repo = creator.createRemoteRepository(key, view);
                            repo.setMetadata(ArtifactStore.METADATA_ORIGIN, REPLICATION_ORIGIN);
                            setProxyAttributes(repo, action);
                            data.storeArtifactStore(repo, new ChangeSummary(user, "REPLICATION: Proxying remote indy repository: " + view.getResourceUri()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
                            replicated.add(repo.getKey());
                        }
                    }
                }
            } else if (action.getType() == ActionType.MIRROR) {
                if (remoteStores == null) {
                    remoteStores = getRemoteStores(dto);
                }
                for (final ArtifactStore store : remoteStores) {
                    final String key = store.getKey().toString();
                    if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
                        if (overwrite || !data.hasArtifactStore(store.getKey())) {
                            if (store instanceof RemoteRepository) {
                                setProxyAttributes(((RemoteRepository) store), action);
                            }
                            data.storeArtifactStore(store, new ChangeSummary(user, "REPLICATION: Mirroring remote indy store: " + store.getKey()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
                            replicated.add(store.getKey());
                        }
                    }
                }
            }
        } catch (final IndyDataException e) {
            logger.error(e.getMessage(), e);
            throw new IndyWorkflowException(e.getMessage(), e);
        }
    }
    return replicated;
}
Also used : EndpointView(org.commonjava.indy.model.core.dto.EndpointView) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyException(org.commonjava.indy.IndyException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ReplicationAction(org.commonjava.indy.model.core.dto.ReplicationAction) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HashSet(java.util.HashSet)

Example 83 with ArtifactStore

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

the class ContentController method rescanAll.

public void rescanAll(final EventMetadata eventMetadata) throws IndyWorkflowException {
    try {
        final List<ArtifactStore> stores = storeManager.query().concreteStores().getAll();
        contentManager.rescanAll(stores, eventMetadata);
    } catch (final IndyDataException e) {
        throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to retrieve list of concrete stores. Reason: {}", e, e.getMessage());
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException)

Example 84 with ArtifactStore

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

the class DefaultDownloadManager method store.

/*
     * (non-Javadoc)
     * @see org.commonjava.indy.core.rest.util.FileManager#upload(java.util.List, java.lang.String,
     * java.io.InputStream)
     */
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    final ContentQuality quality = getQuality(path);
    HostedRepository selected = null;
    for (final ArtifactStore store : stores) {
        if (storeManager.isReadonly(store)) {
            logger.info("The store {} is readonly, store operation not allowed");
            continue;
        }
        if (storeIsSuitableFor(store, quality, op)) {
            selected = (HostedRepository) store;
            break;
        }
    }
    if (selected == null) {
        logger.warn("Cannot deploy. No valid deploy points in group.");
        throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No deployment locations available.");
    }
    logger.info("Storing: {} in selected: {} with event metadata: {}", path, selected, eventMetadata);
    store(selected, path, stream, op, eventMetadata);
    return getStorageReference(selected.getKey(), path);
}
Also used : ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 85 with ArtifactStore

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

the class DefaultContentManager method retrieveAll.

@Override
public List<Transfer> retrieveAll(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    final List<Transfer> txfrs = new ArrayList<>();
    for (final ArtifactStore store : stores) {
        if (group == store.getKey().getType()) {
            List<ArtifactStore> members;
            try {
                members = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
            } catch (final IndyDataException e) {
                throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
            }
            final List<Transfer> storeTransfers = new ArrayList<>();
            for (final ContentGenerator generator : contentGenerators) {
                final Transfer txfr = generator.generateGroupFileContent((Group) store, members, path, eventMetadata);
                if (txfr != null) {
                    storeTransfers.add(txfr);
                }
            }
            // ...if it's generated, it's merged in this case.
            if (storeTransfers.isEmpty()) {
                for (final ArtifactStore member : members) {
                    // NOTE: This is only safe to call because we're concrete ordered stores, so anything passing through here is concrete.
                    final Transfer txfr = doRetrieve(member, path, eventMetadata);
                    if (txfr != null) {
                        storeTransfers.add(txfr);
                    }
                }
            }
            txfrs.addAll(storeTransfers);
        } else {
            // NOTE: This is only safe to call because we're doing the group check up front, so anything passing through here is concrete.
            final Transfer txfr = doRetrieve(store, path, eventMetadata);
            if (txfr != null) {
                txfrs.add(txfr);
            }
        }
    }
    return txfrs;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)93 IndyDataException (org.commonjava.indy.data.IndyDataException)54 StoreKey (org.commonjava.indy.model.core.StoreKey)46 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)35 Logger (org.slf4j.Logger)30 ArrayList (java.util.ArrayList)25 Transfer (org.commonjava.maven.galley.model.Transfer)25 Group (org.commonjava.indy.model.core.Group)20 StoreType (org.commonjava.indy.model.core.StoreType)19 IOException (java.io.IOException)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)17 HashSet (java.util.HashSet)15 List (java.util.List)15 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 StoreDataManager (org.commonjava.indy.data.StoreDataManager)10 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 Test (org.junit.Test)9 ApiOperation (io.swagger.annotations.ApiOperation)8