028 prevent repeated run

This commit is contained in:
msyu
2024-11-26 11:56:50 +03:00
parent 205b5979d3
commit de88b5d0ad
3 changed files with 58 additions and 25 deletions
+1 -1
View File
@@ -71,7 +71,7 @@
//variables.framework.docs={}; //variables.framework.docs={};
variables.framework.docs.APIName="Deck API"; variables.framework.docs.APIName="Deck API";
variables.framework.docs.APIVersion="0.027"; variables.framework.docs.APIVersion="0.028";
variables.framework.globalHeaders = structNew(); variables.framework.globalHeaders = structNew();
variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location"; variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location";
+2 -1
View File
@@ -3,6 +3,7 @@
output="true" output="true"
hint="Static helper methods for ReST API"> hint="Static helper methods for ReST API">
<!--- v0.02 2024-10-15 ---> <!--- v0.02 2024-10-15 --->
<!--- v0.03 2024-11-27 --->
<cffunction name="empty2null" <cffunction name="empty2null"
@@ -270,7 +271,7 @@
<cfargument name="title" type="string" required="false" /> <cfargument name="title" type="string" required="false" />
<cfset var detail = listAppend(#ARGUMENTS.ex.message#,#ARGUMENTS.ex.detail#,": " )/> <cfset var detail = listAppend(#ARGUMENTS.ex.message#,#ARGUMENTS.ex.detail#,": " )/>
<cfset var title = structKeyExists(ARGUMENTS,"title") ? #ARGUMENTS.title# : #ARGUMENTS.message# /> <cfset var title = structKeyExists(ARGUMENTS,"title") ? #ARGUMENTS.title# : #ARGUMENTS.ex.message# />
<cfreturn formatMessage(detail, title) /> <cfreturn formatMessage(detail, title) />
</cffunction> </cffunction>
+54 -22
View File
@@ -10,33 +10,50 @@
<cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/> <cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/>
<cfset local={}/> <cfset local={}/>
<cfset local.instanceUid=#createGUID()#/> <!--- <cfset local.instanceUid=#createGUID()#/> --->
<!--- *** Проверить наличие обязательных CFS параметров <!--- *** Проверить наличие обязательных CFS параметров
Создать RFS параметры Создать RFS параметры
(валидируем CFS параметры при создании, а не сейчас) ---> (валидируем CFS параметры при создании, а не сейчас)
Проверить, что операция уже не выполняется
--->
<cftry> <cftry>
<!---NOT NULL fields---> <!---NOT NULL fields--->
<cfset this.helper.keyExistsAndValid(arguments, "instanceOperationUid", "guid")/> <cfset this.helper.keyExistsAndValid(arguments, "instanceOperationUid", "guid")/>
<!--- Check operation status --->
<cfquery name="local.qCheckStarted" result="local.result">
select io.dt_submit, io.dt_finish, io.submit_result
from instance_operation io
where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#" null=#!isValid('guid',arguments.instanceOperationUid)#/>
</cfquery> <!--- <cfdump var=#local.qCheckStarted.dt_finish#/><cfabort/> --->
<cfif local.qCheckStarted.recordCount EQ 0>
<cfreturn representationOf(this.helper.formatMessage("There is no configured instance operation with uid #arguments.instanceOperationUid#","Instance operation not found")).withStatus(404)/>
<cfelseif left(local.qCheckStarted.submit_result,1) EQ "2" AND len(local.qCheckStarted.dt_finish EQ 0)><!--- 201 etc --->
<cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter creation disabled for started operation")).withStatus(422)/>
</cfif>
<cfset generateRfsParams(arguments.instanceOperationUid, arguments.usrId)/> <cfset generateRfsParams(arguments.instanceOperationUid, arguments.usrId)/>
<cfset submitJob(arguments.instanceOperationUid)/> <cfset submitJob(arguments.instanceOperationUid)/>
<cfcatch type="invalidParamValue"> <cfcatch type="invalidParamValue">
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/> <cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
</cfcatch> </cfcatch>
<cfcatch type="missingDependency">
<cfreturn representationOf(this.helper.formatException(cfcatch,"Missing Dependency")).withStatus(424)/>
</cfcatch>
</cftry> </cftry>
<!--- <cfreturn representationOf("Not Implemented yet").withStatus(501)/> ---> <!--- <cfreturn representationOf("Not Implemented yet").withStatus(501)/> --->
<cfset generateRfsParams(arguments.instanceOperationUid)/>
<!--- --->
<cfreturn noData() <cfreturn noData().withStatus(201, "Created") />
.withHeaders({location: "./#local.instanceUid#"})
.withStatus(201, "Created")
/>
</cffunction> </cffunction>
<cffunction name="generateRfsParams"> <cffunction name="generateRfsParams">
<cfargument name="instanceOperationUid" type="guid"/> <cfargument name="instanceOperationUid" type="guid"/>
<cfargument name="usrId" type="numeric"/> <cfargument name="usrId" type="numeric"/>
@@ -129,21 +146,36 @@
where instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value=#arguments.instanceOperationUid#/> where instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value=#arguments.instanceOperationUid#/>
</cfquery> </cfquery>
<cfhttp method="post"
url="#qInstanceOperation.url#"
multipart=true <cftry>
multipartType="form-data" <cfhttp method="post"
timeout="3" url="#qInstanceOperation.url#"
charset="utf-8" multipart=true
result="orchestrator" multipartType="form-data"
> timeout="3"
<cfhttpparam type="HEADER" name="Authorization" value="#request.ORCHESTRATOR_AUTH#"/> charset="utf-8"
<cfhttpparam type="HEADER" name="Accept" value="application/json"/> result="orchestrator"
<cfhttpparam type="formfield" name="delay" value="0sec"/> >
<cfloop query="qInstanceOperationParam"> <cfhttpparam type="HEADER" name="Authorization" value="#request.ORCHESTRATOR_AUTH#"/>
<cfhttpparam type="formfield" name="#param#" value="#param_value#"/> <cfhttpparam type="HEADER" name="Accept" value="application/json"/>
</cfloop> <cfhttpparam type="formfield" name="delay" value="0sec"/>
</cfhttp> <cfloop query="qInstanceOperationParam">
<cfhttpparam type="formfield" name="#param#" value="#param_value#"/>
</cfloop>
</cfhttp>
<cfcatch type="any">
<cfthrow message="Cannot initiate connection to the orchestrator #cfcatch.message#" detail="#cfcatch.detail#"/>
<!--- <cfdump var=#qInstanceOperation#/>
<cfabort/> --->
</cfcatch>
</cftry>
<cfif len(orchestrator.errorDetail)>
<cfthrow type="missingDependency" message="Orchestrator communication error" detail="#orchestrator.errorDetail#"/>
<!--- лучше бы возвращать 503 или 424 --->
</cfif>
<cfquery name="qMarkOperationSubmit"> <cfquery name="qMarkOperationSubmit">
update instance_operation update instance_operation