Search in sources :

Example 1 with TopologySubmissionException

use of com.twitter.heron.scheduler.TopologySubmissionException in project incubator-heron by apache.

the class AppsV1beta1Controller method submit.

@Override
boolean submit(PackingPlan packingPlan) {
    final String topologyName = getTopologyName();
    if (!topologyName.equals(topologyName.toLowerCase())) {
        throw new TopologySubmissionException("K8S scheduler does not allow upper case topologies.");
    }
    final Resource containerResource = getContainerResource(packingPlan);
    // find the max number of instances in a container so we can open
    // enough ports if remote debugging is enabled.
    int numberOfInstances = 0;
    for (PackingPlan.ContainerPlan containerPlan : packingPlan.getContainers()) {
        numberOfInstances = Math.max(numberOfInstances, containerPlan.getInstances().size());
    }
    final V1beta1StatefulSet statefulSet = createStatefulSet(containerResource, numberOfInstances);
    try {
        final Response response = client.createNamespacedStatefulSetCall(getNamespace(), statefulSet, null, null, null).execute();
        if (!response.isSuccessful()) {
            LOG.log(Level.SEVERE, "Error creating topology message: " + response.message());
            KubernetesUtils.logResponseBodyIfPresent(LOG, response);
            // construct a message based on the k8s api server response
            throw new TopologySubmissionException(KubernetesUtils.errorMessageFromResponse(response));
        }
    } catch (IOException | ApiException e) {
        KubernetesUtils.logExceptionWithDetails(LOG, "Error creating topology", e);
        throw new TopologySubmissionException(e.getMessage());
    }
    return true;
}
Also used : TopologySubmissionException(com.twitter.heron.scheduler.TopologySubmissionException) Response(com.squareup.okhttp.Response) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) IOException(java.io.IOException) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) ApiException(io.kubernetes.client.ApiException)

Aggregations

Response (com.squareup.okhttp.Response)1 TopologySubmissionException (com.twitter.heron.scheduler.TopologySubmissionException)1 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)1 Resource (com.twitter.heron.spi.packing.Resource)1 ApiException (io.kubernetes.client.ApiException)1 V1beta1StatefulSet (io.kubernetes.client.models.V1beta1StatefulSet)1 IOException (java.io.IOException)1