diff --git a/pgadmin/dlg/dlgResourceGroup.cpp b/pgadmin/dlg/dlgResourceGroup.cpp new file mode 100644 index 0000000..46d5fdf --- /dev/null +++ b/pgadmin/dlg/dlgResourceGroup.cpp @@ -0,0 +1,141 @@ +////////////////////////////////////////////////////////////////////////// +// +// pgAdmin III - PostgreSQL Tools +// +// Copyright (C) 2002 - 2014, The pgAdmin Development Team +// This software is released under the PostgreSQL Licence +// +// dlgResourceGroup.cpp - Resource Group Property +// +////////////////////////////////////////////////////////////////////////// + +#include "pgAdmin3.h" + +// wxWindows headers +#include + +// App headers +#include "dlg/dlgResourceGroup.h" +#include "schema/pgResourceGroup.h" + + +// pointer to controls +#define txtResGrpName CTRL_TEXT("txtResGrpName") +#define txtCPURate CTRL_TEXT("txtCPURate") +#define txtDirtyRate CTRL_TEXT("txtDirtyRate") + +dlgProperty *pgResourceGroupFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent) +{ + return new dlgResourceGroup(this, frame, (pgResourceGroup *)node); +} + + +BEGIN_EVENT_TABLE(dlgResourceGroup, dlgProperty) + EVT_TEXT(XRCID("txtCPURate"), dlgResourceGroup::OnChange) + EVT_TEXT(XRCID("txtDirtyRate"), dlgResourceGroup::OnChange) + EVT_BUTTON(wxID_OK, dlgResourceGroup::OnOK) +END_EVENT_TABLE(); + +dlgResourceGroup::dlgResourceGroup(pgaFactory *f, frmMain *frame, pgResourceGroup *node) + : dlgProperty(f, frame, wxT("dlgResourceGroup")) +{ + resourceGroup = node; +} + +pgObject *dlgResourceGroup::GetObject() +{ + return resourceGroup; +} + +int dlgResourceGroup::Go(bool modal) +{ + txtCPURate->SetValidator(numericValidator); + txtDirtyRate->SetValidator(numericValidator); + + if (resourceGroup) + { + wxString sql = wxT("SELECT rgrpcpuratelimit, rgrpdirtyratelimit from edb_resource_group WHERE rgrpname = '") + + resourceGroup->GetName() + wxT("'"); + + pgSet *set = connection->ExecuteSet(sql); + if (set && set->NumRows() > 0) + { + txtCPURate->SetValue(set->GetVal(0)); + txtDirtyRate->SetValue(set->GetVal(1)); + delete set; + } + } + else + { + txtCPURate->SetValue(wxT("0")); + txtDirtyRate->SetValue(wxT("0")); + } + + return dlgProperty::Go(modal); +} + +void dlgResourceGroup::OnChange(wxCommandEvent &event) +{ + CheckChange(); +} + +void dlgResourceGroup::CheckChange() +{ + if (resourceGroup) + { + EnableOK(!GetSql().IsEmpty()); + } + else + { + wxString name = GetName(); + wxString cpuRate = txtCPURate->GetValue(); + wxString dirtyRate = txtDirtyRate->GetValue(); + + bool enable = true; + CheckValid(enable, !name.IsEmpty(), _("Please specify name.")); + CheckValid(enable, !cpuRate.IsEmpty(), _("Please specify CPU rate limit.")); + CheckValid(enable, !dirtyRate.IsEmpty(), _("Please specify Dirty rate limit.")); + + EnableOK(enable); + } +} + +pgObject *dlgResourceGroup::CreateObject(pgCollection *collection) +{ + wxString name = GetName(); + + pgObject *obj = resourceGroupFactory.CreateObjects(collection, 0, wxT("\n WHERE rgrpname= ") + qtDbString(name)); + return obj; +} + +wxString dlgResourceGroup::GetSql() +{ + wxString sql; + wxString name = GetName(); + wxString cpuRate = txtCPURate->GetValue(); + wxString dirtyRate = txtDirtyRate->GetValue(); + + if (resourceGroup) + { + // Edit Mode + AppendNameChange(sql, wxT("RESOURCE GROUP ") + resourceGroup->GetQuotedFullIdentifier()); + + sql += wxT("ALTER RESOURCE GROUP ") + qtIdent(name) + wxT(" SET cpu_rate_limit = ") + + cpuRate + wxT(", dirty_rate_limit = ") + dirtyRate + wxT(";\n"); + } + else + { + // Create Mode + wxString name = GetName(); + + sql = wxT("CREATE RESOURCE GROUP ") + qtIdent(name) + wxT(";\n"); + sql += wxT("ALTER RESOURCE GROUP ") + qtIdent(name) + wxT(" SET cpu_rate_limit = ") + + cpuRate + wxT(", dirty_rate_limit = ") + dirtyRate + wxT(";\n"); + } + return sql; +} + +void dlgResourceGroup::OnOK(wxCommandEvent &ev) +{ + dlgProperty::OnOK(ev); +} diff --git a/pgadmin/dlg/module.mk b/pgadmin/dlg/module.mk index 70d83f5..bece179 100644 --- a/pgadmin/dlg/module.mk +++ b/pgadmin/dlg/module.mk @@ -63,7 +63,8 @@ pgadmin3_SOURCES += \ dlg/dlgView.cpp \ dlg/dlgManageMacros.cpp \ dlg/dlgExtTable.cpp \ - dlg/dlgSelectDatabase.cpp + dlg/dlgSelectDatabase.cpp \ + dlg/dlgResourceGroup.cpp EXTRA_DIST += \ dlg/module.mk diff --git a/pgadmin/frm/frmOptions.cpp b/pgadmin/frm/frmOptions.cpp index b599f4f..e500998 100644 --- a/pgadmin/frm/frmOptions.cpp +++ b/pgadmin/frm/frmOptions.cpp @@ -383,6 +383,7 @@ frmOptions::frmOptions(frmMain *parent) lstDisplay->Append(_("Groups/group Roles")); lstDisplay->Append(_("Users/login Roles")); lstDisplay->Append(_("Resource Queues")); + lstDisplay->Append(_("Resource Groups")); lstDisplay->Append(_("Catalogs")); lstDisplay->Append(_("Casts")); lstDisplay->Append(_("Event Triggers")); diff --git a/pgadmin/include/dlg/dlgResourceGroup.h b/pgadmin/include/dlg/dlgResourceGroup.h new file mode 100644 index 0000000..e8e2260 --- /dev/null +++ b/pgadmin/include/dlg/dlgResourceGroup.h @@ -0,0 +1,44 @@ +////////////////////////////////////////////////////////////////////////// +// +// pgAdmin III - PostgreSQL Tools +// +// Copyright (C) 2002 - 2014, The pgAdmin Development Team +// This software is released under the PostgreSQL Licence +// +// dlgResourceGroup.h - Resource Group property +// +////////////////////////////////////////////////////////////////////////// + +#ifndef __DLG_RESOURCEGROUPPROP +#define __DLG_RESOURCEGROUPPROP + +#include "dlg/dlgProperty.h" + +class pgResourceGroup; + +class dlgResourceGroup : public dlgProperty +{ +public: + dlgResourceGroup(pgaFactory *factory, frmMain *frame, pgResourceGroup *node = 0); + wxString GetSql(); + pgObject *CreateObject(pgCollection *collection); + pgObject *GetObject(); + + void CheckChange(); + int Go(bool modal); + + bool WannaSplitQueries() + { + return true; + } + +private: + void OnChange(wxCommandEvent &event); + void OnOK(wxCommandEvent &ev); + +private: + pgResourceGroup *resourceGroup; + DECLARE_EVENT_TABLE() +}; + +#endif diff --git a/pgadmin/include/dlg/module.mk b/pgadmin/include/dlg/module.mk index 11d21f4..64f382c 100644 --- a/pgadmin/include/dlg/module.mk +++ b/pgadmin/include/dlg/module.mk @@ -63,7 +63,8 @@ pgadmin3_SOURCES += \ include/dlg/dlgView.h \ include/dlg/dlgManageMacros.h \ include/dlg/dlgExtTable.h \ - include/dlg/dlgSelectDatabase.h + include/dlg/dlgSelectDatabase.h \ + include/dlg/dlgResourceGroup.h EXTRA_DIST += \ include/dlg/module.mk diff --git a/pgadmin/include/schema/module.mk b/pgadmin/include/schema/module.mk index d56b4d2..5ecd23f 100644 --- a/pgadmin/include/schema/module.mk +++ b/pgadmin/include/schema/module.mk @@ -60,7 +60,8 @@ pgadmin3_SOURCES += \ include/schema/pgView.h \ include/schema/gpExtTable.h \ include/schema/gpResQueue.h \ - include/schema/gpPartition.h + include/schema/gpPartition.h \ + include/schema/pgResourceGroup.h EXTRA_DIST += \ include/schema/module.mk diff --git a/pgadmin/include/schema/pgResourceGroup.h b/pgadmin/include/schema/pgResourceGroup.h new file mode 100644 index 0000000..6869ca8 --- /dev/null +++ b/pgadmin/include/schema/pgResourceGroup.h @@ -0,0 +1,71 @@ +////////////////////////////////////////////////////////////////////////// +// +// pgAdmin III - PostgreSQL Tools +// +// Copyright (C) 2002 - 2014, The pgAdmin Development Team +// This software is released under the PostgreSQL Licence +// +// pgResourceGroup.h - Resource Group (only used for PPAS 9.4) +// +////////////////////////////////////////////////////////////////////////// + +#ifndef PGRESOURCEGROUP_H +#define PGRESOURCEGROUP_H + +#include "pgServer.h" + +class pgResourceGroupFactory : public pgServerObjFactory +{ +public: + pgResourceGroupFactory(); + virtual dlgProperty *CreateDialog(frmMain *frame, pgObject *node, pgObject *parent); + virtual pgObject *CreateObjects(pgCollection *obj, ctlTree *browser, const wxString &restr = wxEmptyString); + virtual pgCollection *CreateCollection(pgObject *obj); +}; + +extern pgResourceGroupFactory resourceGroupFactory; + + +// Class declarations +class pgResourceGroup : public pgServerObject +{ +public: + pgResourceGroup(const wxString &newName = wxT("")); + ~pgResourceGroup(); + wxString GetTranslatedMessage(int kindOfMessage) const; + + void ShowTreeDetail(ctlTree *browser, frmMain *form = 0, ctlListView *properties = 0, ctlSQLBox *sqlPane = 0); + + bool DropObject(wxFrame *frame, ctlTree *browser, bool cascaded); + wxString GetSql(ctlTree *browser); + pgObject *Refresh(ctlTree *browser, const wxTreeItemId item); + + double GetCPURateLimit() const + { + return cpuRateLimit; + } + void iSetCPURateLimit(const double b) + { + cpuRateLimit = b; + } + double GetDirtyRateLimit() const + { + return dirtyRateLimit; + } + void iSetDirtyRateLimit(const double b) + { + dirtyRateLimit = b; + } + +private: + double cpuRateLimit, dirtyRateLimit; +}; + +class pgResourceGroupCollection : public pgServerObjCollection +{ +public: + pgResourceGroupCollection(pgaFactory *factory, pgServer *sv); + wxString GetTranslatedMessage(int kindOfMessage) const; +}; + +#endif diff --git a/pgadmin/pgAdmin3.vcxproj b/pgadmin/pgAdmin3.vcxproj index 7951628..6fdfd8e 100644 --- a/pgadmin/pgAdmin3.vcxproj +++ b/pgadmin/pgAdmin3.vcxproj @@ -850,6 +850,7 @@ + @@ -2206,6 +2207,7 @@ + @@ -2696,6 +2698,7 @@ + @@ -2774,6 +2777,7 @@ + @@ -2794,6 +2798,7 @@ + @@ -3540,4 +3545,4 @@ - + \ No newline at end of file diff --git a/pgadmin/pgAdmin3.vcxproj.filters b/pgadmin/pgAdmin3.vcxproj.filters index 1f6f1f6..906a1cd 100644 --- a/pgadmin/pgAdmin3.vcxproj.filters +++ b/pgadmin/pgAdmin3.vcxproj.filters @@ -1677,6 +1677,12 @@ utils + + schema + + + dlg + @@ -2196,6 +2202,9 @@ libssh2 + + ui + @@ -3555,6 +3564,12 @@ include\utils + + include\schema + + + include\dlg + @@ -4455,4 +4470,4 @@ - + \ No newline at end of file diff --git a/pgadmin/schema/module.mk b/pgadmin/schema/module.mk index 87786b3..8bfca32 100644 --- a/pgadmin/schema/module.mk +++ b/pgadmin/schema/module.mk @@ -60,7 +60,8 @@ pgadmin3_SOURCES += \ schema/pgView.cpp \ schema/gpExtTable.cpp \ schema/gpResQueue.cpp \ - schema/gpPartition.cpp + schema/gpPartition.cpp \ + schema/pgResourceGroup.cpp EXTRA_DIST += \ schema/module.mk diff --git a/pgadmin/schema/pgResourceGroup.cpp b/pgadmin/schema/pgResourceGroup.cpp new file mode 100644 index 0000000..42cf0ae --- /dev/null +++ b/pgadmin/schema/pgResourceGroup.cpp @@ -0,0 +1,202 @@ +////////////////////////////////////////////////////////////////////////// +// +// pgAdmin III - PostgreSQL Tools +// +// Copyright (C) 2002 - 2014, The pgAdmin Development Team +// This software is released under the PostgreSQL Licence +// +// pgResourceGroup.cpp - Resource Group (only used for PPAS 9.4) +// +////////////////////////////////////////////////////////////////////////// + +// wxWindows headers +#include + +// App headers +#include "pgAdmin3.h" +#include "utils/misc.h" +#include "schema/pgResourceGroup.h" + +#include "images/group.pngc" +#include "images/groups.pngc" + +pgResourceGroup::pgResourceGroup(const wxString &newName) + : pgServerObject(resourceGroupFactory, newName), cpuRateLimit(0), dirtyRateLimit(0) +{ +} + +pgResourceGroup::~pgResourceGroup() +{ +} + +wxString pgResourceGroup::GetTranslatedMessage(int kindOfMessage) const +{ + wxString message = wxEmptyString; + + switch (kindOfMessage) + { + case RETRIEVINGDETAILS: + message = _("Retrieving details on resource group"); + message += wxT(" ") + GetName(); + break; + case REFRESHINGDETAILS: + message = _("Refreshing resouce group"); + message += wxT(" ") + GetName(); + break; + case DROPINCLUDINGDEPS: + message = wxString::Format(_("Are you sure you wish to drop resource group \"%s\" including all objects that depend on it?"), + GetFullIdentifier().c_str()); + break; + case DROPEXCLUDINGDEPS: + message = wxString::Format(_("Are you sure you wish to drop resource group \"%s\"?"), + GetFullIdentifier().c_str()); + break; + case DROPCASCADETITLE: + message = _("Drop resource group cascaded?"); + break; + case DROPTITLE: + message = _("Drop resource group?"); + break; + case PROPERTIESREPORT: + message = _("Resource group properties report"); + message += wxT(" - ") + GetName(); + break; + case PROPERTIES: + message = _("Resource group properties"); + break; + case DDLREPORT: + message = _("Resource group DDL report"); + message += wxT(" - ") + GetName(); + break; + case DDL: + message = _("Resource group DDL"); + break; + case DEPENDENCIESREPORT: + message = _("Resource group dependencies report"); + message += wxT(" - ") + GetName(); + break; + case DEPENDENCIES: + message = _("Resource group dependencies"); + break; + case DEPENDENTSREPORT: + message = _("Resource group dependents report"); + message += wxT(" - ") + GetName(); + break; + case DEPENDENTS: + message = _("Resource group dependents"); + break; + } + + return message; +} + +bool pgResourceGroup::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded) +{ + return server->ExecuteVoid(wxT("DROP RESOURCE GROUP ") + GetQuotedFullIdentifier()); +} + +wxString pgResourceGroup::GetSql(ctlTree *browser) +{ + if (sql.IsNull()) + { + sql = wxT("-- RESOURCE GROUP: ") + GetName() + wxT("\n\n") + + wxT("-- DROP RESOURCE GROUP ") + GetQuotedFullIdentifier() + wxT(";") + + wxT("\n\nCREATE RESOURCE GROUP ") + GetQuotedIdentifier() + wxT(";"); + } + + return sql; +} + +void pgResourceGroup::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane) +{ + if (properties) + { + CreateListColumns(properties); + properties->AppendItem(_("Name"), GetName()); + properties->AppendItem(_("CPU Rate Limit"), GetCPURateLimit()); + properties->AppendItem(_("Dirty Rate Limit"), GetDirtyRateLimit()); + } +} + +pgObject *pgResourceGroup::Refresh(ctlTree *browser, const wxTreeItemId item) +{ + pgObject *group = 0; + pgCollection *coll = browser->GetParentCollection(item); + if (coll) + group = resourceGroupFactory.CreateObjects(coll, 0, wxT("\n WHERE oid=") + GetOidStr()); + + return group; +} + + +pgResourceGroupFactory::pgResourceGroupFactory() + : pgServerObjFactory(__("Resource Group"), __("New Resource Group..."), __("Create a new Resource Group."), group_png_img) +{ +} + +pgObject *pgResourceGroupFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction) +{ + pgResourceGroup *resGroup = 0; + double cpuLimit, dirtyLimit; + + pgSet *groups = collection->GetServer()->ExecuteSet(wxT("SELECT oid, * from edb_resource_group") + restriction); + + if (groups) + { + while (!groups->Eof()) + { + resGroup = new pgResourceGroup(groups->GetVal(wxT("rgrpname"))); + resGroup->iSetServer(collection->GetServer()); + resGroup->iSetOid(groups->GetOid(wxT("oid"))); + groups->GetVal(wxT("rgrpcpuratelimit")).ToDouble(&cpuLimit); + resGroup->iSetCPURateLimit(cpuLimit); + groups->GetVal(wxT("rgrpdirtyratelimit")).ToDouble(&dirtyLimit); + resGroup->iSetDirtyRateLimit(dirtyLimit); + + if (browser) + { + browser->AppendObject(collection, resGroup); + groups->MoveNext(); + } + else + break; + } + + delete groups; + } + return resGroup; +} + +pgCollection *pgResourceGroupFactory::CreateCollection(pgObject *obj) +{ + return new pgResourceGroupCollection(GetCollectionFactory(), (pgServer *)obj); +} + +pgResourceGroupFactory resourceGroupFactory; +static pgaCollectionFactory rgcf(&resourceGroupFactory, __("Resource Groups"), groups_png_img); + +pgResourceGroupCollection::pgResourceGroupCollection(pgaFactory *factory, pgServer *sv) + : pgServerObjCollection(factory, sv) +{ +} + +wxString pgResourceGroupCollection::GetTranslatedMessage(int kindOfMessage) const +{ + wxString message = wxEmptyString; + + switch (kindOfMessage) + { + case RETRIEVINGDETAILS: + message = _("Retrieving details on resource groups"); + break; + case REFRESHINGDETAILS: + message = _("Refreshing resource groups"); + break; + case OBJECTSLISTREPORT: + message = _("Resource groups list report"); + break; + } + + return message; +} + diff --git a/pgadmin/schema/pgServer.cpp b/pgadmin/schema/pgServer.cpp index 310efe3..a489b19 100644 --- a/pgadmin/schema/pgServer.cpp +++ b/pgadmin/schema/pgServer.cpp @@ -37,6 +37,7 @@ #include "utils/registry.h" #include "frm/frmReport.h" #include "dlg/dlgServer.h" +#include "schema/pgResourceGroup.h" #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT) #include "utils/sshTunnel.h" @@ -198,6 +199,12 @@ wxMenu *pgServer::GetNewMenu() if (settings->GetDisplayOption(_("Users/login Roles"))) userFactory.AppendMenu(menu); } + // Added Resource Group only for PPAS 9.4 and above + if (conn->GetIsEdb() && conn->EdbMinimumVersion(9, 4)) + { + if (settings->GetDisplayOption(_("Resource Groups"))) + resourceGroupFactory.AppendMenu(menu); + } } return menu; } @@ -1095,6 +1102,13 @@ void pgServer::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *prop browser->AppendCollection(this, userFactory); } + // Added Resource Group only for PPAS 9.4 and above + if (conn->GetIsEdb() && conn->EdbMinimumVersion(9, 4)) + { + if (settings->GetDisplayOption(_("Resource Groups"))) + browser->AppendCollection(this, resourceGroupFactory); + } + autovacuumRunning = true; wxString qry; diff --git a/pgadmin/ui/dlgResourceGroup.xrc b/pgadmin/ui/dlgResourceGroup.xrc new file mode 100644 index 0000000..7338c22 --- /dev/null +++ b/pgadmin/ui/dlgResourceGroup.xrc @@ -0,0 +1,106 @@ + + + + + 1 + 0 + 0 + + + + + + + + + + wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + + + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + + + + + wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + + + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + + + + + wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + + + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + 2 + 15 + 5 + 1 + + + + + + 216,205d + + wxEXPAND|wxALIGN_CENTRE|wxALL + 3 + + + + 4 + 1 + + + + + wxEXPAND|wxALL + 3 + + + 0,0d + + + + + 1 + + wxEXPAND|wxALL + 3 + + + + + + wxEXPAND|wxALL + 3 + + + wxEXPAND|wxTOP|wxLEFT|wxRIGHT + + + + + + wxEXPAND|wxALIGN_CENTRE + 3 + + + 220,230d + + + \ No newline at end of file diff --git a/pgadmin/ui/module.mk b/pgadmin/ui/module.mk index 19af4ec..3760d95 100644 --- a/pgadmin/ui/module.mk +++ b/pgadmin/ui/module.mk @@ -92,7 +92,8 @@ TMP_ui += \ ui/frmOptions.xrc \ ui/frmPassword.xrc \ ui/frmReport.xrc \ - ui/frmRestore.xrc + ui/frmRestore.xrc \ + ui/dlgResourceGroup.xrc EXTRA_DIST += \ ui/module.mk \ diff --git a/pgadmin/utils/sysSettings.cpp b/pgadmin/utils/sysSettings.cpp index 0d2e5f1..decb6c4 100644 --- a/pgadmin/utils/sysSettings.cpp +++ b/pgadmin/utils/sysSettings.cpp @@ -77,6 +77,8 @@ bool sysSettings::GetDisplayOption(const wxString &objtype, bool GetDefault) engtype = wxT("Users-login Roles"); else if (objtype == _("Resource Queues")) engtype = wxT("Resource Queues"); + else if (objtype == _("Resource Groups")) + engtype = wxT("Resource Groups"); else if (objtype == _("Catalogs")) engtype = wxT("Catalogs"); else if (objtype == _("Casts")) @@ -195,6 +197,7 @@ void sysSettings::SetDisplayOption(const wxString &objtype, bool display) else if (objtype == _("Groups/group Roles")) engtype = wxT("Groups-login Roles"); else if (objtype == _("Users/login Roles")) engtype = wxT("Users-login Roles"); else if (objtype == _("Resource Queues")) engtype = wxT("Resource Queues"); + else if (objtype == _("Resource Groups")) engtype = wxT("Resource Groups"); else if (objtype == _("Catalogs")) engtype = wxT("Catalogs"); else if (objtype == _("Casts")) engtype = wxT("Casts"); else if (objtype == _("Foreign Data Wrappers")) engtype = wxT("Foreign Data Wrappers");