From e65a44713f277d3886be15e79def20b2ebed9b8e Mon Sep 17 00:00:00 2001 From: Tim Kuhlman Date: Wed, 26 Feb 2014 08:39:17 -0700 Subject: [PATCH] Added a simple technique to pre load the mysql schema, fixed bind address. --- files/default/addr_validate.sql | 38 ++++++ files/default/maas.sql | 199 ++++++++++++++++++++++++++++++++ recipes/mysql_schema.rb | 27 +++++ roles/MySQL.json | 5 +- 4 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 files/default/addr_validate.sql create mode 100644 files/default/maas.sql create mode 100644 recipes/mysql_schema.rb diff --git a/files/default/addr_validate.sql b/files/default/addr_validate.sql new file mode 100644 index 0000000..8b04236 --- /dev/null +++ b/files/default/addr_validate.sql @@ -0,0 +1,38 @@ +CREATE DATABASE IF NOT EXISTS `addr_validate` DEFAULT CHARACTER SET latin1; +USE `addr_validate`; + +DROP TABLE IF EXISTS `address_blacklist`; +CREATE TABLE `address_blacklist` ( + `name` varchar(100) NOT NULL, + `type` enum('SMS','EMAIL') NOT NULL, + `comment` varchar(256) NOT NULL, + PRIMARY KEY (`name`,`type`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `limits`; +CREATE TABLE `limits` ( + `tenant_id` varchar(64) NOT NULL, + `max_addresses` int(11) DEFAULT NULL, + `max_outstanding_requests` int(11) DEFAULT NULL, + PRIMARY KEY (`tenant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `requests`; +CREATE TABLE `requests` ( + `id` varchar(36) NOT NULL, + `address` varchar(128) DEFAULT NULL, + `type` enum('EMAIL','SMS') DEFAULT NULL, + `state` enum('in-progress','timed-out','verified') DEFAULT NULL, + `created` datetime DEFAULT NULL, + `updated` datetime DEFAULT NULL, + `tenant_id` varchar(64) DEFAULT NULL, + `token` varchar(128) DEFAULT NULL, + `name` varchar(128) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `schema_migrations`; +CREATE TABLE `schema_migrations` ( + `version` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + UNIQUE KEY `unique_schema_migrations` (`version`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/files/default/maas.sql b/files/default/maas.sql new file mode 100644 index 0000000..51a5af1 --- /dev/null +++ b/files/default/maas.sql @@ -0,0 +1,199 @@ +CREATE DATABASE IF NOT EXISTS `maas` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +USE `maas`; + +SET foreign_key_checks = 0; + +DROP TABLE IF EXISTS `access`; +CREATE TABLE `access` ( + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + `access_type` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + PRIMARY KEY (`tenant_id`,`access_type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `alarm`; +CREATE TABLE `alarm` ( + `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `name` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `expression` mediumtext COLLATE utf8mb4_unicode_ci, + `state` enum('UNDETERMINED','OK','ALARM') COLLATE utf8mb4_unicode_ci NOT NULL, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + `deleted_at` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `tenant_id` (`tenant_id`), + KEY `created_at` (`created_at`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `alarm_action`; +CREATE TABLE `alarm_action` ( + `alarm_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `action_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`alarm_id`,`action_id`), + CONSTRAINT `alarm_action` FOREIGN KEY (`alarm_id`) REFERENCES `alarm` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `audit_api_call_count`; +CREATE TABLE `audit_api_call_count` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `count` int(11) NOT NULL, + `created_at` datetime NOT NULL, + PRIMARY KEY (`id`), + KEY `tenant_id` (`tenant_id`), + KEY `created_at` (`created_at`) +) ENGINE=InnoDB AUTO_INCREMENT=107928 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `audit_billing`; +CREATE TABLE `audit_billing` ( + `audit_period_beginning` datetime NOT NULL, + `audit_period_ending` datetime NOT NULL, + PRIMARY KEY (`audit_period_beginning`,`audit_period_ending`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `audit_metric_post_definitions`; +CREATE TABLE `audit_metric_post_definitions` ( + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `hash` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + `created_at` datetime NOT NULL, + PRIMARY KEY (`tenant_id`,`hash`,`created_at`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `audit_notifications`; +CREATE TABLE `audit_notifications` ( + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `type` enum('EMAIL','SMS') COLLATE utf8mb4_unicode_ci NOT NULL, + `created_at` datetime NOT NULL, + PRIMARY KEY (`tenant_id`,`created_at`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `endpoint`; +CREATE TABLE `endpoint` ( + `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `uri` varchar(300) COLLATE utf8mb4_unicode_ci NOT NULL, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `tenant_id` (`tenant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `endpoint_meta`; +CREATE TABLE `endpoint_meta` ( + `endpoint_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, + `value` varchar(300) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`endpoint_id`,`name`), + CONSTRAINT `endpoint_meta` FOREIGN KEY (`endpoint_id`) REFERENCES `endpoint` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `metering_settings`; +CREATE TABLE `metering_settings` ( + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `setting` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + `value` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + PRIMARY KEY (`tenant_id`,`setting`,`value`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `notification_limit`; +CREATE TABLE `notification_limit` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `type` enum('EMAIL','SMS') COLLATE utf8mb4_unicode_ci NOT NULL, + `total` int(11) NOT NULL, + `limit` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `notification_method`; +CREATE TABLE `notification_method` ( + `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `name` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `type` enum('EMAIL','SMS') COLLATE utf8mb4_unicode_ci NOT NULL, + `address` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `notification_time_limit`; +CREATE TABLE `notification_time_limit` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `tenant_id` varchar(36) NOT NULL, + `notifications_per_minute` float NOT NULL, + `notifications_per_hour` float NOT NULL, + `notifications_per_day` float NOT NULL, + `last_updated` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `schema_migrations`; +CREATE TABLE `schema_migrations` ( + `version` varchar(255) NOT NULL, + UNIQUE KEY `unique_schema_migrations` (`version`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `sub_alarm`; +CREATE TABLE `sub_alarm` ( + `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `alarm_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `function` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, + `namespace` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `operator` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL, + `threshold` double NOT NULL, + `period` int(11) NOT NULL, + `periods` int(11) NOT NULL, + `state` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_sub_alarm` (`alarm_id`), + CONSTRAINT `fk_sub_alarm` FOREIGN KEY (`alarm_id`) REFERENCES `alarm` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `sub_alarm_dimension`; +CREATE TABLE `sub_alarm_dimension` ( + `sub_alarm_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `dimension_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + `value` varchar(300) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`sub_alarm_id`,`dimension_name`), + CONSTRAINT `fk_sub_alarm_dimension` FOREIGN KEY (`sub_alarm_id`) REFERENCES `sub_alarm` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `subscription`; +CREATE TABLE `subscription` ( + `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `endpoint_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `namespace` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + `deleted_at` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `subscription_endpoint` (`endpoint_id`), + KEY `tenant_id` (`tenant_id`), + KEY `namespace` (`namespace`), + KEY `created_at` (`created_at`), + CONSTRAINT `subscription_endpoint` FOREIGN KEY (`endpoint_id`) REFERENCES `endpoint` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `subscription_dimension`; +CREATE TABLE `subscription_dimension` ( + `subscription_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `dimension_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + `value` varchar(300) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`subscription_id`,`dimension_name`), + CONSTRAINT `subscription_dimension` FOREIGN KEY (`subscription_id`) REFERENCES `subscription` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +DROP TABLE IF EXISTS `subscription_meta`; +CREATE TABLE `subscription_meta` ( + `subscription_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, + `name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + `value` varchar(300) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`subscription_id`,`name`), + CONSTRAINT `subscription_meta` FOREIGN KEY (`subscription_id`) REFERENCES `subscription` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +SET foreign_key_checks = 1; diff --git a/recipes/mysql_schema.rb b/recipes/mysql_schema.rb new file mode 100644 index 0000000..e48c4c5 --- /dev/null +++ b/recipes/mysql_schema.rb @@ -0,0 +1,27 @@ +# Temporary way of loading in the mysql schema + +bash 'maas_schema' do + action :nothing + code 'mysql -uroot -ppassword < /var/lib/mysql/maas.sql' +end + +bash 'addr_validate_schema' do + action :nothing + code 'mysql -uroot -ppassword < /var/lib/mysql/addr_validate.sql' +end + +cookbook_file '/var/lib/mysql/maas.sql' do + action :create + owner 'root' + group 'root' + source 'maas.sql' + notifies :run, "bash[maas_schema]" +end + +cookbook_file '/var/lib/mysql/addr_validate.sql' do + action :create + owner 'root' + group 'root' + source 'addr_validate.sql' + notifies :run, "bash[addr_validate_schema]" +end diff --git a/roles/MySQL.json b/roles/MySQL.json index f9e4119..c2ff6f2 100644 --- a/roles/MySQL.json +++ b/roles/MySQL.json @@ -10,7 +10,9 @@ "cluster": { "package": "percona-xtradb-cluster-56" }, + "main_config_file": "/etc/mysql/my.cnf", "server": { + "bind_address": "0.0.0.0", "debain_password": "password", "replication": { "password": "password" @@ -25,7 +27,8 @@ "chef_type": "role", "run_list": [ "role[Basenode]", - "recipe[percona::cluster]" + "recipe[percona::cluster]", + "recipe[mini-mon::mysql_schema]" ], "env_run_lists": { }