Search in sources :

Example 6 with TopologyRuntimeManagementException

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);
    }
}
Also used : V1EnvVarSource(io.kubernetes.client.openapi.models.V1EnvVarSource) TopologyRuntimeManagementException(org.apache.heron.scheduler.TopologyRuntimeManagementException) Config(org.apache.heron.spi.common.Config) V1SecretKeySelector(io.kubernetes.client.openapi.models.V1SecretKeySelector) V1EnvVar(io.kubernetes.client.openapi.models.V1EnvVar) Map(java.util.Map) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 7 with TopologyRuntimeManagementException

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.");
}
Also used : Response(okhttp3.Response) TopologyRuntimeManagementException(org.apache.heron.scheduler.TopologyRuntimeManagementException) IOException(java.io.IOException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 8 with TopologyRuntimeManagementException

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());
    }
}
Also used : TopologyRuntimeManagementException(org.apache.heron.scheduler.TopologyRuntimeManagementException) V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) V1StatefulSetSpec(io.kubernetes.client.openapi.models.V1StatefulSetSpec) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

TopologyRuntimeManagementException (org.apache.heron.scheduler.TopologyRuntimeManagementException)8 ApiException (io.kubernetes.client.openapi.ApiException)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)2 V1StatefulSet (io.kubernetes.client.openapi.models.V1StatefulSet)2 V1StatefulSetSpec (io.kubernetes.client.openapi.models.V1StatefulSetSpec)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Response (okhttp3.Response)2 Test (org.junit.Test)2 V1EnvVar (io.kubernetes.client.openapi.models.V1EnvVar)1 V1EnvVarSource (io.kubernetes.client.openapi.models.V1EnvVarSource)1 V1SecretKeySelector (io.kubernetes.client.openapi.models.V1SecretKeySelector)1 V1Status (io.kubernetes.client.openapi.models.V1Status)1 Config (org.apache.heron.spi.common.Config)1