Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Merge pull request #698 from NuGet/dev
Browse files Browse the repository at this point in the history
Merge branch 'dev' into master
  • Loading branch information
joelverhagen authored Dec 3, 2019
2 parents b9a038f + e03d8e6 commit 1ab3792
Show file tree
Hide file tree
Showing 48 changed files with 736 additions and 377 deletions.
1 change: 1 addition & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nugetbuild" value="https://dotnet.myget.org/F/nuget-build/api/v3/index.json" />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Expand Down
31 changes: 29 additions & 2 deletions src/Catalog/Icons/ExternalIconCopyResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,51 @@ public class ExternalIconCopyResult
{
public static ExternalIconCopyResult Success(Uri sourceUrl, Uri storageUrl)
{
if (sourceUrl == null)
{
throw new ArgumentNullException(nameof(sourceUrl));
}

if (storageUrl == null)
{
throw new ArgumentNullException(nameof(storageUrl));
}

return new ExternalIconCopyResult
{
SourceUrl = sourceUrl,
StorageUrl = storageUrl,
Expiration = null, // successes don't expire
};
}

public static ExternalIconCopyResult Fail(Uri sourceUrl)
public static ExternalIconCopyResult Fail(Uri sourceUrl, TimeSpan validityPeriod)
{
if (sourceUrl == null)
{
throw new ArgumentNullException(nameof(sourceUrl));
}

if (validityPeriod < TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(validityPeriod), $"{nameof(validityPeriod)} cannot be negative");
}

return new ExternalIconCopyResult
{
SourceUrl = sourceUrl,
StorageUrl = null
StorageUrl = null,
Expiration = DateTimeOffset.UtcNow.Add(validityPeriod),
};
}

public Uri SourceUrl { get; set; }
public Uri StorageUrl { get; set; }

/// <summary>
/// Expiration time for the fail cache item.
/// </summary>
public DateTimeOffset? Expiration { get; set; }
public bool IsCopySucceeded => StorageUrl != null;
}
}
16 changes: 11 additions & 5 deletions src/Catalog/Icons/IconCopyResultCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ public class IconCopyResultCache : IIconCopyResultCache, IIconCopyResultCachePer
private ConcurrentDictionary<Uri, SemaphoreSlim> _uriSemaphores = null;

private readonly IStorage _auxStorage;
private readonly TimeSpan _failCacheTime;
private readonly ILogger<IconCopyResultCache> _logger;

public IconCopyResultCache(
IStorage auxStorage,
TimeSpan failCacheTime,
ILogger<IconCopyResultCache> logger)
{
_auxStorage = auxStorage ?? throw new ArgumentNullException(nameof(auxStorage));
_failCacheTime = failCacheTime;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));

_uriSemaphores = new ConcurrentDictionary<Uri, SemaphoreSlim>();
Expand Down Expand Up @@ -73,12 +76,15 @@ public ExternalIconCopyResult Get(Uri iconUrl)
throw new InvalidOperationException("Object was not initialized");
}

if (_externalIconCopyResults.TryGetValue(iconUrl, out var result))
if (!_externalIconCopyResults.TryGetValue(iconUrl, out var result))
{
return result;
return null;
}

return null;
if (!result.IsCopySucceeded && (!result.Expiration.HasValue || result.Expiration.Value < DateTimeOffset.UtcNow))
{
return null;
}
return result;
}

public async Task<Uri> SaveExternalIcon(Uri originalIconUrl, Uri storageUrl, IStorage mainDestinationStorage, IStorage cacheStorage, CancellationToken cancellationToken)
Expand Down Expand Up @@ -144,7 +150,7 @@ public void SaveExternalCopyFailure(Uri iconUrl)
throw new InvalidOperationException("Object was not initialized");
}

Set(iconUrl, ExternalIconCopyResult.Fail(iconUrl));
Set(iconUrl, ExternalIconCopyResult.Fail(iconUrl, _failCacheTime));
}

private void Set(Uri iconUrl, ExternalIconCopyResult newItem)
Expand Down
9 changes: 0 additions & 9 deletions src/Catalog/NuGet.Services.Metadata.Catalog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,6 @@
<PackageReference Include="NuGet.Services.Sql">
<Version>2.58.0</Version>
</PackageReference>
<PackageReference Include="NuGet.Protocol">
<Version>5.0.0-preview1.5665</Version>
</PackageReference>
<PackageReference Include="NuGet.Packaging">
<Version>5.0.0-preview1.5665</Version>
</PackageReference>
<PackageReference Include="NuGet.StrongName.json-ld.net">
<Version>1.0.6</Version>
</PackageReference>
Expand All @@ -314,9 +308,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NuGet.Packaging.Core">
<Version>5.0.0-preview1.5665</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.Logging">
<Version>2.58.0</Version>
</PackageReference>
Expand Down
4 changes: 3 additions & 1 deletion src/Ng/Jobs/Catalog2IconJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Ng.Jobs
public class Catalog2IconJob : LoopingNgJob
{
private const int DegreeOfParallelism = 120;
private const string FailCacheTime = "failCacheTime";
private IconsCollector _collector;
private DurableCursor _front;

Expand All @@ -33,6 +34,7 @@ protected override void Init(IDictionary<string, string> arguments, Cancellation

var verbose = arguments.GetOrDefault(Arguments.Verbose, false);
var packageStorageBase = arguments.GetOrThrow<string>(Arguments.ContentBaseAddress);
var failCacheTime = arguments.GetOrDefault(FailCacheTime, TimeSpan.FromHours(1));
var auxStorageFactory = CreateAuxStorageFactory(arguments, verbose);
var targetStorageFactory = CreateTargetStorageFactory(arguments, verbose);
var packageStorage = new AzureStorage(
Expand All @@ -52,7 +54,7 @@ protected override void Init(IDictionary<string, string> arguments, Cancellation
var catalogClient = new CatalogClient(simpleHttpClient, LoggerFactory.CreateLogger<CatalogClient>());
var httpResponseProvider = new HttpClientWrapper(httpClient);
var externalIconProvider = new ExternalIconContentProvider(httpResponseProvider, LoggerFactory.CreateLogger<ExternalIconContentProvider>());
var iconCopyResultCache = new IconCopyResultCache(auxStorageFactory.Create(), LoggerFactory.CreateLogger<IconCopyResultCache>());
var iconCopyResultCache = new IconCopyResultCache(auxStorageFactory.Create(), failCacheTime, LoggerFactory.CreateLogger<IconCopyResultCache>());

var leafProcessor = new CatalogLeafDataProcessor(
packageStorage,
Expand Down
3 changes: 0 additions & 3 deletions src/Ng/Ng.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NuGet.Protocol">
<Version>5.0.0-preview1.5665</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.Configuration">
<Version>2.58.0</Version>
</PackageReference>
Expand Down
7 changes: 7 additions & 0 deletions src/Ng/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -98,6 +99,12 @@ public static async Task MainAsync(string[] args)

Console.WriteLine(job != null ? job.GetUsage() : NgJob.GetUsageBase());
}
catch (KeyNotFoundException knfe)
{
_logger?.LogError("An expected key was not found. One possible cause of this is required argument has not been provided: {Exception}", knfe);

Console.WriteLine(job != null ? job.GetUsage() : NgJob.GetUsageBase());
}
catch (Exception e)
{
_logger?.LogCritical("A critical exception occured in ng.exe! {Exception}", e);
Expand Down
7 changes: 1 addition & 6 deletions src/NuGet.Indexing/Extraction/CatalogPackageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,11 @@ public override Task<byte[]> GetArchiveHashAsync(HashAlgorithmName hashAlgorithm
}

public override bool CanVerifySignedPackages(SignedPackageVerifierSettings verifierSettings)
{
return false;
}

public override string GetContentHashForSignedPackage(CancellationToken token)
{
throw new NotImplementedException();
}

public override string GetContentHash(CancellationToken token)
public override string GetContentHash(CancellationToken token, Func<string> GetUnsignedPackageHash = null)
{
throw new NotImplementedException();
}
Expand Down
3 changes: 0 additions & 3 deletions src/NuGet.Indexing/NuGet.Indexing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NuGet.Packaging">
<Version>5.0.0-preview1.5665</Version>
</PackageReference>
<PackageReference Include="NuGet.Services.Configuration">
<Version>2.58.0</Version>
</PackageReference>
Expand Down
25 changes: 25 additions & 0 deletions src/NuGet.Protocol.Catalog/Models/AlternatePackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Newtonsoft.Json;

namespace NuGet.Protocol.Catalog
{
/// <summary>
/// Source: https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#alternate-package
/// </summary>
public class AlternatePackage
{
[JsonProperty("@id")]
public string Url { get; set; }

[JsonProperty("@type")]
public string Type { get; set; }

[JsonProperty("id")]
public string Id { get; set; }

[JsonProperty("range")]
public string Range { get; set; }
}
}
23 changes: 23 additions & 0 deletions src/NuGet.Protocol.Catalog/Models/BasePackageDependencyGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using Newtonsoft.Json;

namespace NuGet.Protocol.Catalog
{
public abstract class BasePackageDependencyGroup<TDependency> where TDependency : PackageDependency
{
[JsonProperty("@id")]
public string Url { get; set; }

[JsonProperty("@type")]
public string Type { get; set; }

[JsonProperty("dependencies")]
public List<TDependency> Dependencies { get; set; }

[JsonProperty("targetFramework")]
public string TargetFramework { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/NuGet.Protocol.Catalog/Models/PackageDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace NuGet.Protocol.Catalog
{
public class PackageDependency
{
[JsonProperty("@id")]
public string Url { get; set; }

[JsonProperty("@type")]
public string Type { get; set; }

[JsonProperty("id")]
public string Id { get; set; }

Expand Down
10 changes: 1 addition & 9 deletions src/NuGet.Protocol.Catalog/Models/PackageDependencyGroup.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using Newtonsoft.Json;

namespace NuGet.Protocol.Catalog
{
public class PackageDependencyGroup
public class PackageDependencyGroup : BasePackageDependencyGroup<PackageDependency>
{
[JsonProperty("targetFramework")]
public string TargetFramework { get; set; }

[JsonProperty("dependencies")]
public List<PackageDependency> Dependencies { get; set; }
}
}
29 changes: 29 additions & 0 deletions src/NuGet.Protocol.Catalog/Models/PackageDeprecation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using Newtonsoft.Json;

namespace NuGet.Protocol.Catalog
{
/// <summary>
/// Source: https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#package-deprecation
/// </summary>
public class PackageDeprecation
{
[JsonProperty("@id")]
public string Url { get; set; }

[JsonProperty("@type")]
public string Type { get; set; }

[JsonProperty("alternatePackage")]
public AlternatePackage AlternatePackage { get; set; }

[JsonProperty("message")]
public string Message { get; set; }

[JsonProperty("reasons")]
public List<string> Reasons { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class PackageDetailsCatalogLeaf : CatalogLeaf
[JsonProperty("dependencyGroups")]
public List<PackageDependencyGroup> DependencyGroups { get; set; }

[JsonProperty("deprecation")]
public PackageDeprecation Deprecation { get; set; }

[JsonProperty("description")]
public string Description { get; set; }

Expand Down
5 changes: 4 additions & 1 deletion src/NuGet.Protocol.Catalog/NuGet.Protocol.Catalog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NuGet.Protocol">
<Version>4.8.0</Version>
<Version>5.0.0-preview1.5707</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand All @@ -76,6 +76,8 @@
<Compile Include="ICatalogLeafProcessor.cs" />
<Compile Include="ICursor.cs" />
<Compile Include="ISimpleHttpClient.cs" />
<Compile Include="Models\AlternatePackage.cs" />
<Compile Include="Models\BasePackageDependencyGroup.cs" />
<Compile Include="Models\CatalogIndex.cs" />
<Compile Include="Models\CatalogLeaf.cs" />
<Compile Include="Models\CatalogLeafItem.cs" />
Expand All @@ -84,6 +86,7 @@
<Compile Include="Models\CatalogPageContext.cs" />
<Compile Include="Models\CatalogPageItem.cs" />
<Compile Include="Models\ContextTypeDescription.cs" />
<Compile Include="Models\PackageDeprecation.cs" />
<Compile Include="Models\ICatalogLeafItem.cs" />
<Compile Include="Models\ModelExtensions.cs" />
<Compile Include="Models\PackageDeleteCatalogLeaf.cs" />
Expand Down
5 changes: 5 additions & 0 deletions src/NuGet.Services.V3/NuGet.Services.V3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<Compile Include="CommitCollectorConfiguration.cs" />
<Compile Include="DefaultBlobRequestOptions.cs" />
<Compile Include="DependencyInjectionExtensions.cs" />
<Compile Include="Registration\Models\ICommitted.cs" />
<Compile Include="Registration\Models\RegistrationPackageDependency.cs" />
<Compile Include="Registration\Models\RegistrationContainerContext.cs" />
<Compile Include="Registration\Models\RegistrationLeafContext.cs" />
<Compile Include="Registration\Models\RegistrationPackageDependencyGroup.cs" />
<Compile Include="Support\Guard.cs" />
<Compile Include="Support\IdAndValue.cs" />
<Compile Include="IV3TelemetryService.cs" />
Expand Down
13 changes: 13 additions & 0 deletions src/NuGet.Services.V3/Registration/Models/ICommitted.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace NuGet.Protocol.Registration
{
public interface ICommitted
{
string CommitId { get; set; }
DateTimeOffset CommitTimestamp { get; set; }
}
}
Loading

0 comments on commit 1ab3792

Please sign in to comment.