Search in sources :

Example 21 with StoreKey

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

the class HttpProxyTest method proxy404.

@Test
public void proxy404() throws Exception {
    final String testRepo = "test";
    final PomRef pom = loadPom("simple.pom", Collections.<String, String>emptyMap());
    final String url = server.formatUrl(testRepo, pom.path);
    final HttpGet get = new HttpGet(url);
    final CloseableHttpClient client = proxiedHttp();
    CloseableHttpResponse response = null;
    final InputStream stream = null;
    try {
        response = client.execute(get, proxyContext(USER, PASS));
        assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_NOT_FOUND));
    } finally {
        IOUtils.closeQuietly(stream);
        HttpUtil.cleanupResources(client, get, response);
    }
    final RemoteRepository remoteRepo = (RemoteRepository) storeManager.getArtifactStore(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1_" + server.getPort()));
    assertThat(remoteRepo, notNullValue());
    assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri()));
}
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) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 22 with StoreKey

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

the class AutoCreateRepoAndRetrievePomTest 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);
    final HttpGet get = new HttpGet(url);
    CloseableHttpClient client = proxiedHttp();
    CloseableHttpResponse response = null;
    InputStream stream = null;
    try {
        response = client.execute(get, proxyContext(USER, PASS));
        stream = response.getEntity().getContent();
        final String resultingPom = IOUtils.toString(stream);
        assertThat(resultingPom, notNullValue());
        assertThat(resultingPom, equalTo(pom.pom));
    } finally {
        IOUtils.closeQuietly(stream);
        HttpResources.cleanupResources(get, response, client);
    }
    final RemoteRepository remoteRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1_" + server.getPort()), RemoteRepository.class);
    assertThat(remoteRepo, notNullValue());
    assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri()));
    String pomUrl = this.client.content().contentUrl(remoteRepo.getKey(), testRepo, pom.path) + "?cache-only=true";
    HttpHead head = new HttpHead(pomUrl);
    client = HttpClients.createDefault();
    try {
        response = client.execute(head);
        assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
    } finally {
        HttpResources.cleanupResources(head, response, client);
    }
}
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) StoreKey(org.commonjava.indy.model.core.StoreKey) HttpHead(org.apache.http.client.methods.HttpHead) Test(org.junit.Test)

Example 23 with StoreKey

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

the class StoreEnablementManager method onStoreError.

//    public void onStoreUpdate( @Observes ArtifactStorePostUpdateEvent event )
//    {
//        for ( ArtifactStore store : event )
//        {
//            if ( store.isDisabled() )
//            {
//                String toStr = store.getMetadata( DISABLE_TIMEOUT );
//                if ( isNotEmpty( toStr ) )
//                {
//                    int timeout = Integer.parseInt( toStr );
//                    try
//                    {
//                        setReEnablementTimeout( store.getKey(), timeout );
//                    }
//                    catch ( IndySchedulerException e )
//                    {
//                        Logger logger = LoggerFactory.getLogger( getClass() );
//                        logger.error( String.format( "Failed to schedule re-enablement of %s.", store.getKey() ), e );
//                    }
//                }
//            }
////            else
////            {
////                try
////                {
////                    cancelReEnablementTimeout( store.getKey() );
////                }
////                catch ( IndySchedulerException e )
////                {
////                    Logger logger = LoggerFactory.getLogger( getClass() );
////                    logger.error( String.format( "Failed to delete re-enablement job for %s.", store.getKey() ), e );
////                }
////            }
//        }
//    }
public void onStoreError(@Observes IndyStoreErrorEvent evt) {
    Logger logger = LoggerFactory.getLogger(getClass());
    StoreKey key = evt.getStoreKey();
    Throwable error = evt.getError();
    try {
        ArtifactStore store = storeDataManager.getArtifactStore(key);
        if (store.getDisableTimeout() <= TIMEOUT_NEVER_DISABLE) {
            logger.debug("Disable-timeout set to {}, will never disable the repo", store.getDisableTimeout());
            store.setDisabled(false);
        } else {
            store.setDisabled(true);
        }
        final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, String.format("Disabling %s due to error: %s\n\nStack Trace:\n  %s", key, error, StringUtils.join(error.getStackTrace(), "\n  ")));
        storeDataManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
        logger.warn("{} has been disabled due to store-level error: {}\n Will re-enable in {} seconds.", key, error, config.getStoreDisableTimeoutSeconds());
        // TODO: How is it this doesn't duplicate the event handler method onStoreUpdate()...we're updating the store just above here.
        setReEnablementTimeout(key);
    } catch (IndyDataException e) {
        logger.error(String.format("Failed to disable %s on error: %s", key, error), e);
    } catch (IndySchedulerException e) {
        logger.error(String.format("Failed to schedule re-enablement of %s for retry.", key), e);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) IndySchedulerException(org.commonjava.indy.core.expire.IndySchedulerException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 24 with StoreKey

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

the class StoreEnablementManager method onDisableTimeout.

public void onDisableTimeout(@Observes SchedulerEvent evt) {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Checking for store-reenable event in: {} (trigger? {} Disable-Timeout? {})", evt, evt instanceof SchedulerTriggerEvent, DISABLE_TIMEOUT.equals(evt.getJobType()));
    if ((evt instanceof SchedulerTriggerEvent) && DISABLE_TIMEOUT.equals(evt.getJobType())) {
        String keystr = evt.getPayload();
        StoreKey key = null;
        try {
            key = objectMapper.readValue(keystr, StoreKey.class);
        } catch (IOException e) {
            logger.warn("Failed to read StoreKey from JSON string: '{}' in event payload.", keystr);
        }
        logger.debug("Read key: {} from JSON string: '{}' in event payload.", key, keystr);
        if (key != null) {
            try {
                ArtifactStore store = storeDataManager.getArtifactStore(key);
                if (store.isDisabled()) {
                    store.setDisabled(false);
                    storeDataManager.storeArtifactStore(store, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Re-enabling " + key), false, true, new EventMetadata());
                    cancelReEnablementTimeout(key);
                }
            } catch (IndyDataException e) {
                logger.error(String.format("Failed to re-enable %s", key), e);
            } catch (IndySchedulerException e) {
                logger.error(String.format("Failed to delete re-enablement job for %s.", key), e);
            }
        }
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) SchedulerTriggerEvent(org.commonjava.indy.core.expire.SchedulerTriggerEvent) IOException(java.io.IOException) Logger(org.slf4j.Logger) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) IndySchedulerException(org.commonjava.indy.core.expire.IndySchedulerException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 25 with StoreKey

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

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