Search in sources :

Example 96 with Node

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

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

the class FreeIpaConfigServiceTest method testCreateFreeIpaConfigs.

@Test
void testCreateFreeIpaConfigs() {
    String backupLocation = "s3://mybucket/test";
    Backup backup = new Backup();
    backup.setStorageLocation(backupLocation);
    backup.setS3(new S3CloudStorageV1Parameters());
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain(DOMAIN);
    freeIpa.setAdminPassword(PASSWORD);
    Stack stack = new Stack();
    stack.setCloudPlatform(CloudPlatform.AWS.name());
    stack.setBackup(backup);
    stack.setEnvironmentCrn("envcrn");
    Network network = new Network();
    network.setNetworkCidrs(List.of(CIDR));
    stack.setNetwork(network);
    when(freeIpaService.findByStack(any())).thenReturn(freeIpa);
    when(freeIpaClientFactory.getAdminUser()).thenReturn(ADMIN);
    when(networkService.getFilteredSubnetWithCidr(any())).thenReturn(subnetWithCidr);
    when(reverseDnsZoneCalculator.reverseDnsZoneForCidrs(any())).thenReturn(REVERSE_ZONE);
    when(environment.getProperty("freeipa.platform.dnssec.validation.AWS", "true")).thenReturn("true");
    GatewayConfig gatewayConfig = mock(GatewayConfig.class);
    when(gatewayConfig.getHostname()).thenReturn(HOSTNAME);
    when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig);
    when(proxyConfigDtoService.getByEnvironmentCrn(anyString())).thenReturn(Optional.empty());
    Node node = new Node(PRIVATE_IP, null, null, null, HOSTNAME, DOMAIN, (String) null);
    Map<String, String> expectedHost = Map.of("ip", PRIVATE_IP, "fqdn", HOSTNAME);
    Set<Object> expectedHosts = ImmutableSet.of(expectedHost);
    FreeIpaConfigView freeIpaConfigView = underTest.createFreeIpaConfigs(stack, ImmutableSet.of(node));
    assertEquals(DOMAIN.toUpperCase(), freeIpaConfigView.getRealm());
    assertEquals(DOMAIN, freeIpaConfigView.getDomain());
    assertEquals(PASSWORD, freeIpaConfigView.getPassword());
    assertEquals(REVERSE_ZONE, freeIpaConfigView.getReverseZones());
    assertEquals(ADMIN, freeIpaConfigView.getAdminUser());
    assertEquals(HOSTNAME, freeIpaConfigView.getFreeipaToReplicate());
    assertEquals(backupLocation, freeIpaConfigView.getBackup().getLocation());
    assertEquals(CloudPlatform.AWS.name(), freeIpaConfigView.getBackup().getPlatform());
    assertEquals(expectedHosts, freeIpaConfigView.getHosts());
    assertEquals(List.of(CIDR), freeIpaConfigView.getCidrBlocks());
}
Also used : S3CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Backup(com.sequenceiq.freeipa.api.model.Backup) Network(com.sequenceiq.freeipa.entity.Network) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 98 with Node

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

the class CreateFullBackupHandlerTest method createNode.

private Node createNode(String hostname) {
    Node node = mock(Node.class);
    when(node.getHostname()).thenReturn(hostname);
    return node;
}
Also used : Node(com.sequenceiq.cloudbreak.common.orchestration.Node)

Example 99 with Node

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

the class CreateFullBackupHandlerTest method testOrchestratorThrowException.

@Test
public void testOrchestratorThrowException() throws CloudbreakOrchestratorFailedException {
    Stack stack = mock(Stack.class);
    when(stackService.getByIdWithListsInTransaction(2L)).thenReturn(stack);
    Set<InstanceMetaData> metaDataSet = Set.of();
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(metaDataSet);
    Node node1 = createNode("node1");
    Set<Node> nodes = Set.of(node1);
    when(nodeService.mapInstancesToNodes(metaDataSet)).thenReturn(nodes);
    GatewayConfig gatewayConfig = mock(GatewayConfig.class);
    when(gatewayConfigService.getPrimaryGatewayConfig(stack)).thenReturn(gatewayConfig);
    doThrow(new CloudbreakOrchestratorFailedException("tada")).when(orchestrator).runOrchestratorState(any(OrchestratorStateParams.class));
    StackFailureEvent result = (StackFailureEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new CreateFullBackupEvent(2L))));
    assertEquals(2L, result.getResourceId());
    assertEquals(FullBackupEvent.FULL_BACKUP_FAILED_EVENT.event(), result.selector());
    assertEquals("tada", result.getException().getMessage());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CreateFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 100 with Node

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

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