ambari-server- 资源provider分析

本篇主要讲解资源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

@Singleton
public 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;

后续将分析数据库存储。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值