Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add APIs to Maintenance Mode in ILM #31410

Merged
merged 7 commits into from
Jun 21, 2018

Conversation

talevy
Copy link
Contributor

@talevy talevy commented Jun 18, 2018

  • POST _xpack/index_lifecycle/_stop

    • issues a request to be placed into STOPPED mode (maintenance mode).
      This is not immediate, since we must first verify that
      it is safe to go from STOPPING -> STOPPED.
  • POST _xpack/index_lifecycle/_start

    • issues a request to be placed back into RUNNING mode (immediately)
  • GET _xpack/index_lifecycle/_status

    • get back the current mode our lifecycle management is in
  • update task was hardened to support uninstalled metadata

  • if no metadata is installed, the start/stop actions will install metadata
    and proceed to try and change it (default start mode is RUNNING)

  • rename MAINTENANCE -> STOPPED, MAINTENANCE_REQUESTED -> STOPPING, NORMAL -> RUNNING

follow-up to #31164.

- POST _xpack/index_lifecycle/maintenance/_request
   - issues a request to be placed into maintenenance mode.
     This is not immediate, since we must first verify that
     it is safe to go from REQUESTED -> IN maintenance mode.
- POST _xpack/index_lifecycle/maintenance/_stop
   - issues a request to be taken out (this is immediate)
- GET _xpack/index_lifecycle/maintenance
   - get back the current mode our lifecycle management is in

- maintenance mode update task was hardened to support uninstalled metadata
- if no metadata is installed, the request/stop actions will install metadata
  and proceed to try and change it (default start mode is NORMAL)

follow-up to elastic#31164.
@talevy talevy added the :Data Management/ILM+SLM Index and Snapshot lifecycle management label Jun 18, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@talevy talevy requested a review from colings86 June 19, 2018 05:22
@talevy
Copy link
Contributor Author

talevy commented Jun 19, 2018

I have some setup issues, I will fix the actions setup tomorrow morning. But, please review the rest when available!

I noticed it would be a weird experience to error because the lifecycle metadata wasn't installed... so I decided that these set APIs can install it too. That feels like the more appropriate thing to do, but I can see it being desired to keep the metadata installation to put-lifecycle. let me know what you think

public class GetMaintenanceModeAction
extends Action<GetMaintenanceModeAction.Request, GetMaintenanceModeAction.Response> {
public static final GetMaintenanceModeAction INSTANCE = new GetMaintenanceModeAction();
public static final String NAME = "cluster:admin/xpack/index_lifecycle/maintenance/get";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be cluster:admin/xpack/index_lifecycle/operation_mode/get

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field("in_maintenance_mode", mode == OperationMode.MAINTENANCE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this given we have the mode below?

builder.startObject();
builder.field("in_maintenance_mode", mode == OperationMode.MAINTENANCE);
builder.field("operation_mode", mode);
return builder;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing end object?


public class SetOperationModeAction extends Action<SetOperationModeAction.Request, SetOperationModeAction.Response> {
public static final SetOperationModeAction INSTANCE = new SetOperationModeAction();
public static final String NAME = "cluster:admin/xpack/index_lifecycle/operation_mode";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be: cluster:admin/xpack/index_lifecycle/operation_mode/set

import java.io.IOException;
import java.util.Objects;

public class SetOperationModeAction extends Action<SetOperationModeAction.Request, SetOperationModeAction.Response> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should call this PutOperationModeAction

if (currentMetadata.getMaintenanceMode().isValidChange(mode)) {
newMode = mode;
} else {
newMode = currentMetadata.getMaintenanceMode();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be any cleaner? We seem to be checking things twice. Maybe we could check for a nell metadata first and then check if the change is valid?

public RestGetOperationModeAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.GET,
IndexLifecycle.BASE_PATH + "maintenance", this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the endpoint shouldn't contain maintenance otherwise its confusing what it means when this API returns mode: normal. Instead I think this should be _xapck/index_lifecycle/mode or _xapck/index_lifecycle/operation_mode

public RestRequestMaintenanceAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.POST,
IndexLifecycle.BASE_PATH + "maintenance/_request", this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to have this endpoint as PUT _xpack/index_lifeycle/operation_mode/{mode}?

public RestStopMaintenanceAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.POST,
IndexLifecycle.BASE_PATH + "maintenance/_stop", this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to have this endpoint as PUT _xpack/index_lifeycle/operation_mode/{mode}?

@clintongormley
Copy link
Contributor

Could this just be:

POST _xpack/index_lifecycle/_start
POST _xpack/index_lifecycle/_stop
GET _xpack/index_lifecycle/_status

where _status could return running, stopping, stopped?

@talevy
Copy link
Contributor Author

talevy commented Jun 19, 2018

@clintongormley yes. I believe I prefer your suggestion. I believe there were two reason we
went down the route of naming it "maintenance"

  1. it was meant to be a state which allows other cluster-level administrative operations to be done
  2. we already had a concept of "stop" by way of "stopping lifecycles per index" with index.lifecycle.skip.

If one steps away from those two points, "maintenance" is a rather ambiguous term and running, stopping, stopped are self-explanatory. We can leave "skipping" to be an index-level "stop".

@colings86, what do you think?

@talevy
Copy link
Contributor Author

talevy commented Jun 19, 2018

@colings86 I've made the changes to the new format that Clint suggested! I think we are in a better place, thanks Clint!

Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some minor comments but I think its close

import java.io.IOException;
import java.util.Objects;

public class SetOperationModeAction extends Action<SetOperationModeAction.Response> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to be consistent with the naming of the other APIs in Elasticsearch we should call this Put instead of Set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this felt weird since I am not PUTing a resty resource, especially since it is being exposed by APIs that do not necessarily ever set a specific operation-mode directly, like STOPPED.

Given all of ^, I also view this as a pedantic argument that loses in the battle of consistency 😄. So I will rename

import org.elasticsearch.xpack.core.indexlifecycle.action.GetOperationModeStatusAction;
import org.elasticsearch.xpack.indexlifecycle.IndexLifecycle;

public class RestGetOperationModeStatusAction extends BaseRestHandler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should call this API *GetStatusAction since that is the endpoint that it maps to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, another one of case of "crossed my mind, but decided against it for mediocre reasons". Will change

@talevy
Copy link
Contributor Author

talevy commented Jun 20, 2018

thanks @colings86, I've updated with the renaming and fixed the failing rest tests

Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming it passes CI

@talevy talevy merged commit 901aafb into elastic:index-lifecycle Jun 21, 2018
@talevy talevy deleted the ilm-maintenance-api branch June 21, 2018 16:56
jasontedor pushed a commit that referenced this pull request Aug 17, 2018
- POST _xpack/index_lifecycle/_stop
   - issues a request to be placed into STOPPED mode (maintenance mode).
     This is not immediate, since we must first verify that
     it is safe to go from STOPPING -> STOPPED.
- POST _xpack/index_lifecycle/_start
   - issues a request to be placed back into RUNNING mode (immediately)
- GET _xpack/index_lifecycle/_status
   - get back the current mode our lifecycle management is in

- update task was hardened to support uninstalled metadata
- if no metadata is installed, the start/stop actions will install metadata
  and proceed to try and change it (default start mode is RUNNING)
- rename MAINTENANCE -> STOPPED, MAINTENANCE_REQUESTED -> STOPPING, NORMAL -> RUNNING

follow-up to #31164.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/ILM+SLM Index and Snapshot lifecycle management
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants