import { TimeUtils } from 'src/app/Utils/TimeUtils' ; import { DataModelBase } from '../DataModels/Base' ; import { DataService } from 'src/app/services/data.service' ; export interface IFabricEventMetadata { kind : string ; eventInstanceId : string ; timeStamp : string ; hasCorrelatedEvents ? : boolean ; } export interface IEventPropertiesCollection { eventProperties : { [ key ] : any ; } ; } export abstract class FabricEventBase implements IFabricEventMetadata , IEventPropertiesCollection { public hasCorrelatedEvents : boolean ; public eventProperties : { [ key ] : any ; } = { } ; public kind : string ; public eventInstanceId : string ; public timeStamp : string ; public category : string ; public raw : { [ key ] : any ; } = { } ; public get timeStampString ( ) { return TimeUtils . datetimeToString ( this . timeStamp ) ; } public fillFromJSON ( responseItem ) { this . raw = responseItem ; for ( const property in responseItem ) { if ( ! this . extractField ( property , responseItem [ property ] ) ) { this . eventProperties [ property ] = responseItem [ property ] ; } } } protected extractField ( name , value ) { switch ( name ) { case 'Kind' : this . kind = value ; return true ; case 'Category' : this . category = value ; return true ; case 'EventInstanceId' : this . eventInstanceId = value ; return true ; case 'TimeStamp' : this . timeStamp = value ; return true ; case 'HasCorrelatedEvents' : this . hasCorrelatedEvents = value ; return true ; default : break ; } return false ; } } export class FabricEventInstanceModel < T extends FabricEventBase > extends DataModelBase < T > { public isSecondRowCollapsed = true ; public constructor ( data , raw ) { super ( data , raw ) ; } public get uniqueId ( ) { return this . raw . kind + this . raw . eventInstanceId + this . raw . timeStamp ; } public get id ( ) { return this . raw . eventInstanceId ; } public get name ( ) { return `${ this . raw . kind } (${ this . raw . eventInstanceId })` ; } } export class FabricEvent extends FabricEventBase { } export class ClusterEvent extends FabricEventBase { } export class NodeEvent extends FabricEventBase { public nodeName : string ; protected extractField ( name , value ) { if ( super . extractField ( name , value ) ) { return true ; } switch ( name ) { case 'NodeName' : this . nodeName = value ; return true ; default : break ; } return false ; } } export class ApplicationEvent extends FabricEventBase { public applicationId : string ; protected extractField ( name , value ) { if ( super . extractField ( name , value ) ) { return true ; } switch ( name ) { case 'ApplicationId' : this . applicationId = value ; return true ; default : break ; } return false ; } } export class ServiceEvent extends FabricEventBase { public serviceId : string ; protected extractField ( name , value ) { if ( super . extractField ( name , value ) ) { return true ; } switch ( name ) { case 'ServiceId' : this . serviceId = value ; return true ; default : break ; } return false ; } } export class PartitionEvent extends FabricEventBase { public partitionId : string ; protected extractField ( name , value ) { if ( super . extractField ( name , value ) ) { return true ; } switch ( name ) { case 'PartitionId' : this . partitionId = value ; return true ; default : break ; } return false ; } } export class ReplicaEvent extends FabricEventBase { public partitionId : string ; public replicaId : string ; protected extractField ( name , value ) { if ( super . extractField ( name , value ) ) { return true ; } switch ( name ) { case 'PartitionId' : this . partitionId = value ; return true ; case 'ReplicaId' : this . replicaId = value ; return true ; default : break ; } return false ; } } export class EventsResponseAdapter < T extends FabricEventBase > { public constructor ( private eventType ) { } public getEvents ( responseItems ) { return responseItems . map ( item => { const eventObj = new this . eventType ( ) ; eventObj . fillFromJSON ( item ) ; return eventObj ; } ) ; } }