Search in sources :

Example 1 with CmSyncOperationStatus

use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus 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());
}
Also used : CmSyncOperationStatus(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CmSyncOperationSummary(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary) Test(org.junit.jupiter.api.Test)

Example 2 with CmSyncOperationStatus

use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus 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());
}
Also used : CmSyncOperationStatus(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CmSyncOperationSummary(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary) Test(org.junit.jupiter.api.Test)

Example 3 with CmSyncOperationStatus

use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus 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);
}
Also used : CmSyncOperationStatus(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus) CmParcelSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmParcelSyncOperationResult) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CmRepoSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmRepoSyncOperationResult) CmSyncOperationSummary(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary) Test(org.junit.jupiter.api.Test)

Example 4 with CmSyncOperationStatus

use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus 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);
}
Also used : CmSyncOperationStatus(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus) CmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CmSyncOperationSummary(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with CmSyncOperationStatus

use of com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus 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());
}
Also used : CmSyncResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult) CmSyncOperationStatus(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus) CmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CmSyncOperationSummary(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

CmSyncOperationStatus (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus)7 CmSyncOperationSummary (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary)7 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)6 Test (org.junit.jupiter.api.Test)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 CmSyncRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 CmSyncResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 CmParcelSyncOperationResult (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmParcelSyncOperationResult)1 CmRepoSyncOperationResult (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmRepoSyncOperationResult)1 CmSyncOperationResult (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationResult)1