<commit_before>/*
 * 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.ambari.server.upgrade;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.persist.Transactional;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.orm.DBAccessor;
import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
import org.apache.ambari.server.orm.dao.DaoUtils;
import org.apache.ambari.server.orm.dao.HostVersionDAO;
import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
import org.apache.ambari.server.orm.dao.StackDAO;
import org.apache.ambari.server.orm.dao.UpgradeDAO;
import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
import org.apache.ambari.server.orm.entities.ClusterEntity;
import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.orm.entities.HostVersionEntity;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.orm.entities.StackEntity;
import org.apache.ambari.server.orm.entities.UpgradeEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
import org.apache.ambari.server.state.RepositoryVersionState;
import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.state.StackInfo;
import org.apache.ambari.server.state.alert.SourceType;
import org.apache.ambari.server.state.stack.upgrade.Direction;
import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
import org.apache.ambari.server.utils.VersionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 * Upgrade catalog for version 2.1.3.
 */
public class UpgradeCatalog213 extends AbstractUpgradeCatalog {

  private static final String UPGRADE_TABLE = "upgrade";
  private static final String STORM_SITE = "storm-site";
  private static final String HDFS_SITE_CONFIG = "hdfs-site";
  private static final String KAFKA_BROKER = "kafka-broker";
  private static final String AMS_ENV = "ams-env";
  private static final String AMS_HBASE_ENV = "ams-hbase-env";
  private static final String AMS_SITE = "ams-site";
  private static final String HBASE_ENV_CONFIG = "hbase-env";
  private static final String HIVE_SITE_CONFIG = "hive-site";
  private static final String RANGER_ENV_CONFIG = "ranger-env";
  private static final String ZOOKEEPER_LOG4J_CONFIG = "zookeeper-log4j";
  private static final String NIMBS_MONITOR_FREQ_SECS_PROPERTY = "nimbus.monitor.freq.secs";
  private static final String HIVE_SERVER2_OPERATION_LOG_LOCATION_PROPERTY = "hive.server2.logging.operation.log.location";
  private static final String HADOOP_ENV_CONFIG = "hadoop-env";
  private static final String CONTENT_PROPERTY = "content";
  private static final String HADOOP_ENV_CONTENT_TO_APPEND = "\n{% if is_datanode_max_locked_memory_set %}\n" +
    "# Fix temporary bug, when ulimit from conf files is not picked up, without full relogin. \n" +
    "# Makes sense to fix only when runing DN as root \n" +
    "if [ \"$command\" == \"datanode\" ] && [ \"$EUID\" -eq 0 ] && [ -n \"$HADOOP_SECURE_DN_USER\" ]; then\n" +
    "  ulimit -l {{datanode_max_locked_memory}}\n" +
    "fi\n" +
    "{% endif %};\n";

  private static final String DOWNGRADE_ALLOWED_COLUMN = "downgrade_allowed";
  private static final String UPGRADE_SKIP_FAILURE_COLUMN = "skip_failures";
  private static final String UPGRADE_SKIP_SC_FAILURE_COLUMN = "skip_sc_failures";
  public static final String UPGRADE_PACKAGE_COL = "upgrade_package";
  public static final String UPGRADE_TYPE_COL = "upgrade_type";
  public static final String REPO_VERSION_TABLE = "repo_version";

  private static final String HOST_ROLE_COMMAND_TABLE = "host_role_command";
  private static final String HOST_ID_COL = "host_id";

  private static final String KERBEROS_DESCRIPTOR_TABLE = "kerberos_descriptor";
  private static final String KERBEROS_DESCRIPTOR_NAME_COLUMN = "kerberos_descriptor_name";<commit_msg>AMBARI-13717. Couldn`t start the most of services after upgrade from 2.1.2 to 192.168.3.11 (Debian7) (aonishuk)<commit_after>/*
 * 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.ambari.server.upgrade;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.persist.Transactional;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.orm.DBAccessor;
import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
import org.apache.ambari.server.orm.dao.DaoUtils;
import org.apache.ambari.server.orm.dao.HostVersionDAO;
import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
import org.apache.ambari.server.orm.dao.StackDAO;
import org.apache.ambari.server.orm.dao.UpgradeDAO;
import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
import org.apache.ambari.server.orm.entities.ClusterEntity;
import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.orm.entities.HostVersionEntity;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.orm.entities.StackEntity;
import org.apache.ambari.server.orm.entities.UpgradeEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
import org.apache.ambari.server.state.RepositoryVersionState;
import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.state.StackInfo;
import org.apache.ambari.server.state.alert.SourceType;
import org.apache.ambari.server.state.stack.upgrade.Direction;
import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
import org.apache.ambari.server.utils.VersionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 * Upgrade catalog for version 2.1.3.
 */
public class UpgradeCatalog213 extends AbstractUpgradeCatalog {

  private static final String UPGRADE_TABLE = "upgrade";
  private static final String STORM_SITE = "storm-site";
  private static final String HDFS_SITE_CONFIG = "hdfs-site";
  private static final String KAFKA_BROKER = "kafka-broker";
  private static final String AMS_ENV = "ams-env";
  private static final String AMS_HBASE_ENV = "ams-hbase-env";
  private static final String AMS_SITE = "ams-site";
  private static final String HBASE_ENV_CONFIG = "hbase-env";
  private static final String HIVE_SITE_CONFIG = "hive-site";
  private static final String RANGER_ENV_CONFIG = "ranger-env";
  private static final String ZOOKEEPER_LOG4J_CONFIG = "zookeeper-log4j";
  private static final String NIMBS_MONITOR_FREQ_SECS_PROPERTY = "nimbus.monitor.freq.secs";
  private static final String HIVE_SERVER2_OPERATION_LOG_LOCATION_PROPERTY = "hive.server2.logging.operation.log.location";
  private static final String HADOOP_ENV_CONFIG = "hadoop-env";
  private static final String CONTENT_PROPERTY = "content";
  private static final String HADOOP_ENV_CONTENT_TO_APPEND = "\n{% if is_datanode_max_locked_memory_set %}\n" +
    "# Fix temporary bug, when ulimit from conf files is not picked up, without full relogin. \n" +
    "# Makes sense to fix only when runing DN as root \n" +
    "if [ \"$command\" == \"datanode\" ] && [ \"$EUID\" -eq 0 ] && [ -n \"$HADOOP_SECURE_DN_USER\" ]; then\n" +
    "  ulimit -l {{datanode_max_locked_memory}}\n" +
    "fi\n" +
    "{% endif %}\n";

  private static final String DOWNGRADE_ALLOWED_COLUMN = "downgrade_allowed";
  private static final String UPGRADE_SKIP_FAILURE_COLUMN = "skip_failures";
  private static final String UPGRADE_SKIP_SC_FAILURE_COLUMN = "skip_sc_failures";
  public static final String UPGRADE_PACKAGE_COL = "upgrade_package";
  public static final String UPGRADE_TYPE_COL = "upgrade_type";
  public static final String REPO_VERSION_TABLE = "repo_version";

  private static final String HOST_ROLE_COMMAND_TABLE = "host_role_command";
  private static final String HOST_ID_COL = "host_id";

  private static final String KERBEROS_DESCRIPTOR_TABLE = "kerberos_descriptor";
  private static final String KERBEROS_DESCRIPTOR_NAME_COLUMN = "kerberos_descriptor_name";
{'fraction_non_alphanumeric': 0.0976303317535545, 'fraction_numerical': 0.004480827229642395, 'mean_word_length': 5.287107258938245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2501199', 'n_tokens_mistral': 3650, 'n_tokens_neox': 3641, 'n_words': 881}