datalust / seq-api

HTTP API client for Seq
https://datalust.co/seq
Apache License 2.0
78 stars 21 forks source link

Unable to create app instances #7

Closed bbrandt closed 7 years ago

bbrandt commented 8 years ago

It seems that the C# Seq.Api.dll code thinks the Add/Create/Self should have a parameter of runOnExisting, but the Seq server Resources API says that runOnExisting is on the Items link, not the Self link.

My code:

        private async Task CreateAppInstanceForActionAsync(string name, string signalId, NotificationModel notification)
        {
            var app = await _appInstances.TemplateAsync(await GetEmailAppId());

            app.Title = name;
            app.SignalIds.Add(signalId);

            // These calls to _appSettings can be replaced with strings of your choosing
            app.Settings["From"] = _appSettings.GetOrThrow("Seq:Email.From");
            app.Settings["To"] = notification.ActionDetails;
            app.Settings["Host"] = _appSettings.GetOrThrow("Seq:Email.Host");
            app.Settings["Port"] = _appSettings.GetOrDefault("Seq:Email.Port", "25");
            app.Settings["EnableSsl"] = _appSettings.GetOrDefault("Seq:Email.EnableSsl", bool.FalseString);
            app.Settings["Username"] = _appSettings.Get("Seq:Email.Username");
            app.Settings["Password"] = _appSettings.Get("Seq:Email.Password");

            await _appInstances.AddAsync(app);
        }
System.ArgumentException : The URI template 'api/appinstances/' does not contain parameter: runOnExisting

   at Seq.Api.Client.SeqApiClient.ResolveLink(ILinked entity, String link, IDictionary`2 parameters)
   at Seq.Api.Client.SeqApiClient.<PostAsync>d__b`2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Seq.Api.ResourceGroups.AppInstancesResourceGroup.<AddAsync>d__c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at FlowCal.LogManagement.Infrastructure.Repositories.SeqNotificationRepository.<CreateAppInstanceForActionAsync>d__e.MoveNext() in f:\src\amp\FlowCal.Desktop\FlowCal.LogManagement.Infrastructure\Repositories\SeqNotificationRepository.cs:line 122
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at FlowCal.LogManagement.Infrastructure.Repositories.SeqNotificationRepository.<AddAsync>d__0.MoveNext() in f:\src\amp\FlowCal.Desktop\FlowCal.LogManagement.Infrastructure\Repositories\SeqNotificationRepository.cs:line 51
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at FlowCal.LogManagement.Module.IntegrationTests.DataRepository.SeqNotificationRepositoryTests.<AddAsyncAnyTime_should_add_no_app_instances_and_1_signal>d__0.MoveNext() in f:\src\amp\FlowCal.Desktop\FlowCal.LogsModule.IntegrationTests\DataRepository\SeqNotificationRepositoryTests.cs:line 54
   at NUnit.Framework.AsyncInvocationRegion.AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete(Object invocationResult)
   at NUnit.Core.NUnitAsyncTestMethod.RunTestMethod()

public async Task LoadResourceGroupAsync(string name) for "AppInstances"

Links   Count = 4   Seq.Api.Model.LinkCollection
[0] {[Self, Seq.Api.Model.Link]}    System.Collections.Generic.KeyValuePair<string,Seq.Api.Model.Link>
Key "Self"  string
key "Self"  string
Value   {Seq.Api.Model.Link}    Seq.Api.Model.Link
_href   "api/appinstances/resources"    string
_isLiteral  true    bool
_parameters Count = 0   System.Collections.Generic.IDictionary<string,object> {System.Collections.Generic.Dictionary<string,object>}
value   {Seq.Api.Model.Link}    Seq.Api.Model.Link
[1] {[Items, Seq.Api.Model.Link]}   System.Collections.Generic.KeyValuePair<string,Seq.Api.Model.Link>
Key "Items" string
key "Items" string
Value   {Seq.Api.Model.Link}    Seq.Api.Model.Link
_href   "api/appinstances/{?runOnExisting}" string
_isLiteral  true    bool
_parameters Count = 0   System.Collections.Generic.IDictionary<string,object> {System.Collections.Generic.Dictionary<string,object>}
value   {Seq.Api.Model.Link}    Seq.Api.Model.Link
[2] {[Item, Seq.Api.Model.Link]}    System.Collections.Generic.KeyValuePair<string,Seq.Api.Model.Link>
Key "Item"  string
key "Item"  string
Value   {Seq.Api.Model.Link}    Seq.Api.Model.Link
_href   "api/appinstances/{id}" string
_isLiteral  true    bool
_parameters Count = 0   System.Collections.Generic.IDictionary<string,object> {System.Collections.Generic.Dictionary<string,object>}
value   {Seq.Api.Model.Link}    Seq.Api.Model.Link
[3] {[Template, Seq.Api.Model.Link]}    System.Collections.Generic.KeyValuePair<string,Seq.Api.Model.Link>
Key "Template"  string
key "Template"  string
Value   {Seq.Api.Model.Link}    Seq.Api.Model.Link
_href   "api/appinstances/template{?appId}" string
_isLiteral  true    bool
_parameters Count = 0   System.Collections.Generic.IDictionary<string,object> {System.Collections.Generic.Dictionary<string,object>}
value   {Seq.Api.Model.Link}    Seq.Api.Model.Link
nblumhardt commented 8 years ago

Thanks Ben! Unfortunately this is a bug in the Seq API - the link template for "Create" should include the runOnExisting parameter, but it does not. I've just pushed a fix for this to the Seq 3.0 branch and should have a prerelease build including it in a week or two.

Since the API client is correct here, I'm inclined to leave this as-is and rely on the server fix to rectify things; you can work around it with the code below in place of the Add() call:

await connection.Client.PostAsync<AppInstanceEntity, AppInstanceEntity>(app, "Create", app);

Let me know what you think. Thanks again for the report!

Regards, Nick