use of org.apache.heron.scheduler.TopologyRuntimeManagementException in project heron by twitter.
the class V1Controller method setSecretKeyRefs.
/**
* Adds <code>Secret Key</code> references to a <code>container</code>.
* @param container <code>container</code> to be configured.
*/
private void setSecretKeyRefs(V1Container container) {
final Config config = getConfiguration();
final Map<String, String> podSecretKeyRefs = KubernetesContext.getPodSecretKeyRefs(config);
for (Map.Entry<String, String> secret : podSecretKeyRefs.entrySet()) {
final String[] keyRefParts = secret.getValue().split(":");
if (keyRefParts.length != 2) {
LOG.log(Level.SEVERE, "SecretKeyRef must be in the form name:key. <" + secret.getValue() + ">");
throw new TopologyRuntimeManagementException("SecretKeyRef must be in the form name:key. <" + secret.getValue() + ">");
}
String name = keyRefParts[0];
String key = keyRefParts[1];
final V1EnvVar envVar = new V1EnvVar().name(secret.getKey()).valueFrom(new V1EnvVarSource().secretKeyRef(new V1SecretKeySelector().key(key).name(name)));
container.addEnvItem(envVar);
}
}
use of org.apache.heron.scheduler.TopologyRuntimeManagementException in project heron by twitter.
the class V1Controller method deleteStatefulSets.
/**
* Deletes the StatefulSets for a <code>topology</code>'s <code>Executors</code> and <code>Manager</code>
* using <code>Label</code>s.
*/
void deleteStatefulSets() {
try (Response response = appsClient.deleteCollectionNamespacedStatefulSetCall(getNamespace(), null, null, null, null, null, createTopologySelectorLabels(), null, null, null, null, null, null, null, null).execute()) {
if (!response.isSuccessful()) {
if (response.code() == HTTP_NOT_FOUND) {
LOG.log(Level.WARNING, "Tried to delete a non-existent StatefulSets for Topology: " + getTopologyName());
return;
}
LOG.log(Level.SEVERE, "Error when deleting the StatefulSets of the job [" + getTopologyName() + "] in namespace [" + getNamespace() + "]");
LOG.log(Level.SEVERE, "Error killing topology message: " + response.message());
KubernetesUtils.logResponseBodyIfPresent(LOG, response);
throw new TopologyRuntimeManagementException(KubernetesUtils.errorMessageFromResponse(response));
}
} catch (ApiException e) {
if (e.getCode() == HTTP_NOT_FOUND) {
LOG.log(Level.WARNING, "Tried to delete a non-existent StatefulSet for Topology: " + getTopologyName());
return;
}
throw new TopologyRuntimeManagementException("Error deleting topology [" + getTopologyName() + "] Kubernetes StatefulSets", e);
} catch (IOException e) {
throw new TopologyRuntimeManagementException("Error deleting topology [" + getTopologyName() + "] Kubernetes StatefulSets", e);
}
LOG.log(Level.INFO, "StatefulSet for the Job [" + getTopologyName() + "] in namespace [" + getNamespace() + "] is deleted.");
}
use of org.apache.heron.scheduler.TopologyRuntimeManagementException in project heron by twitter.
the class V1Controller method removeContainers.
/**
* Removes a specified number of Pods from a <code>topology</code>'s <code>Executors</code>.
* @param containersToRemove Set of containers to be removed.
*/
@Override
public void removeContainers(Set<PackingPlan.ContainerPlan> containersToRemove) {
final V1StatefulSet statefulSet;
try {
statefulSet = getStatefulSet();
} catch (ApiException ae) {
final String message = ae.getMessage() + "\ndetails:" + ae.getResponseBody();
throw new TopologyRuntimeManagementException(message, ae);
}
final V1StatefulSetSpec v1StatefulSet = Objects.requireNonNull(statefulSet.getSpec());
final int currentContainerCount = Objects.requireNonNull(v1StatefulSet.getReplicas());
final int newContainerCount = currentContainerCount - containersToRemove.size();
try {
patchStatefulSetReplicas(newContainerCount);
} catch (ApiException e) {
throw new TopologyRuntimeManagementException(e.getMessage() + "\ndetails\n" + e.getResponseBody());
}
}
Aggregations