2626import time
2727import textwrap
2828import json
29+ import glob
30+ import datetime
2931from uuid import uuid1 as uuid , UUID
3032from optparse import OptionParser , BadOptionError , Option , IndentedHelpFormatter
3133
3941from ssh import LocalClient
4042from const import (
4143 CONST_OBD_HOME ,
42- VERSION , REVISION , BUILD_BRANCH , BUILD_TIME , FORBIDDEN_VARS ,
43- COMP_OCEANBASE_DIAGNOSTIC_TOOL , PKG_RPM_FILE ,PKG_REPO_FILE
44+ VERSION , REVISION , BUILD_BRANCH , BUILD_TIME , FORBIDDEN_VARS , COMP_OB_CE , COMP_ODP_CE , COMP_ODP , COMP_OCP_SERVER_CE ,
45+ COMP_OCEANBASE_DIAGNOSTIC_TOOL , PKG_RPM_FILE ,PKG_REPO_FILE , BUILD_PLUGIN_LIST
4446)
4547
4648
@@ -197,12 +199,50 @@ def init_home(self):
197199 if not COMMAND_ENV .get (ENV .ENV_OBD_ID ):
198200 COMMAND_ENV .set (ENV .ENV_OBD_ID , uuid ())
199201 if VERSION != version :
200- for part in ['plugins' , 'config_parser' , 'optimize' , 'mirror/remote' ]:
202+ for part in ['workflows' , ' plugins' , 'config_parser' , 'optimize' , 'mirror/remote' ]:
201203 obd_part_dir = os .path .join (self .OBD_PATH , part )
204+ root_part_path = os .path .join (self .OBD_INSTALL_PATH , part )
202205 if DirectoryUtil .mkdir (self .OBD_PATH ):
203- root_part_path = os .path .join (self .OBD_INSTALL_PATH , part )
204- if os .path .exists (root_part_path ):
205- DirectoryUtil .copy (root_part_path , obd_part_dir , ROOT_IO )
206+ if part != 'mirror/remote' :
207+ if os .path .exists (obd_part_dir ):
208+ backup_path = os .path .join (self .OBD_PATH , '.backup_plugin' , VERSION + '_' + REVISION , part )
209+ if DirectoryUtil .mkdir (backup_path ):
210+ DirectoryUtil .copy (obd_part_dir , backup_path , ROOT_IO )
211+ os .chdir (obd_part_dir )
212+ if part != 'config_parser' :
213+ for file in glob .glob ('*/*/*' ):
214+ if COMP_OB_CE in file or COMP_OCP_SERVER_CE in file or (COMP_ODP_CE in file and 'file_map.yaml' in file ):
215+ continue
216+ if file not in BUILD_PLUGIN_LIST :
217+ FileUtil .rm (file )
218+ else :
219+ for file in glob .glob ('*/*' ):
220+ if file not in BUILD_PLUGIN_LIST :
221+ FileUtil .rm (file )
222+
223+ if os .path .exists (root_part_path ):
224+ os .chdir (root_part_path )
225+ if part != 'config_parser' :
226+ for file in glob .glob ('*/*/*' ):
227+ if COMP_OB_CE in file or COMP_OCP_SERVER_CE in file or (COMP_ODP_CE in file and 'file_map.yaml' in file ):
228+ continue
229+ if file not in BUILD_PLUGIN_LIST :
230+ if file .replace (COMP_ODP_CE , COMP_ODP ).replace ('3.2.1' , '3.1.0' ) in BUILD_PLUGIN_LIST :
231+ continue
232+ FileUtil .rm (file )
233+ else :
234+ for file in glob .glob ('*/*' ):
235+ if file not in BUILD_PLUGIN_LIST :
236+ FileUtil .rm (file )
237+ if os .path .exists (root_part_path ):
238+ DirectoryUtil .copy (root_part_path , obd_part_dir , ROOT_IO )
239+
240+ backup_path = os .path .join (self .OBD_PATH , '.backup_plugin' )
241+ if os .path .exists (backup_path ):
242+ dir_list = [os .path .join (backup_path , f ) for f in os .listdir (backup_path )]
243+ sorted_dir_list = sorted (dir_list , key = lambda dir : datetime .datetime .fromtimestamp (os .path .getmtime (dir )))
244+ for dir in sorted_dir_list [12 :]:
245+ DirectoryUtil .rm (dir )
206246 version_fobj .seek (0 )
207247 version_fobj .truncate ()
208248 version_fobj .write (VERSION )
@@ -1208,7 +1248,8 @@ def init(self, cmd, args):
12081248
12091249 def _do_command (self , obd ):
12101250 if len (self .cmds ) == 2 :
1211- return obd .failover_decouple_tenant (self .cmds [0 ], self .cmds [1 ], 'failover' )
1251+ self .cmds .append ('failover' )
1252+ return obd .failover_decouple_tenant (self .cmds [0 ], self .cmds [1 ], self .cmds [2 ])
12121253 else :
12131254 return self ._show_help ()
12141255
@@ -1226,7 +1267,8 @@ def init(self, cmd, args):
12261267
12271268 def _do_command (self , obd ):
12281269 if len (self .cmds ) == 2 :
1229- return obd .failover_decouple_tenant (self .cmds [0 ], self .cmds [1 ], 'decouple' )
1270+ self .cmds .append ('decouple' )
1271+ return obd .failover_decouple_tenant (self .cmds [0 ], self .cmds [1 ], self .cmds [2 ])
12301272 else :
12311273 return self ._show_help ()
12321274
@@ -1652,7 +1694,7 @@ def do_command(self):
16521694 return super (UpdateCommand , self ).do_command ()
16531695
16541696 def _do_command (self , obd ):
1655- return obd .update_obd (VERSION , self .OBD_INSTALL_PRE )
1697+ return obd .update_obd (VERSION , self .OBD_INSTALL_PRE , self . OBD_INSTALL_PATH )
16561698
16571699
16581700class DisplayTraceCommand (ObdCommand ):
0 commit comments