All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.zeppelin.cluster.meta.ClusterMeta Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.zeppelin.cluster.meta;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Metadata stores metadata information in a KV key-value pair
 */
public class ClusterMeta implements Serializable {
  private static final Logger LOGGER = LoggerFactory.getLogger(ClusterMeta.class);

  // The name of each server node in the cluster
  public static final String NODE_NAME = "NODE_NAME";

  // zeppelin-server meta
  public static final String SERVER_HOST = "SERVER_HOST";
  public static final String SERVER_PORT = "SERVER_PORT";
  public static final String SERVER_START_TIME = "SERVER_START_TIME";

  // interperter-process meta
  public static final String INTP_PROCESS_NAME = "INTP_PROCESS_NAME";
  public static final String INTP_TSERVER_HOST = "INTP_TSERVER_HOST";
  public static final String INTP_TSERVER_PORT = "INTP_TSERVER_PORT";
  public static final String INTP_START_TIME = "INTP_START_TIME";

  // zeppelin-server resource usage
  public static final String CPU_CAPACITY = "CPU_CAPACITY";
  public static final String CPU_USED = "CPU_USED";
  public static final String MEMORY_CAPACITY = "MEMORY_CAPACITY";
  public static final String MEMORY_USED = "MEMORY_USED";

  public static final String LATEST_HEARTBEAT = "LATEST_HEARTBEAT";

  // zeppelin-server or interperter-process status
  public static final String STATUS = "STATUS";
  public static final String ONLINE_STATUS = "ONLINE";
  public static final String OFFLINE_STATUS = "OFFLINE";
  public static final String INTP_PROCESS_COUNT = "INTP_PROCESS_COUNT";
  public static final String INTP_PROCESS_LIST = "INTP_PROCESS_LIST";

  // cluster_name = host:port
  // Map:cluster_name -> {server_tserver_host,server_tserver_port,cpu_capacity,...}
  private Map> mapServerMeta = new HashMap<>();

  // Map:InterpreterGroupId -> {cluster_name,intp_tserver_host,...}
  private Map> mapInterpreterMeta = new HashMap<>();

  public void put(ClusterMetaType type, String key, Object value) {
    Map mapValue = (Map) value;

    switch (type) {
      case SERVER_META:
        // Because it may be partially updated metadata information
        if (mapServerMeta.containsKey(key)) {
          Map values = mapServerMeta.get(key);
          values.putAll(mapValue);
        } else {
          mapServerMeta.put(key, mapValue);
        }
        break;
      case INTP_PROCESS_META:
        if (mapInterpreterMeta.containsKey(key)) {
          Map values = mapInterpreterMeta.get(key);
          values.putAll(mapValue);
        } else {
          mapInterpreterMeta.put(key, mapValue);
        }
        break;
    }
  }

  public Map> get(ClusterMetaType type, String key) {
    Map values = null;

    switch (type) {
      case SERVER_META:
        if (null == key || StringUtils.isEmpty(key)) {
          return mapServerMeta;
        }
        if (mapServerMeta.containsKey(key)) {
          values = mapServerMeta.get(key);
        } else {
          LOGGER.warn("can not find key : {}", key);
        }
        break;
      case INTP_PROCESS_META:
        if (null == key || StringUtils.isEmpty(key)) {
          return mapInterpreterMeta;
        }
        if (mapInterpreterMeta.containsKey(key)) {
          values = mapInterpreterMeta.get(key);
        } else {
          LOGGER.warn("can not find key : {}", key);
        }
        break;
    }

    Map> result = new HashMap<>();
    result.put(key, values);

    return result;
  }

  public Map remove(ClusterMetaType type, String key) {
    switch (type) {
      case SERVER_META:
        if (mapServerMeta.containsKey(key)) {
          return mapServerMeta.remove(key);
        } else {
          LOGGER.warn("can not find key : {}", key);
        }
        break;
      case INTP_PROCESS_META:
        if (mapInterpreterMeta.containsKey(key)) {
          return mapInterpreterMeta.remove(key);
        } else {
          LOGGER.warn("can not find key : {}", key);
        }
        break;
    }

    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy