def _get_node_lookup(revision_id):
    # get a Drydock node_lookup function using the supplied revision_id

    return NodeLookup(
        service_clients.drydock_client(),
        DesignRefHelper().get_design_reference_dict(revision_id)
    ).lookup
Example #2
0
    def _get_validations_from_ucp_components(self, revision_id):
        """Invoke other UCP components to retrieve their validations"""
        resp_msgs = []
        error_count = 0
        design_ref = DesignRefHelper().get_design_reference(revision_id)

        validation_threads = _get_validation_threads(
            _get_validation_endpoints(), self.ctx, design_ref)
        # trigger each validation in parallel
        for validation_thread in validation_threads:
            if validation_thread.get('thread'):
                validation_thread.get('thread').start()
        # wait for all validations to return
        for validation_thread in validation_threads:
            validation_thread.get('thread').join()

        # check on the response, extract the validations
        for validation_thread in validation_threads:
            th_name = validation_thread.get('name')
            val_response = validation_thread.get('response',
                                                 {}).get('response')
            LOG.debug("Validation from:  %s response: %s", th_name,
                      str(val_response))
            if validation_thread.get('exception', {}).get('exception'):
                LOG.error('Invocation of validation by %s has failed', th_name)
            # invalid status needs collection of messages
            # valid status means that it passed. No messages to collect
            if val_response.get('details') is None:
                msg_list = [{'message': str(val_response), 'error': True}]
            else:
                msg_list = val_response.get('details').get('messageList', [])
            for msg in msg_list:
                # Count errors, convert message to ValidationMessage
                default_level = 'Info'
                if msg.get('error'):
                    error_count = error_count + 1
                    default_level = 'Error'
                val_msg = _generate_validation_message(msg,
                                                       level=default_level,
                                                       source=th_name)
                resp_msgs.append(val_msg)
        return (error_count, resp_msgs)
Example #3
0
def get_deployment_status(action, force_completed=False):
    """Given a set of action data, make/return a set of deployment status data

    :param dict action: A dictionary of data about an action.
                        The keys of the dict should include:
                            - committed_rev_id
                            - context_marker
                            - dag_status
                            - id
                            - timestamp
                            - user
                        Any missing key will result in a piece of the
                        deployment status being "unknown"
    :param bool force_completed: optional. If True the status will be forced
                                 to "completed". This will be useful when the
                                 last step of the DAG wants to get the status
                                 of the deployment, and knows that the
                                 DAG/deployment/action really is completed even
                                 though it does not appear to be.
    :returns: A dict of deployment status data
    :rtype: dict
    """
    # Create a URL to get the documents in Deckhand, using the Deckhand
    # revision ID associated with the action
    document_url = DesignRefHelper().get_design_reference_href(
        action.get('committed_rev_id', 'unknown'))

    # Create the "status" and "result" of the deployment
    dag_status = action.get('dag_status', '').upper()
    status = 'running'
    result = 'unknown'
    status_result_map = {
        'FAILED': 'failed',
        'UPSTREAM_FAILED': 'failed',
        'SKIPPED': 'failed',
        'REMOVED': 'failed',
        'SHUTDOWN': 'failed',
        'SUCCESS': 'successful'
    }
    if dag_status in status_result_map:
        # We don't need to check anything else, we know the status of the
        # deployment is completed and we can map directly to a result
        status = 'completed'
        result = status_result_map[dag_status]
    else:
        # The DAG could still be running, or be in some other state, so we
        # need to dig into the DAG to determine what the result really is
        # Use an ActionsHelper to check all the DAG steps
        helper = ActionsHelper(action.get('id'))
        result = helper.get_result_from_dag_steps()

    # Check to see if we need to override the status to "completed"
    if force_completed:
        status = "completed"

    # Return the dictionary of data
    return {
        'status': status,
        'results': result,
        'context-marker': action.get('context_marker', 'unknown'),
        'action': action.get('id', 'unknown'),
        'document_url': document_url,
        'user': action.get('user', 'unknown'),
        'date': action.get('timestamp', 'unknown')
    }