def get_request_from_request(self, request: ABCAuthorityReservation, term: Term, ticket: Ticket):
     rset = ResourceSet(units=1, rtype=request.get_type())
     rset.set_resources(cset=ticket)
     result = AuthorityReservationFactory.create(resources=rset, term=term, slice_obj=request.get_slice(),
                                                 rid=request.get_reservation_id())
     result.set_sequence_in(sequence=request.get_sequence_in() + 1)
     return result
    def test_c_fail(self):
        controller = self.get_controller()
        clock = controller.get_actor_clock()
        Term.clock = clock

        resources = ResourceSet(units=1, rtype=ResourceType(resource_type="1"))
        slice_obj = SliceFactory.create(slice_id=ID(), name="fail")
        controller.register_slice(slice_object=slice_obj)

        start = 5
        end = 10

        term = Term(start=clock.cycle_start_date(cycle=start), end=clock.cycle_end_date(cycle=end))

        r1 = ClientReservationFactory.create(rid=ID(), resources=resources, term=term, slice_object=slice_obj)
        r1.set_renewable(renewable=False)
        controller.register(reservation=r1)
        controller.demand(rid=r1.get_reservation_id())

        r2 = ClientReservationFactory.create(rid=ID(), resources=resources, term=term, slice_object=slice_obj)
        r2.set_renewable(renewable=False)
        controller.register(reservation=r2)
        controller.demand(rid=r2.get_reservation_id())

        for i in range(1, end + 3):
            controller.external_tick(cycle=i)

            while controller.get_current_cycle() != i:
                time.sleep(0.001)

            if i >= start and (i < (end - 1)):
                self.assertTrue(r1.is_closed())
                self.assertTrue(r2.is_closed())
                self.assertTrue(r2.get_notices().__contains__(Constants.CLOSURE_BY_TICKET_REVIEW_POLICY))
    def pass_reservation(reservation: ABCServerReservation,
                         auth: AuthToken) -> ReservationAvro:
        avro_reservation = ReservationAvro()
        avro_reservation.slice = Translate.translate_slice_to_avro(
            slice_obj=reservation.get_slice())
        term = None
        if reservation.get_term() is None:
            term = reservation.get_requested_term().clone()
        else:
            term = reservation.get_term().clone()

        avro_reservation.term = Translate.translate_term(term=term)
        avro_reservation.reservation_id = str(reservation.get_reservation_id())

        rset = None
        if reservation.get_resources() is None:
            from fabric_cf.actor.core.kernel.resource_set import ResourceSet
            rset = Translate.translate_resource_set(resource_set=ResourceSet(
                units=0, rtype=reservation.get_requested_type()))
        else:
            rset = Translate.translate_resource_set(
                resource_set=reservation.get_resources())
        if reservation.get_resources() is not None:
            cset = reservation.get_resources().get_resources()

            if cset is not None and isinstance(cset, Ticket):
                rset.ticket = Translate.translate_ticket(ticket=cset)

            if cset is not None and isinstance(cset, UnitSet):
                rset.unit_set = Translate.translate_unit_set(unit_set=cset)

        avro_reservation.resource_set = rset
        return avro_reservation
                def run(self):
                    result = ResultAvro()
                    r = self.actor.get_reservation(rid=reservation)
                    if r is None:
                        result.set_code(
                            ErrorCodes.ErrorNoSuchReservation.value)
                        result.set_message(
                            ErrorCodes.ErrorNoSuchReservation.interpret())
                        return result

                    rset = ResourceSet()
                    if new_units == Constants.EXTEND_SAME_UNITS:
                        rset.set_units(units=r.get_resources().get_units())
                    else:
                        rset.set_units(units=new_units)

                    rset.set_type(rtype=r.get_resources().get_type())

                    tmp_start_time = r.get_term().get_start_time()
                    new_term = r.get_term().extend()

                    new_term.set_end_time(date=new_end_time)
                    new_term.set_new_start_time(date=tmp_start_time)
                    new_term.set_start_time(date=tmp_start_time)

                    self.actor.extend(rid=r.get_reservation_id(),
                                      resources=rset,
                                      term=new_term)

                    return result
 def get_reservation_for_network_node(self, start: datetime, end: datetime,
                                      sliver: NodeSliver):
     slice_obj = SliceFactory.create(slice_id=ID(), name="test-slice")
     rtype = ResourceType(resource_type=sliver.resource_type.name)
     rset = ResourceSet(units=1, rtype=rtype, sliver=sliver)
     term = Term(start=start, end=end)
     request = BrokerReservationFactory.create(rid=ID(),
                                               resources=rset,
                                               term=term,
                                               slice_obj=slice_obj)
     return request
    def assign(
            self, *, reservation: ABCAuthorityReservation,
            delegation_name: str, graph_node: BaseSliver,
            existing_reservations: List[ABCReservationMixin]) -> ResourceSet:
        """
        Assign a reservation
        :param reservation: reservation
        :param delegation_name: Name of delegation serving the request
        :param graph_node: ARM Graph Node serving the reservation
        :param existing_reservations: Existing Reservations served by the same ARM node
        :return: ResourceSet with updated sliver annotated with properties
        :raises: AuthorityException in case the request cannot be satisfied
        """
        reservation.set_send_with_deficit(value=True)

        requested = reservation.get_requested_resources().get_sliver()
        self.__dump_sliver(sliver=requested)
        if not isinstance(requested, NetworkServiceSliver):
            raise AuthorityException(
                f"Invalid resource type {requested.get_type()}")

        current = reservation.get_resources()

        resource_type = ResourceType(resource_type=str(requested.get_type()))

        gained = None
        lost = None
        if current is None:
            self.logger.debug("check if sliver can be provisioned")
            # FIXME Add validation to check ticketed sliver against ARM
            # Refer Network Node Control for reference

            self.logger.debug(
                f"Slice properties: {reservation.get_slice().get_config_properties()}"
            )
            unit = Unit(
                rid=reservation.get_reservation_id(),
                slice_id=reservation.get_slice_id(),
                actor_id=self.authority.get_guid(),
                sliver=requested,
                rtype=resource_type,
                properties=reservation.get_slice().get_config_properties())
            gained = UnitSet(plugin=self.authority.get_plugin(),
                             units={unit.reservation_id: unit})
        else:
            # FIXME: handle modify
            self.logger.info(
                f"Extend Lease for now, no modify supported res# {reservation}"
            )
            return current

        result = ResourceSet(gained=gained, lost=lost, rtype=resource_type)
        result.set_sliver(sliver=requested)
        return result
Beispiel #7
0
 def abstract_clone_return(rset: ResourceSet) -> ResourceSet:
     """
     Clones the resource set, but without any of the concrete sets. Preserves
     only the configuration properties. This method should be used when
     sending a redeem/extend/close request to an authority.
     @param rset resource set
     @return a resources set that is a copy of the current but without any
             concrete sets.
     """
     return ResourceSet(units=rset.get_units(),
                        rtype=rset.get_type(),
                        sliver=rset.get_sliver())
    def get_request_from_request(self, request: ABCBrokerReservation,
                                 units: int, rtype: ResourceType,
                                 start: datetime, end: datetime):
        rset = ResourceSet(units=units, rtype=rtype)

        term = Term(start=request.get_term().get_start_time(),
                    end=end,
                    new_start=start)

        result = BrokerReservationFactory.create(
            rid=request.get_reservation_id(),
            resources=rset,
            term=term,
            slice_obj=request.get_slice())

        result.set_sequence_in(sequence=request.get_sequence_in() + 1)
        return result
    def test_d_nascent(self):
        controller = self.get_controller()
        clock = controller.get_actor_clock()
        Term.clock = clock

        resources = ResourceSet(units=1, rtype=ResourceType(resource_type="1"))
        slice_obj = SliceFactory.create(slice_id=ID(), name="nascent")
        controller.register_slice(slice_object=slice_obj)

        start = 5
        end = 10

        term = Term(start=clock.cycle_start_date(cycle=start), end=clock.cycle_end_date(cycle=end))

        r1 = ClientReservationFactory.create(rid=ID(), resources=resources, term=term, slice_object=slice_obj)
        r1.set_renewable(renewable=False)
        controller.register(reservation=r1)
        controller.demand(rid=r1.get_reservation_id())

        r2 = ClientReservationFactory.create(rid=ID(), resources=resources, term=term, slice_object=slice_obj)
        r2.set_renewable(renewable=False)
        controller.register(reservation=r2)

        r2demanded = False

        for i in range(1, end + 3):
            controller.external_tick(cycle=i)

            while controller.get_current_cycle() != i:
                time.sleep(0.001)

            if i == (start -3) and not r2demanded:
                self.assertTrue(r1.is_ticketed())
                self.assertTrue(r2.is_nascent())
                controller.demand(rid=r2.get_reservation_id())
                r2demanded = True

            if i >= start and (i < end - 1):
                self.assertTrue(r1.is_active())
                self.assertTrue(r2.is_active())

            if i > end:
                self.assertTrue(r1.is_closed())
                self.assertTrue(r2.is_closed())
    def pass_reservation(*, reservation: ABCServerReservation,
                         plugin: ABCBasePlugin) -> ABCReservationMixin:
        slice_obj = reservation.get_slice().clone_request()
        term = None

        if reservation.get_term() is None:
            term = reservation.get_requested_term().clone()
        else:
            term = reservation.get_term().clone()

        rset = None

        if reservation.get_resources() is None:
            rset = ResourceSet(units=0, rtype=reservation.get_requested_type())
        else:
            rset = LocalReturn.abstract_clone_return(
                rset=reservation.get_resources())

            concrete = reservation.get_resources().get_resources()

            if concrete is not None:
                cset = concrete.clone()
                rset.set_resources(cset=cset)

        if isinstance(reservation, ABCBrokerReservation):
            client_reservation = ClientReservationFactory.create(
                rid=reservation.get_reservation_id(),
                resources=rset,
                term=term,
                slice_object=slice_obj)
            client_reservation.set_ticket_sequence_in(
                sequence=reservation.get_sequence_out())
            return client_reservation
        else:
            controller_reservation = ClientReservationFactory.create(
                rid=reservation.get_reservation_id(),
                resources=rset,
                term=term,
                slice_object=slice_obj)
            controller_reservation.set_lease_sequence_in(
                sequence=reservation.get_sequence_out())
            return controller_reservation
Beispiel #11
0
    def extract(self, *, source: ABCDelegation,
                delegation: ResourceTicket) -> ResourceSet:
        """
        Creates a new resource set using the source and the specified delegation.

        @param source source
        @param delegation delegation
        @return returns ResourceSet
        @throws Exception in case of error
        """
        extracted = ResourceSet(units=delegation.get_units(),
                                rtype=delegation.get_resource_type())

        cset = Ticket(resource_ticket=delegation,
                      plugin=self.actor.get_plugin(),
                      authority=source.get_site_proxy(),
                      delegation_id=source.get_delegation_id())

        extracted.set_resources(cset=cset)
        return extracted
Beispiel #12
0
    def test_d_add_update_get_unit(self):
        actor = self.prepare_actor_database()
        db = actor.get_plugin().get_database()
        slice_obj = SliceFactory.create(slice_id=ID(), name="slice-1")
        db.add_slice(slice_object=slice_obj)

        rset = ResourceSet()
        term = Term(start=datetime.now(),
                    end=datetime.now().replace(minute=20))
        res = AuthorityReservationFactory.create(resources=rset,
                                                 term=term,
                                                 slice_obj=slice_obj,
                                                 rid=ID())
        db.add_reservation(reservation=res)

        rtype = ResourceType(resource_type="12")
        u = Unit(rid=res.get_reservation_id(),
                 slice_id=slice_obj.get_slice_id(),
                 actor_id=actor.get_guid())
        u.set_resource_type(rtype=rtype)
        db.add_unit(u=u)

        self.assertIsNotNone(db.get_unit(uid=u.get_id()))
 def get_request(self, term: Term, ticket: Ticket, sliver: BaseSliver):
     rset = ResourceSet(units=1, rtype=ResourceType(resource_type=sliver.resource_type.name), sliver=sliver)
     rset.set_resources(cset=ticket)
     slice_object = self.get_request_slice()
     return AuthorityReservationFactory.create(resources=rset, term=term, slice_obj=slice_object, rid=ID())
    def assign(
            self, *, reservation: ABCAuthorityReservation,
            delegation_name: str, graph_node: BaseSliver,
            existing_reservations: List[ABCReservationMixin]) -> ResourceSet:
        """
        Assign a reservation
        :param reservation: reservation
        :param delegation_name: Name of delegation serving the request
        :param graph_node: ARM Graph Node serving the reservation
        :param existing_reservations: Existing Reservations served by the same ARM node
        :return: ResourceSet with updated sliver annotated with properties
        :raises: AuthorityException in case the request cannot be satisfied
        """

        if graph_node.capacity_delegations is None or reservation is None:
            raise AuthorityException(Constants.INVALID_ARGUMENT)

        delegated_capacities = graph_node.get_capacity_delegations()
        available_delegated_capacity = FimHelper.get_delegation(
            delegated_capacities=delegated_capacities,
            delegation_name=delegation_name)
        if available_delegated_capacity is None:
            raise AuthorityException(
                f"Allocated node {graph_node.node_id} does not have delegation: {delegation_name}"
            )

        reservation.set_send_with_deficit(value=True)

        requested = reservation.get_requested_resources().get_sliver()
        if not isinstance(requested, NodeSliver):
            raise AuthorityException(
                f"Invalid resource type {requested.get_type()}")

        current = reservation.get_resources()

        resource_type = ResourceType(resource_type=str(requested.get_type()))

        gained = None
        lost = None
        if current is None:
            # Check if Capacities can be satisfied by Delegated Capacities
            self.__check_capacities(
                rid=reservation.get_reservation_id(),
                requested_capacities=requested.get_capacity_allocations(),
                available_capacities=available_delegated_capacity,
                existing_reservations=existing_reservations)

            # Check if Capacities can be satisfied by Capacities
            self.__check_capacities(
                rid=reservation.get_reservation_id(),
                requested_capacities=requested.get_capacity_allocations(),
                available_capacities=graph_node.get_capacities(),
                existing_reservations=existing_reservations)

            # Check components
            # Check if Components can be allocated
            if requested.attached_components_info is not None:
                self.__check_components(
                    rid=reservation.get_reservation_id(),
                    requested_components=requested.attached_components_info,
                    graph_node=graph_node,
                    existing_reservations=existing_reservations)

            self.logger.debug(
                f"Slice properties: {reservation.get_slice().get_config_properties()}"
            )
            unit = Unit(
                rid=reservation.get_reservation_id(),
                slice_id=reservation.get_slice_id(),
                actor_id=self.authority.get_guid(),
                sliver=requested,
                rtype=resource_type,
                properties=reservation.get_slice().get_config_properties())
            gained = UnitSet(plugin=self.authority.get_plugin(),
                             units={unit.reservation_id: unit})
        else:
            # FIX ME: handle modify
            self.logger.info(
                f"Extend Lease for now, no modify supported res# {reservation}"
            )
            return current

        result = ResourceSet(gained=gained, lost=lost, rtype=resource_type)
        result.set_sliver(sliver=requested)
        return result
 def translate_resource_set_from_avro(*, rset: ResourceSetAvro) -> ResourceSet:
     result = ResourceSet(units=rset.units, rtype=ResourceType(resource_type=rset.type), sliver=rset.get_sliver())
     return result
Beispiel #16
0
 def get_resource_set(*, res_mng: ReservationMng) -> ResourceSet:
     return ResourceSet(
         units=res_mng.get_units(),
         rtype=ResourceType(resource_type=res_mng.get_resource_type()),
         sliver=res_mng.get_sliver())