address feedback

Original commit: elastic/x-pack-elasticsearch@7f7f2c0e1f
This commit is contained in:
jaymode 2016-11-14 10:33:47 -05:00
parent 8e0f5f905e
commit 8285fbdd46
1 changed files with 11 additions and 9 deletions

View File

@ -270,15 +270,19 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
client.admin().cluster().prepareState().execute(new ActionListener<ClusterStateResponse>() { client.admin().cluster().prepareState().execute(new ActionListener<ClusterStateResponse>() {
@Override @Override
public void onResponse(ClusterStateResponse clusterStateResponse) { public void onResponse(ClusterStateResponse clusterStateResponse) {
if (canStart(clusterStateResponse.getState(), master)) { final boolean currentMaster = clusterService.state().getNodes().isLocalNodeElectedMaster();
if (master) { if (canStart(clusterStateResponse.getState(), currentMaster)) {
if (currentMaster) {
putTemplate(customAuditIndexSettings(settings), ActionListener.wrap((v) -> innerStart(), putTemplate(customAuditIndexSettings(settings), ActionListener.wrap((v) -> innerStart(),
(e) -> state.set(State.FAILED))); (e) -> state.set(State.FAILED)));
} else { } else {
innerStart(); innerStart();
} }
} else { } else {
state.compareAndSet(State.STARTING, State.INITIALIZED); if (state.compareAndSet(State.STARTING, State.INITIALIZED) == false) {
throw new IllegalStateException("state transition from starting to initialized failed, current value: " +
state.get());
}
} }
} }
@ -287,8 +291,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
logger.error("failed to get remote cluster state", e); logger.error("failed to get remote cluster state", e);
} }
}); });
} else { } else if (master) {
if (master) {
putTemplate(customAuditIndexSettings(settings), ActionListener.wrap((v) -> innerStart(), putTemplate(customAuditIndexSettings(settings), ActionListener.wrap((v) -> innerStart(),
(e) -> state.set(State.FAILED))); (e) -> state.set(State.FAILED)));
} else { } else {
@ -296,7 +299,6 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
} }
} }
} }
}
private void innerStart() { private void innerStart() {
if (indexToRemoteCluster == false) { if (indexToRemoteCluster == false) {