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

Commit

Permalink
NEXUS-5639: "Deep" rename WL to Routing
Browse files Browse the repository at this point in the history
Initial code changes, bundle smoke tested and is working.

Tests and ITs not verified yet.
  • Loading branch information
cstamas committed Mar 28, 2013
1 parent a7444cd commit 2dbec3c
Show file tree
Hide file tree
Showing 103 changed files with 989 additions and 1,047 deletions.
Expand Up @@ -20,46 +20,44 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.sonatype.nexus.client.core.exception.NexusClientBadRequestException;
import org.sonatype.nexus.client.core.exception.NexusClientNotFoundException;
import org.sonatype.nexus.client.core.subsystem.whitelist.DiscoveryConfiguration;
import org.sonatype.nexus.client.core.subsystem.whitelist.Status;
import org.sonatype.nexus.client.core.subsystem.whitelist.Status.Outcome;
import org.sonatype.nexus.client.core.subsystem.whitelist.Whitelist;
import org.sonatype.nexus.client.core.subsystem.routing.DiscoveryConfiguration;
import org.sonatype.nexus.client.core.subsystem.routing.Routing;
import org.sonatype.nexus.client.core.subsystem.routing.Status;
import org.sonatype.nexus.client.core.subsystem.routing.Status.Outcome;

/**
* Will not work until proxy404 merged into master, AND at least one CI build/deploys of that master, as it seems Sisu
* Maven Bridge will download the "latest" from remote, not use the build from branch.
*
* @author cstamas
*/
public class WhitelistIT
public class RoutingIT
extends NexusClientITSupport
{

public WhitelistIT( final String nexusBundleCoordinates )
public RoutingIT( final String nexusBundleCoordinates )
{
super( nexusBundleCoordinates );
}

private Whitelist whitelist()
private Routing routing()
{
return client().getSubsystem( Whitelist.class );
return client().getSubsystem( Routing.class );
}

@Test( expected = NexusClientNotFoundException.class )
public void getNonExistentStatus()
{
final Status status = whitelist().getWhitelistStatus( "no-such-repo-id" );
final Status status = routing().getStatus( "no-such-repo-id" );
}

@Test
public void getReleaseStatus()
{
final Status status = whitelist().getWhitelistStatus( "releases" );
final Status status = routing().getStatus( "releases" );
assertThat( status, is( not( nullValue() ) ) );
assertThat( status.getPublishedStatus(), equalTo( Outcome.SUCCEEDED ) );
assertThat( status.getPublishedMessage(), is( notNullValue() ) );
Expand All @@ -70,7 +68,7 @@ public void getReleaseStatus()
@Test
public void getSnapshotsStatus()
{
final Status status = whitelist().getWhitelistStatus( "snapshots" );
final Status status = routing().getStatus( "snapshots" );
assertThat( status, is( not( nullValue() ) ) );
assertThat( status.getPublishedStatus(), equalTo( Outcome.SUCCEEDED ) );
assertThat( status.getPublishedMessage(), is( notNullValue() ) );
Expand All @@ -81,19 +79,19 @@ public void getSnapshotsStatus()
@Test( expected = NexusClientBadRequestException.class )
public void getCentralM1Status()
{
final Status status = whitelist().getWhitelistStatus( "central-m1" );
final Status status = routing().getStatus( "central-m1" );
}

@Test( expected = NexusClientNotFoundException.class )
public void getNonExistentConfig()
{
final DiscoveryConfiguration config = whitelist().getDiscoveryConfigurationFor( "no-such-repo-id" );
final DiscoveryConfiguration config = routing().getDiscoveryConfigurationFor( "no-such-repo-id" );
}

@Test
public void getCentralDefaultConfig()
{
final DiscoveryConfiguration config = whitelist().getDiscoveryConfigurationFor( "central" );
final DiscoveryConfiguration config = routing().getDiscoveryConfigurationFor( "central" );
assertThat( config, is( notNullValue() ) );
assertThat( config.isEnabled(), is( true ) );
assertThat( config.getIntervalHours(), is( 24 ) );
Expand All @@ -103,13 +101,13 @@ public void getCentralDefaultConfig()
public void modifyDiscoveryConfig()
{
{
final DiscoveryConfiguration config = whitelist().getDiscoveryConfigurationFor( "central" );
final DiscoveryConfiguration config = routing().getDiscoveryConfigurationFor( "central" );
config.setEnabled( false );
config.setIntervalHours( 12 );
whitelist().setDiscoveryConfigurationFor( "central", config );
routing().setDiscoveryConfigurationFor( "central", config );
}
{
final DiscoveryConfiguration config = whitelist().getDiscoveryConfigurationFor( "central" );
final DiscoveryConfiguration config = routing().getDiscoveryConfigurationFor( "central" );
assertThat( config.isEnabled(), is( false ) );
assertThat( config.getIntervalHours(), is( 12 ) );
}
Expand All @@ -118,30 +116,30 @@ public void modifyDiscoveryConfig()
@Test
public void updateReleases()
{
whitelist().updateWhitelist( "releases" );
routing().updatePrefixFile( "releases" );
}

@Test
public void updateSnapshots()
{
whitelist().updateWhitelist( "snapshots" );
routing().updatePrefixFile( "snapshots" );
}

@Test
public void updateCentral()
{
whitelist().updateWhitelist( "central" );
routing().updatePrefixFile( "central" );
}

@Test( expected = NexusClientBadRequestException.class )
public void updateCentralM1()
{
whitelist().updateWhitelist( "central-m1" );
routing().updatePrefixFile( "central-m1" );
}

@Test( expected = NexusClientNotFoundException.class )
public void updateNonExistent()
{
whitelist().updateWhitelist( "no-such-repo-id" );
routing().updatePrefixFile( "no-such-repo-id" );
}
}
Expand Up @@ -10,12 +10,12 @@
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.client.core.subsystem.whitelist;
package org.sonatype.nexus.client.core.subsystem.routing;

import static com.google.common.base.Preconditions.checkArgument;

/**
* The whitelist discovery configuration for a proxy repository.
* The routing discovery configuration for a proxy repository.
*
* @author cstamas
* @since 2.4
Expand Down
Expand Up @@ -10,39 +10,39 @@
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.client.core.subsystem.whitelist;
package org.sonatype.nexus.client.core.subsystem.routing;

import org.sonatype.nexus.client.core.exception.NexusClientErrorResponseException;
import org.sonatype.nexus.client.core.exception.NexusClientNotFoundException;

/**
* Client subsystem for Nexus Whitelist feature.
* Client subsystem for Nexus Automatic Routing feature.
*
* @author cstamas
* @since 2.4
*/
public interface Whitelist
public interface Routing
{
/**
* Returns the status of the Whitelist of a Maven Repository (proxy, hosted or group).
* Returns the status of the Automatic Routing of a Maven Repository (proxy, hosted or group).
*
* @param mavenRepositoryId the ID of the Maven repository you want get status for.
* @return the status for given repository.
* @throws NexusClientNotFoundException if the passed in ID does not exists.
*/
Status getWhitelistStatus( String mavenRepositoryId );
Status getStatus( String mavenRepositoryId );

/**
* Perform a forced update of the Whitelist of a Maven repository. This method returns immediately, but it spawns a
* background operation on Nexus that will perform the update and it's outcome will be reflected in status when
* Perform a forced update of the prefix file of a Maven repository. This method returns immediately, but it spawns
* a background operation on Nexus that will perform the update and it's outcome will be reflected in status when
* update is done.
*
* @param mavenRepositoryId the ID of the Maven Repository you want update the whitelist for (see throws for what
* @param mavenRepositoryId the ID of the Maven Repository you want update the prefix file for (see throws for what
* kind of repositories this call is allowed).
* @throws NexusClientErrorResponseException if the passed in ID is not a Maven Proxy repository.
* @throws NexusClientNotFoundException if the passed in ID does not exists.
*/
void updateWhitelist( String mavenRepositoryId )
void updatePrefixFile( String mavenRepositoryId )
throws NexusClientErrorResponseException, NexusClientNotFoundException;

/**
Expand Down
Expand Up @@ -10,10 +10,10 @@
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.client.core.subsystem.whitelist;
package org.sonatype.nexus.client.core.subsystem.routing;

/**
* The whitelist status for a Maven repository.
* The routing status for a Maven repository.
*
* @author cstamas
* @since 2.4
Expand Down Expand Up @@ -42,7 +42,7 @@ public static enum Outcome
}

/**
* The whitelist discovery status for a Maven Proxy repository.
* The routing discovery status for a Maven Proxy repository.
*/
public static class DiscoveryStatus
{
Expand Down Expand Up @@ -175,7 +175,7 @@ public long getDiscoveryLastRunTimestamp()
private final long publishedTimestamp;

/**
* The URL of the published WL prefix file or {@code null} if not published.
* The URL of the published prefix file or {@code null} if not published.
*/
private final String publishedUrl;

Expand Down Expand Up @@ -234,7 +234,7 @@ public long getPublishedTimestamp()
}

/**
* Returns the URL of the published whitelist file, or {@code null} if not published.
* Returns the URL of the published prefix file, or {@code null} if not published.
*
* @return the prefix file URL if published, or {@code null}.
*/
Expand Down
Expand Up @@ -10,56 +10,56 @@
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.client.internal.rest.jersey.subsystem.whitelist;
package org.sonatype.nexus.client.internal.rest.jersey.subsystem.routing;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.sonatype.nexus.client.core.exception.NexusClientNotFoundException;
import org.sonatype.nexus.client.core.spi.SubsystemSupport;
import org.sonatype.nexus.client.core.subsystem.whitelist.DiscoveryConfiguration;
import org.sonatype.nexus.client.core.subsystem.whitelist.Status;
import org.sonatype.nexus.client.core.subsystem.whitelist.Status.DiscoveryStatus;
import org.sonatype.nexus.client.core.subsystem.whitelist.Status.Outcome;
import org.sonatype.nexus.client.core.subsystem.whitelist.Whitelist;
import org.sonatype.nexus.client.core.subsystem.routing.DiscoveryConfiguration;
import org.sonatype.nexus.client.core.subsystem.routing.Routing;
import org.sonatype.nexus.client.core.subsystem.routing.Status;
import org.sonatype.nexus.client.core.subsystem.routing.Status.DiscoveryStatus;
import org.sonatype.nexus.client.core.subsystem.routing.Status.Outcome;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
import org.sonatype.nexus.rest.model.WLConfigMessage;
import org.sonatype.nexus.rest.model.WLConfigMessageWrapper;
import org.sonatype.nexus.rest.model.WLStatusMessage;
import org.sonatype.nexus.rest.model.WLStatusMessageWrapper;
import org.sonatype.nexus.rest.model.RoutingConfigMessage;
import org.sonatype.nexus.rest.model.RoutingConfigMessageWrapper;
import org.sonatype.nexus.rest.model.RoutingStatusMessage;
import org.sonatype.nexus.rest.model.RoutingStatusMessageWrapper;

import com.google.common.base.Throwables;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.UniformInterfaceException;

/**
* Jersey based {@link Whitelist} implementation.
* Jersey based {@link Routing} implementation.
*
* @author cstamas
* @since 2.4
*/
public class JerseyWhitelist
public class JerseyRouting
extends SubsystemSupport<JerseyNexusClient>
implements Whitelist
implements Routing
{

/**
* Constructor.
*
* @param nexusClient
*/
public JerseyWhitelist( final JerseyNexusClient nexusClient )
public JerseyRouting( final JerseyNexusClient nexusClient )
{
super( nexusClient );
}

@Override
public Status getWhitelistStatus( final String mavenRepositoryId )
public Status getStatus( final String mavenRepositoryId )
{
try
{
final WLStatusMessage message =
getNexusClient().serviceResource( wlPath( mavenRepositoryId ) ).get( WLStatusMessageWrapper.class ).getData();
final RoutingStatusMessage message =
getNexusClient().serviceResource( wlPath( mavenRepositoryId ) ).get( RoutingStatusMessageWrapper.class ).getData();

final DiscoveryStatus discoveryStatus;
if ( message.getDiscovery() == null )
Expand Down Expand Up @@ -93,7 +93,7 @@ public Status getWhitelistStatus( final String mavenRepositoryId )
}

@Override
public void updateWhitelist( final String mavenProxyRepositoryId )
public void updatePrefixFile( final String mavenProxyRepositoryId )
throws IllegalArgumentException, NexusClientNotFoundException
{
try
Expand All @@ -116,9 +116,9 @@ public DiscoveryConfiguration getDiscoveryConfigurationFor( final String mavenPr
{
try
{
final WLConfigMessage message =
final RoutingConfigMessage message =
getNexusClient().serviceResource( wlConfigPath( mavenProxyRepositoryId ) ).get(
WLConfigMessageWrapper.class ).getData();
RoutingConfigMessageWrapper.class ).getData();
return new DiscoveryConfiguration( message.isDiscoveryEnabled(), message.getDiscoveryIntervalHours() );
}
catch ( UniformInterfaceException e )
Expand All @@ -138,10 +138,10 @@ public void setDiscoveryConfigurationFor( final String mavenProxyRepositoryId,
{
try
{
final WLConfigMessage message = new WLConfigMessage();
final RoutingConfigMessage message = new RoutingConfigMessage();
message.setDiscoveryEnabled( configuration.isEnabled() );
message.setDiscoveryIntervalHours( configuration.getIntervalHours() );
final WLConfigMessageWrapper wrapper = new WLConfigMessageWrapper();
final RoutingConfigMessageWrapper wrapper = new RoutingConfigMessageWrapper();
wrapper.setData( message );
getNexusClient().serviceResource( wlConfigPath( mavenProxyRepositoryId ) ).put( wrapper );
}
Expand Down
Expand Up @@ -18,19 +18,19 @@
import org.sonatype.nexus.client.core.Condition;
import org.sonatype.nexus.client.core.condition.NexusStatusConditions;
import org.sonatype.nexus.client.core.spi.SubsystemFactory;
import org.sonatype.nexus.client.core.subsystem.whitelist.Whitelist;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.whitelist.JerseyWhitelist;
import org.sonatype.nexus.client.core.subsystem.routing.Routing;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.routing.JerseyRouting;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;

/**
* Jersey based {@link Whitelist} subsystem factory.
* Jersey based {@link Routing} subsystem factory.
*
* @since 2.4
*/
@Named
@Singleton
public class JerseyWhitelistFactory
implements SubsystemFactory<Whitelist, JerseyNexusClient>
public class JerseyRoutingFactory
implements SubsystemFactory<Routing, JerseyNexusClient>
{
@Override
public Condition availableWhen()
Expand All @@ -39,14 +39,14 @@ public Condition availableWhen()
}

@Override
public Class<Whitelist> getType()
public Class<Routing> getType()
{
return Whitelist.class;
return Routing.class;
}

@Override
public Whitelist create( final JerseyNexusClient nexusClient )
public Routing create( final JerseyNexusClient nexusClient )
{
return new JerseyWhitelist( nexusClient );
return new JerseyRouting( nexusClient );
}
}

0 comments on commit 2dbec3c

Please sign in to comment.