Search in sources :

Example 6 with BootstrapParams

use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.

the class SaltBootstrapTest method callTest.

@Test
public void callTest() throws Exception {
    List<Map<String, JsonNode>> result = new ArrayList<>();
    Map<String, JsonNode> ipAddressesForMinions = new HashMap<>();
    ipAddressesForMinions.put("10-0-0-1.example.com", JsonUtil.readTree("[\"10.0.0.1\"]"));
    ipAddressesForMinions.put("10-0-0-2.example.com", JsonUtil.readTree("[\"10.0.0.2\"]"));
    ipAddressesForMinions.put("10-0-0-3.example.com", JsonUtil.readTree("[\"10.0.0.3\"]"));
    result.add(ipAddressesForMinions);
    minionIpAddressesResponse.setResult(result);
    Set<Node> targets = new HashSet<>();
    targets.add(new Node("10.0.0.1", null, null, "hg"));
    targets.add(new Node("10.0.0.2", null, null, "hg"));
    targets.add(new Node("10.0.0.3", null, null, "hg"));
    SaltBootstrap saltBootstrap = new SaltBootstrap(saltConnector, List.of(saltConnector), Collections.singletonList(gatewayConfig), targets, new BootstrapParams());
    saltBootstrap = spy(saltBootstrap);
    doReturn(mock(MinionAcceptor.class)).when(saltBootstrap).createMinionAcceptor();
    saltBootstrap.call();
}
Also used : HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) StringContains.containsString(org.hamcrest.core.StringContains.containsString) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) MinionAcceptor(com.sequenceiq.cloudbreak.orchestrator.salt.poller.join.MinionAcceptor) Test(org.junit.Test)

Example 7 with BootstrapParams

use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.

the class ClusterBootstrapper method bootstrapOnHostInternal.

private void bootstrapOnHostInternal(Stack stack, Consumer<Stack> saveOrUpdateSaltComponent) throws CloudbreakException {
    try {
        Set<Node> nodes = transactionService.required(() -> collectNodesForBootstrap(stack));
        List<GatewayConfig> allGatewayConfig = collectAndCheckGateways(stack);
        saveOrUpdateSaltComponent.accept(stack);
        BootstrapParams params = createBootstrapParams(stack);
        hostOrchestrator.bootstrap(allGatewayConfig, nodes, params, clusterDeletionBasedModel(stack.getId(), null));
        InstanceMetaData primaryGateway = stack.getPrimaryGatewayInstance();
        saveOrchestrator(stack, primaryGateway);
        checkIfAllNodesAvailable(stack, nodes, primaryGateway);
    } catch (TransactionExecutionException e) {
        throw new CloudbreakException(e.getCause());
    } catch (CloudbreakOrchestratorFailedException e) {
        checkIfAnyInstanceIsNotInStartedState(stack, e);
        throw new CloudbreakException(e);
    } catch (Exception e) {
        throw new CloudbreakException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) IOException(java.io.IOException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 8 with BootstrapParams

use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.

the class ClusterBootstrapper method createBootstrapParams.

private BootstrapParams createBootstrapParams(Stack stack) {
    LOGGER.debug("Create bootstrap params");
    BootstrapParams params = new BootstrapParams();
    params.setCloud(stack.cloudPlatform());
    try {
        Image image = componentConfigProviderService.getImage(stack.getId());
        params.setOs(image.getOs());
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.warn("Image not found for stack {}", stack.getName(), e);
    }
    boolean saltBootstrapFpSupported = isSaltBootstrapFpSupported(stack);
    boolean saltBootstrapRestartNeededSupported = isSaltBootstrapRestartNeededSupported(stack);
    params.setSaltBootstrapFpSupported(saltBootstrapFpSupported);
    params.setRestartNeededFlagSupported(saltBootstrapRestartNeededSupported);
    LOGGER.debug("Created bootstrap params: {}", params);
    return params;
}
Also used : BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image)

Example 9 with BootstrapParams

use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.

the class BootstrapServiceTest method testBootstrapWithInstanceIds.

@Test
public void testBootstrapWithInstanceIds() 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"), createInstance("filterMe", "filtered" + 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, List.of(INSTANCE_WITH_FQDN, INSTANCE_WO_FQDN, INSTANCE_WRONG_DOMAIN));
    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 10 with BootstrapParams

use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.

the class SaltBootstrapTest method restartNeededFalseAndFlagNotSupportedBySaltBootstrap.

@Test
public void restartNeededFalseAndFlagNotSupportedBySaltBootstrap() throws Exception {
    List<Map<String, JsonNode>> result = new ArrayList<>();
    Map<String, JsonNode> ipAddressesForMinions = new HashMap<>();
    ipAddressesForMinions.put("10-0-0-1.example.com", JsonUtil.readTree("[\"10.0.0.1\"]"));
    ipAddressesForMinions.put("10-0-0-2.example.com", JsonUtil.readTree("[\"10.0.0.2\"]"));
    ipAddressesForMinions.put("10-0-0-3.example.com", JsonUtil.readTree("[\"10.0.0.3\"]"));
    result.add(ipAddressesForMinions);
    minionIpAddressesResponse.setResult(result);
    Set<Node> targets = new HashSet<>();
    targets.add(new Node("10.0.0.1", null, null, "hg"));
    targets.add(new Node("10.0.0.2", null, null, "hg"));
    targets.add(new Node("10.0.0.3", null, null, "hg"));
    BootstrapParams params = new BootstrapParams();
    params.setRestartNeeded(false);
    params.setRestartNeededFlagSupported(false);
    SaltBootstrap saltBootstrap = new SaltBootstrap(saltConnector, List.of(saltConnector), Collections.singletonList(gatewayConfig), targets, params);
    saltBootstrap = spy(saltBootstrap);
    doReturn(mock(MinionAcceptor.class)).when(saltBootstrap).createMinionAcceptor();
    saltBootstrap.call();
    ArgumentCaptor<SaltAction> captor = ArgumentCaptor.forClass(SaltAction.class);
    verify(saltConnector, times(1)).action(captor.capture());
    SaltAction saltAction = captor.getValue();
    List<Minion> minions = saltAction.getMinions();
    assertEquals(3, minions.size());
    assertEquals(Collections.singletonList("172.16.252.43"), minions.get(0).getServers());
    assertEquals(Collections.singletonList("172.16.252.43"), minions.get(1).getServers());
    assertEquals(Collections.singletonList("172.16.252.43"), minions.get(2).getServers());
    assertFalse(minions.get(0).isRestartNeeded());
    assertFalse(minions.get(1).isRestartNeeded());
    assertFalse(minions.get(2).isRestartNeeded());
}
Also used : HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) StringContains.containsString(org.hamcrest.core.StringContains.containsString) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) Minion(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) MinionAcceptor(com.sequenceiq.cloudbreak.orchestrator.salt.poller.join.MinionAcceptor) Test(org.junit.Test)

Aggregations

BootstrapParams (com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams)15 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)11 Test (org.junit.Test)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 MinionAcceptor (com.sequenceiq.cloudbreak.orchestrator.salt.poller.join.MinionAcceptor)6 StringContains.containsString (org.hamcrest.core.StringContains.containsString)6 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)5 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)4 Minion (com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion)4 SaltAction (com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction)4 IOException (java.io.IOException)4 Set (java.util.Set)4 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)3 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)3 SaltBootstrap (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap)3