Search in sources :

Example 1 with ActionFailedException

use of com.sequenceiq.cloudbreak.service.Retry.ActionFailedException in project cloudbreak by hortonworks.

the class AwsTerminateService method isStackDeleted.

private Boolean isStackDeleted(AmazonCloudFormationClient cfRetryClient, DescribeStacksRequest describeStacksRequest, DeleteStackRequest deleteStackRequest) {
    cfRetryClient.deleteStack(deleteStackRequest);
    Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = cfRetryClient.waiters().stackDeleteComplete();
    try {
        LOGGER.debug("Waiting for final state of CloudFormation deletion attempt.");
        WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest).withPollingStrategy(getBackoffCancellablePollingStrategy(null));
        stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters);
    } catch (Exception e) {
        LOGGER.debug("CloudFormation stack delete ended in failed state. Delete operation will be retried.");
        throw new ActionFailedException(e.getMessage());
    }
    return Boolean.TRUE;
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) ActionFailedException(com.sequenceiq.cloudbreak.service.Retry.ActionFailedException) ActionFailedException(com.sequenceiq.cloudbreak.service.Retry.ActionFailedException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 2 with ActionFailedException

use of com.sequenceiq.cloudbreak.service.Retry.ActionFailedException in project cloudbreak by hortonworks.

the class HeartbeatService method heartbeat.

private void heartbeat(boolean unLeaderIt) {
    if (periscopeNodeConfig.isNodeIdSpecified()) {
        String nodeId = periscopeNodeConfig.getId();
        try {
            retryService.testWith2SecDelayMax5Times(() -> {
                try {
                    PeriscopeNode self = periscopeNodeRepository.findById(nodeId).orElse(new PeriscopeNode(nodeId));
                    self.setLastUpdated(clock.getCurrentTimeMillis());
                    if (unLeaderIt) {
                        self.setLeader(false);
                    }
                    periscopeNodeRepository.save(self);
                } catch (RuntimeException e) {
                    LOGGER.error("Failed to update the heartbeat timestamp", e);
                    throw new ActionFailedException(e.getMessage());
                }
                return Boolean.TRUE;
            });
        } catch (ActionFailedException af) {
            LOGGER.error("Failed to update the heartbeat timestamp 5 times for node {}: {}", nodeId, af.getMessage());
            try {
                transactionService.required(() -> {
                    clusterRepository.deallocateClustersOfNode(nodeId);
                    return null;
                });
            } catch (TransactionExecutionException e) {
                LOGGER.error("Unable to deallocate clusters", e);
            }
        }
    }
}
Also used : PeriscopeNode(com.sequenceiq.periscope.domain.PeriscopeNode) ActionFailedException(com.sequenceiq.cloudbreak.service.Retry.ActionFailedException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)

Example 3 with ActionFailedException

use of com.sequenceiq.cloudbreak.service.Retry.ActionFailedException in project cloudbreak by hortonworks.

the class AzureResourceConnector method terminate.

@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) {
    AzureClient client = ac.getParameter(AzureClient.class);
    String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(ac.getCloudContext(), stack);
    ResourceGroupUsage resourceGroupUsage = azureResourceGroupMetadataProvider.getResourceGroupUsage(stack);
    if (resourceGroupUsage != ResourceGroupUsage.MULTIPLE) {
        String deploymentName = azureUtils.getStackName(ac.getCloudContext());
        List<CloudResource> transientResources = azureTerminationHelperService.handleTransientDeployment(client, resourceGroupName, deploymentName);
        NullUtil.doIfNotNull(transientResources, resources::addAll);
        azureTerminationHelperService.terminate(ac, stack, resources);
        return check(ac, Collections.emptyList());
    } else {
        try {
            try {
                azureUtils.checkResourceGroupExistence(client, resourceGroupName);
                client.deleteResourceGroup(resourceGroupName);
            } catch (ActionFailedException ignored) {
                LOGGER.debug("Resource group not found with name: {}", resourceGroupName);
            }
        } catch (CloudException e) {
            if (e.response().code() != AzureConstants.NOT_FOUND) {
                throw new CloudConnectorException(String.format("Could not delete resource group: %s", resourceGroupName), e);
            } else {
                return check(ac, Collections.emptyList());
            }
        }
        return check(ac, resources);
    }
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) ActionFailedException(com.sequenceiq.cloudbreak.service.Retry.ActionFailedException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudException(com.microsoft.azure.CloudException)

Aggregations

ActionFailedException (com.sequenceiq.cloudbreak.service.Retry.ActionFailedException)3 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)1 CloudException (com.microsoft.azure.CloudException)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 PeriscopeNode (com.sequenceiq.periscope.domain.PeriscopeNode)1