Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add createTime and updateTime in db for systempolicy #386

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/libs/mysqlHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ func CreateTableWorkLoadProcessFileSetMySQL(cfg types.ConfigDB) error {
" `fromSource` varchar(256) DEFAULT NULL," +
" `settype` varchar(16) DEFAULT NULL," + // settype: "file" or "process"
" `fileset` text DEFAULT NULL," +
" `createdTime` bigint NOT NULL," +
" `updatedTime` bigint NOT NULL," +
" PRIMARY KEY (`id`)" +
" );"

Expand Down Expand Up @@ -592,9 +594,10 @@ func InsertWorkloadProcessFileSetMySQL(cfg types.ConfigDB, wpfs types.WorkloadPr
db := connectMySQL(cfg)
defer db.Close()
policyName := "autopol-" + strings.ToLower(wpfs.SetType) + "-" + RandSeq(15)
time := ConvertStrToUnixTime("now")

stmt, err := db.Prepare("INSERT INTO " + WorkloadProcessFileSet_TableName +
"(policyName,clusterName,namespace,containerName,labels,fromSource,settype,fileset) values(?,?,?,?,?,?,?,?)")
"(policyName,clusterName,namespace,containerName,labels,fromSource,settype,fileset,createdtime,updatedtime) values(?,?,?,?,?,?,?,?,?,?)")
if err != nil {
return err
}
Expand All @@ -609,7 +612,9 @@ func InsertWorkloadProcessFileSetMySQL(cfg types.ConfigDB, wpfs types.WorkloadPr
wpfs.Labels,
wpfs.FromSource,
wpfs.SetType,
fsset)
fsset,
time,
time)
return err
}

Expand All @@ -618,17 +623,19 @@ func UpdateWorkloadProcessFileSetMySQL(cfg types.ConfigDB, wpfs types.WorkloadPr
defer db.Close()

var err error
time := ConvertStrToUnixTime("now")

// set status -> outdated
stmt, err := db.Prepare("UPDATE " + WorkloadProcessFileSet_TableName +
" SET fileset=? WHERE clusterName = ? and containerName = ? and namespace = ? and labels = ? and fromSource = ? and settype = ?")
" SET fileset=?,updatedtime=? WHERE clusterName = ? and containerName = ? and namespace = ? and labels = ? and fromSource = ? and settype = ?")
if err != nil {
return err
}
defer stmt.Close()
fsset := strings.Join(fs[:], ",")

_, err = stmt.Exec(fsset,
time,
wpfs.ClusterName,
wpfs.ContainerName,
wpfs.Namespace,
Expand Down