use of org.apache.heron.scheduler.TopologyRuntimeManagementException in project heron by twitter.
the class V1Controller method deleteService.
/**
* Deletes the headless <code>Service</code> for a <code>topology</code>'s <code>Executors</code>
* and <code>Manager</code> using the <code>topology</code>'s name.
*/
void deleteService() {
try (Response response = coreClient.deleteNamespacedServiceCall(getTopologyName(), getNamespace(), null, null, 0, null, KubernetesConstants.DELETE_OPTIONS_PROPAGATION_POLICY, null, null).execute()) {
if (!response.isSuccessful()) {
if (response.code() == HTTP_NOT_FOUND) {
LOG.log(Level.WARNING, "Deleting non-existent Kubernetes headless service for Topology: " + getTopologyName());
return;
}
LOG.log(Level.SEVERE, "Error when deleting the Service 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 Kubernetes service for Topology: " + getTopologyName());
return;
}
throw new TopologyRuntimeManagementException("Error deleting topology [" + getTopologyName() + "] Kubernetes service", e);
} catch (IOException e) {
throw new TopologyRuntimeManagementException("Error deleting topology [" + getTopologyName() + "] Kubernetes service", e);
}
LOG.log(Level.INFO, "Headless Service 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 addContainers.
/**
* Adds a specified number of Pods to a <code>topology</code>'s <code>Executors</code>.
* @param containersToAdd Set of containers to be added.
* @return The passed in <code>Packing Plan</code>.
*/
@Override
public Set<PackingPlan.ContainerPlan> addContainers(Set<PackingPlan.ContainerPlan> containersToAdd) {
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 + containersToAdd.size();
try {
patchStatefulSetReplicas(newContainerCount);
} catch (ApiException ae) {
throw new TopologyRuntimeManagementException(ae.getMessage() + "\ndetails\n" + ae.getResponseBody());
}
return containersToAdd;
}
use of org.apache.heron.scheduler.TopologyRuntimeManagementException in project heron by twitter.
the class V1Controller method removePersistentVolumeClaims.
/**
* Removes all Persistent Volume Claims associated with a specific topology, if they exist.
* It looks for the following:
* metadata:
* labels:
* topology: <code>topology-name</code>
* onDemand: <code>true</code>
*/
private void removePersistentVolumeClaims() {
final String name = getTopologyName();
final StringBuilder selectorLabel = new StringBuilder();
// Generate selector label.
for (Map.Entry<String, String> label : getPersistentVolumeClaimLabels(name).entrySet()) {
if (selectorLabel.length() != 0) {
selectorLabel.append(",");
}
selectorLabel.append(label.getKey()).append("=").append(label.getValue());
}
// Remove all dynamically backed Persistent Volume Claims.
try {
V1Status status = coreClient.deleteCollectionNamespacedPersistentVolumeClaim(getNamespace(), null, null, null, null, null, selectorLabel.toString(), null, null, null, null, null, null, null);
LOG.log(Level.INFO, String.format("Removing automatically generated Persistent Volume Claims for `%s`:%n%s", name, status.getMessage()));
} catch (ApiException e) {
final String message = String.format("Failed to connect to K8s cluster to delete Persistent " + "Volume Claims for topology `%s`. A manual clean-up is required.%n%s", name, e.getMessage());
LOG.log(Level.WARNING, message);
throw new TopologyRuntimeManagementException(message);
}
}
use of org.apache.heron.scheduler.TopologyRuntimeManagementException in project heron by twitter.
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);
}
use of org.apache.heron.scheduler.TopologyRuntimeManagementException in project heron by twitter.
the class KubernetesSchedulerTest method testRemoveContainers.
@Test
public void testRemoveContainers() throws Exception {
KubernetesController controller = Mockito.mock(KubernetesController.class);
Mockito.doReturn(controller).when(scheduler).getController();
scheduler.initialize(config, mockRuntime);
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(PackingTestUtils.testContainerPlan(0));
// Failure to remove container
Mockito.doThrow(new TopologyRuntimeManagementException("")).when(controller).removeContainers(Mockito.anySetOf(PackingPlan.ContainerPlan.class));
expectedException.expect(TopologyRuntimeManagementException.class);
scheduler.removeContainers(containers);
// Successful removal
Mockito.doNothing().when(controller).removeContainers(Mockito.anySetOf(PackingPlan.ContainerPlan.class));
scheduler.removeContainers(containers);
}
Aggregations