summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-02-21 12:27:59 +0000
committerGerrit Code Review <review@openstack.org>2019-02-21 12:27:59 +0000
commit4681262d8266723ec572c75e79f675977bf10a32 (patch)
tree25f7dadf44715c37ad545bc4966fa53def632e96
parent87631f37f92db195d330974696e8ebccb3c4bbf4 (diff)
parent6409d064390b11b0c4d622e35f1cfb2d99215674 (diff)
Merge "Set up DB schema in DevStack plugin using Alembic"HEADmaster
-rw-r--r--devstack/files/monasca-notification/notification.yaml4
-rw-r--r--devstack/files/schema/mon_mysql.sql198
-rw-r--r--devstack/files/schema/mon_postgresql.sql227
-rw-r--r--devstack/lib/notification.sh2
-rwxr-xr-xdevstack/plugin.sh19
-rw-r--r--monasca_api/db/alembic/versions/00597b5c8325_initial.py15
-rw-r--r--monasca_api/db/alembic/versions/6b2b88f3cab4_add_sub_alarm_state.py3
7 files changed, 18 insertions, 450 deletions
diff --git a/devstack/files/monasca-notification/notification.yaml b/devstack/files/monasca-notification/notification.yaml
index 5e386f6..1f9ad95 100644
--- a/devstack/files/monasca-notification/notification.yaml
+++ b/devstack/files/monasca-notification/notification.yaml
@@ -48,6 +48,10 @@ postgresql:
48 database: mon 48 database: mon
49 49
50notification_types: 50notification_types:
51 plugins:
52 - monasca_notification.plugins.email_notifier:EmailNotifier
53 - monasca_notification.plugins.webhook_notifier:WebhookNotifier
54 - monasca_notification.plugins.pagerduty_notifier:PagerdutyNotifier
51 55
52 email: 56 email:
53 server: "localhost" 57 server: "localhost"
diff --git a/devstack/files/schema/mon_mysql.sql b/devstack/files/schema/mon_mysql.sql
deleted file mode 100644
index d041f08..0000000
--- a/devstack/files/schema/mon_mysql.sql
+++ /dev/null
@@ -1,198 +0,0 @@
1/*
2* (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP
3* Copyright 2017 FUJITSU LIMITED
4*
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9*    http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14* implied.
15* See the License for the specific language governing permissions and
16* limitations under the License.
17*/
18
19USE `mon`;
20SET foreign_key_checks = 0;
21
22/*
23 * Enum tables
24 */
25CREATE TABLE `alarm_state` (
26 `name` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
27 PRIMARY KEY (`name`)
28) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
29
30CREATE TABLE `alarm_definition_severity` (
31 `name` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
32 PRIMARY KEY (`name`)
33) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
34
35CREATE TABLE `notification_method_type` (
36 `name` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
37 PRIMARY KEY (`name`)
38) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
39
40CREATE TABLE `alarm` (
41 `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
42 `alarm_definition_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
43 `state` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
44 `lifecycle_state` varchar(50) DEFAULT NULL,
45 `link` varchar(512) DEFAULT NULL,
46 `created_at` datetime NOT NULL,
47 `state_updated_at` datetime,
48 `updated_at` datetime NOT NULL,
49 PRIMARY KEY (`id`),
50 KEY `alarm_definition_id` (`alarm_definition_id`),
51 CONSTRAINT `fk_alarm_definition_id` FOREIGN KEY (`alarm_definition_id`) REFERENCES `alarm_definition` (`id`) ON DELETE CASCADE,
52 CONSTRAINT `fk_alarm_alarm_state` FOREIGN KEY (`state`) REFERENCES `alarm_state` (`name`)
53) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
54
55CREATE TABLE `alarm_action` (
56 `alarm_definition_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
57 `alarm_state` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
58 `action_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
59 PRIMARY KEY (`alarm_definition_id`,`alarm_state`,`action_id`),
60 CONSTRAINT `fk_alarm_action_alarm_definition_id` FOREIGN KEY (`alarm_definition_id`) REFERENCES `alarm_definition` (`id`) ON DELETE CASCADE,
61 CONSTRAINT `fk_alarm_action_notification_method_id` FOREIGN KEY (`action_id`) REFERENCES `notification_method` (`id`) ON DELETE CASCADE,
62 CONSTRAINT `fk_alarm_action_alarm_state` FOREIGN KEY (`alarm_state`) REFERENCES `alarm_state` (`name`)
63) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
64
65CREATE TABLE `alarm_definition` (
66 `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
67 `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
68 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
69 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
70 `expression` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
71 `severity` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
72 `match_by` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '',
73 `actions_enabled` tinyint(1) NOT NULL DEFAULT '1',
74 `created_at` datetime NOT NULL,
75 `updated_at` datetime NOT NULL,
76 `deleted_at` datetime DEFAULT NULL,
77 PRIMARY KEY (`id`),
78 KEY `tenant_id` (`tenant_id`),
79 KEY `deleted_at` (`deleted_at`),
80 CONSTRAINT `fk_alarm_definition_severity` FOREIGN KEY (`severity`) REFERENCES `alarm_definition_severity` (`name`)
81) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
82
83CREATE TABLE `alarm_metric` (
84 `alarm_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
85 `metric_definition_dimensions_id` binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
86 PRIMARY KEY (`alarm_id`,`metric_definition_dimensions_id`),
87 KEY `alarm_id` (`alarm_id`),
88 KEY `metric_definition_dimensions_id` (`metric_definition_dimensions_id`),
89 CONSTRAINT `fk_alarm_id` FOREIGN KEY (`alarm_id`) REFERENCES `alarm` (`id`) ON DELETE CASCADE
90) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
91
92CREATE TABLE `metric_definition` (
93 `id` binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
94 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
95 `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
96 `region` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
97 PRIMARY KEY (`id`)
98) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
99
100CREATE TABLE `metric_definition_dimensions` (
101 `id` binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
102 `metric_definition_id` binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
103 `metric_dimension_set_id` binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
104 KEY `metric_definition_id` (`metric_definition_id`),
105 KEY `metric_dimension_set_id` (`metric_dimension_set_id`),
106 PRIMARY KEY (`id`)
107) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
108
109/*
110 * mysql limits the size of a unique key to 767 bytes. The utf8mb4 charset requires
111 * 4 bytes to be allocated for each character while the utf8 charset requires 3 bytes.
112 * The utf8 charset should be sufficient for any reasonable characters, see the definition
113 * of supplementary characters for what it doesn't support.
114 * Even with utf8, the unique key length would be 785 bytes so only a subset of the
115 * name is used. Potentially the size of the name should be limited to 250 characters
116 * which would resolve this issue.
117 *
118 * The unique key is required to allow high performance inserts without doing a select by using
119 * the "insert into metric_dimension ... on duplicate key update dimension_set_id=dimension_set_id
120 * syntax
121 */
122CREATE TABLE `metric_dimension` (
123 `dimension_set_id` binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
124 `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
125 `value` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
126 UNIQUE KEY `metric_dimension_key` (`dimension_set_id`,`name`(252)),
127 KEY `dimension_set_id` (`dimension_set_id`)
128) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='PRIMARY KEY (`id`)';
129
130CREATE TABLE `notification_method` (
131 `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
132 `tenant_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
133 `name` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
134 `type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
135 `address` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
136 `period` int NOT NULL DEFAULT 0,
137 `created_at` datetime NOT NULL,
138 `updated_at` datetime NOT NULL,
139 PRIMARY KEY (`id`),
140 CONSTRAINT `fk_alarm_noticication_method_type` FOREIGN KEY (`type`) REFERENCES `notification_method_type` (`name`)
141) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
142
143CREATE TABLE `sub_alarm_definition` (
144 `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
145 `alarm_definition_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
146 `function` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
147 `metric_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
148 `operator` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL,
149 `threshold` double NOT NULL,
150 `period` int(11) NOT NULL,
151 `periods` int(11) NOT NULL,
152 `is_deterministic` tinyint(1) NOT NULL DEFAULT '0',
153 `created_at` datetime NOT NULL,
154 `updated_at` datetime NOT NULL,
155 PRIMARY KEY (`id`),
156 KEY `fk_sub_alarm_definition` (`alarm_definition_id`),
157 CONSTRAINT `fk_sub_alarm_definition` FOREIGN KEY (`alarm_definition_id`) REFERENCES `alarm_definition` (`id`) ON DELETE CASCADE
158) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
159
160CREATE TABLE `sub_alarm_definition_dimension` (
161 `sub_alarm_definition_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
162 `dimension_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
163 `value` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
164 CONSTRAINT `fk_sub_alarm_definition_dimension` FOREIGN KEY (`sub_alarm_definition_id`) REFERENCES `sub_alarm_definition` (`id`) ON DELETE CASCADE
165) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
166
167CREATE TABLE `sub_alarm` (
168 `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
169 `alarm_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
170 `sub_expression_id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
171 `expression` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
172 `created_at` datetime NOT NULL,
173 `updated_at` datetime NOT NULL,
174 `state` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'OK',
175 PRIMARY KEY (`id`),
176 KEY `fk_sub_alarm` (`alarm_id`),
177 KEY `fk_sub_alarm_expr` (`sub_expression_id`),
178 CONSTRAINT `fk_sub_alarm` FOREIGN KEY (`alarm_id`) REFERENCES `alarm` (`id`) ON DELETE CASCADE,
179 CONSTRAINT `fk_sub_alarm_state` FOREIGN KEY (`state`) REFERENCES `alarm_state` (`name`),
180 CONSTRAINT `fk_sub_alarm_expr` FOREIGN KEY (`sub_expression_id`) REFERENCES `sub_alarm_definition` (`id`)
181);
182
183SET foreign_key_checks = 1;
184
185/* provide data for enum tables */
186insert into `alarm_state` values ('UNDETERMINED');
187insert into `alarm_state` values ('OK');
188insert into `alarm_state` values ('ALARM');
189
190insert into `alarm_definition_severity` values ('LOW');
191insert into `alarm_definition_severity` values ('MEDIUM');
192insert into `alarm_definition_severity` values ('HIGH');
193insert into `alarm_definition_severity` values ('CRITICAL');
194
195insert into `notification_method_type` values ('EMAIL');
196insert into `notification_method_type` values ('WEBHOOK');
197insert into `notification_method_type` values ('PAGERDUTY');
198/* provide data for enum tables */
diff --git a/devstack/files/schema/mon_postgresql.sql b/devstack/files/schema/mon_postgresql.sql
deleted file mode 100644
index 000113a..0000000
--- a/devstack/files/schema/mon_postgresql.sql
+++ /dev/null
@@ -1,227 +0,0 @@
1---
2-- # Copyright 2017 FUJITSU LIMITED
3---
4
5SET statement_timeout = 0;
6SET lock_timeout = 0;
7SET client_encoding = 'UTF8';
8SET standard_conforming_strings = on;
9SET check_function_bodies = false;
10SET client_min_messages = warning;
11
12---
13-- enum tables
14---
15
16CREATE TABLE alarm_state (
17 name character varying(20) NOT NULL,
18 CONSTRAINT alarm_state_pkey PRIMARY KEY (name)
19);
20
21CREATE TABLE alarm_definition_severity (
22 name character varying(20) NOT NULL,
23 CONSTRAINT alarm_definition_severity_pkey PRIMARY KEY (name)
24);
25
26CREATE TABLE notification_method_type (
27 name character varying(20) NOT NULL,
28 CONSTRAINT notification_method_type_pkey PRIMARY KEY (name)
29);
30
31---
32-- tables
33---
34
35CREATE TABLE alarm (
36 id character varying(36) NOT NULL,
37 created_at timestamp without time zone NOT NULL,
38 updated_at timestamp without time zone NOT NULL,
39 lifecycle_state character varying(50),
40 link character varying(512),
41 state character varying(20) NOT NULL,
42 state_updated_at timestamp without time zone,
43 alarm_definition_id character varying(36) NOT NULL
44);
45
46CREATE TABLE alarm_action (
47 action_id character varying(36) NOT NULL,
48 alarm_state character varying(20) NOT NULL,
49 alarm_definition_id character varying(36) NOT NULL
50);
51
52CREATE TABLE alarm_definition (
53 id character varying(36) NOT NULL,
54 created_at timestamp without time zone NOT NULL,
55 updated_at timestamp without time zone NOT NULL,
56 actions_enabled boolean NOT NULL,
57 deleted_at timestamp without time zone,
58 description character varying(255),
59 expression text NOT NULL,
60 match_by character varying(255),
61 name character varying(255) NOT NULL,
62 severity character varying(20) NOT NULL,
63 tenant_id character varying(36) NOT NULL
64);
65
66CREATE TABLE alarm_metric (
67 metric_definition_dimensions_id bytea NOT NULL,
68 alarm_id character varying(36) NOT NULL
69);
70
71CREATE TABLE metric_definition (
72 id bytea NOT NULL,
73 name character varying(255) NOT NULL,
74 region character varying(255) NOT NULL,
75 tenant_id character varying(36) NOT NULL
76);
77
78CREATE TABLE metric_definition_dimensions (
79 id bytea NOT NULL,
80 metric_definition_id bytea NOT NULL,
81 metric_dimension_set_id bytea NOT NULL
82);
83
84CREATE TABLE metric_dimension (
85 dimension_set_id bytea NOT NULL,
86 name character varying(255) NOT NULL,
87 value character varying(255) NOT NULL
88);
89
90CREATE TABLE notification_method (
91 id character varying(36) NOT NULL,
92 created_at timestamp without time zone NOT NULL,
93 updated_at timestamp without time zone NOT NULL,
94 address character varying(512) NOT NULL,
95 name character varying(250),
96 tenant_id character varying(36) NOT NULL,
97 type character varying(20) NOT NULL,
98 period integer NOT NULL
99);
100
101CREATE TABLE sub_alarm (
102 id character varying(36) NOT NULL,
103 created_at timestamp without time zone NOT NULL,
104 updated_at timestamp without time zone NOT NULL,
105 expression text NOT NULL,
106 alarm_id character varying(36) NOT NULL,
107 sub_expression_id character varying(36),
108 state character varying(20) NOT NULL DEFAULT 'OK'
109);
110
111CREATE TABLE sub_alarm_definition (
112 id character varying(36) NOT NULL,
113 created_at timestamp without time zone NOT NULL,
114 updated_at timestamp without time zone NOT NULL,
115 function character varying(10) NOT NULL,
116 metric_name character varying(100),
117 operator character varying(5) NOT NULL,
118 period integer NOT NULL,
119 periods integer NOT NULL,
120 threshold double precision NOT NULL,
121 is_deterministic boolean NOT NULL,
122 alarm_definition_id character varying(36) NOT NULL
123);
124
125CREATE TABLE sub_alarm_definition_dimension (
126 dimension_name character varying(255) NOT NULL,
127 value character varying(255),
128 sub_alarm_definition_id character varying(36) NOT NULL
129);
130
131---
132-- primary keys
133---
134ALTER TABLE ONLY alarm_action
135 ADD CONSTRAINT alarm_action_pkey PRIMARY KEY (action_id, alarm_definition_id, alarm_state);
136
137ALTER TABLE ONLY alarm_definition
138 ADD CONSTRAINT alarm_definition_pkey PRIMARY KEY (id);
139
140ALTER TABLE ONLY alarm_metric
141 ADD CONSTRAINT alarm_metric_pkey PRIMARY KEY (alarm_id, metric_definition_dimensions_id);
142
143ALTER TABLE ONLY alarm
144 ADD CONSTRAINT alarm_pkey PRIMARY KEY (id);
145
146ALTER TABLE ONLY metric_definition_dimensions
147 ADD CONSTRAINT metric_definition_dimensions_pkey PRIMARY KEY (id);
148
149ALTER TABLE ONLY metric_definition
150 ADD CONSTRAINT metric_definition_pkey PRIMARY KEY (id);
151
152ALTER TABLE ONLY notification_method
153 ADD CONSTRAINT notification_method_pkey PRIMARY KEY (id);
154
155ALTER TABLE ONLY sub_alarm_definition_dimension
156 ADD CONSTRAINT sub_alarm_definition_dimension_pkey PRIMARY KEY (dimension_name, sub_alarm_definition_id);
157
158ALTER TABLE ONLY sub_alarm_definition
159 ADD CONSTRAINT sub_alarm_definition_pkey PRIMARY KEY (id);
160
161ALTER TABLE ONLY sub_alarm
162 ADD CONSTRAINT sub_alarm_pkey PRIMARY KEY (id);
163
164---
165-- indexes
166---
167
168CREATE INDEX alarm_id ON alarm_metric USING btree (alarm_id);
169CREATE INDEX deleted_at ON alarm_definition USING btree (deleted_at);
170CREATE INDEX dimension_set_id ON metric_dimension USING btree (dimension_set_id);
171CREATE INDEX metric_definition_dimensions_id ON alarm_metric USING btree (metric_definition_dimensions_id);
172CREATE INDEX metric_definition_id ON metric_definition_dimensions USING btree (metric_definition_id);
173CREATE UNIQUE INDEX metric_dimension_key ON metric_dimension USING btree (dimension_set_id, name);
174CREATE INDEX metric_dimension_set_id ON metric_definition_dimensions USING btree (metric_dimension_set_id);
175CREATE INDEX tenant_id ON alarm_definition USING btree (tenant_id);
176
177---
178-- foreign key constraints
179---
180ALTER TABLE ONLY alarm_action
181 ADD CONSTRAINT fk_alarm_action_alarm_definition FOREIGN KEY (alarm_definition_id) REFERENCES alarm_definition(id);
182
183ALTER TABLE ONLY sub_alarm
184 ADD CONSTRAINT fk_sub_alarm_sub_alarm_definition FOREIGN KEY (sub_expression_id) REFERENCES sub_alarm_definition(id);
185
186ALTER TABLE ONLY alarm
187 ADD CONSTRAINT fk_alarm_alarm_definition FOREIGN KEY (alarm_definition_id) REFERENCES alarm_definition(id);
188
189ALTER TABLE ONLY sub_alarm_definition_dimension
190 ADD CONSTRAINT fk_sub_alarm_def_dim_sub_alarm_def FOREIGN KEY (sub_alarm_definition_id) REFERENCES sub_alarm_definition(id) ON DELETE CASCADE;
191
192ALTER TABLE ONLY alarm_metric
193 ADD CONSTRAINT fk_alarm_metric_alamr FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE;
194
195ALTER TABLE ONLY sub_alarm_definition
196 ADD CONSTRAINT fk_sub_alarm_def_alarm_def FOREIGN KEY (alarm_definition_id) REFERENCES alarm_definition(id) ON DELETE CASCADE;
197
198ALTER TABLE ONLY sub_alarm
199 ADD CONSTRAINT fk_sub_alarm_alarm FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE;
200
201ALTER TABLE ONLY alarm
202 ADD CONSTRAINT fk_alarm_state FOREIGN KEY (state) REFERENCES alarm_state (name);
203
204ALTER TABLE ONLY alarm_action
205 ADD CONSTRAINT fk_alarm_action_state FOREIGN KEY (alarm_state) REFERENCES alarm_state (name);
206
207ALTER TABLE ONLY alarm_definition
208 ADD CONSTRAINT fk_alarm_definition_severity FOREIGN KEY (severity) REFERENCES alarm_definition_severity (name);
209
210ALTER TABLE ONLY notification_method
211 ADD CONSTRAINT fk_alarm_noticication_method_type FOREIGN KEY (type) REFERENCES notification_method_type (name);
212
213---
214-- data for enum tables
215---
216insert into alarm_state values ('UNDETERMINED');
217insert into alarm_state values ('OK');
218insert into alarm_state values ('ALARM');
219
220insert into alarm_definition_severity values ('LOW');
221insert into alarm_definition_severity values ('MEDIUM');
222insert into alarm_definition_severity values ('HIGH');
223insert into alarm_definition_severity values ('CRITICAL');
224
225insert into notification_method_type values ('EMAIL');
226insert into notification_method_type values ('WEBHOOK');
227insert into notification_method_type values ('PAGERDUTY');
diff --git a/devstack/lib/notification.sh b/devstack/lib/notification.sh
index c060ca2..accf46d 100644
--- a/devstack/lib/notification.sh
+++ b/devstack/lib/notification.sh
@@ -46,7 +46,7 @@ install_monasca-notification() {
46 if python3_enabled; then 46 if python3_enabled; then
47 enable_python3_package monasca-notification 47 enable_python3_package monasca-notification
48 fi 48 fi
49 setup_develop ${MONASCA_NOTIFICATION_DIR} 49 setup_develop ${MONASCA_NOTIFICATION_DIR} jira_plugin
50 # see devstack/plugin.sh 50 # see devstack/plugin.sh
51 install_monasca_common 51 install_monasca_common
52 install_monasca_statsd 52 install_monasca_statsd
diff --git a/devstack/plugin.sh b/devstack/plugin.sh
index 8d37e5d..06b1f3b 100755
--- a/devstack/plugin.sh
+++ b/devstack/plugin.sh
@@ -148,14 +148,13 @@ function install_monasca {
148 148
149function configure_monasca { 149function configure_monasca {
150 echo_summary "Configuring Monasca" 150 echo_summary "Configuring Monasca"
151 #(trebskit) Installing should happen in post-config phase 151
152 # at this point databases is already configured
153 install_schema
154 configure_storm 152 configure_storm
155 configure_ui 153 configure_ui
156 configure_monasca_api 154 configure_monasca_api
157 configure_monasca-notification 155 configure_monasca-notification
158 configure_monasca-persister 156 configure_monasca-persister
157 install_schema
159} 158}
160 159
161function configure_system_encoding_format { 160function configure_system_encoding_format {
@@ -653,17 +652,9 @@ function install_schema_kafka_topics {
653function install_schema_alarm_database { 652function install_schema_alarm_database {
654 local databaseName="mon" 653 local databaseName="mon"
655 654
656 # copy the file with the $DATABASE_TYPE to just know what DB is used 655 if is_service_enabled mysql postgresql; then
657 sudo cp -f "${MONASCA_API_DIR}"/devstack/files/schema/mon_$DATABASE_TYPE.sql $MONASCA_SCHEMA_DIR/mon_$DATABASE_TYPE.sql 656 recreate_database $databaseName
658 sudo ln -sf $MONASCA_SCHEMA_DIR/mon_$DATABASE_TYPE.sql $MONASCA_SCHEMA_DIR/mon.sql 657 $MONASCA_API_BIN_DIR/monasca_db upgrade
659 sudo chmod 0644 $MONASCA_SCHEMA_DIR/mon.sql
660 sudo chown root:root $MONASCA_SCHEMA_DIR/mon.sql
661
662 recreate_database $databaseName
663 if is_service_enabled mysql; then
664 sudo mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST < $MONASCA_SCHEMA_DIR/mon.sql
665 elif is_service_enabled postgresql; then
666 sudo -u root sudo -u postgres -i psql -d $databaseName -f $MONASCA_SCHEMA_DIR/mon.sql
667 fi 658 fi
668} 659}
669 660
diff --git a/monasca_api/db/alembic/versions/00597b5c8325_initial.py b/monasca_api/db/alembic/versions/00597b5c8325_initial.py
index fb5ac17..b044863 100644
--- a/monasca_api/db/alembic/versions/00597b5c8325_initial.py
+++ b/monasca_api/db/alembic/versions/00597b5c8325_initial.py
@@ -401,25 +401,22 @@ def upgrade():
401 op.create_table( 401 op.create_table(
402 'sub_alarm', 402 'sub_alarm',
403 sa.Column('id', 403 sa.Column('id',
404 sa.dialects.mysql.VARCHAR(length=36, 404 sa.String(length=36),
405 collation='utf8mb4_unicode_ci'),
406 nullable=False), 405 nullable=False),
407 sa.Column('alarm_id', 406 sa.Column('alarm_id',
408 sa.dialects.mysql.VARCHAR(length=36, 407 sa.String(length=36),
409 collation='utf8mb4_unicode_ci'),
410 sa.ForeignKey('alarm.id', ondelete='CASCADE', 408 sa.ForeignKey('alarm.id', ondelete='CASCADE',
411 name='fk_sub_alarm'), 409 name='fk_sub_alarm'),
412 nullable=False, 410 nullable=False,
413 server_default=''), 411 server_default=''),
414 sa.Column('sub_expression_id', 412 sa.Column('sub_expression_id',
415 sa.dialects.mysql.VARCHAR(length=36, 413 sa.String(length=36),
416 collation='utf8mb4_unicode_ci'),
417 sa.ForeignKey('sub_alarm_definition.id', 414 sa.ForeignKey('sub_alarm_definition.id',
418 name='fk_sub_alarm_expr'), 415 name='fk_sub_alarm_expr'),
419 nullable=False, 416 nullable=False,
420 server_default=''), 417 server_default=''),
421 sa.Column('expression', 418 sa.Column('expression',
422 sa.dialects.mysql.LONGTEXT(collation='utf8mb4_unicode_ci'), 419 sa.dialects.mysql.LONGTEXT(),
423 nullable=False), 420 nullable=False),
424 sa.Column('created_at', 421 sa.Column('created_at',
425 sa.DateTime(), 422 sa.DateTime(),
@@ -427,7 +424,9 @@ def upgrade():
427 sa.Column('updated_at', 424 sa.Column('updated_at',
428 sa.DateTime(), 425 sa.DateTime(),
429 nullable=False), 426 nullable=False),
430 sa.PrimaryKeyConstraint('id')) 427 sa.PrimaryKeyConstraint('id'),
428 mysql_charset='utf8mb4',
429 mysql_collate='utf8mb4_unicode_ci')
431 430
432 op.create_table( 431 op.create_table(
433 'schema_migrations', 432 'schema_migrations',
diff --git a/monasca_api/db/alembic/versions/6b2b88f3cab4_add_sub_alarm_state.py b/monasca_api/db/alembic/versions/6b2b88f3cab4_add_sub_alarm_state.py
index 73f55cd..75c2909 100644
--- a/monasca_api/db/alembic/versions/6b2b88f3cab4_add_sub_alarm_state.py
+++ b/monasca_api/db/alembic/versions/6b2b88f3cab4_add_sub_alarm_state.py
@@ -34,8 +34,7 @@ def upgrade():
34 op.add_column( 34 op.add_column(
35 'sub_alarm', 35 'sub_alarm',
36 sa.Column('state', 36 sa.Column('state',
37 sa.dialects.mysql.VARCHAR(length=20, 37 sa.String(length=20),
38 collate='utf8mb4_unicode_ci'),
39 sa.ForeignKey('alarm_state.name'), 38 sa.ForeignKey('alarm_state.name'),
40 nullable=False, 39 nullable=False,
41 server_default='OK')) 40 server_default='OK'))