use of com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException in project cloudbreak by hortonworks.
the class AwsResourceConnector method terminate.
@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) {
LOGGER.info("Deleting stack: {}", ac.getCloudContext().getId());
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
if (resources != null && !resources.isEmpty()) {
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
CloudResource stackResource = getCloudFormationStackResource(resources);
if (stackResource == null) {
return Collections.emptyList();
}
String cFStackName = stackResource.getName();
LOGGER.info("Deleting CloudFormation stack for stack: {} [cf stack id: {}]", cFStackName, ac.getCloudContext().getId());
DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName);
try {
retryService.testWith2SecDelayMax5Times(() -> {
try {
cfClient.describeStacks(describeStacksRequest);
} catch (AmazonServiceException e) {
if (!e.getErrorMessage().contains(cFStackName + " does not exist")) {
throw e;
}
throw new ActionWentFailException("Stack not exists");
}
return Boolean.TRUE;
});
} catch (ActionWentFailException ignored) {
LOGGER.info(String.format("Stack not found with name: %s", cFStackName));
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
return Collections.emptyList();
}
resumeAutoScalingPolicies(ac, stack);
DeleteStackRequest deleteStackRequest = new DeleteStackRequest().withStackName(cFStackName);
cfClient.deleteStack(deleteStackRequest);
PollTask<Boolean> task = awsPollTaskFactory.newAwsTerminateStackStatusCheckerTask(ac, cfClient, DELETE_COMPLETE, DELETE_FAILED, ERROR_STATUSES, cFStackName);
try {
Boolean statePollerResult = task.call();
if (!task.completed(statePollerResult)) {
syncPollingScheduler.schedule(task);
}
} catch (Exception e) {
throw new CloudConnectorException(e.getMessage(), e);
}
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
deleteKeyPair(ac, stack);
} else if (resources != null) {
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
LOGGER.info("No CloudFormation stack saved for stack.");
} else {
LOGGER.info("No resources to release.");
}
return check(ac, resources);
}
use of com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException in project cloudbreak by hortonworks.
the class HeartbeatService method heartbeat.
@Scheduled(cron = "${cb.ha.heartbeat.rate:0/30 * * * * *}")
public void heartbeat() {
if (cloudbreakNodeConfig.isNodeIdSpecified()) {
String nodeId = cloudbreakNodeConfig.getId();
try {
retryService.testWith2SecDelayMax5Times(() -> {
try {
CloudbreakNode self = cloudbreakNodeRepository.findOne(nodeId);
if (self == null) {
self = new CloudbreakNode(nodeId);
}
self.setLastUpdated(clock.getCurrentTime());
cloudbreakNodeRepository.save(self);
return true;
} catch (RuntimeException e) {
LOGGER.error("Failed to update the heartbeat timestamp", e);
metricService.incrementMetricCounter(MetricType.HEARTBEAT_UPDATE_FAILED);
throw new ActionWentFailException(e.getMessage());
}
});
} catch (ActionWentFailException af) {
LOGGER.error(String.format("Failed to update the heartbeat timestamp 5 times for node %s: %s", nodeId, af.getMessage()));
cancelEveryFlowWithoutDbUpdate();
}
cancelInvalidFlows();
}
}
use of com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException in project cloudbreak by hortonworks.
the class AzureResourceConnector method terminate.
@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) {
AzureClient client = authenticatedContext.getParameter(AzureClient.class);
for (CloudResource resource : resources) {
try {
try {
retryService.testWith2SecDelayMax5Times(() -> {
if (!client.resourceGroupExists(resource.getName())) {
throw new ActionWentFailException("Resource group not exists");
}
return true;
});
client.deleteResourceGroup(resource.getName());
} catch (ActionWentFailException ignored) {
LOGGER.info(String.format("Resource group not found with name: %s", resource.getName()));
}
if (azureStorage.isPersistentStorage(azureStorage.getPersistentStorageName(stack))) {
CloudContext cloudCtx = authenticatedContext.getCloudContext();
AzureCredentialView azureCredentialView = new AzureCredentialView(authenticatedContext.getCloudCredential());
String imageStorageName = azureStorage.getImageStorageName(azureCredentialView, cloudCtx, stack);
String imageResourceGroupName = azureStorage.getImageResourceGroupName(cloudCtx, stack);
String diskContainer = azureStorage.getDiskContainerName(cloudCtx);
deleteContainer(client, imageResourceGroupName, imageStorageName, diskContainer);
}
} catch (CloudException e) {
if (e.response().code() != AzureConstants.NOT_FOUND) {
throw new CloudConnectorException(String.format("Could not delete resource group: %s", resource.getName()), e);
} else {
return check(authenticatedContext, Collections.emptyList());
}
}
}
return check(authenticatedContext, resources);
}
Aggregations