Package org.sonatype.nexus.proxy.maven.routing

Examples of org.sonatype.nexus.proxy.maven.routing.DiscoveryStatus


      final String lastDiscoveryStrategy = props.getProperty(LAST_DISCOVERY_STRATEGY_KEY, "unknown");
      final String lastDiscoveryMessage = props.getProperty(LAST_DISCOVERY_MESSAGE_KEY, "");
      final long lastDiscoveryTimestamp =
          Long.parseLong(props.getProperty(LAST_DISCOVERY_TIMESTAMP_KEY, Long.toString(-1L)));

      return new DiscoveryStatus(lastDiscoveryStatus, lastDiscoveryStrategy, lastDiscoveryMessage,
          lastDiscoveryTimestamp);
    }
    catch (IllegalArgumentException e) {
      deleteFileItem();
      return null;
View Full Code Here


   *
   * @return {@code true} if update has been spawned, {@code false} if no update needed (prefix list is up to date or
   *         remote discovery is disable for repository).
   */
  protected boolean mayUpdateProxyPrefixFile(final MavenProxyRepository mavenProxyRepository) {
    final DiscoveryStatus discoveryStatus = getStatusFor(mavenProxyRepository).getDiscoveryStatus();
    if (discoveryStatus.getStatus().isEnabled()) {
      // only update if any of these below are true:
      // status is ERROR or ENABLED_NOT_POSSIBLE (hit an error during last discovery)
      // status is anything else and prefix list update period is here
      final DiscoveryConfig config = getRemoteDiscoveryConfig(mavenProxyRepository);
      if (discoveryStatus.getStatus() == DStatus.ERROR
          || discoveryStatus.getStatus() == DStatus.ENABLED_NOT_POSSIBLE
          || ((System.currentTimeMillis() - discoveryStatus.getLastDiscoveryTimestamp()) >
          config.getDiscoveryInterval())) {
        if (discoveryStatus.getStatus() == DStatus.ENABLED_IN_PROGRESS) {
          log.debug("Proxy {} has never been discovered before", mavenProxyRepository);
        }
        else if (discoveryStatus.getStatus() == DStatus.ENABLED_NOT_POSSIBLE) {
          log.debug("Proxy {} discovery was not possible before", mavenProxyRepository);
        }
        else if (discoveryStatus.getStatus() == DStatus.ERROR) {
          log.debug("Proxy {} previous discovery hit an error", mavenProxyRepository);
        }
        else {
          log.debug("Proxy {} needs periodic remote discovery update", mavenProxyRepository);
        }
View Full Code Here

    final PropfileDiscoveryStatusSource discoveryStatusSource =
        new PropfileDiscoveryStatusSource(mavenProxyRepository);

    final ProxyMode proxyMode = mavenProxyRepository.getProxyMode();
    if (!proxyMode.shouldProxy()) {
      final DiscoveryStatus discoveryStatus =
          new DiscoveryStatus(DStatus.ENABLED_NOT_POSSIBLE, "none", "Proxy repository is blocked.",
              System.currentTimeMillis());
      discoveryStatusSource.write(discoveryStatus);
      throw new IllegalStateException("Maven repository "
          + RepositoryStringUtils.getHumanizedNameString(mavenProxyRepository)
          + " not in state to be updated (is blocked).");
    }

    PrefixSource prefixSource = null;
    final DiscoveryConfig config = getRemoteDiscoveryConfig(mavenProxyRepository);
    if (config.isEnabled()) {
      final DiscoveryResult<MavenProxyRepository> discoveryResult;
      if (null == remoteStrategies) {
        discoveryResult = remoteContentDiscoverer.discoverRemoteContent(mavenProxyRepository);
      }
      else {
        discoveryResult =
            remoteContentDiscoverer.discoverRemoteContent(mavenProxyRepository, remoteStrategies);
      }

      log.debug("Results of {} remote discovery: {}", mavenProxyRepository,
          discoveryResult.getAllResults());

      if (discoveryResult.isSuccessful()) {
        final PrefixSource remotePrefixSource = discoveryResult.getPrefixSource();
        if (remotePrefixSource.supported()) {
          // grab local too and merge them
          final DiscoveryResult<MavenRepository> localDiscoveryResult =
              localContentDiscoverer.discoverLocalContent(mavenProxyRepository);
          if (localDiscoveryResult.isSuccessful()) {
            final HashSet<String> mergedEntries = Sets.newHashSet();
            mergedEntries.addAll(remotePrefixSource.readEntries());
            mergedEntries.addAll(localDiscoveryResult.getPrefixSource().readEntries());
            final ArrayListPrefixSource mergedPrefixSource =
                new ArrayListPrefixSource(Lists.newArrayList(mergedEntries),
                    remotePrefixSource.getLostModifiedTimestamp());
            prefixSource = mergedPrefixSource;
          }
          else {
            log.debug("{} local discovery unsuccessful", mavenProxyRepository);
          }
        }
      }
      final Outcome lastOutcome = discoveryResult.getLastResult();

      final DStatus status;
      if (lastOutcome.isSuccessful()) {
        status = DStatus.SUCCESSFUL;
      }
      else {
        if (lastOutcome.getThrowable() == null) {
          status = DStatus.UNSUCCESSFUL;
        }
        else {
          status = DStatus.ERROR;
        }
      }
      final DiscoveryStatus discoveryStatus =
          new DiscoveryStatus(status, lastOutcome.getStrategyId(), lastOutcome.getMessage(),
              System.currentTimeMillis());
      discoveryStatusSource.write(discoveryStatus);
    }
    else {
      log.info("{} remote discovery disabled",
View Full Code Here

    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",
                    "Repository is out of service.", System.currentTimeMillis());
          }
          else {
            // should run but not yet scheduled, or never run yet
            discoveryStatus = new DiscoveryStatus(DStatus.ENABLED_IN_PROGRESS);
          }
        }
        else {
          // all the other "ending" states are persisted
          try {
View Full Code Here

    }
    if (DStatus.NOT_A_PROXY == status.getDiscoveryStatus().getStatus()) {
      payload.setDiscovery(null);
    }
    else {
      final DiscoveryStatus dstatus = status.getDiscoveryStatus();
      final RoutingDiscoveryStatusMessage discoveryPayload = new RoutingDiscoveryStatusMessage();
      payload.setDiscovery(discoveryPayload);
      if (DStatus.DISABLED == status.getDiscoveryStatus().getStatus()) {
        discoveryPayload.setDiscoveryEnabled(false);
        discoveryPayload.setDiscoveryLastStrategy("");
        discoveryPayload.setDiscoveryLastMessage("");
      }
      else {
        final MavenProxyRepository mavenProxyRepository =
            getMavenRepository(request, MavenProxyRepository.class);
        final DiscoveryConfig config = getManager().getRemoteDiscoveryConfig(mavenProxyRepository);
        discoveryPayload.setDiscoveryEnabled(true);
        discoveryPayload.setDiscoveryIntervalHours(
            Ints.saturatedCast(TimeUnit.MILLISECONDS.toHours(config.getDiscoveryInterval())));
        discoveryPayload.setDiscoveryLastStatus(0);
        discoveryPayload.setDiscoveryLastStrategy("");
        discoveryPayload.setDiscoveryLastMessage("");

        // if we have it run at all
        if (DStatus.ENABLED_IN_PROGRESS.ordinal() < status.getDiscoveryStatus().getStatus().ordinal()) {
          if (DStatus.SUCCESSFUL == status.getDiscoveryStatus().getStatus()) {
            discoveryPayload.setDiscoveryLastStatus(1);
          }
          else {
            discoveryPayload.setDiscoveryLastStatus(-1);
          }
          // last- messages
          discoveryPayload.setDiscoveryLastStrategy(Strings.nullToEmpty(dstatus.getLastDiscoveryStrategy()));
          discoveryPayload.setDiscoveryLastMessage(Strings.nullToEmpty(dstatus.getLastDiscoveryMessage()));
          discoveryPayload.setDiscoveryLastRunTimestamp(dstatus.getLastDiscoveryTimestamp());
        }
      }
    }

    final RoutingStatusMessageWrapper responseNessage = new RoutingStatusMessageWrapper();
View Full Code Here

    final MavenProxyRepository mavenProxyRepository =
        getRepositoryRegistry().getRepositoryWithFacet(REPO_ID, MavenProxyRepository.class);

    PropfileDiscoveryStatusSource propsSource = new PropfileDiscoveryStatusSource(mavenProxyRepository);

    final DiscoveryStatus older =
        new DiscoveryStatus(DStatus.SUCCESSFUL, "strategyId", "message", System.currentTimeMillis());
    propsSource.write(older);
    final DiscoveryStatus newer = propsSource.read();

    assertThat(System.identityHashCode(older), not(equalTo(System.identityHashCode(newer))));
    assertThat(older.getStatus(), equalTo(newer.getStatus()));
    assertThat(older.getLastDiscoveryStrategy(), equalTo(newer.getLastDiscoveryStrategy()));
    assertThat(older.getLastDiscoveryMessage(), equalTo(newer.getLastDiscoveryMessage()));
    assertThat(older.getLastDiscoveryTimestamp(), equalTo(newer.getLastDiscoveryTimestamp()));
  }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.maven.routing.DiscoveryStatus

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.