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>
This commit is contained in:
Suresh Kumar Anaparti 2026-01-28 19:39:37 +05:30 committed by GitHub
parent 9fc93af85f
commit 059debf212
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 264 additions and 0 deletions

View File

@ -0,0 +1,27 @@
-- 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.
-- Add new OS categories if not present
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_CATEGORY_IF_NOT_EXIST`;
CREATE PROCEDURE `cloud`.`INSERT_CATEGORY_IF_NOT_EXIST`(IN os_name VARCHAR(255))
BEGIN
IF NOT EXISTS ((SELECT 1 FROM `cloud`.`guest_os_category` WHERE name = os_name))
THEN
INSERT INTO `cloud`.`guest_os_category` (name, uuid)
VALUES (os_name, UUID())
; END IF
; END;

View File

@ -0,0 +1,46 @@
-- 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.
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_EXTENSION_CUSTOM_ACTION_DETAILS_IF_NOT_EXISTS`;
CREATE PROCEDURE `cloud`.`INSERT_EXTENSION_CUSTOM_ACTION_DETAILS_IF_NOT_EXISTS` (
IN ext_name VARCHAR(255),
IN action_name VARCHAR(255),
IN param_json TEXT
)
BEGIN
DECLARE action_id BIGINT UNSIGNED
; SELECT `eca`.`id` INTO action_id FROM `cloud`.`extension_custom_action` `eca`
JOIN `cloud`.`extension` `e` ON `e`.`id` = `eca`.`extension_id`
WHERE `eca`.`name` = action_name AND `e`.`name` = ext_name LIMIT 1
; IF NOT EXISTS (
SELECT 1 FROM `cloud`.`extension_custom_action_details`
WHERE `extension_custom_action_id` = action_id
AND `name` = 'parameters'
) THEN
INSERT INTO `cloud`.`extension_custom_action_details` (
`extension_custom_action_id`,
`name`,
`value`,
`display`
) VALUES (
action_id,
'parameters',
param_json,
0
)
; END IF
;END;

View File

@ -0,0 +1,46 @@
-- 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.
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_EXTENSION_CUSTOM_ACTION_IF_NOT_EXISTS`;
CREATE PROCEDURE `cloud`.`INSERT_EXTENSION_CUSTOM_ACTION_IF_NOT_EXISTS`(
IN ext_name VARCHAR(255),
IN action_name VARCHAR(255),
IN action_desc VARCHAR(4096),
IN resource_type VARCHAR(255),
IN allowed_roles INT UNSIGNED,
IN success_msg VARCHAR(4096),
IN error_msg VARCHAR(4096),
IN timeout_seconds INT UNSIGNED
)
BEGIN
DECLARE ext_id BIGINT
; SELECT `id` INTO ext_id FROM `cloud`.`extension` WHERE `name` = ext_name LIMIT 1
; IF NOT EXISTS (
SELECT 1 FROM `cloud`.`extension_custom_action` WHERE `name` = action_name AND `extension_id` = ext_id
) THEN
INSERT INTO `cloud`.`extension_custom_action` (
`uuid`, `name`, `description`, `extension_id`, `resource_type`,
`allowed_role_types`, `success_message`, `error_message`,
`enabled`, `timeout`, `created`, `removed`
)
VALUES (
UUID(), action_name, action_desc, ext_id, resource_type,
allowed_roles, success_msg, error_msg,
1, timeout_seconds, NOW(), NULL
)
; END IF
;END;

View File

@ -0,0 +1,39 @@
-- 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.
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_EXTENSION_DETAIL_IF_NOT_EXISTS`;
CREATE PROCEDURE `cloud`.`INSERT_EXTENSION_DETAIL_IF_NOT_EXISTS`(
IN ext_name VARCHAR(255),
IN detail_key VARCHAR(255),
IN detail_value TEXT,
IN display TINYINT(1)
)
BEGIN
DECLARE ext_id BIGINT
; SELECT `id` INTO ext_id FROM `cloud`.`extension` WHERE `name` = ext_name LIMIT 1
; IF NOT EXISTS (
SELECT 1 FROM `cloud`.`extension_details`
WHERE `extension_id` = ext_id AND `name` = detail_key
) THEN
INSERT INTO `cloud`.`extension_details` (
`extension_id`, `name`, `value`, `display`
)
VALUES (
ext_id, detail_key, detail_value, display
)
; END IF
;END;

View File

@ -0,0 +1,38 @@
-- 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.
DROP PROCEDURE IF EXISTS `cloud`.`INSERT_EXTENSION_IF_NOT_EXISTS`;
CREATE PROCEDURE `cloud`.`INSERT_EXTENSION_IF_NOT_EXISTS`(
IN ext_name VARCHAR(255),
IN ext_desc VARCHAR(255),
IN ext_path VARCHAR(255)
)
BEGIN
IF NOT EXISTS (
SELECT 1 FROM `cloud`.`extension` WHERE `name` = ext_name
) THEN
INSERT INTO `cloud`.`extension` (
`uuid`, `name`, `description`, `type`,
`relative_path`, `path_ready`,
`is_user_defined`, `state`, `created`, `removed`
)
VALUES (
UUID(), ext_name, ext_desc, 'Orchestrator',
ext_path, 1, 0, 'Enabled', NOW(), NULL
)
; END IF
;END;

View File

@ -0,0 +1,33 @@
-- 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.
-- Move existing guest OS to new categories
DROP PROCEDURE IF EXISTS `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`;
CREATE PROCEDURE `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`(IN category_name VARCHAR(255), IN os_name VARCHAR(255))
BEGIN
DECLARE category_id BIGINT
; SELECT `id` INTO category_id
FROM `cloud`.`guest_os_category`
WHERE `name` = category_name
LIMIT 1
; IF category_id IS NULL THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Category not found'
; END IF
; UPDATE `cloud`.`guest_os`
SET `category_id` = category_id
WHERE `display_name` LIKE CONCAT('%', os_name, '%')
; END;

View File

@ -0,0 +1,35 @@
-- 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.
-- Move existing guest OS whose category will be deleted to Other category
DROP PROCEDURE IF EXISTS `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`;
CREATE PROCEDURE `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`(IN to_category_name VARCHAR(255), IN from_category_name VARCHAR(255))
BEGIN
DECLARE done INT DEFAULT 0
; DECLARE to_category_id BIGINT
; SELECT id INTO to_category_id
FROM `cloud`.`guest_os_category`
WHERE `name` = to_category_name
LIMIT 1
; IF to_category_id IS NULL THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'ToCategory not found'
; END IF
; UPDATE `cloud`.`guest_os`
SET `category_id` = to_category_id
WHERE `category_id` = (SELECT `id` FROM `cloud`.`guest_os_category` WHERE `name` = from_category_name)
; UPDATE `cloud`.`guest_os_category` SET `removed`=now() WHERE `name` = from_category_name
; END;