Skip to content

Commit

Permalink
Implement integrations API (#414)
Browse files Browse the repository at this point in the history
* Implement integrations API

* Use newer .NET
  • Loading branch information
einarmo authored Jan 24, 2025
1 parent f04f180 commit 2aa4efb
Show file tree
Hide file tree
Showing 15 changed files with 945 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
162 changes: 162 additions & 0 deletions CogniteSdk.Types/Alpha/Integrations/CheckIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright 2025 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;

namespace CogniteSdk.Alpha
{
/// <summary>
/// Type of task update.
/// </summary>
public enum TaskUpdateType
{
/// <summary>
/// Task was started.
/// </summary>
started,
/// <summary>
/// Task ended.
/// </summary>
ended
}

/// <summary>
/// Update to the status of a task.
/// </summary>
public class TaskUpdate
{
/// <summary>
/// Type of task update.
/// </summary>
public TaskUpdateType Type { get; set; }
/// <summary>
/// Name of the task to update, must correspond to a task in the task array given
/// during calls to `extractorinfo`.
/// </summary>
public string Name { get; set; }
/// <summary>
/// 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.
/// </summary>
public long Timestamp { get; set; }
}

/// <summary>
/// Error severity level.
/// </summary>
public enum ErrorLevel
{
/// <summary>
/// Something wrong happened but the extractor was able to continue.
/// </summary>
warning,
/// <summary>
/// Something wrong happened and the extractor _may_ be able to recover,
/// but there will likely be downtime and/or loss of data.
/// </summary>
error,
/// <summary>
/// Something wrong happened that cannot be recovered from.
/// After reporting a fatal error the task should end.
/// </summary>
fatal,
}

/// <summary>
/// Error with optional associated task.
/// </summary>
public class ErrorWithTask
{
/// <summary>
/// Error external ID. Errors may be updated by reporting them again with the
/// same external ID.
/// </summary>
public string ExternalId { get; set; }
/// <summary>
/// Error level.
/// </summary>
public ErrorLevel Level { get; set; }
/// <summary>
/// Short error description.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Long error details, may contain details such as stack traces.
/// </summary>
public string Details { get; set; }
/// <summary>
/// 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.
/// </summary>
public string Task { get; set; }
/// <summary>
/// Time the error started.
/// </summary>
public long StartTime { get; set; }
/// <summary>
/// Time the error ended. Set this equal to `StartTime` if the error is instantaneous.
/// </summary>
public long? EndTime { get; set; }
}

/// <summary>
/// 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.
/// </summary>
public class CheckInRequest
{
/// <summary>
/// ExternalId of the integration to report checkin to.
/// </summary>
public string ExternalId { get; set; }
/// <summary>
/// Started and ended tasks.
/// </summary>
public IEnumerable<TaskUpdate> TaskEvents { get; set; }
/// <summary>
/// Errors and warnings.
/// </summary>
public IEnumerable<ErrorWithTask> Errors { get; set; }
}

/// <summary>
/// Response to a checkin request.
/// </summary>
public class CheckInResponse
{
/// <summary>
/// Integration external ID.
/// </summary>
public string ExternalId { get; set; }
/// <summary>
/// Last stored extractor configuration revision. The extractor may use this
/// to decide to restart with a new remote configuration file.
/// </summary>
public int? LastConfigRevision { get; set; }
}

/// <summary>
/// Report changes to general information about the extractor.
/// This is typically used on extractor startup and when loading a new config file.
/// </summary>
public class ExtractorInfo
{
/// <summary>
/// ID of the running extractor.
/// </summary>
public ExtractorId Extractor { get; set; }
/// <summary>
/// List of tasks configured for this extractor.
/// </summary>
public IEnumerable<IntegrationTask> Tasks { get; set; }
/// <summary>
/// Active config revision, either the revision number or "local" if a local config file is
/// currently in use.
/// </summary>
public StringOrInt ActiveConfigRevision { get; set; }
}
}
119 changes: 119 additions & 0 deletions CogniteSdk.Types/Alpha/Integrations/ConfigRevision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright 2025 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;

namespace CogniteSdk.Alpha
{
/// <summary>
/// Create a new configuration revision.
/// </summary>
public class CreateConfigRevision
{
/// <summary>
/// Integration external ID.
/// </summary>
public string ExternalId { get; set; }
/// <summary>
/// Optional revision description. Should contain the list of changes.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The actual config revision contents.
/// </summary>
public string Config { get; set; }
}

/// <summary>
/// Metadata about a configuration revision.
/// </summary>
public class ConfigRevisionMetadata
{
/// <summary>
/// Integration external ID.
/// </summary>
public string ExternalId { get; set; }
/// <summary>
/// Config revision number. This is simply an incrementing integer.
/// </summary>
public int Revision { get; set; }
/// <summary>
/// Optional revision description. Should contain the list of changes.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Time when this revision was created in milliseconds since Jan 1, 1970.
/// </summary>
public long CreatedTime { get; set; }
/// <summary>
/// Time when this revision was last updated in milliseconds since Jan 1, 1970.
/// </summary>
public long LastUpdatedTime { get; set; }
}

/// <summary>
/// An integration configuration revision.
/// </summary>
public class ConfigRevision : ConfigRevisionMetadata
{
/// <summary>
/// The actual config revision contents.
/// </summary>
public string Config { get; set; }
}

/// <summary>
/// Query for retrieving integration config revisions.
/// </summary>
public class ConfigRevisionQuery : IQueryParams
{
/// <summary>
/// Integration external ID, required.
/// </summary>
public string Integration { get; set; }
/// <summary>
/// Config revision to fetch. If left out, fetches the latest revision.
/// </summary>
public int? Revision { get; set; }

/// <inheritdoc />
public List<(string, string)> ToQueryParams()
{
var res = new List<(string, string)>
{
("integration", Integration)
};
if (Revision.HasValue)
{
res.Add(("revision", Revision.Value.ToString()));
}
return res;
}
}



/// <summary>
/// Query for listing integration config revisions.
/// </summary>
public class ConfigRevisionsQuery : IQueryParams
{
/// <summary>
/// Integration external ID.
/// </summary>
public string Integration { get; set; }

/// <inheritdoc />
public List<(string, string)> ToQueryParams()
{
var res = new List<(string, string)>();
if (Integration != null)
{
res.Add(("integration", Integration));
}
return res;
}
}


}
Loading

0 comments on commit 2aa4efb

Please sign in to comment.