use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class SaltCheckerConclusionStepTest method checkShouldFallbackIfNodeStatusCheckFailsAndBeSuccessfulIfNoUnreachableNodeFound.
@Test
public void checkShouldFallbackIfNodeStatusCheckFailsAndBeSuccessfulIfNoUnreachableNodeFound() throws NodesUnreachableException {
when(nodeStatusService.saltPing(eq(1L))).thenThrow(new CloudbreakServiceException("error"));
when(stackService.getByIdWithListsInTransaction(eq(1L))).thenReturn(new Stack());
Set<Node> nodes = Set.of(createNode("host1"), createNode("host2"));
when(stackUtil.collectNodes(any())).thenReturn(nodes);
when(stackUtil.collectAndCheckReachableNodes(any(), anyCollection())).thenReturn(nodes);
Conclusion stepResult = underTest.check(1L);
assertFalse(stepResult.isFailureFound());
assertNull(stepResult.getConclusion());
assertNull(stepResult.getDetails());
assertEquals(SaltCheckerConclusionStep.class, stepResult.getConclusionStepClass());
verify(nodeStatusService, times(1)).saltPing(eq(1L));
verify(stackService, times(1)).getByIdWithListsInTransaction(eq(1L));
verify(stackUtil, times(1)).collectNodes(any());
verify(stackUtil, times(1)).collectAndCheckReachableNodes(any(), any());
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ProxyConfigDtoServiceTest method testGetWhenSecretCouldNotBeFetchedFromVault.
@Test
void testGetWhenSecretCouldNotBeFetchedFromVault() {
String name = "aProxyConfig";
String host = "https://test.cloudera.com";
Integer port = 8443;
SecretResponse secretResponse = new SecretResponse();
ProxyResponse proxyResponse = new ProxyResponse();
proxyResponse.setName(name);
proxyResponse.setHost(host);
proxyResponse.setPort(port);
proxyResponse.setUserName(secretResponse);
proxyResponse.setPassword(secretResponse);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
when(secretService.getByResponse(any(SecretResponse.class))).thenThrow(new VaultException("Vault token is invalid!"));
CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad"));
assertEquals("Failed to get Proxy config related secret due to: 'Vault token is invalid!' ", exception.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class Flow2Handler method doAccept.
private void doAccept(Event<? extends Payload> event, String key, Payload payload, String flowChainId, String flowChainType, FlowParameters flowParameters) {
try {
if (FLOW_CANCEL.equals(key)) {
cancelRunningFlows(payload.getResourceId());
} else if (FLOW_FINAL.equals(key)) {
finalizeFlow(flowParameters, flowChainId, payload.getResourceId(), getContextParams(event));
} else if (flowParameters.getFlowId() == null) {
AcceptResult result = handleNewFlowRequest(key, payload, flowParameters, flowChainId, flowChainType, getContextParams(event));
LOGGER.info("Create new flow result {}", result);
if (isAcceptablePayload(payload)) {
((Acceptable) payload).accepted().accept(result);
}
} else {
handleFlowControlEvent(key, payload, flowParameters, flowChainId);
}
} catch (FlowNotTriggerableException e) {
LOGGER.error("Failed to handle flow event.", e);
if (isAcceptablePayload(payload)) {
((Acceptable) payload).accepted().onError(e);
} else {
throw e;
}
} catch (CloudbreakServiceException e) {
LOGGER.error("Failed to handle flow event.", e);
throw e;
} catch (Exception e) {
LOGGER.error("Failed to handle flow event.", e);
throw new CloudbreakServiceException(e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class CDPStructuredEventDBService method getPagedEventsOfResources.
@Override
public <T extends CDPStructuredEvent> Page<T> getPagedEventsOfResources(List<StructuredEventType> eventTypes, List<String> resourceCrns, Pageable pageable) {
LOGGER.debug("Gathering pageable events for types: '{}' and resource CRNs: '{}'", eventTypes, resourceCrns);
List<StructuredEventType> types = getAllEventTypeIfEmpty(eventTypes);
try {
Page<CDPStructuredEventEntity> events = pagingStructuredEventRepository.findByEventTypeInAndResourceCrnIn(types, resourceCrns, pageable);
return (Page<T>) Optional.ofNullable(events).orElse(Page.empty()).map(event -> cdpStructuredEventEntityToCDPStructuredEventConverter.convert(event));
} catch (Exception ex) {
String msg = String.format("Failed get pageable events for types: '%s' and resource CRNs: '%s'", types, resourceCrns);
LOGGER.warn(msg, ex);
throw new CloudbreakServiceException(msg, ex);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackImageUpdateActionsTest method handleImageUpdateFailure.
@Test
public void handleImageUpdateFailure() {
FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(flowEvent.name()).thenReturn(EVENT_NAME);
StackFailureEvent payload = new StackFailureEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT.event(), 1L, new CloudbreakServiceException("test"));
when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
when(state.getId()).thenReturn(StackImageUpdateState.STACK_IMAGE_UPDATE_FAILED_STATE);
when(stackService.getViewByIdWithoutAuth(anyLong())).thenReturn(new StackView(1L, null, null, null));
when(runningFlows.get(anyString())).thenReturn(flow);
handleImageUpdateFailureAction.execute(stateContext);
verify(flowMessageService, times(1)).fireEventAndLog(anyLong(), eq(Status.UPDATE_FAILED.name()), eq(ResourceEvent.STACK_IMAGE_UPDATE_FAILED), eq("test"));
verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILE_HANDLED_EVENT.event()), any(Event.class));
verify(stackUpdater).updateStackStatus(eq(1L), eq(DetailedStackStatus.STACK_IMAGE_UPDATE_FAILED), eq("test"));
verifyNoInteractions(componentConfigProviderService);
}
Aggregations