Skip to content

Commit ba2d230

Browse files
committed
Implement unimplemented concurrency methods for all server classes
1 parent 6ecc668 commit ba2d230

6 files changed

Lines changed: 388 additions & 80 deletions

File tree

src/code/ContainerRegistryServerAPICalls.cs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,40 @@ public ContainerRegistryServerAPICalls(PSRepositoryInfo repository, PSCmdlet cmd
8282

8383
#region Overridden Methods
8484

85+
/// <summary>
86+
/// Async find method which allows for searching for single name with specific version.
87+
/// Name: no wildcard support
88+
/// Version: no wildcard support
89+
/// This is the concurrent (parallel) counterpart of FindVersion().
90+
/// </summary>
8591
public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
8692
{
87-
throw new NotImplementedException("FindVersionAsync is not implemented for ContainerRegistryServerAPICalls.");
93+
debugMsgs.Enqueue("In ContainerRegistryServerAPICalls::FindVersionAsync()");
94+
FindResults findResponse = FindVersion(packageName, version, type, out ErrorRecord errRecord);
95+
if (errRecord != null)
96+
{
97+
errorMsgs.Enqueue(errRecord);
98+
}
99+
100+
return Task.FromResult(findResponse);
88101
}
89102

103+
/// <summary>
104+
/// Async find method which allows for searching for single name with version range.
105+
/// Name: no wildcard support
106+
/// Version: supports wildcards
107+
/// This is the concurrent (parallel) counterpart of FindVersionGlobbing().
108+
/// </summary>
90109
public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
91110
{
92-
throw new NotImplementedException("FindVersionGlobbingAsync is not implemented for ContainerRegistryServerAPICalls.");
111+
debugMsgs.Enqueue("In ContainerRegistryServerAPICalls::FindVersionGlobbingAsync()");
112+
FindResults findResponse = FindVersionGlobbing(packageName, versionRange, includePrerelease, type, getOnlyLatest, out ErrorRecord errRecord);
113+
if (errRecord != null)
114+
{
115+
errorMsgs.Enqueue(errRecord);
116+
}
117+
118+
return Task.FromResult(findResponse);
93119
}
94120

95121
/// <summary>
@@ -158,9 +184,21 @@ public override FindResults FindName(string packageName, bool includePrerelease,
158184
}
159185

160186

187+
/// <summary>
188+
/// Async find method which allows for searching for single name and returns latest version.
189+
/// Name: no wildcard support
190+
/// This is the concurrent (parallel) counterpart of FindName().
191+
/// </summary>
161192
public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
162193
{
163-
throw new NotImplementedException("FindNameAsync is not implemented for ContainerRegistryServerAPICalls.");
194+
debugMsgs.Enqueue("In ContainerRegistryServerAPICalls::FindNameAsync()");
195+
FindResults findResponse = FindName(packageName, includePrerelease, type, out ErrorRecord errRecord);
196+
if (errRecord != null)
197+
{
198+
errorMsgs.Enqueue(errRecord);
199+
}
200+
201+
return Task.FromResult(findResponse);
164202
}
165203

166204
/// <summary>
@@ -329,7 +367,14 @@ public override Stream InstallPackage(string packageName, string packageVersion,
329367
/// </summary>
330368
public override Task<Stream> InstallPackageAsync(string packageName, string packageVersion, bool includePrerelease, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
331369
{
332-
throw new NotImplementedException("FindNameAsync is not implemented for ContainerRegistryServerAPICalls.");
370+
debugMsgs.Enqueue("In ContainerRegistryServerAPICalls::InstallPackageAsync()");
371+
Stream results = InstallPackage(packageName, packageVersion, includePrerelease, out ErrorRecord errRecord);
372+
if (errRecord != null)
373+
{
374+
errorMsgs.Enqueue(errRecord);
375+
}
376+
377+
return Task.FromResult(results);
333378
}
334379

335380
/// <summary>

src/code/FindHelper.cs

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -912,17 +912,12 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
912912

913913
ConcurrentDictionary<string, Task<FindResults>> cachedNetworkCalls = new ConcurrentDictionary<string, Task<FindResults>>();
914914
Task<FindResults> response = null;
915-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2) {
916-
string key = $"{pkgName}|{_nugetVersion.ToNormalizedString()}|{_type}";
917-
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(pkgName, _nugetVersion.ToNormalizedString(), _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
918-
919-
responses = response.GetAwaiter().GetResult();
915+
string key = $"{pkgName}|{_nugetVersion.ToNormalizedString()}|{_type}";
916+
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(pkgName, _nugetVersion.ToNormalizedString(), _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
917+
918+
responses = response.GetAwaiter().GetResult();
920919

921-
Utils.WriteOutConcurrentQueue(_cmdletPassedIn, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
922-
}
923-
else {
924-
responses = currentServer.FindVersion(pkgName, _nugetVersion.ToNormalizedString(), _type, out errRecord);
925-
}
920+
Utils.WriteOutConcurrentQueue(_cmdletPassedIn, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
926921
}
927922
else
928923
{
@@ -996,15 +991,10 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
996991
{
997992
ConcurrentDictionary<string, Task<FindResults>> cachedNetworkCalls = new ConcurrentDictionary<string, Task<FindResults>>();
998993
Task<FindResults> response = null;
999-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2) {
1000-
string key = $"{pkgName}|{_versionRange.ToString()}|{_type}";
1001-
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionGlobbingAsync(pkgName, _versionRange, _prerelease, _type, getOnlyLatest: false, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
1002-
1003-
responses = response.GetAwaiter().GetResult();
1004-
}
1005-
else {
1006-
responses = currentServer.FindVersionGlobbing(pkgName, _versionRange, _prerelease, _type, getOnlyLatest: false, out errRecord);
1007-
}
994+
string key = $"{pkgName}|{_versionRange.ToString()}|{_type}";
995+
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionGlobbingAsync(pkgName, _versionRange, _prerelease, _type, getOnlyLatest: false, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
996+
997+
responses = response.GetAwaiter().GetResult();
1008998
}
1009999
else
10101000
{
@@ -1189,7 +1179,7 @@ internal void FindDependencyPackagesHelper(ServerApiCall currentServer, Response
11891179
//const int PARALLEL_THRESHOLD = 5; // TODO: Trottle limit from user, defaults to 5;
11901180
int processorCount = Environment.ProcessorCount;
11911181
int maxDegreeOfParallelism = processorCount * 4;
1192-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2 && currentPkg.Dependencies.Length > processorCount)
1182+
if (currentPkg.Dependencies.Length > processorCount)
11931183
{
11941184
Parallel.ForEach(currentPkg.Dependencies, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, dep =>
11951185
{
@@ -1293,20 +1283,13 @@ private PSResourceInfo FindDependencyWithSpecificVersion(
12931283
Task<FindResults> response = null;
12941284
debugMsgs.Enqueue("In FindHelper::FindDependencyWithSpecificVersion()");
12951285

1296-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2)
1297-
{
1298-
// See if the network call we're making is already cached, if not, call FindNameAsync() and cache results
1299-
string key = $"{dep.Name}|{dep.VersionRange.MaxVersion.ToString()}|{_type}";
1300-
debugMsgs.Enqueue("Checking if network call is cached.");
1301-
response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(dep.Name, dep.VersionRange.MaxVersion.ToString(), _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
1302-
1303-
responses = response.GetAwaiter().GetResult();
1304-
}
1305-
else
1306-
{
1307-
responses = currentServer.FindVersion(dep.Name, dep.VersionRange.MaxVersion.ToString(), _type, out errRecord);
1308-
}
1309-
1286+
1287+
// See if the network call we're making is already cached, if not, call FindNameAsync() and cache results
1288+
string key = $"{dep.Name}|{dep.VersionRange.MaxVersion.ToString()}|{_type}";
1289+
debugMsgs.Enqueue("Checking if network call is cached.");
1290+
response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(dep.Name, dep.VersionRange.MaxVersion.ToString(), _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
1291+
1292+
responses = response.GetAwaiter().GetResult();
13101293

13111294
// Error handling and Convert to PSResource object
13121295
if (errRecord != null)
@@ -1369,19 +1352,12 @@ private PSResourceInfo FindDependencyWithLowerBound(
13691352
Task<FindResults> response = null;
13701353
debugMsgs.Enqueue("In FindHelper::FindDependencyWithLowerBound()");
13711354

1372-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2)
1373-
{
1374-
// See if the network call we're making is already cached, if not, call FindNameAsync() and cache results
1375-
string key = $"{dep.Name}|*|{_type}";
1376-
debugMsgs.Enqueue("Checking if network call is cached.");
1377-
response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindNameAsync(dep.Name, includePrerelease: true, _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
1378-
1379-
responses = response.GetAwaiter().GetResult();
1380-
}
1381-
else
1382-
{
1383-
responses = currentServer.FindName(dep.Name, includePrerelease: true, _type, out errRecord);
1384-
}
1355+
// See if the network call we're making is already cached, if not, call FindNameAsync() and cache results
1356+
string key = $"{dep.Name}|*|{_type}";
1357+
debugMsgs.Enqueue("Checking if network call is cached.");
1358+
response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindNameAsync(dep.Name, includePrerelease: true, _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
1359+
1360+
responses = response.GetAwaiter().GetResult();
13851361

13861362
// Error handling and Convert to PSResource object
13871363
if (errRecord != null)
@@ -1445,21 +1421,13 @@ private PSResourceInfo FindDependencyWithUpperBound(
14451421

14461422
ConcurrentDictionary<string, Task<FindResults>> cachedNetworkCalls = new ConcurrentDictionary<string, Task<FindResults>>();
14471423
debugMsgs.Enqueue("In FindHelper::FindDependencyWithUpperBound()");
1424+
// See if the network call we're making is already caced, if not, call FindNameAsync() and cache results
1425+
string key = $"{dep.Name}|{dep.VersionRange.MaxVersion.ToString()}|{_type}";
1426+
debugMsgs.Enqueue("Checking if network call is cached.");
1427+
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionGlobbingAsync(dep.Name, dep.VersionRange, includePrerelease: true, ResourceType.None, getOnlyLatest: true, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
14481428

1449-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2)
1450-
{
1451-
// See if the network call we're making is already caced, if not, call FindNameAsync() and cache results
1452-
string key = $"{dep.Name}|{dep.VersionRange.MaxVersion.ToString()}|{_type}";
1453-
debugMsgs.Enqueue("Checking if network call is cached.");
1454-
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionGlobbingAsync(dep.Name, dep.VersionRange, includePrerelease: true, ResourceType.None, getOnlyLatest: true, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
1455-
1456-
responses = response.GetAwaiter().GetResult();
1429+
responses = response.GetAwaiter().GetResult();
14571430

1458-
}
1459-
else
1460-
{
1461-
responses = currentServer.FindVersionGlobbing(dep.Name, dep.VersionRange, includePrerelease: true, ResourceType.None, getOnlyLatest: true, out errRecord);
1462-
}
14631431

14641432
// Error handling and Convert to PSResource object
14651433
if (errRecord != null)

src/code/InstallHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ private ConcurrentDictionary<string, Hashtable> BeginPackageInstall(
801801
}
802802
else
803803
{
804-
// Concurrent updates, currently only implemented for v2 server repositories
804+
// Concurrent updates
805805
// Find all dependencies
806806
if (!skipDependencyCheck)
807807
{
@@ -853,7 +853,7 @@ private ConcurrentDictionary<string, Hashtable> InstallParentAndDependencyPackag
853853
// TODO: figure out a good threshold and parallel count
854854
int processorCount = Environment.ProcessorCount;
855855
_cmdletPassedIn.WriteDebug($"parentAndDeps.Count is {parentAndDeps.Count}, processor count is: {processorCount}");
856-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2 && parentAndDeps.Count > processorCount)
856+
if (parentAndDeps.Count > processorCount)
857857
{
858858
_cmdletPassedIn.WriteDebug($"parentAndDeps.Count is greater than processor count");
859859
// Set the maximum degree of parallelism to 32? (Invoke-Command has default of 32, that's where we got this number from)

src/code/LocalServerApiCalls.cs

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,40 @@ public LocalServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn
4141

4242
#region Overridden Methods
4343

44+
/// <summary>
45+
/// Async find method which allows for searching for single name with specific version.
46+
/// Name: no wildcard support
47+
/// Version: no wildcard support
48+
/// This is the concurrent (parallel) counterpart of FindVersion().
49+
/// </summary>
4450
public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
4551
{
46-
throw new NotImplementedException();
52+
debugMsgs.Enqueue("In LocalServerApiCalls::FindVersionAsync()");
53+
FindResults findResponse = FindVersionHelper(packageName, version, tags: Utils.EmptyStrArray, type, out ErrorRecord errRecord);
54+
if (errRecord != null)
55+
{
56+
errorMsgs.Enqueue(errRecord);
57+
}
58+
59+
return Task.FromResult(findResponse);
4760
}
4861

62+
/// <summary>
63+
/// Async find method which allows for searching for single name with version range.
64+
/// Name: no wildcard support
65+
/// Version: supports wildcards
66+
/// This is the concurrent (parallel) counterpart of FindVersionGlobbing().
67+
/// </summary>
4968
public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
5069
{
51-
throw new NotImplementedException();
70+
debugMsgs.Enqueue("In LocalServerApiCalls::FindVersionGlobbingAsync()");
71+
FindResults findResponse = FindVersionGlobbing(packageName, versionRange, includePrerelease, type, getOnlyLatest, out ErrorRecord errRecord);
72+
if (errRecord != null)
73+
{
74+
errorMsgs.Enqueue(errRecord);
75+
}
76+
77+
return Task.FromResult(findResponse);
5278
}
5379
/// <summary>
5480
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
@@ -124,9 +150,21 @@ public override FindResults FindName(string packageName, bool includePrerelease,
124150
return FindNameHelper(packageName, Utils.EmptyStrArray, includePrerelease, type, out errRecord);
125151
}
126152

153+
/// <summary>
154+
/// Async find method which allows for searching for single name and returns latest version.
155+
/// Name: no wildcard support
156+
/// This is the concurrent (parallel) counterpart of FindName().
157+
/// </summary>
127158
public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
128159
{
129-
throw new NotImplementedException();
160+
debugMsgs.Enqueue("In LocalServerApiCalls::FindNameAsync()");
161+
FindResults findResponse = FindNameHelper(packageName, tags: Utils.EmptyStrArray, includePrerelease, type, out ErrorRecord errRecord);
162+
if (errRecord != null)
163+
{
164+
errorMsgs.Enqueue(errRecord);
165+
}
166+
167+
return Task.FromResult(findResponse);
130168
}
131169

132170
/// <summary>
@@ -278,7 +316,26 @@ public override Stream InstallPackage(string packageName, string packageVersion,
278316
/// </summary>
279317
public override Task<Stream> InstallPackageAsync(string packageName, string packageVersion, bool includePrerelease, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
280318
{
281-
throw new NotImplementedException("InstallPackageAsync is not implemented for LocalServerAPICalls.");
319+
debugMsgs.Enqueue("In LocalServerApiCalls::InstallPackageAsync()");
320+
Stream results = new MemoryStream();
321+
if (string.IsNullOrEmpty(packageVersion))
322+
{
323+
errorMsgs.Enqueue(new ErrorRecord(
324+
exception: new ArgumentNullException($"Package version could not be found for {packageName}"),
325+
"PackageVersionNullOrEmptyError",
326+
ErrorCategory.InvalidArgument,
327+
_cmdletPassedIn));
328+
329+
return Task.FromResult(results);
330+
}
331+
332+
results = InstallVersion(packageName, packageVersion, out ErrorRecord errRecord);
333+
if (errRecord != null)
334+
{
335+
errorMsgs.Enqueue(errRecord);
336+
}
337+
338+
return Task.FromResult(results);
282339
}
283340

284341
#endregion

0 commit comments

Comments
 (0)