Ejemplo n.º 1
0
int
sched_save_db(struct sched *ps, int mode)
{
	pbs_db_conn_t *conn = (pbs_db_conn_t *) svr_db_conn;
	pbs_db_sched_info_t dbsched;
	pbs_db_attr_info_t attr_info;
	pbs_db_obj_info_t obj;
	int flag=0;

	svr_to_db_sched(ps, &dbsched);
	obj.pbs_db_obj_type = PBS_DB_SCHED;
	obj.pbs_db_un.pbs_db_sched = &dbsched;

	if (mode == SVR_SAVE_QUICK) {
		/* save server_qs */
		if (pbs_db_update_obj(conn, &obj) != 0)
			goto db_err;
	} else {	/* SVR_SAVE_FULL Save */
		if (pbs_db_begin_trx(conn, 0, 0) !=0)
			goto db_err;

		if (mode == SVR_SAVE_NEW) {
			if (pbs_db_insert_obj(conn, &obj) != 0)
				goto db_err;
			flag = 1;
		} else {

			/* server_qs */
			if (pbs_db_update_obj(conn, &obj) != 0) {
				if (pbs_db_insert_obj(conn, &obj) != 0)
					goto db_err;
			}
		}

		/* svr_attrs */
		attr_info.parent_obj_type = PARENT_TYPE_SCHED; /* svr attr */
		attr_info.parent_id = pbs_server_id;

		if (save_attr_db(conn, &attr_info, sched_attr_def, ps->sch_attr, (int)SCHED_ATR_LAST, flag) !=0)
			goto db_err;

		if (pbs_db_end_trx(conn, PBS_DB_COMMIT) != 0)
			goto db_err;
	}
	return (0);

db_err:
	strcpy(log_buffer, schedemsg);
	if (conn->conn_db_err != NULL)
		strncat(log_buffer, conn->conn_db_err, LOG_BUF_SIZE - strlen(log_buffer) - 1);
	log_err(-1, __func__, log_buffer);
	(void) pbs_db_end_trx(conn, PBS_DB_ROLLBACK);
	panic_stop_db(log_buffer);
	return (-1);
}
Ejemplo n.º 2
0
int
sched_save_db(pbs_sched *ps, int mode)
{
	pbs_db_conn_t *conn = (pbs_db_conn_t *) svr_db_conn;
	pbs_db_sched_info_t dbsched;
	pbs_db_obj_info_t obj;
	int savetype = PBS_UPDATE_DB_FULL;
	int rc;

	if (mode == SVR_SAVE_FULL)
		savetype = PBS_UPDATE_DB_FULL;
	else if (mode == SVR_SAVE_QUICK)
		savetype = PBS_UPDATE_DB_QUICK;
	else
		savetype = PBS_INSERT_DB;

	if (svr_to_db_sched(ps, &dbsched, savetype) != 0)
		goto db_err;

	obj.pbs_db_obj_type = PBS_DB_SCHED;
	obj.pbs_db_un.pbs_db_sched = &dbsched;


	rc = pbs_db_save_obj(conn, &obj, savetype);
	if (rc != 0) {
		savetype = PBS_INSERT_DB;
		rc = pbs_db_save_obj(conn, &obj, savetype);
	}

	/* free the attribute list allocated by encode_attrs */
	pbs_db_reset_obj(&obj);

	if (rc != 0)
		goto db_err;

	return (0);

db_err:
	strcpy(log_buffer, schedemsg);
	if (conn->conn_db_err != NULL)
		strncat(log_buffer, conn->conn_db_err, LOG_BUF_SIZE - strlen(log_buffer) - 1);
	log_err(-1, __func__, log_buffer);

	panic_stop_db(log_buffer);
	return (-1);
}