Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1090 from luisyonaldo/fix-audit-recovery-cluster-…
Browse files Browse the repository at this point in the history
…alias

search recoveries by cluster alias
  • Loading branch information
shlomi-noach authored Apr 5, 2020
2 parents 6db91c7 + 755ea47 commit ed8895e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
11 changes: 5 additions & 6 deletions go/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3196,14 +3196,12 @@ func (this *HttpAPI) AuditFailureDetection(params martini.Params, r render.Rende

if detectionId, derr := strconv.ParseInt(params["id"], 10, 0); derr == nil && detectionId > 0 {
audits, err = logic.ReadFailureDetection(detectionId)
} else if clusterAlias := params["clusterAlias"]; clusterAlias != "" {
audits, err = logic.ReadFailureDetectionsForClusterAlias(clusterAlias)
} else {
page, derr := strconv.Atoi(params["page"])
if derr != nil || page < 0 {
page = 0
}
audits, err = logic.ReadRecentFailureDetections(page)
audits, err = logic.ReadRecentFailureDetections(params["clusterAlias"], page)
}

if err != nil {
Expand Down Expand Up @@ -3248,15 +3246,14 @@ func (this *HttpAPI) AuditRecovery(params martini.Params, r render.Render, req *
audits, err = logic.ReadRecoveryByUID(recoveryUID)
} else if recoveryId, derr := strconv.ParseInt(params["id"], 10, 0); derr == nil && recoveryId > 0 {
audits, err = logic.ReadRecovery(recoveryId)
} else if clusterAlias := params["clusterAlias"]; clusterAlias != "" {
audits, err = logic.ReadRecoveriesForClusterAlias(clusterAlias)
} else {
page, derr := strconv.Atoi(params["page"])
if derr != nil || page < 0 {
page = 0
}
unacknowledgedOnly := (req.URL.Query().Get("unacknowledged") == "true")
audits, err = logic.ReadRecentRecoveries(params["clusterName"], unacknowledgedOnly, page)

audits, err = logic.ReadRecentRecoveries(params["clusterName"], params["clusterAlias"], unacknowledgedOnly, page)
}

if err != nil {
Expand Down Expand Up @@ -3746,6 +3743,7 @@ func (this *HttpAPI) RegisterRequests(m *martini.ClassicMartini) {
this.registerAPIRequest(m, "audit-failure-detection/:page", this.AuditFailureDetection)
this.registerAPIRequest(m, "audit-failure-detection/id/:id", this.AuditFailureDetection)
this.registerAPIRequest(m, "audit-failure-detection/alias/:clusterAlias", this.AuditFailureDetection)
this.registerAPIRequest(m, "audit-failure-detection/alias/:clusterAlias/:page", this.AuditFailureDetection)
this.registerAPIRequest(m, "replication-analysis-changelog", this.ReadReplicationAnalysisChangelog)
this.registerAPIRequest(m, "audit-recovery", this.AuditRecovery)
this.registerAPIRequest(m, "audit-recovery/:page", this.AuditRecovery)
Expand All @@ -3754,6 +3752,7 @@ func (this *HttpAPI) RegisterRequests(m *martini.ClassicMartini) {
this.registerAPIRequest(m, "audit-recovery/cluster/:clusterName", this.AuditRecovery)
this.registerAPIRequest(m, "audit-recovery/cluster/:clusterName/:page", this.AuditRecovery)
this.registerAPIRequest(m, "audit-recovery/alias/:clusterAlias", this.AuditRecovery)
this.registerAPIRequest(m, "audit-recovery/alias/:clusterAlias/:page", this.AuditRecovery)
this.registerAPIRequest(m, "audit-recovery-steps/:uid", this.AuditRecoverySteps)
this.registerAPIRequest(m, "active-cluster-recovery/:clusterName", this.ActiveClusterRecovery)
this.registerAPIRequest(m, "recently-active-cluster-recovery/:clusterName", this.RecentlyActiveClusterRecovery)
Expand Down
2 changes: 2 additions & 0 deletions go/http/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,12 @@ func (this *HttpWeb) RegisterRequests(m *martini.ClassicMartini) {
this.registerWebRequest(m, "audit-recovery/cluster/:clusterName", this.AuditRecovery)
this.registerWebRequest(m, "audit-recovery/cluster/:clusterName/:page", this.AuditRecovery)
this.registerWebRequest(m, "audit-recovery/alias/:clusterAlias", this.AuditRecovery)
this.registerWebRequest(m, "audit-recovery/alias/:clusterAlias/:page", this.AuditRecovery)
this.registerWebRequest(m, "audit-failure-detection", this.AuditFailureDetection)
this.registerWebRequest(m, "audit-failure-detection/:page", this.AuditFailureDetection)
this.registerWebRequest(m, "audit-failure-detection/id/:id", this.AuditFailureDetection)
this.registerWebRequest(m, "audit-failure-detection/alias/:clusterAlias", this.AuditFailureDetection)
this.registerWebRequest(m, "audit-failure-detection/alias/:clusterAlias/:page", this.AuditFailureDetection)
this.registerWebRequest(m, "audit-recovery-steps/:uid", this.AuditRecovery)
this.registerWebRequest(m, "agents", this.Agents)
this.registerWebRequest(m, "agent/:host", this.Agent)
Expand Down
30 changes: 13 additions & 17 deletions go/logic/topology_recovery_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,6 @@ func ReadRecentlyActiveClusterRecovery(clusterName string) ([]TopologyRecovery,
return readRecoveries(whereClause, ``, sqlutils.Args(clusterName))
}

// ReadRecoveriesForClusterAlias reads open/closed recoveries by alias
func ReadRecoveriesForClusterAlias(clusteAlias string) ([]TopologyRecovery, error) {
whereClause := `
where
cluster_alias=?`
return readRecoveries(whereClause, ``, sqlutils.Args(clusteAlias))
}

// ReadInActivePeriodSuccessorInstanceRecovery reads completed recoveries for a given instance, where said instance
// was promoted as result, still in active period (may be used to block further recoveries should this instance die)
func ReadInActivePeriodSuccessorInstanceRecovery(instanceKey *inst.InstanceKey) ([]TopologyRecovery, error) {
Expand Down Expand Up @@ -673,7 +665,7 @@ func ReadRecoveryByUID(recoveryUID string) ([]TopologyRecovery, error) {
}

// ReadCRecoveries reads latest recovery entries from topology_recovery
func ReadRecentRecoveries(clusterName string, unacknowledgedOnly bool, page int) ([]TopologyRecovery, error) {
func ReadRecentRecoveries(clusterName string, clusterAlias string, unacknowledgedOnly bool, page int) ([]TopologyRecovery, error) {
whereConditions := []string{}
whereClause := ""
args := sqlutils.Args()
Expand All @@ -683,6 +675,9 @@ func ReadRecentRecoveries(clusterName string, unacknowledgedOnly bool, page int)
if clusterName != "" {
whereConditions = append(whereConditions, `cluster_name=?`)
args = append(args, clusterName)
} else if clusterAlias != "" {
whereConditions = append(whereConditions, `cluster_alias=?`)
args = append(args, clusterAlias)
}
if len(whereConditions) > 0 {
whereClause = fmt.Sprintf("where %s", strings.Join(whereConditions, " and "))
Expand Down Expand Up @@ -750,11 +745,18 @@ func readFailureDetections(whereCondition string, limit string, args []interface
}

// ReadRecentFailureDetections
func ReadRecentFailureDetections(page int) ([]TopologyRecovery, error) {
func ReadRecentFailureDetections(clusterAlias string, page int) ([]TopologyRecovery, error) {
whereClause := ""
args := sqlutils.Args()
if clusterAlias != "" {
whereClause = `where cluster_alias = ?`
args = append(args, clusterAlias)
}
limit := `
limit ?
offset ?`
return readFailureDetections(``, limit, sqlutils.Args(config.AuditPageSize, page*config.AuditPageSize))
args = append(args, config.AuditPageSize, page*config.AuditPageSize)
return readFailureDetections(whereClause, limit, args)
}

// ReadFailureDetection
Expand All @@ -763,12 +765,6 @@ func ReadFailureDetection(detectionId int64) ([]TopologyRecovery, error) {
return readFailureDetections(whereClause, ``, sqlutils.Args(detectionId))
}

// ReadFailureDetectionsForClusterAlias
func ReadFailureDetectionsForClusterAlias(clusterAlias string) ([]TopologyRecovery, error) {
whereClause := `where cluster_alias = ?`
return readFailureDetections(whereClause, ``, sqlutils.Args(clusterAlias))
}

// ReadBlockedRecoveries reads blocked recovery entries, potentially filtered by cluster name (empty to unfilter)
func ReadBlockedRecoveries(clusterName string) ([]BlockedTopologyRecovery, error) {
res := []BlockedTopologyRecovery{}
Expand Down
19 changes: 11 additions & 8 deletions resources/public/js/audit-failure-detection.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
$(document).ready(function() {
showLoader();
var uri = "/api/audit-failure-detection/" + currentPage();
var apiUri = "/api/audit-failure-detection/" + currentPage();
if (clusterAlias() != "") {
uri = "/api/audit-failure-detection/alias/" + clusterAlias();
apiUri = "/api/audit-failure-detection/alias/" + clusterAlias() + "/" + currentPage();
} else if (detectionId() > 0) {
apiUri = "/api/audit-failure-detection/id/" + detectionId();
}
if (detectionId() > 0) {
uri = "/api/audit-failure-detection/id/" + detectionId();
}
$.get(appUrl(uri), function(auditEntries) {
$.get(appUrl(apiUri), function(auditEntries) {
auditEntries = auditEntries || [];
$.get(appUrl("/api/replication-analysis-changelog"), function(analysisChangelog) {
analysisChangelog = analysisChangelog || [];
Expand All @@ -16,6 +15,10 @@ $(document).ready(function() {
}, "json");

function displayAudit(auditEntries, analysisChangelog) {
var baseWebUri = appUrl("/web/audit-failure-detection/");
if (clusterAlias()) {
baseWebUri += "alias/" + clusterAlias() + "/";
}
var changelogMap = {}
analysisChangelog.forEach(function(changelogEntry) {
changelogMap[getInstanceId(changelogEntry.AnalyzedInstanceKey.Hostname, changelogEntry.AnalyzedInstanceKey.Port)] = changelogEntry.Changelog;
Expand Down Expand Up @@ -93,10 +96,10 @@ $(document).ready(function() {
$("#audit .pager .next").addClass("disabled");
}
$("#audit .pager .previous").not(".disabled").find("a").click(function() {
window.location.href = appUrl("/web/audit-failure-detection/" + (currentPage() - 1));
window.location.href = appUrl(baseWebUri + (currentPage() - 1));
});
$("#audit .pager .next").not(".disabled").find("a").click(function() {
window.location.href = appUrl("/web/audit-failure-detection/" + (currentPage() + 1));
window.location.href = appUrl(baseWebUri + (currentPage() + 1));
});
$("#audit .pager .disabled a").click(function() {
return false;
Expand Down
18 changes: 10 additions & 8 deletions resources/public/js/audit-recovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ $(document).ready(function() {
$("#audit_recovery_steps").hide();
showLoader();
var apiUri = "/api/audit-recovery/" + currentPage();
if (auditCluster()) {
apiUri = "/api/audit-recovery/cluster/" + auditCluster() + "/" + currentPage();
}
if (recoveryId() > 0) {
if (clusterName()) {
apiUri = "/api/audit-recovery/cluster/" + clusterName() + "/" + currentPage();
} else if (clusterAlias()) {
apiUri = "/api/audit-recovery/alias/" + clusterAlias() + "/" + currentPage();;
} else if (recoveryId() > 0) {
apiUri = "/api/audit-recovery/id/" + recoveryId();
}
if (recoveryUid() != "") {
} else if (recoveryUid()) {
apiUri = "/api/audit-recovery/uid/" + recoveryUid();
}
$.get(appUrl(apiUri), function(auditEntries) {
Expand Down Expand Up @@ -114,8 +114,10 @@ $(document).ready(function() {

function displayAudit(auditEntries) {
var baseWebUri = appUrl("/web/audit-recovery/");
if (auditCluster()) {
baseWebUri += "cluster/" + auditCluster() + "/";
if (clusterName()) {
baseWebUri += "cluster/" + clusterName() + "/";
} else if (clusterAlias()) {
baseWebUri += "alias/" + clusterAlias() + "/";
}
var singleRecoveryAudit = (auditEntries.length == 1);

Expand Down
6 changes: 5 additions & 1 deletion resources/templates/audit_recovery.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@
return parseInt("{{.page}}");
}

function auditCluster() {
function clusterName() {
return "{{.clusterName}}";
}

function clusterAlias() {
return "{{.clusterAlias}}";
}

function recoveryId() {
return "{{.recoveryId}}";
}
Expand Down

0 comments on commit ed8895e

Please sign in to comment.