use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class MetadataSetupService method cleanupRequestedInstancesWithoutFQDN.
public void cleanupRequestedInstancesWithoutFQDN(Long stackId, Set<String> instanceGroups) {
try {
transactionService.required(() -> {
for (String instanceGroupName : instanceGroups) {
Optional<InstanceGroup> ig = instanceGroupService.findOneWithInstanceMetadataByGroupNameInStack(stackId, instanceGroupName);
if (ig.isPresent()) {
List<InstanceMetaData> requestedInstances = instanceMetaDataService.findAllByInstanceGroupAndInstanceStatus(ig.get(), InstanceStatus.REQUESTED);
List<InstanceMetaData> requestedInstancesWithoutFQDN = requestedInstances.stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() == null).collect(Collectors.toList());
LOGGER.info("Set requested instances without FQDN to terminated: {}", requestedInstancesWithoutFQDN);
for (InstanceMetaData inst : requestedInstancesWithoutFQDN) {
inst.setTerminationDate(clock.getCurrentTimeMillis());
inst.setInstanceStatus(InstanceStatus.TERMINATED);
}
instanceMetaDataService.saveAll(requestedInstances);
}
}
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class MetadataSetupService method handleRepairFail.
public void handleRepairFail(Long stackId, Set<String> hostNames) {
LOGGER.info("Handle repair fail for hostnames: {}", hostNames);
for (String hostName : hostNames) {
try {
transactionService.required(() -> {
Optional<InstanceMetaData> instance = instanceMetaDataService.findByHostname(stackId, hostName);
instance.ifPresentOrElse(instanceMetaData -> {
LOGGER.info("Instance status for {}: {}", hostName, instanceMetaData.getInstanceStatus());
if (InstanceStatus.REQUESTED.equals(instanceMetaData.getInstanceStatus())) {
LOGGER.info("Instance in requested status is deleted: {}", hostName);
restorePreviousTerminatedInstanceMetadata(stackId, hostName);
instanceMetaData.setTerminationDate(clock.getCurrentTimeMillis());
instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
instanceMetaDataService.save(instanceMetaData);
}
}, () -> restorePreviousTerminatedInstanceMetadata(stackId, hostName));
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class StackService method getJsonByCrn.
public StackV4Response getJsonByCrn(String crn, Collection<String> entry) {
try {
return transactionService.required(() -> {
Stack stack = getByCrnWithLists(crn);
StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack);
stackResponse = stackResponseDecorator.decorate(stackResponse, stack, entry);
return stackResponse;
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class StackService method getByCrnInWorkspaceWithEntries.
public StackV4Response getByCrnInWorkspaceWithEntries(String crn, Long workspaceId, Set<String> entries, User user, StackType stackType) {
try {
return transactionService.required(() -> {
Workspace workspace = workspaceService.get(workspaceId, user);
ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
Optional<Stack> stack = findByCrnAndWorkspaceIdWithLists(crn, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
if (stack.isEmpty()) {
throw new NotFoundException(format("Stack not found by crn '%s'", crn));
}
StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
return stackResponse;
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class LeaderElectionServiceTest method testElectionNeededAndFails.
@Test
public void testElectionNeededAndFails() throws TransactionExecutionException {
when(periscopeNodeRepository.countByLeaderIsTrueAndLastUpdatedIsGreaterThan(anyLong())).thenReturn(0L);
when(transactionService.required(any(Supplier.class))).thenThrow(new TransactionExecutionException("Persisting went wrong", new RuntimeException()));
underTest.leaderElection();
verify(transactionService, times(1)).required(any(Supplier.class));
verify(timer, times(1)).cancel();
verify(timer, times(1)).purge();
verify(timerFactory, times(1)).get();
verify(timer, times(0)).schedule(any(TimerTask.class), anyLong(), anyLong());
}
Aggregations