Ejemplo n.º 1
0
// return map[location][class_name]*JobInfoEntry
func getGroupedJobInfo() (map[string]map[string]*JobInfoEntry, error) {
	res := make(map[string]map[string]*JobInfoEntry)

	rows, err := db.Query(QUERY_GET_JOB_INFO)
	if err != nil {
		return nil, err
	}

	for rows.Next() {
		entry := new(JobInfoEntry)
		err = rows.Scan(
			&entry.generation_id,
			&entry.class_name,
			&entry.location,
			&entry.init_jobs_ts,
			&entry.jobs_generated_ts,
			&entry.finish_jobs_ts,
			&entry.next_generate_job_ts,
			&entry.settings_id)

		if err != nil {
			return nil, err
		}

		if _, ok := res[entry.class_name]; !ok {
			res[entry.class_name] = make(map[string]*JobInfoEntry)
		}

		res[entry.class_name][entry.location] = entry
	}

	return res, nil
}
Ejemplo n.º 2
0
// get existing ids from db for provided checkIds list
func getExistingTTIds(checkIds []uint64) (map[uint64]bool, error) {
	res := make(map[uint64]bool, len(checkIds))
	if len(checkIds) == 0 {
		return res, nil
	}

	rows, err := db.Query(QUERY_CHECK_TT_IDS, "ids", db.INUint64(checkIds))
	if err != nil {
		return nil, err
	}

	defer rows.Close()

	var id uint64
	for rows.Next() {
		err = rows.Scan(&id)

		if err != nil {
			return nil, err
		}

		res[id] = true
	}

	return res, nil
}
Ejemplo n.º 3
0
func selectTimetable() (map[string]map[string][]*TimetableEntry, error) {
	timetableRows := make(map[string]map[string][]*TimetableEntry)

	rows, err := db.Query(QUERY_SELECT_FROM_TIMETABLE, "add_where", "")
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	for rows.Next() {
		tt_entry, err := scanTimetableEntry(rows)
		if err != nil {
			return nil, err
		}

		perLoc, ok := timetableRows[tt_entry.class_name]
		if !ok {
			perLoc = make(map[string][]*TimetableEntry)
			timetableRows[tt_entry.class_name] = perLoc
		}

		if _, ok := perLoc[tt_entry.location]; !ok {
			perLoc[tt_entry.location] = make([]*TimetableEntry, 0)
		}

		perLoc[tt_entry.location] = append(perLoc[tt_entry.location], tt_entry)
	}

	return timetableRows, nil
}
Ejemplo n.º 4
0
func getFlags() (map[string]*FlagEntry, error) {
	res := make(map[string]*FlagEntry)

	rows, err := db.Query(QUERY_GET_FLAGS)
	if err != nil {
		return nil, err
	}

	for rows.Next() {
		entry := new(FlagEntry)
		err = rows.Scan(
			&entry.class_name,
			&entry.run_requested_ts,
			&entry.run_accepted_ts,
			&entry.pause_requested_ts,
			&entry.kill_requested_ts,
			&entry.kill_request_employee_id,
			&entry.run_queue_killed_ts,
			&entry.killed_ts,
			&entry.paused_ts)

		if err != nil {
			return nil, err
		}

		res[entry.class_name] = entry
	}

	return res, nil
}
Ejemplo n.º 5
0
func getScriptRusageStats() (map[string]*ScriptRusageEntry, error) {
	res := make(map[string]*ScriptRusageEntry)

	rows, err := db.Query(QUERY_GET_SCRIPTS_RUSAGE_STATS)
	if err != nil {
		return nil, err
	}

	var (
		class_name string
		max_memory int64
		user_time  float64
		sys_time   float64
		real_time  float64
	)

	for rows.Next() {
		entry := new(ScriptRusageEntry)
		err = rows.Scan(
			&class_name,
			&real_time,
			&sys_time,
			&user_time,
			&max_memory)

		if err != nil {
			return nil, err
		}

		entry.cpu_usage = defaultRusage
		entry.max_memory = defaultMaxMemory

		if max_memory > 0 {
			entry.max_memory = max_memory
		}

		if (user_time > 0 || sys_time > 0) && real_time > 0 {
			entry.cpu_usage = (user_time + sys_time) / real_time
		}

		res[class_name] = entry
	}

	return res, nil
}
Ejemplo n.º 6
0
func SelectRunQueue() (map[string][]*RunQueueEntry, error) {
	rqRows := make(map[string][]*RunQueueEntry, 0)
	rows, err := db.Query(QUERY_GET_RUNQUEUE, "where", "")
	if err != nil {
		return nil, err
	}

	for rows.Next() {
		rq_entry, err := scanRqEntry(rows)
		if err != nil {
			return nil, err
		}

		rqRows[rq_entry.hostname] = append(rqRows[rq_entry.hostname], rq_entry)
	}

	return rqRows, nil
}
Ejemplo n.º 7
0
func getRunningInfo(run_id uint64) (*RunQueueEntry, error) {
	rows, err := db.Query(QUERY_GET_RUNQUEUE, "where", &db.RawData{Data: fmt.Sprintf("WHERE id = %d", run_id)})
	if err != nil {
		return nil, err
	}

	defer rows.Close()

	for rows.Next() {
		rq_entry, err := scanRqEntry(rows)
		if err != nil {
			return nil, err
		}

		return rq_entry, nil
	}

	return nil, errorNoRow
}
Ejemplo n.º 8
0
func getAvailableHosts() (map[string][]string, map[string]*ServerInfo, error) {
	rows, err := db.Query(QUERY_GET_AVAILABLE_HOSTS)
	if err != nil {
		return nil, nil, err
	}

	hosts := make(map[string][]string)
	info := make(map[string]*ServerInfo)

	defer rows.Close()

	for rows.Next() {
		entry := new(ServerInfo)

		err = rows.Scan(
			&entry.hostname,
			&entry.group,
			&entry.cpu_idle_parrots,
			&entry.cpu_parrots_per_core,
			&entry.cpu_idle_cores,
			&entry.cpu_cores,
			&entry.cpu_parasite,
			&entry.mem_total,
			&entry.mem_free,
			&entry.mem_cached,
			&entry.mem_parasite,
			&entry.swap_used,
			&entry.min_memory,
			&entry.min_memory_ratio)

		if err != nil {
			return nil, nil, err
		}

		hosts[entry.group] = append(hosts[entry.group], entry.hostname)
		info[entry.hostname] = entry
	}

	return hosts, info, nil
}
Ejemplo n.º 9
0
func selectTimetableByIds(ids []uint64) ([]*TimetableEntry, error) {
	timetableRows := make([]*TimetableEntry, 0, len(ids))
	if len(ids) == 0 {
		return timetableRows, nil
	}

	rows, err := db.Query(QUERY_SELECT_FROM_TIMETABLE, "add_where", &db.RawData{Data: fmt.Sprintf("WHERE id IN (%s)", db.INUint64(ids).Data)})
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	for rows.Next() {
		tt_entry, err := scanTimetableEntry(rows)
		if err != nil {
			return nil, err
		}
		timetableRows = append(timetableRows, tt_entry)
	}

	return timetableRows, nil
}
Ejemplo n.º 10
0
func getAutoIncrementIncrement() int64 {
	rows, err := db.Query("SHOW VARIABLES LIKE 'auto_increment_increment'")
	if err != nil {
		log.Fatal("Could not get auto_increment_increment variable from DB: " + err.Error())
	}

	defer rows.Close()

	var varName string
	var res int64

	for rows.Next() {
		if err := rows.Scan(&varName, &res); err != nil {
			log.Fatal("Could not fetch results for auto_increment_increment variable: " + err.Error())
		}

		if varName == "auto_increment_increment" {
			return res
		}
	}

	return 1 // default value if no special variable is set
}
Ejemplo n.º 11
0
func getGroupedScriptsForPlatform() (map[string]*ScriptEntry, error) {
	res := make(map[string]*ScriptEntry)

	rows, err := db.Query(QUERY_SIMPLE_GET_SCRIPTS_FOR_PLATFORM)
	if err != nil {
		return nil, err
	}

	for rows.Next() {
		entry := new(ScriptEntry)
		err = rows.Scan(
			&entry.class_name,
			&entry.settings_id)

		if err != nil {
			return nil, err
		}

		res[entry.class_name] = entry
	}

	return res, nil
}
Ejemplo n.º 12
0
func getRunningInfos(run_ids []uint64) ([]*RunQueueEntry, error) {
	res := make([]*RunQueueEntry, 0, len(run_ids))
	if len(run_ids) == 0 {
		return res, nil
	}
	rows, err := db.Query(QUERY_GET_RUNQUEUE, "where", &db.RawData{Data: fmt.Sprintf("WHERE id IN (%s)", db.INUint64(run_ids).Data)})
	if err != nil {
		return nil, err
	}

	defer rows.Close()

	for rows.Next() {
		rq_entry, err := scanRqEntry(rows)
		if err != nil {
			return nil, err
		}

		res = append(res, rq_entry)
	}

	return res, nil
}
Ejemplo n.º 13
0
func loadNewIds(newIds map[uint64]bool) error {
	if len(newIds) == 0 {
		return nil
	}

	var ids []string

	for id := range newIds {
		ids = append(ids, strconv.FormatUint(id, 10))
	}

	rows, err := db.Query(QUERY_GET_NEW_SETTINGS, "new_settings_ids", strings.Join(ids, ","))
	if err != nil {
		return err
	}

	for rows.Next() {
		entry := new(ScriptSettings)

		var (
			jobsStr           string
			nextTsCallbackStr sql.NullString
		)

		err = rows.Scan(
			&entry.id,
			&entry.class_name,
			&entry.instance_count,
			&entry.max_time,
			&jobsStr,
			&nextTsCallbackStr,
			&entry.repeat,
			&entry.retry,
			&entry.ttl,
			&entry.repeat_job,
			&entry.retry_job,
			&entry.location,
			&entry.location_type,
			&entry.developer,
			&entry.max_retries,
			&entry.profiling_enabled,
			&entry.debug_enabled,
			&entry.named_params,
			&entry.created)

		if err != nil {
			log.Errorf("Invalid settings: %s", err.Error())
			err = nil
			continue
		}

		entry.jobs, err = parseJobs(jobsStr)
		if err != nil {
			log.Errorf("Could not parse Jobs for %s #%d: %s", entry.class_name, entry.id, err.Error())
			err = nil
			continue
		}

		if nextTsCallbackStr.Valid {
			entry.have_next_ts_callback = true
			entry.next_ts_callback, err = parseNextTsCallback(nextTsCallbackStr.String)
			if err != nil {
				log.Errorf("Could not parse next ts callback for %s #%d: %s", entry.class_name, entry.id, err.Error())
				err = nil
				continue
			}
		} else {
			entry.have_next_ts_callback = false
		}

		if err != nil {
			log.Errorf("Scan error in loadNewIds: %s", err.Error())
			err = nil
			continue
		}

		allSettingsMutex.Lock()
		allSettings[entry.id] = entry
		allSettingsMutex.Unlock()
	}

	return nil
}