Esframework (22)-automatic server system upgrade

Source: Internet
Author: User

(This document is named "automatic server system upgrade", which is applicable to all applications.ProgramAutomatic Upgrade .)
The previous article describes how to automatically upgrade and update the plug-in when the server or client application is running. For the same reason as above, as, FS, and IRAs must also have the automatic upgrade function.
Different from the dynamic update during running of the plug-in, the server system cannot be dynamically updated during running. It is the starting point for automatic upgrade only when the server system is restarted.
(1) For function server FS, you can use the continuous/one-by-one update method, that is, restart each function server in turn. This prevents the interruption of function services. Note that the FS can be restarted only when there is no function request on the target FS. Otherwise, the terminal may experience a bad user experience where the request is not responded. Solution: Before the FS restarts, the FS reports to the corresponding as that it will immediately restart, so that the as will no longer distribute requests to the fs. After a while, there is no function request on this FS, so it can be restarted smoothly.
(2) For IRAs and as, it is necessary to meet the condition that the system does not have function requests before the restart, which can be achieved by not accepting terminal connection requests for a period of time. If the as service cannot be stopped, you can enable the backup as (you can switch between the master as and the backup as through port ing) When upgrading the as in the current region. After the upgrade, switch back.

As mentioned above, when the server is restarted, it is the starting point for system upgrade. This starting point is generally in the main function and is located before application. Run. Example:CodeAs shown in:

# Region System Upgrade
  If (Mainclass. asconfig. updateenabled)
{
Datacenterbase. Common. datacenterhelper = (Datacenterbase. Common. datacenterhelper) mainclass. springcontext. GetObject ( " Datacenterhelper " );

// If a new version is available
If (Datacenterhelper. getappservernewversion () > Mainclass. Version)
{
String Dir = System. Io. Path. getdirectoryname (system. Windows. Forms. application. executablepath );
// Path of the Upgrade Program
String Updateexepath = Dir +   " \\ "   + Mainclass. asconfig. updateexefilename;
// Start the Upgrade Program and Exit Main
Enterpriseserverbase. Common. advancedfunction. startapplication (updateexepath );
Return ;
}
}
# Endregion

There are so many upgrade-related code in the system that requires automatic upgrade (for example, the above as). This article focuses on the implementation of the upgrade program. In the Upgrade Program, the core interface is iautoupdator, which is located in the esframework. Deploy namespace:

Public   Interface Iautoupdator
{
Void Start ();
Void Cancel ();

Iupdateassistant updateassistant {Set;}
Iuireporter uireporter {Set;}

EventCbsimple updatefinished;
}

The start method starts the upgrade process. When the upgrade is complete, the updatefinished event is triggered. When the upgrade starts, iautoupdator reads the version information of the application in the local configuration file and each DLL and related files, and then compares it with the obtained latest version to determine which EXE or DLL to be upgraded, which DLL to delete and which EXE or DLL to download. Each EXE or DLL (or even an important file required for upgrading) has a oneupdate object.

Public   Class Oneupdate
{
Public Updatingtype updatetype = Updatingtype. Keep;
Public   String URL;
Public   String Filepath;
Public   String Filename;
Public   Float Newversion;
}

///   <Summary>
/// Updatingtype
///   </Summary>
Public   Enum Updatingtype
{
Add, remove, update, keep // Keep indicates that no update is required.
}

This is the same as the previous plug-in upgrade. Some people may ask why plug-in Upgrade and application upgrade cannot be made into the same components, which can be reused more? The reason is that their upgrade modes are different, plug-ins are dynamically upgraded, and the application itself can only be statically upgraded (of course, even if you dynamically upgrade the plug-in loaded in this application ).
If the upgrade is to be completed smoothly, some necessary information needs to be obtained, such as the version number of the latest version, the server system EXE of the latest version, and related DLL, which are provided through the iupdateassistant interface:

Public   Interface Iupdateassistant
{
Iupdateinformation [] getupdateinformation (); // Obtain information about the latest files (such as EXE and DLL ).
Fileinfo [] getfileinfotoupdate (); // Obtain the current version of the file to be upgraded (such as EXE and DLL)
String Getfiledirectory ();

// Usually operate on local configuration files
Void Revisefileversion ( String Filename, Float Newver ); // Add or modify
Void Removefileversion ( String Filename );
}

Public ClassFileinfo
{
Public StringFilename;
Public FloatVersion;
}

Public   Interface Iupdateinformation
{
String Filename { Get ; Set ;}
String URL { Get ; Set ;}
Float Version { Get ; Set ;}
String Filetype { Get ; Set ;}
Bool Isvalid { Get ; Set ;}
}

Different applications have different implementations for iupdateassistant. For example, some store the latest version of the server system EXE and related DLL in the database, and some may be stored on a web to be downloaded and obtained through URL. Sometimes new applications may need to delete some unnecessary DLL or other auxiliary files in the old version. removefileversion is used for this purpose. After the application and related DLL are upgraded, you need to change the corresponding version in the local configuration. revisefileversion provides this function.
Iautoupdator notifies the UI of the update progress through the iuireporter interface, so that the user can understand the update process.

Public   Interface Iuireporter
{
Void Initialize ( Int Minval, Int Maxval, Int Val );
Void Set ( Int Val );
 
Void Showmessage ( String MSG );
}

When an important event (such as network disconnection) causes the upgrade to fail, iupdateassistant will send a notification through the showmessage method of iuireporter. The implementation of iautoupdator is very easy with the help of the preceding auxiliary interfaces. For the implementation source code, see sframework. Deploy. autoupdator class.

With the help of autoupdator, You can implement your own Automatic Upgrade Program. First, create a new winform project to implement the auxiliary interfaces listed above based on your application needs, then assemble these implementations to autoupdator, as shown in the following figure:

Public Form1 ()
{
Initializecomponent ();

This . Autoupdator =   New Autoupdator ();
This . Autoupdator. uireporter =   This ;
This . Autoupdator. updateassistant =   New Updateassistant ();
This . Autoupdator. updatefinished + =   New Cbupdate (Autoupdator_updatefinished);
}

Then, start the upgrade in the load event:

Private   Void Form1_load ( Object Sender, system. eventargs E)
{
This . Autoupdator. Start ();
}

Finally, when the upgrade is complete, you need to restart the new version of the application:

Private   Void  Autoupdator_updatefinished()
{
MessageBox. Show ( " Upgrade complete! " );

String Apppath = System. Io. Directory. getparent (application. executablepath). tostring ();
Enterpriseserverbase. Configure. xmlparser =   New Enterpriseserverbase. Configure. xmlparser (apppath +   " \\ "   +   " Versioninfo. xml " );

// Start new applications
Process downprocess =   New Process ();
Downprocess. startinfo. filename =   String . Format ( " {0} \ {1} " , Apppath, xmlparser. getconfigvalue ( " Hostinfo " , " Startappname " ));
Downprocess. Start ();

This. Close ();
}

The current design mainly supports downloading the latest file from the URL (this can be seen from the URL attribute of the iupdateinformation Interface), which is also the most common method. Of course, you can store the latest version of the file in the database. In this case, you need to modify the iupdateinformation interface definition to adapt. Give full play to your creativity. Welcome to share your thoughts with me!
Thanks for your attention!

PreviousArticle: Esframework introduction (20)-Automatic agent upgrade

Go to: esframework reusable Communication Framework (sequence)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.