Skip to content

Commit

Permalink
Update ElasticReload to comply with new API (#50)
Browse files Browse the repository at this point in the history
Add new CREATED status to list of pending statuses for elasticreload. Make reloadlog optional and add debug logging when the reload state changes.
  • Loading branch information
SeBBBe authored Jun 2, 2020
1 parent bc8b7f0 commit ffb7219
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/settingup.md
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ Reload an app by simulating selecting **Reload** in the app context menu in the
* `list`: List of apps. Used with `appmode` set to `randomnamefromlist`, `randomguidfromlist`, `roundnamefromlist` or `roundguidfromlist`.
* `filename`: Path to a file in which each line represents an app. Used with `appmode` set to `randomnamefromfile`, `randomguidfromfile`, `roundnamefromfile` or `roundguidfromfile`.
* `pollinterval`: Reload status polling interval (seconds). Defaults to 5 seconds, if omitted.
* `log`: Save the reload log as a field in the output (`true` / `false`). Defaults to `false`, if omitted. **Note:** This should only be used when needed as the reload log can become very large.

### Example

Expand Down
3 changes: 3 additions & 0 deletions generatedocs/data/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@
"elasticreload.pollinterval": [
"Reload status polling interval (seconds). Defaults to 5 seconds, if omitted."
],
"elasticreload.log": [
"Save the reload log as a field in the output (`true` / `false`). Defaults to `false`, if omitted. **Note:** This should only be used when needed as the reload log can become very large."
],
"elasticshareapp.appguid": [
"GUID of the app to share."
],
Expand Down
1 change: 1 addition & 0 deletions generatedocs/generated/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ var (
"elastichubsearch.querysource": { "","`querystring`: The query is provided as a string specified by `query`.","`fromfile`: The queries are read from the file specified by `queryfile`, where each line represents a query." },
"elastichubsearch.searchfor": { "","`collections`: Search for collections only.","`apps`: Search for apps only.","`both`: Search for both collections and apps." },
"elasticpublishapp.cleartags": { "Publish the app without its original tags." },
"elasticreload.log": { "Save the reload log as a field in the output (`true` / `false`). Defaults to `false`, if omitted. **Note:** This should only be used when needed as the reload log can become very large." },
"elasticreload.pollinterval": { "Reload status polling interval (seconds). Defaults to 5 seconds, if omitted." },
"elasticshareapp.appguid": { "GUID of the app to share." },
"elasticshareapp.groups": { "List of groups that should be given access to the app." },
Expand Down
13 changes: 11 additions & 2 deletions scenario/elasticreload.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type (
ElasticReloadCore struct {
// PollInterval time in-between polling for reload status
PollInterval helpers.TimeDuration `json:"pollinterval" displayname:"Poll interval" doc-key:"elasticreload.pollinterval"`
SaveLog bool `json:"log" displayname:"Save log" doc-key:"elasticreload.log"`
}

//ElasticReloadSettings specify app to reload
Expand All @@ -41,6 +42,7 @@ const (
)

const (
statusCreated = "CREATED"
statusQueued = "QUEUED"
statusReloading = "RELOADING"
statusSuccess = "SUCCEEDED"
Expand Down Expand Up @@ -122,10 +124,11 @@ func (settings ElasticReloadSettings) Execute(sessionState *session.State, actio
}

status := postReloadResponse.Status
var prevStatus string
log := ""
reloadTime := ""

for status == statusQueued || status == statusReloading || status == statusInterrupted {
for status == statusCreated || status == statusQueued || status == statusReloading || status == statusInterrupted {
helpers.WaitFor(sessionState.BaseContext(), time.Duration(settings.PollInterval))
if sessionState.IsAbortTriggered() {
return
Expand All @@ -147,7 +150,11 @@ func (settings ElasticReloadSettings) Execute(sessionState *session.State, actio
return
}

prevStatus = status
status = reloadStatus.Status
if status != prevStatus {
sessionState.LogEntry.LogDebugf("StatusChange: <%s> -> <%s>", prevStatus, status)
}
log = reloadStatus.Log
reloadTime = reloadStatus.Duration
}
Expand All @@ -157,6 +164,8 @@ func (settings ElasticReloadSettings) Execute(sessionState *session.State, actio
return
}

sessionState.LogEntry.LogInfo("ReloadLog", log)
if settings.ElasticReloadCore.SaveLog {
sessionState.LogEntry.LogInfo("ReloadLog", log)
}
sessionState.LogEntry.LogInfo("ReloadDuration", reloadTime)
}

0 comments on commit ffb7219

Please sign in to comment.