private void deleteResourceAndDependencies(Stack stack, InstanceMetaData instanceMetaData) {
   LOGGER.info(String.format("Instance %s rollback started.", instanceMetaData.getInstanceId()));
   CloudPlatformConnector cloudPlatformConnector =
       cloudPlatformConnectors.get(stack.cloudPlatform());
   Set<String> instanceIds = new HashSet<>();
   instanceIds.add(instanceMetaData.getInstanceId());
   cloudPlatformConnector.removeInstances(
       stack, instanceIds, instanceMetaData.getInstanceGroup().getGroupName());
   LOGGER.info(
       String.format(
           "Instance deleted with %s id and %s name.",
           instanceMetaData.getId(), instanceMetaData.getInstanceId()));
 }
 public void terminateFailedNodes(
     ContainerOrchestrator orchestrator, Stack stack, GatewayConfig gatewayConfig, Set<Node> nodes)
     throws CloudbreakOrchestratorFailedException {
   List<String> allAvailableNode = orchestrator.getAvailableNodes(gatewayConfig, nodes);
   List<Node> missingNodes = selectMissingNodes(nodes, allAvailableNode);
   if (missingNodes.size() > 0) {
     String message =
         String.format(
             "Bootstrap failed on %s nodes. These nodes will be terminated.", missingNodes.size());
     LOGGER.info(message);
     eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
     for (Node missingNode : missingNodes) {
       InstanceMetaData instanceMetaData =
           instanceMetaDataRepository.findNotTerminatedByPrivateAddress(
               stack.getId(), missingNode.getPrivateIp());
       InstanceGroup ig =
           instanceGroupRepository.findOneByGroupNameInStack(
               stack.getId(), instanceMetaData.getInstanceGroup().getGroupName());
       ig.setNodeCount(ig.getNodeCount() - 1);
       if (ig.getNodeCount() < 1) {
         throw new CloudbreakOrchestratorFailedException(
             String.format(
                 "%s instancegroup nodecount was lower than 1 cluster creation failed.",
                 ig.getGroupName()));
       }
       instanceGroupRepository.save(ig);
       message =
           String.format(
               "Delete '%s' node. and Decrease the nodecount on %s instancegroup",
               instanceMetaData.getInstanceId(), ig.getGroupName());
       LOGGER.info(message);
       eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
       deleteResourceAndDependencies(stack, instanceMetaData);
       deleteInstanceResourceFromDatabase(stack, instanceMetaData);
       instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
       instanceMetaDataRepository.save(instanceMetaData);
       LOGGER.info(
           String.format(
               "The status of instanceMetadata with %s id and %s name setted to TERMINATED.",
               instanceMetaData.getId(), instanceMetaData.getInstanceId()));
     }
   }
 }