Search in sources :

Example 1 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class StackTerminationService method handleStackTerminationError.

public void handleStackTerminationError(StackView stackView, Exception errorDetails, boolean forced) {
    Long stackId = stackView.getId();
    String stackUpdateMessage;
    ResourceEvent resourceEvent;
    DetailedStackStatus status;
    if (!forced) {
        stackUpdateMessage = "Termination failed: " + errorDetails.getMessage();
        status = DetailedStackStatus.DELETE_FAILED;
        resourceEvent = STACK_INFRASTRUCTURE_DELETE_FAILED;
        stackUpdater.updateStackStatus(stackId, status, stackUpdateMessage);
        LOGGER.debug("Error during stack termination flow: ", errorDetails);
    } else {
        clusterService.updateClusterStatusByStackId(stackId, DetailedStackStatus.CLUSTER_DELETE_COMPLETED);
        terminationService.finalizeTermination(stackId, true);
        stackUpdateMessage = "Stack was force terminated.";
        status = DetailedStackStatus.DELETE_COMPLETED;
        resourceEvent = STACK_FORCED_DELETE_COMPLETED;
    }
    flowMessageService.fireEventAndLog(stackId, status.name(), resourceEvent, stackUpdateMessage);
    metricService.incrementMetricCounter(MetricType.STACK_TERMINATION_FAILED, stackView, errorDetails);
}
Also used : ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)

Example 2 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class ClusterOperationService method updateAutoRecoverableNodes.

private void updateAutoRecoverableNodes(Cluster cluster, Map<String, List<String>> autoRecoveryNodesMap, Map<String, InstanceMetaData> autoRecoveryHostMetadata) throws TransactionExecutionException {
    if (!autoRecoveryNodesMap.isEmpty()) {
        flowManager.triggerClusterRepairFlow(cluster.getStack().getId(), autoRecoveryNodesMap, false);
        Map<String, Optional<String>> hostNamesWithReason = autoRecoveryHostMetadata.keySet().stream().collect(Collectors.toMap(host -> host, host -> Optional.empty()));
        Set<InstanceStatus> expectedStates = Set.of(SERVICES_HEALTHY);
        InstanceStatus newState = InstanceStatus.WAITING_FOR_REPAIR;
        ResourceEvent clusterEvent = CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT;
        ResourceEvent hostEvent = CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT;
        updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.of(hostEvent));
    }
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) SERVICES_RUNNING(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) SERVICES_UNHEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY) LoggerFactory(org.slf4j.LoggerFactory) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) Math.abs(java.lang.Math.abs) Measure(com.sequenceiq.cloudbreak.aspect.Measure) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) StatusRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.StatusRequest) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Map(java.util.Map) CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) EnumSet(java.util.EnumSet) RecoveryMode(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.RecoveryMode) CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) SERVICES_HEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY) FileSystemConfigService(com.sequenceiq.cloudbreak.service.filesystem.FileSystemConfigService) Collection(java.util.Collection) CLUSTER_STOP_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_STOP_IGNORED) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Sets(com.google.common.collect.Sets) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT) START_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.START_IN_PROGRESS) CMRepositoryVersionUtil(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) HashMap(java.util.HashMap) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) StackStopRestrictionService(com.sequenceiq.cloudbreak.service.stack.StackStopRestrictionService) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ResourceType(com.sequenceiq.common.api.type.ResourceType) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DECOMMISSION_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DECOMMISSION_FAILED) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) BlueprintValidator(com.sequenceiq.cloudbreak.template.validation.BlueprintValidator) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) IOException(java.io.IOException) CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) NotAllowedStatusUpdate(com.sequenceiq.cloudbreak.util.NotAllowedStatusUpdate) User(com.sequenceiq.cloudbreak.workspace.model.User) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CLUSTER_START_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_START_IGNORED) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) UsageLoggingUtil(com.sequenceiq.cloudbreak.util.UsageLoggingUtil) BlueprintValidatorFactory(com.sequenceiq.cloudbreak.service.blueprint.BlueprintValidatorFactory) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED) Collections(java.util.Collections) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Optional(java.util.Optional) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent)

Example 3 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class InteractiveCredentialCreationStatusHandler method accept.

@Override
public void accept(Event<InteractiveCredentialCreationStatus> interactiveCredentialCreationStatusEvent) {
    InteractiveCredentialCreationStatus interactiveCredentialCreationStatus = interactiveCredentialCreationStatusEvent.getData();
    String userCrn = interactiveCredentialCreationStatus.getExtendedCloudCredential().getUserCrn();
    ThreadBasedUserCrnProvider.doAs(userCrn, () -> {
        String message = interactiveCredentialCreationStatus.getMessage();
        InteractiveCredentialNotification notification = new InteractiveCredentialNotification().withEventTimestamp(new Date().getTime()).withUserId(interactiveCredentialCreationStatus.getExtendedCloudCredential().getUserCrn()).withCloud(interactiveCredentialCreationStatus.getExtendedCloudCredential().getCloudPlatform()).withEventMessage(message);
        ResourceEvent event;
        if (interactiveCredentialCreationStatus.isError()) {
            event = CREDENTIAL_AZURE_INTERACTIVE_FAILED;
            notification.withEventType(event.name());
            LOGGER.info("Interactive credential creation failed status: {}", new Json(notification).getValue());
        } else {
            event = CREDENTIAL_AZURE_INTERACTIVE_STATUS;
            notification.withEventType(event.name());
            LOGGER.info("Interactive credential creation success status: {}", new Json(notification).getValue());
        }
        notificationService.send(event, notification, ThreadBasedUserCrnProvider.getUserCrn());
    });
}
Also used : InteractiveCredentialCreationStatus(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Json(com.sequenceiq.cloudbreak.common.json.Json) Date(java.util.Date)

Example 4 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class EnvStopActions method stopDatalake.

@Bean(name = "STOP_DATALAKE_STATE")
public Action<?, ?> stopDatalake() {
    return new AbstractEnvStopAction<>(EnvStopEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStopEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.STOP_DATALAKE_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_STOP_DATALAKE_STARTED;
            EnvStopState envStopState = EnvStopState.STOP_DATALAKE_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStopState);
            sendEvent(context, EnvStopHandlerSelectors.STOP_DATALAKE_HANDLER_EVENT.selector(), envDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 5 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class EnvStartActions method startFreeipa.

@Bean(name = "START_FREEIPA_STATE")
public Action<?, ?> startFreeipa() {
    return new AbstractEnvStartAction<>(EnvStartEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStartEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.START_FREEIPA_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_START_FREEIPA_STARTED;
            EnvStartState envStartState = EnvStartState.START_FREEIPA_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStartState);
            EnvironmentStartDto environmentStartDto = EnvironmentStartDto.builder().withDataHubStart(payload.getDataHubStartAction()).withEnvironmentDto(envDto).withId(envDto.getId()).build();
            sendEvent(context, EnvStartHandlerSelectors.START_FREEIPA_HANDLER_EVENT.selector(), environmentStartDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) EnvironmentStartDto(com.sequenceiq.environment.environment.dto.EnvironmentStartDto) Bean(org.springframework.context.annotation.Bean)

Aggregations

ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)20 Map (java.util.Map)15 Bean (org.springframework.context.annotation.Bean)12 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)11 CommonContext (com.sequenceiq.flow.core.CommonContext)11 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)9 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)4 Sets (com.google.common.collect.Sets)3 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)3 AVAILABLE (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE)3 START_IN_PROGRESS (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.START_IN_PROGRESS)3 STOPPED (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED)3 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)3 DECOMMISSION_FAILED (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DECOMMISSION_FAILED)3 FAILED (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED)3 SERVICES_HEALTHY (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY)3 SERVICES_RUNNING (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING)3 SERVICES_UNHEALTHY (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY)3 RecoveryMode (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.RecoveryMode)3 StatusRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.StatusRequest)3