21 char* commitHash =
fo_sysconfig(AGENT_NAME,
"COMMIT_HASH");
24 if (!commitHash || !version)
26 LOG_FATAL(
"Reuser: fo_sysconfig returned NULL for VERSION or COMMIT_HASH.");
30 char* revision =
nullptr;
31 if (asprintf(&revision,
"%s.%s", version, commitHash) < 0)
33 LOG_FATAL(
"Reuser: asprintf failed allocating revision string.");
38 AGENT_NAME, 0, revision, AGENT_DESC);
51 state.getAgentId(), AGENT_ARS,
nullptr, success);
54 void bail(
int exitval)
68 for (
const auto& triple : reusedUploads)
74 LOG_WARNING(
"Reuser: could not determine parent bounds for reused"
75 " upload %d, skipping.", triple.reusedUploadId);
79 if (triple.reuseMode & REUSE_ENHANCED)
82 uploadId, triple.reusedUploadId,
83 groupId, triple.reusedGroupId, userId))
89 uploadId, triple.reusedUploadId,
90 groupId, triple.reusedGroupId, userId))
96 if (triple.reuseMode & REUSE_MAIN)
99 triple.reusedUploadId, triple.reusedGroupId))
100 LOG_WARNING(
"Reuser: reuseMainLicense failed for upload %d"
101 " (reused %d), continuing.",
102 uploadId, triple.reusedUploadId);
105 if (triple.reuseMode & REUSE_CONF)
108 LOG_WARNING(
"Reuser: reuseConfSettings failed for upload %d"
109 " (reused %d), continuing.",
110 uploadId, triple.reusedUploadId);
113 if (triple.reuseMode & REUSE_COPYRIGHT)
117 LOG_WARNING(
"Reuser: reuseCopyrights failed for upload %d"
118 " (reused %d), continuing.",
119 uploadId, triple.reusedUploadId);
bool processUploadId(const CompatibilityState &state, int uploadId, CompatibilityDatabaseHandler &databaseHandler, int groupId)
CompatibilityState getState(DbManager &dbManager, CompatibilityCliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
int writeARS(const CompatibilityState &state, int arsId, int uploadId, int success, DbManager &dbManager)
int queryAgentId(DbManager &dbManager)
Query and register the agent id. Bails on failure.
void bail(int exitval)
Disconnect scheduler and exit.
Database handler for the reuser agent.
virtual bool processUploadReuse(int uploadId, int reusedUploadId, int groupId, int reusedGroupId, int userId)
virtual bool getParentItemBounds(int uploadId, ItemTreeBounds &out)
Fetch the parent item bounds for a given upload.
virtual bool reuseMainLicense(int uploadId, int groupId, int reusedUploadId, int reusedGroupId)
virtual bool processEnhancedUploadReuse(int uploadId, int reusedUploadId, int groupId, int reusedGroupId, int userId)
virtual bool reuseCopyrights(int uploadId, int reusedUploadId, int userId)
virtual std::vector< ReuseTriple > getReusedUploads(int uploadId, int groupId)
Return the list of uploads that should be reused for uploadId.
virtual bool reuseConfSettings(int uploadId, int reusedUploadId)
Holds the runtime state of the reuser agent (agent id).
FUNCTION int fo_WriteARS(PGconn *pgConn, int ars_pk, int upload_pk, int agent_pk, const char *tableName, const char *ars_status, int ars_success)
Write ars record.
FUNCTION int fo_GetAgentKey(PGconn *pgConn, const char *agent_name, long Upload_pk, const char *rev, const char *agent_desc)
Get the latest enabled agent key (agent_pk) from the database.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
int fo_scheduler_groupID()
Gets the id of the group that created the job that the agent is running.
fo_dbManager * dbManager
fo_dbManager object
fo namespace holds the FOSSology library functions.
Bounds of an item within an uploadtree table.