Search in sources :

Example 1 with SdxWaitException

use of com.sequenceiq.datalake.service.sdx.flowwait.exception.SdxWaitException in project cloudbreak by hortonworks.

the class SdxCmSyncWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<SdxCmSyncWaitEvent> event) {
    LOGGER.debug("Entering handler for calling sync CM and parcel versions from CM server");
    SdxCmSyncWaitEvent sdxCmSyncWaitEvent = event.getData();
    try {
        SdxCluster sdxCluster = sdxService.getById(sdxCmSyncWaitEvent.getResourceId());
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES).withStopPollingIfExceptionOccurred(true);
        sdxWaitService.waitForCloudbreakFlow(sdxCluster, pollingConfig, "Sync cm");
        return new SdxEvent(SDX_CM_SYNC_FINISHED_EVENT.event(), event.getData().getResourceId(), event.getData().getUserId());
    } catch (SdxWaitException e) {
        LOGGER.warn("Error happened during waiting for syncing CM and parcel versions from a datalake CM to component table {}, error: ", sdxCmSyncWaitEvent.getResourceId(), e);
        return new SdxCmSyncFailedEvent(sdxCmSyncWaitEvent.getResourceId(), sdxCmSyncWaitEvent.getUserId(), e);
    }
}
Also used : SdxCmSyncWaitEvent(com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncWaitEvent) SdxWaitException(com.sequenceiq.datalake.service.sdx.flowwait.exception.SdxWaitException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) SdxCmSyncFailedEvent(com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncFailedEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig)

Example 2 with SdxWaitException

use of com.sequenceiq.datalake.service.sdx.flowwait.exception.SdxWaitException in project cloudbreak by hortonworks.

the class SdxCmSyncWaitHandlerTest method testAcceptWhenSdxWaitServiceThrows.

@Test
void testAcceptWhenSdxWaitServiceThrows() {
    ReflectionTestUtils.setField(underTest, "sleepTimeInSec", SLEEP_TIME_IN_SEC);
    ReflectionTestUtils.setField(underTest, "durationInMinutes", DURATION_IN_MINUTES);
    SdxCluster sdxCluster = new SdxCluster();
    when(sdxService.getById(SDX_ID)).thenReturn(sdxCluster);
    doThrow(new SdxWaitException("Polling threw", new RuntimeException())).when(sdxWaitService).waitForCloudbreakFlow(eq(sdxCluster), any(), eq(SYNC_CM));
    Selectable nextEvent = underTest.doAccept(getEvent());
    assertEquals("SDXCMSYNCFAILEDEVENT", nextEvent.selector());
    assertEquals(SDX_ID, nextEvent.getResourceId());
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) SdxWaitException(com.sequenceiq.datalake.service.sdx.flowwait.exception.SdxWaitException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Test(org.junit.jupiter.api.Test)

Example 3 with SdxWaitException

use of com.sequenceiq.datalake.service.sdx.flowwait.exception.SdxWaitException in project cloudbreak by hortonworks.

the class SdxWaitTaskService method waitFor.

/**
 * Will start a wait task on an SDX cluster.
 * For the frequency of checks and the total amount of time allowed for the task, please check {@linkplain PollingConfig} in the waitTask
 *
 * This wait service uses {@linkplain com.dyngr.Polling} as the underlying polling mechanism, meaning:
 * - if the polling succeeds, the method returns
 * - if there is a timeout, or the wait task wants to indicate a negative result, then an exception is thrown of type {@linkplain PollerException}
 * - optionally you can set to stop on any encountered exceptions, check {@linkplain PollingConfig.stopPollingIfExceptionOccured} for that
 *
 * @param sdxWaitTask A wait task with polling parameters as well as the algorithm for polling itself
 * @param <V> The type of parameter returned by the underlying poller package's AttemptMaker interface, hidden from outside world
 * @throws SdxWaitException is thrown if a {@linkplain PollerException} is reached
 */
public <V> void waitFor(SdxWaitTask<V> sdxWaitTask) {
    try {
        LOGGER.debug("Starting an sdx wait task: {}", sdxWaitTask);
        PollingConfig pollingConfig = sdxWaitTask.getPollingConfig();
        Polling.waitPeriodly(pollingConfig.getSleepTime(), pollingConfig.getSleepTimeUnit()).stopIfException(pollingConfig.getStopPollingIfExceptionOccurred()).stopAfterDelay(pollingConfig.getDuration(), pollingConfig.getDurationTimeUnit()).run(sdxWaitTask);
    } catch (PollerException e) {
        LOGGER.warn("Polling of {} reached an exception: ", sdxWaitTask.getPollingMessage(), e);
        throw new SdxWaitException(String.format("Polling of %s reached an error state.", sdxWaitTask.getPollingMessage()), e);
    }
}
Also used : PollerException(com.dyngr.exception.PollerException) SdxWaitException(com.sequenceiq.datalake.service.sdx.flowwait.exception.SdxWaitException) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig)

Aggregations

SdxWaitException (com.sequenceiq.datalake.service.sdx.flowwait.exception.SdxWaitException)3 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)2 PollerException (com.dyngr.exception.PollerException)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)1 SdxCmSyncFailedEvent (com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncFailedEvent)1 SdxCmSyncWaitEvent (com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncWaitEvent)1 Test (org.junit.jupiter.api.Test)1