Search in sources :

Example 46 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class BootstrapService method bootstrap.

public void bootstrap(Long stackId, List<String> instanceIds) throws CloudbreakOrchestratorException {
    Set<InstanceMetaData> instanceMetaDatas = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(instanceMetaData -> Objects.isNull(instanceIds) || instanceIds.contains(instanceMetaData.getInstanceId())).collect(Collectors.toSet());
    Stack stack = stackRepository.findById(stackId).get();
    FreeIpa freeIpa = freeIpaService.findByStack(stack);
    List<GatewayConfig> gatewayConfigs = gatewayConfigService.getGatewayConfigs(stack, instanceMetaDatas);
    Set<Node> allNodes = instanceMetaDatas.stream().map(im -> {
        String hostname = getHostname(freeIpa, im);
        return new Node(im.getPrivateIp(), im.getPublicIpWrapper(), im.getInstanceId(), im.getInstanceGroup().getTemplate().getInstanceType(), hostname, freeIpa.getDomain(), im.getInstanceGroup().getGroupName());
    }).collect(Collectors.toSet());
    BootstrapParams params = new BootstrapParams();
    params.setCloud(stack.getCloudPlatform());
    ImageEntity image = imageService.getByStack(stack);
    params.setOs(image.getOs());
    params.setSaltBootstrapFpSupported(true);
    params.setRestartNeededFlagSupported(true);
    try {
        byte[] stateConfigZip = getStateConfigZip();
        hostOrchestrator.bootstrapNewNodes(gatewayConfigs, allNodes, allNodes, stateConfigZip, params, new StackBasedExitCriteriaModel(stackId));
    } catch (IOException e) {
        LOGGER.error("Couldn't read state config", e);
        throw new CloudbreakOrchestratorFailedException("Couldn't read state config", e);
    } catch (CloudbreakOrchestratorException e) {
        LOGGER.error("Bootstrap failed", e);
        throw e;
    }
}
Also used : ImageService(com.sequenceiq.freeipa.service.image.ImageService) LoggerFactory(org.slf4j.LoggerFactory) HostDiscoveryService(com.sequenceiq.cloudbreak.common.service.HostDiscoveryService) CompressUtil(com.sequenceiq.cloudbreak.util.CompressUtil) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) StackRepository(com.sequenceiq.freeipa.repository.StackRepository) Service(org.springframework.stereotype.Service) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Set(java.util.Set) IOException(java.io.IOException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) FreeIpaService(com.sequenceiq.freeipa.service.freeipa.FreeIpaService) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) IOException(java.io.IOException) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 47 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class NodeStatusJob method checkNodeHealthReports.

private void checkNodeHealthReports(Stack stack, Set<InstanceMetaData> checkableInstances) {
    for (InstanceMetaData instanceMetaData : checkableInstances) {
        try {
            CdpNodeStatuses nodeStatuses = checkedMeasure(() -> freeIpaNodeStatusService.nodeStatusReport(stack, instanceMetaData), LOGGER, "FreeIPA node status job checks ran in {}ms");
            LOGGER.debug("Fetching node health reports for instance: {}", instanceMetaData.getInstanceId());
            if (nodeStatuses.getNetworkReport().isPresent()) {
                logReportResult(instanceMetaData, nodeStatuses.getNetworkReport().get(), "network");
            }
            if (nodeStatuses.getServicesReport().isPresent()) {
                logReportResult(instanceMetaData, nodeStatuses.getServicesReport().get(), "services");
            }
            if (nodeStatuses.getSystemMetricsReport().isPresent()) {
                logReportResult(instanceMetaData, nodeStatuses.getServicesReport().get(), "system metrics");
            }
        } catch (Exception e) {
            LOGGER.info("FreeIpaClientException occurred during node status check: " + e.getMessage(), e);
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CdpNodeStatuses(com.sequenceiq.node.health.client.model.CdpNodeStatuses) InterruptSyncingException(com.sequenceiq.freeipa.sync.InterruptSyncingException) JobExecutionException(org.quartz.JobExecutionException)

Example 48 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandler method fetchInstancesHealth.

private List<NodeHealthDetails> fetchInstancesHealth(ValidateInstancesHealthEvent event) {
    Stack stack = stackService.getStackById(event.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    Set<InstanceMetaData> instanceMetaDatas = instanceMetaDataService.getNotTerminatedByInstanceIds(stack.getId(), event.getInstanceIds());
    List<NodeHealthDetails> healthDetails = instanceMetaDatas.stream().map(im -> getInstanceHealthDetails(stack, im)).collect(Collectors.toList());
    LOGGER.info("Fetched healthdetails for instances {} - {}", event.getInstanceIds(), healthDetails);
    return healthDetails;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) Inject(javax.inject.Inject) FreeIpaInstanceHealthDetailsService(com.sequenceiq.freeipa.service.stack.FreeIpaInstanceHealthDetailsService) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) Event(reactor.bus.Event) Map(java.util.Map) StackService(com.sequenceiq.freeipa.service.stack.StackService) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.upscale.UpscaleFlowEvent.UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) Joiner(com.google.common.base.Joiner) NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 49 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class RebootActions method rebootFailureAction.

@Bean(name = "REBOOT_FAILED_STATE")
public Action<?, ?> rebootFailureAction() {
    return new AbstractRebootAction<>(InstanceFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(RebootContext context, InstanceFailureEvent payload, Map<Object, Object> variables) {
            addMdcOperationId(variables);
            rebootService.handleInstanceRebootError(context);
            String message = String.format("Rebooting failed for %s.", context.getInstanceIds());
            LOGGER.error(message);
            Stack stack = context.getStack();
            SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
            FailureDetails failureDetails = new FailureDetails(stack.getEnvironmentCrn(), message);
            operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
            sendEvent(context, new InstanceEvent(RebootEvent.REBOOT_FAIL_HANDLED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList()));
        }

        @Override
        protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, InstanceFailureEvent payload) {
            Long stackId = payload.getResourceId();
            Stack stack = stackService.getStackById(stackId);
            MDCBuilder.buildMdcContext(stack);
            return new RebootContext(flowParameters, stack, payload.getInstanceIds().stream().map(instanceId -> {
                InstanceMetaData md = new InstanceMetaData();
                md.setInstanceId(instanceId);
                return md;
            }).collect(Collectors.toList()), null, null);
        }

        @Override
        protected Object getFailurePayload(InstanceFailureEvent payload, Optional<RebootContext> flowContext, Exception ex) {
            return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<InstanceFailureEvent>> payloadConverters) {
            payloadConverters.add(new RebootInstancesResultToCleanupFailureEventConverter());
            payloadConverters.add(new WaitUntilAvailableFailedToInstanceFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) InstanceFailureEvent(com.sequenceiq.freeipa.flow.instance.InstanceFailureEvent) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Stack(com.sequenceiq.freeipa.entity.Stack) RebootInstanceEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent) InstanceEvent(com.sequenceiq.freeipa.flow.instance.InstanceEvent) RebootInstancesResultToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RebootInstancesResultToCleanupFailureEventConverter) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FlowParameters(com.sequenceiq.flow.core.FlowParameters) List(java.util.List) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) WaitUntilAvailableFailedToInstanceFailureEventConverter(com.sequenceiq.freeipa.flow.instance.reboot.failure.WaitUntilAvailableFailedToInstanceFailureEventConverter) RebootContext(com.sequenceiq.freeipa.flow.instance.reboot.RebootContext) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 50 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class StackProvisionService method setupTls.

public void setupTls(StackContext context) throws CloudbreakException {
    Stack stack = context.getStack();
    Set<InstanceMetaData> instanceMetaDataSet = stack.getInstanceGroups().stream().flatMap(instanceGroup -> instanceGroup.getAllInstanceMetaData().stream()).collect(Collectors.toSet());
    for (InstanceMetaData gwInstance : instanceMetaDataSet) {
        tlsSetupService.setupTls(stack.getId(), gwInstance);
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) ImageService(com.sequenceiq.freeipa.service.image.ImageService) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) ErrorHandlerAwareReactorEventFactory(com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory) Inject(javax.inject.Inject) Map(java.util.Map) StackService(com.sequenceiq.freeipa.service.stack.StackService) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) TlsSetupService(com.sequenceiq.freeipa.service.TlsSetupService) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Set(java.util.Set) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) EventBus(reactor.bus.EventBus) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) DateUtils(org.apache.commons.lang3.time.DateUtils) SecurityConfig(com.sequenceiq.freeipa.entity.SecurityConfig) List(java.util.List) Component(org.springframework.stereotype.Component) OperationException(com.sequenceiq.cloudbreak.service.OperationException) StackToCloudStackConverter(com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter) MetadataSetupService(com.sequenceiq.freeipa.service.stack.instance.MetadataSetupService) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackUpdater(com.sequenceiq.freeipa.service.stack.StackUpdater) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)163 Stack (com.sequenceiq.freeipa.entity.Stack)104 Test (org.junit.jupiter.api.Test)77 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)30 List (java.util.List)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Inject (javax.inject.Inject)18 Set (java.util.Set)16 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)12 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)11 StackService (com.sequenceiq.freeipa.service.stack.StackService)10 ArrayList (java.util.ArrayList)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 HealthDetailsFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse)9 Operation (com.sequenceiq.freeipa.entity.Operation)9