コード例 #1
0
/**
 * @brief
 *	Delete the job from the database
 *
 * @param[in]	conn - Connection handle
 * @param[in]	obj  - Job information
 *
 * @return      Error code
 * @retval	-1 - Failure
 * @retval	 0 - Success
 * @retval	 1 -  Success but no rows deleted
 *
 */
int
pg_db_delete_job(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj)
{
	pbs_db_job_info_t *pj = obj->pbs_db_un.pbs_db_job;
	int rc = 0;

	SET_PARAM_STR(conn, pj->ji_jobid, 0);

	if (pbs_db_begin_trx(conn, 0, 0) != 0)
		goto err;

	if ((rc = pg_db_cmd(conn, STMT_DELETE_JOB, 1)) == -1)
		goto err;

	if (pg_db_cmd(conn, STMT_DELETE_JOBSCR, 1) == -1)
		goto err;


	if (pbs_db_end_trx(conn, PBS_DB_COMMIT) != 0)
		goto err;

	return rc;
err:
	(void) pbs_db_end_trx(conn, PBS_DB_ROLLBACK);
	return -1;
}
コード例 #2
0
ファイル: db_postgres_svr.c プロジェクト: A9-William/pbspro
/**
 * @brief
 *	Delete all the server attributes from the database
 *
 * @param[in]	conn - Connection handle
 * @param[in]	obj  - server information
 *
 * @return      Error code
 * @retval	-1 - Failure
 * @retval	 0 - Success
 * @retval	 1 - Success but no rows deleted
 *
 */
int
pg_db_delete_svrattr(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj)
{
	pbs_db_svr_info_t *ps = obj->pbs_db_un.pbs_db_svr;
	LOAD_STR(conn, ps->sv_name, 0);

	return (pg_db_cmd(conn, STMT_DELETE_SVRATTR_ALL, 1));
}
コード例 #3
0
/**
 *@brief
 *	Save (insert/update) a new/existing job
 *
 * @param[in]	conn - The connnection handle
 * @param[in]	obj  - The job object to save
 * @param[in]	savetype - PBS_UPDATE_DB_QUICK/PBS_UPDATE_DB_FULL/PBS_INSERT_DB
 *
 * @return      Error code
 * @retval	-1 - Execution of prepared statement failed
 * @retval	 0 - Success and > 0 rows were affected
 * @retval	 1 - Execution succeeded but statement did not affect any rows
 *
 */
int
pg_db_save_job(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj, int savetype)
{
	char *stmt;
	pbs_db_job_info_t *pjob = obj->pbs_db_un.pbs_db_job;
	int params;
	int rc;
	char *raw_array = NULL;

	SET_PARAM_STR(conn, pjob->ji_jobid, 0);
	SET_PARAM_INTEGER(conn, pjob->ji_state, 1);
	SET_PARAM_INTEGER(conn, pjob->ji_substate, 2);
	SET_PARAM_INTEGER(conn, pjob->ji_svrflags, 3);
	SET_PARAM_INTEGER(conn, pjob->ji_numattr, 4);
	SET_PARAM_INTEGER(conn, pjob->ji_ordering, 5);
	SET_PARAM_INTEGER(conn, pjob->ji_priority, 6);
	SET_PARAM_BIGINT(conn, pjob->ji_stime, 7);
	SET_PARAM_BIGINT(conn, pjob->ji_endtBdry, 8);
	SET_PARAM_STR(conn, pjob->ji_queue, 9);
	SET_PARAM_STR(conn, pjob->ji_destin, 10);
	SET_PARAM_INTEGER(conn, pjob->ji_un_type, 11);
	SET_PARAM_BIGINT(conn, pjob->ji_momaddr, 12);
	SET_PARAM_INTEGER(conn, pjob->ji_momport, 13);
	SET_PARAM_INTEGER(conn, pjob->ji_exitstat, 14);
	SET_PARAM_BIGINT(conn, pjob->ji_quetime, 15);
	SET_PARAM_BIGINT(conn, pjob->ji_rteretry, 16);
	SET_PARAM_INTEGER(conn, pjob->ji_fromsock, 17);
	SET_PARAM_BIGINT(conn, pjob->ji_fromaddr, 18);
	SET_PARAM_STR(conn, pjob->ji_4jid, 19);
	SET_PARAM_STR(conn, pjob->ji_4ash, 20);
	SET_PARAM_INTEGER(conn, pjob->ji_credtype, 21);
	SET_PARAM_INTEGER(conn, pjob->ji_qrank, 22);

	if (savetype == PBS_UPDATE_DB_QUICK) {
		params = 23;
	} else {
		int len = 0;
		/* convert attributes to postgres raw array format */
		if ((len = convert_db_attr_list_to_array(&raw_array, &pjob->attr_list)) <= 0)
			return -1;

		SET_PARAM_BIN(conn, raw_array, len, 23);
		params = 24;
	}

	if (savetype == PBS_UPDATE_DB_FULL)
		stmt = STMT_UPDATE_JOB;
	else if (savetype == PBS_UPDATE_DB_QUICK)
		stmt = STMT_UPDATE_JOB_QUICK;
	else
		stmt = STMT_INSERT_JOB;

	rc = pg_db_cmd(conn, stmt, params);

	free(raw_array);

	return rc;
}
コード例 #4
0
ファイル: db_postgres_sched.c プロジェクト: A9-William/pbspro
/**
 * @brief
 *	Update scheduler data into the database
 *
 * @param[in]	conn - Connection handle
 * @param[in]	obj  - Information of scheduler to be updated
 *
 * @return      Error code
 * @retval	-1 - Failure
 * @retval	 0 - Success
 * @retval	 1 - Success but no rows updated
 */
int
pg_db_update_sched(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj)
{
	pbs_db_sched_info_t *psch = obj->pbs_db_un.pbs_db_sched;

	LOAD_STR(conn, psch->sched_name, 0);
	LOAD_STR(conn, psch->sched_sv_name, 1);

	return (pg_db_cmd(conn, STMT_UPDATE_SCHED, 2));
}
コード例 #5
0
ファイル: db_postgres_sched.c プロジェクト: A9-William/pbspro
/**
 * @brief
 *	Insert scheduler data into the database
 *
 * @param[in]	conn - Connection handle
 * @param[in]	obj  - Information of scheduler to be inserted
 *
 * @return      Error code
 * @retval	-1 - Failure
 * @retval	 0 - Success
 *
 */
int
pg_db_insert_sched(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj)
{
	pbs_db_sched_info_t *psch = obj->pbs_db_un.pbs_db_sched;

	LOAD_STR(conn, psch->sched_name, 0);
	LOAD_STR(conn, psch->sched_sv_name, 1);

	if (pg_db_cmd(conn, STMT_INSERT_SCHED, 2) != 0)
		return -1;

	return 0;
}
コード例 #6
0
ファイル: db_postgres_svr.c プロジェクト: A9-William/pbspro
/**
 * @brief
 *	Update server data into the database
 *
 * @param[in]	conn - Connection handle
 * @param[in]	obj  - Information of server to be updated
 *
 * @return      Error code
 * @retval	-1 - Failure
 * @retval	 0 - Success
 * @retval	 1 - Success but no rows updated
 *
 */
int
pg_db_update_svr(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj)
{
	pbs_db_svr_info_t *ps = obj->pbs_db_un.pbs_db_svr;

	LOAD_STR(conn, ps->sv_name, 0);
	LOAD_STR(conn, ps->sv_hostname, 1);
	LOAD_INTEGER(conn, ps->sv_numjobs, 2);
	LOAD_INTEGER(conn, ps->sv_numque, 3);
	LOAD_INTEGER(conn, ps->sv_jobidnumber, 4);
	LOAD_BIGINT(conn, ps->sv_svraddr, 5);
	LOAD_INTEGER(conn, ps->sv_svrport, 6);

	return (pg_db_cmd(conn, STMT_UPDATE_SVR, 7));
}
コード例 #7
0
ファイル: db_postgres_svr.c プロジェクト: A9-William/pbspro
/**
 * @brief
 *	Insert server data into the database
 *
 * @param[in]	conn - Connection handle
 * @param[in]	obj  - Information of server to be inserted
 *
 * @return      Error code
 * @retval	-1 - Failure
 * @retval	 0 - Success
 *
 */
int
pg_db_insert_svr(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj)
{
	pbs_db_svr_info_t *ps = obj->pbs_db_un.pbs_db_svr;

	LOAD_STR(conn, ps->sv_name, 0);
	LOAD_STR(conn, ps->sv_hostname, 1);
	LOAD_INTEGER(conn, ps->sv_numjobs, 2);
	LOAD_INTEGER(conn, ps->sv_numque, 3);
	LOAD_INTEGER(conn, ps->sv_jobidnumber, 4);
	LOAD_BIGINT(conn, ps->sv_svraddr, 5);
	LOAD_INTEGER(conn, ps->sv_svrport, 6);

	if (pg_db_cmd(conn, STMT_INSERT_SVR, 7) != 0)
		return -1;

	return 0;
}
コード例 #8
0
/**
 * @brief
 *	Deletes attributes of a job
 *
 * @param[in]	conn - Connection handle
 * @param[in]	obj  - Job information
 * @param[in]	obj_id  - Job id
 * @param[in]	attr_list - List of attributes
 *
 * @return      Error code
 * @retval	 0 - Success
 * @retval	-1 - On Failure
 *
 */
int
pg_db_del_attr_job(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj, void *obj_id, pbs_db_attr_list_t *attr_list)
{
	char *raw_array = NULL;
	int len = 0;

	if ((len = convert_db_attr_list_to_array(&raw_array, attr_list)) <= 0)
		return -1;
	SET_PARAM_STR(conn, obj_id, 0);

	SET_PARAM_BIN(conn, raw_array, len, 1);

	if (pg_db_cmd(conn, STMT_REMOVE_JOBATTRS, 2) != 0)
		return -1;

	free(raw_array);

	return 0;
}
コード例 #9
0
/**
 * @brief
 *	Insert job script
 *
 * @param[in]	conn - Connection handle
 * @param[in]	obj  - Job script object
 * @param[in]	savetype - Just a place holder here. Maintained the same prototype as with
 * 		           the other database save functions since this is called through function pointer.
 *
 * @return      Error code
 * @retval	-1 - Failure
 * @retval	 0 - Success
 *
 */
int
pg_db_save_jobscr(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj, int savetype)
{
	pbs_db_jobscr_info_t *pscr = obj->pbs_db_un.pbs_db_jobscr;

	SET_PARAM_STR(conn, pscr->ji_jobid, 0);

	/*
	 * The script data could contain non-UTF8 characters. We therefore
	 * consider it binary and encode it into TEXT by using the "encode"
	 * sql function. The input data to load, therefore, is binary data
	 * and so we use the function "LOAD_BIN" to load the parameter to
	 * the prepared statement
	 */
	SET_PARAM_BIN(conn, pscr->script, (pscr->script)?strlen(pscr->script):0, 1);

	if ((pg_db_cmd(conn, STMT_INSERT_JOBSCR, 2)) != 0)
		return -1;

	return 0;
}