From: Olivier Lamy Date: Fri, 30 Sep 2011 13:36:56 +0000 (+0000) Subject: [MRM-1526] configure http connection pool values for wagon http. X-Git-Tag: archiva-1.4-M1~154 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e42e26c8e11f682494aaa9a42a79813c9fc3934b;p=archiva.git [MRM-1526] configure http connection pool values for wagon http. add basic services. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1177654 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index 763e5ee6f..b867ef7d8 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -157,7 +157,18 @@ The organisation info. - + + + networkConfiguration + 1.4.0+ + + NetworkConfiguration + 1 + + + The NetworkConfiguration . + + @@ -1277,6 +1288,37 @@ + + NetworkConfiguration + 1.4.0+ + + The network configuration for external http request to repositories. + + + + maxTotal + maximum total external http connections. + 1.4.0+ + int + 30 + + + maxTotalPerHost + maximum total external http connections per host + 1.4.0+ + int + 30 + + + usePooling + use or not http connection pooling default true + 1.4.0+ + boolean + true + + + + diff --git a/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/mock/MockArchivaAdministration.java b/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/mock/MockArchivaAdministration.java index fa34784db..93e6c33ac 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/mock/MockArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/mock/MockArchivaAdministration.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; +import org.apache.archiva.admin.model.beans.NetworkConfiguration; import org.apache.archiva.admin.model.beans.OrganisationInformation; import org.apache.archiva.admin.model.beans.UiConfiguration; @@ -160,4 +161,16 @@ public class MockArchivaAdministration { } + + public NetworkConfiguration getNetworkConfiguration() + throws RepositoryAdminException + { + return null; + } + + public void setNetworkConfiguration( NetworkConfiguration networkConfiguration ) + throws RepositoryAdminException + { + + } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java index bfd271ef4..975b045f3 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java @@ -22,6 +22,7 @@ import org.apache.archiva.admin.model.AuditInformation; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; +import org.apache.archiva.admin.model.beans.NetworkConfiguration; import org.apache.archiva.admin.model.beans.OrganisationInformation; import org.apache.archiva.admin.model.beans.UiConfiguration; @@ -97,4 +98,10 @@ public interface ArchivaAdministration void updateUiConfiguration( UiConfiguration uiConfiguration ) throws RepositoryAdminException; + NetworkConfiguration getNetworkConfiguration() + throws RepositoryAdminException; + + void setNetworkConfiguration( NetworkConfiguration networkConfiguration ) + throws RepositoryAdminException; + } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/NetworkConfiguration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/NetworkConfiguration.java new file mode 100644 index 000000000..26e732d73 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/NetworkConfiguration.java @@ -0,0 +1,97 @@ +package org.apache.archiva.admin.model.beans; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +@XmlRootElement( name = "networkConfiguration" ) +public class NetworkConfiguration + implements Serializable +{ + /** + * maximum total external http connections. + */ + private int maxTotal = 30; + + /** + * maximum total external http connections per host. + */ + private int maxTotalPerHost = 30; + + private boolean usePooling = true; + + public NetworkConfiguration() + { + // no op + } + + public NetworkConfiguration( int maxTotal, int maxTotalPerHost, boolean usePooling ) + { + this.maxTotal = maxTotal; + this.maxTotalPerHost = maxTotalPerHost; + this.usePooling = usePooling; + } + + public int getMaxTotal() + { + return maxTotal; + } + + public void setMaxTotal( int maxTotal ) + { + this.maxTotal = maxTotal; + } + + public int getMaxTotalPerHost() + { + return maxTotalPerHost; + } + + public void setMaxTotalPerHost( int maxTotalPerHost ) + { + this.maxTotalPerHost = maxTotalPerHost; + } + + public boolean isUsePooling() + { + return usePooling; + } + + public void setUsePooling( boolean usePooling ) + { + this.usePooling = usePooling; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "NetworkConfiguration" ); + sb.append( "{maxTotal=" ).append( maxTotal ); + sb.append( ", maxTotalPerHost=" ).append( maxTotalPerHost ); + sb.append( ", usePooling=" ).append( usePooling ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml index a2f4721da..232f246cd 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml @@ -66,6 +66,26 @@ + + org.apache.maven.wagon + wagon-http + + + commons-logging + commons-logging + + + + + org.apache.httpcomponents + httpclient + + + commons-logging + commons-logging + + + org.springframework spring-context-support diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java index 8cb88007f..6a6999c8e 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java @@ -24,6 +24,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; +import org.apache.archiva.admin.model.beans.NetworkConfiguration; import org.apache.archiva.admin.model.beans.OrganisationInformation; import org.apache.archiva.admin.model.beans.UiConfiguration; import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; @@ -32,6 +33,8 @@ import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.UserInterfaceOptions; import org.apache.archiva.configuration.WebappConfiguration; import org.apache.commons.lang.StringUtils; +import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; +import org.apache.maven.wagon.providers.http.HttpWagon; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -56,7 +59,6 @@ public class DefaultArchivaAdministration new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) ); } return legacyArtifactPaths; - } public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation ) @@ -323,7 +325,48 @@ public class DefaultArchivaAdministration } -//------------------------- + public NetworkConfiguration getNetworkConfiguration() + throws RepositoryAdminException + { + org.apache.archiva.configuration.NetworkConfiguration networkConfiguration = + getArchivaConfiguration().getConfiguration().getNetworkConfiguration(); + + if ( networkConfiguration == null ) + { + return null; + } + return new BeanReplicator().replicateBean( networkConfiguration, NetworkConfiguration.class ); + } + + public void setNetworkConfiguration( NetworkConfiguration networkConfiguration ) + throws RepositoryAdminException + { + Configuration configuration = getArchivaConfiguration().getConfiguration(); + if ( networkConfiguration == null ) + { + configuration.setNetworkConfiguration( null ); + // back to default values + HttpWagon.setUseClientManagerPooled( true ); + ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager(); + threadSafeClientConnManager.setDefaultMaxPerRoute( 30 ); + threadSafeClientConnManager.setMaxTotal( 30 ); + HttpWagon.setConnectionManagerPooled( threadSafeClientConnManager ); + + } + else + { + HttpWagon.setUseClientManagerPooled( networkConfiguration.isUsePooling() ); + ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager(); + threadSafeClientConnManager.setDefaultMaxPerRoute( networkConfiguration.getMaxTotalPerHost() ); + threadSafeClientConnManager.setMaxTotal( networkConfiguration.getMaxTotal() ); + HttpWagon.setConnectionManagerPooled( threadSafeClientConnManager ); + configuration.setNetworkConfiguration( new BeanReplicator().replicateBean( networkConfiguration, + org.apache.archiva.configuration.NetworkConfiguration.class ) ); + } + saveConfiguration( configuration ); + } + + //------------------------- // //------------------------- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java index 1a3e153fa..59165ba5c 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java @@ -22,6 +22,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; +import org.apache.archiva.admin.model.beans.NetworkConfiguration; import org.apache.archiva.admin.model.beans.OrganisationInformation; import org.apache.archiva.admin.model.beans.UiConfiguration; import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest; @@ -219,4 +220,16 @@ public class ArchivaAdministrationTest assertFalse( ui.isAppletFindEnabled() ); assertFalse( ui.isShowFindArtifacts() ); } + + @Test + public void networkConfiguration() + throws Exception + { + NetworkConfiguration networkConfiguration = archivaAdministration.getNetworkConfiguration(); + assertNotNull( networkConfiguration ); + + assertTrue( networkConfiguration.isUsePooling() ); + assertEquals( 30, networkConfiguration.getMaxTotal() ); + assertEquals( 30, networkConfiguration.getMaxTotalPerHost() ); + } } diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/ArchivaAdministrationStub.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/ArchivaAdministrationStub.java index 671a48598..57041e32d 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/ArchivaAdministrationStub.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/ArchivaAdministrationStub.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; +import org.apache.archiva.admin.model.beans.NetworkConfiguration; import org.apache.archiva.admin.model.beans.OrganisationInformation; import org.apache.archiva.admin.model.beans.UiConfiguration; import org.apache.archiva.configuration.ArchivaConfiguration; @@ -174,6 +175,19 @@ public class ArchivaAdministrationStub public void updateUiConfiguration( UiConfiguration uiConfiguration ) throws RepositoryAdminException { - //To change body of implemented methods use File | Settings | File Templates. + + } + + + public NetworkConfiguration getNetworkConfiguration() + throws RepositoryAdminException + { + return null; + } + + public void setNetworkConfiguration( NetworkConfiguration networkConfiguration ) + throws RepositoryAdminException + { + } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockArchivaAdministration.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockArchivaAdministration.java index f87f1b7f9..2cb62ef78 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockArchivaAdministration.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockArchivaAdministration.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; +import org.apache.archiva.admin.model.beans.NetworkConfiguration; import org.apache.archiva.admin.model.beans.OrganisationInformation; import org.apache.archiva.admin.model.beans.UiConfiguration; import org.apache.archiva.configuration.ArchivaConfiguration; @@ -175,4 +176,16 @@ public class MockArchivaAdministration { } + + public NetworkConfiguration getNetworkConfiguration() + throws RepositoryAdminException + { + return null; + } + + public void setNetworkConfiguration( NetworkConfiguration networkConfiguration ) + throws RepositoryAdminException + { + + } } diff --git a/pom.xml b/pom.xml index 9a8b9cf02..0f18f5086 100644 --- a/pom.xml +++ b/pom.xml @@ -1056,6 +1056,17 @@ + + org.apache.httpcomponents + httpclient + 4.1.2 + + + commons-logging + commons-logging + + + org.apache.maven.wagon wagon-provider-api