DeployHubProject / DeployHub-Pro

DeployHub Pro Pipeline Status Project
https://www.openmakesoftware.com/application-release-automation-for-continuous-delivery/
Other
11 stars 4 forks source link

Domains can't be deleted #367

Closed hatati closed 2 years ago

hatati commented 2 years ago

When I try to delete a domain nothing happens. Watch the below gif for example: delete domain bug

The UI is successfully sending a request: image

The container logs shows that it's trying to delete the domain, but nothing happens:

Wed Apr 13 11:18:19 2022: connectToDatabase()
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: DMHOME=/opt/deployhub/engine
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: DRIVERNAME=org.postgresql.Driver
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: CONNECTIONSTRING=jdbc:postgresql://Obexdb2.schantz.com:5432/ortelius?api.trace=true&api.trace.file=/tmp/pg.log
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: USERNAME=orteliusAdmin
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: PASSWORDNAME=********
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: CLOSED=false
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: GetDomains (1) - grabbing lock
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: user domain = 1
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: Before GetParentDomains, m_domains.size()=0
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: CLOSED2=false
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: parentid=1
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: After GetParentDomains, m_domains.size()=1
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: m_parentdomains=1
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: domainlist=128,1,129,2,130,131,4,132,5,133,6,134,7,135,8,138,139,140,141,142,143,144,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: ut (from cookie)=null
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: url=RemoveNode?rel=Domain&id=127
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: RemoveObject Type=Domain id=127
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: in domainHasObjects(127)
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: SELECT count(*) FROM dm.dm_environment WHERE domainid=? and status <> 'D' = 0
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: SELECT count(*) FROM dm.dm_domain WHERE domainid=? and status <> 'D' = 0
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: SELECT count(*) FROM dm.dm_user WHERE domainid=? and status <> 'D' = 0
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: SELECT count(*) FROM dm.dm_credentials WHERE domainid=? and status <> 'D' = 0
Wed, Apr 13 2022 1:18:19 pm | Wed Apr 13 11:18:19 2022: SELECT count(*) FROM dm.dm_application WHERE domainid=? and status <> 'D' = 0

Deployhub image tag: ui-skin-v9.0.0.3271-g1077e12

hatati commented 2 years ago

If I create a new domain then I am able to delete it: delete domain deletable domain

sbtaylor15 commented 2 years ago

@hatati - a domain can't be deleted if there are objects associated to the domain. A message should be displayed listing the objects that need to be removed first. We will debug this to see what is happening. Another option is to change the code to delete the domain and the associated objects for you.

hatati commented 2 years ago

@sbtaylor15 - Initially a list of objects in the domain would be nice to have when trying to delete it so a user can manually delete them. An option to delete them automatically would also be nice, but a confirmation dialog should be added to this.

sbtaylor15 commented 2 years ago

@hatati - please make sure that you have this function defined. And then run the second query (updating the domain name you want to delete). Running this outside of the UI will expose where the delete is having issues.

CREATE OR REPLACE FUNCTION dm.fulldomain(
    val integer)
    RETURNS character varying
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE full_domain varchar;
BEGIN
WITH RECURSIVE pops (id, level, name, name_path) AS (
    SELECT  id, 0, name, ARRAY[name]
    FROM    dm.dm_domain a
    WHERE   a.domainid is null
UNION ALL
    SELECT  p.id, t0.level + 1, p.name, ARRAY_APPEND(t0.name_path, p.name)
    FROM    dm.dm_domain p
            INNER JOIN pops t0 ON t0.id = p.domainid
)

SELECT  ARRAY_TO_STRING(name_path, '.') into full_domain
FROM    pops where id = $1;

RETURN full_domain;
END; 
$BODY$;

ALTER FUNCTION dm.fulldomain(integer)
    OWNER TO postgres;
begin;
delete from dm.dm_componentitem where id in (select b.id from dm.dm_component a, dm.dm_componentitem b where a.id = b.compid and fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%');
delete from dm.dm_componentvars where compid in (select b.compid from dm.dm_component a, dm.dm_componentvars b where a.id = b.compid and fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%');
delete from dm.dm_applicationcomponent where compid in (select b.compid from dm.dm_component a, dm.dm_applicationcomponent b where a.id = b.compid and fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%');
delete from dm.dm_component a where fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%';
delete from dm.dm_appsallowedinenv where appid in (select b.appid from dm.dm_application a, dm.dm_appsallowedinenv b where a.id = b.appid and fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%');
delete from dm.dm_applicationvars where appid in (select b.appid from dm.dm_application a, dm.dm_applicationvars b where a.id = b.appid and fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%');
delete from dm.dm_application a where fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%';
delete from dm.dm_environmentvars where envid in (select b.envid from dm.dm_environment a, dm.dm_environmentvars b where a.id = b.envid and fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%');
delete from dm.dm_serversinenv where envid in (select b.envid from dm.dm_environment a, dm.dm_serversinenv b where a.id = b.envid and fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%');
delete from dm.dm_environment a where fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%';
delete from dm.dm_usersingroup where userid in (select b.userid from dm.dm_user a, dm.dm_usersingroup b where a.id = b.userid and fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%');
delete from dm.dm_user a where fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%';
delete from dm.dm_domain where id in (select id from dm.dm_domain a where fulldomain(a.domainid) like 'GLOBAL.Src Consulting.%' order by fulldomain(a.domainid) || '.' || name desc);
delete from dm.dm_domain where id in (select id from dm.dm_domain a where fulldomain(a.domainid) || '.' || name = 'GLOBAL.Src Consulting' order by fulldomain(a.domainid) || '.' || name desc);
delete from dm.dm_task where domainid not in (select id from dm.dm_domain);
delete from dm.dm_engine where domainid not in (select id from dm.dm_domain);
commit;