Search in sources :

Example 1 with StackBasedExitCriteriaModel

use of com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel in project cloudbreak by hortonworks.

the class FreeIpaInstallService method installFreeIpa.

private void installFreeIpa(Long stackId, Stack stack, List<GatewayConfig> gatewayConfigs, Set<Node> allNodes) throws CloudbreakOrchestratorException {
    GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
    hostOrchestrator.installFreeIpa(primaryGatewayConfig, gatewayConfigs, allNodes, new StackBasedExitCriteriaModel(stackId));
}
Also used : StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with StackBasedExitCriteriaModel

use of com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel in project cloudbreak by hortonworks.

the class FreeIpaOrchestrationConfigService method configureOrchestrator.

public void configureOrchestrator(Long stackId) throws CloudbreakOrchestratorException {
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    Set<InstanceMetaData> instanceMetaDatas = stack.getNotDeletedInstanceMetaDataSet();
    List<GatewayConfig> gatewayConfigs = gatewayConfigService.getGatewayConfigs(stack, instanceMetaDatas);
    Set<Node> allNodes = freeIpaNodeUtilService.mapInstancesToNodes(instanceMetaDatas);
    SaltConfig saltConfig = saltConfigProvider.getSaltConfig(stack, allNodes);
    hostOrchestrator.initSaltConfig(stack, gatewayConfigs, allNodes, saltConfig, new StackBasedExitCriteriaModel(stackId));
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 3 with StackBasedExitCriteriaModel

use of com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel 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 4 with StackBasedExitCriteriaModel

use of com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel in project cloudbreak by hortonworks.

the class BootstrapServiceTest method testBootstrapWithoutInstanceIds.

@Test
public void testBootstrapWithoutInstanceIds() throws CloudbreakOrchestratorException, IOException {
    when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(createInstance(INSTANCE_WITH_FQDN, "instance1" + DOMAIN), createInstance(INSTANCE_WO_FQDN, null), createInstance(INSTANCE_WRONG_DOMAIN, "instance.wrong.domain")));
    Stack stack = new Stack();
    stack.setCloudPlatform("cloud");
    when(stackRepository.findById(STACK_ID)).thenReturn(Optional.of(stack));
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain(DOMAIN);
    freeIpa.setHostname(HOSTNAME);
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    List<GatewayConfig> gatewayConfigs = List.of();
    when(gatewayConfigService.getGatewayConfigs(eq(stack), anySet())).thenReturn(gatewayConfigs);
    byte[] bytes = {};
    when(compressUtil.generateCompressedOutputFromFolders("salt-common", "freeipa-salt")).thenReturn(bytes);
    ImageEntity image = new ImageEntity();
    image.setOs("ZOS");
    when(imageService.getByStack(stack)).thenReturn(image);
    when(hostDiscoveryService.generateHostname(anyString(), any(), anyLong(), anyBoolean())).thenCallRealMethod();
    underTest.bootstrap(STACK_ID);
    ArgumentCaptor<Set<Node>> targetCaptor = ArgumentCaptor.forClass((Class) Set.class);
    ArgumentCaptor<Set<Node>> allCaptor = ArgumentCaptor.forClass((Class) Set.class);
    ArgumentCaptor<BootstrapParams> bootstrapParamsCaptor = ArgumentCaptor.forClass(BootstrapParams.class);
    ArgumentCaptor<ExitCriteriaModel> exitCriteriaModelCaptor = ArgumentCaptor.forClass(ExitCriteriaModel.class);
    verify(hostOrchestrator).bootstrapNewNodes(eq(gatewayConfigs), targetCaptor.capture(), allCaptor.capture(), eq(bytes), bootstrapParamsCaptor.capture(), exitCriteriaModelCaptor.capture());
    Set<Node> targetNodes = targetCaptor.getValue();
    Set<Node> allNodes = allCaptor.getValue();
    assertEquals(targetNodes, allNodes);
    assertEquals(3, allNodes.size());
    assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WITH_FQDN)), hasProperty("hostname", is("instance1")), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
    assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WO_FQDN)), hasProperty("hostname", is(HOSTNAME + '1')), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
    assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WRONG_DOMAIN)), hasProperty("hostname", is(HOSTNAME + '1')), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
    BootstrapParams bootstrapParams = bootstrapParamsCaptor.getValue();
    assertTrue(bootstrapParams.isSaltBootstrapFpSupported());
    assertTrue(bootstrapParams.isRestartNeededFlagSupported());
    assertEquals(image.getOs(), bootstrapParams.getOs());
    assertEquals(stack.getCloudPlatform(), bootstrapParams.getCloud());
    StackBasedExitCriteriaModel exitCriteriaModel = (StackBasedExitCriteriaModel) exitCriteriaModelCaptor.getValue();
    assertEquals(STACK_ID, exitCriteriaModel.getStackId().get());
}
Also used : StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) Set(java.util.Set) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) Stack(com.sequenceiq.freeipa.entity.Stack) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 5 with StackBasedExitCriteriaModel

use of com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel in project cloudbreak by hortonworks.

the class UpgradeCcmOrchestratorService method createStateParams.

private OrchestratorStateParams createStateParams(Long stackId, String saltState) {
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    Set<InstanceMetaData> instanceMetaDatas = stack.getNotDeletedInstanceMetaDataSet();
    Set<Node> allNodes = freeIpaNodeUtilService.mapInstancesToNodes(instanceMetaDatas);
    OrchestratorStateParams stateParams = new OrchestratorStateParams();
    stateParams.setState(saltState);
    stateParams.setPrimaryGatewayConfig(gatewayConfigService.getPrimaryGatewayConfig(stack));
    stateParams.setTargetHostNames(allNodes.stream().map(Node::getHostname).collect(Collectors.toSet()));
    stateParams.setAllNodes(allNodes);
    stateParams.setExitCriteriaModel(new StackBasedExitCriteriaModel(stack.getId()));
    return stateParams;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

StackBasedExitCriteriaModel (com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel)11 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)9 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)8 Stack (com.sequenceiq.freeipa.entity.Stack)8 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)6 Set (java.util.Set)5 BootstrapParams (com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams)3 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)3 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)3 List (java.util.List)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)2 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)2 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)2 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)2 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)2 StackRepository (com.sequenceiq.freeipa.repository.StackRepository)2