Skip to content

Commit

Permalink
feat(simint): multiple API updates (#402)
Browse files Browse the repository at this point in the history
- remove deprecated "Labels" property on simulator models
- add LogSeverity override for a simulation run
- add "Active" property on simulator integration resource
- added IncludeAllFields property to control amount of data returned by routine revision list endpoint
  • Loading branch information
polomani authored Oct 23, 2024
1 parent 0666648 commit a3a2224
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 29 deletions.
6 changes: 6 additions & 0 deletions CogniteSdk.Types/Alpha/Simulators/SimulationRunCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class SimulationRunCreate
/// </summary>
public long? RunTime { get; set; }

/// <summary>
/// Override the minimum severity level for the simulation run logs.
/// If not set defaults to minimum severity specified in the connector logger configuration.
/// </summary>
public string LogSeverity { get; set; }

/// <summary>
/// Queue the simulation run when connector is down
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions CogniteSdk.Types/Alpha/Simulators/SimulatorIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public class SimulatorIntegration
/// </summary>
public long? ConnectorStatusUpdatedTime { get; set; }
/// <summary>
/// Connector is considered active if the heartbeat was reported within the last minute.
/// </summary>
public bool Active { get; set; }
/// <summary>
/// Log id of the simulator integration.
/// </summary>
public long LogId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public class SimulatorIntegrationFilter
/// <summary>
/// Filter by simulator external ids.
/// </summary>
public IEnumerable<string> simulatorExternalIds { get; set; }
public IEnumerable<string> SimulatorExternalIds { get; set; }

/// <summary>
/// Filter by whether the simulator integration is active or not.
/// Connector is considered active if the heartbeat was reported within the last minute.
/// </summary>
public bool? Active { get; set; }

/// <inheritdoc />
public override string ToString() => Stringable.ToString<SimulatorIntegrationFilter>(this);
Expand Down
6 changes: 6 additions & 0 deletions CogniteSdk.Types/Alpha/Simulators/SimulatorLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class SimulatorLog
/// </summary>
public IEnumerable<SimulatorLogDataEntry> Data { get; set; }

/// <summary>
/// Minimum severity level of the log data.
/// This overrides connector configuration minimum severity level and can be used for more granular control, e.g. to debug a specific simulation run.
/// </summary>
public string Severity { get; set; }

/// <summary>
/// Data set id of the simulator log.
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions CogniteSdk.Types/Alpha/Simulators/SimulatorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public class SimulatorModel
/// </summary>
public long DataSetId { get; set; }

/// <summary>
/// Labels of the simulation model.
/// </summary>
public IEnumerable<CogniteExternalId> Labels { get; set; }

/// <summary>
/// Model type of the simulation model. List of available types is available in the simulator resource.
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions CogniteSdk.Types/Alpha/Simulators/SimulatorModelCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public class SimulatorModelCreate
/// </summary>
public long DataSetId { get; set; }

/// <summary>
/// Labels of the simulation model.
/// </summary>
public IEnumerable<CogniteExternalId> Labels { get; set; }

/// <summary>
/// Model type of the simulation model. List of available types is available in the simulator resource.
/// </summary>
Expand Down
7 changes: 0 additions & 7 deletions CogniteSdk.Types/Alpha/Simulators/SimulatorModelUpdate.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2024 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;
using CogniteSdk.Types.Common;

namespace CogniteSdk.Alpha
Expand All @@ -21,11 +19,6 @@ public class SimulatorModelUpdate
/// </summary>
public Update<string> Description { get; set; }

/// <summary>
/// Update the labels of the simulator model.
/// </summary>
public Update<IEnumerable<string>> Labels { get; set; }

/// <inheritdoc />
public override string ToString() => Stringable.ToString<SimulatorModelUpdate>(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class SimulatorRoutineRevisionQuery : CursorQueryBase
/// </summary>
public IEnumerable<SimulatorSortItem> Sort { get; set; }

/// <summary>
/// If all fields should be included in the response.
/// If set to false - script, configuration.inputs and configuration.outputs are excluded from the response.
/// </summary>
public bool? IncludeAllFields { get; set; }
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions CogniteSdk/test/fsharp/Alpha/SimulatorModels.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open Tests.Integration.Alpha.Common

[<Fact>]
[<Trait("resource", "simulatorModels")>]
[<Trait("api", "simulators")>]
let ``Create and list simulator models is Ok`` () =
task {
// Arrange
Expand All @@ -34,7 +35,6 @@ let ``Create and list simulator models is Ok`` () =
SimulatorExternalId = simulatorExternalId,
Name = "test_model",
Description = "test_model_description",
Labels = [ new CogniteExternalId("test_label") ],
DataSetId = dataSet.Id,
Type = "OilWell"
)
Expand Down Expand Up @@ -100,6 +100,7 @@ let ``Create and list simulator models is Ok`` () =

[<Fact>]
[<Trait("resource", "simulatorModels")>]
[<Trait("api", "simulators")>]
let ``Create and list simulator model revisions is Ok`` () =
task {
// Arrange
Expand Down Expand Up @@ -131,7 +132,6 @@ let ``Create and list simulator model revisions is Ok`` () =
SimulatorExternalId = simulatorExternalId,
Name = "test_model",
Description = "test_model_description",
Labels = [ new CogniteExternalId("test_label") ],
DataSetId = dataSet.Id,
Type = "OilWell"
)
Expand Down
21 changes: 16 additions & 5 deletions CogniteSdk/test/fsharp/Alpha/SimulatorRoutines.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open Common

[<Fact>]
[<Trait("resource", "simulatorRoutines")>]
[<Trait("api", "simulators")>]
let ``Create simulator routines is Ok`` () =
task {
// Arrange
Expand Down Expand Up @@ -45,7 +46,6 @@ let ``Create simulator routines is Ok`` () =
SimulatorExternalId = simulatorExternalId,
Name = "test_model",
Description = "test_model_description",
Labels = [ new CogniteExternalId("test_label") ],
DataSetId = dataSet.Id,
Type = "OilWell"
)
Expand Down Expand Up @@ -109,13 +109,14 @@ let ``Create simulator routines is Ok`` () =

[<Fact>]
[<Trait("resource", "simulatorRoutines")>]
[<Trait("api", "simulators")>]
let ``Create simulator routine revision is Ok`` () =
task {
// Arrange
let now = DateTimeOffset.Now.ToUnixTimeMilliseconds()
let routineExternalId = $"test_routine_3_{now}"
let routineRevisionExternalId = $"{routineExternalId}_1"
let modelExternalId = $"test_model_{now}"
let modelExternalId = $"test_model_1_{now}"
let simulatorExternalId = $"test_sim_2_{now}"
let integrationExternalId = $"test_integration_{now}"

Expand All @@ -140,7 +141,6 @@ let ``Create simulator routine revision is Ok`` () =
SimulatorExternalId = simulatorExternalId,
Name = "test_model",
Description = "test_model_description",
Labels = [ new CogniteExternalId("test_label") ],
DataSetId = dataSet.Id,
Type = "OilWell"
)
Expand Down Expand Up @@ -229,15 +229,23 @@ let ``Create simulator routine revision is Ok`` () =

let! resRevision = writeClient.Alpha.Simulators.CreateSimulatorRoutineRevisionsAsync([ revToCreate ])

let! resListRevisions =
let! resRetrieveRevisions =
writeClient.Alpha.Simulators.RetrieveSimulatorRoutineRevisionsAsync(
[ new Identity(routineRevisionExternalId) ]
)

let revision = resListRevisions |> Seq.head
let revision = resRetrieveRevisions |> Seq.head
let revConfig = revision.Configuration
let revConfigToCreate = revToCreate.Configuration

let! resListRevisions = writeClient.Alpha.Simulators.ListSimulatorRoutineRevisionsAsync(
new SimulatorRoutineRevisionQuery(
Filter = SimulatorRoutineRevisionFilter(RoutineExternalIds = [ routineExternalId ]),
IncludeAllFields = true,
Limit = 10
)
)

// Assert
test <@ resRevision |> Seq.length = 1 @>

Expand Down Expand Up @@ -277,6 +285,9 @@ let ``Create simulator routine revision is Ok`` () =

let scriptStageRes = Seq.head revision.Script
test <@ scriptStageRes.ToString() = scriptStage.ToString() @>

let listRev = resListRevisions.Items |> Seq.find (fun (item: SimulatorRoutineRevision) -> item.ExternalId = routineRevisionExternalId)
test <@ listRev.ToString() = revision.ToString() @>
finally
writeClient.Alpha.Simulators.DeleteAsync([ new Identity(simulatorExternalId) ])
|> ignore
Expand Down
10 changes: 10 additions & 0 deletions CogniteSdk/test/fsharp/Alpha/SimulatorRuns.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let ``Create simulation runs by routine with data and callback is Ok`` () =
Value = SimulatorValue.Create(50.1), // original value is 10 C
Unit = SimulationInputUnitOverride(Name = "F")
) ],
LogSeverity = "Debug",
RunTime = now,
Queue = true
)
Expand Down Expand Up @@ -58,6 +59,10 @@ let ``Create simulation runs by routine with data and callback is Ok`` () =

let! resDataAfterCallback = writeClient.Alpha.Simulators.ListSimulationRunsDataAsync([ simulationRun.Id ])

let! resSimRunLogs = writeClient.Alpha.Simulators.RetrieveSimulatorLogsAsync(
[ new Identity(simulationRun.LogId.Value) ]
)


// Assert
let len = Seq.length res
Expand Down Expand Up @@ -90,6 +95,11 @@ let ``Create simulation runs by routine with data and callback is Ok`` () =
let item = item.Value
test <@ item.Value = SimulatorValue.Create(100) @>
test <@ item.Unit.Name = "F" @>

// Assert log
test <@ resSimRunLogs |> Seq.length = 1 @>
let logItem = resSimRunLogs |> Seq.head
test <@ logItem.Severity = "Debug" @>
}

[<Fact>]
Expand Down
9 changes: 6 additions & 3 deletions CogniteSdk/test/fsharp/Alpha/Simulators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let simulatorExternalId = $"test_sim_{now}"

[<Fact>]
[<Trait("resource", "simulators")>]
[<Trait("api", "simulators")>]
let ``Create and delete simulators is Ok`` () =
task {

Expand Down Expand Up @@ -61,7 +62,8 @@ let ``List simulators is Ok`` () =
}

[<Fact>]
[<Trait("resource", "simulators")>]
[<Trait("resource", "simulatorIntegrations")>]
[<Trait("api", "simulators")>]
let ``Create and update simulator integration is Ok`` () =
task {
// Arrange
Expand Down Expand Up @@ -130,11 +132,12 @@ let ``Create and update simulator integration is Ok`` () =
}

[<Fact>]
[<Trait("resource", "simulators")>]
[<Trait("resource", "simulatorIntegrations")>]
[<Trait("api", "simulators")>]
let ``List simulator integrations is Ok`` () =
task {
// Arrange
let query = SimulatorIntegrationQuery()
let query = SimulatorIntegrationQuery(Filter = SimulatorIntegrationFilter(Active=true))

// Act
let! res = writeClient.Alpha.Simulators.ListSimulatorIntegrationsAsync(query)
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.7.0
4.8.0

0 comments on commit a3a2224

Please sign in to comment.