Search in sources :

Example 36 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class SaltOrchestrator method getFreeDiskSpaceByNodes.

@Override
public Map<String, String> getFreeDiskSpaceByNodes(Set<Node> nodes, List<GatewayConfig> gatewayConfigs) {
    Map<String, String> freeDiskSpaceByNode;
    try {
        GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(gatewayConfigs);
        SaltConnector sc = saltService.createSaltConnector(primaryGateway);
        Target<String> allHosts = new HostList(nodes.stream().map(Node::getHostname).collect(Collectors.toSet()));
        freeDiskSpaceByNode = SaltStates.runCommandOnHosts(retry, sc, allHosts, "df -k / | tail -1 | awk '{print $4}'");
    } catch (Exception e) {
        String errorMessage = String.format("Failed to get free disk space on hosts. Reason: %s", e.getMessage());
        LOGGER.warn(errorMessage, e);
        throw new CloudbreakServiceException(errorMessage, e);
    }
    return freeDiskSpaceByNode;
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) HostList(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakOrchestratorTimeoutException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 37 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class SaltBootstrap method call.

@Override
public Boolean call() throws Exception {
    LOGGER.debug("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size());
    if (!targets.isEmpty()) {
        LOGGER.debug("Missing targets for SaltBootstrap: {}", targets);
        SaltAction saltAction = createBootstrap(params.isRestartNeededFlagSupported(), params.isRestartNeeded());
        GenericResponses responses = sc.action(saltAction);
        Set<Node> failedTargets = new HashSet<>();
        LOGGER.debug("SaltBootstrap responses: {}", responses);
        for (GenericResponse genericResponse : responses.getResponses()) {
            if (genericResponse.getStatusCode() != HttpStatus.OK.value()) {
                LOGGER.info("Failed to distributed salt run to: {}, error: {}", genericResponse.getAddress(), genericResponse.getErrorText());
                String address = genericResponse.getAddress().split(":")[0];
                failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList()));
            }
        }
        targets = failedTargets;
        if (!targets.isEmpty()) {
            LOGGER.info("Missing nodes to run saltbootstrap: {}", targets);
            throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets);
        }
        if (params.isRestartNeeded()) {
            params.setRestartNeeded(false);
        }
        createMinionAcceptor().acceptMinions();
    }
    MinionIpAddressesResponse minionIpAddressesResponse = SaltStates.collectMinionIpAddresses(sc);
    if (minionIpAddressesResponse != null) {
        originalTargets.forEach(node -> {
            if (!minionIpAddressesResponse.getAllIpAddresses().contains(node.getPrivateIp())) {
                LOGGER.info("Salt-minion is not responding on host: {}, yet", node);
                targets.add(node);
            }
        });
    } else {
        throw new CloudbreakOrchestratorFailedException("Minions ip address collection returned null value");
    }
    if (!targets.isEmpty()) {
        throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets);
    }
    LOGGER.debug("Bootstrapping of nodes completed: {}", originalTargets.size());
    return true;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) MinionIpAddressesResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionIpAddressesResponse) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) HashSet(java.util.HashSet)

Example 38 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class SaltBootstrap method createBootstrap.

private SaltAction createBootstrap(boolean restartNeededFlagSupported, boolean restartNeeded) {
    SaltAction saltAction = new SaltAction(SaltActionType.RUN);
    if (params.getCloud() != null) {
        saltAction.setCloud(new Cloud(params.getCloud()));
    }
    if (params.getOs() != null) {
        saltAction.setOs(new Os(params.getOs()));
    }
    SaltAuth auth = new SaltAuth();
    auth.setPassword(sc.getSaltPassword());
    List<String> targetIps = targets.stream().map(Node::getPrivateIp).collect(Collectors.toList());
    for (GatewayConfig gatewayConfig : allGatewayConfigs) {
        String gatewayAddress = gatewayConfig.getPrivateAddress();
        if (targetIps.contains(gatewayAddress)) {
            Node saltMaster = targets.stream().filter(n -> n.getPrivateIp().equals(gatewayAddress)).findFirst().get();
            SaltMaster master = new SaltMaster();
            master.setAddress(gatewayAddress);
            master.setAuth(auth);
            master.setDomain(saltMaster.getDomain());
            master.setHostName(saltMaster.getHostname());
            // set due to compatibility reasons
            saltAction.setServer(gatewayAddress);
            saltAction.setMaster(master);
            saltAction.addMinion(createMinion(saltMaster, restartNeededFlagSupported, restartNeeded));
            saltAction.addMaster(master);
        }
    }
    for (Node minion : targets.stream().filter(node -> !getGatewayPrivateIps().contains(node.getPrivateIp())).collect(Collectors.toList())) {
        saltAction.addMinion(createMinion(minion, restartNeededFlagSupported, restartNeeded));
    }
    return saltAction;
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) FingerprintFromSbCollector(com.sequenceiq.cloudbreak.orchestrator.salt.poller.join.FingerprintFromSbCollector) EqualMinionFpMatcher(com.sequenceiq.cloudbreak.orchestrator.salt.poller.join.EqualMinionFpMatcher) MinionIpAddressesResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionIpAddressesResponse) HashSet(java.util.HashSet) DummyFingerprintCollector(com.sequenceiq.cloudbreak.orchestrator.salt.poller.join.DummyFingerprintCollector) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) Cloud(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Cloud) Minion(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) SaltActionType(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltActionType) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Logger(org.slf4j.Logger) Os(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Os) Collection(java.util.Collection) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) SaltAuth(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAuth) Set(java.util.Set) SaltMaster(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltMaster) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) SaltStates(com.sequenceiq.cloudbreak.orchestrator.salt.states.SaltStates) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) AcceptAllFpMatcher(com.sequenceiq.cloudbreak.orchestrator.salt.poller.join.AcceptAllFpMatcher) MinionAcceptor(com.sequenceiq.cloudbreak.orchestrator.salt.poller.join.MinionAcceptor) Collections(java.util.Collections) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Os(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Os) SaltAuth(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAuth) Cloud(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Cloud) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) SaltMaster(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltMaster) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 39 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node 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 40 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayServiceTest method testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwIsOnListToAvoid.

@Test
void testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwIsOnListToAvoid() throws Exception {
    Stack stack = mock(Stack.class);
    GatewayConfig gatewayConfig = mock(GatewayConfig.class);
    InstanceMetaData im1 = mock(InstanceMetaData.class);
    InstanceMetaData im2 = mock(InstanceMetaData.class);
    Node node = mock(Node.class);
    Set<Node> allNodes = Set.of(node);
    when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig);
    when(gatewayConfig.getInstanceId()).thenReturn(INSTANCE_ID_1);
    when(freeIpaNodeUtilService.mapInstancesToNodes(any())).thenReturn(allNodes);
    when(hostOrchestrator.getFreeIpaMasterHostname(any(), any())).thenReturn(Optional.of(HOSTNAME_1));
    when(stack.getNotDeletedInstanceMetaDataList()).thenReturn(List.of(im1, im2));
    when(im1.getDiscoveryFQDN()).thenReturn(HOSTNAME_1);
    lenient().when(im2.getDiscoveryFQDN()).thenReturn(HOSTNAME_2);
    when(im1.getInstanceId()).thenReturn(INSTANCE_ID_1);
    lenient().when(im2.getInstanceId()).thenReturn(INSTANCE_ID_2);
    assertEquals(INSTANCE_ID_2, underTest.selectNewPrimaryGatewayInstanceId(stack, List.of(INSTANCE_ID_1)));
    verify(gatewayConfigService).getPrimaryGatewayConfig(eq(stack));
    verify(hostOrchestrator).getFreeIpaMasterHostname(eq(gatewayConfig), eq(allNodes));
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Aggregations

Node (com.sequenceiq.cloudbreak.common.orchestration.Node)126 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)57 HashSet (java.util.HashSet)42 Map (java.util.Map)32 JsonNode (com.fasterxml.jackson.databind.JsonNode)30 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)29 Test (org.junit.Test)29 HashMap (java.util.HashMap)28 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)27 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)26 ArrayList (java.util.ArrayList)26 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)25 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)25 Set (java.util.Set)25 Test (org.junit.jupiter.api.Test)25 List (java.util.List)22 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)21 IOException (java.io.IOException)21 Collectors (java.util.stream.Collectors)21 BootstrapParams (com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams)19