Package org.sonatype.nexus.proxy.maven

Examples of org.sonatype.nexus.proxy.maven.MavenProxyRepository


  /**
   * Handler for {@link PrefixFilePublishedRepositoryEvent} event.
   */
  @Subscribe
  public void onPrefixFilePublishedRepositoryEvent(final PrefixFilePublishedRepositoryEvent evt) {
    final MavenProxyRepository mavenProxyRepository = evt.getRepository().adaptToFacet(MavenProxyRepository.class);
    if (isRepositoryHandled(mavenProxyRepository)) {
      buildPathMatcherFor(mavenProxyRepository);
    }
  }
View Full Code Here


  /**
   * Handler for {@link PrefixFileUnpublishedRepositoryEvent} event.
   */
  @Subscribe
  public void onPrefixFileUnpublishedRepositoryEvent(final PrefixFileUnpublishedRepositoryEvent evt) {
    final MavenProxyRepository mavenProxyRepository = evt.getRepository().adaptToFacet(MavenProxyRepository.class);
    if (isRepositoryHandled(mavenProxyRepository)) {
      dropPathMatcherFor(mavenProxyRepository);
    }
  }
View Full Code Here

  @Test
  public void testNEXUS4943RepositoryMetadataManager_expireNotFoundMetadataCaches()
      throws Exception
  {
    // hosted reposes has NFC shut down (see NEXUS-4798)
    MavenProxyRepository m2Repo =
        getRepositoryRegistry().getRepositoryWithFacet("repo1", MavenProxyRepository.class);
    m2Repo.addToNotFoundCache(new ResourceStoreRequest("/some/path/file.jar"));
    m2Repo.addToNotFoundCache(new ResourceStoreRequest("/some/path/maven-metadata.xml"));

    // note: above, that is the "standard" way to write item paths! (starting with slash)
    // below, we tamper directly with NFC, so the lack of starting slash should not confuse you!

    // we have two known entries in NFC
    assertThat(m2Repo.getNotFoundCache().listKeysInCache().size(), equalTo(2));
    assertThat(m2Repo.getNotFoundCache().listKeysInCache(),
        contains("some/path/file.jar", "some/path/maven-metadata.xml"));

    m2Repo.getRepositoryMetadataManager().expireNotFoundMetadataCaches(new ResourceStoreRequest("/"));

    // M2 metadata should be removed, so we have one known entry in NFC
    assertThat(m2Repo.getNotFoundCache().listKeysInCache().size(), equalTo(1));
    assertThat(m2Repo.getNotFoundCache().listKeysInCache(), contains("some/path/file.jar"));
  }
View Full Code Here

  @Test
  public void testNEXUS4943RepositoryMetadataManager_expireMetadataCaches()
      throws Exception
  {
    // hosted reposes has NFC shut down (see NEXUS-4798)
    MavenProxyRepository m2Repo =
        getRepositoryRegistry().getRepositoryWithFacet("repo1", MavenProxyRepository.class);

    // put some proxied content
    // we need GavBuilder-like class, this below is hilarious!
    final Gav gav =
        new Gav("org.slf4j", "slf4j-api", "1.4.3", null, "jar", null, null, null, false, null, false, null);
    m2Repo.getArtifactStoreHelper().retrieveArtifact(new ArtifactStoreRequest(m2Repo, gav, false));
    // get GAV metadata (is present)
    m2Repo.retrieveItem(new ResourceStoreRequest("/org/slf4j/slf4j-api/1.4.3/maven-metadata.xml"));
    // get GA metadat (not present, will go into NFC
    try {
      m2Repo.retrieveItem(new ResourceStoreRequest("/org/slf4j/slf4j-api/maven-metadata.xml"));
    }
    catch (ItemNotFoundException e) {
      // good, we expected this
    }

    // expire sub-tree to use walking method to update all item attributes to expired=true
    m2Repo.getRepositoryMetadataManager().expireMetadataCaches(new ResourceStoreRequest("/org/"));

    // the GA metadata should be removed from NFC, so we have no known entry in NFC
    assertThat(m2Repo.getNotFoundCache().listKeysInCache().size(), equalTo(0));

    // the GAV metadata should be expired
    assertThat(
        m2Repo.retrieveItem(new ResourceStoreRequest("/org/slf4j/slf4j-api/1.4.3/maven-metadata.xml")).isExpired(),
        is(true));
    // but the JAR should not be expired
    assertThat(
        m2Repo.retrieveItem(new ResourceStoreRequest("/org/slf4j/slf4j-api/1.4.3/slf4j-api-1.4.3.jar")).isExpired(),
        is(false));
  }
View Full Code Here

          if (!prefixSource.exists()) {
            // automatic routing has not been initialized for this repository yet, for initialization.
            doUpdatePrefixFileAsync(true, mavenRepository);
          }
          else {
            MavenProxyRepository mavenProxyRepository =
                mavenRepository.adaptToFacet(MavenProxyRepository.class);
            if (mavenProxyRepository != null) {
              mayUpdateProxyPrefixFile(mavenProxyRepository);
            }
          }
View Full Code Here

  // ==

  @Override
  public RoutingStatus getStatusFor(final MavenRepository mavenRepository) {
    final MavenProxyRepository mavenProxyRepository = mavenRepository.adaptToFacet(MavenProxyRepository.class);
    final boolean remoteDiscoveryEnabled;
    if (mavenProxyRepository != null) {
      final DiscoveryConfig discoveryConfig = getRemoteDiscoveryConfig(mavenProxyRepository);
      remoteDiscoveryEnabled = discoveryConfig.isEnabled();
    }
    else {
      remoteDiscoveryEnabled = false;
    }

    PublishingStatus publishingStatus = null;
    DiscoveryStatus discoveryStatus = null;

    // publish status
    final FilePrefixSource publishedEntrySource = getPrefixSourceFor(mavenRepository);
    if (!publishedEntrySource.supported()) {
      final String message;
      if (isMavenRepositorySupported(mavenRepository)) {
        if (mavenRepository.getRepositoryKind().isFacetAvailable(MavenGroupRepository.class)) {
          final MavenGroupRepository mavenGroupRepository =
              mavenRepository.adaptToFacet(MavenGroupRepository.class);
          final List<String> membersWithoutPrefixFiles = new ArrayList<String>();
          for (Repository member : mavenGroupRepository.getMemberRepositories()) {
            final MavenRepository memberMavenRepository = member.adaptToFacet(MavenRepository.class);
            if (null != memberMavenRepository) {
              final PrefixSource ps = getPrefixSourceFor(memberMavenRepository);
              if (!ps.supported()) {
                membersWithoutPrefixFiles.add(memberMavenRepository.getName());
              }
            }
          }
          message =
              "Publishing not possible, following members have no published prefix file: "
                  + Joiner.on(", ").join(membersWithoutPrefixFiles);
        }
        else if (mavenRepository.getRepositoryKind().isFacetAvailable(MavenProxyRepository.class)) {
          if (remoteDiscoveryEnabled) {
            message = "Discovery in progress or unable to discover remote content (see discovery status).";
          }
          else {
            message = "Remote discovery not enabled.";
          }
        }
        else if (mavenRepository.getRepositoryKind().isFacetAvailable(MavenHostedRepository.class)) {
          message = "Check Nexus logs for more details."; // hosted reposes must be discovered always
        }
        else if (mavenRepository.getRepositoryKind().isFacetAvailable(ShadowRepository.class)) {
          message = "Unsupported repository type (only hosted, proxy and groups are supported).";
        }
        else {
          message = "Check Nexus logs for more details.";
        }
      }
      else {
        message = "Unsupported repository format (only Maven2 format is supported).";
      }
      publishingStatus = new PublishingStatus(PStatus.NOT_PUBLISHED, message, -1, null);
    }
    else {
      publishingStatus =
          new PublishingStatus(PStatus.PUBLISHED, "Prefix file published successfully.",
              publishedEntrySource.getLostModifiedTimestamp(), publishedEntrySource.getFilePath());
    }

    if (mavenProxyRepository == null) {
      discoveryStatus = new DiscoveryStatus(DStatus.NOT_A_PROXY);
    }
    else {
      if (!remoteDiscoveryEnabled) {
        discoveryStatus = new DiscoveryStatus(DStatus.DISABLED);
      }
      else if (constrainedExecutor.hasRunningWithKey(mavenProxyRepository.getId())) {
        // still running or never run yet
        discoveryStatus = new DiscoveryStatus(DStatus.ENABLED_IN_PROGRESS);
      }
      else {
        final PropfileDiscoveryStatusSource discoveryStatusSource =
            new PropfileDiscoveryStatusSource(mavenProxyRepository);
        if (!discoveryStatusSource.exists()) {
          if (!mavenProxyRepository.getLocalStatus().shouldServiceRequest()) {
            // should run but not yet scheduled, or never run yet
            // out of service prevents us to persist ending states, so this
            // is the only place where we actually "calculate" it
            discoveryStatus =
                new DiscoveryStatus(DStatus.ENABLED_NOT_POSSIBLE, "none",
View Full Code Here

  @Test
  public void proxyPrefixFileIsUnchanged()
      throws Exception
  {
    // all is settled now, proxy should have prefix file pulled from remote AND merged with cache content
    final MavenProxyRepository proxyRepository =
        getRepositoryRegistry().getRepositoryWithFacet(PROXY_REPO_ID, MavenProxyRepository.class);

    final Manager routingManager = lookup(Manager.class);
    final PrefixSource proxyPrefixSource = routingManager.getPrefixSourceFor(proxyRepository);
View Full Code Here

              if (repository.getRepositoryKind().isFacetAvailable(MavenProxyRepository.class)) {
                ChecksumPolicy checksum =
                    EnumUtil.valueOf(model.getChecksumPolicy(), ChecksumPolicy.class);

                MavenProxyRepository pRepository = repository.adaptToFacet(MavenProxyRepository.class);
                pRepository.setChecksumPolicy(checksum);

                pRepository.setDownloadRemoteIndexes(model.isDownloadRemoteIndexes());

                pRepository.setChecksumPolicy(EnumUtil.valueOf(model.getChecksumPolicy(),
                    ChecksumPolicy.class));

                pRepository.setDownloadRemoteIndexes(model.isDownloadRemoteIndexes());

                RepositoryProxyResource proxyModel = (RepositoryProxyResource) model;

                pRepository.setArtifactMaxAge(proxyModel.getArtifactMaxAge());

                pRepository.setMetadataMaxAge(proxyModel.getMetadataMaxAge());

                if (proxyModel.getItemMaxAge() != null) {
                  pRepository.setItemMaxAge(proxyModel.getItemMaxAge());
                }
              }
            }
            else {
              // This is a total hack to be able to retrieve this data from a non core repo if available
View Full Code Here

  public void outOfServiceRepositoryDoesNotAffectWLInitialization()
      throws Exception
  {
    // at this point, NexusStartedEvent was fired, and hence, WL's should be inited
    final Manager wm = lookup(Manager.class);
    final MavenProxyRepository proxy1 =
        getRepositoryRegistry().getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class);

    assertThat(proxy1.getLocalStatus(), equalTo(LocalStatus.OUT_OF_SERVICE));
    waitForRoutingBackgroundUpdates();

    // let's check states

    {
View Full Code Here

  public void flippingLocalStatusUpdatesWL()
      throws Exception
  {
    // at this point, NexusStartedEvent was fired, and hence, WL's should be inited
    final Manager wm = lookup(Manager.class);
    final MavenProxyRepository proxy1 =
        getRepositoryRegistry().getRepositoryWithFacet(PROXY1_REPO_ID, MavenProxyRepository.class);

    assertThat(proxy1.getLocalStatus(), equalTo(LocalStatus.OUT_OF_SERVICE));
    waitForRoutingBackgroundUpdates();

    // let's check states
    {
      // proxy1
      final RoutingStatus proxy1status = wm.getStatusFor(proxy1);
      // this repo is Out of Service
      assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.NOT_PUBLISHED));
      assertThat(proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.ENABLED_NOT_POSSIBLE));
      assertThat(proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is("none"));
      // Remark: the combination of those three above simply means "discovery never tried against it"
      // yet.
    }
    {
      // group
      final RoutingStatus groupStatus =
          wm.getStatusFor(getRepositoryRegistry().getRepositoryWithFacet(GROUP_REPO_ID,
              MavenGroupRepository.class));
      // not all members have WL, unpublished
      assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY));
    }

    {
      // let's flip proxy1 now
      proxy1.setLocalStatus(LocalStatus.IN_SERVICE);
      getApplicationConfiguration().saveConfiguration();
      wairForAsyncEventsToCalmDown();
      waitForRoutingBackgroundUpdates();
    }

    // let's check states again, now with enabled proxy1

    {
      // proxy1
      final RoutingStatus proxy1status =
          wm.getStatusFor(getRepositoryRegistry().getRepositoryWithFacet(PROXY1_REPO_ID,
              MavenProxyRepository.class));
      // this repo is Out of Service
      assertThat(proxy1status.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(proxy1status.getDiscoveryStatus().getStatus(), equalTo(DStatus.SUCCESSFUL));
      assertThat(proxy1status.getDiscoveryStatus().getLastDiscoveryStrategy(), is(RemotePrefixFileStrategy.ID));
    }
    {
      // group
      final RoutingStatus groupStatus =
          wm.getStatusFor(getRepositoryRegistry().getRepositoryWithFacet(GROUP_REPO_ID,
              MavenGroupRepository.class));
      // not all members have WL, unpublisged
      assertThat(groupStatus.getPublishingStatus().getStatus(), equalTo(PStatus.PUBLISHED));
      assertThat(groupStatus.getDiscoveryStatus().getStatus(), equalTo(DStatus.NOT_A_PROXY));
    }

    {
      // let's flip proxy1 now back
      proxy1.setLocalStatus(LocalStatus.OUT_OF_SERVICE);
      getApplicationConfiguration().saveConfiguration();
      wairForAsyncEventsToCalmDown();
      waitForRoutingBackgroundUpdates();
    }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.maven.MavenProxyRepository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.