What are fossology Agents and modify or create a schema in fossolgy application

Agents in FOSSology

In FOSSology Agents are used to perform analysis, statistics, or management tasks related to anything in the database. The best practice is each agent performs one task, you should not overload agent functionality. For three different tasks, three different agents should be created. The agents play a crucial part in FOSSology project. A various task like unpacking, copyright searching, license listing etc. are done through agents in FOSSology. In simple words, agents are nothing the functionality through which the tasks are being performed. In FOSSology you can write the agents in PHP, c or in python. My task is to integrate Software Heritage in fossology. Software Heritage is an open-source platform which holds the records of various files that are hosted on the web. My job is to fetch the origins of the files of a package from software heritage and store it in the fossology DB. In this topic, I am going to discuss the shema structure of software_heritage table and what each attribute is going to store.

Database Structure for Software Heritage

You can view the database structure in the below table definition. Also, I am going to give a brief description in fossology how are you going to add a new database schema.

Table Structure

Column Type Modifiers
Software_heritage_pk integer not null default nextval('software_heritage_pk_seq'::regclass)
Pfile_fk integer not null
License text
Origin text
Foreign-key constraints:
    "software_heritage_pfile_fk_fkey" FOREIGN KEY (pfile_fk) REFERENCES pfile(pfile_pk) ON DELETE CASCADE

As you can see here the primary key is software_heritage_pk, pfile_fk is the foreign key and other two columns license and origin holds the records from the software heritage.

Developer Section

How the make the changes in fossology project There is a core-schema.dat which is situated in the directory of fossology/src/www/ui/core-schema.dat you need to add the basic functionality of the table to make the table in fossology. You don't need to create the table explicitly. You just need to add the basic structure of the table. The fossology will do everything by itself. I will tell you the installation process through a vagrant configuration or in a virtual box configuration. The database configuration contains three steps

  • Defining the table structure
  • Creating a sequence for the primary key
  • Add the foreigin key constraint.

You can refer to my own code or other code from the core-shema.dat file.

Defining the table structure

$Schema["TABLE"]["software_heritage"]["software_heritage_pk"]["DESC"] = "";
$Schema["TABLE"]["software_heritage"]["software_heritage_pk"]["ADD"] = "ALTER TABLE \"software_heritage\" ADD COLUMN \"software_heritage_pk\" int4 DEFAULT nextval('software_heritage_pk_seq'::regclass)";
$Schema["TABLE"]["software_heritage"]["software_heritage_pk"]["ALTER"] = "ALTER TABLE \"software_heritage\" ALTER COLUMN \"software_heritage_pk\" SET NOT NULL, ALTER COLUMN \"software_heritage_pk\" SET DEFAULT nextval('software_heritage_pk_seq'::regclass)";

$Schema["TABLE"]["software_heritage"]["pfile_fk"]["DESC"] = "";
$Schema["TABLE"]["software_heritage"]["pfile_fk"]["ADD"] = "ALTER TABLE \"software_heritage\" ADD COLUMN \"pfile_fk\" int4";
$Schema["TABLE"]["software_heritage"]["pfile_fk"]["ALTER"] = "ALTER TABLE \"software_heritage\" ALTER COLUMN \"pfile_fk\" SET NOT NULL";

$Schema["TABLE"]["software_heritage"]["license"]["DESC"] = "";
$Schema["TABLE"]["software_heritage"]["license"]["ADD"] = "ALTER TABLE \"software_heritage\" ADD COLUMN \"license\" text";
$Schema["TABLE"]["software_heritage"]["license"]["ALTER"] = "ALTER TABLE \"software_heritage\" ALTER COLUMN \"license\" DROP NOT NULL";

$Schema["TABLE"]["software_heritage"]["origin"]["DESC"] = "";
$Schema["TABLE"]["software_heritage"]["origin"]["ADD"] = "ALTER TABLE \"software_heritage\" ADD COLUMN \"origin\" text";
$Schema["TABLE"]["software_heritage"]["origin"]["ALTER"] = "ALTER TABLE \"software_heritage\" ALTER COLUMN \"origin\" DROP NOT NULL";

Defining the schema

$Schema["SEQUENCE"]["software_heritage_pk_seq"]["CREATE"]="CREATE SEQUENCE \"software_heritage_pk_seq\"";
$Schema["SEQUENCE"]["software_heritage_pk_seq"]["UPDATE"]="SELECT setval('software_heritage_pk_seq',(SELECT greatest(1,max(software_heritage_pk)) val FROM software_heritage))";

Foreign key constraint

$Schema["CONSTRAINT"]["software_heritage_pfile_fk_fkey"] = "ALTER TABLE \"software_heritage\" ADD CONSTRAINT \"software_heritage_pfile_fk_fkey\" FOREIGN KEY (\"pfile_fk\") REFERENCES \"pfile\" (\"pfile_pk\") ON UPDATE NO ACTION ON DELETE CASCADE;";

Run the changes

To run the changes you need to do the following steps

  • You need to go to the root directory of the fossolgy in the virtual engine
  • Do a sudo make install
  • Then sudo ./install/fo-postinstall

For now this much is enough. If you get to doubt the please inform me through the contact now section contact me

printf(“Happy!, Coding”);
printf(“Sandip”);