summaryrefslogtreecommitdiffstats
path: root/src/main/resources
AgeCommit message (Expand)AuthorFilesLines
2019-04-26Fix policy Hostssebdet3-22/+29
2019-04-26Merge "Change Yaml to Json payload"Xue Gao1-1/+1
2019-04-26Merge "Clamp uses new Loop implementation by default"Sébastien Determe2-2/+4
2019-04-26Change Yaml to Json payloadsebdet1-1/+1
2019-04-26Rework the loggingsebdet2-470/+419
2019-04-25Fix policy callssebdet5-492/+576
2019-04-24Clamp uses new Loop implementation by
# ============LICENSE_START=======================================================
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.

# -*- coding: utf-8 -*-
"""
Provides utilities for undeploying components
"""
from functools import partial
from dcae_cli.util.exc import DcaeException
import dcae_cli.util.profiles as profiles
from dcae_cli.util.cdap_util import undeploy_component as undeploy_cdap_component
from dcae_cli.util.discovery import get_healthy_instances, get_defective_instances, \
        remove_config
from dcae_cli.util import docker_util as du
from dcae_cli.util.logger import get_logger


log = get_logger('Undeploy')


def _handler(undeploy_funcs, instances):
    """Handles the undeployment

    Executes all undeployment functions for all instances and gathers up the
    results. No short circuiting.

    Args
    ----
    undeploy_funcs: List of functions that have the following signature `fn: string->boolean`
        the input is a fully qualified instance name and the return is True upon
        success and False for failures
    instances: List of fully qualified instance names

    Returns
    -------
    (failures, results) where each are a list of tuples.  Each tuple has the
    structure: `(<instance name>, result of func 1, result of func 2, ..)`.
    """
    if not instances:
        return [], []

    # Invoke all undeploy funcs for all instances
    def invoke_undeploys(instance):
        return tuple([ undeploy_func(instance) for undeploy_func in undeploy_funcs ])

    results = [ (instance, ) + invoke_undeploys(instance) for instance in instances ]

    # Determine failures
    filter_failures_func = partial(filter, lambda result: not all(result[1:]))
    failures = list(filter_failures_func(results))

    return failures, results


def _handler_report(failures, results):
    """Reports the result of handling"""
    if len(failures) > 0:
        failed_names = [ result[0] for result in failures ]
        log.warn("Could not completely undeploy: {0}".format(", ".join(failed_names)))

        # This message captures a case where you are seeing a false negative. If
        # you attempted to undeploy a component instance and it partially failed
        # the first time but "succeeded" the second time, the second undeploy
        # would get reported as a failure. The second undeploy would probably
        # also be partial undeploy because the undeploy operation that succeeded
        # the first time will fail the second time.
        log.warn("NOTE: This could be expected since we are attempting to undeploy a component in a bad partial state")
    elif len(results) == 0:
        log.warn("No components found to undeploy")
    else:
        # This seems like important info so set it to warning so that it shows up
        log.warn("Undeplo
4-868/+851
2019-03-29Merge "Rework the submit operation"Sébastien Determe4-1/+25
2019-03-29Merge "Rework the UI"Sébastien Determe2-68/+21
2019-03-29Merge "Rework deploy/undeploy UI"Sébastien Determe7-184/+112
2019-03-29Merge "Rework the deploy/undeploy method"Sébastien Determe1-10/+28
2019-03-28Rework the submit operationxg353y4-1/+25
2019-03-26Update SSL certificate for DublinChrisC4-30/+30
2019-03-25Rework the UIxg353y2-68/+21
2019-03-25Rework deploy/undeploy UI2019-03-19Removal of dead codesebdet4-149/+2
2019-03-19Remove useless UI codesebdet16-1449/+152
2019-03-18Improve Policy windowsebdet2-10229/+13