Search in sources :

Example 1 with BootstrapParams

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

the class ClusterBootstrapper method bootstrapNewNodesOnHost.

private void bootstrapNewNodesOnHost(Stack stack, List<GatewayConfig> allGatewayConfigs, Set<Node> nodes, Set<Node> allNodes) throws CloudbreakOrchestratorException {
    LOGGER.info("Bootstrap new nodes: {}", nodes);
    Cluster cluster = stack.getCluster();
    Boolean enableKnox = cluster.getGateway() != null;
    for (InstanceMetaData gateway : stack.getNotTerminatedAndNotZombieGatewayInstanceMetadata()) {
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gateway, enableKnox);
        ExtendedPollingResult bootstrapApiPolling = hostBootstrapApiPollingService.pollWithAbsoluteTimeout(hostBootstrapApiCheckerTask, new HostBootstrapApiContext(stack, gatewayConfig, hostOrchestrator), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
        validatePollingResultForCancellation(bootstrapApiPolling.getPollingResult(), "Polling of bootstrap API was cancelled.");
    }
    byte[] stateZip = null;
    ClusterComponent stateComponent = clusterComponentProvider.getComponent(cluster.getId(), ComponentType.SALT_STATE);
    if (stateComponent != null) {
        String content = (String) stateComponent.getAttributes().getMap().getOrDefault(ComponentType.SALT_STATE.name(), "");
        if (!content.isEmpty()) {
            stateZip = Base64.decodeBase64(content);
        }
    }
    BootstrapParams params = createBootstrapParams(stack);
    hostOrchestrator.bootstrapNewNodes(allGatewayConfigs, nodes, allNodes, stateZip, params, clusterDeletionBasedModel(stack.getId(), null));
    InstanceMetaData primaryGateway = stack.getPrimaryGatewayInstance();
    GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, primaryGateway, enableKnox);
    ExtendedPollingResult allNodesAvailabilityPolling = hostClusterAvailabilityPollingService.pollWithAbsoluteTimeout(hostClusterAvailabilityCheckerTask, new HostOrchestratorClusterContext(stack, hostOrchestrator, gatewayConfig, nodes), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
    validatePollingResultForCancellation(allNodesAvailabilityPolling.getPollingResult(), "Polling of new nodes availability was cancelled.");
    if (allNodesAvailabilityPolling.isTimeout()) {
        clusterBootstrapperErrorHandler.terminateFailedNodes(hostOrchestrator, null, stack, gatewayConfig, nodes);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) HostBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with BootstrapParams

use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams 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 3 with BootstrapParams

use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams 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 4 with BootstrapParams

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

the class SaltOrchestratorTest method bootstrapTest.

@Test
public void bootstrapTest() throws Exception {
    whenNew(SaltBootstrap.class).withAnyArguments().thenReturn(mock(SaltBootstrap.class));
    whenNew(OrchestratorBootstrapRunner.class).withArguments(any(OrchestratorBootstrap.class), any(ExitCriteria.class), any(ExitCriteriaModel.class), isNull(), anyInt(), anyInt(), anyInt()).thenReturn(mock(OrchestratorBootstrapRunner.class));
    when(compressUtil.generateCompressedOutputFromFolders("salt-common", "salt")).thenReturn(new byte[] {});
    BootstrapParams bootstrapParams = mock(BootstrapParams.class);
    List<GatewayConfig> allGatewayConfigs = Collections.singletonList(gatewayConfig);
    saltOrchestrator.bootstrap(allGatewayConfigs, targets, bootstrapParams, exitCriteriaModel);
    verify(saltRunner, times(4)).runner(any(OrchestratorBootstrap.class), any(ExitCriteria.class), any(ExitCriteriaModel.class));
    // salt.zip, master_sign.pem, master_sign.pub
    verifyNew(SaltBootstrap.class, times(1)).withArguments(eq(saltConnector), eq(saltConnectors), eq(allGatewayConfigs), eq(targets), eq(bootstrapParams));
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) OrchestratorBootstrapRunner(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrapRunner) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with BootstrapParams

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

the class SaltBootstrapTest method callFailTest.

@Test
public void callFailTest() throws IOException {
    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\"]"));
    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"));
    String missingNodeIp = "10.0.0.3";
    targets.add(new Node(missingNodeIp, 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();
    try {
        saltBootstrap.call();
        fail("should throw exception");
    } catch (Exception e) {
        assertEquals(CloudbreakOrchestratorFailedException.class.getSimpleName(), e.getClass().getSimpleName());
        assertThat(e.getMessage(), containsString("10.0.0.3"));
        assertThat(e.getMessage(), not(containsString("10.0.0.2")));
        assertThat(e.getMessage(), not(containsString("10.0.0.1")));
    }
}
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) IOException(java.io.IOException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) 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