module Sfx { 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 this . data . routes . 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 this . data . routes . 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 ( ) . then ( ( ) => Utils . getHttpResponseData ( this . data . restClient . getReplicaOnPartition ( this . parent . parent . parent . id , this . parent . parent . id , this . parent . id , this . id , messageHandler ) ) ) ; } protected updateInternal ( ) { this . address = Utils . parseReplicaAddress ( this . raw . Address ) ; } private setUpActions ( ) { let serviceName = this . parent . parent . raw . Name ; if ( this . isStatefulService ) { this . actions . add ( new ActionWithConfirmationDialog ( this . data . $uibModal , this . data . $q , "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 . $uibModal , this . data . $q , "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 Utils . getHttpResponseData ( 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 ) ) ; } } }