Ejemplo n.º 1
0
    def armada_base(self, context):

        # Define task_instance
        self.task_instance = context['task_instance']

        # Set up and retrieve values from xcom
        self.xcom_puller = XcomPuller(self.main_dag_name, self.task_instance)
        self.action_info = self.xcom_puller.get_action_info()
        self.dc = self.xcom_puller.get_deployment_configuration()

        # Set up xcom_pusher to push values to xcom
        self.xcom_pusher = XcomPusher(self.task_instance)

        # Logs uuid of action performed by the Operator
        logging.info("Armada Operator for action %s", self.action_info['id'])

        # Retrieve Endpoint Information
        armada_svc_endpoint = ucp_service_endpoint(
            self, svc_type=self.armada_svc_type)

        # Set up armada client
        self.armada_client = self._init_armada_client(armada_svc_endpoint,
                                                      self.svc_token)

        # Retrieve DeckHand Endpoint Information
        deckhand_svc_endpoint = ucp_service_endpoint(
            self, svc_type=self.deckhand_svc_type)

        # Retrieve last committed revision id
        committed_revision_id = self.xcom_puller.get_design_version()

        # Get deckhand design reference url
        self.deckhand_design_ref = self._init_deckhand_design_ref(
            deckhand_svc_endpoint, committed_revision_id)
Ejemplo n.º 2
0
    def execute(self, context):

        # Initialize variable
        ucp_components = [
            service_endpoint.ARMADA,
            service_endpoint.DECKHAND,
            service_endpoint.DRYDOCK,
            service_endpoint.PROMENADE,
            service_endpoint.SHIPYARD
        ]

        # Define task_instance
        self.task_instance = context['task_instance']

        # Set up and retrieve values from xcom
        self.xcom_puller = XcomPuller(self.main_dag_name, self.task_instance)
        self.action_info = self.xcom_puller.get_action_info()

        # Set up xcom_pusher to push values to xcom
        self.xcom_pusher = XcomPusher(self.task_instance)

        # Loop through various Airship Components
        for component in ucp_components:

            # Retrieve Endpoint Information
            endpoint = self.endpoints.endpoint_by_name(component)
            LOG.info("%s endpoint is %s", component, endpoint)

            # Construct Health Check Endpoint
            healthcheck_endpoint = os.path.join(endpoint,
                                                'health')

            try:
                LOG.info("Performing Health Check on %s at %s", component,
                         healthcheck_endpoint)
                # Set health check timeout to 30 seconds
                req = requests.get(healthcheck_endpoint, timeout=30)

                # An empty response/body returned by a component means
                # that it is healthy
                if req.status_code == 204:
                    LOG.info("%s is alive and healthy", component)

            except requests.exceptions.RequestException as e:
                self.log_health_exception(component, e)
Ejemplo n.º 3
0
    def execute(self, context):

        # Initialize variable
        ucp_components = [
            'armada', 'deckhand', 'kubernetesprovisioner',
            'physicalprovisioner', 'shipyard'
        ]

        # Define task_instance
        self.task_instance = context['task_instance']

        # Set up and retrieve values from xcom
        self.xcom_puller = XcomPuller(self.main_dag_name, self.task_instance)
        self.action_info = self.xcom_puller.get_action_info()

        # Set up xcom_pusher to push values to xcom
        self.xcom_pusher = XcomPusher(self.task_instance)

        # Loop through various UCP Components
        for component in ucp_components:

            # Retrieve Endpoint Information
            service_endpoint = ucp_service_endpoint(self, svc_type=component)
            LOG.info("%s endpoint is %s", component, service_endpoint)

            # Construct Health Check Endpoint
            healthcheck_endpoint = os.path.join(service_endpoint, 'health')

            LOG.info("%s healthcheck endpoint is %s", component,
                     healthcheck_endpoint)

            try:
                LOG.info("Performing Health Check on %s", component)
                # Set health check timeout to 30 seconds
                req = requests.get(healthcheck_endpoint, timeout=30)

                # An empty response/body returned by a component means
                # that it is healthy
                if req.status_code == 204:
                    LOG.info("%s is alive and healthy", component)

            except requests.exceptions.RequestException as e:
                self.log_health_exception(component, e)
    def run_base(self, context):

        # Set up xcom_pusher to push values to xcom
        self.xcom_pusher = XcomPusher(self.task_instance)

        # Logs uuid of action performed by the Operator
        LOG.info("Armada Operator for action %s", self.action_id)

        # Set up armada client
        self.armada_client = self._init_armada_client(
            self.endpoints.endpoint_by_name(service_endpoint.ARMADA),
            self.svc_token, self.context_marker, self.user)
Ejemplo n.º 5
0
    def run_base(self, context):

        # Set up xcom_pusher to push values to xcom
        self.xcom_pusher = XcomPusher(self.task_instance)

        # Logs uuid of action performed by the Operator
        LOG.info("Armada Operator for action %s", self.action_id)

        # Set up armada client
        self.armada_client = self._init_armada_client(
            self.endpoints.endpoint_by_name(service_endpoint.ARMADA),
            self.svc_token)

        # Retrieve Tiller Information
        # TODO(@drewwalters96): This should be explicit. Refactor in
        # conjunction with `get_pod_port_ip` decorator.
        self.get_tiller_info(pods_ip_port={})
Ejemplo n.º 6
0
    def run_base(self, context):

        # Set up xcom_pusher to push values to xcom
        self.xcom_pusher = XcomPusher(self.task_instance)

        # Logs uuid of action performed by the Operator
        LOG.info("Armada Operator for action %s", self.action_info['id'])

        # Retrieve Endpoint Information
        armada_svc_endpoint = ucp_service_endpoint(
            self, svc_type=self.armada_svc_type)

        # Set up armada client
        self.armada_client = self._init_armada_client(armada_svc_endpoint,
                                                      self.svc_token)

        # Retrieve DeckHand Endpoint Information
        deckhand_svc_endpoint = ucp_service_endpoint(
            self, svc_type=self.deckhand_svc_type)

        # Get deckhand design reference url
        self.deckhand_design_ref = self._init_deckhand_design_ref(
            deckhand_svc_endpoint)
Ejemplo n.º 7
0
class UcpHealthCheckOperator(BaseOperator):
    """
    Airship Health Checks
    """

    @apply_defaults
    def __init__(self,
                 shipyard_conf=None,
                 main_dag_name=None,
                 xcom_push=True,
                 *args,
                 **kwargs):

        super(UcpHealthCheckOperator, self).__init__(*args, **kwargs)
        self.shipyard_conf = shipyard_conf
        self.main_dag_name = main_dag_name
        self.xcom_push_flag = xcom_push
        self.endpoints = service_endpoint.ServiceEndpoints(self.shipyard_conf)

    def execute(self, context):

        # Initialize variable
        ucp_components = [
            service_endpoint.ARMADA,
            service_endpoint.DECKHAND,
            service_endpoint.DRYDOCK,
            service_endpoint.PROMENADE,
            service_endpoint.SHIPYARD
        ]

        # Define task_instance
        self.task_instance = context['task_instance']

        # Set up and retrieve values from xcom
        self.xcom_puller = XcomPuller(self.main_dag_name, self.task_instance)
        self.action_info = self.xcom_puller.get_action_info()

        # Set up xcom_pusher to push values to xcom
        self.xcom_pusher = XcomPusher(self.task_instance)

        # Loop through various Airship Components
        for component in ucp_components:

            # Retrieve Endpoint Information
            endpoint = self.endpoints.endpoint_by_name(component)
            LOG.info("%s endpoint is %s", component, endpoint)

            # Construct Health Check Endpoint
            healthcheck_endpoint = os.path.join(endpoint,
                                                'health')

            try:
                LOG.info("Performing Health Check on %s at %s", component,
                         healthcheck_endpoint)
                # Set health check timeout to 30 seconds
                req = requests.get(healthcheck_endpoint, timeout=30)

                # An empty response/body returned by a component means
                # that it is healthy
                if req.status_code == 204:
                    LOG.info("%s is alive and healthy", component)

            except requests.exceptions.RequestException as e:
                self.log_health_exception(component, e)

    def log_health_exception(self, component, error_messages):
        """Logs Exceptions for health check
        """
        # If Drydock health check fails and continue-on-fail, continue
        # and create xcom key 'drydock_continue_on_fail'
        # Note that 'update_software' does not interact with Drydock, and
        # therefore does not use the continue-on-fail option.
        if (component == service_endpoint.DRYDOCK and
                self.action_info['parameters'].get(
                    'continue-on-fail', 'false').lower() == 'true' and
                self.action_info['dag_id'] in ['update_site', 'deploy_site']):
            LOG.warning('Drydock did not pass health check. Continuing '
                        'as "continue-on-fail" option is enabled.')
            self.xcom_pusher.xcom_push(key='drydock_continue_on_fail',
                                       value=True)

        else:
            LOG.error(error_messages)
            raise AirflowException("Health check failed for %s component on "
                                   "dag_id=%s. Details: %s" %
                                   (component, self.action_info.get('dag_id'),
                                    error_messages))
Ejemplo n.º 8
0
class UcpHealthCheckOperator(BaseOperator):
    """
    UCP Health Checks
    """
    @apply_defaults
    def __init__(self,
                 shipyard_conf=None,
                 main_dag_name=None,
                 xcom_push=True,
                 *args,
                 **kwargs):

        super(UcpHealthCheckOperator, self).__init__(*args, **kwargs)
        self.shipyard_conf = shipyard_conf
        self.main_dag_name = main_dag_name
        self.xcom_push_flag = xcom_push

    def execute(self, context):

        # Initialize variable
        ucp_components = [
            'armada', 'deckhand', 'kubernetesprovisioner',
            'physicalprovisioner', 'shipyard'
        ]

        # Define task_instance
        self.task_instance = context['task_instance']

        # Set up and retrieve values from xcom
        self.xcom_puller = XcomPuller(self.main_dag_name, self.task_instance)
        self.action_info = self.xcom_puller.get_action_info()

        # Set up xcom_pusher to push values to xcom
        self.xcom_pusher = XcomPusher(self.task_instance)

        # Loop through various UCP Components
        for component in ucp_components:

            # Retrieve Endpoint Information
            service_endpoint = ucp_service_endpoint(self, svc_type=component)
            LOG.info("%s endpoint is %s", component, service_endpoint)

            # Construct Health Check Endpoint
            healthcheck_endpoint = os.path.join(service_endpoint, 'health')

            LOG.info("%s healthcheck endpoint is %s", component,
                     healthcheck_endpoint)

            try:
                LOG.info("Performing Health Check on %s", component)
                # Set health check timeout to 30 seconds
                req = requests.get(healthcheck_endpoint, timeout=30)

                # An empty response/body returned by a component means
                # that it is healthy
                if req.status_code == 204:
                    LOG.info("%s is alive and healthy", component)

            except requests.exceptions.RequestException as e:
                self.log_health_exception(component, e)

    def log_health_exception(self, component, error_messages):
        """Logs Exceptions for health check
        """
        # If Drydock health check fails and continue-on-fail, continue
        # and create xcom key 'drydock_continue_on_fail'
        if (component == 'physicalprovisioner' and
                self.action_info['parameters'].get('continue-on-fail').lower()
                == 'true' and self.action_info['dag_id']
                in ['update_site', 'deploy_site']):
            LOG.warning('Drydock did not pass health check. Continuing '
                        'as "continue-on-fail" option is enabled.')
            self.xcom_pusher.xcom_push(key='drydock_continue_on_fail',
                                       value=True)

        else:
            LOG.error(error_messages)
            raise AirflowException(
                "Health check failed for %s component on "
                "dag_id=%s. Details: %s" %
                (component, self.action_info.get('dag_id'), error_messages))