// Path: cm-schema/src/main/java/com/cloudera/csd/descriptors/MetricEntityTypeDescriptor.java
// @Named
// @Unstable
// public interface MetricEntityTypeDescriptor {
// 
//   /**
//    * Returns the name of the entity type. This name uniquely identifies this
//    * entity type and is used to reference the type in the Cloudera Manager
//    * API and charting features.
//    * @return
//    */
//   @MetricEntityTypeFormat
//   String getName();
// 
//   /**
//    * Returns the string to use to pluralize the name of the entity for cross
//    * entity aggregate metrics. For example, for an entity named "ECHO_ENTITY"
//    * this should be "echo_entities". Cross entity aggregate metric names will be
//    * composed using this to generate metrics named like
//    * 'fd_open_across_echo_entities'.
//    *
//    * The string must be prefixed with the service name and be unique within this
//    * descriptor.
//    *
//    * If this is not specified the name will be constructed from the service
//    * name, the entity name, and an "s".
//    * @return
//    */
//   @NameForCrossEntityAggregatesFormat
//   String getNameForCrossEntityAggregateMetrics();
// 
//   /**
//    * Returns the display name of the entity type.
//    * @return
//    */
//   @NotEmpty
//   String getLabel();
// 
//   /**
//    * Returns the display name of the entity type in plural form.
//    * @return
//    */
//   @NotEmpty
//   String getLabelPlural();
// 
//   /**
//    * Returns the description of the entity type.
//    * @return
//    */
//   @NotEmpty
//   String getDescription();
// 
//   /**
//    * Returns the list immutable attributes for this entity type. Immutable
//    * attributes values for an entity may not change over its lifetime.
//    * @return
//    */
//   @NotEmpty
//   List<String> getImmutableAttributeNames();
// 
//   /**
//    * Returns the list mutable attributes for this entity type. Mutable
//    * attributes for an entity may change over its lifetime.
//    * @return
//    */
//   List<String> getMutableAttributeNames();
// 
//   /**
//    * Returns a list of attribute names that will be used to construct entity
//    * names for entities of this type. The attributes named here must be immutable
//    * attributes of this type or a parent type.
//    * @return
//    */
//   @NotEmpty
//   List<String> getEntityNameFormat();
// 
//   /**
//    * Returns a format string that will be used to construct the display name of
//    * entities of this type. If this returns null the entity name would be used
//    * as the display name.
//    *
//    * The entity attribute values are used to replace $attribute name portions of
//    * this format string. For example, an entity with roleType "DATANODE" and
//    * hostname "foo.com" will have a display name "DATANODE (foo.com)" if the
//    * format is "$roleType ($hostname)".
//    * @return
//    */
//   String getEntityLabelFormat();
// 
//   /**
//    * Returns a list of metric entity type names which are parents of this
//    * metric entity type. A metric entity type inherits the attributes of
//    * its ancestors. For example a role metric entity type has its service as a
//    * parent. A service metric entity type has a cluster as a parent. The role
//    * type inherits its cluster name attribute through its service parent. Only
//    * parent ancestors should be returned here. In the example given, only the
//    * service metric entity type should be specified in the parent list.
//    */
//   List<String> getParentMetricEntityTypeNames();
// 
//   /**
//    * Specifies metrics that will be registered for this metric entity type.
//    * @return
//    */
//   @UniqueField("name")
//   List<MetricDescriptor> getMetricDefinitions();
// }


import com.cloudera.csd.descriptors.MetricEntityTypeDescriptor;
import com.google.common.base.Preconditions;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
   * name that will be used for role cross entity aggregate metrics instead.
   * @param serviceType
   * @param roleType
   * @return
   */
  public static String getNameForRoleCrossEntityAggregateMetrics(
      String serviceType,
      String roleType) {
    Preconditions.checkNotNull(serviceType);
    Preconditions.checkNotNull(roleType);
    String normalizedRoleType = roleType.toLowerCase();
    String normalizedServiceType = serviceType.toLowerCase() + "_";
    if (normalizedRoleType.startsWith(normalizedServiceType)) {
      return normalizedRoleType + "s";
    }
    return String.format("%s%ss", normalizedServiceType, normalizedRoleType);
  }

  /**
   * Returns the name for cross entity aggregate metrics for an entity. For
   * example for the metric fd_open, echo service and echo_entity_one the cross
   * entity aggregate will be fd_open_across_echo_entity_ones. For the
   * metric fd_open echo service, and foobar the cross entity aggregate
   * will be fd_open_across_echo_foobars. Note that a CSD can provide a
   * name that will be used for entity cross entity aggregate metrics instead.
   * @param entityDescriptor
   * @param serviceType
   * @return
   */
  public static String getNameForEntityTypeCrossEntityAggregateMetrics(
// Path: cm-schema/src/main/java/com/cloudera/csd/descriptors/MetricEntityTypeDescriptor.java
// @Named
// @Unstable
// public interface MetricEntityTypeDescriptor {
// 
//   /**
//    * Returns the name of the entity type. This name uniquely identifies this
//    * entity type and is used to reference the type in the Cloudera Manager
//    * API and charting features.
//    * @return
//    */
//   @MetricEntityTypeFormat
//   String getName();
// 
//   /**
//    * Returns the string to use to pluralize the name of the entity for cross
//    * entity aggregate metrics. For example, for an entity named "ECHO_ENTITY"
//    * this should be "echo_entities". Cross entity aggregate metric names will be
//    * composed using this to generate metrics named like
//    * 'fd_open_across_echo_entities'.
//    *
//    * The string must be prefixed with the service name and be unique within this
//    * descriptor.
//    *
//    * If this is not specified the name will be constructed from the service
//    * name, the entity name, and an "s".
//    * @return
//    */
//   @NameForCrossEntityAggregatesFormat
//   String getNameForCrossEntityAggregateMetrics();
// 
//   /**
//    * Returns the display name of the entity type.
//    * @return
//    */
//   @NotEmpty
//   String getLabel();
// 
//   /**
//    * Returns the display name of the entity type in plural form.
//    * @return
//    */
//   @NotEmpty
//   String getLabelPlural();
// 
//   /**
//    * Returns the description of the entity type.
//    * @return
//    */
//   @NotEmpty
//   String getDescription();
// 
//   /**
//    * Returns the list immutable attributes for this entity type. Immutable
//    * attributes values for an entity may not change over its lifetime.
//    * @return
//    */
//   @NotEmpty
//   List<String> getImmutableAttributeNames();
// 
//   /**
//    * Returns the list mutable attributes for this entity type. Mutable
//    * attributes for an entity may change over its lifetime.
//    * @return
//    */
//   List<String> getMutableAttributeNames();
// 
//   /**
//    * Returns a list of attribute names that will be used to construct entity
//    * names for entities of this type. The attributes named here must be immutable
//    * attributes of this type or a parent type.
//    * @return
//    */
//   @NotEmpty
//   List<String> getEntityNameFormat();
// 
//   /**
//    * Returns a format string that will be used to construct the display name of
//    * entities of this type. If this returns null the entity name would be used
//    * as the display name.
//    *
//    * The entity attribute values are used to replace $attribute name portions of
//    * this format string. For example, an entity with roleType "DATANODE" and
//    * hostname "foo.com" will have a display name "DATANODE (foo.com)" if the
//    * format is "$roleType ($hostname)".
//    * @return
//    */
//   String getEntityLabelFormat();
// 
//   /**
//    * Returns a list of metric entity type names which are parents of this
//    * metric entity type. A metric entity type inherits the attributes of
//    * its ancestors. For example a role metric entity type has its service as a
//    * parent. A service metric entity type has a cluster as a parent. The role
//    * type inherits its cluster name attribute through its service parent. Only
//    * parent ancestors should be returned here. In the example given, only the
//    * service metric entity type should be specified in the parent list.
//    */
//   List<String> getParentMetricEntityTypeNames();
// 
//   /**
//    * Specifies metrics that will be registered for this metric entity type.
//    * @return
//    */
//   @UniqueField("name")
//   List<MetricDescriptor> getMetricDefinitions();
// }


// Path: cm-schema/src/main/java/com/cloudera/csd/validation/monitoring/MonitoringConventions.java
import com.cloudera.csd.descriptors.MetricEntityTypeDescriptor;
import com.google.common.base.Preconditions;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

   * name that will be used for role cross entity aggregate metrics instead.
   * @param serviceType
   * @param roleType
   * @return
   */
  public static String getNameForRoleCrossEntityAggregateMetrics(
      String serviceType,
      String roleType) {
    Preconditions.checkNotNull(serviceType);
    Preconditions.checkNotNull(roleType);
    String normalizedRoleType = roleType.toLowerCase();
    String normalizedServiceType = serviceType.toLowerCase() + "_";
    if (normalizedRoleType.startsWith(normalizedServiceType)) {
      return normalizedRoleType + "s";
    }
    return String.format("%s%ss", normalizedServiceType, normalizedRoleType);
  }

  /**
   * Returns the name for cross entity aggregate metrics for an entity. For
   * example for the metric fd_open, echo service and echo_entity_one the cross
   * entity aggregate will be fd_open_across_echo_entity_ones. For the
   * metric fd_open echo service, and foobar the cross entity aggregate
   * will be fd_open_across_echo_foobars. Note that a CSD can provide a
   * name that will be used for entity cross entity aggregate metrics instead.
   * @param entityDescriptor
   * @param serviceType
   * @return
   */
  public static String getNameForEntityTypeCrossEntityAggregateMetrics(
      MetricEntityTypeDescriptor entityDescriptor,