Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Restart a Topology on Kubernetes #3740

Merged
merged 5 commits into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deploy/kubernetes/helm/templates/tools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ rules:
- patch
- update
- watch
- apiGroups:
- ""
resources:
- pods
verbs:
- deletecollection
- apiGroups:
- ""
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,23 @@ boolean killTopology() {
return true;
}

/**
* Restarts a topology by deleting the Pods associated with it using <code>Selector Labels</code>.
* @param shardId Not used but required because of interface.
* @return Indicator of successful submission of restart request to Kubernetes cluster.
*/
@Override
boolean restart(int shardId) {
final String message = "Restarting the whole topology is not supported yet. "
+ "Please kill and resubmit the topology.";
LOG.log(Level.SEVERE, message);
return false;
try {
coreClient.deleteCollectionNamespacedPod(getNamespace(), null, null, null, null,
0, createTopologySelectorLabels(), null, null, null, null,
null, null, null);
LOG.log(Level.WARNING, String.format("Restarting topology '%s'...", getTopologyName()));
} catch (ApiException e) {
LOG.log(Level.SEVERE, String.format("Failed to restart topology '%s'...", getTopologyName()));
return false;
}
return true;
}

@Override
Expand Down Expand Up @@ -839,4 +850,14 @@ protected V1ConfigMap getConfigMap(String configMapName) {
throw new TopologySubmissionException(String.format("%s: %s", message, e.getMessage()));
}
}

/**
* Generates the <code>Selector</code> match labels with which resources in this topology can be found.
* @return A label of the form <code>app=heron,topology=topology-name</code>.
*/
private String createTopologySelectorLabels() {
return String.format("%s=%s,%s=%s",
KubernetesConstants.LABEL_APP, KubernetesConstants.LABEL_APP_VALUE,
KubernetesConstants.LABEL_TOPOLOGY, getTopologyName());
}
}