Search in sources :

Example 21 with RemoteRepository

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

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

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

the class StoreDataSetupAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Initializing default data.");
    boolean changed = false;
    try {
        logger.info("Verfiying that Indy basic stores are installed...");
        storeManager.install();
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(RemoteRepository.class).containsByName("central")) {
            final RemoteRepository central = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2/");
            central.setCacheTimeoutSeconds(86400);
            storeManager.storeArtifactStore(central, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(HostedRepository.class).containsByName("local-deployments")) {
            final HostedRepository local = new HostedRepository(MAVEN_PKG_KEY, "local-deployments");
            local.setAllowReleases(true);
            local.setAllowSnapshots(true);
            local.setSnapshotTimeoutSeconds(86400);
            storeManager.storeArtifactStore(local, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(Group.class).containsByName("public")) {
            final Group pub = new Group(MAVEN_PKG_KEY, "public");
            pub.addConstituent(new StoreKey(MAVEN_PKG_KEY, StoreType.remote, "central"));
            pub.addConstituent(new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, "local-deployments"));
            storeManager.storeArtifactStore(pub, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
    } catch (final IndyDataException e) {
        throw new RuntimeException("Failed to boot indy components: " + e.getMessage(), e);
    }
    return changed;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 24 with RemoteRepository

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

the class ScheduleManager method setProxyTimeouts.

public synchronized void setProxyTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
    if (!schedulerConfig.isEnabled()) {
        logger.debug("Scheduler disabled.");
        return;
    }
    RemoteRepository repo = null;
    try {
        repo = (RemoteRepository) dataManager.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
    }
    if (repo == null) {
        return;
    }
    int timeout = config.getPassthroughTimeoutSeconds();
    final ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(repo), path);
    final SpecialPathInfo info = specialPathManager.getSpecialPathInfo(resource);
    if (!repo.isPassthrough()) {
        if ((info != null && info.isMetadata()) && repo.getMetadataTimeoutSeconds() > 0) {
            logger.debug("Using metadata timeout for: {}", resource);
            timeout = repo.getMetadataTimeoutSeconds();
        } else {
            if (info == null) {
                logger.debug("No special path info for: {}", resource);
            } else {
                logger.debug("{} is a special path, but not metadata.", resource);
            }
            timeout = repo.getCacheTimeoutSeconds();
        }
    }
    if (timeout > 0) {
        //            logger.info( "[PROXY TIMEOUT SET] {}/{}; {}", repo.getKey(), path, new Date( System.currentTimeMillis()
        //                + timeout ) );
        cancel(new StoreKeyMatcher(key, CONTENT_JOB_TYPE), path);
        scheduleContentExpiration(key, path, timeout);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Example 25 with RemoteRepository

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

Aggregations

RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)149 Test (org.junit.Test)99 InputStream (java.io.InputStream)52 Group (org.commonjava.indy.model.core.Group)48 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)32 StoreKey (org.commonjava.indy.model.core.StoreKey)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 File (java.io.File)17 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)17 HostedRepository (org.commonjava.indy.model.core.HostedRepository)17 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)16 IndyDataException (org.commonjava.indy.data.IndyDataException)14 Before (org.junit.Before)13 Category (org.junit.experimental.categories.Category)12 Date (java.util.Date)10 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)10 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9