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());
}
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);
}
}
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());
}
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());
}
Aggregations