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 2 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
18 changes: 14 additions & 4 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 All @@ -521,7 +523,7 @@ func GetWorkloadProcessFileSetMySQL(cfg types.ConfigDB, wpfs types.WorkloadProce
var results *sql.Rows
var err error

query := "SELECT policyName,clusterName,namespace,containerName,labels,fromSource,settype,fileset FROM " + WorkloadProcessFileSet_TableName
query := "SELECT policyName,clusterName,namespace,containerName,labels,fromSource,settype,fileset,createdtime,updatedtime FROM " + WorkloadProcessFileSet_TableName
seswarrajan marked this conversation as resolved.
Show resolved Hide resolved

var whereClause string
var args []interface{}
Expand Down Expand Up @@ -566,6 +568,7 @@ func GetWorkloadProcessFileSetMySQL(cfg types.ConfigDB, wpfs types.WorkloadProce
var fs []string
var policyNames []string
var policyName string
var createdTime, updatedTime int64
seswarrajan marked this conversation as resolved.
Show resolved Hide resolved
seswarrajan marked this conversation as resolved.
Show resolved Hide resolved

for results.Next() {
if err := results.Scan(
Expand All @@ -577,6 +580,8 @@ func GetWorkloadProcessFileSetMySQL(cfg types.ConfigDB, wpfs types.WorkloadProce
&loc_wpfs.FromSource,
&loc_wpfs.SetType,
&fscsv,
&createdTime,
&updatedTime,
seswarrajan marked this conversation as resolved.
Show resolved Hide resolved
); err != nil {
return nil, nil, err
}
Expand All @@ -592,9 +597,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 +615,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 +626,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