Search in sources :

Example 41 with CloudbreakServiceException

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());
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 42 with CloudbreakServiceException

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());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) VaultException(org.springframework.vault.VaultException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with CloudbreakServiceException

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);
    }
}
Also used : FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) FlowNotFoundException(com.sequenceiq.flow.core.exception.FlowNotFoundException) FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 44 with CloudbreakServiceException

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);
    }
}
Also used : CDPStructuredEventEntityToCDPStructuredEventConverter(com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventEntityToCDPStructuredEventConverter) CDPStructuredEventService(com.sequenceiq.cloudbreak.structuredevent.service.CDPStructuredEventService) LoggerFactory(org.slf4j.LoggerFactory) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AccountAwareResourceRepository(com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository) Pageable(org.springframework.data.domain.Pageable) AnonymizerUtil(com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil) CDPStructuredEventRepository(com.sequenceiq.cloudbreak.structuredevent.repository.CDPStructuredEventRepository) Logger(org.slf4j.Logger) CDPPagingStructuredEventRepository(com.sequenceiq.cloudbreak.structuredevent.repository.CDPPagingStructuredEventRepository) Page(org.springframework.data.domain.Page) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) List(java.util.List) Component(org.springframework.stereotype.Component) CollectionUtils(org.springframework.util.CollectionUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Optional(java.util.Optional) CDPStructuredEventToCDPStructuredEventEntityConverter(com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventToCDPStructuredEventEntityConverter) AbstractAccountAwareResourceService(com.sequenceiq.cloudbreak.common.service.account.AbstractAccountAwareResourceService) StringUtils(org.springframework.util.StringUtils) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) Page(org.springframework.data.domain.Page) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 45 with CloudbreakServiceException

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);
}
Also used : FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Test(org.junit.Test)

Aggregations

CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)142 Test (org.junit.jupiter.api.Test)25 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)24 List (java.util.List)20 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 IOException (java.io.IOException)18 Map (java.util.Map)18 ApiException (com.cloudera.api.swagger.client.ApiException)17 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)16 Collectors (java.util.stream.Collectors)15 Inject (javax.inject.Inject)15 Logger (org.slf4j.Logger)15 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)14 LoggerFactory (org.slf4j.LoggerFactory)14 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)13 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)12 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)12 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)12 Optional (java.util.Optional)12 Set (java.util.Set)12