Search in sources :

Example 1 with CmSyncResult

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult 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)

Example 2 with CmSyncResult

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult in project cloudbreak by hortonworks.

the class CmSyncHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<CmSyncRequest> event) {
    CmSyncRequest request = event.getData();
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        Set<Image> candidateImages = cmSyncImageCollectorService.collectImages(request.getFlowTriggerUserCrn(), stack, request.getCandidateImageUuids());
        CmSyncOperationSummary cmSyncOperationSummary = cmSyncerService.syncFromCmToDb(stack, candidateImages);
        CmSyncOperationStatus cmSyncOperationStatus = cmSyncOperationSummary.getSyncOperationStatus();
        if (!cmSyncOperationStatus.hasSucceeded()) {
            LOGGER.debug("Reading CM and active parcel versions from CM server encountered failures. Details: {}", cmSyncOperationStatus.getMessage());
            Exception e = new CloudbreakServiceException(cmSyncOperationStatus.getMessage());
            return new CmSyncResult(cmSyncOperationStatus.getMessage(), e, request);
        }
        return new CmSyncResult(request, cmSyncOperationStatus.getMessage());
    } catch (Exception e) {
        LOGGER.warn("Reading CM and active parcel versions from CM server resulted in error ", e);
        String message = String.format("unexpected error: %s", e.getMessage());
        return new CmSyncResult(message, new CloudbreakServiceException(message, e), request);
    }
}
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) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CmSyncOperationSummary(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 3 with CmSyncResult

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult in project cloudbreak by hortonworks.

the class CmSyncHandler method defaultFailureEvent.

@Override
protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event<CmSyncRequest> event) {
    LOGGER.debug("Reading CM and active parcel versions from CM server encountered an unexpected error ", e);
    String message = String.format("unexpected error: %s", e.getMessage());
    return new CmSyncResult(message, new CloudbreakServiceException(message, e), event.getData());
}
Also used : CmSyncResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 4 with CmSyncResult

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult in project cloudbreak by hortonworks.

the class CmSyncHandlerTest method testAcceptWhenStackNotFound.

@Test
void testAcceptWhenStackNotFound() {
    Set<String> candidateImageUuids = Set.of(IMAGE_UUID_1);
    HandlerEvent<CmSyncRequest> event = getCmSyncRequestHandlerEvent(candidateImageUuids);
    Exception exception = new CloudbreakServiceException("errordetail");
    when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenThrow(exception);
    CmSyncResult result = (CmSyncResult) underTest.doAccept(event);
    assertEquals("CMSYNCRESULT_ERROR", result.selector());
    assertThat(result.getErrorDetails(), instanceOf(CloudbreakServiceException.class));
    assertEquals("unexpected error: errordetail", result.getErrorDetails().getMessage());
    assertEquals("unexpected error: errordetail", result.getStatusReason());
    verify(stackService).getByIdWithListsInTransaction(STACK_ID);
    verify(cmSyncImageCollectorService, never()).collectImages(anyString(), any(), any());
    verify(cmSyncerService, never()).syncFromCmToDb(any(), any());
}
Also used : CmSyncResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult) CmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Test(org.junit.jupiter.api.Test)

Aggregations

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