|
|
|
@@ -120,24 +120,10 @@
|
|
|
|
|
<cfcatch type="invalidParamValue">
|
|
|
|
|
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
|
|
|
|
</cfcatch>
|
|
|
|
|
</cftry>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--- *********** 2DO ShortList --->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!---
|
|
|
|
|
<cfdump var=#order#/>
|
|
|
|
|
<cfdump var=#local.fieldsToQueryFor#/>
|
|
|
|
|
<cfdump var=#local.fieldsToOutput#/>
|
|
|
|
|
<cfabort/>--->
|
|
|
|
|
|
|
|
|
|
</cftry>
|
|
|
|
|
|
|
|
|
|
<cftry><!--- *** времянка, пока глотается ошибка 500 --->
|
|
|
|
|
<!--- <cfset var maxrows=arguments.pageSize*arguments.page/> --->
|
|
|
|
|
<!--- <cfset var startrow=arguments.pageSize*(arguments.page-1)+1/> --->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--- Такая бодяга. Кастомные сериализаторы не умеют вложенных структур (поразительно, или я не нашел как). Стандартный сериализатор не умеет выводить дату в ISO 8601. Приходится колхозить и форматировать на стороне БД (насилу подобрал формат). Также на стороне БД приходится конвертировать GUID, потому что драйвер pg jdbc его представляет как структуру из 2 чисел.
|
|
|
|
|
И то сказать, jsonb как-то странно сериализуется, в 3 поля, вместо одного Value
|
|
|
|
|
--->
|
|
|
|
@@ -151,8 +137,6 @@
|
|
|
|
|
<m:field>e.instance_uid::text as instance_uid</m:field>
|
|
|
|
|
<m:field>e.display_name</m:field>
|
|
|
|
|
<m:field>e.service_id</m:field>
|
|
|
|
|
<!--- <m:field>e.resource_realm_id</m:field> --->
|
|
|
|
|
<!--- <m:field>r.resource_realm</m:field> --->
|
|
|
|
|
<m:field>e.specification_item_id</m:field>
|
|
|
|
|
<m:field formatter=#request.castToBool#>e.is_auxiliary</m:field>
|
|
|
|
|
<m:field>d.contract_id</m:field>
|
|
|
|
@@ -176,14 +160,22 @@
|
|
|
|
|
<m:field>(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as operation_dt_finish</m:field>
|
|
|
|
|
<m:field>(select round(extract('epoch' from coalesce(io.dt_finish,CURRENT_TIMESTAMP)- io.dt_start),1) from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as duration</m:field>
|
|
|
|
|
|
|
|
|
|
<m:field>(select case when io.operation IN ('delete', 'suspend') AND io.is_successful then 0 /*null*/ when io.is_successful then extract('epoch' from CURRENT_TIMESTAMP - coalesce(io.dt_finish,CURRENT_TIMESTAMP)) else 0 end from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as uptime</m:field>/* *** это вообще неправильно, некоторые операции заканчиваются состоянием running, а некоторые нет, переделать */
|
|
|
|
|
<m:field>(select case
|
|
|
|
|
when io.operation IN ('delete', 'suspend') AND io.is_successful then 0 /*null*/
|
|
|
|
|
when io.is_successful then extract('epoch' from CURRENT_TIMESTAMP - coalesce(io.dt_finish,CURRENT_TIMESTAMP))
|
|
|
|
|
else 0 end
|
|
|
|
|
from instance_operation io
|
|
|
|
|
where io.instance_uid=e.instance_uid
|
|
|
|
|
order by dt_submit desc
|
|
|
|
|
limit 1)
|
|
|
|
|
as uptime</m:field>
|
|
|
|
|
|
|
|
|
|
<m:field>(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid AND io.is_successful AND io.operation='create' order by dt_submit desc limit 1) as dt_deploy</m:field>
|
|
|
|
|
<m:field formatter=#function(x){return (deserializeJson(x))}#>(select instance_data::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_data</m:field><!--- *** операция выглядит очень накладно, но можно это поле в дельнейшем не выводить --->
|
|
|
|
|
<m:field>(select st.instance_state_uid::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_state_uid</m:field>
|
|
|
|
|
<m:field formatter=#request.castToBool#>(select st.is_test from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as is_test</m:field>
|
|
|
|
|
<m:field formatter=#request.castToBool#>coalesce((select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1),'false') as is_deleted</m:field><!--- attention it is not bool in state --->
|
|
|
|
|
<m:field formatter=#request.castToBool#>(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as suspended</m:field>
|
|
|
|
|
<m:field formatter=#request.castToBool#>(select st.instance_data->>'isSuspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as suspended</m:field>
|
|
|
|
|
<m:field>(select cast(st.instance_data->>'params' as json)->>'resourceRealm' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as resource_realm</m:field>
|
|
|
|
|
<m:field>(select to_char(st.dt_state, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as dt_state</m:field>
|
|
|
|
|
<m:field>
|
|
|
|
@@ -191,9 +183,12 @@
|
|
|
|
|
when
|
|
|
|
|
(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'deleted'
|
|
|
|
|
when
|
|
|
|
|
(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
|
|
|
|
|
(select st.instance_data->>'isSuspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
|
|
|
|
|
when
|
|
|
|
|
(select coalesce(st.instance_data->>'isDeleted','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' AND (select coalesce(st.instance_data->>'suspended','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' then 'running'
|
|
|
|
|
(select coalesce(st.instance_data->>'isDeleted','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false'
|
|
|
|
|
AND
|
|
|
|
|
(select coalesce(st.instance_data->>'isSuspended','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false'
|
|
|
|
|
then 'running'
|
|
|
|
|
when
|
|
|
|
|
not exists (select * from instance_operation o where o.instance_uid=e.instance_uid) then 'not configured'
|
|
|
|
|
when
|
|
|
|
@@ -204,7 +199,7 @@
|
|
|
|
|
<m:field>(select max(version) from instance_state st where st.instance_uid=e.instance_uid) as version</m:field>
|
|
|
|
|
</m:field_set>
|
|
|
|
|
|
|
|
|
|
<!--- <cfdump var=#definedInstanceFields#/><cfabort/> --->
|
|
|
|
|
<!--- <cfdump var=#definedInstanceFields#/><cfabort/> --->
|
|
|
|
|
|
|
|
|
|
<cfquery name="local.qCnt" result="local.result">
|
|
|
|
|
select count(*) as cnt
|
|
|
|
@@ -233,8 +228,6 @@
|
|
|
|
|
) inr
|
|
|
|
|
where 1=1 <m:filter_build filter=#filter#/>
|
|
|
|
|
</cfquery>
|
|
|
|
|
<!--- <cfdump var=#url#/>
|
|
|
|
|
<cfdump var=#local.qCnt#/><cfabort/> --->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<cfquery name="local.qRead" result="local.result">
|
|
|
|
@@ -266,8 +259,6 @@
|
|
|
|
|
limit #arguments.pageSize#
|
|
|
|
|
offset #arguments.pageSize*(arguments.page-1)#
|
|
|
|
|
</cfquery>
|
|
|
|
|
<!--- <cfdump var=#local.qRead#/><cfabort/> --->
|
|
|
|
|
<!--- formatter=#function(x){if (isNull(x)) {return x} else {return (x NEQ 0)}}# --->
|
|
|
|
|
|
|
|
|
|
<cfquery name="local.qTotal">
|
|
|
|
|
select count(*) as cnt
|
|
|
|
@@ -308,7 +299,7 @@
|
|
|
|
|
<cfreturn representationOf(cfcatch).withStatus(500)/>
|
|
|
|
|
</cfcatch>
|
|
|
|
|
</cftry>
|
|
|
|
|
</cffunction>
|
|
|
|
|
</cffunction><!--- get --->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<cffunction name="post" hint="(ТЕСТИРОВАНИЕ) ВНИМАНИЕ! У текущего контрагента должна быть спецификация, в которую будет вписан создаваемый экземпляр. Новая пустая запись экземпляра. Фактическое развертывание выполняется отдельно,асинхронной операцией create сконфигурированного экземпляра. Одновременно мы создаем строку в спецификации по умолчанию и связываем экземпляр с этой строкой. Первичный ключ генерируется. Текущий пользователь, контракт, спецификация получаются из контекста.">
|
|
|
|
@@ -316,19 +307,14 @@
|
|
|
|
|
<cfargument name="serviceId" type="string" required=true hint="type:integer"/>
|
|
|
|
|
<cfargument name="descr" type="string" required=false default="" hint="type:varchar (no cleanup here!)"/>
|
|
|
|
|
<cfargument name="resourceRealmId" type="string" required=false default="-1" hint="type:integer"/>
|
|
|
|
|
<!--- <cfargument name="instanceUid" type="string" required=false default="" hint="type:guid)"/> --->
|
|
|
|
|
|
|
|
|
|
<!--- <cfargument name="usrUid" type="string" required=true hint="type:guid"/>
|
|
|
|
|
<!--- <cfargument name="instanceUid" type="string" required=false default="" hint="type:guid)"/>
|
|
|
|
|
<cfargument name="usrUid" type="string" required=true hint="type:guid"/>
|
|
|
|
|
<cfargument name="companyUid" type="string" required=true hint="type:guid"/> --->
|
|
|
|
|
<!--- оказывается, их можно и не декларировать --->
|
|
|
|
|
|
|
|
|
|
<cfset local={}/>
|
|
|
|
|
<!--- <cfif structKeyExists(arguments,"instanceUid")>
|
|
|
|
|
<cfset local.instanceUid=arguments.instanceUid/>
|
|
|
|
|
<cfelse> --->
|
|
|
|
|
<cfset local.instanceUid=#createGUID()#/>
|
|
|
|
|
<!--- </cfif> --->
|
|
|
|
|
|
|
|
|
|
<cfset var local={}/>
|
|
|
|
|
|
|
|
|
|
<cfset local.instanceUid=#createGUID()#/>
|
|
|
|
|
|
|
|
|
|
<cftry>
|
|
|
|
|
<cfset this.helper.keyExistsAndValid(arguments, "serviceId", "integer")/>
|
|
|
|
@@ -377,11 +363,8 @@
|
|
|
|
|
<cfreturn noData()
|
|
|
|
|
.withHeaders({location: "./#local.instanceUid#"})
|
|
|
|
|
.withStatus(201, "Created")
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
</cffunction>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
</cffunction><!--- post --->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -459,35 +442,3 @@
|
|
|
|
|
|
|
|
|
|
</cfcomponent>
|
|
|
|
|
|
|
|
|
|
<!--- select
|
|
|
|
|
*
|
|
|
|
|
from (
|
|
|
|
|
select
|
|
|
|
|
to_char(e.dt_created, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as instance_config_dt_created,to_char(e.dt_updated, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as instance_config_dt_updated,e.instance_uid::text as instance_uid,e.display_name,e.service_id,e.specification_item_id,e.is_auxiliary,d.contract_id,i.specification_id,s.specification,i.quantity,i.price,v.svc,v.code,e.updater_id,u.login as updater_login,u.shortname as updater_shortname,(select io.operation from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as last_operation,(select io.instance_operation_uid::text from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as last_operation_uid,(select io.submit_result from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as submit_result,(select to_char(io.dt_start, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as operation_dt_start,(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as operation_dt_finish,(select round(extract('epoch' from coalesce(io.dt_finish,CURRENT_TIMESTAMP)- io.dt_start),1) from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as duration,(select case when io.operation IN ('delete', 'suspend') AND io.is_successful then 0 /*null*/ when io.is_successful then extract('epoch' from CURRENT_TIMESTAMP - coalesce(io.dt_finish,CURRENT_TIMESTAMP)) else 0 end from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as uptime,(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid AND io.is_successful AND io.operation='create' order by dt_submit desc limit 1) as dt_deploy,(select instance_data::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_data,(select st.instance_state_uid::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_state_uid,(select st.is_test from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as is_test,(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as is_deleted,(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as suspended,(select to_char(st.dt_state, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as dt_state,
|
|
|
|
|
(case
|
|
|
|
|
when
|
|
|
|
|
(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'deleted'
|
|
|
|
|
when
|
|
|
|
|
(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
|
|
|
|
|
when
|
|
|
|
|
(select COALESCE(st.instance_data->>'isDeleted','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' AND (select COALESCE(st.instance_data->>'suspended','false') from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' then 'running'
|
|
|
|
|
when
|
|
|
|
|
not exists (select * from instance_operation o where o.instance_uid=e.instance_uid) then 'not configured'
|
|
|
|
|
when
|
|
|
|
|
not exists (select * from instance_state st where st.instance_uid=e.instance_uid) then 'not created'
|
|
|
|
|
else null end
|
|
|
|
|
) as explained_status
|
|
|
|
|
,(select max(version) from instance_state st where st.instance_uid=e.instance_uid) as version
|
|
|
|
|
from instance e
|
|
|
|
|
join specification_item i on (e.specification_item_id=i.specification_item_id)
|
|
|
|
|
join specification s on (i.specification_id=s.specification_id)
|
|
|
|
|
join contract d on (s.contract_id=d.contract_id)
|
|
|
|
|
join contragent k on (d.contragent_id=k.contragent_id)
|
|
|
|
|
join svc v on (e.service_id=v.svc_id)
|
|
|
|
|
left outer join usr u on (e.updater_id=u.usr_id)
|
|
|
|
|
where s.specification_id=2
|
|
|
|
|
) inr
|
|
|
|
|
where 1=1
|
|
|
|
|
order by 1 desc
|
|
|
|
|
limit 3
|
|
|
|
|
offset 18 --->
|