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;
}
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());
}
}
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;
}
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;
}
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);
}
Aggregations