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

Commit

Permalink
fix #31 decomissioning for pod '0' (#61)
Browse files Browse the repository at this point in the history
* add graceful shutdown of nifi node #31

* add decomissioning when pod is stopped

* move extraContainer in statefulset def

* update README.md

* fix typo

* revert

* update termintation in statefulset

* correctly decomission node
update terminationGracePeriod

* update value.yaml

* fix decomissioning for pod '0'

Co-authored-by: Alexandre Nuttinck <[email protected]>
  • Loading branch information
stoetti and alexnuttinck authored Jun 25, 2020
1 parent bfa53bf commit f765c65
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,45 +130,46 @@ spec:
exec bin/nifi.sh run & nifi_pid="$!"

function offloadNode() {
echo executing preStop > /tmp/preStop.out
FQDN=$(hostname -f)
echo disconnecting node '$FQDN'
baseUrl=http://nifi-0.nifi-headless:8080
{{- if .Values.properties.clusterSecure }}
servicePort={{ .Values.service.httpsPort }}
{{- else }}
servicePort={{ .Values.service.httpPort }}
{{- end }}
baseUrl=http://{{ template "apache-nifi.fullname" . }}:${servicePort}
echo baseUrl ${baseUrl}
# no cluster without initial node
if [[ "$FQDN" != nifi-0.nifi-headless* ]]; then
echo "gracefully disconnecting node '$FQDN' from cluster"
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json
nnid=$(jq --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .nodeId' nodes.json)
echo "disconnecting node ${nnid}"
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi disconnect-node -nnid $nnid -u ${baseUrl}
echo ""
echo "wait until node has state 'DISCONNECTED'"
while [[ "$node_state" != "DISCONNECTED" ]]; do
sleep 1
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json
node_state=$(jq -r --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .status' nodes.json)
echo "state is '$node_state'"
done
echo ""
echo "node '${nnid}' was disconnected"
echo "offloading node"
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi offload-node -nnid $nnid -u ${baseUrl}
echo ""
echo "wait until node has state 'OFFLOADED'"
while [[ "$node_state" != "OFFLOADED" ]]; do
sleep 1
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json
node_state=$(jq -r --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .status' nodes.json)
echo "state is '$node_state'"
done
fi
echo "gracefully disconnecting node '$FQDN' from cluster"
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json
nnid=$(jq --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .nodeId' nodes.json)
echo "disconnecting node ${nnid}"
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi disconnect-node -nnid $nnid -u ${baseUrl}
echo ""
echo "wait until node has state 'DISCONNECTED'"
while [[ "$node_state" != "DISCONNECTED" ]]; do
sleep 1
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json
node_state=$(jq -r --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .status' nodes.json)
echo "state is '$node_state'"
done
echo ""
echo "node '${nnid}' was disconnected"
echo "offloading node"
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi offload-node -nnid $nnid -u ${baseUrl}
echo ""
echo "wait until node has state 'OFFLOADED'"
while [[ "$node_state" != "OFFLOADED" ]]; do
sleep 1
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json
node_state=$(jq -r --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .status' nodes.json)
echo "state is '$node_state'"
done
}

deleteNode() {
echo "deleting node"
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi delete-node -nnid ${nnid} -u ${baseUrl}
echo "node deleted"
echo "deleting node"
${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi delete-node -nnid ${nnid} -u ${baseUrl}
echo "node deleted"
}

trap 'echo Received trapped signal, beginning shutdown...;offloadNode;./bin/nifi.sh stop;deleteNode;exit 0;' TERM HUP INT;
Expand Down

0 comments on commit f765c65

Please sign in to comment.