use of com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException in project cloudbreak by hortonworks.
the class ClusterTerminationService method deleteClusterContainers.
public Boolean deleteClusterContainers(Cluster cluster) {
try {
Orchestrator orchestrator = cluster.getStack().getOrchestrator();
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
try {
Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
Set<Container> containers = containerRepository.findContainersInCluster(cluster.getId());
List<ContainerInfo> containerInfo = containers.stream().map(c -> new ContainerInfo(c.getContainerId(), c.getName(), c.getHost(), c.getImage())).collect(Collectors.toList());
containerOrchestrator.deleteContainer(containerInfo, credential);
containerRepository.delete(containers);
deleteClusterHostGroupsWithItsMetadata(cluster);
} catch (CloudbreakOrchestratorException e) {
throw new TerminationFailedException(String.format("Failed to delete containers of cluster (id:'%s',name:'%s').", cluster.getId(), cluster.getName()), e);
}
return Boolean.TRUE;
} catch (CloudbreakException ignored) {
return Boolean.FALSE;
}
}
use of com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException in project cloudbreak by hortonworks.
the class ClusterTerminationService method deleteClusterComponents.
public Boolean deleteClusterComponents(Long clusterId) {
Cluster cluster = clusterRepository.findById(clusterId);
if (cluster == null) {
LOGGER.warn("Failed to delete containers of cluster (id:'{}'), because the cluster could not be found in the database.", clusterId);
return Boolean.TRUE;
}
OrchestratorType orchestratorType;
try {
orchestratorType = orchestratorTypeResolver.resolveType(cluster.getStack().getOrchestrator().getType());
} catch (CloudbreakException e) {
throw new TerminationFailedException(String.format("Failed to delete containers of cluster (id:'%s',name:'%s').", cluster.getId(), cluster.getName()), e);
}
if (orchestratorType.hostOrchestrator()) {
return Boolean.TRUE;
}
return deleteClusterContainers(cluster);
}
use of com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException in project cloudbreak by hortonworks.
the class ClusterTerminationService method deleteFileSystemResources.
private void deleteFileSystemResources(Long stackId, FileSystem fileSystem) {
try {
FileSystemConfigurator fsConfigurator = fileSystemConfigurators.get(FileSystemType.valueOf(fileSystem.getType()));
String json = writeValueAsString(fileSystem.getProperties());
FileSystemConfiguration fsConfiguration = readValue(json, FileSystemType.valueOf(fileSystem.getType()).getClazz());
fsConfiguration.addProperty(FileSystemConfiguration.STORAGE_CONTAINER, "cloudbreak" + stackId);
fsConfigurator.deleteResources(fsConfiguration);
} catch (IOException e) {
throw new TerminationFailedException("File system resources could not be deleted: ", e);
}
}
use of com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException in project cloudbreak by hortonworks.
the class ClusterCreationService method handleClusterCreationFailure.
public void handleClusterCreationFailure(StackView stackView, Exception exception) {
if (stackView.getClusterView() != null) {
Cluster cluster = clusterService.getById(stackView.getClusterView().getId());
clusterService.cleanupKerberosCredential(cluster);
String errorMessage = exception instanceof CloudbreakException && exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage();
clusterService.updateClusterStatusByStackId(stackView.getId(), CREATE_FAILED, errorMessage);
stackUpdater.updateStackStatus(stackView.getId(), DetailedStackStatus.AVAILABLE);
flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_CREATE_FAILED, CREATE_FAILED.name(), errorMessage);
try {
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stackView.getOrchestrator().getType());
if (cluster != null && orchestratorType.containerOrchestrator()) {
clusterTerminationService.deleteClusterContainers(cluster);
}
} catch (CloudbreakException | TerminationFailedException ex) {
LOGGER.error("Cluster containers could not be deleted, preparation for reinstall failed: ", ex);
}
if (cluster != null && cluster.getEmailNeeded()) {
emailSenderService.sendProvisioningFailureEmail(cluster.getOwner(), stackView.getClusterView().getEmailTo(), cluster.getName());
flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_NOTIFICATION_EMAIL, AVAILABLE.name());
}
} else {
LOGGER.error("Cluster was null. Flow action was not required.");
}
}
Aggregations