use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class CertRenewalService method renewInternalCertificate.
public void renewInternalCertificate(SdxCluster sdxCluster) {
try {
FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.renewInternalCertificate(WORKSPACE_ID_DEFAULT, sdxCluster.getStackCrn()));
transactionService.required(() -> saveChainIdAndStatus(sdxCluster, flowIdentifier));
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
} catch (WebApplicationException e) {
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
throw new RuntimeException(errorMessage);
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class CertRenewalService method renewCertificate.
public void renewCertificate(SdxCluster sdxCluster, String userCrn) {
try {
transactionService.required(() -> {
FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.renewCertificate(WORKSPACE_ID_DEFAULT, sdxCluster.getClusterName(), userCrn));
saveChainIdAndStatus(sdxCluster, flowIdentifier);
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class ClusterTemplateV4Controller method getByName.
@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.DESCRIBE_CLUSTER_DEFINITION)
public ClusterTemplateV4Response getByName(Long workspaceId, @ResourceName String name) {
try {
ClusterTemplate clusterTemplate = transactionService.required(() -> clusterTemplateService.getByNameForWorkspaceId(name, threadLocalService.getRequestedWorkspaceId()));
ClusterTemplateV4Response response = transactionService.required(() -> clusterTemplateToClusterTemplateV4ResponseConverter.convert(clusterTemplate));
Optional.ofNullable(response.getEnvironmentCrn()).ifPresent(crn -> environmentServiceDecorator.prepareEnvironment(response));
return response;
} catch (TransactionExecutionException cse) {
LOGGER.warn("Unable to find cluster definition due to " + cse.getMessage(), cse.getCause());
throw new CloudbreakServiceException("Unable to obtain cluster definition!", cse.getCause());
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class ClusterTemplateV4Controller method getByCrn.
@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_CLUSTER_DEFINITION)
public ClusterTemplateV4Response getByCrn(Long workspaceId, @TenantAwareParam @ResourceCrn String crn) {
boolean internalTenant = isInternalTenant();
try {
ClusterTemplate clusterTemplate = transactionService.required(() -> clusterTemplateService.getByCrn(crn, threadLocalService.getRequestedWorkspaceId(), internalTenant));
ClusterTemplateV4Response response = transactionService.required(() -> clusterTemplateToClusterTemplateV4ResponseConverter.convert(clusterTemplate));
if (!StringUtils.isEmpty(response.getEnvironmentCrn())) {
environmentServiceDecorator.prepareEnvironment(response);
} else {
LOGGER.warn("Skipping response decoration with environment name. Environment CRN was empty.");
}
return response;
} catch (TransactionExecutionException cse) {
LOGGER.warn("Unable to find cluster definition due to {}", cse.getMessage());
throw new CloudbreakServiceException("Unable to obtain cluster definition!");
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class UserServiceTest method testCreateUserWithDuplicateException.
@Test
public void testCreateUserWithDuplicateException() throws TransactionExecutionException {
doAnswer(invocation -> ((Supplier<?>) invocation.getArgument(0)).get()).when(transactionService).requiresNew(any());
when(tenantService.findByName(anyString())).thenReturn(Optional.empty());
when(tenantService.save(any())).thenReturn(createTenant());
when(workspaceService.create(any())).thenReturn(createWorkspace());
when(userRepository.findByTenantNameAndUserId(anyString(), anyString())).thenAnswer(new Answer() {
private int count;
public Object answer(InvocationOnMock invocation) {
if (count++ == 0) {
return Optional.empty();
}
return Optional.of(createUser());
}
});
when(userRepository.save(any())).thenAnswer(new Answer() {
private int count;
public Object answer(InvocationOnMock invocation) {
if (count++ == 0) {
TransactionExecutionException exception = new TransactionExecutionException("", new RuntimeException("User already exists!"));
throw new TransactionRuntimeExecutionException(exception);
}
TransactionExecutionException exception = new TransactionExecutionException("", new RuntimeException("This is not expected to run"));
throw new TransactionRuntimeExecutionException(exception);
}
});
User user = underTest.getOrCreate(createCbUser());
assertNotNull(user);
verify(cachedUserService, times(1)).getUser(any(), any(), any());
verify(workspaceService, times(1)).create(any());
verify(tenantService, times(1)).save(any());
}
Aggregations