Skip to content

Commit 0eb6c7e

Browse files
committed
feat: health support implemented
1 parent b33a065 commit 0eb6c7e

File tree

6 files changed

+170
-4
lines changed

6 files changed

+170
-4
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## NEXT
44
* improved error handling.
5+
* new method GetHealth().
56

67
## 1.1.0 (2020-06-25)
78
* supports FOSSology REST API v1.0.16 (FOSSology 3.8.0 built @ 2020/06/19).
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="DatabaseInfo.cs" company="Tethys">
3+
// Copyright (C) 2022 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet.Model
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// Fossology database information.
21+
/// </summary>
22+
public class DatabaseInfo
23+
{
24+
/// <summary>
25+
/// Gets or sets the status.
26+
/// </summary>
27+
[JsonProperty("status")]
28+
public string Status { get; set; }
29+
30+
/// <inheritdoc />
31+
public override string ToString()
32+
{
33+
return $"{this.Status}";
34+
}
35+
} // DatabaseInfo
36+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="HealthInfo.cs" company="Tethys">
3+
// Copyright (C) 2022 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet.Model
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// Fossology health information.
21+
/// </summary>
22+
public class HealthInfo
23+
{
24+
/// <summary>
25+
/// Gets or sets the status.
26+
/// </summary>
27+
[JsonProperty("status")]
28+
public string Status { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the scheduler.
32+
/// </summary>
33+
[JsonProperty("scheduler")]
34+
public SchedulerInfo Scheduler { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the database.
38+
/// </summary>
39+
[JsonProperty("db")]
40+
public DatabaseInfo Database { get; set; }
41+
42+
/// <inheritdoc />
43+
public override string ToString()
44+
{
45+
return $"{this.Status}: scheduler={this.Scheduler.Status}, database={this.Database.Status}";
46+
}
47+
} // HealthInfo
48+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="SchedulerInfo.cs" company="Tethys">
3+
// Copyright (C) 2022 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet.Model
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// Fossology scheduler information.
21+
/// </summary>
22+
public class SchedulerInfo
23+
{
24+
/// <summary>
25+
/// Gets or sets the status.
26+
/// </summary>
27+
[JsonProperty("status")]
28+
public string Status { get; set; }
29+
30+
/// <inheritdoc />
31+
public override string ToString()
32+
{
33+
return $"{this.Status}";
34+
}
35+
} // SchedulerInfo
36+
}

Fossology.Rest.Dotnet.Test/FossologyClientTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,20 @@ public void MyIntegrationTestLikeUnitTest()
689689
Assert.AreEqual(202, result.Code);
690690
}
691691

692+
/// <summary>
693+
/// Unit test.
694+
/// </summary>
695+
[TestMethod]
696+
public void TestGetHealth()
697+
{
698+
var client = new FossologyClient(LocalUrl, Token);
699+
var actual = client.GetHealth();
700+
Assert.IsNotNull(actual);
701+
Assert.AreEqual("OK", actual.Status);
702+
Assert.AreEqual("OK", actual.Scheduler.Status);
703+
Assert.AreEqual("OK", actual.Database.Status);
704+
}
705+
692706
private static void WaitUntilUploadIsDone(FossologyClient client, int id)
693707
{
694708
while (!client.IsUploadUnpacked(id))

Fossology.Rest.Dotnet/FossologyClient.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ---------------------------------------------------------------------------
22
// <copyright file="FossologyClient.cs" company="Tethys">
3-
// Copyright (C) 2019 T. Graf
3+
// Copyright (C) 2019-2022 T. Graf
44
// </copyright>
55
//
66
// Licensed under the MIT License.
@@ -507,13 +507,24 @@ public UploadSummary GetUploadSummary(int id)
507507
/// Gets the upload with the specified id.
508508
/// </summary>
509509
/// <returns>A list of <see cref="Upload"/> objects.</returns>
510-
public IReadOnlyList<Upload> GetUploadList()
510+
/// <param name="groupName">The group name to use while retrieving uploads.</param>
511+
public IReadOnlyList<Upload> GetUploadList(string groupName = "")
511512
{
512513
Log.Debug("Getting all uploads...");
513514

514-
var result = this.api.Get(this.Url + "/uploads");
515+
var request = new RestRequest(this.Url + $"/uploads", Method.GET);
516+
request.RequestFormat = DataFormat.Json;
517+
request.JsonSerializer = new JsonSerializer();
518+
request.Parameters.Clear();
519+
if (!string.IsNullOrEmpty(groupName))
520+
{
521+
request.AddHeader("groupName", groupName);
522+
} // if
523+
524+
var response = this.api.Execute(request);
525+
515526
var list = JsonConvert.DeserializeObject<List<Upload>>(
516-
result.Content,
527+
response.Content,
517528
new JsonSerializerSettings
518529
{
519530
NullValueHandling = NullValueHandling.Ignore,
@@ -818,6 +829,26 @@ public IReadOnlyList<SearchResult> Search(
818829
return result;
819830
} // Search()
820831
#endregion // SEARCH SUPPORT
832+
833+
#region HEALTH SUPPORT
834+
/// <summary>
835+
/// Gets the health information.
836+
/// </summary>
837+
/// <returns><see cref="HealthInfo"/>.</returns>
838+
public HealthInfo GetHealth()
839+
{
840+
Log.Debug($"Getting health info...");
841+
842+
var result = this.api.Get(this.Url + $"/health");
843+
var info = JsonConvert.DeserializeObject<HealthInfo>(
844+
result.Content,
845+
new JsonSerializerSettings
846+
{
847+
NullValueHandling = NullValueHandling.Ignore,
848+
});
849+
return info;
850+
} // GetHealth()
851+
#endregion
821852
#endregion // PUBLIC METHODS
822853
} // FossologyClient
823854
}

0 commit comments

Comments
 (0)