blob: ed8151b4b26b0627be05f5786a2f1ed25e09e1cd [file]
/**
*
* 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.
*/
package model
import (
applicationmodel "github.com/apache/airavata/api/application/model"
computemodel "github.com/apache/airavata/api/compute/model"
"github.com/google/uuid"
"gorm.io/gorm"
"time"
)
// BatchJobProcess carries what a BATCH_JOB process needs beyond a Process: the
// deployment being run, the resources this run asked for, and the scheduler's
// identifiers for the job once it has one.
//
// It is not a resource of its own. A caller creates it as the batchProcess section of
// a process, reads it back nested in that process, and deletes it by deleting the
// process — which is why the row is keyed by its own id but reached only through
// parent_process_id, unique because a process has at most one of them.
type BatchJobProcess struct {
ID string `gorm:"column:batch_process_id;primaryKey;type:varchar(36)" json:"batchProcessId"`
// Owned by Process.BatchProcess, which declares the cascade; only the key is held
// here. Unique because a process has at most one batch process.
ProcessID *string `gorm:"column:parent_process_id;type:varchar(36);uniqueIndex" json:"parentProcessId,omitempty"`
DeploymentID *string `gorm:"column:deployment_id;type:varchar(36);index" json:"deploymentId,omitempty"`
Deployment *applicationmodel.BatchDeployment `gorm:"references:ID;constraint:OnDelete:RESTRICT,OnUpdate:CASCADE" json:"-"`
// The cluster login config this batch job submits under: the account, the key and
// the work root it runs as. RESTRICT, so a config cannot be deleted out from under
// a run that submitted through it.
SlurmClusterConfigID string `gorm:"column:slurm_cluster_config_id;type:varchar(36);not null;index" json:"slurmClusterConfigId"`
SlurmClusterConfig *computemodel.SlurmClusterConfig `gorm:"references:ID;constraint:OnDelete:RESTRICT,OnUpdate:CASCADE" json:"-"`
// Owned one-to-one, as on BatchDeployment: unique foreign key on this side, with
// the orphan removed by AfterDelete since the database cannot cascade outward.
BatchJobConfigID string `gorm:"column:batch_job_config_id;type:varchar(36);not null;uniqueIndex" json:"batchJobConfigId"`
BatchJobConfig *applicationmodel.BatchJobConfig `gorm:"references:ID;constraint:OnDelete:RESTRICT,OnUpdate:CASCADE" json:"batchJobConfig,omitempty"`
JobID *string `gorm:"column:job_id;type:varchar(255)" json:"jobId,omitempty"`
// The values this run supplies for the deployment template's declared inputs and
// outputs. They hang off the batch process rather than off the process because the
// declarations they name belong to the deployment, which only a BATCH_JOB has.
InputMappings []*TemplateInputMapping `gorm:"foreignKey:BatchProcessID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"inputMappings,omitempty"`
OutputMappings []*TemplateOutputMapping `gorm:"foreignKey:BatchProcessID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"outputMappings,omitempty"`
BaseWorkDir *string `gorm:"column:base_work_dir;type:varchar(1024)" json:"baseWorkDir,omitempty"`
BatchJobStatuses []*BatchJobStatus `gorm:"foreignKey:BatchProcessID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"batchJobStatuses,omitempty"`
}
// TableName returns the table backing BatchJobProcess.
func (BatchJobProcess) TableName() string { return "batch_processes" }
// BeforeCreate assigns a UUID when none was supplied.
func (p *BatchJobProcess) BeforeCreate(*gorm.DB) error {
if p.ID == "" {
p.ID = uuid.NewString()
}
return nil
}
// AfterDelete removes the owned BatchJobConfig, standing in for JPA's orphanRemoval.
//
// It fires only when the row is deleted through GORM, which is why Process.BeforeDelete
// deletes it explicitly rather than letting the database cascade do it.
func (p *BatchJobProcess) AfterDelete(tx *gorm.DB) error {
if p.BatchJobConfigID == "" {
return nil
}
return tx.Where("batch_job_config_id = ?", p.BatchJobConfigID).
Delete(&applicationmodel.BatchJobConfig{}).Error
}
type BatchJobStatusType string
const (
// Airavata specific status codes
BatchJobStatusSubmitted BatchJobStatusType = "SUBMITTED"
BatchJobStatusSubmissionFailed BatchJobStatusType = "SUBMISSION_FAILED"
BatchJobStatusCancelling BatchJobStatusType = "CANCELLING"
BatchJobStatusCancelled BatchJobStatusType = "CANCELLED"
// SLURM specific status codes
BatchJobStatusBegin BatchJobStatusType = "BEGIN"
BatchJobStatusRequeued BatchJobStatusType = "REQUEUE"
BatchJobStatusInvalidDepend BatchJobStatusType = "INVALID_DEPEND"
BatchJobStatusStageOut BatchJobStatusType = "STAGE_OUT"
BatchJobStatusTimeLimit BatchJobStatusType = "TIME_LIMIT"
BatchJobStatusTimeLimit90 BatchJobStatusType = "TIME_LIMIT_90"
BatchJobStatusTimeLimit80 BatchJobStatusType = "TIME_LIMIT_80"
BatchJobStatusTimeLimit50 BatchJobStatusType = "TIME_LIMIT_50"
BatchJobStatusFailed BatchJobStatusType = "FAIL"
BatchJobStatusEnded BatchJobStatusType = "END"
)
type BatchJobStatus struct {
ID string `gorm:"column:batch_process_status_id;primaryKey;type:varchar(36)" json:"batchProcessStatusId"`
BatchProcessID string `gorm:"column:batch_process_id;type:varchar(36);not null;index" json:"batchProcessId"`
Status BatchJobStatusType `gorm:"column:status;type:varchar(255);not null" json:"status"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;not null;autoUpdateTime" json:"updatedAt"`
}
func (BatchJobStatus) TableName() string { return "batch_process_statuses" }
func (s *BatchJobStatus) BeforeCreate(*gorm.DB) error {
if s.ID == "" {
s.ID = uuid.NewString()
}
return nil
}