@@ -16,6 +16,7 @@ function promoteNewPrimary() {
1616 let containerEnvs = { } ;
1717 let base = api . data . base ;
1818 let tableName = "promotePrimary" ;
19+ let END_POINT = "EditEndpoint" ;
1920 let dbPromoteData = "" ;
2021 let force = getParam ( "force" , false ) ;
2122
@@ -132,7 +133,11 @@ function promoteNewPrimary() {
132133 } ;
133134
134135 this . EditEndPoint = function ( ) {
135- let resp = this . getEnvInfo ( ) ;
136+ //check if method is available
137+ let resp = api . dev . scripting . Eval ( "ext" , session , END_POINT , { } ) ;
138+ if ( resp . result != 3 ) return { result : 0 }
139+
140+ resp = this . getEnvInfo ( ) ;
136141 if ( resp . result != 0 ) return resp ;
137142
138143 let nodes = resp . nodes , node ;
@@ -141,7 +146,7 @@ function promoteNewPrimary() {
141146 if ( node . endpoints ) {
142147 for ( let k = 0 , l = node . endpoints . length ; k < l ; k ++ ) {
143148 if ( node . endpoints [ k ] . name == "PrimaryDB" ) {
144- return api . dev . scripting . Eval ( "ext" , session , "EditEndpoint" , {
149+ return api . dev . scripting . Eval ( "ext" , session , END_POINT , {
145150 envName : envName ,
146151 id : node . endpoints [ k ] . id ,
147152 name : node . endpoints [ k ] . name ,
@@ -411,27 +416,43 @@ function promoteNewPrimary() {
411416 let envInfo = this . getEnvInfo ( ) ;
412417 if ( envInfo . result != 0 ) return envInfo ;
413418
414- let resp = this . getNodesByGroup ( SQLDB ) ;
415- if ( resp . result != 0 ) return resp ;
416- let sqlNodes = resp . nodes ;
419+ let nodes = [ ] ;
420+ let nodeTypes = [ ] , node , count ;
421+
422+ for ( let i = 0 , n = envInfo . nodes . length ; i < n ; i ++ ) {
423+ node = envInfo . nodes [ i ] ;
424+
425+ if ( nodeTypes . indexOf ( String ( node . nodeType ) ) == - 1 ) {
426+ nodeTypes . push ( String ( node . nodeType ) ) ;
427+ resp = this . getNodesByGroup ( node . nodeGroup ) ;
428+ if ( resp . result != 0 ) return resp ;
417429
418- resp = api . env . control . ChangeTopology ( {
430+ count = resp . nodes . length ;
431+ if ( node . nodeGroup == SQLDB ) count += 1 ;
432+
433+ nodes . push ( {
434+ flexibleCloudlets : node . flexibleCloudlets ,
435+ fixedCloudlets : node . fixedCloudlets ,
436+ nodeType : node . nodeType ,
437+ nodeGroup : node . nodeGroup ,
438+ count : count
439+ } ) ;
440+ }
441+ }
442+
443+ this . log ( "addNode nodes ->" + nodes ) ;
444+
445+ let resp = api . env . control . ChangeTopology ( {
419446 envName : envName ,
420447 session : session ,
421448 env : {
422449 region : envInfo . env . hostGroup . uniqueName ,
423450 sslstate : envInfo . env . sslstate
424451 } ,
425- nodes : [ {
426- nodeType : sqlNodes [ 0 ] . nodeType ,
427- nodeGroup : sqlNodes [ 0 ] . nodeGroup ,
428- count : sqlNodes . length + 1 ,
429- fixedCloudlets : sqlNodes [ 0 ] . fixedCloudlets ,
430- flexibleCloudlets : sqlNodes [ 0 ] . flexibleCloudlets
431- } ]
452+ nodes : nodes
432453 } ) ;
433454 if ( resp . result != 0 ) return resp ;
434-
455+
435456 return this . cmdByGroup ( "rm -rf " + TMP_FILE , SQLDB , 3 ) ;
436457 } ;
437458
0 commit comments