class UpgradeCatalog274 extends AbstractUpgradeCatalog {

  protected void updateNameNodeAlertsAppId() {
    AlertDefinitionDAO alertDefinitionDAO = injector.getInstance(AlertDefinitionDAO.class);
    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
    AlertDefinitionFactory alertDefinitionFactory = injector.getInstance(AlertDefinitionFactory.class);

    Clusters clusters = ambariManagementController.getClusters();
    if (clusters != null) {
      Map<String, Cluster> clusterMap = clusters.getClusters();
      if (MapUtils.isNotEmpty(clusterMap)) {
        for (final Cluster cluster : clusterMap.values()) {
          if (cluster.getServices().containsKey(HDFS_SERVICE_NAME)) {
            List<AlertDefinitionEntity> alertDefinitions =
                alertDefinitionDAO.findByServiceComponent(cluster.getClusterId(), HDFS_SERVICE_NAME, NAMENODE_COMPONENT_NAME);
            for (AlertDefinitionEntity alertDefinitionEntity : alertDefinitions) {
              if (SourceType.SCRIPT.equals(alertDefinitionEntity.getSourceType())) {
                AlertDefinition databaseDefinition = alertDefinitionFactory.coerce(alertDefinitionEntity);
                ScriptSource scriptSource = (ScriptSource) databaseDefinition.getSource();
                for (ParameterizedSource.AlertParameter scriptParameter : scriptSource.getParameters()) {
                  if (APPID_PROPERTY_NAME.equals(scriptParameter.getName())) {
                    String value = (String) scriptParameter.getValue();
                    if (value.equalsIgnoreCase(NAMENODE_APP_ID) && !value.equals(NAMENODE_APP_ID)) {
                      scriptParameter.setValue(NAMENODE_APP_ID);
                    }
                  }
                }
                alertDefinitionEntity = alertDefinitionFactory.mergeSource(scriptSource, alertDefinitionEntity);
                alertDefinitionDAO.merge(alertDefinitionEntity);
              }
            }
          }
        }
      }
    }
  }

  @Inject public  UpgradeCatalog274(Injector injector);

}