def execute(self):
        """Main Agent code:
      1.- Query BigDataDB for existing Running, Queue, or Submitted jobs
      2.- Ask about the status
      3.- Change the status into DB in the case of had changed
    """

        self.pendingJobs["Submitted"] = BigDataDB.getBigDataJobsByStatus("Submitted")
        self.pendingJobs["Running"] = BigDataDB.getBigDataJobsByStatus("Running")
        self.pendingJobs["Unknown"] = BigDataDB.getBigDataJobsByStatus("Unknown")

        self.__getMonitoringPools()
        self.log.verbose("monitoring pools", self.monitoringEndPoints)

        for status in self.pendingJobs:
            self.log.verbose("Analizing %s jobs" % status)
            JobStatus = 0
            if self.pendingJobs[status]["OK"]:
                for jobId in self.pendingJobs[status]["Value"]:
                    self.log.verbose("Analizing job %s" % jobId)
                    getSoftIdAndSiteName = BigDataDB.getSoftwareJobIDByJobID(jobId[0])
                    self.log.verbose("Site and SoftID:", getSoftIdAndSiteName)
                    for runningEndPoint in self.monitoringEndPoints:
                        if (self.monitoringEndPoints[runningEndPoint]["NameNode"] == getSoftIdAndSiteName[0][1]) and (
                            getSoftIdAndSiteName[0][0] != ""
                        ):
                            # Depending on the BigData Software the Query should be different
                            if self.monitoringEndPoints[runningEndPoint]["BigDataSoftware"] == "hadoop":
                                if self.monitoringEndPoints[runningEndPoint]["BigDataSoftwareVersion"] == "hdv1":
                                    if (
                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"]["HLLName"]
                                        == "none"
                                    ):
                                        self.log.info(
                                            "Hadoop V.1 Monitoring submmission command with Hadoop jobID: ",
                                            getSoftIdAndSiteName[0][0],
                                        )
                                        from BigDataDIRAC.WorkloadManagementSystem.Client.HadoopV1Client import (
                                            HadoopV1Client,
                                        )

                                        HadoopV1cli = HadoopV1Client(
                                            self.monitoringEndPoints[runningEndPoint]["User"],
                                            self.monitoringEndPoints[runningEndPoint]["PublicIP"],
                                            self.monitoringEndPoints[runningEndPoint]["Port"],
                                        )
                                        JobStatus = HadoopV1cli.jobStatus(
                                            getSoftIdAndSiteName[0][0],
                                            self.monitoringEndPoints[runningEndPoint]["User"],
                                            self.monitoringEndPoints[runningEndPoint]["PublicIP"],
                                        )
                                        if (JobStatus["OK"] == True) and (
                                            self.monitoringEndPoints[runningEndPoint]["IsInteractive"] == "1"
                                        ):
                                            if JobStatus["Value"][1].strip() == "Succeded":
                                                result = HadoopV1cli.newJob(
                                                    self.__tmpSandBoxDir, jobId[0], getSoftIdAndSiteName[0][0]
                                                )

                                                if result["OK"] == True:
                                                    result = BigDataDB.updateHadoopIDAndJobStatus(
                                                        jobId[0], result["Value"]
                                                    )
                                                    BigDataDB.setJobStatus(jobId[0], "Running")
                                                    JobStatus["OK"] = False
                                                else:
                                                    self.log.info("New result from new Job", result)
                                        if JobStatus["OK"] == True:
                                            if JobStatus["Value"][1].strip() == "Succeded":
                                                BigDataDB.setJobStatus(jobId[0], "Done")
                                                if self.monitoringEndPoints[runningEndPoint]["IsInteractive"] == "1":
                                                    self.__updateInteractiveSandBox(
                                                        jobId[0],
                                                        self.monitoringEndPoints[runningEndPoint]["BigDataSoftware"],
                                                        self.monitoringEndPoints[runningEndPoint][
                                                            "BigDataSoftwareVersion"
                                                        ],
                                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"][
                                                            "HLLName"
                                                        ],
                                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"][
                                                            "HLLVersion"
                                                        ],
                                                        HadoopV1cli,
                                                    )
                                                else:
                                                    self.__updateSandBox(
                                                        jobId[0],
                                                        self.monitoringEndPoints[runningEndPoint]["BigDataSoftware"],
                                                        self.monitoringEndPoints[runningEndPoint][
                                                            "BigDataSoftwareVersion"
                                                        ],
                                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"][
                                                            "HLLName"
                                                        ],
                                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"][
                                                            "HLLVersion"
                                                        ],
                                                        HadoopV1cli,
                                                    )
                                                getStatus = HadoopV1cli.jobCompleteStatus(getSoftIdAndSiteName[0][0])
                                                if getStatus["OK"]:
                                                    result = self.getJobFinalStatusInfo(getStatus["Value"][1])
                                                if result["OK"]:
                                                    self.sendJobAccounting(result["Value"], jobId[0])
                                                if self.cleanDataAfterFinish:
                                                    self.__deleteData(jobId[0], HadoopV1cli)
                                            if JobStatus["Value"][1].strip() == "Unknown":
                                                BigDataDB.setJobStatus(jobId[0], "Submitted")
                                            if JobStatus["Value"][1].strip() == "Running":
                                                BigDataDB.setJobStatus(jobId[0], "Running")

                            if self.monitoringEndPoints[runningEndPoint]["BigDataSoftware"] == "hadoop":
                                if self.monitoringEndPoints[runningEndPoint]["BigDataSoftwareVersion"] == "hdv2":
                                    if (
                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"]["HLLName"]
                                        == "none"
                                    ):
                                        self.log.info(
                                            "Hadoop V.2 Monitoring submmission command with Hadoop jobID: ",
                                            getSoftIdAndSiteName[0][0],
                                        )
                                        from BigDataDIRAC.WorkloadManagementSystem.Client.HadoopV2Client import (
                                            HadoopV2Client,
                                        )

                                        HadoopV2cli = HadoopV2Client(
                                            self.monitoringEndPoints[runningEndPoint]["User"],
                                            self.monitoringEndPoints[runningEndPoint]["PublicIP"],
                                        )
                                        JobStatus = HadoopV2cli.jobStatus(
                                            getSoftIdAndSiteName[0][0],
                                            self.monitoringEndPoints[runningEndPoint]["User"],
                                            self.monitoringEndPoints[runningEndPoint]["PublicIP"],
                                        )
                                        if (JobStatus["OK"] == True) and (
                                            self.monitoringEndPoints[runningEndPoint]["IsInteractive"] == "1"
                                        ):
                                            if JobStatus["Value"].strip() == "Succeded":
                                                result = HadoopV2cli.newJob(
                                                    self.__tmpSandBoxDir, jobId[0], getSoftIdAndSiteName[0][0]
                                                )

                                                if result["OK"] == True:
                                                    result = BigDataDB.updateHadoopIDAndJobStatus(
                                                        jobId[0], result["Value"]
                                                    )
                                                    BigDataDB.setJobStatus(jobId[0], "Running")
                                                    JobStatus["OK"] = False
                                                else:
                                                    self.log.info("New result from new Job", result)
                                        if JobStatus["OK"] == True:
                                            if JobStatus["Value"] == "Succeded":
                                                BigDataDB.setJobStatus(jobId[0], "Done")
                                                if self.monitoringEndPoints[runningEndPoint]["IsInteractive"] == "1":
                                                    self.__updateInteractiveSandBox(
                                                        jobId[0],
                                                        self.monitoringEndPoints[runningEndPoint]["BigDataSoftware"],
                                                        self.monitoringEndPoints[runningEndPoint][
                                                            "BigDataSoftwareVersion"
                                                        ],
                                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"][
                                                            "HLLName"
                                                        ],
                                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"][
                                                            "HLLVersion"
                                                        ],
                                                        HadoopV2cli,
                                                    )
                                                else:
                                                    self.__updateSandBox(
                                                        jobId[0],
                                                        self.monitoringEndPoints[runningEndPoint]["BigDataSoftware"],
                                                        self.monitoringEndPoints[runningEndPoint][
                                                            "BigDataSoftwareVersion"
                                                        ],
                                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"][
                                                            "HLLName"
                                                        ],
                                                        self.monitoringEndPoints[runningEndPoint]["HighLevelLanguage"][
                                                            "HLLVersion"
                                                        ],
                                                        HadoopV2cli,
                                                    )
                                                getStatus = HadoopV2cli.jobCompleteStatus(getSoftIdAndSiteName[0][0])
                                                if getStatus["OK"]:
                                                    result = self.getJobFinalStatusInfo(getStatus["Value"][1])
                                                if result["OK"]:
                                                    self.sendJobAccounting(result["Value"], jobId[0])
                                                # if self.cleanDataAfterFinish:
                                                #  self.__deleteData( jobId[0], HadoopV2cli )
                                            if JobStatus["Value"] == "Unknown":
                                                BigDataDB.setJobStatus(jobId[0], "Submitted")
                                            if JobStatus["Value"] == "Running":
                                                BigDataDB.setJobStatus(jobId[0], "Running")
        return DIRAC.S_OK()