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