public async Task <IActionResult> GetAvailableStructures([FromQuery] int offset = -1, [FromQuery] int length = -1) { try { var range = QueryRange.Make(offset, length); var result = await _store.Structures.GetAvailable(range); if (result.IsError) { return(ProviderError(result)); } var sortedData = result.Data .GroupBy(s => s.Name) .ToDictionary(g => g.Key, g => g.Select(s => s.Version) .ToArray()); return(Ok(sortedData)); } catch (Exception e) { Logger.LogError(e, "failed to retrieve available structures"); return(StatusCode((int)HttpStatusCode.InternalServerError, "failed to retrieve available structures")); } }
public async Task <IActionResult> GetVariables([FromRoute] string name, [FromRoute] int structureVersion, [FromQuery] int offset = -1, [FromQuery] int length = -1) { if (string.IsNullOrWhiteSpace(name)) { return(BadRequest("no name provided")); } if (structureVersion <= 0) { return(BadRequest($"invalid version provided '{structureVersion}'")); } var range = QueryRange.Make(offset, length); var identifier = new StructureIdentifier(name, structureVersion); try { var result = await _store.Structures.GetVariables(identifier, range); return(Result(result)); } catch (Exception e) { Logger.LogError(e, $"failed to retrieve structure-variables of ({nameof(name)}: {name}, {nameof(structureVersion)}: {structureVersion})"); return(StatusCode(HttpStatusCode.InternalServerError, "failed to retrieve structure")); } }
public async Task GetAutocompleteParametersForwarded(string category, string name, string query, int offset, int length, long targetVersion) { _projectionStore.Setup(s => s.Environments.GetKeyAutoComplete(new EnvironmentIdentifier(category, name), query, QueryRange.Make(offset, length), targetVersion)) .ReturnsAsync(() => Result.Success <IList <DtoConfigKeyCompletion> >(new List <DtoConfigKeyCompletion> { new DtoConfigKeyCompletion { FullPath = "Foo/Bar", Completion = "Baz", HasChildren = false }, new DtoConfigKeyCompletion { FullPath = "Foo/Bar", Completion = "Que", HasChildren = true } })) .Verifiable("autocomplete-data not searched"); await TestAction <OkObjectResult>(c => c.GetKeyAutocompleteList(category, name, query, offset, length, targetVersion)); _projectionStore.Verify(); }
public async Task <IActionResult> GetKeyAutocompleteList([FromRoute] string category, [FromRoute] string name, [FromQuery] string query = null, [FromQuery] int offset = -1, [FromQuery] int length = -1, [FromQuery] long targetVersion = -1) { try { var range = QueryRange.Make(offset, length); var identifier = new EnvironmentIdentifier(category, name); var result = await _store.Environments.GetKeyAutoComplete(identifier, query, range, targetVersion); return(Result(result)); } catch (Exception e) { KnownMetrics.Exception.WithLabels(e.GetType().Name).Inc(); Logger.LogError(e, $"failed to export retrieve autocomplete-data (" + $"{nameof(category)}: {category}; " + $"{nameof(name)}: {name}; " + $"{nameof(query)}: {query}; " + $"{nameof(offset)}: {offset}; " + $"{nameof(length)}: {length}; " + $"{nameof(targetVersion)}: {targetVersion};)"); return(StatusCode(HttpStatusCode.InternalServerError, "failed to retrieve autocomplete-data")); } }
public async Task <IActionResult> GetKeysWithMetadata([FromRoute] string category, [FromRoute] string name, [FromQuery] string filter, [FromQuery] string preferExactMatch, [FromQuery] string root, [FromQuery] int offset = -1, [FromQuery] int length = -1, [FromQuery] long targetVersion = -1) { try { var range = QueryRange.Make(offset, length); var identifier = new EnvironmentIdentifier(category, name); var result = await _store.Environments.GetKeyObjects(new EnvironmentKeyQueryParameters { Environment = identifier, Filter = filter, PreferExactMatch = preferExactMatch, Range = range, RemoveRoot = root, TargetVersion = targetVersion }); if (result.IsError) { return(ProviderError(result)); } foreach (var item in result.Data) { if (item.Description is null) { item.Description = string.Empty; } if (item.Type is null) { item.Type = string.Empty; } } return(Ok(result.Data)); } catch (Exception e) { KnownMetrics.Exception.WithLabels(e.GetType().Name).Inc(); Logger.LogError(e, "failed to retrieve Environment-Keys (" + $"{nameof(category)}: {category}; " + $"{nameof(name)}: {name}; " + $"{nameof(filter)}: {filter}; " + $"{nameof(preferExactMatch)}: {preferExactMatch}; " + $"{nameof(root)}: {root}; " + $"{nameof(offset)}: {offset}; " + $"{nameof(length)}: {length}; " + $"{nameof(targetVersion)}: {targetVersion})"); return(StatusCode(HttpStatusCode.InternalServerError, "failed to retrieve environment-keys")); } }
public async Task GetKeysPaged() { var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict); domainObjectStore.Setup(dos => dos.ReplayObject(It.IsAny <ConfigEnvironment>(), It.IsAny <string>())) .ReturnsAsync((ConfigEnvironment str, string id) => { str.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar")), UtcTime = DateTime.UtcNow, Version = 4710 }); str.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentKeysImported(new EnvironmentIdentifier("Foo", "Bar"), new[] { ConfigKeyAction.Set("Foo", "FooValue"), ConfigKeyAction.Set("Bar", "BarValue"), ConfigKeyAction.Set("Baz", "BazValue") }), UtcTime = DateTime.UtcNow, Version = 4711 }); return(Result.Success(str)); }) .Verifiable(); var eventStore = new Mock <IEventStore>(MockBehavior.Strict); eventStore.Setup(es => es.ReplayEventsAsStream( It.IsAny <Func <(StoredEvent StoredEvent, DomainEventMetadata Metadata), bool> >(), It.IsAny <Func <(StoredEvent StoredEvent, DomainEvent DomainEvent), bool> >(), It.IsAny <int>(), It.IsAny <StreamDirection>(), It.IsAny <long>())) .Returns(Task.CompletedTask); var store = new EnvironmentProjectionStore(eventStore.Object, domainObjectStore.Object, _logger, new ICommandValidator[0]); var result = await store.GetKeys(new EnvironmentKeyQueryParameters { Environment = new EnvironmentIdentifier("Foo", "Bar"), Range = QueryRange.Make(1, 1) }); Assert.Empty(result.Message); Assert.False(result.IsError, "result.IsError"); Assert.Single(result.Data); Assert.Equal(new KeyValuePair <string, string>("Baz", "BazValue"), result.Data.First()); domainObjectStore.Verify(); eventStore.Verify(); }
public async Task GetAvailablePaged() { var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict); domainObjectStore.Setup(dos => dos.ReplayObject <ConfigEnvironmentList>(It.IsAny <long>())) .ReturnsAsync((long v) => { var list = new ConfigEnvironmentList(); list.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Foo")), UtcTime = DateTime.UtcNow, Version = 4710 }); list.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar")), UtcTime = DateTime.UtcNow, Version = 4711 }); list.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Baz")), UtcTime = DateTime.UtcNow, Version = 4712 }); return(Result.Success(list)); }) .Verifiable(); var eventStore = new Mock <IEventStore>(MockBehavior.Strict); eventStore.Setup(es => es.ReplayEventsAsStream( It.IsAny <Func <(StoredEvent StoredEvent, DomainEventMetadata Metadata), bool> >(), It.IsAny <Func <(StoredEvent StoredEvent, DomainEvent DomainEvent), bool> >(), It.IsAny <int>(), It.IsAny <StreamDirection>(), It.IsAny <long>())) .Returns(Task.CompletedTask); var store = new EnvironmentProjectionStore(eventStore.Object, domainObjectStore.Object, _logger, new ICommandValidator[0]); var result = await store.GetAvailable(QueryRange.Make(1, 1)); Assert.Empty(result.Message); Assert.False(result.IsError, "result.IsError"); Assert.Single(result.Data); domainObjectStore.Verify(); eventStore.Verify(); }
public async Task GetEnvironmentsParametersForwarded() { _projectionStoreMock.Setup(s => s.Environments.GetAvailable(QueryRange.Make(1, 2), 4711)) .ReturnsAsync(() => Result.Success <IList <EnvironmentIdentifier> >(new List <EnvironmentIdentifier> { new EnvironmentIdentifier("Foo", "Bar") })) .Verifiable("environments not queried"); await TestAction <OkObjectResult>(c => c.GetAvailableEnvironments(1, 2, 4711)); _projectionStoreMock.Verify(); }
public async Task GetKeysPaged() { var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict); domainObjectStore.Setup(dos => dos.ReplayObject(It.IsAny <ConfigStructure>(), It.IsAny <string>())) .ReturnsAsync((ConfigStructure str, string id) => { str.ApplyEvent(new ReplayedEvent { DomainEvent = new StructureCreated(new StructureIdentifier("Foo", 42), new Dictionary <string, string> { { "Bar", "BarValue" }, { "Baz", "BazValue" }, { "Foo", "FooValue" } }, new Dictionary <string, string> { { "Bar", "Baz" } }), UtcTime = DateTime.UtcNow, Version = 4710 }); return(Result.Success(str)); }) .Verifiable(); var eventStore = new Mock <IEventStore>(MockBehavior.Strict); eventStore.Setup(es => es.ReplayEventsAsStream( It.IsAny <Func <(StoredEvent StoredEvent, DomainEventMetadata Metadata), bool> >(), It.IsAny <Func <(StoredEvent StoredEvent, DomainEvent DomainEvent), bool> >(), It.IsAny <int>(), It.IsAny <StreamDirection>(), It.IsAny <long>())) .Returns(Task.CompletedTask); var store = new StructureProjectionStore(_logger, domainObjectStore.Object, eventStore.Object, new ICommandValidator[0]); var result = await store.GetKeys(new StructureIdentifier("Foo", 42), QueryRange.Make(1, 1)); Assert.False(result.IsError, "result.IsError"); Assert.Single(result.Data); Assert.Equal(new KeyValuePair <string, string>("Baz", "BazValue"), result.Data.First()); domainObjectStore.Verify(); eventStore.Verify(); }
public async Task <IActionResult> GetConfiguration([FromRoute] string environmentCategory, [FromRoute] string environmentName, [FromRoute] string structureName, [FromRoute] int structureVersion, [FromQuery] DateTime when, [FromQuery] int offset = -1, [FromQuery] int length = -1) { try { var range = QueryRange.Make(offset, length); var envIdentifier = new EnvironmentIdentifier(environmentCategory, environmentName); var structureIdentifier = new StructureIdentifier(structureName, structureVersion); var configId = new ConfigurationIdentifier(envIdentifier, structureIdentifier, default); var result = await _store.Configurations.GetKeys(configId, when, range); if (result.IsError) { return(ProviderError(result)); } var version = await _store.Configurations.GetVersion(configId, when); if (version.IsError) { return(ProviderError(version)); } // add version to the response-headers Response.Headers.Add("x-version", version.Data); return(Result(result)); } catch (Exception e) { KnownMetrics.Exception.WithLabels(e.GetType().Name).Inc(); Logger.LogError(e, "failed to add new environment at (" + $"{nameof(environmentCategory)}: {environmentCategory}; " + $"{nameof(environmentName)}: {environmentName}; " + $"{nameof(structureName)}: {structureName}; " + $"{nameof(structureVersion)}: {structureVersion}; " + $"{nameof(when)}: {when}; " + $"{nameof(offset)}: {offset}; " + $"{nameof(length)}: {length})"); return(StatusCode(HttpStatusCode.InternalServerError, "failed to retrieve configuration")); } }
public async Task GetKeysParametersForwarded() { _projectionStoreMock.Setup(s => s.Environments.GetKeys(new EnvironmentKeyQueryParameters { Environment = new EnvironmentIdentifier("Foo", "Bar"), Filter = "filter", PreferExactMatch = "preferExactMatch", Range = QueryRange.Make(1, 2), RemoveRoot = "removeRoot", TargetVersion = 4711 })) .ReturnsAsync(() => Result.Success <IDictionary <string, string> >(new Dictionary <string, string>())) .Verifiable("keys not queried"); await TestAction <OkObjectResult>(c => c.GetKeys("Foo", "Bar", "filter", "preferExactMatch", "removeRoot", 1, 2, 4711)); _projectionStoreMock.Verify(); }
public async Task <IActionResult> GetKeys([FromRoute] string category, [FromRoute] string name, [FromQuery] string filter, [FromQuery] string preferExactMatch, [FromQuery] string root, [FromQuery] int offset = -1, [FromQuery] int length = -1, [FromQuery] long targetVersion = -1) { var range = QueryRange.Make(offset, length); var identifier = new EnvironmentIdentifier(category, name); try { var result = await _store.Environments.GetKeys(new EnvironmentKeyQueryParameters { Environment = identifier, Filter = filter, PreferExactMatch = preferExactMatch, Range = range, RemoveRoot = root, TargetVersion = targetVersion }); return(result.IsError ? ProviderError(result) : Ok(result.Data.ToImmutableSortedDictionary())); } catch (Exception e) { KnownMetrics.Exception.WithLabels(e.GetType().Name).Inc(); Logger.LogError(e, "failed to retrieve Environment-Keys (" + $"{nameof(category)}: {category}; " + $"{nameof(name)}: {name}; " + $"{nameof(filter)}: {filter}; " + $"{nameof(preferExactMatch)}: {preferExactMatch}; " + $"{nameof(root)}: {root}; " + $"{nameof(offset)}: {offset}; " + $"{nameof(length)}: {length}; " + $"{nameof(targetVersion)}: {targetVersion})"); return(StatusCode(HttpStatusCode.InternalServerError, "failed to retrieve environment-keys")); } }
public async Task <IActionResult> GetStaleConfigurations([FromQuery] int offset = -1, [FromQuery] int length = -1) { try { var range = QueryRange.Make(offset, length); var result = await _store.Configurations.GetStale(range); return(Result(result)); } catch (Exception e) { KnownMetrics.Exception.WithLabels(e.GetType().Name).Inc(); Logger.LogError(e, "failed to add new environment at (" + $"{nameof(offset)}: {offset}; " + $"{nameof(length)}: {length})"); return(StatusCode(HttpStatusCode.InternalServerError, "failed to retrieve stale configurations")); } }
public async Task <IActionResult> GetAvailableEnvironments([FromQuery] int offset = -1, [FromQuery] int length = -1, [FromQuery] long targetVersion = -1) { var range = QueryRange.Make(offset, length); try { var result = await _store.Environments.GetAvailable(range, targetVersion); return(Result(result)); } catch (Exception e) { KnownMetrics.Exception.WithLabels(e.GetType().Name).Inc(); Logger.LogError(e, "failed to retrieve available Environments (" + $"{nameof(offset)}: {offset}; " + $"{nameof(length)}: {length}; " + $"{nameof(targetVersion)}: {targetVersion})"); return(StatusCode(HttpStatusCode.InternalServerError, "failed to retrieve available environments")); } }
public async Task <IActionResult> GetUsedKeys([FromRoute] string environmentCategory, [FromRoute] string environmentName, [FromRoute] string structureName, [FromRoute] int structureVersion, [FromQuery] DateTime when, [FromQuery] int offset = -1, [FromQuery] int length = -1) { try { var range = QueryRange.Make(offset, length); var envIdentifier = new EnvironmentIdentifier(environmentCategory, environmentName); var structureIdentifier = new StructureIdentifier(structureName, structureVersion); var result = await _store.Configurations.GetUsedConfigurationKeys( new ConfigurationIdentifier( envIdentifier, structureIdentifier, default), when, range); return(Result(result)); } catch (Exception e) { KnownMetrics.Exception.WithLabels(e.GetType().Name).Inc(); Logger.LogError(e, "failed to add new environment at (" + $"{nameof(environmentCategory)}: {environmentCategory}; " + $"{nameof(environmentName)}: {environmentName}; " + $"{nameof(structureName)}: {structureName}; " + $"{nameof(structureVersion)}: {structureVersion}; " + $"{nameof(when)}: {when}; " + $"{nameof(offset)}: {offset}; " + $"{nameof(length)}: {length})"); return(StatusCode(HttpStatusCode.InternalServerError, "failed to retrieve used keys in configuration")); } }
public void MakeSanitizesLength(int offset, int length) => Assert.InRange(QueryRange.Make(offset, length).Length, 1, int.MaxValue);