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