Search in sources :

Example 1 with TerminationFailedException

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;
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Date(java.util.Date) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) HostGroupRepository(com.sequenceiq.cloudbreak.repository.HostGroupRepository) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException) HashSet(java.util.HashSet) Inject(javax.inject.Inject) FileSystemConfiguration(com.sequenceiq.cloudbreak.api.model.FileSystemConfiguration) OrchestratorTypeResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver) RdsConfigService(com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) Map(java.util.Map) FileSystemType(com.sequenceiq.cloudbreak.api.model.FileSystemType) FileSystemConfigurator(com.sequenceiq.cloudbreak.blueprint.filesystem.FileSystemConfigurator) DELETE_COMPLETED(com.sequenceiq.cloudbreak.api.model.Status.DELETE_COMPLETED) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) ContainerRepository(com.sequenceiq.cloudbreak.repository.ContainerRepository) LinkedList(java.util.LinkedList) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) Logger(org.slf4j.Logger) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) Transactional(javax.transaction.Transactional) Collection(java.util.Collection) Resource(javax.annotation.Resource) JsonUtil.writeValueAsString(com.sequenceiq.cloudbreak.util.JsonUtil.writeValueAsString) Set(java.util.Set) IOException(java.io.IOException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) JsonUtil.readValue(com.sequenceiq.cloudbreak.util.JsonUtil.readValue) Container(com.sequenceiq.cloudbreak.domain.Container) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) List(java.util.List) Component(org.springframework.stereotype.Component) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) ConstraintRepository(com.sequenceiq.cloudbreak.repository.ConstraintRepository) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) ComponentConfigProvider(com.sequenceiq.cloudbreak.service.ComponentConfigProvider) HashMap(java.util.HashMap) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) JsonUtil.writeValueAsString(com.sequenceiq.cloudbreak.util.JsonUtil.writeValueAsString) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) Container(com.sequenceiq.cloudbreak.domain.Container) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException)

Example 2 with TerminationFailedException

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);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType)

Example 3 with TerminationFailedException

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);
    }
}
Also used : FileSystemConfigurator(com.sequenceiq.cloudbreak.blueprint.filesystem.FileSystemConfigurator) JsonUtil.writeValueAsString(com.sequenceiq.cloudbreak.util.JsonUtil.writeValueAsString) IOException(java.io.IOException) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException) FileSystemConfiguration(com.sequenceiq.cloudbreak.api.model.FileSystemConfiguration)

Example 4 with TerminationFailedException

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.");
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType)

Aggregations

TerminationFailedException (com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException)4 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)3 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)3 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)3 FileSystemConfiguration (com.sequenceiq.cloudbreak.api.model.FileSystemConfiguration)2 FileSystemConfigurator (com.sequenceiq.cloudbreak.blueprint.filesystem.FileSystemConfigurator)2 JsonUtil.writeValueAsString (com.sequenceiq.cloudbreak.util.JsonUtil.writeValueAsString)2 IOException (java.io.IOException)2 FileSystemType (com.sequenceiq.cloudbreak.api.model.FileSystemType)1 DELETE_COMPLETED (com.sequenceiq.cloudbreak.api.model.Status.DELETE_COMPLETED)1 OrchestratorTypeResolver (com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver)1 ContainerOrchestratorResolver (com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver)1 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)1 Container (com.sequenceiq.cloudbreak.domain.Container)1 FileSystem (com.sequenceiq.cloudbreak.domain.FileSystem)1 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)1 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)1 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)1 ContainerOrchestrator (com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator)1 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1