use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.
the class SaltOrchestrator method getFreeDiskSpaceByNodes.
@Override
public Map<String, String> getFreeDiskSpaceByNodes(Set<Node> nodes, List<GatewayConfig> gatewayConfigs) {
Map<String, String> freeDiskSpaceByNode;
try {
GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(gatewayConfigs);
SaltConnector sc = saltService.createSaltConnector(primaryGateway);
Target<String> allHosts = new HostList(nodes.stream().map(Node::getHostname).collect(Collectors.toSet()));
freeDiskSpaceByNode = SaltStates.runCommandOnHosts(retry, sc, allHosts, "df -k / | tail -1 | awk '{print $4}'");
} catch (Exception e) {
String errorMessage = String.format("Failed to get free disk space on hosts. Reason: %s", e.getMessage());
LOGGER.warn(errorMessage, e);
throw new CloudbreakServiceException(errorMessage, e);
}
return freeDiskSpaceByNode;
}
use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.
the class SaltBootstrap method call.
@Override
public Boolean call() throws Exception {
LOGGER.debug("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size());
if (!targets.isEmpty()) {
LOGGER.debug("Missing targets for SaltBootstrap: {}", targets);
SaltAction saltAction = createBootstrap(params.isRestartNeededFlagSupported(), params.isRestartNeeded());
GenericResponses responses = sc.action(saltAction);
Set<Node> failedTargets = new HashSet<>();
LOGGER.debug("SaltBootstrap responses: {}", responses);
for (GenericResponse genericResponse : responses.getResponses()) {
if (genericResponse.getStatusCode() != HttpStatus.OK.value()) {
LOGGER.info("Failed to distributed salt run to: {}, error: {}", genericResponse.getAddress(), genericResponse.getErrorText());
String address = genericResponse.getAddress().split(":")[0];
failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList()));
}
}
targets = failedTargets;
if (!targets.isEmpty()) {
LOGGER.info("Missing nodes to run saltbootstrap: {}", targets);
throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets);
}
if (params.isRestartNeeded()) {
params.setRestartNeeded(false);
}
createMinionAcceptor().acceptMinions();
}
MinionIpAddressesResponse minionIpAddressesResponse = SaltStates.collectMinionIpAddresses(sc);
if (minionIpAddressesResponse != null) {
originalTargets.forEach(node -> {
if (!minionIpAddressesResponse.getAllIpAddresses().contains(node.getPrivateIp())) {
LOGGER.info("Salt-minion is not responding on host: {}, yet", node);
targets.add(node);
}
});
} else {
throw new CloudbreakOrchestratorFailedException("Minions ip address collection returned null value");
}
if (!targets.isEmpty()) {
throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets);
}
LOGGER.debug("Bootstrapping of nodes completed: {}", originalTargets.size());
return true;
}
use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.
the class SaltBootstrap method createBootstrap.
private SaltAction createBootstrap(boolean restartNeededFlagSupported, boolean restartNeeded) {
SaltAction saltAction = new SaltAction(SaltActionType.RUN);
if (params.getCloud() != null) {
saltAction.setCloud(new Cloud(params.getCloud()));
}
if (params.getOs() != null) {
saltAction.setOs(new Os(params.getOs()));
}
SaltAuth auth = new SaltAuth();
auth.setPassword(sc.getSaltPassword());
List<String> targetIps = targets.stream().map(Node::getPrivateIp).collect(Collectors.toList());
for (GatewayConfig gatewayConfig : allGatewayConfigs) {
String gatewayAddress = gatewayConfig.getPrivateAddress();
if (targetIps.contains(gatewayAddress)) {
Node saltMaster = targets.stream().filter(n -> n.getPrivateIp().equals(gatewayAddress)).findFirst().get();
SaltMaster master = new SaltMaster();
master.setAddress(gatewayAddress);
master.setAuth(auth);
master.setDomain(saltMaster.getDomain());
master.setHostName(saltMaster.getHostname());
// set due to compatibility reasons
saltAction.setServer(gatewayAddress);
saltAction.setMaster(master);
saltAction.addMinion(createMinion(saltMaster, restartNeededFlagSupported, restartNeeded));
saltAction.addMaster(master);
}
}
for (Node minion : targets.stream().filter(node -> !getGatewayPrivateIps().contains(node.getPrivateIp())).collect(Collectors.toList())) {
saltAction.addMinion(createMinion(minion, restartNeededFlagSupported, restartNeeded));
}
return saltAction;
}
use of com.sequenceiq.cloudbreak.common.orchestration.Node 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.common.orchestration.Node in project cloudbreak by hortonworks.
the class ChangePrimaryGatewayServiceTest method testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwIsOnListToAvoid.
@Test
void testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwIsOnListToAvoid() throws Exception {
Stack stack = mock(Stack.class);
GatewayConfig gatewayConfig = mock(GatewayConfig.class);
InstanceMetaData im1 = mock(InstanceMetaData.class);
InstanceMetaData im2 = mock(InstanceMetaData.class);
Node node = mock(Node.class);
Set<Node> allNodes = Set.of(node);
when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig);
when(gatewayConfig.getInstanceId()).thenReturn(INSTANCE_ID_1);
when(freeIpaNodeUtilService.mapInstancesToNodes(any())).thenReturn(allNodes);
when(hostOrchestrator.getFreeIpaMasterHostname(any(), any())).thenReturn(Optional.of(HOSTNAME_1));
when(stack.getNotDeletedInstanceMetaDataList()).thenReturn(List.of(im1, im2));
when(im1.getDiscoveryFQDN()).thenReturn(HOSTNAME_1);
lenient().when(im2.getDiscoveryFQDN()).thenReturn(HOSTNAME_2);
when(im1.getInstanceId()).thenReturn(INSTANCE_ID_1);
lenient().when(im2.getInstanceId()).thenReturn(INSTANCE_ID_2);
assertEquals(INSTANCE_ID_2, underTest.selectNewPrimaryGatewayInstanceId(stack, List.of(INSTANCE_ID_1)));
verify(gatewayConfigService).getPrimaryGatewayConfig(eq(stack));
verify(hostOrchestrator).getFreeIpaMasterHostname(eq(gatewayConfig), eq(allNodes));
}
Aggregations