Skip to content

Commit

Permalink
Remove Execution usages of GormExecReportDataProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ocerda committed May 9, 2024
1 parent 1e2978e commit a60f65d
Show file tree
Hide file tree
Showing 16 changed files with 286 additions and 187 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {
api project(":rundeck-authz:rundeck-authz-api")
api project(":rundeck-authz:rundeck-authz-core")
api project(":rundeck-authz:rundeck-authz-yaml")
api "org.rundeck:rundeck-data-models:1.0.5"
api "org.rundeck:rundeck-data-models:1.0.6"

api ('com.google.guava:guava:32.0.1-jre') {
exclude group:'org.codehaus.mojo', module: 'animal-sniffer-annotations'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ class RdExecution implements ExecutionData, Validateable {
boolean statusSucceeded(){
return getExecutionState()== ExecutionConstants.EXECUTION_SUCCEEDED
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ import java.lang.reflect.Field;

@Slf4j
class SaveReportRequestImpl implements SaveReportRequest {
Long executionId;
Date dateStarted;
String jobId;
String reportId;
Boolean adhocExecution;
String succeededNodeList;
String failedNodeList;
String filterApplied;
String project;
String abortedByUser;
String author;
String title;
String status;
String node;
String message;
Date dateCompleted;
String adhocScript;
String tags;
Long executionId
Date dateStarted
String jobId
String reportId
Boolean adhocExecution
String succeededNodeList
String failedNodeList
String filterApplied
String project
String abortedByUser
String author
String title
String status
String node
String message
Date dateCompleted
String adhocScript
String tags
String jobUuid
String executionUuid

static void buildFromMap(SaveReportRequestImpl obj, Map<String, Object> data) {
for (String key : data.keySet()) {
Field field;
Field field
try {
if(key == "ctxProject") {
obj.project = (String)data.get("ctxProject");
Expand All @@ -41,17 +43,17 @@ class SaveReportRequestImpl implements SaveReportRequest {
if(field != null){
if(key == "dateStarted" | key == "dateCompleted"){
if (!(data.get("dateCompleted") instanceof Date)) {
obj.dateCompleted = new Date();
obj.dateCompleted = new Date()
} else {
obj.dateCompleted = (Date)data.get("dateCompleted");
obj.dateCompleted = (Date)data.get("dateCompleted")
}
if (data.get("dateStarted") instanceof Date) {
obj.dateStarted = (Date)data.get("dateStarted");
obj.dateStarted = (Date)data.get("dateStarted")
}
}else if(key == "executionId"){
obj.executionId = new Long((Integer)data.get(key));
obj.executionId = new Long((Integer)data.get(key))
}else if(key == "adhocExecution"){
obj.adhocExecution = Boolean.parseBoolean(String.valueOf(data.get(key)));
obj.adhocExecution = Boolean.parseBoolean(String.valueOf(data.get(key)))
}else{
obj[key] = data.get(key)
}
Expand All @@ -60,18 +62,19 @@ class SaveReportRequestImpl implements SaveReportRequest {

} catch (NoSuchFieldException nsfe) {
if(!DEPRECATED_FIELD_NAMES.contains(key)) {
log.info("Report builder found unknown field: " + key);
log.info("Report builder found unknown field: " + key)
}
} catch (IllegalAccessException iex) {
log.warn("Unable to set field: "+key+" illegal access");
log.warn("Unable to set field: "+key+" illegal access")
}
}
}
static SaveReportRequestImpl fromMap(Map data) {
SaveReportRequestImpl SaveReportRequest = new SaveReportRequestImpl();
buildFromMap(SaveReportRequest, data);
return SaveReportRequest;
SaveReportRequestImpl SaveReportRequest = new SaveReportRequestImpl()
buildFromMap(SaveReportRequest, data)
return SaveReportRequest
}

public static final List<String> DEPRECATED_FIELD_NAMES = Arrays.asList("ctxProject","jcJobId","jcExecId","actionType","ctxType","ctxName","ctxCommand","ctxController","maprefUri");
public static final List<String> DEPRECATED_FIELD_NAMES = Arrays.asList("ctxProject","jcJobId","jcExecId","actionType","ctxType","ctxName","ctxCommand","ctxController","maprefUri")

}
Original file line number Diff line number Diff line change
Expand Up @@ -298,21 +298,23 @@ class ReportsController extends ControllerBase{
results.reports=results?.reports.collect{
def map=it.toMap()
map.duration= (it.dateCompleted ?: new Date()).time - it.dateStarted.time
if(map.executionId){
if(map.executionUuid){
//nb:response data type expects string
map.executionId= map.executionId.toString()
try {
map.execution = Execution.get(map.executionId).toMap()
map.executionHref = createLink(controller: 'execution', action: 'show', absolute: false, id: map.executionId, params: [project: (map?.project != null)? map.project : params.project])
} catch (Exception e) {
map.execution = Execution.findByUuid(map.executionUuid)?.toMap()
map.executionId= map.execution.id.toString()
map.executionHref = createLink(controller: 'execution', action: 'show', absolute: false, id: map.execution.id, params: [project: (map?.project != null)? map.project : params.project])

} catch (Exception e) {
log.debug("Error getting Execution: " + e.message)
}
}
}

map.jobName= map.remove('reportId')
if(map.jcJobId){
if(map.jobUuid){
map.jobId= map.remove('jcJobId')
try {
def job = ScheduledExecution.get(Long.parseLong(map.jobId))
def job = ScheduledExecution.findByUuid(map.jobUuid)
map.jobId=job?.extid
map.jobDeleted = job==null
map['jobPermalink']= createLink(
Expand All @@ -325,6 +327,7 @@ class ReportsController extends ControllerBase{
map.jobName=job?.jobName
map.jobGroup=job?.groupPath
}catch(Exception e){
log.debug("Error getting job: "+e.message)
}
if(map.execution?.argString){
map.execution.jobArguments= OptionsParserUtil.parseOptsFromString(map.execution.argString)
Expand Down
8 changes: 6 additions & 2 deletions rundeckapp/grails-app/domain/rundeck/ExecReport.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ExecReport extends BaseReport implements RdExecReport{
String failedNodeList
String filterApplied
String jobUuid
String executionUuid

static mapping = {
adhocScript type: 'text'
Expand All @@ -61,6 +62,7 @@ class ExecReport extends BaseReport implements RdExecReport{
failedNodeList(nullable:true,blank:true)
filterApplied(nullable:true,blank:true)
jobUuid(nullable:true)
executionUuid(nullable:true)

}

Expand All @@ -73,7 +75,8 @@ class ExecReport extends BaseReport implements RdExecReport{
'succeededNodeList',
'failedNodeList',
'filterApplied',
'jobUuid'
'jobUuid',
'executionUuid'
]
def Map toMap(){
def map = this.properties.subMap(exportProps)
Expand Down Expand Up @@ -135,7 +138,8 @@ class ExecReport extends BaseReport implements RdExecReport{
failedNodeList: failedList,
succeededNodeList: succeededList,
filterApplied: exec.filter,
jobUuid: exec.scheduledExecution?.uuid
jobUuid: exec.scheduledExecution?.uuid,
executionUuid: exec.uuid
])
}
static ExecReport fromMap(Map map) {
Expand Down
48 changes: 48 additions & 0 deletions rundeckapp/grails-app/domain/rundeck/Execution.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import com.fasterxml.jackson.core.JsonParseException
import grails.gorm.DetachedCriteria
import org.rundeck.app.data.model.v1.execution.ExecutionData
import org.rundeck.app.data.model.v1.execution.ExecutionDataSummary
import org.rundeck.app.data.model.v1.report.dto.SaveReportRequest
import rundeck.data.execution.RdExecutionDataSummary
import rundeck.data.job.RdNodeConfig
import rundeck.data.report.SaveReportRequestImpl
import rundeck.data.validation.shared.SharedExecutionConstraints
import rundeck.data.validation.shared.SharedNodeConfigConstraints
import rundeck.data.validation.shared.SharedProjectNameConstraints
Expand Down Expand Up @@ -565,5 +567,51 @@ class Execution extends ExecutionContext implements EmbeddedJsonData, ExecutionD
serverNodeUUID: this.serverNodeUUID
)
}

SaveReportRequest toSaveReportRequest() {
def failedCount = failedNodeList ? failedNodeList.split(',').size() : 0
def successCount = succeededNodeList ? succeededNodeList.split(',').size() : 0;
def failedList = failedNodeList ? failedNodeList : ''
def succeededList = succeededNodeList ? succeededNodeList : '';
def totalCount = failedCount + successCount;
def adhocScript = null
if (
null == scheduledExecution
&& workflow.commands
&& workflow.commands.size() == 1
&& workflow.commands[0] instanceof CommandExec
) {
adhocScript = workflow.commands[0].adhocRemoteString
}
def summary = "[${workflow.commands ? workflow.commands.size() : 0} steps]"
def issuccess = statusSucceeded()
def iscancelled = cancelled
def istimedout = timedOut
def ismissed = status == "missed"
def status = issuccess ? "succeed" : iscancelled ? "cancel" : willRetry ? "retry" : istimedout ?
"timedout" : ismissed ? "missed" : "fail"
return new SaveReportRequestImpl(
executionId: id,
jobId: scheduledExecution?.id,
adhocExecution: null == scheduledExecution,
adhocScript: adhocScript,
abortedByUser: iscancelled ? abortedby ?: user : null,
node: "${successCount}/${failedCount}/${totalCount}",
title: adhocScript ? adhocScript : summary,
status: status,
project: project,
reportId: scheduledExecution ? (scheduledExecution.groupPath ? scheduledExecution.generateFullName() : scheduledExecution.jobName) : 'adhoc',
author: user,
message: (issuccess ? 'Job completed successfully' : iscancelled ? ('Job killed by: ' + (abortedby ?: user)) : ismissed ? "Job missed execution at: ${dateStarted}" : 'Job failed'),
dateStarted: dateStarted,
dateCompleted: dateCompleted,
failedNodeList: failedList,
succeededNodeList: succeededList,
filterApplied: filter,
jobUuid: scheduledExecution?.uuid,
executionUuid: uuid)
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ExecutionsCleanUp implements InterruptableJob {
referencedExecutionDataProvider.deleteByExecutionId(e.id)

//delete all reports
reportService.deleteByExecutionId(e.id)
reportService.deleteByExecutionUuid(e.uuid)
def executionFiles = logFileStorageService.getExecutionFiles(e, [], false)

List<File> files = []
Expand Down
24 changes: 24 additions & 0 deletions rundeckapp/grails-app/migrations/core/BaseReportSpi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,28 @@ databaseChangeLog = {
" inner join execution ON execution.scheduled_execution_id = scheduled_execution.id\n" +
" WHERE base_report.execution_id = execution.id)")
}

changeSet(author: "rundeckdev", id: "add-execution-uuid-to-base-report") {
preConditions(onFail: "MARK_RAN") {
not {
columnExists(tableName: "base_report", columnName: 'execution_uuid')
}
}
addColumn(tableName: "base_report") {
column(name: 'execution_uuid', type: '${varchar255.type}')
}
}

changeSet(author: "rundeckdev", id: "populate-base-report-execution-uuid") {
preConditions(onFail: "MARK_RAN") {
tableExists(tableName: "base_report")
tableExists(tableName: "execution")
}
sql("update base_report\n" +
"set execution_uuid =\n" +
" (select execution.uuid\n" +
" from execution\n" +
" WHERE base_report.execution_id = execution.id)")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte

public logExecution(uri,project,user,issuccess,statusString,execId,Date startDate=null, jobExecId=null, jobName=null,
jobSummary=null,iscancelled=false,istimedout=false,willretry=false, nodesummary=null,
abortedby=null, succeededNodeList=null, failedNodeList=null, filter=null){
abortedby=null, succeededNodeList=null, failedNodeList=null, filter=null, executionUuid=null, jobUuid=null){

SaveReportRequestImpl saveReportRequest = new SaveReportRequestImpl()
def internalLog = LoggerFactory.getLogger("ExecutionService")
Expand All @@ -931,6 +931,9 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
if(execId){
saveReportRequest.executionId=execId
}
if(executionUuid){
saveReportRequest.executionUuid=executionUuid
}
if(startDate){
saveReportRequest.dateStarted=startDate
}
Expand Down Expand Up @@ -961,6 +964,9 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
}else if(iscancelled){
saveReportRequest.abortedByUser=user
}
if(jobUuid){
saveReportRequest.jobUuid = jobUuid
}
saveReportRequest.author=user
saveReportRequest.title= jobSummary?jobSummary:"Rundeck Job Execution"

Expand All @@ -981,7 +987,7 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
saveReportRequest.dateCompleted=new Date()
def result=reportService.reportExecutionResult(saveReportRequest)
if(result.error){
log.error("Failed to create report: "+result.report.errors.allErrors.collect{it.toString()}).join("; ")
log.error("Failed to create report: "+result.errors)
}
}

Expand Down Expand Up @@ -2030,7 +2036,7 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
}
referencedExecutionDataProvider.deleteByExecutionId(e.id)
//delete all reports
execReportDataProvider.deleteAllByExecutionId(e.id)
execReportDataProvider.deleteAllByExecutionUuid(e.uuid)

List<File> files = []
def execs = []
Expand Down Expand Up @@ -3186,10 +3192,12 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
}
def jobname="adhoc"
def jobid=null
def jobUuid=null
def summary= summarizeJob(scheduledExecution, execution)
if (scheduledExecution) {
jobname = scheduledExecution.groupPath ? scheduledExecution.generateFullName() : scheduledExecution.jobName
jobid = scheduledExecution.id
jobUuid = scheduledExecution.uuid
}
if(execSaved) {
//summarize node success
Expand Down Expand Up @@ -3226,7 +3234,9 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
execution.abortedby,
execution.succeededNodeList,
execution.failedNodeList,
execution.filter
execution.filter,
execution.uuid,
jobUuid
)
logExecutionLog4j(execution, "finish", execution.user)

Expand Down Expand Up @@ -4450,7 +4460,7 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
missed.status = 'missed'
missed.save()

execReportDataProvider.createReportFromExecution(missed.id)
execReportDataProvider.saveReport(missed.toSaveReportRequest())

if(scheduledExecution.notifications) {
AuthContext authContext = rundeckAuthContextProcessor.
Expand Down

0 comments on commit a60f65d

Please sign in to comment.