use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary in project cloudbreak by hortonworks.
the class CmSyncerServiceTest method testSyncFromCmToDbWhenCmServerDownThenSyncSkipped.
@Test
void testSyncFromCmToDbWhenCmServerDownThenSyncSkipped() {
when(cmServerQueryService.isCmServerRunning(stack)).thenReturn(false);
Set<Image> candidateImages = Set.of(mock(Image.class));
CmSyncOperationSummary cmSyncOperationSummary = underTest.syncFromCmToDb(stack, candidateImages);
CmSyncOperationStatus cmSyncOperationStatus = cmSyncOperationSummary.getSyncOperationStatus();
assertFalse(cmSyncOperationStatus.hasSucceeded());
assertEquals("CM server is down, it is not possible to sync parcels and CM version from the server.", cmSyncOperationStatus.getMessage());
verify(cmServerQueryService).isCmServerRunning(eq(stack));
verify(cmInstalledComponentFinderService, never()).findCmRepoComponent(any(), any());
verify(cmInstalledComponentFinderService, never()).findParcelComponents(any(), any());
verify(cmSyncOperationSummaryService, never()).evaluate(any());
}
use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary in project cloudbreak by hortonworks.
the class CmSyncerServiceTest method testSyncFromCmToDbWhenNoCandidateImagesThenSyncSkipped.
@Test
void testSyncFromCmToDbWhenNoCandidateImagesThenSyncSkipped() {
when(cmServerQueryService.isCmServerRunning(stack)).thenReturn(true);
Set<Image> candidateImages = Set.of();
CmSyncOperationSummary cmSyncOperationSummary = underTest.syncFromCmToDb(stack, candidateImages);
CmSyncOperationStatus cmSyncOperationStatus = cmSyncOperationSummary.getSyncOperationStatus();
assertFalse(cmSyncOperationStatus.hasSucceeded());
assertEquals("No candidate images supplied for CM sync, it is not possible to sync parcels and CM version from the server. Please call Cloudera support", cmSyncOperationStatus.getMessage());
verify(cmServerQueryService).isCmServerRunning(eq(stack));
verify(cmInstalledComponentFinderService, never()).findCmRepoComponent(any(), any());
verify(cmInstalledComponentFinderService, never()).findParcelComponents(any(), any());
verify(cmSyncOperationSummaryService, never()).evaluate(any());
}
use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary in project cloudbreak by hortonworks.
the class CmSyncerServiceTest method testSyncFromCmToDbWhenCmServerRunningThenSyncIsExecuted.
@Test
void testSyncFromCmToDbWhenCmServerRunningThenSyncIsExecuted() {
when(cmServerQueryService.isCmServerRunning(stack)).thenReturn(true);
Set<Image> candidateImages = Set.of(mock(Image.class));
CmRepoSyncOperationResult cmRepoSyncOperationResult = mock(CmRepoSyncOperationResult.class);
CmParcelSyncOperationResult cmParcelSyncOperationResult = mock(CmParcelSyncOperationResult.class);
when(stack.getId()).thenReturn(STACK_ID);
when(cmInstalledComponentFinderService.findCmRepoComponent(stack, candidateImages)).thenReturn(cmRepoSyncOperationResult);
when(cmInstalledComponentFinderService.findParcelComponents(stack, candidateImages)).thenReturn(cmParcelSyncOperationResult);
when(cmSyncOperationSummaryService.evaluate(any())).thenReturn(CmSyncOperationStatus.builder().withSuccess("myMessage").build());
CmSyncOperationSummary cmSyncOperationSummary = underTest.syncFromCmToDb(stack, candidateImages);
CmSyncOperationStatus cmSyncOperationStatus = cmSyncOperationSummary.getSyncOperationStatus();
assertTrue(cmSyncOperationStatus.hasSucceeded());
assertEquals("myMessage", cmSyncOperationStatus.getMessage());
verify(cmInstalledComponentFinderService).findCmRepoComponent(stack, candidateImages);
verify(cmInstalledComponentFinderService).findParcelComponents(stack, candidateImages);
verify(stack).getId();
verify(mixedPackageVersionService).validatePackageVersions(eq(STACK_ID), any(), eq(candidateImages));
verifyEvaluateCmSyncResults(cmRepoSyncOperationResult, cmParcelSyncOperationResult);
verifyPersistComponentsToDb(cmRepoSyncOperationResult, cmParcelSyncOperationResult);
}
use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary in project cloudbreak by hortonworks.
the class CmSyncHandlerTest method testAcceptWhenSuccess.
@Test
void testAcceptWhenSuccess() {
Set<String> candidateImageUuids = Set.of(IMAGE_UUID_1);
HandlerEvent<CmSyncRequest> event = getCmSyncRequestHandlerEvent(candidateImageUuids);
Stack stack = new Stack();
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
Set<Image> foundImages = Set.of(mock(Image.class));
when(cmSyncImageCollectorService.collectImages(USER_CRN, stack, candidateImageUuids)).thenReturn(foundImages);
CmSyncOperationStatus cmSyncOperationStatus = CmSyncOperationStatus.builder().withSuccess("").build();
CmSyncOperationSummary cmSyncOperationSummary = new CmSyncOperationSummary(cmSyncOperationStatus);
when(cmSyncerService.syncFromCmToDb(stack, foundImages)).thenReturn(cmSyncOperationSummary);
Selectable result = underTest.doAccept(event);
assertEquals("CMSYNCRESULT", result.selector());
verify(stackService).getByIdWithListsInTransaction(STACK_ID);
verify(cmSyncImageCollectorService).collectImages(USER_CRN, stack, candidateImageUuids);
verify(cmSyncerService).syncFromCmToDb(stack, foundImages);
}
use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary in project cloudbreak by hortonworks.
the class CmSyncHandlerTest method testAcceptWhenOperationSummaryIsFail.
@Test
void testAcceptWhenOperationSummaryIsFail() {
Set<String> candidateImageUuids = Set.of(IMAGE_UUID_1);
HandlerEvent<CmSyncRequest> event = getCmSyncRequestHandlerEvent(candidateImageUuids);
Stack stack = new Stack();
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
Set<Image> foundImages = Set.of(mock(Image.class));
when(cmSyncImageCollectorService.collectImages(USER_CRN, stack, candidateImageUuids)).thenReturn(foundImages);
CmSyncOperationStatus cmSyncOperationStatus = CmSyncOperationStatus.builder().withError("My error description").build();
CmSyncOperationSummary cmSyncOperationSummary = new CmSyncOperationSummary(cmSyncOperationStatus);
when(cmSyncerService.syncFromCmToDb(stack, foundImages)).thenReturn(cmSyncOperationSummary);
CmSyncResult result = (CmSyncResult) underTest.doAccept(event);
assertEquals("CMSYNCRESULT_ERROR", result.selector());
assertThat(result.getErrorDetails(), instanceOf(CloudbreakServiceException.class));
assertEquals("My error description", result.getErrorDetails().getMessage());
assertEquals("My error description", result.getStatusReason());
}
Aggregations