Пример #1
0
def resolve_extends(compose_data, file_name, vertex_list, edge_list):
    for local_service_name, local_service_data in compose_data.items():
        if 'extends' in local_service_data.keys():
            extends = local_service_data['extends']
            extends_file_name = os.path.abspath(extends['file'])
            original_service_name = extends['service']
            if extends_file_name not in vertex_list:
                vertex_list.append(extends_file_name)
            edge = (file_name, extends_file_name)
            if edge not in edge_list:
                edge_list.append(edge)
            vertex_list_tmp = deepcopy(vertex_list)
            edge_list_tmp = deepcopy(edge_list)
            result = util.topoSort(vertex_list_tmp, edge_list_tmp)
            if result is None:
                raise AlaudaInputError('There is a circular dependency in extends definitions')
            original_compose_data = _load_yaml(extends_file_name)
            resolve_extends(original_compose_data, extends_file_name, vertex_list, edge_list)
            original_service_data = original_compose_data[original_service_name]
            for key, value in original_service_data.items():
                if key == 'links' or key == 'volumes_from':
                    continue
                elif key == 'ports':
                    merge_ports(local_service_data, value)
                elif key == 'expose':
                    merge_expose(local_service_data, value)
                elif key == 'environment':
                    merge_environment(local_service_data, value)
                elif key == 'volumes':
                    merge_volumes(local_service_data, value)
                elif key not in local_service_data.keys():
                    local_service_data[key] = value
                else:
                    continue
Пример #2
0
def toposort_services(compose_data):
    service_vertex = []
    service_edge = []
    src_keys = compose_data.keys()
    for key, value in compose_data.items():
        links = _get_linked_services(value.get('links'))
        if key not in service_vertex:
            service_vertex.append(key)
        if not set(links).issubset(set(src_keys)):
            raise AlaudaInputError("{} has invalid link name".format(links))
        else:
            for link in links:
                if link not in service_vertex:
                    service_vertex.append(link)
                service_edge.append((link, key))
    sorted_result = util.topoSort(service_vertex, service_edge)
    if sorted_result == -1:
        raise AlaudaInputError("there is a circle in your service depended list")
    return sorted_result
Пример #3
0
def toposort_services(compose_data):
    service_vertex = []
    service_edge = []
    src_keys = compose_data.keys()
    for key, value in compose_data.items():
        links = _get_linked_services(value.get('links'))
        if key not in service_vertex:
            service_vertex.append(key)
        if not set(links).issubset(set(src_keys)):
            raise AlaudaInputError("{} has invalid link name".format(links))
        else:
            for link in links:
                if link not in service_vertex:
                    service_vertex.append(link)
                service_edge.append((link, key))
    sorted_result = util.topoSort(service_vertex, service_edge)
    if sorted_result == -1:
        raise AlaudaInputError(
            "there is a circle in your service depended list")
    return sorted_result
Пример #4
0
def resolve_extends(compose_data, file_name, vertex_list, edge_list):
    for local_service_name, local_service_data in compose_data.items():
        if 'extends' in local_service_data.keys():
            extends = local_service_data['extends']
            extends_file_name = os.path.abspath(extends['file'])
            original_service_name = extends['service']
            if extends_file_name not in vertex_list:
                vertex_list.append(extends_file_name)
            edge = (file_name, extends_file_name)
            if edge not in edge_list:
                edge_list.append(edge)
            vertex_list_tmp = deepcopy(vertex_list)
            edge_list_tmp = deepcopy(edge_list)
            result = util.topoSort(vertex_list_tmp, edge_list_tmp)
            if result is None:
                raise AlaudaInputError(
                    'There is a circular dependency in extends definitions')
            original_compose_data = _load_yaml(extends_file_name)
            resolve_extends(original_compose_data, extends_file_name,
                            vertex_list, edge_list)
            original_service_data = original_compose_data[
                original_service_name]
            for key, value in original_service_data.items():
                if key == 'links' or key == 'volumes_from':
                    continue
                elif key == 'ports':
                    merge_ports(local_service_data, value)
                elif key == 'expose':
                    merge_expose(local_service_data, value)
                elif key == 'environment':
                    merge_environment(local_service_data, value)
                elif key == 'volumes':
                    merge_volumes(local_service_data, value)
                elif key not in local_service_data.keys():
                    local_service_data[key] = value
                else:
                    continue