Search in sources :

Example 1 with TopologyRuntimeManagementException

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

the class AppsV1beta1Controller method deleteStatefulSet.

boolean deleteStatefulSet() {
    try {
        final V1DeleteOptions options = new V1DeleteOptions();
        options.setGracePeriodSeconds(0L);
        options.setPropagationPolicy(KubernetesConstants.DELETE_OPTIONS_PROPAGATION_POLICY);
        final Response response = client.deleteNamespacedStatefulSetCall(getTopologyName(), getNamespace(), options, null, null, null, null, null, null).execute();
        if (!response.isSuccessful()) {
            LOG.log(Level.SEVERE, "Error killing topology message: " + response.message());
            KubernetesUtils.logResponseBodyIfPresent(LOG, response);
            throw new TopologyRuntimeManagementException(KubernetesUtils.errorMessageFromResponse(response));
        }
    } catch (IOException | ApiException e) {
        KubernetesUtils.logExceptionWithDetails(LOG, "Error deleting topology", e);
        return false;
    }
    return true;
}
Also used : Response(com.squareup.okhttp.Response) V1DeleteOptions(io.kubernetes.client.models.V1DeleteOptions) TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) IOException(java.io.IOException) ApiException(io.kubernetes.client.ApiException)

Example 2 with TopologyRuntimeManagementException

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

the class AppsV1beta1Controller method removeContainers.

@Override
public void removeContainers(Set<PackingPlan.ContainerPlan> containersToRemove) {
    final V1beta1StatefulSet statefulSet;
    try {
        statefulSet = getStatefulSet();
    } catch (ApiException ae) {
        final String message = ae.getMessage() + "\ndetails:" + ae.getResponseBody();
        throw new TopologyRuntimeManagementException(message, ae);
    }
    final int currentContainerCount = statefulSet.getSpec().getReplicas();
    final int newContainerCount = currentContainerCount - containersToRemove.size();
    final V1beta1StatefulSetSpec newSpec = new V1beta1StatefulSetSpec();
    newSpec.setReplicas(newContainerCount);
    try {
        doPatch(newSpec);
    } catch (ApiException e) {
        throw new TopologyRuntimeManagementException(e.getMessage() + "\ndetails\n" + e.getResponseBody());
    }
}
Also used : TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) V1beta1StatefulSetSpec(io.kubernetes.client.models.V1beta1StatefulSetSpec) ApiException(io.kubernetes.client.ApiException)

Example 3 with TopologyRuntimeManagementException

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

the class KubernetesCompat method killTopology.

boolean killTopology(String kubernetesUri, String topology, String namespace) {
    final CoreV1Api client = new CoreV1Api(new ApiClient().setBasePath(kubernetesUri));
    // old version deployed topologies as naked pods
    try {
        final String labelSelector = KubernetesConstants.LABEL_TOPOLOGY + "=" + topology;
        final Response response = client.deleteCollectionNamespacedPodCall(namespace, null, null, null, null, labelSelector, null, null, null, null, null, null).execute();
        if (!response.isSuccessful()) {
            LOG.log(Level.SEVERE, "Error killing topology message: " + response.message());
            KubernetesUtils.logResponseBodyIfPresent(LOG, response);
            throw new TopologyRuntimeManagementException(KubernetesUtils.errorMessageFromResponse(response));
        }
    } catch (IOException | ApiException e) {
        LOG.log(Level.SEVERE, "Error killing topology " + e.getMessage());
        if (e instanceof ApiException) {
            LOG.log(Level.SEVERE, "Error details:\n" + ((ApiException) e).getResponseBody());
        }
        return false;
    }
    return true;
}
Also used : Response(com.squareup.okhttp.Response) TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient) CoreV1Api(io.kubernetes.client.apis.CoreV1Api) ApiException(io.kubernetes.client.ApiException)

Example 4 with TopologyRuntimeManagementException

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

the class AppsV1beta1Controller method addContainers.

@Override
public Set<PackingPlan.ContainerPlan> addContainers(Set<PackingPlan.ContainerPlan> containersToAdd) {
    final V1beta1StatefulSet statefulSet;
    try {
        statefulSet = getStatefulSet();
    } catch (ApiException ae) {
        final String message = ae.getMessage() + "\ndetails:" + ae.getResponseBody();
        throw new TopologyRuntimeManagementException(message, ae);
    }
    final int currentContainerCount = statefulSet.getSpec().getReplicas();
    final int newContainerCount = currentContainerCount + containersToAdd.size();
    final V1beta1StatefulSetSpec newSpec = new V1beta1StatefulSetSpec();
    newSpec.setReplicas(newContainerCount);
    try {
        doPatch(newSpec);
    } catch (ApiException ae) {
        throw new TopologyRuntimeManagementException(ae.getMessage() + "\ndetails\n" + ae.getResponseBody());
    }
    return containersToAdd;
}
Also used : TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) V1beta1StatefulSetSpec(io.kubernetes.client.models.V1beta1StatefulSetSpec) ApiException(io.kubernetes.client.ApiException)

Example 5 with TopologyRuntimeManagementException

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

the class KubernetesSchedulerTest method testAddContainers.

@Test
public void testAddContainers() throws Exception {
    KubernetesController controller = Mockito.mock(KubernetesController.class);
    Mockito.doReturn(controller).when(scheduler).getController();
    scheduler.initialize(config, mockRuntime);
    Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
    // Failure to deploy a container
    Mockito.doThrow(new TopologyRuntimeManagementException("")).when(controller).addContainers(Mockito.anySetOf(PackingPlan.ContainerPlan.class));
    expectedException.expect(TopologyRuntimeManagementException.class);
    scheduler.addContainers(containers);
    // Successful deployment
    Mockito.doNothing().when(controller).addContainers(Mockito.anySetOf(PackingPlan.ContainerPlan.class));
    scheduler.addContainers(containers);
}
Also used : TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

TopologyRuntimeManagementException (com.twitter.heron.scheduler.TopologyRuntimeManagementException)6 ApiException (io.kubernetes.client.ApiException)4 Response (com.squareup.okhttp.Response)2 V1beta1StatefulSet (io.kubernetes.client.models.V1beta1StatefulSet)2 V1beta1StatefulSetSpec (io.kubernetes.client.models.V1beta1StatefulSetSpec)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 ApiClient (io.kubernetes.client.ApiClient)1 CoreV1Api (io.kubernetes.client.apis.CoreV1Api)1 V1DeleteOptions (io.kubernetes.client.models.V1DeleteOptions)1