<commit_before>package org.apache.ambari.server.upgrade;

import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.Injector;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
import org.apache.ambari.server.orm.dao.ClusterStateDAO;
import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
import org.apache.ambari.server.orm.dao.HostDAO;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.dao.KeyValueDAO;
import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
import org.apache.ambari.server.orm.entities.ClusterConfigEntityPK;
import org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity;
import org.apache.ambari.server.orm.entities.ClusterEntity;
import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
import org.apache.ambari.server.orm.entities.ClusterServiceEntityPK;
import org.apache.ambari.server.orm.entities.ClusterStateEntity;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK;
import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
import org.apache.ambari.server.orm.entities.KeyValueEntity;
import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntityPK;
import org.apache.ambari.server.state.HostComponentAdminState;
import org.apache.ambari.server.state.PropertyInfo;
import org.apache.ambari.server.state.ServiceInfo;
import org.apache.ambari.server.state.State;
import org.eclipse.persistence.jpa.JpaEntityManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.*;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.HashMap;

public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
  private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog150.class);
  private static final String quartzScriptFilePattern = "quartz.%s.sql";
  private Injector injector;

  @Inject
  public UpgradeCatalog150(Injector injector) {
    super(injector);
    this.injector = injector;
  }

  @Override
  public void executeDDLUpdates() throws AmbariException, SQLException {
    LOG.debug("Upgrading schema...");
    String dbType = getDbType();
    List<DBColumnInfo> columns = new ArrayList<DBColumnInfo>();

    // ========================================================================
    // Create tables

    // ClusterConfigMapping
    columns.add(new DBColumnInfo("cluster_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("type_name", String.class, 255, null, false));
    columns.add(new DBColumnInfo("version_tag", String.class, 255, null, false));
    columns.add(new DBColumnInfo("create_timestamp", Long.class, null, null, false));
    columns.add(new DBColumnInfo("selected", Integer.class, 0, null, false));
    columns.add(new DBColumnInfo("user_name", String.class, 255, "_db", false));

    dbAccessor.createTable("clusterconfigmapping", columns, "cluster_id", "type_name", "create_timestamp");

    // Request
    columns.clear();
    columns.add(new DBColumnInfo("request_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("cluster_id", Long.class, null, null, true));
    columns.add(new DBColumnInfo("request_schedule_id", Long.class, null, null, true));
    columns.add(new DBColumnInfo("command_name", String.class, 255, null, true));
    columns.add(new DBColumnInfo("create_time", Long.class, null, null, true));
    columns.add(new DBColumnInfo("end_time", Long.class, null, null, true));
    columns.add(new DBColumnInfo("inputs", byte[].class, null, null, true));
    columns.add(new DBColumnInfo("request_context", String.class, 255, null, true));
    columns.add(new DBColumnInfo("request_type", String.class, 255, null, true));
    columns.add(new DBColumnInfo("start_time", Long.class, null, null, false));
    columns.add(new DBColumnInfo("status", String.class, 255));

    dbAccessor.createTable("request", columns, "request_id");

    // RequestSchedule
    columns.clear();
    columns.add(new DBColumnInfo("schedule_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("cluster_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("description", String.class, 255, null, true));
    columns.add(new DBColumnInfo("status", String.class, 255, null, true));
    columns.add(new DBColumnInfo("batch_separation_seconds", Integer.class, null, null, true));
    columns.add(new DBColumnInfo("batch_toleration_limit", Integer.class, null, null, true));
    columns.add(new DBColumnInfo("create_user", String.class, 255, null, true));
    columns.add(new DBColumnInfo("create_timestamp", Long.class, null, null, true));
    columns.add(new DBColumnInfo("update_user", String.class, 255, null, true));
    columns.add(new DBColumnInfo("update_timestamp", Long.class, null, null, true));
    columns.add(new DBColumnInfo("minutes", String.class, 10, null, true));
    columns.add(new DBColumnInfo("hours", String.class, 10, null, true));
    columns.add(new DBColumnInfo("days_of_month", String.class, 10, null, true));
    columns.add(new DBColumnInfo("month", String.class, 10, null, true));
    columns.add(new DBColumnInfo("day_of_week", String.class, 10, null, true));
    columns.add(new DBColumnInfo("yearToSchedule", String.class, 10, null, true));
    columns.add(new DBColumnInfo("startTime", String.class, 50, null, true));
    columns.add(new DBColumnInfo("endTime", String.class, 50, null, true));
    columns.add(new DBColumnInfo("last_execution_status", String.class, 255, null, true));

    dbAccessor.createTable("requestschedule", columns, "schedule_id");

    // RequestScheduleBatchRequest
    columns.clear();
    columns.add(new DBColumnInfo("schedule_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("batch_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("request_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("request_type", String.class, 255, null, true));
    columns.add(new DBColumnInfo("request_uri", String.class, 1024, null, true));
    columns.add(new DBColumnInfo("request_body", byte[].class, null, null, true));
    columns.add(new DBColumnInfo("request_status", String.class, 255, null, true));
    columns.add(new DBColumnInfo("return_code", Integer.class, null, null, true));
    columns.add(new DBColumnInfo("return_message", String.class, 2000, null, true));

    dbAccessor.createTable("requestschedulebatchrequest", columns, "schedule_id", "batch_id");

    // HostConfigMapping
    columns.clear();
    columns.add(new DBColumnInfo("cluster_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("host_name", String.class, 255, null, false));
    columns.add(new DBColumnInfo("type_name", String.class, 255, null, false));
    columns.add(new DBColumnInfo("version_tag", String.class, 255, null, true));<commit_msg>AMBARI-5271. Rolling Restart doesn't work after upgrade from 1.4.4. (swagle)<commit_after>package org.apache.ambari.server.upgrade;

import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.Injector;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
import org.apache.ambari.server.orm.dao.ClusterStateDAO;
import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
import org.apache.ambari.server.orm.dao.HostDAO;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.dao.KeyValueDAO;
import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
import org.apache.ambari.server.orm.entities.ClusterConfigEntityPK;
import org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity;
import org.apache.ambari.server.orm.entities.ClusterEntity;
import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
import org.apache.ambari.server.orm.entities.ClusterServiceEntityPK;
import org.apache.ambari.server.orm.entities.ClusterStateEntity;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK;
import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
import org.apache.ambari.server.orm.entities.KeyValueEntity;
import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntityPK;
import org.apache.ambari.server.state.HostComponentAdminState;
import org.apache.ambari.server.state.PropertyInfo;
import org.apache.ambari.server.state.ServiceInfo;
import org.apache.ambari.server.state.State;
import org.eclipse.persistence.jpa.JpaEntityManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.*;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.HashMap;

public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
  private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog150.class);
  private static final String quartzScriptFilePattern = "quartz.%s.sql";
  private Injector injector;

  @Inject
  public UpgradeCatalog150(Injector injector) {
    super(injector);
    this.injector = injector;
  }

  @Override
  public void executeDDLUpdates() throws AmbariException, SQLException {
    LOG.debug("Upgrading schema...");
    String dbType = getDbType();
    List<DBColumnInfo> columns = new ArrayList<DBColumnInfo>();

    // ========================================================================
    // Create tables

    // ClusterConfigMapping
    columns.add(new DBColumnInfo("cluster_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("type_name", String.class, 255, null, false));
    columns.add(new DBColumnInfo("version_tag", String.class, 255, null, false));
    columns.add(new DBColumnInfo("create_timestamp", Long.class, null, null, false));
    columns.add(new DBColumnInfo("selected", Integer.class, 0, null, false));
    columns.add(new DBColumnInfo("user_name", String.class, 255, "_db", false));

    dbAccessor.createTable("clusterconfigmapping", columns, "cluster_id", "type_name", "create_timestamp");

    // Request
    columns.clear();
    columns.add(new DBColumnInfo("request_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("cluster_id", Long.class, null, null, true));
    columns.add(new DBColumnInfo("request_schedule_id", Long.class, null, null, true));
    columns.add(new DBColumnInfo("command_name", String.class, 255, null, true));
    columns.add(new DBColumnInfo("create_time", Long.class, null, null, true));
    columns.add(new DBColumnInfo("end_time", Long.class, null, null, true));
    columns.add(new DBColumnInfo("inputs", byte[].class, null, null, true));
    columns.add(new DBColumnInfo("request_context", String.class, 255, null, true));
    columns.add(new DBColumnInfo("request_type", String.class, 255, null, true));
    columns.add(new DBColumnInfo("start_time", Long.class, null, null, false));
    columns.add(new DBColumnInfo("status", String.class, 255));

    dbAccessor.createTable("request", columns, "request_id");

    // RequestSchedule
    columns.clear();
    columns.add(new DBColumnInfo("schedule_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("cluster_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("description", String.class, 255, null, true));
    columns.add(new DBColumnInfo("status", String.class, 255, null, true));
    columns.add(new DBColumnInfo("batch_separation_seconds", Integer.class, null, null, true));
    columns.add(new DBColumnInfo("batch_toleration_limit", Integer.class, null, null, true));
    columns.add(new DBColumnInfo("create_user", String.class, 255, null, true));
    columns.add(new DBColumnInfo("create_timestamp", Long.class, null, null, true));
    columns.add(new DBColumnInfo("update_user", String.class, 255, null, true));
    columns.add(new DBColumnInfo("update_timestamp", Long.class, null, null, true));
    columns.add(new DBColumnInfo("minutes", String.class, 10, null, true));
    columns.add(new DBColumnInfo("hours", String.class, 10, null, true));
    columns.add(new DBColumnInfo("days_of_month", String.class, 10, null, true));
    columns.add(new DBColumnInfo("month", String.class, 10, null, true));
    columns.add(new DBColumnInfo("day_of_week", String.class, 10, null, true));
    columns.add(new DBColumnInfo("yearToSchedule", String.class, 10, null, true));
    columns.add(new DBColumnInfo("startTime", String.class, 50, null, true));
    columns.add(new DBColumnInfo("endTime", String.class, 50, null, true));
    columns.add(new DBColumnInfo("last_execution_status", String.class, 255, null, true));

    dbAccessor.createTable("requestschedule", columns, "schedule_id");

    // RequestScheduleBatchRequest
    columns.clear();
    columns.add(new DBColumnInfo("schedule_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("batch_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("request_id", Long.class, null, null, true));
    columns.add(new DBColumnInfo("request_type", String.class, 255, null, true));
    columns.add(new DBColumnInfo("request_uri", String.class, 1024, null, true));
    columns.add(new DBColumnInfo("request_body", byte[].class, null, null, true));
    columns.add(new DBColumnInfo("request_status", String.class, 255, null, true));
    columns.add(new DBColumnInfo("return_code", Integer.class, null, null, true));
    columns.add(new DBColumnInfo("return_message", String.class, 2000, null, true));

    dbAccessor.createTable("requestschedulebatchrequest", columns, "schedule_id", "batch_id");

    // HostConfigMapping
    columns.clear();
    columns.add(new DBColumnInfo("cluster_id", Long.class, null, null, false));
    columns.add(new DBColumnInfo("host_name", String.class, 255, null, false));
    columns.add(new DBColumnInfo("type_name", String.class, 255, null, false));
    columns.add(new DBColumnInfo("version_tag", String.class, 255, null, true));
{'fraction_non_alphanumeric': 0.14303638644918445, 'fraction_numerical': 0.01135508155583438, 'mean_word_length': 5.8563440860215055, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '3406732', 'n_tokens_mistral': 4992, 'n_tokens_neox': 4846, 'n_words': 938}