use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class SecretAspects method proceedSave.
private Object proceedSave(ProceedingJoinPoint proceedingJoinPoint) {
Collection<Object> entities = convertFirstArgToCollection(proceedingJoinPoint);
for (Object entity : entities) {
String tenant = null;
try {
for (Field field : entity.getClass().getDeclaredFields()) {
if (field.isAnnotationPresent(SecretValue.class)) {
LOGGER.debug("Found SecretValue annotation on {}", field);
field.setAccessible(true);
Secret value = (Secret) field.get(entity);
if (value != null && value.getRaw() != null && value.getSecret() == null) {
tenant = Optional.ofNullable(tenant).orElseGet(() -> findTenant(entity));
String path = String.format("%s/%s/%s/%s-%s", tenant, entity.getClass().getSimpleName().toLowerCase(), field.getName().toLowerCase(), UUID.randomUUID().toString(), Long.toHexString(clock.getCurrentTimeMillis()));
String secret = secretService.put(path, value.getRaw());
LOGGER.debug("Field: '{}' is saved at path: {}", field.getName(), path);
field.set(entity, new SecretProxy(secretService, secret));
}
}
}
} catch (IllegalArgumentException e) {
LOGGER.error("Given entity isn't instance of TenantAwareResource or AccountIdAwareResource. Secret is not saved!", e);
throw new CloudbreakServiceException(e);
} catch (Exception e) {
LOGGER.warn("Looks like something went wrong with Secret store. Secret is not saved!", e);
throw new CloudbreakServiceException(e);
}
}
Object proceed;
try {
proceed = proceedingJoinPoint.proceed();
} catch (RuntimeException re) {
LOGGER.warn("Failed to invoke repository save", re);
throw re;
} catch (Throwable throwable) {
LOGGER.error("Failed to invoke repository save", throwable);
throw new CloudbreakServiceException(throwable);
}
return proceed;
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class RangerVirtualGroupService method getRangerVirtualGroup.
public String getRangerVirtualGroup(Stack stack) {
if (CloudPlatform.MOCK.equalsIgnoreCase(stack.getCloudPlatform())) {
return "mockGroup";
}
Optional<LdapView> ldapView = ldapConfigService.get(stack.getEnvironmentCrn(), stack.getName());
String virtualGroupsEnvironmentCrn = environmentConfigProvider.getParentEnvironmentCrn(stack.getEnvironmentCrn());
String adminGroup = ldapView.orElseThrow(() -> new CloudbreakServiceException("Ranger admin group not found.")).getAdminGroup();
LOGGER.debug("Admin Group:", adminGroup);
VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(virtualGroupsEnvironmentCrn, adminGroup);
return virtualGroupService.createOrGetVirtualGroup(virtualGroupRequest, UmsVirtualGroupRight.RANGER_ADMIN);
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackToTemplatePreparationObjectConverterTest method testConvertWhenUnableToGetStackInputsThenCloudbreakServiceExceptionWouldCome.
@Test
public void testConvertWhenUnableToGetStackInputsThenCloudbreakServiceExceptionWouldCome() throws IOException {
String ioExceptionMessage = "unable to get inputs";
IOException invokedException = new IOException(ioExceptionMessage);
when(stackInputs.get(StackInputs.class)).thenThrow(invokedException);
CloudbreakServiceException cloudbreakServiceException = assertThrows(CloudbreakServiceException.class, () -> underTest.convert(stackMock));
assertThat(cloudbreakServiceException).hasMessage(ioExceptionMessage).hasCause(invokedException);
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackToTemplatePreparationObjectConverterTest method testConvertIfTheAttemptOfObtainingBaseFileSystemConfigurationsViewThrowsIOExceptionThenCloudbreakServiceExceptionShouldComeOutside.
@Test
public void testConvertIfTheAttemptOfObtainingBaseFileSystemConfigurationsViewThrowsIOExceptionThenCloudbreakServiceExceptionShouldComeOutside() throws IOException {
String ioExceptionMessage = "Unable to obtain BaseFileSystemConfigurationsView";
IOException invokedException = new IOException(ioExceptionMessage);
FileSystem sourceFileSystem = new FileSystem();
FileSystem clusterServiceFileSystem = new FileSystem();
ConfigQueryEntries configQueryEntries = new ConfigQueryEntries();
when(sourceCluster.getFileSystem()).thenReturn(sourceFileSystem);
when(cluster.getFileSystem()).thenReturn(clusterServiceFileSystem);
when(stackMock.getEnvironmentCrn()).thenReturn("envCredentialCRN");
when(fileSystemConfigurationProvider.fileSystemConfiguration(eq(clusterServiceFileSystem), eq(stackMock), any(), eq(new Json("")), eq(configQueryEntries))).thenThrow(invokedException);
when(cmCloudStorageConfigProvider.getConfigQueryEntries()).thenReturn(configQueryEntries);
CloudbreakServiceException cloudbreakServiceException = assertThrows(CloudbreakServiceException.class, () -> underTest.convert(stackMock));
assertThat(cloudbreakServiceException).hasMessage(ioExceptionMessage).hasCause(invokedException);
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class CmVersionQueryServiceTest method testWhenServerAndAgentHaveDifferentPackageVersionsThenValidateConsistencyShouldFail.
@Test
void testWhenServerAndAgentHaveDifferentPackageVersionsThenValidateConsistencyShouldFail() {
Map<String, List<PackageInfo>> hostPackageMap = Maps.newHashMap();
hostPackageMap.put(HOST_1, getPackageInfoList(false));
hostPackageMap.put(HOST_2, getPackageInfoList(false));
CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.checkCmPackageInfoConsistency(hostPackageMap));
Assertions.assertEquals("Error during sync! CM server and agent has different versions:" + " cloudera-manager-server (2-2000), cloudera-manager-agent (1-1000)", exception.getMessage());
}
Aggregations