Beispiel #1
0
        public void WhenNodeHasPlacementWithName_ThenZoneAndProjectIdAreNotNull()
        {
            var instance = new InstanceHistory(
                1,
                new InstanceLocator("project-1", "zone-1", "instance-1"),
                InstanceHistoryState.MissingImage,
                null,
                null);
            var node = new NodeHistory(
                "server-1",
                null,
                DateTime.UtcNow.AddDays(-1),
                DateTime.UtcNow,
                0,
                new[]
            {
                new NodePlacement(
                    DateTime.UtcNow.AddDays(-1),
                    DateTime.UtcNow,
                    instance)
            });

            Assert.AreEqual("project-1", node.ProjectId);
            Assert.AreEqual("zone-1", node.Zone);
        }
Beispiel #2
0
        public void WhenNodeHasPlacementWithoutName_ThenZoneAndProjectIdAreNull()
        {
            var instance = new InstanceHistory(
                1,
                null,
                InstanceHistoryState.MissingName,
                null,
                null);
            var node = new NodeHistory(
                "server-1",
                null,
                DateTime.UtcNow.AddDays(-1),
                DateTime.UtcNow,
                0,
                new[]
            {
                new NodePlacement(
                    DateTime.UtcNow.AddDays(-1),
                    DateTime.UtcNow,
                    instance)
            });

            Assert.IsNull(node.ProjectId);
            Assert.IsNull(node.Zone);
        }
Beispiel #3
0
        public void WhenNodeHasPlacements_ThenMaxInstancePlacementsByDayUsesFirstAndLastDate()
        {
            var baselineDate = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var instance     = new InstanceHistory(
                1,
                new InstanceLocator("project-1", "zone-1", "instance-1"),
                InstanceHistoryState.MissingImage,
                null,
                null);
            var node = new NodeHistory(
                "server-1",
                null,
                baselineDate,
                baselineDate.AddDays(2),
                0,
                new[]
            {
                new NodePlacement(
                    baselineDate.AddDays(1),
                    baselineDate.AddDays(2),
                    instance),
                new NodePlacement(
                    baselineDate,
                    baselineDate.AddDays(1),
                    instance)
            });

            var histogram = node.MaxInstancePlacementsByDay;

            Assert.AreEqual(baselineDate, histogram.First().Timestamp);
            Assert.AreEqual(baselineDate.AddDays(2), histogram.Last().Timestamp);
        }
        //---------------------------------------------------------------------

        public ImageAnnotation GetImageAnnotation(InstanceHistory instance)
        {
            ImageAnnotation annotation;

            if (instance.Image != null &&
                this.parent.Model.LicenseAnnotations.TryGetValue(instance.Image.ToString(), out annotation))
            {
                return(annotation);
            }
            else
            {
                return(ImageAnnotation.Default);
            }
        }
Beispiel #5
0
        internal bool IsInstanceAnnotatedAs(
            InstanceHistory instance,
            OperatingSystemTypes osTypes,
            LicenseTypes licenseTypes)
        {
            if (instance.Image == null ||
                !this.LicenseAnnotations.TryGetValue(instance.Image.ToString(), out ImageAnnotation annotation))
            {
                annotation = ImageAnnotation.Default;
            }

            Debug.Assert(annotation != null);

            return(osTypes.HasFlag(annotation.OperatingSystem) &&
                   licenseTypes.HasFlag(annotation.LicenseType));
        }