Search in sources :

Example 76 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class StackCreationService method checkImage.

public CheckImageResult checkImage(StackContext context) {
    try {
        Stack stack = context.getStack();
        Image image = imageService.getImage(stack.getId());
        CheckImageRequest<CheckImageResult> checkImageRequest = new CheckImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStackConverter.convert(stack), image);
        LOGGER.debug("Triggering event: {}", checkImageRequest);
        eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
        CheckImageResult result = checkImageRequest.await();
        sendNotificationIfNecessary(result, stack);
        LOGGER.debug("Result: {}", result);
        return result;
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing check image", e);
        throw new OperationException(e);
    } catch (CloudbreakImageNotFoundException e) {
        throw new CloudbreakServiceException(e);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest)

Example 77 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class StackSyncService method updateInstances.

public void updateInstances(Stack stack, Iterable<InstanceMetaData> instanceMetaDataList, Collection<CloudVmInstanceStatus> instanceStatuses, SyncConfig syncConfig) {
    try {
        Map<InstanceSyncState, Integer> counts = initInstanceStateCounts();
        Json imageJson = new Json(imageService.getImage(stack.getId()));
        for (InstanceMetaData metaData : instanceMetaDataList) {
            Optional<CloudVmInstanceStatus> status = instanceStatuses.stream().filter(is -> is != null && is.getCloudInstance().getInstanceId() != null && is.getCloudInstance().getInstanceId().equals(metaData.getInstanceId())).findFirst();
            InstanceSyncState state;
            if (status.isPresent()) {
                CloudVmInstanceStatus cloudVmInstanceStatus = status.get();
                CloudInstance cloudInstance = cloudVmInstanceStatus.getCloudInstance();
                state = InstanceSyncState.getInstanceSyncState(cloudVmInstanceStatus.getStatus());
                syncInstance(metaData, cloudInstance, imageJson);
            } else {
                state = InstanceSyncState.DELETED;
            }
            try {
                syncInstanceStatusByState(stack, counts, metaData, state);
            } catch (TransactionRuntimeExecutionException e) {
                LOGGER.error("Can't sync instance status by state!", e);
            }
        }
        handleSyncResult(stack, counts, syncConfig);
    } catch (CloudbreakImageNotFoundException | IllegalArgumentException ex) {
        LOGGER.info("Error during stack sync:", ex);
        throw new CloudbreakServiceException("Stack sync failed", ex);
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) STACK_SYNC_INSTANCE_DELETED_CBMETADATA(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_SYNC_INSTANCE_DELETED_CBMETADATA) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Service(org.springframework.stereotype.Service) STACK_SYNC_INSTANCE_DELETED_BY_PROVIDER_CBMETADATA(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_SYNC_INSTANCE_DELETED_BY_PROVIDER_CBMETADATA) Map(java.util.Map) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) INSTANCE_NAME(com.sequenceiq.cloudbreak.cloud.model.CloudInstance.INSTANCE_NAME) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) Logger(org.slf4j.Logger) EnumMap(java.util.EnumMap) Collection(java.util.Collection) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) Collectors(java.util.stream.Collectors) CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) NODE_FAILURE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.NODE_FAILURE) STACK_SYNC_INSTANCE_STATUS_RETRIEVAL_FAILED(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_SYNC_INSTANCE_STATUS_RETRIEVAL_FAILED) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) DELETE_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.DELETE_FAILED) WAIT_FOR_SYNC(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.WAIT_FOR_SYNC) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Optional(java.util.Optional) UNREACHABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UNREACHABLE) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED) Collections(java.util.Collections) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Json(com.sequenceiq.cloudbreak.common.json.Json) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)

Example 78 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class ClusterTemplateService method listInWorkspaceAndCleanUpInvalids.

public Set<ClusterTemplateViewV4Response> listInWorkspaceAndCleanUpInvalids(Long workspaceId, String accountId) {
    try {
        boolean internalTenant = entitlementService.internalTenant(accountId);
        Set<ClusterTemplateView> views = transactionService.required(() -> clusterTemplateViewService.findAllActive(workspaceId, internalTenant));
        Set<ClusterTemplateViewV4Response> responses = transactionService.required(() -> views.stream().map(v -> clusterTemplateViewToClusterTemplateViewV4ResponseConverter.convert(v)).collect(toSet()));
        environmentServiceDecorator.prepareEnvironments(responses);
        cleanUpInvalidClusterDefinitions(workspaceId, responses);
        return responses.stream().filter(this::isUsableClusterTemplate).filter(this::isClusterTemplateHasValidCloudPlatform).collect(toSet());
    } catch (TransactionExecutionException e) {
        LOGGER.warn("Unable to find cluster definitions due to {}", e.getMessage());
        LOGGER.warn("Unable to find cluster definitions", e);
        throw new CloudbreakServiceException("Unable to obtain cluster definitions!");
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) ClusterTemplateViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response)

Example 79 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class ClusterHostServiceRunnerTest method collectAndCheckReachableNodesThrowsException.

@Test
void collectAndCheckReachableNodesThrowsException() throws NodesUnreachableException {
    Set<String> unreachableNodes = new HashSet<>();
    unreachableNodes.add("node1.example.com");
    when(stackUtil.collectAndCheckReachableNodes(eq(stack), any())).thenThrow(new NodesUnreachableException("error", unreachableNodes));
    CloudbreakServiceException cloudbreakServiceException = Assertions.assertThrows(CloudbreakServiceException.class, () -> underTest.runClusterServices(stack, cluster, Map.of()));
    assertEquals("Can not run cluster services on new nodes because the configuration management service is not responding on these nodes: " + "[node1.example.com]", cloudbreakServiceException.getMessage());
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) NodesUnreachableException(com.sequenceiq.cloudbreak.util.NodesUnreachableException) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 80 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class CmSyncHandlerTest method testAcceptWhenStackNotFound.

@Test
void testAcceptWhenStackNotFound() {
    Set<String> candidateImageUuids = Set.of(IMAGE_UUID_1);
    HandlerEvent<CmSyncRequest> event = getCmSyncRequestHandlerEvent(candidateImageUuids);
    Exception exception = new CloudbreakServiceException("errordetail");
    when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenThrow(exception);
    CmSyncResult result = (CmSyncResult) underTest.doAccept(event);
    assertEquals("CMSYNCRESULT_ERROR", result.selector());
    assertThat(result.getErrorDetails(), instanceOf(CloudbreakServiceException.class));
    assertEquals("unexpected error: errordetail", result.getErrorDetails().getMessage());
    assertEquals("unexpected error: errordetail", result.getStatusReason());
    verify(stackService).getByIdWithListsInTransaction(STACK_ID);
    verify(cmSyncImageCollectorService, never()).collectImages(anyString(), any(), any());
    verify(cmSyncerService, never()).syncFromCmToDb(any(), any());
}
Also used : CmSyncResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncResult) CmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CmSyncRequest) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Test(org.junit.jupiter.api.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