You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2013/12/22 13:25:24 UTC

svn commit: r1552981 - in /archiva/trunk/archiva-modules: archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ ar...

Author: olamy
Date: Sun Dec 22 12:25:23 2013
New Revision: 1552981

URL: http://svn.apache.org/r1552981
Log:
[MRM-1750] Add remote repository health check
Add rest api

Modified:
    archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RemoteRepositoriesService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java

Modified: archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java?rev=1552981&r1=1552980&r2=1552981&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java (original)
+++ archiva/trunk/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java Sun Dec 22 12:25:23 2013
@@ -135,19 +135,18 @@ public class DownloadRemoteIndexTask
             final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(
                 new WagonFactoryRequest( wagonProtocol, this.remoteRepository.getExtraHeaders() ).networkProxy(
                     this.networkProxy ) );
-            int timeoutInMilliseconds = remoteRepository.getTimeout() * 1000;
             // FIXME olamy having 2 config values
-            wagon.setReadTimeout( timeoutInMilliseconds );
-            wagon.setTimeout( timeoutInMilliseconds );
+            wagon.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
+            wagon.setTimeout( remoteRepository.getTimeout() * 1000 );
 
             if ( wagon instanceof AbstractHttpClientWagon )
             {
                 HttpConfiguration httpConfiguration = new HttpConfiguration();
                 HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
                 httpMethodConfiguration.setUsePreemptive( true );
-                httpMethodConfiguration.setReadTimeout( timeoutInMilliseconds );
+                httpMethodConfiguration.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
                 httpConfiguration.setGet( httpMethodConfiguration );
-                ( (AbstractHttpClientWagon) wagon ).setHttpConfiguration( httpConfiguration );
+                AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
             }
 
             wagon.addTransferListener( new DownloadListener() );

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RemoteRepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RemoteRepositoriesService.java?rev=1552981&r1=1552980&r2=1552981&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RemoteRepositoriesService.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RemoteRepositoriesService.java Sun Dec 22 12:25:23 2013
@@ -36,47 +36,52 @@ import java.util.List;
  * @author Olivier Lamy
  * @since 1.4-M1
  */
-@Path( "/remoteRepositoriesService/" )
+@Path("/remoteRepositoriesService/")
 public interface RemoteRepositoriesService
 {
-    @Path( "getRemoteRepositories" )
+    @Path("getRemoteRepositories")
     @GET
-    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
     List<RemoteRepository> getRemoteRepositories()
         throws ArchivaRestServiceException;
 
-    @Path( "getRemoteRepository/{repositoryId}" )
+    @Path("getRemoteRepository/{repositoryId}")
     @GET
-    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
-    RemoteRepository getRemoteRepository( @PathParam( "repositoryId" ) String repositoryId )
+    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    RemoteRepository getRemoteRepository( @PathParam("repositoryId") String repositoryId )
         throws ArchivaRestServiceException;
 
-    @Path( "deleteRemoteRepository/{repositoryId}" )
+    @Path("deleteRemoteRepository/{repositoryId}")
     @GET
-    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
-    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
-    Boolean deleteRemoteRepository( @PathParam( "repositoryId" ) String repositoryId )
-        throws Exception;
+    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    Boolean deleteRemoteRepository( @PathParam("repositoryId") String repositoryId )
+        throws ArchivaRestServiceException;
 
 
-    @Path( "addRemoteRepository" )
+    @Path("addRemoteRepository")
     @POST
-    @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
-    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
     Boolean addRemoteRepository( RemoteRepository remoteRepository )
-        throws Exception;
+        throws ArchivaRestServiceException;
 
 
-    @Path( "updateRemoteRepository" )
+    @Path("updateRemoteRepository")
     @POST
-    @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
-    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
     Boolean updateRemoteRepository( RemoteRepository remoteRepository )
-        throws Exception;
-
+        throws ArchivaRestServiceException;
 
+    @Path("checkRemoteConnectivity/{repositoryId}")
+    @GET
+    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    Boolean checkRemoteConnectivity( @PathParam( "repositoryId" ) String repositoryId )
+        throws ArchivaRestServiceException;
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml?rev=1552981&r1=1552980&r2=1552981&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml Sun Dec 22 12:25:23 2013
@@ -159,6 +159,12 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
       <groupId>commons-validator</groupId>
       <artifactId>commons-validator</artifactId>
     </dependency>

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java?rev=1552981&r1=1552980&r2=1552981&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java Sun Dec 22 12:25:23 2013
@@ -19,14 +19,30 @@ package org.apache.archiva.rest.services
  */
 
 import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.beans.NetworkProxy;
 import org.apache.archiva.admin.model.beans.RemoteRepository;
+import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
+import org.apache.archiva.proxy.common.WagonFactory;
+import org.apache.archiva.proxy.common.WagonFactoryException;
+import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
 import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
 import org.apache.commons.lang.StringUtils;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.StreamWagon;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.maven.wagon.providers.http.AbstractHttpClientWagon;
+import org.apache.maven.wagon.providers.http.HttpConfiguration;
+import org.apache.maven.wagon.providers.http.HttpMethodConfiguration;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
+import javax.ws.rs.core.Response;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Collections;
 import java.util.List;
 
@@ -34,7 +50,7 @@ import java.util.List;
  * @author Olivier Lamy
  * @since 1.4-M1
  */
-@Service ("remoteRepositoriesService#rest")
+@Service( "remoteRepositoriesService#rest" )
 public class DefaultRemoteRepositoriesService
     extends AbstractRestService
     implements RemoteRepositoriesService
@@ -43,6 +59,13 @@ public class DefaultRemoteRepositoriesSe
     @Inject
     private RemoteRepositoryAdmin remoteRepositoryAdmin;
 
+    @Inject
+    private WagonFactory wagonFactory;
+
+
+    @Inject
+    private NetworkProxyAdmin networkProxyAdmin;
+
     public List<RemoteRepository> getRemoteRepositories()
         throws ArchivaRestServiceException
     {
@@ -74,7 +97,7 @@ public class DefaultRemoteRepositoriesSe
     }
 
     public Boolean deleteRemoteRepository( String repositoryId )
-        throws Exception
+        throws ArchivaRestServiceException
     {
         try
         {
@@ -88,7 +111,7 @@ public class DefaultRemoteRepositoriesSe
     }
 
     public Boolean addRemoteRepository( RemoteRepository remoteRepository )
-        throws Exception
+        throws ArchivaRestServiceException
     {
         try
         {
@@ -102,7 +125,7 @@ public class DefaultRemoteRepositoriesSe
     }
 
     public Boolean updateRemoteRepository( RemoteRepository remoteRepository )
-        throws Exception
+        throws ArchivaRestServiceException
     {
         try
         {
@@ -115,5 +138,84 @@ public class DefaultRemoteRepositoriesSe
         }
     }
 
+    @Override
+    public Boolean checkRemoteConnectivity( String repositoryId )
+        throws ArchivaRestServiceException
+    {
+        try
+        {
+            RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository( repositoryId );
+            if ( remoteRepository == null )
+            {
+                log.warn( "ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId );
+                return Boolean.FALSE;
+            }
+            NetworkProxy networkProxy = null;
+            if ( StringUtils.isNotBlank( remoteRepository.getRemoteDownloadNetworkProxyId() ) )
+            {
+                networkProxy = networkProxyAdmin.getNetworkProxy( remoteRepository.getRemoteDownloadNetworkProxyId() );
+                if ( networkProxy == null )
+                {
+                    log.warn(
+                        "your remote repository is configured to download remote index trought a proxy we cannot find id:{}",
+                        remoteRepository.getRemoteDownloadNetworkProxyId() );
+                }
+            }
+
+            String wagonProtocol = new URL( remoteRepository.getUrl() ).getProtocol();
+
+            final Wagon wagon = wagonFactory.getWagon(
+                new WagonFactoryRequest( wagonProtocol, remoteRepository.getExtraHeaders() ).networkProxy(
+                    networkProxy ) );
 
+            wagon.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
+            wagon.setTimeout( remoteRepository.getTimeout() * 1000 );
+
+            if ( wagon instanceof AbstractHttpClientWagon )
+            {
+                HttpConfiguration httpConfiguration = new HttpConfiguration();
+                HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
+                httpMethodConfiguration.setUsePreemptive( true );
+                httpMethodConfiguration.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
+                httpConfiguration.setGet( httpMethodConfiguration );
+                AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
+            }
+
+            // we only check connectivity as remote repo can be empty
+            wagon.getFileList( "/" );
+
+            return Boolean.TRUE;
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(),
+                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+        }
+        catch ( MalformedURLException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(),
+                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+        }
+        catch ( WagonFactoryException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(),
+                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+        }
+        catch ( TransferFailedException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(),
+                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(),
+                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+        }
+        catch ( AuthorizationException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(),
+                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+        }
+
+    }
 }