Commit 909433c2 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'release/2.0.1' of https://labs.etsi.org/rep/tfs/controller into feat/slice-grouping

parents 2c7fccae 08e7992a
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ def compose_config_rules_data(
    return dict_config_rules

def upsert_config_rules(
    session : Session, config_rules : List[Dict],
    session : Session, config_rules : List[Dict], is_delete : bool = False,
    device_uuid : Optional[str] = None, service_uuid : Optional[str] = None, slice_uuid : Optional[str] = None,
) -> bool:
    uuids_to_delete : Set[str] = set()
@@ -89,7 +89,9 @@ def upsert_config_rules(
    for config_rule in config_rules:
        configrule_uuid = config_rule['configrule_uuid']
        configrule_action = config_rule['action']
        if configrule_action == ORM_ConfigActionEnum.SET:
        if is_delete or configrule_action == ORM_ConfigActionEnum.DELETE:
            uuids_to_delete.add(configrule_uuid)
        elif configrule_action == ORM_ConfigActionEnum.SET:
            position = uuids_to_upsert.get(configrule_uuid)
            if position is None:
                # if not added, add it
@@ -98,8 +100,6 @@ def upsert_config_rules(
            else:
                # if already added, update occurrence
                rules_to_upsert[position] = config_rule
        elif configrule_action == ORM_ConfigActionEnum.DELETE:
            uuids_to_delete.add(configrule_uuid)
        else:
            MSG = 'Action for ConfigRule({:s}) is not supported '+\
                  '(device_uuid={:s}, service_uuid={:s}, slice_uuid={:s})'
+16 −14
Original line number Diff line number Diff line
@@ -81,11 +81,12 @@ def compose_constraints_data(
    return dict_constraints

def upsert_constraints(
    session : Session, constraints : List[Dict],
    session : Session, constraints : List[Dict], is_delete : bool = False,
    service_uuid : Optional[str] = None, slice_uuid : Optional[str] = None
) -> bool:
    uuids_to_upsert : Dict[str, int] = dict()
    rules_to_upsert : List[Dict] = list()
    if not is_delete:
        for constraint in constraints:
            constraint_uuid = constraint['constraint_uuid']
            position = uuids_to_upsert.get(constraint_uuid)
@@ -99,10 +100,11 @@ def upsert_constraints(

    # Delete all constraints not in uuids_to_upsert
    delete_affected = False
    if len(uuids_to_upsert) > 0:
    if is_delete or len(uuids_to_upsert) > 0:
        stmt = delete(ConstraintModel)
        if service_uuid is not None: stmt = stmt.where(ConstraintModel.service_uuid == service_uuid)
        if slice_uuid   is not None: stmt = stmt.where(ConstraintModel.slice_uuid   == slice_uuid  )
        if not is_delete:
            stmt = stmt.where(ConstraintModel.constraint_uuid.not_in(set(uuids_to_upsert.keys())))
        #str_stmt = stmt.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True})
        #LOGGER.warning('delete stmt={:s}'.format(str(str_stmt)))
@@ -111,7 +113,7 @@ def upsert_constraints(
        delete_affected = int(constraint_deletes.rowcount) > 0

    upsert_affected = False
    if len(constraints) > 0:
    if not is_delete and len(constraints) > 0:
        stmt = insert(ConstraintModel).values(constraints)
        stmt = stmt.on_conflict_do_update(
            index_elements=[ConstraintModel.constraint_uuid],
+9 −5
Original line number Diff line number Diff line
@@ -178,10 +178,6 @@ def slice_unset(db_engine : Engine, request : Slice) -> Tuple[Dict, bool]:
    slice_name = raw_slice_uuid if len(raw_slice_name) == 0 else raw_slice_name
    context_uuid,slice_uuid = slice_get_uuid(request.slice_id, slice_name=slice_name, allow_random=False)

    if len(request.slice_constraints) > 0:         raise NotImplementedError('UnsetSlice: removal of constraints')
    if len(request.slice_config.config_rules) > 0: raise NotImplementedError('UnsetSlice: removal of config rules')
    #if len(request.slice_endpoint_ids) > 0:        raise NotImplementedError('UnsetSlice: removal of endpoints')

    slice_endpoint_uuids : Set[str] = set()
    for i,endpoint_id in enumerate(request.slice_endpoint_ids):
        endpoint_context_uuid = endpoint_id.topology_id.context_id.context_uuid.uuid
@@ -203,6 +199,10 @@ def slice_unset(db_engine : Engine, request : Slice) -> Tuple[Dict, bool]:
        for subslice_id in request.slice_subslice_ids
    }

    now = datetime.datetime.utcnow()
    constraints = compose_constraints_data(request.slice_constraints, now, slice_uuid=slice_uuid)
    config_rules = compose_config_rules_data(request.slice_config.config_rules, now, slice_uuid=slice_uuid)

    def callback(session : Session) -> bool:
        num_deletes = 0
        if len(slice_service_uuids) > 0:
@@ -223,7 +223,11 @@ def slice_unset(db_engine : Engine, request : Slice) -> Tuple[Dict, bool]:
                    SliceEndPointModel.slice_uuid == slice_uuid,
                    SliceEndPointModel.endpoint_uuid.in_(slice_endpoint_uuids)
                )).delete()
        return num_deletes > 0

        changed_constraints = upsert_constraints(session, constraints, is_delete=True, slice_uuid=slice_uuid)
        changed_config_rules = upsert_config_rules(session, config_rules, is_delete=True, slice_uuid=slice_uuid)

        return num_deletes > 0 or changed_constraints or changed_config_rules

    updated = run_transaction(sessionmaker(bind=db_engine), callback)
    return json_slice_id(slice_uuid, json_context_id(context_uuid)),updated
+4 −4
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ class TasksScheduler:
                self._dag.add(connection_key, service_key_done)

        t1 = time.time()
        LOGGER.info('[compose_from_pathcompreply] elapsed_time: {:f} sec'.format(t1-t0))
        LOGGER.debug('[compose_from_pathcompreply] elapsed_time: {:f} sec'.format(t1-t0))

    def compose_from_service(self, service : Service, is_delete : bool = False) -> None:
        t0 = time.time()
@@ -196,11 +196,11 @@ class TasksScheduler:
                raise Exception(MSG.format(type(item).__name__, grpc_message_to_json_string(item)))

        t1 = time.time()
        LOGGER.info('[compose_from_service] elapsed_time: {:f} sec'.format(t1-t0))
        LOGGER.debug('[compose_from_service] elapsed_time: {:f} sec'.format(t1-t0))

    def execute_all(self, dry_run : bool = False) -> None:
        ordered_task_keys = list(self._dag.static_order())
        LOGGER.info('[execute_all] ordered_task_keys={:s}'.format(str(ordered_task_keys)))
        LOGGER.debug('[execute_all] ordered_task_keys={:s}'.format(str(ordered_task_keys)))

        results = []
        for task_key in ordered_task_keys:
@@ -208,5 +208,5 @@ class TasksScheduler:
            succeeded = True if dry_run else task.execute()
            results.append(succeeded)

        LOGGER.info('[execute_all] results={:s}'.format(str(results)))
        LOGGER.debug('[execute_all] results={:s}'.format(str(results)))
        return zip(ordered_task_keys, results)