@@ -44,6 +44,9 @@ function promoteNewPrimary() {
4444 resp = this . setContainerVar ( ) ;
4545 if ( resp . result != 0 ) return resp ;
4646
47+ resp = this . setNewMasterNode ( ) ;
48+ if ( resp . result != 0 ) return resp ;
49+
4750 resp = this . addNode ( ) ;
4851 if ( resp . result != 0 ) return resp ;
4952
@@ -114,6 +117,13 @@ function promoteNewPrimary() {
114117 return this . cmdByGroup ( "touch " + TMP_FILE , SQLDB , 3 ) ;
115118 } ;
116119
120+ this . setNewMasterNode = function ( ) {
121+ return jelastic . dev . scripting . Eval ( "ext" , session , "api.env.control.SetMasterNode" , {
122+ envName : envName ,
123+ nodeId : this . getNewPrimaryNode ( ) . id
124+ } ) ;
125+ } ;
126+
117127 this . setContainerVar = function ( ) {
118128 let resp = this . setDomains ( ) ;
119129 if ( resp . result != 0 ) return resp ;
@@ -355,21 +365,24 @@ function promoteNewPrimary() {
355365 if ( resp . result != 0 ) return resp ;
356366
357367 let nodes = this . getParsedNodes ( ) ;
368+
369+ this . log ( "getParsedNodes resp->" + nodes ) ;
358370
359371 if ( nodes ) {
360372 for ( let i = 0 , n = nodes . length ; i < n ; i ++ ) {
361373 if ( nodes [ i ] ) {
362- if ( nodes [ i ] . type == SECONDARY && ! alreadySetNewPrimary ) {
374+ if ( nodes [ i ] . type == "secondary" && ! alreadySetNewPrimary ) {
363375 this . setNewPrimaryNode ( nodes [ i ] ) ;
364376 alreadySetNewPrimary = true ;
365- } else {
377+ }
378+ if ( nodes [ i ] . type == "primary" ) {
366379 resp = api . env . control . SetNodeDisplayName ( envName , session , nodes [ i ] . id , PRIMARY + " - " + FAILED ) ;
367380 if ( resp . result != 0 ) return resp ;
368381
369382 resp = this . getSQLNodeById ( nodes [ i ] . id ) ;
370383 if ( resp . result != 0 ) return resp ;
371384
372- if ( resp . node && ! resp . node . ismaster ) {
385+ if ( resp . node ) {
373386 this . setFailedPrimary ( resp . node ) ;
374387 }
375388 }
@@ -388,15 +401,24 @@ function promoteNewPrimary() {
388401 let resp = this . cmdById ( newPrimary . id , command , 20 ) ;
389402 if ( resp . result != 0 ) return resp ;
390403
404+
405+
391406 return api . env . control . SetNodeDisplayName ( envName , session , newPrimary . id , PRIMARY ) ;
392407 } ;
393408
394409 this . restoreNodes = function ( ) {
395410 let nodes = this . getParsedNodes ( ) ;
411+
412+ this . log ( "restoreNodes: getParsedNodes resp->" + nodes ) ;
396413
397414 let newPrimary = this . getNewPrimaryNode ( ) ;
415+
416+ this . log ( "restoreNodes: getNewPrimaryNode resp->" + newPrimary ) ;
398417
399- let command = "/bash /tmp/db_recovery.sh --scenario restore_secondary_from_primary --donor-ip " + newPrimary . address ;
418+ let command = "bash /tmp/db_recovery.sh --scenario restore_secondary_from_primary --donor-ip " + newPrimary . address ;
419+
420+ this . log ( "restoreNodes: command resp->" + command ) ;
421+
400422 for ( let i = 0 , n = nodes . length ; i < n ; i ++ ) {
401423 if ( nodes [ i ] . id != newPrimary . id && nodes [ i ] . type == SECONDARY ) {
402424 let resp = this . cmdById ( nodes [ i ] . id , command ) ;
@@ -494,6 +516,7 @@ function promoteNewPrimary() {
494516
495517 this . removeFailedPrimary = function ( ) {
496518 let failedPrimary = this . getFailedPrimary ( ) ;
519+ this . log ( "diagnosticNodes Primary ->" + failedPrimary ) ;
497520 if ( failedPrimary && ! failedPrimary . ismaster ) {
498521 return api . env . control . RemoveNode ( envName , session , failedPrimary . id ) ;
499522 }
0 commit comments