Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Notification about autoBlock changed. Now mails are sent out for ever…
Browse files Browse the repository at this point in the history
…y retry, when blocked for more than 60sec

http://scm.sonatype.org/revinfo.svn?revision=6316&name=Nexus

git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/branches/nexus-1.6.0@6317 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information
velo committed Apr 12, 2010
1 parent f2e7dd0 commit 0cb5641
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Sonatype Nexus (TM) Open Source Version.
* Copyright (c) 2008 Sonatype, Inc. All rights reserved.
* Includes the third-party code listed at http://nexus.sonatype.org/dev/attributions.html
* This program is licensed to you under Version 3 only of the GNU General Public License as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License Version 3 for more details.
* You should have received a copy of the GNU General Public License Version 3 along with this program.
* If not, see http://www.gnu.org/licenses/.
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc.
* "Sonatype" and "Sonatype Nexus" are trademarks of Sonatype, Inc.
*/
package org.sonatype.nexus.proxy.events;

import org.sonatype.nexus.proxy.repository.ProxyMode;
import org.sonatype.nexus.proxy.repository.ProxyRepository;

/**
* The superclass event of ProxyReposiory ProxyMode related events.
*
* @author cstamas
*/
public abstract class RepositoryEventProxyMode
extends RepositoryEvent
{
private final ProxyMode oldProxyMode;

private final ProxyMode newProxyMode;

private final Throwable cause;

public RepositoryEventProxyMode( final ProxyRepository repository, final ProxyMode oldProxyMode,
final ProxyMode newProxyMode, final Throwable cause )
{
super( repository );

this.oldProxyMode = oldProxyMode;

this.newProxyMode = newProxyMode;

this.cause = cause;
}

public ProxyMode getOldProxyMode()
{
return oldProxyMode;
}

public ProxyMode getNewProxyMode()
{
return newProxyMode;
}

public Throwable getCause()
{
return cause;
}

public ProxyRepository getRepository()
{
return (ProxyRepository) super.getRepository();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,17 @@
import org.sonatype.nexus.proxy.repository.ProxyRepository;

/**
* The event fired when a repository's proxy mode changed.
* The event fired when a repository's proxy mode changed. This event is fired on <b>transitions only</b>, when
* ProxyMode of ProxyRepository is actually being changed (oldMode != newMode).
*
* @author cstamas
*/
public class RepositoryEventProxyModeChanged
extends RepositoryEvent
extends RepositoryEventProxyMode
{
private final ProxyMode oldProxyMode;

private final ProxyMode newProxyMode;

private final Throwable cause;

public RepositoryEventProxyModeChanged( final ProxyRepository repository, final ProxyMode oldProxyMode,
final ProxyMode newProxyMode, final Throwable cause )
{
super( repository );

this.oldProxyMode = oldProxyMode;

this.newProxyMode = newProxyMode;

this.cause = cause;
}

public ProxyMode getOldProxyMode()
{
return oldProxyMode;
}

public ProxyMode getNewProxyMode()
{
return newProxyMode;
}

public Throwable getCause()
{
return cause;
}

public ProxyRepository getRepository()
final ProxyMode newProxyMode, final Throwable cause )
{
return (ProxyRepository) super.getRepository();
super( repository, oldProxyMode, newProxyMode, cause );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Sonatype Nexus (TM) Open Source Version.
* Copyright (c) 2008 Sonatype, Inc. All rights reserved.
* Includes the third-party code listed at http://nexus.sonatype.org/dev/attributions.html
* This program is licensed to you under Version 3 only of the GNU General Public License as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License Version 3 for more details.
* You should have received a copy of the GNU General Public License Version 3 along with this program.
* If not, see http://www.gnu.org/licenses/.
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc.
* "Sonatype" and "Sonatype Nexus" are trademarks of Sonatype, Inc.
*/
package org.sonatype.nexus.proxy.events;

import org.sonatype.nexus.proxy.repository.ProxyMode;
import org.sonatype.nexus.proxy.repository.ProxyRepository;

/**
* The event fired when a repository's proxy mode is set. This event is fired on <b>every</b> setting of ProxyMode on a
* ProxyRepository, unlike the RepositoryEventProxyModeChanged event.
*
* @author cstamas
*/
public class RepositoryEventProxyModeSet
extends RepositoryEventProxyMode
{
public RepositoryEventProxyModeSet( final ProxyRepository repository, final ProxyMode oldProxyMode,
final ProxyMode newProxyMode, final Throwable cause )
{
super( repository, oldProxyMode, newProxyMode, cause );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.sonatype.nexus.notification.NotificationManager;
import org.sonatype.nexus.notification.NotificationRequest;
import org.sonatype.nexus.notification.NotificationTarget;
import org.sonatype.nexus.proxy.events.RepositoryEventProxyModeChanged;
import org.sonatype.nexus.proxy.events.RepositoryEventProxyModeSet;
import org.sonatype.nexus.proxy.repository.ProxyMode;
import org.sonatype.plexus.appevents.Event;

Expand All @@ -28,9 +28,10 @@ public class DefaultNotificationEventRouter

public NotificationRequest getRequestForEvent( Event<?> evt )
{
if ( evt instanceof RepositoryEventProxyModeChanged )
if ( evt instanceof RepositoryEventProxyModeSet )
{
RepositoryEventProxyModeChanged rpmevt = (RepositoryEventProxyModeChanged) evt;
// this event is _always_ fired! Do not mix it with RepositoryEventProxyModeChanged event! Read their JavaDoc!
RepositoryEventProxyModeSet rpmevt = (RepositoryEventProxyModeSet) evt;

HashSet<NotificationTarget> targets = new HashSet<NotificationTarget>();

Expand All @@ -56,8 +57,8 @@ public NotificationRequest getRequestForEvent( Event<?> evt )

if ( !targets.isEmpty() )
{
RepositoryEventProxyModeChangedMessage message =
new RepositoryEventProxyModeChangedMessage( rpmevt, null );
RepositoryEventProxyModeMessage message =
new RepositoryEventProxyModeMessage( rpmevt, null );

return new NotificationRequest( message, targets );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
import java.io.StringWriter;
import java.io.Writer;

import org.apache.commons.lang.time.DurationFormatUtils;
import org.sonatype.nexus.notification.NotificationMessage;
import org.sonatype.nexus.proxy.events.RepositoryEventProxyModeChanged;
import org.sonatype.nexus.proxy.events.RepositoryEventProxyMode;
import org.sonatype.nexus.proxy.repository.ProxyMode;
import org.sonatype.security.usermanagement.User;

public class RepositoryEventProxyModeChangedMessage
public class RepositoryEventProxyModeMessage
implements NotificationMessage
{
private final RepositoryEventProxyModeChanged repositoryEventProxyModeChanged;
private final RepositoryEventProxyMode repositoryEventProxyMode;

private final User user;

private final String title;

private final String body;

public RepositoryEventProxyModeChangedMessage( RepositoryEventProxyModeChanged revt, User user )
public RepositoryEventProxyModeMessage( RepositoryEventProxyMode revt, User user )
{
this.repositoryEventProxyModeChanged = revt;
this.repositoryEventProxyMode = revt;

this.user = user;

Expand Down Expand Up @@ -63,26 +64,36 @@ else if ( ProxyMode.BLOCKED_MANUAL.equals( revt.getNewProxyMode() ) )

sb.append( revt.getRepository().getName() );

sb.append( "\" (repoId=" ).append( revt.getRepository().getId() ).append( ") was set to " );
sb.append( "\" (repoId=" ).append( revt.getRepository().getId() );

sb.append( ", remoteUrl=" );

sb.append( revt.getRepository().getRemoteUrl() );

sb.append( ") was set to \n\n" );

if ( ProxyMode.ALLOW.equals( revt.getNewProxyMode() ) )
{
sb.append( "Allow." );
}
else if ( ProxyMode.BLOCKED_AUTO.equals( revt.getNewProxyMode() ) )
{
sb.append( "Blocked (automatically by Nexus)." );
sb.append( "Blocked (automatically by Nexus). Next attempt to check remote peer health will occur in " );

sb.append( DurationFormatUtils.formatDurationWords( revt.getRepository().getRepositoryStatusCheckPeriod(),
true, true )
+ "." );
}
else if ( ProxyMode.BLOCKED_MANUAL.equals( revt.getNewProxyMode() ) )
{
sb.append( "Blocked (by a user)." );
}
else
{
sb.append( revt.getRepository().getProxyMode().toString() ).append( "." );
sb.append( revt.getNewProxyMode().toString() ).append( "." );
}

sb.append( " The previous state was " );
sb.append( "\n\nThe previous state was \n\n" );

if ( ProxyMode.ALLOW.equals( revt.getOldProxyMode() ) )
{
Expand Down Expand Up @@ -117,9 +128,9 @@ else if ( ProxyMode.BLOCKED_MANUAL.equals( revt.getOldProxyMode() ) )
this.body = sb.toString();
}

public RepositoryEventProxyModeChanged getRepositoryEventProxyModeChanged()
public RepositoryEventProxyMode getRepositoryEventProxyMode()
{
return repositoryEventProxyModeChanged;
return repositoryEventProxyMode;
}

public User getUser()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.sonatype.nexus.proxy.events.RepositoryConfigurationUpdatedEvent;
import org.sonatype.nexus.proxy.events.RepositoryEventEvictUnusedItems;
import org.sonatype.nexus.proxy.events.RepositoryEventProxyModeChanged;
import org.sonatype.nexus.proxy.events.RepositoryEventProxyModeSet;
import org.sonatype.nexus.proxy.events.RepositoryItemEventCache;
import org.sonatype.nexus.proxy.item.AbstractStorageItem;
import org.sonatype.nexus.proxy.item.RepositoryItemUid;
Expand Down Expand Up @@ -314,10 +315,18 @@ protected void setProxyMode( ProxyMode proxyMode, boolean sendNotification, Thro
resetRemoteStatus();
}

if ( sendNotification && !proxyMode.equals( oldProxyMode ) )
if ( sendNotification )
{
// this one should be fired _always_
getApplicationEventMulticaster().notifyEventListeners(
new RepositoryEventProxyModeChanged( this, oldProxyMode, proxyMode, cause ) );
new RepositoryEventProxyModeSet( this, oldProxyMode, proxyMode, cause ) );

if ( !proxyMode.equals( oldProxyMode ) )
{
// this one should be fired on _transition_ only
getApplicationEventMulticaster().notifyEventListeners(
new RepositoryEventProxyModeChanged( this, oldProxyMode, proxyMode, cause ) );
}
}
}
}
Expand Down

0 comments on commit 0cb5641

Please sign in to comment.