Package org.sonatype.nexus.proxy.item

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUid


  private static void doStoreChechsumItem(ProxyRepository proxy, StorageItem artifact, String attrname,
                                          String noattrname, String hash)
      throws IOException
  {
    final RepositoryItemUid itemUid = artifact.getRepositoryItemUid();
    itemUid.getLock().lock(Action.update);
    final Attributes attributes = artifact.getRepositoryItemAttributes();
    try {
      if (hash != null) {
        attributes.put(attrname, hash);
      }
      else {
        attributes.put(noattrname, Boolean.toString(true));
      }
      proxy.getAttributesHandler().storeAttributes(artifact);
    }
    finally {
      itemUid.getLock().unlock();
    }
  }
View Full Code Here


      throw new RepositoryNotAvailableException(this);
    }

    maintainNotFoundCache(from);

    final RepositoryItemUid fromUid = createUid(from.getRequestPath());

    final RepositoryItemUid toUid = createUid(to.getRequestPath());

    final RepositoryItemUidLock fromUidLock = fromUid.getLock();

    final RepositoryItemUidLock toUidLock = toUid.getLock();

    fromUidLock.lock(Action.read);
    toUidLock.lock(Action.create);

    try {
View Full Code Here

      throw new RepositoryNotAvailableException(this);
    }

    maintainNotFoundCache(request);

    final RepositoryItemUid uid = createUid(request.getRequestPath());

    final RepositoryItemUidLock uidLock = uid.getLock();

    uidLock.lock(Action.delete);

    try {
      StorageItem item = null;
View Full Code Here

    if (!getLocalStatus().shouldServiceRequest()) {
      throw new RepositoryNotAvailableException(this);
    }

    final RepositoryItemUid uid = createUid(item.getPath());

    // replace UID to own one
    item.setRepositoryItemUid(uid);

    // NEXUS-4550: This "fake" UID/lock here is introduced only to serialize uploaders
    // This will catch immediately an uploader if an upload already happens
    // and prevent deadlocks, since uploader still does not have
    // shared lock
    final RepositoryItemUid uploaderUid = createUid(item.getPath() + ".storeItem()");

    final RepositoryItemUidLock uidUploaderLock = uploaderUid.getLock();

    uidUploaderLock.lock(Action.create);

    final Action action = getResultingActionOnWrite(item.getResourceStoreRequest());
View Full Code Here

      localItem = getLocalStorage().retrieveItem(this, request);
      if (localItem instanceof StorageFileItem) {
        StorageFileItem file = (StorageFileItem) localItem;
        // wrap the content locator if needed
        if (!(file.getContentLocator() instanceof ReadLockingContentLocator)) {
          final RepositoryItemUid uid = createUid(request.getRequestPath());
          file.setContentLocator(new ReadLockingContentLocator(uid, file.getContentLocator()));
        }
      }
      if (log.isDebugEnabled()) {
        log.debug("Item " + request.toString() + " found in local storage.");
View Full Code Here

    log.debug("Looking for remote prefix on {} at path {}", mavenProxyRepository, path);
    // we keep exclusive lock on UID during discovery to prevent other threads grabbing this file
    // prematurely. We release the lock only when file is present locally, and is validated.
    // in that moment it's not published yet, but the content is correct and it will be
    // the same that will get published.
    final RepositoryItemUid uid = mavenProxyRepository.createUid(path);
    uid.getLock().lock(Action.update);
    try {
      item = retrieveFromRemoteIfExists(mavenProxyRepository, path);
      if (item != null) {
        log.debug("Remote prefix on {} at path {} found!", mavenProxyRepository, path);
        long prefixFileAgeInDays = (System.currentTimeMillis() - item.getModified()) / 86400000L;
        Result unmarshalled = new TextFilePrefixSourceMarshaller(config).read(item);
        if (!unmarshalled.supported()) {
          return new StrategyResult("Remote disabled automatic routing", UNSUPPORTED_PREFIXSOURCE, false);
        }
        if (unmarshalled.entries().isEmpty()) {
          return new StrategyResult("Remote publishes empty prefix file", UNSUPPORTED_PREFIXSOURCE, false);
        }

        final PrefixSource prefixSource = new FilePrefixSource(mavenProxyRepository, path, config);
        if (prefixFileAgeInDays < 1) {
          return new StrategyResult("Remote publishes prefix file (is less than a day old), using it.", prefixSource,
              true);
        }
        else {
          return new StrategyResult(
              "Remote publishes prefix file (is " + prefixFileAgeInDays + " days old), using it.", prefixSource, true);
        }
      }
    }
    finally {
      uid.getLock().unlock();
    }
    throw new StrategyFailedException("Remote does not publish prefix files on path " + path);
  }
View Full Code Here

    // we start with "usual" read lock, we still don't know is this hosted or proxy repo
    // if proxy, we still don't know do we have to go remote (local copy is old) or not
    // if proxy and need to go remote, we want to _protect_ ourselves from
    // serving up partial downloads...

    final RepositoryItemUid itemUid = createUid(request.getRequestPath());

    final RepositoryItemUidLock itemUidLock = itemUid.getLock();

    itemUidLock.lock(Action.read);

    try {
      if (!getRepositoryKind().isFacetAvailable(ProxyRepository.class)) {
View Full Code Here

   * </pre>
   */
  protected AbstractStorageItem doRetrieveRemoteItem(ResourceStoreRequest request)
      throws ItemNotFoundException, RemoteAccessException, StorageException
  {
    final RepositoryItemUid itemUid = createUid(request.getRequestPath());

    final RepositoryItemUidLock itemUidLock = itemUid.getLock();

    // all this remote download happens in exclusive lock
    itemUidLock.lock(Action.create);

    try {
View Full Code Here

  // ==

  public Object retrieveView(ResourceStore store, ResourceStoreRequest request, StorageItem item, Request req)
      throws IOException
  {
    RepositoryItemUid itemUid = null;

    if (item == null) {
      if (store instanceof RepositoryRouter) {
        RepositoryRouter repositoryRouter = (RepositoryRouter) store;
        // item is either not present or is not here yet (remote index)
        // the we can "simulate" what route would be used to get it, and just get info from the route
        RequestRoute route;

        try {
          route = repositoryRouter.getRequestRouteForRequest(request);
        }
        catch (ItemNotFoundException e) {
          // this is thrown while getting routes for any path "outside" of legal ones is given
          // like /content/foo/bar, since 2nd pathelem may be "repositories", "groups", "shadows", etc
          // (depends on
          // type of registered reposes)
          return null;
        }

        // request would be processed by targeted repository
        Repository itemRepository = route.getTargetedRepository();

        // create an UID against that repository
        itemUid = itemRepository.createUid(route.getRepositoryPath());
      }
      else if (store instanceof Repository) {
        itemUid = ((Repository) store).createUid(request.getRequestPath());
      }
      else {
        // this is highly unbelievable, unless Core gets extended by 3rd party
        return null;
      }
    }
    else {
      itemUid = item.getRepositoryItemUid();

      if ((item instanceof StorageLinkItem) && dereferenceLinks()) {
        // TODO: we may have "deeper" links too! Implement this properly!
        try {
          item =
              repositoryRouter.dereferenceLink((StorageLinkItem) item, request.isRequestLocalOnly(),
                  request.isRequestRemoteOnly());
        }
        catch (Exception e) {
          getLogger().warn("Failed to dereference the storagelink " + item.getRepositoryItemUid(), e);

          // leave item unchanged
        }
      }
    }

    // so, we ended with:
    // itemUid is always populated, hence we have Repository and repository path
    // so, item may be null or non-null, if non-null, it may be link

    // check for item not found finally. Those may be allowed in proxy repositories only.
    if (item == null && !processNotFoundItems(itemUid.getRepository())) {
      // return not-applicable. This is not a proxy repository, and the item is not found. Since it is not
      // proxy repo, it will be never cached from remote too, simply, it is not here.
      return null;
    }
View Full Code Here

    }

    setDefaults();

    final Repository repository = findRepository();
    final RepositoryItemUid mdUid = repository.createUid("/" + PATH_OF_REPOMD_XML);
    try {
      mdUid.getLock().lock(Action.update);

      LOG.debug("Generating Yum-Repository for '{}' ...", getRpmDir());
      try {
        // NEXUS-6680: Nuke cache dir if force rebuild in effect
        if (shouldForceFullScan()) {
          DirSupport.deleteIfExists(getCacheDir().toPath());
        }
        DirSupport.mkdir(getRepoDir().toPath());

        File rpmListFile = createRpmListFile();
        commandLineExecutor.exec(buildCreateRepositoryCommand(rpmListFile));
      }
      catch (IOException e) {
        LOG.warn("Yum metadata generation failed", e);
        throw new IOException("Yum metadata generation failed", e);
      }
      // TODO dubious
      Thread.sleep(100);

      if (repository != null) {
        final MavenRepository mavenRepository = repository.adaptToFacet(MavenRepository.class);
        if (mavenRepository != null) {
          try {
            routingManager.forceUpdatePrefixFile(mavenRepository);
          }
          catch (Exception e) {
            logger.warn("Could not update Whitelist for repository '{}'", mavenRepository, e);
          }
        }
      }

      regenerateMetadataForGroups();
      return new YumRepositoryImpl(getRepoDir(), repositoryId, getVersion());
    }
    finally {
      mdUid.getLock().unlock();
    }
  }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.item.RepositoryItemUid

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.