use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class ClusterCommonService method getHostNamesAsIniString.
/**
* Get cluster host details (ips + cluster name) - ini format
*
* @param stack stack object that is used to fill the cluster details ini
* @param loginUser ssh username that will be used as a default user in the inventory
* @return Ini file content in string
*/
public String getHostNamesAsIniString(Stack stack, String loginUser) {
Cluster cluster = stack.getCluster();
String clusterName = cluster.getName();
String serverHost = cluster.getClusterManagerIp();
List<InstanceMetaData> agentHostsSet = instanceMetaDataService.getAllInstanceMetadataByStackId(stack.getId()).stream().filter(i -> i.getInstanceStatus() != InstanceStatus.TERMINATED).collect(Collectors.toList());
if (agentHostsSet.isEmpty()) {
throw new NotFoundException(String.format("Not found any agent hosts (yet) for cluster '%s'", cluster.getId()));
}
String agentHosts = agentHostsSet.stream().map(InstanceMetaData::getPublicIpWrapper).collect(Collectors.joining("\n"));
List<String> hostGroupHostsStrings = agentHostsSet.stream().collect(Collectors.groupingBy(InstanceMetaData::getInstanceGroupName)).entrySet().stream().map(s -> addSectionWithBody(s.getKey(), s.getValue().stream().map(InstanceMetaData::getPublicIpWrapper).collect(Collectors.joining("\n")))).collect(Collectors.toList());
return String.join("\n", addSectionWithBody("cluster", "name=" + clusterName), addSectionWithBody("server", serverHost), String.join("\n", hostGroupHostsStrings), addSectionWithBody("agent", agentHosts), addSectionWithBody("all:vars", String.join("\n", String.format("ansible_ssh_user=%s", loginUser), "ansible_ssh_common_args='-o StrictHostKeyChecking=no'", "ansible_become=yes")));
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class ClusterOperationService method updateAutoRecoverableNodes.
private void updateAutoRecoverableNodes(Cluster cluster, Map<String, List<String>> autoRecoveryNodesMap, Map<String, InstanceMetaData> autoRecoveryHostMetadata) throws TransactionExecutionException {
if (!autoRecoveryNodesMap.isEmpty()) {
flowManager.triggerClusterRepairFlow(cluster.getStack().getId(), autoRecoveryNodesMap, false);
Map<String, Optional<String>> hostNamesWithReason = autoRecoveryHostMetadata.keySet().stream().collect(Collectors.toMap(host -> host, host -> Optional.empty()));
Set<InstanceStatus> expectedStates = Set.of(SERVICES_HEALTHY);
InstanceStatus newState = InstanceStatus.WAITING_FOR_REPAIR;
ResourceEvent clusterEvent = CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT;
ResourceEvent hostEvent = CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT;
updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.of(hostEvent));
}
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class ClusterService method updateClusterMetadata.
public Cluster updateClusterMetadata(Long stackId) {
Stack stack = stackService.getById(stackId);
ClusterApi connector = clusterApiConnectors.getConnector(stack);
if (!connector.clusterStatusService().isClusterManagerRunning()) {
Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
InstanceMetaData cmInstance = updateClusterManagerHostStatus(notTerminatedInstanceMetaDatas);
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), CLUSTER_HOST_STATUS_UPDATED, Arrays.asList(cmInstance.getDiscoveryFQDN(), cmInstance.getInstanceStatus().name()));
return stack.getCluster();
} else {
ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(stack.getCluster().getId()));
updateClusterCertExpirationState(stack.getCluster(), extendedHostStatuses.isAnyCertExpiring());
try {
return transactionService.required(() -> {
Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
List<InstanceMetaData> updatedInstanceMetaData = updateInstanceStatuses(notTerminatedInstanceMetaDatas, extendedHostStatuses);
instanceMetaDataService.saveAll(updatedInstanceMetaData);
fireHostStatusUpdateNotification(stack, updatedInstanceMetaData);
return stack.getCluster();
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class ClusterService method updateInstancesToRunning.
public void updateInstancesToRunning(Long stackId, Set<Node> reachableNodes) {
try {
transactionService.required(() -> {
List<InstanceMetaData> createdInstances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(InstanceMetaData::isCreated).collect(Collectors.toList());
for (InstanceMetaData instanceMetaData : createdInstances) {
if (reachableNodes.stream().anyMatch(node -> node.getHostname().equals(instanceMetaData.getDiscoveryFQDN()))) {
instanceMetaData.setInstanceStatus(SERVICES_RUNNING);
instanceMetaDataService.save(instanceMetaData);
}
}
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class ClusterService method updateClusterManagerHostStatus.
private InstanceMetaData updateClusterManagerHostStatus(Set<InstanceMetaData> notTerminatedInstanceMetaDatas) {
InstanceMetaData cmInstance = notTerminatedInstanceMetaDatas.stream().filter(InstanceMetaData::getClusterManagerServer).findFirst().orElseThrow(() -> new CloudbreakServiceException("Cluster manager inaccessible, and the corresponding instance metadata not found."));
cmInstance.setInstanceStatus(SERVICES_UNHEALTHY);
cmInstance.setStatusReason("Cluster manager inaccessible.");
instanceMetaDataService.save(cmInstance);
return cmInstance;
}
Aggregations