use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest in project cloudbreak by hortonworks.
the class CmSyncActions method cmSync.
@Bean(name = "CM_SYNC_STATE")
public Action<?, ?> cmSync() {
return new AbstractCmSyncAction<>(CmSyncTriggerEvent.class) {
@Override
protected void doExecute(CmSyncContext context, CmSyncTriggerEvent payload, Map<Object, Object> variables) {
CmSyncRequest cmSyncRequest = new CmSyncRequest(context.getStack().getId(), payload.getCandidateImageUuids(), context.getFlowTriggerUserCrn());
sendEvent(context, cmSyncRequest.selector(), cmSyncRequest);
}
};
}
use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest 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.reactor.api.event.resource.CmSyncRequest 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.CmSyncRequest in project cloudbreak by hortonworks.
the class CmSyncHandlerTest method getCmSyncRequestHandlerEvent.
private HandlerEvent<CmSyncRequest> getCmSyncRequestHandlerEvent(Set<String> candidateImageUuids) {
CmSyncRequest cmSyncRequest = new CmSyncRequest(STACK_ID, candidateImageUuids, USER_CRN);
HandlerEvent<CmSyncRequest> event = mock(HandlerEvent.class);
when(event.getData()).thenReturn(cmSyncRequest);
return event;
}
use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest 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);
}
}
Aggregations