Search in sources :

Example 31 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class ClusterProxyService method registerGatewayConfiguration.

public void registerGatewayConfiguration(Long stackId) {
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    if (!stack.getCluster().hasGateway()) {
        LOGGER.warn("Cluster {} with crn {} in environment {} not configured with Gateway (Knox). Not updating Cluster Proxy with Gateway url.", stack.getCluster().getName(), stack.getResourceCrn(), stack.getEnvironmentCrn());
        return;
    }
    registerGateway(stack);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 32 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayService method primaryGatewayChanged.

public void primaryGatewayChanged(long stackId, String newPrimaryGatewayFQDN) throws CloudbreakException, TransactionExecutionException {
    LOGGER.info("Update primary gateway ip");
    Set<InstanceMetaData> imds = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
    Optional<InstanceMetaData> formerPrimaryGateway = imds.stream().filter(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).findFirst();
    Optional<InstanceMetaData> newPrimaryGateway = imds.stream().filter(imd -> imd.getDiscoveryFQDN() != null && imd.getDiscoveryFQDN().equals(newPrimaryGatewayFQDN)).findFirst();
    if (newPrimaryGateway.isPresent() && formerPrimaryGateway.isPresent()) {
        InstanceMetaData fpg = formerPrimaryGateway.get();
        fpg.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
        fpg.setServer(Boolean.FALSE);
        transactionService.required(() -> {
            instanceMetaDataService.save(fpg);
            InstanceMetaData npg = newPrimaryGateway.get();
            npg.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
            npg.setServer(Boolean.TRUE);
            instanceMetaDataService.save(npg);
            Stack updatedStack = stackService.getByIdWithListsInTransaction(stackId);
            String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(updatedStack);
            Cluster cluster = updatedStack.getCluster();
            cluster.setClusterManagerIp(gatewayIp);
            LOGGER.info("Primary gateway IP has been updated to: '{}'", gatewayIp);
            clusterService.save(cluster);
            clusterPublicEndpointManagementService.changeGateway(updatedStack);
            return null;
        });
    } else {
        throw new CloudbreakException("Primary gateway change was not successful.");
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) LoggerFactory(org.slf4j.LoggerFactory) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) CLUSTER_GATEWAY_CHANGE(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_GATEWAY_CHANGE) Inject(javax.inject.Inject) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) CLUSTER_GATEWAY_CHANGE_FAILED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_GATEWAY_CHANGE_FAILED) CLUSTER_GATEWAY_CHANGED_SUCCESSFULLY(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_GATEWAY_CHANGED_SUCCESSFULLY) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_FAILED) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) Logger(org.slf4j.Logger) Set(java.util.Set) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) Component(org.springframework.stereotype.Component) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 33 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class ClusterUpgradeExistingUpgradeCommandValidationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeExistingUpgradeCommandValidationEvent> event) {
    LOGGER.debug("Accepting Cluster upgrade existing upgradeCDH command validation event.");
    ClusterUpgradeExistingUpgradeCommandValidationEvent request = event.getData();
    Image targetImage = request.getImage();
    Long stackId = request.getResourceId();
    Stack stack = getStack(stackId);
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    Optional<ClusterManagerCommand> optionalUpgradeCommand = connector.clusterStatusService().findCommand(stack, ClusterCommandType.UPGRADE_CLUSTER);
    if (optionalUpgradeCommand.isEmpty()) {
        LOGGER.debug("There is no existing upgradeCDH command, validation passed successfully");
        return new ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(stackId);
    } else {
        ClusterManagerCommand upgradeCommand = optionalUpgradeCommand.get();
        if (upgradeCommand.getActive() || (!upgradeCommand.getSuccess() && upgradeCommand.getRetryable())) {
            return validateIfExistingRuntimeMatchesTargetRuntime(stack, connector, targetImage);
        } else {
            LOGGER.debug("There is no retryable upgradeCDH command, validation passed successfully");
            return new ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(stackId);
        }
    }
}
Also used : ClusterUpgradeExistingUpgradeCommandValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationEvent) ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 34 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class ClusterUpgradeActions method clusterUpgradeFailedAction.

@Bean(name = "CLUSTER_UPGRADE_FAILED_STATE")
public Action<?, ?> clusterUpgradeFailedAction() {
    return new AbstractClusterUpgradeAction<>(ClusterUpgradeFailedEvent.class) {

        @Value("${cb.upgrade.failure.sync.sdx.enabled}")
        private boolean syncAfterFailureEnabled;

        @Override
        protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeFailedEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            Stack stack = stackService.getById(payload.getResourceId());
            MDCBuilder.buildMdcContext(stack);
            flow.setFlowFailed(payload.getException());
            return ClusterUpgradeContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeFailedEvent payload, Map<Object, Object> variables) {
            clusterUpgradeService.handleUpgradeClusterFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
            if (syncAfterFailureEnabled) {
                LOGGER.debug("Starting syncing parcel and CM version from CM to DB.");
                try {
                    Set<Image> candidateImages = new HashSet<>();
                    Optional.ofNullable(getCurrentImage(variables)).ifPresent(si -> candidateImages.add(si.getImage()));
                    Optional.ofNullable(getTargetImage(variables)).ifPresent(si -> candidateImages.add(si.getImage()));
                    ClusterUpgradeFailedCmSyncRequest cmSyncRequest = new ClusterUpgradeFailedCmSyncRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus(), candidateImages);
                    sendEvent(context, cmSyncRequest);
                } catch (Exception e) {
                    LOGGER.warn("Error starting syncing CM version to DB, syncing skipped: ", e);
                    sendEvent(context, new ClusterUpgradeFailHandledRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus()));
                }
            } else {
                LOGGER.debug("Syncing from CM to DB is not enabled.");
                sendEvent(context, new ClusterUpgradeFailHandledRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus()));
            }
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeFailedEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ClusterUpgradeFailedCmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedCmSyncRequest) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ClusterUpgradeFailHandledRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest) Map(java.util.Map) HashSet(java.util.HashSet) Bean(org.springframework.context.annotation.Bean)

Example 35 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class StartExternalDatabaseHandler method defaultFailureEvent.

@Override
protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event<StartExternalDatabaseRequest> event) {
    Stack stack = stackService.getById(event.getData().getResourceId());
    LOGGER.error(String.format("Exception during DB 'start' for stack/cluster: %s", stack.getName()), e);
    return startFailedEvent(stack, e);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1041 Test (org.junit.jupiter.api.Test)326 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)255 Test (org.junit.Test)208 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)158 Map (java.util.Map)114 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)113 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)112 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)111 List (java.util.List)101 Set (java.util.Set)101 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)100 Collectors (java.util.stream.Collectors)84 Optional (java.util.Optional)83 HashSet (java.util.HashSet)82 Inject (javax.inject.Inject)80 Logger (org.slf4j.Logger)78 LoggerFactory (org.slf4j.LoggerFactory)78 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)69 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)67