Search in sources :

Example 1 with CmSyncRequest

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);
        }
    };
}
Also used : CmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest) CmSyncTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.CmSyncTriggerEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with 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);
}
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 3 with CmSyncRequest

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());
}
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 4 with CmSyncRequest

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;
}
Also used : CmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest)

Example 5 with CmSyncRequest

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

Aggregations

CmSyncRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest)6 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 CmSyncResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult)3 CmSyncOperationStatus (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationStatus)3 CmSyncOperationSummary (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationSummary)3 Test (org.junit.jupiter.api.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 CmSyncTriggerEvent (com.sequenceiq.cloudbreak.reactor.api.event.orchestration.CmSyncTriggerEvent)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1