import { IRawReplicaOnPartition , IRawReplicaHealth } from '../RawDataTypes' ; import { IDecorators , DataModelBase } from './Base' ; import { HtmlUtils } from 'src/app/Utils/HtmlUtils' ; import { DeployedReplicaDetail } from './DeployedReplica' ; import { DataService } from 'src/app/services/data.service' ; import { Partition } from './Partition' ; import { HealthStateFilterFlags } from '../HealthChunkRawDataTypes' ; import { ServiceKindRegexes , SortPriorities } from 'src/app/Common/Constants' ; import { TimeUtils } from 'src/app/Utils/TimeUtils' ; import { IResponseMessageHandler } from 'src/app/Common/ResponseMessageHandlers' ; import { HealthBase } from './HealthEvent' ; import { Observable } from 'rxjs' ; import { map , mergeMap } from 'rxjs/operators' ; import { ActionWithConfirmationDialog } from '../Action' ; import { RoutesService } from 'src/app/services/routes.service' ; export class ReplicaOnPartition extends DataModelBase < IRawReplicaOnPartition > { public decorators : IDecorators = { decorators : { LastInBuildDurationInSeconds : { displayName : ( name ) => 'Last In Build Duration' , displayValueInHtml : ( value ) => this . lastInBuildDuration } , NodeName : { displayValueInHtml : ( value ) => HtmlUtils . getLinkHtml ( value , this . nodeViewPath ) } , ReplicaRole : { displayValueInHtml : ( value ) => this . role } } } ; public health : ReplicaHealth ; public detail : DeployedReplicaDetail ; public address : any ; public constructor ( data , raw , public parent ) { super ( data , raw , parent ) ; this . health = new ReplicaHealth ( this . data , this , HealthStateFilterFlags . Default ) ; this . detail = new DeployedReplicaDetail ( this . data , this ) ; this . updateInternal ( ) ; if ( this . data . actionsEnabled ( ) ) { this . setUpActions ( ) ; } } public restartReplica ( ) { return this . data . restClient . restartReplica ( this . raw . NodeName , this . parent . raw . PartitionInformation . Id , this . raw . ReplicaId ) ; } public deleteInstance ( ) { return this . data . restClient . deleteReplica ( this . raw . NodeName , this . parent . raw . PartitionInformation . Id , this . raw . InstanceId ) ; } public get isStatefulService ( ) : boolean { return ServiceKindRegexes . Stateful . test ( this . raw . ServiceKind ) ; } public get isStatelessService ( ) : boolean { return ServiceKindRegexes . Stateless . test ( this . raw . ServiceKind ) ; } public get id ( ) : string { return this . raw . ReplicaId || this . raw . InstanceId ; } public get name ( ) : string { return this . id ; } public get role ( ) : string { if ( this . parent . raw . PartitionStatus === 'Reconfiguring' ) { return `Reconfiguring - Target Role: ${ this . raw . ReplicaRole }` ; } return this . raw . ReplicaRole ; } public get viewPath ( ) : string { return RoutesService . getReplicaViewPath ( this . parent . parent . parent . raw . TypeName , this . parent . parent . parent . id , this . parent . parent . id , this . parent . id , this . id ) ; } public get nodeViewPath ( ) : string { return RoutesService . getNodeViewPath ( this . raw . NodeName ) ; } public get lastInBuildDuration ( ) : string { return TimeUtils . getDurationFromSeconds ( this . raw . LastInBuildDurationInSeconds ) ; } public get replicaRoleSortPriority ( ) : number { return SortPriorities . ReplicaRolesToSortPriorities [ this . raw . ReplicaRole ] || 0 ; } protected retrieveNewData ( messageHandler ? ) { return this . parent . refresh ( ) . pipe ( mergeMap ( ( ) => this . data . restClient . getReplicaOnPartition ( this . parent . parent . parent . id , this . parent . parent . id , this . parent . id , this . id , messageHandler ) ) ) ; } protected updateInternal ( ) { this . address = HtmlUtils . parseReplicaAddress ( this . raw . Address ) ; } private setUpActions ( ) { const serviceName = this . parent . parent . raw . Name ; if ( this . isStatefulService ) { this . actions . add ( new ActionWithConfirmationDialog ( this . data . dialog , 'Restart Replica' , 'Restart Replica' , 'Restarting' , ( ) => this . restartReplica ( ) , ( ) => true , `Confirm Replica Restart` , `Restart Replica for ${ serviceName }` , 'confirm' ) ) ; } else if ( this . isStatelessService ) { this . actions . add ( new ActionWithConfirmationDialog ( this . data . dialog , 'Delete Instance' , 'Delete Instance' , 'Deleting' , ( ) => this . deleteInstance ( ) , ( ) => true , `Confirm Instance Delete` , `Delete Instance for ${ serviceName }` , 'confirm' ) ) ; } } } export class ReplicaHealth extends HealthBase < IRawReplicaHealth > { public constructor ( data , public parent , protected eventsHealthStateFilter ) { super ( data , parent ) ; } protected retrieveNewData ( messageHandler ? ) { return this . data . restClient . getReplicaHealth ( this . parent . parent . parent . parent . id , this . parent . parent . parent . id , this . parent . parent . id , this . parent . id , this . eventsHealthStateFilter , messageHandler ) ; } }