private void AddExistingInstance( InstanceSetHistoryBuilder builder, int count, DateTime lastSeen, Tenancies tenancy) { for (int i = 0; i < count; i++) { instanceIdSequence++; var locator = new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}"); builder.AddExistingInstance( instanceIdSequence, locator, new ImageLocator("project", $"image-{instanceIdSequence}"), InstanceState.Running, lastSeen, tenancy, tenancy == Tenancies.SoleTenant ? "server-1" : null, null); builder.GetInstanceHistoryBuilder(instanceIdSequence) .OnStart(BaselineTime.AddDays(i), locator); } }
//--------------------------------------------------------------------- // Ctor //--------------------------------------------------------------------- private InstanceHistoryBuilder( ulong instanceId, InstanceLocator reference, ImageLocator image, InstanceState state, DateTime?lastSeen, Tenancies tenancy) { Debug.Assert(!tenancy.IsFlagCombination()); if (instanceId == 0) { throw new ArgumentException("Instance ID cannot be 0"); } this.InstanceId = instanceId; this.reference = reference; this.image = image; this.lastStoppedOn = lastSeen; if (state == InstanceState.Running) { Debug.Assert(tenancy != Tenancies.Unknown); Debug.Assert(lastSeen != null); // Add a synthetic placement. AddPlacement(new InstancePlacement(tenancy, null, lastSeen.Value, lastSeen.Value)); } }
private static IEnumerable <NodeHistory> NodesFromInstanceSetHistory( IEnumerable <InstanceHistory> instanceHistories, Tenancies tenancies) { var placementsByServer = instanceHistories .Where(i => i.Placements != null) .SelectMany(i => i.Placements.Select(p => new { Instance = i, p.ServerId, p.From, p.To, p.Tenancy })) .Where(p => tenancies.HasFlag(p.Tenancy)) .GroupBy(p => p.ServerId); foreach (var server in placementsByServer) { var peakInstanceCount = (uint)TimeseriesUtil.HighWatermark( server.Select(p => p.From), server.Select(p => p.To)); yield return(new NodeHistory( server.Key, server.Select(p => p.From).Min(), server.Select(p => p.To).Max(), peakInstanceCount, server.Select(p => new NodePlacement(p.From, p.To, p.Instance)))); } }
private void AddExistingInstance( InstanceSetHistoryBuilder builder, int count, Tenancies tenancy) { for (int i = 0; i < count; i++) { instanceIdSequence++; builder.AddExistingInstance( instanceIdSequence, new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}"), new ImageLocator("project", $"image-{instanceIdSequence}"), InstanceState.Running, BaselineTime.AddDays(i), tenancy); var instanceBuilder = builder.GetInstanceHistoryBuilder(instanceIdSequence); if (tenancy == Tenancies.SoleTenant) { // Add sole tenant placement. instanceBuilder.OnSetPlacement("server-1", BaselineTime); } // Add fleet placement. instanceBuilder.OnStop( BaselineTime.AddDays(-1), new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}")); instanceBuilder.OnStart( BaselineTime.AddDays(-2), new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}")); } }
private void AddExistingInstance( InstanceSetHistoryBuilder builder, int count, DateTime lastSeen, Tenancies tenancy) { for (int i = 0; i < count; i++) { instanceIdSequence++; var locator = new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}"); builder.AddExistingInstance( instanceIdSequence, locator, new ImageLocator("project", $"image-{instanceIdSequence}"), InstanceState.Running, lastSeen, tenancy, tenancy == Tenancies.SoleTenant ? "server-1" : null, null); var instanceBuilder = builder.GetInstanceHistoryBuilder(instanceIdSequence); if (tenancy == Tenancies.SoleTenant) { // Add sole tenant placement. instanceBuilder.OnSetPlacement("server-1", null, lastSeen.AddHours(-1)); } // Add fleet placement. instanceBuilder.OnStart(BaselineTime.AddDays(i), locator); } }
public static NodeSetHistory FromInstancyHistory( IEnumerable <InstanceHistory> instanceHistories, Tenancies tenancies) { return(new NodeSetHistory( NodesFromInstanceSetHistory( instanceHistories, tenancies))); }
public void AddPlacement(Tenancies tenancy, string serverId, NodeTypeLocator nodeType, DateTime date) { Debug.Assert(!tenancy.IsFlagCombination()); Debug.Assert(date <= this.lastEventDate); Debug.Assert(tenancy == Tenancies.SoleTenant || (serverId == null && nodeType == null)); this.lastEventDate = date; DateTime placedUntil; if (this.placements.Count == 0) { if (this.lastStoppedOn.HasValue) { Debug.Assert(this.lastStoppedOn != null); Debug.Assert(date <= this.lastStoppedOn); placedUntil = this.lastStoppedOn.Value; } else { ApplicationTraceSources.Default.TraceWarning( "Instance {0} was placed, but never stopped, " + "and yet is not running anymore. Flagging as defunct.", this.InstanceId); this.missingStopEvent = true; return; } } else { if (this.lastStoppedOn.HasValue) { Debug.Assert(date <= this.lastStoppedOn); Debug.Assert(date <= this.placements.First().From); placedUntil = DateTimeUtil.Min( this.lastStoppedOn.Value, this.placements.First().From); } else { Debug.Assert(date <= this.placements.First().From); placedUntil = this.placements.First().From; } } if (tenancy == Tenancies.SoleTenant) { AddPlacement(new InstancePlacement(serverId, nodeType, date, placedUntil)); } else { AddPlacement(new InstancePlacement(date, placedUntil)); } }
internal InstancePlacement( [JsonProperty("tenancy")] Tenancies tenancy, [JsonProperty("server")] string serverId, [JsonProperty("from")] DateTime from, [JsonProperty("to")] DateTime to) { Debug.Assert(from <= to); Debug.Assert(tenancy != Tenancies.Unknown); Debug.Assert(!tenancy.IsFlagCombination()); this.Tenancy = tenancy; this.ServerId = serverId; this.From = from; this.To = to; }
public void AddExistingInstance( ulong instanceId, InstanceLocator reference, ImageLocator image, InstanceState state, DateTime lastSeen, Tenancies tenancy) { Debug.Assert(!tenancy.IsFlagCombination()); this.instanceBuilders[instanceId] = InstanceHistoryBuilder.ForExistingInstance( instanceId, reference, image, state, lastSeen, tenancy); }
private void AddExistingInstance( InstanceSetHistoryBuilder builder, int count, Tenancies tenancy) { for (int i = 0; i < count; i++) { instanceIdSequence++; builder.AddExistingInstance( instanceIdSequence, new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}"), new ImageLocator("project", $"image-{instanceIdSequence}"), InstanceState.Running, BaselineTime.AddDays(i), tenancy); } }
internal static InstanceHistoryBuilder ForExistingInstance( ulong instanceId, InstanceLocator reference, ImageLocator image, InstanceState state, DateTime lastSeen, Tenancies tenancy) { Debug.Assert(!tenancy.IsFlagCombination()); Debug.Assert(state != InstanceState.Deleted); return(new InstanceHistoryBuilder( instanceId, reference, image, state, lastSeen, tenancy)); }
private static Tenancies MergeTenancy(Tenancies lhs, Tenancies rhs) { Debug.Assert(lhs.IsSingleFlag()); Debug.Assert(rhs.IsSingleFlag()); if (lhs == Tenancies.SoleTenant || rhs == Tenancies.SoleTenant) { // If one of them is sole tenant, both of them must be. // that is because in case of SoleTenant, we have strong // evidence that this is a SoleTenant VM whereas in the // case of Fleet, there is simply an absence of evidence // that it might be SoleTenant. return(Tenancies.SoleTenant); } else { return(Tenancies.Fleet); } }
//--------------------------------------------------------------------- // Ctor //--------------------------------------------------------------------- private InstanceHistoryBuilder( ulong instanceId, InstanceLocator reference, ImageLocator image, InstanceState state, DateTime?lastSeen, Tenancies tenancy, string serverId, NodeTypeLocator nodeType) { Debug.Assert(!tenancy.IsFlagCombination()); Debug.Assert(tenancy == Tenancies.SoleTenant || (serverId == null && nodeType == null)); if (instanceId == 0) { throw new ArgumentException("Instance ID cannot be 0"); } this.InstanceId = instanceId; this.reference = reference; this.image = image; this.lastStoppedOn = lastSeen; if (state == InstanceState.Running) { Debug.Assert(tenancy != Tenancies.Unknown); Debug.Assert(lastSeen != null); AddPlacement(new InstancePlacement( tenancy, serverId, nodeType, lastSeen.Value, lastSeen.Value)); } }