Skip to content

Commit 059debf

Browse files
Add the procedure files for insert extensions and update guest os category (#12482)
* Add the procedure files for insert extensions and update guestos category * fixed indentation * Apply suggestions from code review Co-authored-by: Vishesh <8760112+vishesh92@users.noreply.github.com> --------- Co-authored-by: Vishesh <8760112+vishesh92@users.noreply.github.com>
1 parent 9fc93af commit 059debf

7 files changed

Lines changed: 264 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- Add new OS categories if not present
19+
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_CATEGORY_IF_NOT_EXIST`;
20+
CREATE PROCEDURE `cloud`.`INSERT_CATEGORY_IF_NOT_EXIST`(IN os_name VARCHAR(255))
21+
BEGIN
22+
IF NOT EXISTS ((SELECT 1 FROM `cloud`.`guest_os_category` WHERE name = os_name))
23+
THEN
24+
INSERT INTO `cloud`.`guest_os_category` (name, uuid)
25+
VALUES (os_name, UUID())
26+
; END IF
27+
; END;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_EXTENSION_CUSTOM_ACTION_DETAILS_IF_NOT_EXISTS`;
19+
CREATE PROCEDURE `cloud`.`INSERT_EXTENSION_CUSTOM_ACTION_DETAILS_IF_NOT_EXISTS` (
20+
IN ext_name VARCHAR(255),
21+
IN action_name VARCHAR(255),
22+
IN param_json TEXT
23+
)
24+
BEGIN
25+
DECLARE action_id BIGINT UNSIGNED
26+
; SELECT `eca`.`id` INTO action_id FROM `cloud`.`extension_custom_action` `eca`
27+
JOIN `cloud`.`extension` `e` ON `e`.`id` = `eca`.`extension_id`
28+
WHERE `eca`.`name` = action_name AND `e`.`name` = ext_name LIMIT 1
29+
; IF NOT EXISTS (
30+
SELECT 1 FROM `cloud`.`extension_custom_action_details`
31+
WHERE `extension_custom_action_id` = action_id
32+
AND `name` = 'parameters'
33+
) THEN
34+
INSERT INTO `cloud`.`extension_custom_action_details` (
35+
`extension_custom_action_id`,
36+
`name`,
37+
`value`,
38+
`display`
39+
) VALUES (
40+
action_id,
41+
'parameters',
42+
param_json,
43+
0
44+
)
45+
; END IF
46+
;END;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_EXTENSION_CUSTOM_ACTION_IF_NOT_EXISTS`;
19+
CREATE PROCEDURE `cloud`.`INSERT_EXTENSION_CUSTOM_ACTION_IF_NOT_EXISTS`(
20+
IN ext_name VARCHAR(255),
21+
IN action_name VARCHAR(255),
22+
IN action_desc VARCHAR(4096),
23+
IN resource_type VARCHAR(255),
24+
IN allowed_roles INT UNSIGNED,
25+
IN success_msg VARCHAR(4096),
26+
IN error_msg VARCHAR(4096),
27+
IN timeout_seconds INT UNSIGNED
28+
)
29+
BEGIN
30+
DECLARE ext_id BIGINT
31+
; SELECT `id` INTO ext_id FROM `cloud`.`extension` WHERE `name` = ext_name LIMIT 1
32+
; IF NOT EXISTS (
33+
SELECT 1 FROM `cloud`.`extension_custom_action` WHERE `name` = action_name AND `extension_id` = ext_id
34+
) THEN
35+
INSERT INTO `cloud`.`extension_custom_action` (
36+
`uuid`, `name`, `description`, `extension_id`, `resource_type`,
37+
`allowed_role_types`, `success_message`, `error_message`,
38+
`enabled`, `timeout`, `created`, `removed`
39+
)
40+
VALUES (
41+
UUID(), action_name, action_desc, ext_id, resource_type,
42+
allowed_roles, success_msg, error_msg,
43+
1, timeout_seconds, NOW(), NULL
44+
)
45+
; END IF
46+
;END;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_EXTENSION_DETAIL_IF_NOT_EXISTS`;
19+
CREATE PROCEDURE `cloud`.`INSERT_EXTENSION_DETAIL_IF_NOT_EXISTS`(
20+
IN ext_name VARCHAR(255),
21+
IN detail_key VARCHAR(255),
22+
IN detail_value TEXT,
23+
IN display TINYINT(1)
24+
)
25+
BEGIN
26+
DECLARE ext_id BIGINT
27+
; SELECT `id` INTO ext_id FROM `cloud`.`extension` WHERE `name` = ext_name LIMIT 1
28+
; IF NOT EXISTS (
29+
SELECT 1 FROM `cloud`.`extension_details`
30+
WHERE `extension_id` = ext_id AND `name` = detail_key
31+
) THEN
32+
INSERT INTO `cloud`.`extension_details` (
33+
`extension_id`, `name`, `value`, `display`
34+
)
35+
VALUES (
36+
ext_id, detail_key, detail_value, display
37+
)
38+
; END IF
39+
;END;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_EXTENSION_IF_NOT_EXISTS`;
19+
CREATE PROCEDURE `cloud`.`INSERT_EXTENSION_IF_NOT_EXISTS`(
20+
IN ext_name VARCHAR(255),
21+
IN ext_desc VARCHAR(255),
22+
IN ext_path VARCHAR(255)
23+
)
24+
BEGIN
25+
IF NOT EXISTS (
26+
SELECT 1 FROM `cloud`.`extension` WHERE `name` = ext_name
27+
) THEN
28+
INSERT INTO `cloud`.`extension` (
29+
`uuid`, `name`, `description`, `type`,
30+
`relative_path`, `path_ready`,
31+
`is_user_defined`, `state`, `created`, `removed`
32+
)
33+
VALUES (
34+
UUID(), ext_name, ext_desc, 'Orchestrator',
35+
ext_path, 1, 0, 'Enabled', NOW(), NULL
36+
)
37+
; END IF
38+
;END;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- Move existing guest OS to new categories
19+
DROP PROCEDURE IF EXISTS `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`;
20+
CREATE PROCEDURE `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`(IN category_name VARCHAR(255), IN os_name VARCHAR(255))
21+
BEGIN
22+
DECLARE category_id BIGINT
23+
; SELECT `id` INTO category_id
24+
FROM `cloud`.`guest_os_category`
25+
WHERE `name` = category_name
26+
LIMIT 1
27+
; IF category_id IS NULL THEN
28+
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Category not found'
29+
; END IF
30+
; UPDATE `cloud`.`guest_os`
31+
SET `category_id` = category_id
32+
WHERE `display_name` LIKE CONCAT('%', os_name, '%')
33+
; END;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. 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,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- Move existing guest OS whose category will be deleted to Other category
19+
DROP PROCEDURE IF EXISTS `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`;
20+
CREATE PROCEDURE `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`(IN to_category_name VARCHAR(255), IN from_category_name VARCHAR(255))
21+
BEGIN
22+
DECLARE done INT DEFAULT 0
23+
; DECLARE to_category_id BIGINT
24+
; SELECT id INTO to_category_id
25+
FROM `cloud`.`guest_os_category`
26+
WHERE `name` = to_category_name
27+
LIMIT 1
28+
; IF to_category_id IS NULL THEN
29+
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'ToCategory not found'
30+
; END IF
31+
; UPDATE `cloud`.`guest_os`
32+
SET `category_id` = to_category_id
33+
WHERE `category_id` = (SELECT `id` FROM `cloud`.`guest_os_category` WHERE `name` = from_category_name)
34+
; UPDATE `cloud`.`guest_os_category` SET `removed`=now() WHERE `name` = from_category_name
35+
; END;

0 commit comments

Comments
 (0)