From 2aa4efb280c99b76b2fa3c8fe5d4dea7db9ddccf Mon Sep 17 00:00:00 2001 From: Einar Date: Fri, 24 Jan 2025 07:27:14 +0100 Subject: [PATCH] Implement integrations API (#414) * Implement integrations API * Use newer .NET --- .github/workflows/build-and-test.yml | 2 +- .github/workflows/publish.yml | 4 +- .../Alpha/Integrations/CheckIn.cs | 162 ++++++++++++++++ .../Alpha/Integrations/ConfigRevision.cs | 119 ++++++++++++ .../Alpha/Integrations/Integration.cs | 183 ++++++++++++++++++ .../Alpha/Integrations/TaskHistory.cs | 54 ++++++ CogniteSdk.Types/Common/StringOrInt.cs | 122 ++++++++++++ .../src/Resources/Alpha/Integrations.cs | 170 ++++++++++++++++ ...t.csproj => CogniteSdk.Test.CSharp.csproj} | 2 +- ...t.fsproj => CogniteSdk.Test.FSharp.fsproj} | 2 +- .../test/fsharp/CoreDataModels/DataPoints.fs | 7 +- Oryx.Cognite/src/Alpha/Integrations.fs | 123 ++++++++++++ Oryx.Cognite/src/Common.fs | 1 + Oryx.Cognite/src/Oryx.Cognite.fsproj | 1 + cognite-sdk-dotnet.sln | 4 +- 15 files changed, 945 insertions(+), 11 deletions(-) create mode 100644 CogniteSdk.Types/Alpha/Integrations/CheckIn.cs create mode 100644 CogniteSdk.Types/Alpha/Integrations/ConfigRevision.cs create mode 100644 CogniteSdk.Types/Alpha/Integrations/Integration.cs create mode 100644 CogniteSdk.Types/Alpha/Integrations/TaskHistory.cs create mode 100644 CogniteSdk.Types/Common/StringOrInt.cs create mode 100644 CogniteSdk/src/Resources/Alpha/Integrations.cs rename CogniteSdk/test/csharp/{CogniteSdk.Test.csproj => CogniteSdk.Test.CSharp.csproj} (94%) rename CogniteSdk/test/fsharp/{CogniteSdk.Test.fsproj => CogniteSdk.Test.FSharp.fsproj} (97%) create mode 100644 Oryx.Cognite/src/Alpha/Integrations.fs diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 1e4c0547..4da5809d 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.200 + dotnet-version: 8.0.x - name: Restore tools run: dotnet tool restore diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f56ad68d..c6a19bc0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,7 +22,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.200 + dotnet-version: 8.0.x - name: Get version id: get-version @@ -74,7 +74,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.200 + dotnet-version: 8.0.x - name: Download nuget packages uses: actions/download-artifact@v4 with: diff --git a/CogniteSdk.Types/Alpha/Integrations/CheckIn.cs b/CogniteSdk.Types/Alpha/Integrations/CheckIn.cs new file mode 100644 index 00000000..e45083d8 --- /dev/null +++ b/CogniteSdk.Types/Alpha/Integrations/CheckIn.cs @@ -0,0 +1,162 @@ +// Copyright 2025 Cognite AS +// SPDX-License-Identifier: Apache-2.0 + +using System.Collections.Generic; + +namespace CogniteSdk.Alpha +{ + /// + /// Type of task update. + /// + public enum TaskUpdateType + { + /// + /// Task was started. + /// + started, + /// + /// Task ended. + /// + ended + } + + /// + /// Update to the status of a task. + /// + public class TaskUpdate + { + /// + /// Type of task update. + /// + public TaskUpdateType Type { get; set; } + /// + /// Name of the task to update, must correspond to a task in the task array given + /// during calls to `extractorinfo`. + /// + public string Name { get; set; } + /// + /// The time this task update occured on the extractor side. + /// Note that task updates are checked to ensure that they are correct when applied sequentially, + /// i.e. that tasks are started after they end etc. + /// + public long Timestamp { get; set; } + } + + /// + /// Error severity level. + /// + public enum ErrorLevel + { + /// + /// Something wrong happened but the extractor was able to continue. + /// + warning, + /// + /// Something wrong happened and the extractor _may_ be able to recover, + /// but there will likely be downtime and/or loss of data. + /// + error, + /// + /// Something wrong happened that cannot be recovered from. + /// After reporting a fatal error the task should end. + /// + fatal, + } + + /// + /// Error with optional associated task. + /// + public class ErrorWithTask + { + /// + /// Error external ID. Errors may be updated by reporting them again with the + /// same external ID. + /// + public string ExternalId { get; set; } + /// + /// Error level. + /// + public ErrorLevel Level { get; set; } + /// + /// Short error description. + /// + public string Description { get; set; } + /// + /// Long error details, may contain details such as stack traces. + /// + public string Details { get; set; } + /// + /// Name of the task this error is associated with. This task must be running when the error occurs. + /// If the task is left out or null, the error is associated with the extractor in general. + /// + public string Task { get; set; } + /// + /// Time the error started. + /// + public long StartTime { get; set; } + /// + /// Time the error ended. Set this equal to `StartTime` if the error is instantaneous. + /// + public long? EndTime { get; set; } + } + + /// + /// Request sent to integrations to report liveness of the extractor and receive any notifications + /// it needs to consider. + /// + /// All fields except `ExternalId` are optional, and an empty checkin still has the semantic + /// meaning of reporting that the extractor is alive. + /// + public class CheckInRequest + { + /// + /// ExternalId of the integration to report checkin to. + /// + public string ExternalId { get; set; } + /// + /// Started and ended tasks. + /// + public IEnumerable TaskEvents { get; set; } + /// + /// Errors and warnings. + /// + public IEnumerable Errors { get; set; } + } + + /// + /// Response to a checkin request. + /// + public class CheckInResponse + { + /// + /// Integration external ID. + /// + public string ExternalId { get; set; } + /// + /// Last stored extractor configuration revision. The extractor may use this + /// to decide to restart with a new remote configuration file. + /// + public int? LastConfigRevision { get; set; } + } + + /// + /// Report changes to general information about the extractor. + /// This is typically used on extractor startup and when loading a new config file. + /// + public class ExtractorInfo + { + /// + /// ID of the running extractor. + /// + public ExtractorId Extractor { get; set; } + /// + /// List of tasks configured for this extractor. + /// + public IEnumerable Tasks { get; set; } + /// + /// Active config revision, either the revision number or "local" if a local config file is + /// currently in use. + /// + public StringOrInt ActiveConfigRevision { get; set; } + } +} \ No newline at end of file diff --git a/CogniteSdk.Types/Alpha/Integrations/ConfigRevision.cs b/CogniteSdk.Types/Alpha/Integrations/ConfigRevision.cs new file mode 100644 index 00000000..6128f3c8 --- /dev/null +++ b/CogniteSdk.Types/Alpha/Integrations/ConfigRevision.cs @@ -0,0 +1,119 @@ +// Copyright 2025 Cognite AS +// SPDX-License-Identifier: Apache-2.0 + +using System.Collections.Generic; + +namespace CogniteSdk.Alpha +{ + /// + /// Create a new configuration revision. + /// + public class CreateConfigRevision + { + /// + /// Integration external ID. + /// + public string ExternalId { get; set; } + /// + /// Optional revision description. Should contain the list of changes. + /// + public string Description { get; set; } + /// + /// The actual config revision contents. + /// + public string Config { get; set; } + } + + /// + /// Metadata about a configuration revision. + /// + public class ConfigRevisionMetadata + { + /// + /// Integration external ID. + /// + public string ExternalId { get; set; } + /// + /// Config revision number. This is simply an incrementing integer. + /// + public int Revision { get; set; } + /// + /// Optional revision description. Should contain the list of changes. + /// + public string Description { get; set; } + /// + /// Time when this revision was created in milliseconds since Jan 1, 1970. + /// + public long CreatedTime { get; set; } + /// + /// Time when this revision was last updated in milliseconds since Jan 1, 1970. + /// + public long LastUpdatedTime { get; set; } + } + + /// + /// An integration configuration revision. + /// + public class ConfigRevision : ConfigRevisionMetadata + { + /// + /// The actual config revision contents. + /// + public string Config { get; set; } + } + + /// + /// Query for retrieving integration config revisions. + /// + public class ConfigRevisionQuery : IQueryParams + { + /// + /// Integration external ID, required. + /// + public string Integration { get; set; } + /// + /// Config revision to fetch. If left out, fetches the latest revision. + /// + public int? Revision { get; set; } + + /// + public List<(string, string)> ToQueryParams() + { + var res = new List<(string, string)> + { + ("integration", Integration) + }; + if (Revision.HasValue) + { + res.Add(("revision", Revision.Value.ToString())); + } + return res; + } + } + + + + /// + /// Query for listing integration config revisions. + /// + public class ConfigRevisionsQuery : IQueryParams + { + /// + /// Integration external ID. + /// + public string Integration { get; set; } + + /// + public List<(string, string)> ToQueryParams() + { + var res = new List<(string, string)>(); + if (Integration != null) + { + res.Add(("integration", Integration)); + } + return res; + } + } + + +} \ No newline at end of file diff --git a/CogniteSdk.Types/Alpha/Integrations/Integration.cs b/CogniteSdk.Types/Alpha/Integrations/Integration.cs new file mode 100644 index 00000000..6a2a1166 --- /dev/null +++ b/CogniteSdk.Types/Alpha/Integrations/Integration.cs @@ -0,0 +1,183 @@ +// Copyright 2025 Cognite AS +// SPDX-License-Identifier: Apache-2.0 + +using System.Collections.Generic; + +namespace CogniteSdk.Alpha +{ + /// + /// ID of an extractor. + /// + public class ExtractorId + { + /// + /// Extractor external ID. If this starts with `cognite` it must + /// correspond to a cognite extractor. + /// + public string ExternalId { get; set; } + /// + /// Extractor version. For cognite extractors this must match a published extractor + /// version. + /// + public string Version { get; set; } + } + + /// + /// Task type. + /// + public enum TaskType + { + /// + /// Task runs continuously. + /// + continuous, + /// + /// Task runs for finite periods of time. + /// + batch, + } + + /// + /// Integration task. + /// + public class IntegrationTask + { + /// + /// Task type. + /// + public TaskType Type { get; set; } + /// + /// Task name, must be unique per integration. + /// + public string Name { get; set; } + /// + /// Whether or not this task can be triggered through an external action. + /// + public bool Action { get; set; } + } + + /// + /// Integration, representing an on-premise program that is managed through CDF. + /// + public class Integration + { + /// + /// Integration external ID, must be unique per project. + /// + public string ExternalId { get; set; } + /// + /// Integration name. + /// + public string Name { get; set; } + /// + /// Integration description. + /// + public string Description { get; set; } + /// + /// ID of the running extractor. + /// + public ExtractorId Extractor { get; set; } + /// + /// Time in milliseconds since Jan 1. 1970 this extractor last checked in. + /// + public long? LastSeen { get; set; } + /// + /// Last published configuration revision. + /// + public int? LastConfigRevision { get; set; } + /// + /// Active config revision, either the revision number or "local" if a local config file is + /// currently in use. + /// + public StringOrInt ActiveConfigRevision { get; set; } + /// + /// List of tasks on this integration. + /// + public IEnumerable Tasks { get; set; } + /// + /// Time when this integration was created in milliseconds since Jan 1, 1970. + /// + public long CreatedTime { get; set; } + /// + /// Time when this integration was last updated in milliseconds since Jan 1, 1970. + /// + public long LastUpdatedTime { get; set; } + } + + /// + /// Create a new integration. + /// + public class CreateIntegration + { + /// + /// Integration external ID, must be unique per project. + /// + public string ExternalId { get; set; } + /// + /// Integration name. + /// + public string Name { get; set; } + /// + /// Integration description. + /// + public string Description { get; set; } + /// + /// ID of the running extractor. + /// Note that this may be changed by the extractor itself once it starts running. + /// + public ExtractorId Extractor { get; set; } + } + + /// + /// Update an integration. + /// + public class UpdateIntegration + { + /// + /// Human readable integration name. + /// + public UpdateNullable Name { get; set; } + /// + /// Integration description. + /// + public UpdateNullable Description { get; set; } + } + + /// + /// Request to delete a list of integrations. + /// + public class IntegrationsDelete : ItemsWithIgnoreUnknownIds { } + + /// + /// Request to retrieve a list of integrations. + /// + public class IntegrationsRetrieve : ItemsWithIgnoreUnknownIds { } + + /// + /// Query for retrieving integration errors. + /// + public class ErrorsQuery : CursorQueryBase + { + /// + /// Filter by task histories belonging to a specific integration. + /// + public string Integration { get; set; } + /// + /// Return task histories belonging to a specific task. Requires integration to be set. + /// + public string TaskName { get; set; } + /// + public override List<(string, string)> ToQueryParams() + { + var qs = base.ToQueryParams(); + if (Integration != null) qs.Add(("integration", Integration)); + if (TaskName != null) qs.Add(("taskName", TaskName)); + return qs; + } + } + + /// + /// Query for retrieving integrations. + /// + public class IntegrationsQuery : CursorQueryBase { } +} \ No newline at end of file diff --git a/CogniteSdk.Types/Alpha/Integrations/TaskHistory.cs b/CogniteSdk.Types/Alpha/Integrations/TaskHistory.cs new file mode 100644 index 00000000..a06e429c --- /dev/null +++ b/CogniteSdk.Types/Alpha/Integrations/TaskHistory.cs @@ -0,0 +1,54 @@ +// Copyright 2025 Cognite AS +// SPDX-License-Identifier: Apache-2.0 + +using System.Collections.Generic; + +namespace CogniteSdk.Alpha +{ + /// + /// A historical task run. + /// + public class TaskHistory + { + /// + /// Name of the task, unique per integration. + /// + public string TaskName { get; set; } + /// + /// Number of errors that occured during this task run. + /// + public int ErrorCount { get; set; } + /// + /// When this task run started, in milliseconds since Jan 1. 1970. + /// + public long StartTime { get; set; } + /// + /// When this task run ended, in milliseconds since Jan 1. 1970. + /// If null the task is still running or the extractor is unresponsive. + /// + public long? EndTime { get; set; } + } + + /// + /// Query for retrieving integration task histories. + /// + public class TaskHistoryQuery : CursorQueryBase + { + /// + /// Filter by task histories belonging to a specific integration. + /// + public string Integration { get; set; } + /// + /// Return task histories belonging to a specific task. Requires integration to be set. + /// + public string TaskName { get; set; } + /// + public override List<(string, string)> ToQueryParams() + { + var qs = base.ToQueryParams(); + if (Integration != null) qs.Add(("integration", Integration)); + if (TaskName != null) qs.Add(("taskName", TaskName)); + return qs; + } + } +} \ No newline at end of file diff --git a/CogniteSdk.Types/Common/StringOrInt.cs b/CogniteSdk.Types/Common/StringOrInt.cs new file mode 100644 index 00000000..239e7ab0 --- /dev/null +++ b/CogniteSdk.Types/Common/StringOrInt.cs @@ -0,0 +1,122 @@ +// Copyright 2025 Cognite AS +// SPDX-License-Identifier: Apache-2.0 + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace CogniteSdk +{ + /// + /// Value that is either a string or an integer. + /// + public abstract class StringOrInt + { + /// + /// Create a StringOrInt from a string value. + /// + /// String value + public static StringOrInt Create(string value) + { + return new String(value); + } + + /// + /// Create a StringOrInt from an integer value. + /// + /// Integer value + public static StringOrInt Create(int value) + { + return new Int(value); + } + + + /// + /// Instance of StringOrInt that is a string. + /// + public class String : StringOrInt + { + /// + /// String value. + /// + public string Value { get; set; } + + /// + /// Constructor. + /// + /// String value + public String(string value) + { + Value = value; + } + } + + /// + /// Instance of StringOrInt that is an integer. + /// + public class Int : StringOrInt + { + /// + /// Integer value. + /// + public int Value { get; set; } + + /// + /// Constructor. + /// + /// Integer value + public Int(int value) + { + Value = value; + } + } + } + + /// + /// Json converter for StringOrInt. + /// + public class StringOrIntConverter : JsonConverter + { + /// + public override StringOrInt Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + switch (reader.TokenType) + { + case JsonTokenType.String: + return StringOrInt.Create(reader.GetString()); + case JsonTokenType.Number: + if (reader.TryGetInt32(out var number)) + { + return StringOrInt.Create(number); + } + + throw new JsonException("Unable to parse value as integer"); + case JsonTokenType.Null: + return null; + default: + throw new JsonException($"Unable to parse value of type: {reader.TokenType}"); + } + } + + /// + public override void Write(Utf8JsonWriter writer, StringOrInt value, JsonSerializerOptions options) + { + if (writer is null) + { + throw new ArgumentNullException(nameof(writer)); + } + + switch (value) + { + case StringOrInt.String s: + writer.WriteStringValue(s.Value); + break; + case StringOrInt.Int i: + writer.WriteNumberValue(i.Value); + break; + default: + throw new ArgumentException($"Unknown StringOrInt: {value}"); + } + } + } +} \ No newline at end of file diff --git a/CogniteSdk/src/Resources/Alpha/Integrations.cs b/CogniteSdk/src/Resources/Alpha/Integrations.cs new file mode 100644 index 00000000..ea3b9697 --- /dev/null +++ b/CogniteSdk/src/Resources/Alpha/Integrations.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using CogniteSdk.Alpha; +using Microsoft.FSharp.Core; +using Oryx; +using Oryx.Cognite.Alpha; + +namespace CogniteSdk.Resources.Alpha +{ + /// + /// Resource for the integrations API. + /// + public class IntegrationsResource : Resource + { + /// + /// Constructor + /// + public IntegrationsResource(Func> authHandler, FSharpFunc, Task> ctx) : base(authHandler, ctx) + { + } + + /// + /// Check in with the integrations API, reporting any changes that occured since the last checkin + /// and generally reporting liveness. + /// + /// Checkin request + /// Optional cancellation token + /// Response with changes and notifications the extractor should be aware of. + public async Task CheckInAsync(CheckInRequest request, CancellationToken token = default) + { + var req = Integrations.checkin(request, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// Report information about the running extractor. + /// + /// This should generally only be called on extractor startup and on changes to config. + /// + /// Changes to extractor info. + /// Optional cancellation token + /// Response with changes and notifications the extractor should be aware of. + public async Task ExtractorInfoAsync(ExtractorInfo request, CancellationToken token = default) + { + var req = Integrations.extractorInfo(request, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// Create a list of integrations. + /// + /// Integrations to create + /// Optional cancellation token + /// Created integrations + public async Task> CreateAsync(IEnumerable items, CancellationToken token = default) + { + var req = Integrations.create(items, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// Delete integrations with all their tasks, configs and task history. + /// + /// Integration IDs to delete + /// Whether to ignore unknown IDs + /// Optional cancellation token + public async Task DeleteAsync(IEnumerable ids, bool ignoreUnknownIds, CancellationToken token = default) + { + var req = Integrations.delete(new IntegrationsDelete + { + Items = ids.Select((id) => new CogniteExternalId(id)).ToList(), + IgnoreUnknownIds = ignoreUnknownIds + }, GetContext(token)); + await RunAsync(req).ConfigureAwait(false); + } + + /// + /// Retrieve integrations, optionally ignoring unknown IDs. + /// + /// Integration IDs to retrieve. + /// Whether to ignore unknown IDs + /// Optional cancellation token + /// Retrieved integrations + public async Task> RetrieveAsync(IEnumerable ids, bool ignoreUnknownIds, CancellationToken token = default) + { + var req = Integrations.retrieve(new IntegrationsRetrieve + { + Items = ids.Select((id) => new CogniteExternalId(id)).ToList(), + IgnoreUnknownIds = ignoreUnknownIds + }, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// Update a list of integrations. + /// + /// Integration updates. + /// Optional cancellation token + /// Updated integrations. + public async Task> UpdateAsync(IEnumerable> items, CancellationToken token = default) + { + var req = Integrations.update(items, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// Create a configuration revision for the given extractor. + /// + /// Configuration revision to update. + /// Optional cancellation token + /// Created config revision + public async Task CreateConfigRevisionAsync(CreateConfigRevision revision, CancellationToken token = default) + { + var req = Integrations.createConfigRevision(revision, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// Retrieve a specific configuration revision, or the latest if is left out. + /// + /// Integration to get the config for. + /// Config revision to retrieve. + /// Optional cancellation token + /// Config revision + public async Task GetConfigRevisionAsync(string integration, int? revision = null, CancellationToken token = default) + { + var req = Integrations.getConfigRevision(integration, revision, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// List all config revisions, optionally filtering by integration. + /// + /// Integration to fetch config revisions for. + /// Optional cancellation token + /// List of config revisions. + public async Task> ListConfigRevisionsAsync(string integration, CancellationToken token = default) + { + var req = Integrations.listConfigRevisions(integration, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// List task history entries for a given integration. + /// + /// Query for fetching task history. + /// Optional cancellation token + /// List of task history entries with optional cursor for pagination. + public async Task> GetTaskHistoryAsync(TaskHistoryQuery query, CancellationToken token = default) + { + var req = Integrations.getTaskHistory(query, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + + /// + /// List errors for a given integration. + /// + /// Query for fetching errors. + /// Optional cancellation token + /// List of errors with optional cursor for pagination. + public async Task> ListErrorsAsync(ErrorsQuery query, CancellationToken token = default) + { + var req = Integrations.listErrors(query, GetContext(token)); + return await RunAsync(req).ConfigureAwait(false); + } + } +} \ No newline at end of file diff --git a/CogniteSdk/test/csharp/CogniteSdk.Test.csproj b/CogniteSdk/test/csharp/CogniteSdk.Test.CSharp.csproj similarity index 94% rename from CogniteSdk/test/csharp/CogniteSdk.Test.csproj rename to CogniteSdk/test/csharp/CogniteSdk.Test.CSharp.csproj index 8cb3d15d..e8e427c7 100644 --- a/CogniteSdk/test/csharp/CogniteSdk.Test.csproj +++ b/CogniteSdk/test/csharp/CogniteSdk.Test.CSharp.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false false false diff --git a/CogniteSdk/test/fsharp/CogniteSdk.Test.fsproj b/CogniteSdk/test/fsharp/CogniteSdk.Test.FSharp.fsproj similarity index 97% rename from CogniteSdk/test/fsharp/CogniteSdk.Test.fsproj rename to CogniteSdk/test/fsharp/CogniteSdk.Test.FSharp.fsproj index 033c1f61..eca04d2a 100644 --- a/CogniteSdk/test/fsharp/CogniteSdk.Test.fsproj +++ b/CogniteSdk/test/fsharp/CogniteSdk.Test.FSharp.fsproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false false diff --git a/CogniteSdk/test/fsharp/CoreDataModels/DataPoints.fs b/CogniteSdk/test/fsharp/CoreDataModels/DataPoints.fs index 7ba76230..9222cd10 100644 --- a/CogniteSdk/test/fsharp/CoreDataModels/DataPoints.fs +++ b/CogniteSdk/test/fsharp/CoreDataModels/DataPoints.fs @@ -70,7 +70,7 @@ module DataPointsTests = let dto = - SourcedNodeWrite<'CogniteTimeSeriesBase>( + SourcedNodeWrite( Space = testSpace, ExternalId = externalIdString, Properties = @@ -100,8 +100,7 @@ module DataPointsTests = let! _ = writeClient.CoreDataModel.TimeSeries().UpsertAsync([ dto ], null) let! _ = writeClient.DataPoints.CreateAsync points - let! _ = - writeClient.DataPoints.CreateAsync(points, System.IO.Compression.CompressionLevel.Fastest) + let! _ = writeClient.DataPoints.CreateAsync(points, System.IO.Compression.CompressionLevel.Fastest) let! _ = writeClient.CoreDataModel.TimeSeries().DeleteAsync @@ -118,7 +117,7 @@ module DataPointsTests = let externalIdString = Guid.NewGuid().ToString() let dto = - SourcedNodeWrite<'CogniteTimeSeriesBase>( + SourcedNodeWrite( Space = testSpace, ExternalId = externalIdString, Properties = diff --git a/Oryx.Cognite/src/Alpha/Integrations.fs b/Oryx.Cognite/src/Alpha/Integrations.fs new file mode 100644 index 00000000..0865739f --- /dev/null +++ b/Oryx.Cognite/src/Alpha/Integrations.fs @@ -0,0 +1,123 @@ +// Copyright 2025 Cognite AS +// SPDX-License-Identifier: Apache-2.0 + +namespace Oryx.Cognite.Alpha + +open System + +open Oryx +open Oryx.Cognite +open Oryx.Cognite.Alpha + +open CogniteSdk.Alpha + + +[] +module Integrations = + open CogniteSdk + open System.Collections.Generic + + [] + let Url = "/integrations" + + let checkin (request: CheckInRequest) (source: HttpHandler) : HttpHandler = + source + |> withLogMessage "integrations:checkin" + |> withAlphaHeader + |> postV10 request (Url +/ "checkin") + + let extractorInfo (request: ExtractorInfo) (source: HttpHandler) : HttpHandler = + source + |> withLogMessage "integrations:extractorinfo" + |> withAlphaHeader + |> postV10 request (Url +/ "extractorinfo") + + let createConfigRevision + (revision: CreateConfigRevision) + (source: HttpHandler) + : HttpHandler = + source + |> withLogMessage "integrations:createconfigrevision" + |> withAlphaHeader + |> postV10 revision (Url +/ "config") + + let create (integrations: CreateIntegration seq) (source: HttpHandler) : HttpHandler = + source + |> withLogMessage "integrations:create" + |> withAlphaHeader + |> create integrations Url + + let delete (items: IntegrationsDelete) (source: HttpHandler) : HttpHandler = + source + |> withLogMessage "integrations:delete" + |> withAlphaHeader + |> delete items Url + + let retrieve (items: IntegrationsRetrieve) (source: HttpHandler) : HttpHandler = + http { + let! res = + source + |> withLogMessage "integrations:retrieve" + |> withAlphaHeader + |> postV10> items (Url +/ "byids") + + return res.Items + } + + let getConfigRevision + (integration: string) + (revision: Nullable) + (source: HttpHandler) + : HttpHandler = + let query = ConfigRevisionQuery(Integration = integration, Revision = revision) + + source + |> withLogMessage "integrations:getconfigrevision" + |> withAlphaHeader + |> getWithQuery query (Url +/ "config") + + let getTaskHistory + (query: TaskHistoryQuery) + (source: HttpHandler) + : HttpHandler> = + source + |> withLogMessage "integrations:gettaskhistory" + |> withAlphaHeader + |> getWithQuery query (Url +/ "history") + + let listConfigRevisions + (integration: string) + (source: HttpHandler) + : HttpHandler = + http { + let query = ConfigRevisionsQuery(Integration = integration) + + let! ret = + source + |> withLogMessage "integrations:listconfigrevisions" + |> withAlphaHeader + |> getWithQuery> query (Url +/ "config" +/ "revisions") + + return ret.Items + } + + let listErrors (query: ErrorsQuery) (source: HttpHandler) : HttpHandler> = + source + |> withLogMessage "integrations:listerrors" + |> withAlphaHeader + |> getWithQuery query (Url +/ "errors") + + let list (query: IntegrationsQuery) (source: HttpHandler) : HttpHandler> = + source + |> withLogMessage "integrations:list" + |> withAlphaHeader + |> getWithQuery query Url + + let update + (items: IEnumerable>) + (source: HttpHandler) + : HttpHandler = + source + |> withLogMessage "integrations:update" + |> withAlphaHeader + |> update items Url diff --git a/Oryx.Cognite/src/Common.fs b/Oryx.Cognite/src/Common.fs index 2a801d10..3954633f 100644 --- a/Oryx.Cognite/src/Common.fs +++ b/Oryx.Cognite/src/Common.fs @@ -78,6 +78,7 @@ module Common = options.Converters.Add(TransformationSchemaConverter()) options.Converters.Add(FieldResolverConverter()) options.Converters.Add(StatusCodeConverter()) + options.Converters.Add(StringOrIntConverter()) // DMS converters options.Converters.Add(ViewDefinitionOrReferenceConverter()) options.Converters.Add(ViewCreateOrReferenceConverter()) diff --git a/Oryx.Cognite/src/Oryx.Cognite.fsproj b/Oryx.Cognite/src/Oryx.Cognite.fsproj index bf6d063a..3bdc3a17 100644 --- a/Oryx.Cognite/src/Oryx.Cognite.fsproj +++ b/Oryx.Cognite/src/Oryx.Cognite.fsproj @@ -40,6 +40,7 @@ + diff --git a/cognite-sdk-dotnet.sln b/cognite-sdk-dotnet.sln index 7b3d9516..ff43f9ed 100644 --- a/cognite-sdk-dotnet.sln +++ b/cognite-sdk-dotnet.sln @@ -9,13 +9,13 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Oryx.Cognite", "Oryx.Cognit EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CogniteSdk", "CogniteSdk\src\CogniteSdk.csproj", "{41482B89-4CC9-4DB8-91D1-ABE7E3B7C5A4}" EndProject -Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "CogniteSdk.Test.FSharp", "CogniteSdk\test\fsharp\CogniteSdk.Test.fsproj", "{A94F7DFA-2202-4705-AADB-FBBF739BED61}" +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "CogniteSdk.Test.FSharp", "CogniteSdk\test\fsharp\CogniteSdk.Test.FSharp.fsproj", "{A94F7DFA-2202-4705-AADB-FBBF739BED61}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CogniteSdk.FSharp", "CogniteSdk.FSharp", "{B2E2DB93-62A4-4F13-AAFB-D666D5ACA0E6}" EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "CogniteSdk.FSharp", "CogniteSdk.FSharp\src\CogniteSdk.FSharp.fsproj", "{1F440E85-0B02-409E-9731-54D873200E46}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CogniteSdk.Test.CSharp", "CogniteSdk\test\csharp\CogniteSdk.Test.csproj", "{B42088FD-0284-46D8-8C34-EE348DC02850}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CogniteSdk.Test.CSharp", "CogniteSdk\test\csharp\CogniteSdk.Test.CSharp.csproj", "{B42088FD-0284-46D8-8C34-EE348DC02850}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CogniteSdk.Protobuf", "CogniteSdk.Protobuf\CogniteSdk.Protobuf.csproj", "{70C1CDD1-42CB-4823-83B2-F08A4E930096}" EndProject