Ñò
ýÉªWc           @   s  d  d k  l  Z  d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k	 l	 Z	 d  d k
 Z
 d  d k Z d  d k Z d  d k Z d  d k Z d  d	 k l Z d
 e	 f d „  ƒ  YZ d „  Z d „  Z e d j o  e
 i
 d d e ƒ Z e ƒ  n d S(   iÿÿÿÿ(   t   InstallComponentCollector(   t   InstallConfigObjectConstructor(   t   InstallHelper(   t   Backup(   t   Deploy(   t   Rollback(   t   CommonN(   t   CMSVersionDeploymentPolicyt   Installc           B   s}   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z RS(   c         C   sW   t  i |  ƒ |  i | t ƒ | |  i d <|  i ƒ  |  i ƒ  t ƒ  |  _ d  |  _
 d  S(   Nt   mode(   R   t   __init__t   loadJsonConfigt   Truet   configt
   initPolicyt   initParametersR    t   installComponentCollectort   Nonet   combinedPath(   t   selft   systemInfoFileR	   (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR
       s    

c      	   C   s    d d  k  } | i d d t d | i d | i ƒ} | i i ƒ  } t | ƒ d j o> | d i d d	 ƒ | d
 i d d	 ƒ | d i d d	 ƒ f St	 t	 t	 f S(   Niÿÿÿÿs-   java -jar ./rpms/prepack-license-manager*.jart   shellt   stdoutt   stderri   i    s   
t    i   i   (
   t
   subprocesst   PopenR   t   PIPEt   STDOUTR   t	   readlinest   lent   replacet   False(   R   R   t   pt   lines(    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyt   getLicenseInfo1   s    '>c         C   s¢  |  i  ƒ  \ } } } | d j o
 | GHt S| d j o
 | GHt S| d j o
 | GHt S| t j o
 d GHt S|  i ƒ  p t S|  i ƒ  p t S|  i ƒ  p t S|  i ƒ  p
 d GHt S| i d ƒ } |  i i | t	 i
 ƒ  | ƒ } | p t S| \ } } }	 }
 } d  } t	 i ƒ  p |  i i |  i |  i ƒ } n t | | |	 |
 | ƒ } | i ƒ  \ } } } | o |  i d ƒ t S| i |  i |  i ƒ } |  i | |  i ƒ } |  i i | ƒ |  _ |  i | ƒ \ } } |  _ | o= | o6 |  i d ƒ |  i ƒ  } | p |  i d	 ƒ t Sn |  i i |	 |
 ƒ |  i | d
 <| o |  i | ƒ p t Sn |  i | ƒ p t S|  i i | |	 |
 ƒ |  i d ƒ t  S(   Nt   LIC_NOTFOUNDt   LIC_CAPACITY_EXCEEDEDt   LIC_INVALIDs   Failed to check license!s=   
Required configuration is not correct. Please fix it first.
t   ,sN   There is no operations selected to handle. System would skip the installation.sb   System is going to roll back to last snapshot before installing the components you selected again.sk   System is encountering problem when rolling back to last snapshot, please contact the system administrator.t   backupVersions   Installation complete.(!   R#   R    t   determineUpgradePatht   validateVersionNumbert   checkInstallerValidToRunt   checkRequiredConfigt   splitR   t   processToCollectAllSelectionsR   t   isPatchModeR   t   isFreshInstallt   collectAllUpgradeComponentst   COMPONENTS_PATH_PREFIXt   installerVersionR   t   getInstallStatust   outputt   constructFinalJsonObjt   mergeConfigR   t   helpert   saveCombinedConfigObjectR   t&   decideBackupOrNotAndSolveBackupVersionR(   t   rollbackFirstt   saveUserSelectionAsTempt   backupt   deployt   saveCurrentInstalledComponentsR   (   R   t   preConfiguredFilet   statet   errorMessget
   componentst   componentPathst   resultt   fullInstallComponentst   installedComponentst   componentsToDeletet   componentsToInstallt   reselectt   availableUpgradeComponentst   configObjectConstructort   isInstallNewOrRemovet   isUpgradeOnlyt   isInvolveNothingt   configObjectt   deployStartedt   proceedBackupt   rollbackResult(    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyt   install9   sn    		c         C   s¯   t  i ƒ  o, |  i i |  i ƒ o |  i d ƒ t Sn t  i ƒ  o, |  i i |  i ƒ p |  i d ƒ t Sn t  i ƒ  o, |  i i	 |  i ƒ p |  i d ƒ t Sn t
 S(   Nss   Fresh installation should have a version number without '-' in it, Please check the system info configuration file.sª   Upgrade installation should have a version number with '-' in it indicating from a earlier version to the latest version, Please check the system info configuration file.sw   Error: Patch installation should have a version number like '3.1.001', Please check the system info configuration file.(   R   R0   R8   t   isVersionUpgradeFormatR3   R5   R    t   isUpgradeModeR/   t   isVersionPatchFormatR   (   R   (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR*   ‚   s    			c         C   sp  |  i  i ƒ  } |  i  i ƒ  } t i ƒ  o¬ | d  j	 o› |  i  i | |  i ƒ } | d j o$ |  i  i d | d ƒ p t	 Sn | d j o |  i
 d | d ƒ t	 S| d j o |  i
 d | d	 ƒ t	 Sq× n t i ƒ  ox|  i d
 ƒ } | p |  i
 d ƒ t	 S|  i  i |  i ƒ \ } } |  i  i | | ƒ d j o | o3 |  i
 d | d d i | ƒ d | d ƒ t	 S|  i  i ƒ  p |  i
 d | d ƒ t	 S|  i
 d | d ƒ t	 Sn? |  i  i | | ƒ d j o" |  i
 d | d | d ƒ t	 S| d  j o |  i
 d ƒ t	 S|  i | j o' |  i
 d |  i d t | ƒ ƒ t	 Sn t i ƒ  o|  i  i |  i ƒ } | p |  i
 d | d ƒ t	 S|  i  i | | ƒ d j o" |  i
 d | d | d ƒ t	 S| o„ |  i | j op | t | ƒ d |  i j o' |  i  i d |  i d ƒ p t	 Sqd|  i
 d | t | ƒ d d ƒ t	 Sqhqln t S(   Ni    s   Version sp    is already installed, Do you still want to rerun this? type 'yes' to continue rerun; type 'no' to skip.======> i   s   There is an earlier version s5    installed, Please run the upgrade installer instead.iÿÿÿÿs%   The current version is already up to s.   , it is not allowed to run an earlier version.t   upgradePathso   There is not any previous prepack version installed, Please check if the correct installer is used. Skipping...s0    is already installed, But patches with version R'   sE    has been applied, Please run the rollback to get it back to version s#    instead of running this installer.s4    is installed, It is not required to run the upgrades5   Current Prepack has already been upgraded to version s(   , it is not required to run the upgrade.s   The current version is: sA   , but the installer is expected to be upgraded based on version: s<   , Please check if the correct installer is used. Skipping...sv   Error: configuration error! upgrade path does not defined in upgrade_sysInfo.json, contact PDU for next level support.s   Error: st    is not a valid upgrade path for this pre-package! This installer package only supports the following upgrade path: si   There is not any previous prepack version installed, but the patch is expected to be applied to version: s6   , but the patch is expected to be applied to version: s   Patch sl    is already installed, Do you still want to rerun this? type yes to continue rerun; type no to skip.======> s   The lastest patches applied is s7   , you are not allowed to reinstall this patch any more.(   R8   t   getCurrentPrepackVersiont"   getPatchesForCurrentPrepackVersionR   R0   R   t   compareVersionR3   t   promptYesOrNoR    R5   RV   t	   getConfigt   getUpgradeFromTot   joint   isCurrentVersionFromUpgradet   strR/   t   getVersionMainR   R   (   R   t   currentInstalledPrepackVersiont   patchest   compareResultt   upgradePathst   fromPrepackVersiont   toPrepackVersiont   patchOnVersin(    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR+   ‘   sn    	.		#c         C   sz   t  i ƒ  p t S|  i i ƒ  } | o= | d |  i |  _ |  i |  i d <|  i d |  i ƒ t S|  i d ƒ t Sd S(   sR   
        determine current upgrade path and update the installer version 
        t   -t   versions   installer version is: so   There is not any previous prepack version installed, Please check if the correct installer is used. Skipping...N(	   R   RV   R   R8   RY   R3   R   R5   R    (   R   Rc   (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR)   Ù   s    c         C   sC   y t  d ƒ } | i t ƒ SWn t j
 o t i ƒ  GHt SXd  S(   Ns   rollback_sysInfo.json(   R   t   rollbackR   t	   Exceptiont	   tracebackt
   format_excR    (   R   t   rol(    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR;   ë   s    c   	      C   si  |  i  i ƒ  } } |  i  i | ƒ \ } } } } t } | p= t } | o, |  i d |  i d ƒ |  i  i | ƒ q n¦ | p< |  i  i d |  i d ƒ o t } |  i  i | ƒ q¾ n | o[ |  i  i	 |  i ƒ o | o |  i d ƒ t } q |  i  i
 | |  i ƒ o
 t } q n | o5 |  i  i |  i  i |  i ƒ ƒ } |  i  i | ƒ n | | | f S(   Ns   Backup for current version: sj    failed on last execution, Last backup will be abandoned, new backup with current status will be executed.s¨    is done on last execution, but nothing has been deployed since the backup, type 'yes' to backup the current status, type 'no' to keep the status of last backup.=====> sy   System will backup this snapshot because the installer is rerun to remove existing components or install more components (   R8   t   getLastHandledBackupVersiont   getBackupDeployStatusForVersionR    R   R5   R3   t   abandonCurrentBackupR\   t   isInstallerRerunt   isDifferentInstallert   appenTimeStampToBackupVersiont   solveBackupVersiont   saveLastHandledBackupVersion(	   R   RM   R(   t   lastHandledBackupVersiont   backupStartedt   backupFinishedRQ   t   deployFinishedRR   (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR:   ô   s,    
!c         C   s>  t  i ƒ  d j o'|  i d ƒ } | d
 j o
 d GHt St | ƒ t g  ƒ j p t | ƒ d j o
 d GHt SxG | D]? } d | j p" | d d
 j p | d d j o
 d GHt Sqv W|  i d ƒ } | og t | ƒ t g  ƒ j oN xK | D]? } d | j p" | d d
 j p | d d j o
 d	 GHt Sqï Wq:n t S(   s1   Try to check required configuration is available.g      @t   cluster_service_nodess?   Configuration entry of "cluster_service_nodes" cannot be empty.i    s/   Error configuration of "cluster_service_nodes".t   ipR   t   cluster_app_nodess+   Error configuration of "cluster_app_nodes".N(   R   t   getCMSVersionR]   R   R    t   typeR   R   (   R   t   csnodest   cnt   appnodest   apn(    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR,     s*    , /	  /c         C   so   |  i  i t i |  i t i ƒ |  i | ƒ } | o6 |  i  i t i |  i t i ƒ |  i  i |  i ƒ n | S(   N(	   R8   t
   logActionsR   t   BACKUPR(   t   STARTt   doBackupt   FINISHt   saveNewBackupVersion(   R   t   inputfileOrObjectRE   (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR=   &  s    c         C   s@   y t  | ƒ } | i ƒ  SWn t j
 o t i ƒ  GHt SXd  S(   N(   R   R=   Rm   Rn   Ro   R    (   R   RŒ   t   bak(    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR‰   /  s    c         C   so   |  i  i t i |  i t i ƒ |  i | ƒ } | o6 |  i  i t i |  i t i ƒ |  i  i |  i	 ƒ n | S(   N(
   R8   R†   R   t   DEPLOYR(   Rˆ   t   doDeployRŠ   t   saveNewPrepackVersionR3   (   R   RŒ   RE   (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR>   8  s    c         C   sP   y* t  | ƒ } | i |  i ƒ | i ƒ  SWn t j
 o t i ƒ  GHt SXd  S(   N(   R   t   setCombinedConfigJsonPathR   R>   Rm   Rn   Ro   R    (   R   RŒ   t   dep(    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR   @  s    (   t   __name__t
   __module__R
   R#   RT   R*   R+   R)   R;   R:   R,   R=   R‰   R>   R   (    (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR      s   			I		H										c         C   s	   |  GHd  S(   N(    (   t	   outputstr(    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyR5   N  s    c          C   sì  d  }  d  } d } y2 t i t i d d d d d d g ƒ \ } } Wn9 t i j
 o* } t d t | ƒ ƒ t i d	 ƒ n Xx | D]y \ } } | d j o t d ƒ t i d ƒ q‡ | d j o
 | }  q‡ | d j o
 | } q‡ | d j o
 | } q‡ q‡ Wt i	 i
 d ƒ } | d j o% t d ƒ t d ƒ t i d ƒ n z yD t | | ƒ }	 |	 i |  ƒ }
 |
 p t d ƒ t i d	 ƒ n Wn4 t j
 o( t d ƒ t d ƒ t i d	 ƒ n XWd  t i ƒ  i ƒ  Xt i d ƒ d  S(   Nt   Freshi   s	   h:i:p:m:vt   helpt   ifilet   preconfigFileR	   s   install.py [-p preconfigFile]i   s   -hs   --helps'   install.py [-p preconfigFile] -m <mode>i    s   -ps   --preconfigFiles   -is   --ifiles   -ms   --modet   LOGNAMEt   roots   You must run this as user root.s
   Exiting...s   Installation Failed Or Skipped.R   s   <CTRL>-C detected...Exiting...(   s   -hs   --help(   s   -ps   --preconfigFile(   s   -is   --ifile(   s   -ms   --mode(   R   t   getoptt   syst   argvt   GetoptErrorR5   Ra   t   exitt   ost   environt   getR   RT   t   KeyboardInterruptR   t   getPrepackDepolymentPolicyt   cleanDatabaseConnection(   t   preConfigFileR   R	   t   optst   argst   errt   ot   at	   userlogint   insRE   (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyt   mainQ  sJ    2 




 


t   __main__s   install.logR¬   (   R    R   R   R=   R   R>   R   Rl   R   R   t   TeeRœ   R¡   R   Rn   R   R   R5   R¯   R“   R   t   logFile(    (    (    sa   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/install.pyt   <module>   s&   ÿ 1		'