use of com.sequenceiq.cloudbreak.common.dal.ResourceBasicView in project cloudbreak by hortonworks.
the class DatalakeService method addSharedServiceResponse.
public void addSharedServiceResponse(Stack stack, StackV4Response stackResponse) {
SharedServiceV4Response sharedServiceResponse = new SharedServiceV4Response();
if (!Strings.isNullOrEmpty(stack.getDatalakeCrn())) {
LOGGER.debug("Checking datalake through the datalakeCrn.");
Optional<ResourceBasicView> resourceBasicView = stackService.getResourceBasicViewByResourceCrn(stack.getDatalakeCrn());
if (resourceBasicView.isPresent()) {
ResourceBasicView s = resourceBasicView.get();
sharedServiceResponse.setSharedClusterId(s.getId());
sharedServiceResponse.setSharedClusterName(s.getName());
} else {
LOGGER.debug("Unable to find datalake with CRN {}", stack.getDatalakeCrn());
}
}
stackResponse.setSharedService(sharedServiceResponse);
}
use of com.sequenceiq.cloudbreak.common.dal.ResourceBasicView in project cloudbreak by hortonworks.
the class RepositoryBasedDataCollector method fetchDataFromDbIfNeed.
/**
* Attaches {@code RESOURCE_ID}, {@code RESOURCE_CRN}, or {@code RESOURCE_NAME} to the provided {@code params} if they're missing.
*
* @param params should include exactly one of {@code RESOURCE_CRN} or {@code RESOURCE_NAME}
*/
public void fetchDataFromDbIfNeed(Map<String, String> params) {
String resourceCrn = params.get(RESOURCE_CRN);
String resourceName = params.get(RESOURCE_NAME);
// check each repository for a matching CRN or Name.
for (Map.Entry<String, AccountAwareResourceRepository<?, ?>> pathRepositoryEntry : pathRepositoryMap.entrySet()) {
AccountAwareResourceRepository<?, ?> resourceRepository = pathRepositoryEntry.getValue();
if (resourceCrn == null && resourceName != null) {
String accountId = ThreadBasedUserCrnProvider.getAccountId();
Optional<ResourceBasicView> entity = resourceRepository.findResourceBasicViewByNameAndAccountId(resourceName, accountId);
if (entity.isPresent()) {
ResourceBasicView resource = entity.get();
params.put(RESOURCE_ID, Long.toString(resource.getId()));
params.put(RESOURCE_CRN, resource.getResourceCrn());
break;
}
} else if (resourceName == null) {
Optional<ResourceBasicView> entity = resourceRepository.findResourceBasicViewByResourceCrn(resourceCrn);
if (entity.isPresent()) {
ResourceBasicView resource = entity.get();
params.put(RESOURCE_ID, Long.toString(resource.getId()));
params.put(RESOURCE_NAME, resource.getName());
break;
}
}
}
}
use of com.sequenceiq.cloudbreak.common.dal.ResourceBasicView in project cloudbreak by hortonworks.
the class DataCollectorComponentTest method testFetchDataFromDbIfNeedWhenCrnNotNullAndNameIsNullAndFound.
@Test
public void testFetchDataFromDbIfNeedWhenCrnNotNullAndNameIsNullAndFound() {
AccountAwareResourceRepository<AccountAwareResource, Long> repo = mock(AccountAwareResourceRepository.class);
ResourceBasicView resource = mock(ResourceBasicView.class);
Optional<ResourceBasicView> entityOpt = Optional.of(resource);
pathRepositoryMap.put("key", repo);
Map<String, String> params = new HashMap<>();
params.put(RESOURCE_CRN, "crn");
params.put(RESOURCE_NAME, null);
when(resource.getName()).thenReturn("name-ret");
when(resource.getId()).thenReturn(342L);
when(repo.findResourceBasicViewByResourceCrn("crn")).thenReturn(entityOpt);
ThreadBasedUserCrnProvider.doAs(userCrn, () -> underTest.fetchDataFromDbIfNeed(params));
Assertions.assertEquals("name-ret", params.get(RESOURCE_NAME));
Assertions.assertEquals("crn", params.get(RESOURCE_CRN));
Assertions.assertEquals("342", params.get(RESOURCE_ID));
verify(repo).findResourceBasicViewByResourceCrn("crn");
}
use of com.sequenceiq.cloudbreak.common.dal.ResourceBasicView in project cloudbreak by hortonworks.
the class DataCollectorComponentTest method testFetchDataFromDbIfNeedWhenNameNotNullAndCrnIsNullAndFound.
@Test
public void testFetchDataFromDbIfNeedWhenNameNotNullAndCrnIsNullAndFound() {
AccountAwareResourceRepository<AccountAwareResource, Long> repo = mock(AccountAwareResourceRepository.class);
ResourceBasicView resource = mock(ResourceBasicView.class);
pathRepositoryMap.put("key", repo);
Map<String, String> params = new HashMap<>();
params.put(RESOURCE_CRN, null);
params.put(RESOURCE_NAME, "name");
Optional<ResourceBasicView> entityOpt = Optional.of(resource);
when(resource.getResourceCrn()).thenReturn("crn-ret");
when(resource.getId()).thenReturn(342L);
when(repo.findResourceBasicViewByNameAndAccountId("name", "acc")).thenReturn(entityOpt);
ThreadBasedUserCrnProvider.doAs(userCrn, () -> underTest.fetchDataFromDbIfNeed(params));
Assertions.assertEquals("name", params.get(RESOURCE_NAME));
Assertions.assertEquals("crn-ret", params.get(RESOURCE_CRN));
Assertions.assertEquals("342", params.get(RESOURCE_ID));
verify(repo).findResourceBasicViewByNameAndAccountId("name", "acc");
}
use of com.sequenceiq.cloudbreak.common.dal.ResourceBasicView in project cloudbreak by hortonworks.
the class DatalakeServiceTest method testAddSharedServiceResponseWhenDatalakeCrnIsNotNull.
@Test
public void testAddSharedServiceResponseWhenDatalakeCrnIsNotNull() {
ResourceBasicView resourceBasicView = mock(ResourceBasicView.class);
when(resourceBasicView.getId()).thenReturn(1L);
when(resourceBasicView.getName()).thenReturn("teststack");
lenient().when(stackService.getResourceBasicViewByResourceCrn(anyString())).thenReturn(Optional.of(resourceBasicView));
Stack source = new Stack();
source.setDatalakeCrn("crn");
StackV4Response x = new StackV4Response();
underTest.addSharedServiceResponse(source, x);
verify(stackService, times(1)).getResourceBasicViewByResourceCrn("crn");
assertEquals(1L, x.getSharedService().getSharedClusterId());
assertEquals("teststack", x.getSharedService().getSharedClusterName());
}
Aggregations