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());
}
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());
}
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;
}
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());
}
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());
}
Aggregations