import { Component , OnInit , Input , OnChanges , OnDestroy } from '@angular/core' ; import { IRawReplicatorStatus , IRawRemoteReplicatorStatus } from 'src/app/Models/RawDataTypes' ; import { ReplicaOnPartition } from 'src/app/Models/DataModels/Replica' ; import { Utils } from 'src/app/Utils/Utils' ; import { Subscription } from 'rxjs' ; import { IEssentialListItem } from '../../charts/essential-health-tile/essential-health-tile.component' ; export interface ITimedReplication extends IRawRemoteReplicatorStatus { date : Date ; } const reduceReplicators = ( data , replica ) => { data [ replica . ReplicaId ] = replica ; return data ; } ; @ Component ( { selector : 'app-replica-status-container' , templateUrl : './replica-status-container.component.html' , styleUrls : [ './replica-status-container.component.scss' ] } ) export class ReplicaStatusContainerComponent implements OnChanges , OnDestroy { @ Input ( ) replicas : ReplicaOnPartition [ ] ; sortedReplicas = [ ] ; replicaDict = { } ; expandedDict = { } ; cachedData : Record < string , ITimedReplication [ ] > = { } ; primaryReplica : ReplicaOnPartition ; overviewItems : IEssentialListItem [ ] = [ ] ; replicationStatus : IEssentialListItem [ ] = [ ] ; sub : Subscription = new Subscription ( ) ; constructor ( ) { } ngOnChanges ( ) { this . replicas . forEach ( replica => { if ( replica . raw . ReplicaRole === 'Primary' ) { this . primaryReplica = replica ; } } ) ; if ( this . primaryReplica ) { this . sub . add ( this . primaryReplica . detail . refresh ( ) . subscribe ( ( ) => { const queueSize = Utils . getFriendlyFileSize ( + this . primaryReplica . detail . raw . ReplicatorStatus . ReplicationQueueStatus . QueueMemorySize ) ; const replicatorData = this . primaryReplica . detail . raw . ReplicatorStatus ; this . replicaDict = replicatorData . RemoteReplicators . reduce ( reduceReplicators , { } ) ; replicatorData . RemoteReplicators . forEach ( replicator => { const cacheData = { ... replicator , date : new Date ( ) } ; if ( ! this . cachedData [ replicator . ReplicaId ] ) { this . cachedData [ replicator . ReplicaId ] = [ ] ; } if ( this . cachedData [ replicator . ReplicaId ] . length > 20 ) { this . cachedData [ replicator . ReplicaId ] . shift ( ) ; } this . cachedData [ replicator . ReplicaId ] . push ( cacheData ) ; } ) ; this . sortedReplicas = this . replicas . sort ( ( a , b ) => a . replicaRoleSortPriority - b . replicaRoleSortPriority ) ; const ref = this . primaryReplica . detail . replicatorStatus . raw . ReplicationQueueStatus ; this . overviewItems = [ { descriptionName : 'Queue Utilization Percentage' , copyTextValue : ref . QueueUtilizationPercentage , displayText : ref . QueueUtilizationPercentage + '%' , } , { descriptionName : 'Queue Memory Size' , copyTextValue : queueSize , displayText : queueSize , } , ] ; this . replicationStatus = [ { descriptionName : 'Last Sequence Number(LSN) ' , copyTextValue : ref . LastSequenceNumber , displayText : ref . LastSequenceNumber , } , { descriptionName : 'Completed Sequence Number' , copyTextValue : ref . CompletedSequenceNumber , displayText : ref . CompletedSequenceNumber , } , { descriptionName : 'Committed Sequence Number' , copyTextValue : ref . CommittedSequenceNumber , displayText : ref . CommittedSequenceNumber , } , ] ; } ) ) ; } } ngOnDestroy ( ) { this . sub . unsubscribe ( ) ; } trackByFn ( index , replicaStatus ) { return replicaStatus . ReplicaId + index ; } }