예제 #1
0
#!/usr/bin/python

import sdetools
import sde_int_api

sdetools.set_api_connector(sde_int_api.InternalAPI)

sdetools.call('api_proxy', {'api_func': 'get_applications'})
예제 #2
0
    def handle(self):
        self.validate_configuration()
        self.sde_connect()

        logger.info("Retrieving connection details")

        connections = self.get_connections()

        logger.info("Found %s connections, starting local execution" % len(connections))

        successful_job_count = 0
        failed_jobs = []
        jobs_with_warnings = []

        filtered_connections = self.filter_connections(connections)
        logger.info("Filtered out %s connections" % (len(connections) - len(filtered_connections)))
        logger.info("Running %s jobs" % len(filtered_connections))

        for connection in filtered_connections:
            command = connection["command"]

            # Check whether this command exists
            if command not in self.config.command_list:
                failed_jobs.append(connection["id"])
                logger.error("No such command %s" % command)
                continue

            params = connection["params"]

            # Set the credentials and method with which to connect to SDE
            # - This isn't sent from the server
            params["sde_api_token"] = self.config["sde_api_token"]
            params["sde_method"] = self.config["sde_method"]

            for key in self.config["command_params"]:
                params[key] = self.config["command_params"][key]

            connection_id = connection["id"]
            connection_type = connection["type"]
            connection_name = connection["alias"]
            connection_combo_id = connection_type + "-" + str(connection_id)

            msg = "Running job with Connection Id: %s, Name: %s, Type: %s"
            logger.info(msg % (connection_id, connection_name, connection_type))

            logger.debug(" + Args: %s" % str(params))

            exit_status = sdetools.call(
                command,
                options=params,
                call_back=self.on_job_complete,
                call_back_args={"connection_combo_id": connection_combo_id},
            )
            if not exit_status:
                failed_jobs.append(connection_combo_id)
            else:
                successful_job_count += 1

            try:
                self.api.update_job_status(
                    connection_id, exit_status, self.job_return_logs[connection_combo_id].msg, connection_type
                )
            except APIError as e:
                jobs_with_warnings.append(connection_combo_id)
                logger.warn(
                    "Could not update job status on server for %s connection id %d: %s"
                    % (connection_type, connection_id, e)
                )

        logger.info("%s jobs completed successfully, %s failed" % (successful_job_count, len(failed_jobs)))

        if failed_jobs:
            logger.error("Failed job(s) by connection id: %s" % ", ".join(failed_jobs))

        if jobs_with_warnings:
            warn_msg = "Connection id(s) of job(s) whose status could not be updated on the server: %s"
            logger.warn(warn_msg % ", ".join(jobs_with_warnings))

        return True
예제 #3
0
#!/usr/bin/env python

import sdetools
import sde_int_api

sdetools.set_api_connector(sde_int_api.InternalAPI)

sdetools.call("api_proxy", {"api_func": "get_applications"})