1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
unit AdminReplication;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, InstanceSections, ComCtrls, ImgList,
AdditionalClasses, myx_admin_public_interface, myx_public_interface,
ApplicationDataModule, MySQLConnection, AuxFuncs,
Options, MyxError, TntExtCtrls, TntComCtrls, TntStdCtrls, gnugettext;
type
TAdminReplicationForm = class(TInstanceSectionForm)
ReplicationPnl: TTntPanel;
ReplicationPageControl: TTntPageControl;
OverviewTabSheet: TTabSheet;
Panel5: TTntPanel;
OverviewBevel: TTntBevel;
Label8: TTntLabel;
Image3: TTntImage;
Panel3: TTntPanel;
BottomBtnPnl: TTntPanel;
Button1: TTntButton;
LogImageList: TImageList;
ServerInformationTabSheet: TTabSheet;
Panel1: TTntPanel;
InformationBevel: TTntBevel;
Label1: TTntLabel;
Image1: TTntImage;
Panel2: TTntPanel;
ServerInformationListView: TTntListView;
ReplOverviewPnl: TTntPanel;
AddInstanceToMonitoringListBtn: TTntButton;
RefreshBtn: TTntButton;
RemoveInstancefromMonitoringListBtn: TTntButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ReplicationPnlResize(Sender: TObject);
procedure GenerateReplicationOverview;
procedure ReplicationPageControlChange(Sender: TObject);
procedure RefreshHostList;
procedure ConnectionLost(var Message: TMessage); message WM_CONNECTION_LOST;
procedure ConnectionEstablished(var Message: TMessage); message WM_CONNECTION_ESTABLISHED;
procedure ServerInformationListViewSelectItem(Sender: TObject;
Item: TListItem; Selected: Boolean);
procedure AddInstanceToMonitoringListBtnClick(Sender: TObject);
procedure RemoveInstancefromMonitoringListBtnClick(Sender: TObject);
procedure CheckUserReplHostBtns;
procedure RefreshBtnClick(Sender: TObject);
private
FReplicationHosts: TMYX_REPL_HOSTS;
FUserReplicationHosts: TMYX_USER_REPL_HOSTS;
FUserReplicationHostsFilename: WideString;
end;
var
AdminReplicationForm: TAdminReplicationForm;
//----------------------------------------------------------------------------------------------------------------------
implementation
{$R *.dfm}
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.FormCreate(Sender: TObject);
begin
InitForm(self);
DockedPanel:=ReplicationPnl;
FReplicationHosts:=nil;
FUserReplicationHosts:=nil;
FUserReplicationHostsFilename := MYXCommonOptions.UserDataDir + 'mysqlx_replication_hosts_' + MySQLConn.UserConnection.hostname +
'.xml';
if MySQLConn.Connected then
RefreshHostList
else
DisableEnablePages(ReplicationPageControl, False);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.FormDestroy(Sender: TObject);
begin
FReplicationHosts.Free;
FUserReplicationHosts.Free;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.ReplicationPnlResize(Sender: TObject);
var
InitSheetWidth,
InitSheetHeight: integer;
begin
InitSheetWidth:=563;
InitSheetHeight:=451;
//Adjust Page Control
ReplicationPageControl.Width:=ReplicationPnl.Width-591+571;
ReplicationPageControl.Height:=ReplicationPnl.Height-501+479;
//Overview Tab Sheet
OverviewBevel.Width:=OverviewTabSheet.Width-InitSheetWidth+535;
ReplOverviewPnl.Width:=OverviewTabSheet.Width-InitSheetWidth+535;
ReplOverviewPnl.Height:=OverviewTabSheet.Height-InitSheetHeight+353;
//Information Tab Sheet
InformationBevel.Width:=ServerInformationTabSheet.Width-InitSheetWidth+535;
ServerInformationListView.Width:=OverviewTabSheet.Width-InitSheetWidth+535;
ServerInformationListView.Height:=OverviewTabSheet.Height-InitSheetHeight+353;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.ReplicationPageControlChange(Sender: TObject);
begin
ReplicationPnlResize(self);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.GenerateReplicationOverview;
var
theReplModel: TReplicationModel;
LizReplNode,
AnnaReplNode,
BettyReplNode,
GraceReplNode: TReplicationNode;
begin
theReplModel:=TReplicationModel.Create(ReplOverviewPnl);
theReplModel.Parent:=ReplOverviewPnl;
theReplModel.Align:=alClient;
LizReplNode:=theReplModel.AddNode('Liz', rsRunning, 300, 40);
AnnaReplNode:=theReplModel.AddNode('Anna', rsRunning, 180, 140);
theReplModel.LinkNodes(LizReplNode, AnnaReplNode);
BettyReplNode:=theReplModel.AddNode('Betty', rsRunning, 300, 160);
theReplModel.LinkNodes(LizReplNode, BettyReplNode);
GraceReplNode:=theReplModel.AddNode('Grace', rsRunning, 420, 140);
theReplModel.LinkNodes(LizReplNode, GraceReplNode);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.RefreshHostList;
var
PUserHosts: PMYX_USER_REPL_HOSTS;
PReplHosts: PMYX_REPL_HOSTS;
error: MYX_ADMIN_LIB_ERROR;
I: integer;
ListItem: TListItem;
begin
ServerInformationListView.Items.Clear;
FReplicationHosts.Free;
if(FUserReplicationHosts=nil)then
if(FileExists(FUserReplicationHostsFilename))then
begin
PUserHosts:=myx_read_repl_user_hosts(FUserReplicationHostsFilename, @error);
if(PUserHosts<>nil)then
begin
try
FUserReplicationHosts:=TMYX_USER_REPL_HOSTS.Create(PUserHosts);
finally
if(PUserHosts<>nil)then
myx_free_repl_user_hosts(PUserHosts);
end;
end
else
FUserReplicationHosts:=TMYX_USER_REPL_HOSTS.Create;
end
else
begin
FUserReplicationHosts:=TMYX_USER_REPL_HOSTS.Create;
end;
if(FUserReplicationHosts<>nil)then
begin
PReplHosts:=myx_show_repl_hosts_status(MySQLConn.MySQL,
FUserReplicationHosts.get_record_pointer, @error);
if(error<>MYX_ADMIN_NO_ERROR)then
raise EMyxSQLError.Create(_('Error while fetching the replication information.'),
myx_mysql_errno(MySQLConn.MySQL),
myx_mysql_error(MySQLConn.MySQL));
if(PReplHosts<>nil)then
begin
try
FReplicationHosts:=TMYX_REPL_HOSTS.create(PReplHosts);
for I:=0 to FReplicationHosts.hosts.Count-1 do
begin
ListItem:=AddListViewItem(ServerInformationListView, nil,
FReplicationHosts.hosts[I].host,
Ord(FReplicationHosts.hosts[I].status),
FReplicationHosts.hosts[I]);
if(FReplicationHosts.hosts[I].server_id<>0)then
ListItem.SubItems.Add(IntToStr(FReplicationHosts.hosts[I].server_id))
else
ListItem.SubItems.Add('');
if(FReplicationHosts.hosts[I].port<>0)then
ListItem.SubItems.Add(IntToStr(FReplicationHosts.hosts[I].port))
else
ListItem.SubItems.Add('');
if(FReplicationHosts.hosts[I].is_master=1)then
ListItem.SubItems.Add('MASTER')
else
ListItem.SubItems.Add('SLAVE');
case FReplicationHosts.hosts[I].status of
MYX_RHS_AVAILABLE:
ListItem.SubItems.Add(_('Available'));
MYX_RHS_NEW_HOST:
ListItem.SubItems.Add(_('New Instance'));
else
ListItem.SubItems.Add(_('Not Available'));
end;
if(FReplicationHosts.hosts[I].is_master=1)then
begin
ListItem.SubItems.Add(FReplicationHosts.hosts[I].binlog_file);
ListItem.SubItems.Add(FReplicationHosts.hosts[I].binlog_pos);
end;
end;
finally
myx_free_repl_hosts_status(PReplHosts);
end;
end;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.ConnectionLost(var Message: TMessage);
begin
DisableEnablePages(ReplicationPageControl, False);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.ConnectionEstablished(var Message: TMessage);
begin
DisableEnablePages(ReplicationPageControl, True);
RefreshHostList;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.CheckUserReplHostBtns;
begin
AddInstanceToMonitoringListBtn.Enabled:=False;
RemoveInstancefromMonitoringListBtn.Enabled:=False;
if(ServerInformationListView.Selected<>nil)then
if(ServerInformationListView.Selected.Data<>nil)then
begin
if(TMYX_REPL_HOST(ServerInformationListView.Selected.Data).status=MYX_RHS_NEW_HOST)then
AddInstanceToMonitoringListBtn.Enabled:=True
else
RemoveInstancefromMonitoringListBtn.Enabled:=True;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.ServerInformationListViewSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
begin
CheckUserReplHostBtns;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.AddInstanceToMonitoringListBtnClick(Sender: TObject);
var
UserReplHost: TMYX_USER_REPL_HOST;
ReplHost: TMYX_REPL_HOST;
begin
if(ServerInformationListView.Selected<>nil)then
if(ServerInformationListView.Selected.Data<>nil)then
begin
ReplHost:=TMYX_REPL_HOST(ServerInformationListView.Selected.Data);
UserReplHost:=TMYX_USER_REPL_HOST.create(ReplHost.host);
FUserReplicationHosts.hosts.Add(UserReplHost);
ReplHost.status:=MYX_RHS_AVAILABLE;
ServerInformationListView.Selected.ImageIndex:=Ord(ReplHost.status);
CheckUserReplHostBtns;
if(FUserReplicationHosts<>nil)then
myx_save_repl_user_hosts(FUserReplicationHosts.get_record_pointer,
FUserReplicationHostsFilename);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.RemoveInstancefromMonitoringListBtnClick(Sender: TObject);
var
I: integer;
ReplHost: TMYX_REPL_HOST;
begin
if(ServerInformationListView.Selected<>nil)then
if(ServerInformationListView.Selected.Data<>nil)then
begin
ReplHost:=TMYX_REPL_HOST(ServerInformationListView.Selected.Data);
for I:=0 to FUserReplicationHosts.hosts.Count-1 do
if(CompareText(FUserReplicationHosts.hosts[I].name, ReplHost.host)=0)then
begin
FUserReplicationHosts.hosts.Delete(I);
ReplHost.status:=MYX_RHS_NEW_HOST;
ServerInformationListView.Selected.ImageIndex:=Ord(ReplHost.status);
break;
end;
CheckUserReplHostBtns;
if(FUserReplicationHosts<>nil)then
myx_save_repl_user_hosts(FUserReplicationHosts.get_record_pointer,
FUserReplicationHostsFilename);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminReplicationForm.RefreshBtnClick(Sender: TObject);
begin
RefreshHostList;
CheckUserReplHostBtns;
end;
//----------------------------------------------------------------------------------------------------------------------
end.
|