ambari-server- 资源provider分析

来源:互联网 发布:伊尔18客机数据 编辑:程序博客网 时间:2024/06/05 04:30

本篇主要讲解资源provider,它们是实际数据的提供者,自然会和原始数据打交道。
原始数据包括mysql等落地数据,还有就是实时数据。

这里还是以 GET /clusters/c1/services/HDFS/components/DATANODE 为例进行,该接口用于获取hdfs服务datanode的信息。

入口为ComponentResourceProvider类的getResources方法,方法首先获得请求对应的response组,response为ServiceComponentResponse类,这里用到了匿名类,该类集成Command类,重载invoke方法。

匿名类

    Set<ServiceComponentResponse> responses = getResources(new Command<Set<ServiceComponentResponse>>() {      @Override      public Set<ServiceComponentResponse> invoke() throws AmbariException {        return getComponents(requests);      }    });

相关实体类

Clusters--》Cluster--》Service--》ServiceComponent

首先获得ServiceComponent类,调用convertToResponse方法,将其转为ServiceComponentResponse,主要包含,服务名等信息。ServiceComponentResponse主要是一些component的基本信息。

目前来看数据信息基本都在内存中存储,没有进行落地,或者说是在启动时加载,运行时不在于数据库产生交互;主要的存储类即为Clusters和Cluster。

clusters

@Singletonpublic class ClustersImpl implements Clusters {  private static final Logger LOG = LoggerFactory.getLogger(ClustersImpl.class);  //名字为key集群组  private final ConcurrentHashMap<String, Cluster> clusters = new ConcurrentHashMap<String, Cluster>();  //id为key集群组  private final ConcurrentHashMap<Long, Cluster> clustersById = new ConcurrentHashMap<Long, Cluster>();  //名字为key主机组  private final ConcurrentHashMap<String, Host> hosts = new ConcurrentHashMap<String, Host>();  //id为key主机组  private final ConcurrentHashMap<Long, Host> hostsById = new ConcurrentHashMap<Long, Host>();  //主机,集群对应关系;一个主机可以在多个集群  private final ConcurrentHashMap<String, Set<Cluster>> hostClusterMap = new ConcurrentHashMap<String, Set<Cluster>>();  //集群,主机对应关系;一个集群可以对应多个主机  private final ConcurrentHashMap<String, Set<Host>> clusterHostMap = new ConcurrentHashMap<String, Set<Host>>();

Cluster

public class ClusterImpl implements Cluster {  。。。  //对应stack id  private StackId desiredStackVersion;  //名字为key服务组  private final ConcurrentSkipListMap<String, Service> services = new ConcurrentSkipListMap<>();  //配置信息  /**   * [ Config Type -> [ Config Version Tag -> Config ] ]   */  private final ConcurrentMap<String, ConcurrentMap<String, Config>> allConfigs = new ConcurrentHashMap<>();  //服务对应 组件 对应 主机信息  /**   * [ ServiceName -> [ ServiceComponentName -> [ HostName -> [ ... ] ] ] ]   */  private final ConcurrentMap<String, ConcurrentMap<String, ConcurrentMap<String, ServiceComponentHost>>> serviceComponentHosts = new ConcurrentHashMap<>();  //主机对应组件信息  /**   * [ HostName -> [ ... ] ]   */  private final ConcurrentMap<String, List<ServiceComponentHost>> serviceComponentHostsByHost = new ConcurrentHashMap<>();  //配置组信息  /**   * Map of existing config groups   */  private final Map<Long, ConfigGroup> clusterConfigGroups = new ConcurrentHashMap<>();  //集群调度执行信息  /**   * Map of Request schedules for this cluster   */  private final Map<Long, RequestExecution> requestExecutions = new ConcurrentHashMap<>();  //集群全局锁  private final ReadWriteLock clusterGlobalLock;  //主机状态切换锁  // This is a lock for operations that do not need to be cluster global  private final Lock hostTransitionStateWriteLock;  /**   * The unique ID of the {@link @ClusterEntity}.   */  private final long clusterId;  //集群名称  private String clusterName;

后续将分析数据库存储。

原创粉丝点击