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