Search in sources :

Example 1 with EndpointView

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

the class StatsController method getEndpointsListing.

public EndpointViewListing getEndpointsListing(final String baseUri, final UriFormatter uriFormatter) throws IndyWorkflowException {
    final List<ArtifactStore> stores = new ArrayList<ArtifactStore>();
    try {
        stores.addAll(dataManager.getAllArtifactStores());
    } catch (final IndyDataException e) {
        throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to retrieve all endpoints: {}", e, e.getMessage());
    }
    final List<EndpointView> points = new ArrayList<EndpointView>();
    for (final ArtifactStore store : stores) {
        final StoreKey key = store.getKey();
        final String resourceUri = uriFormatter.formatAbsolutePathTo(baseUri, "content", key.getPackageType(), key.getType().singularEndpointName(), key.getName());
        final EndpointView point = new EndpointView(store, resourceUri);
        if (!points.contains(point)) {
            points.add(point);
        }
    }
    return new EndpointViewListing(points);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) EndpointView(org.commonjava.indy.model.core.dto.EndpointView) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 2 with EndpointView

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

the class CreateHostedStoreAndVerifyUrlInAllEndpointsTest method verifyHostedStoreUrlsEndpoints.

@Test
public void verifyHostedStoreUrlsEndpoints() throws Exception {
    final EndpointViewListing endpoints = client.stats().getAllEndpoints();
    for (final EndpointView endpoint : endpoints) {
        final String endpointUrl = client.content().contentUrl(endpoint.getStoreKey());
        assertThat("Resource URI: '" + endpoint.getResourceUri() + "' for endpoint: " + endpoint.getKey() + " should be: '" + endpointUrl + "'", endpoint.getResourceUri(), equalTo(endpointUrl));
    }
}
Also used : EndpointView(org.commonjava.indy.model.core.dto.EndpointView) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) Test(org.junit.Test)

Example 3 with EndpointView

use of org.commonjava.indy.model.core.dto.EndpointView 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)

Aggregations

EndpointView (org.commonjava.indy.model.core.dto.EndpointView)3 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 IndyDataException (org.commonjava.indy.data.IndyDataException)2 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 EndpointViewListing (org.commonjava.indy.model.core.dto.EndpointViewListing)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IndyException (org.commonjava.indy.IndyException)1 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1 ReplicationAction (org.commonjava.indy.model.core.dto.ReplicationAction)1 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)1 Test (org.junit.Test)1