use of com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList in project cloudbreak by hortonworks.
the class SaltStatesTest method setUp.
@Before
public void setUp() {
Set<String> targets = new HashSet<>();
targets.add("10-0-0-1.example.com");
targets.add("10-0-0-2.example.com");
targets.add("10-0-0-3.example.com");
target = new HostList(targets);
saltConnector = mock(SaltConnector.class);
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList in project cloudbreak by hortonworks.
the class StateRunnerTest method submit.
@Test
public void submit() throws Exception {
targets = new HashSet<>();
targets.add("10-0-0-1.example.com");
allNode = new HashSet<>();
allNode.add(new Node("10.0.0.1", "5.5.5.1", "10-0-0-1.example.com", "hg"));
allNode.add(new Node("10.0.0.2", "5.5.5.2", "10-0-0-2.example.com", "hg"));
allNode.add(new Node("10.0.0.3", "5.5.5.3", "10-0-0-3.example.com", "hg"));
StateRunner stateRunner = new StateRunner(targets, allNode, "example_state");
SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
PowerMockito.mockStatic(SaltStates.class);
String jobId = "1";
ApplyResponse applyResponse = new ApplyResponse();
List<Map<String, JsonNode>> result = new ArrayList<>();
Map<String, JsonNode> nodes = new HashMap<>();
ObjectMapper objectMapper = new ObjectMapper();
nodes.put("jid", objectMapper.valueToTree(jobId));
result.add(nodes);
applyResponse.setResult(result);
PowerMockito.when(SaltStates.applyState(any(), any(), any())).thenReturn(applyResponse);
String jid = stateRunner.submit(saltConnector);
assertEquals(jobId, jid);
PowerMockito.verifyStatic(SaltStates.class);
ArgumentCaptor acHostList = ArgumentCaptor.forClass(HostList.class);
SaltStates.applyState(eq(saltConnector), eq("example_state"), (Target<String>) acHostList.capture());
assertThat(acHostList.getValue(), IsInstanceOf.instanceOf(HostList.class));
HostList hostList = (HostList) acHostList.getValue();
assertEquals("10-0-0-1.example.com", hostList.getTarget());
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList in project cloudbreak by hortonworks.
the class SaltOrchestrator method formatAndMountDisksOnNodes.
@Override
@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
public Map<String, Map<String, String>> formatAndMountDisksOnNodes(OrchestratorAware stack, List<GatewayConfig> allGateway, Set<Node> nodesWithDiskData, Set<Node> allNodes, ExitCriteriaModel exitModel, String platformVariant) throws CloudbreakOrchestratorFailedException {
GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateway);
Set<String> gatewayTargetIpAddresses = getGatewayPrivateIps(allGateway);
Target<String> allHosts = new HostList(nodesWithDiskData.stream().map(Node::getHostname).collect(Collectors.toSet()));
try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) {
saveHostsPillar(stack, exitModel, gatewayTargetIpAddresses, sc);
Callable<Boolean> saltPillarRunner;
Map<String, String> dataVolumeMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getDataVolumes()));
Map<String, String> serialIdMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getSerialIds()));
Map<String, String> fstabMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getFstab()));
Map<String, String> temporaryStorageMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getTemporaryStorage().name()));
Map<String, Integer> dataBaseVolumeIndexMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getDatabaseVolumeIndex()));
Map<String, Object> hostnameDiskMountMap = nodesWithDiskData.stream().map(Node::getHostname).collect(Collectors.toMap(hn -> hn, hn -> Map.of("attached_volume_name_list", dataVolumeMap.getOrDefault(hn, ""), "attached_volume_serial_list", serialIdMap.getOrDefault(hn, ""), "cloud_platform", platformVariant, "previous_fstab", fstabMap.getOrDefault(hn, ""), "database_volume_index", dataBaseVolumeIndexMap.getOrDefault(hn, -1), "temporary_storage", temporaryStorageMap.getOrDefault(hn, TemporaryStorage.ATTACHED_VOLUMES.name()))));
SaltPillarProperties mounDiskProperties = new SaltPillarProperties("/mount/disk.sls", Collections.singletonMap("mount_data", hostnameDiskMountMap));
OrchestratorBootstrap pillarSave = PillarSave.createCustomPillar(sc, gatewayTargetIpAddresses, mounDiskProperties);
saltPillarRunner = saltRunner.runner(pillarSave, exitCriteria, exitModel);
saltPillarRunner.call();
saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(hostnameDiskMountMap.keySet(), allNodes, "mount_disks"), exitModel, exitCriteria);
StateAllRunner stateAllRunner = new StateAllRunner(gatewayTargetIpAddresses, allNodes, "disks.format-and-mount");
OrchestratorBootstrap saltJobIdTracker = new SaltJobIdTracker(sc, stateAllRunner);
Callable<Boolean> saltJobRunBootstrapRunner = saltRunner.runner(saltJobIdTracker, exitCriteria, exitModel);
saltJobRunBootstrapRunner.call();
Map<String, String> uuidResponse = SaltStates.getUuidList(sc);
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(hostnameDiskMountMap.keySet(), allNodes, "mount_disks"), exitModel, exitCriteria);
Map<String, String> fstabResponse = SaltStates.runCommandOnHosts(retry, sc, allHosts, "cat /etc/fstab");
return nodesWithDiskData.stream().map(node -> {
String fstab = fstabResponse.getOrDefault(node.getHostname(), "");
String uuidList = uuidResponse.getOrDefault(node.getHostname(), "");
return new SimpleImmutableEntry<>(node.getHostname(), Map.of("uuids", uuidList, "fstab", fstab));
}).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
} catch (Exception e) {
LOGGER.info("Error occurred during the salt bootstrap", e);
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList in project cloudbreak by hortonworks.
the class SaltOrchestrator method formatAndMountDisksOnNodesLegacy.
@Override
public Map<String, Map<String, String>> formatAndMountDisksOnNodesLegacy(List<GatewayConfig> gatewayConfigs, Set<Node> nodesWithDiskData, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel, String platformVariant) throws CloudbreakOrchestratorFailedException {
GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(gatewayConfigs);
Set<String> allTargets = nodesWithDiskData.stream().map(Node::getHostname).collect(Collectors.toSet());
Target<String> allHosts = new HostList(nodesWithDiskData.stream().map(Node::getHostname).collect(Collectors.toSet()));
try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) {
uploadMountScriptsAndMakeThemExecutable(nodesWithDiskData, exitCriteriaModel, allTargets, allHosts, sc);
SaltStates.runCommandOnHosts(retry, sc, allHosts, "(cd " + SRV_SALT_DISK + ";./" + DISK_INITIALIZE + ')');
return nodesWithDiskData.stream().map(node -> {
Glob hostname = new Glob(node.getHostname());
String uuidList = formatDisks(platformVariant, sc, node, hostname);
Map<String, String> fstabResponse = mountDisks(platformVariant, sc, hostname, uuidList, node.getNodeVolumes().getFstab());
String fstab = fstabResponse.getOrDefault(node.getHostname(), "");
return new SimpleImmutableEntry<>(node.getHostname(), Map.of("uuids", uuidList, "fstab", fstab));
}).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
} catch (Exception e) {
LOGGER.info("Error occurred during the salt bootstrap", e);
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList in project cloudbreak by hortonworks.
the class SaltTelemetryOrchestrator method preFlightDiagnosticsCheck.
@Override
public void preFlightDiagnosticsCheck(List<GatewayConfig> allGateways, Set<Node> nodes, Map<String, Object> parameters, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorFailedException {
GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateways);
Set<String> gatewayTargets = getGatewayPrivateIps(allGateways);
Set<String> gatewayHostnames = getGatewayHostnames(allGateways);
try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) {
Target<String> targets = new HostList(gatewayHostnames);
uploadScripts(sc, gatewayTargets, exitModel, LOCAL_PREFLIGHT_SCRIPTS_LOCATION, SCRIPTS_TO_UPLOAD);
executeVmPreFlightCheck(sc, targets, nodes, parameters);
} catch (Exception e) {
LOGGER.info("Error occurred during preflight_check.sh script upload/execution", e);
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
}
Aggregations