def reclaim(self, *, request: ReclaimResourcesAvro):
        result = ResultDelegationAvro()
        result.status = ResultAvro()
        result.message_id = request.message_id

        try:
            if request.guid is None or request.broker_id is None or request.delegation_id is None:
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())
                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))

            if mo is None:
                self.logger.debug("Management object could not be found: guid: {} auth: {}".format(request.guid, auth))
                result.status.set_code(ErrorCodes.ErrorNoSuchBroker.value)
                result.status.set_message(ErrorCodes.ErrorNoSuchBroker.interpret())
                return result

            result = mo.reclaim_delegations(broker=ID(uid=request.broker_id), did=request.delegation_id, caller=auth,
                                            id_token=request.id_token)

        except Exception as e:
            result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
            result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())
            result.status.set_message(str(e))
            result.status.set_details(traceback.format_exc())

        result.message_id = request.message_id
        return result
    def extend_reservation(self, *, request: ExtendReservationAvro) -> ResultStringAvro:
        result = ResultStringAvro()
        result.message_id = request.message_id

        try:
            if request.guid is None or request.reservation_id is None:
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())

                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))

            end_time = ActorClock.from_milliseconds(milli_seconds=request.end_time)
            rtype = None
            if request.new_resource_type is not None:
                rtype = ResourceType(resource_type=request.new_resource_type)

            result.status = mo.extend_reservation(rid=ID(uid=request.reservation_id), new_end_time=end_time,
                                                  new_units=request.new_units, new_resource_type=rtype,
                                                  request_properties=request.request_properties,
                                                  config_properties=request.config_properties, caller=auth)

        except Exception as e:
            result.status.set_code(ErrorCodes.ErrorInternalError.value)
            result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e))
            result.status = ManagementObject.set_exception_details(result=result.status, e=e)

        result.message_id = request.message_id
        return result
示例#3
0
    def test_a_register_reservation(self):
        actor = self.prepare_actor()
        kernel = self.get_kernel_wrapper(actor=actor)
        db = actor.get_plugin().get_database()

        slice_obj = SliceFactory.create(slice_id=ID(), name="test_slice")
        kernel.register_slice(slice_object=slice_obj)
        self.base_slices_count += 1

        for i in range(10):
            rid = ID()
            reservation = ClientReservationFactory.create(
                rid=rid, slice_object=slice_obj)
            kernel.register_reservation(reservation=reservation)

            self.assertIsNotNone(kernel.get_reservation(rid=rid))
            self.enforceReservationExistsInDatabase(db=db, rid=rid)

            failed = False

            try:
                kernel.register_reservation(reservation=reservation)
            except Exception:
                failed = True

            self.assertTrue(failed)
            self.assertIsNotNone(kernel.get_reservation(rid=rid))
            self.enforceReservationExistsInDatabase(db=db, rid=rid)
    def demand_reservation(self, *, request: DemandReservationAvro) -> ResultStringAvro:
        result = ResultStringAvro()
        result.status = ResultAvro()
        result.message_id = request.message_id

        try:
            if request.guid is None or (request.reservation_id is None and request.reservation_obj is None):
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())

                return result

            if request.reservation_obj is not None and request.reservation_id is not None:
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())

                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))

            if request.reservation_id is not None:
                result.status = mo.demand_reservation_rid(rid=ID(uid=request.reservation_id), caller=auth)
            else:
                result.status = mo.demand_reservation(reservation=request.reservation_obj, caller=auth)

        except Exception as e:
            result.status.set_code(ErrorCodes.ErrorInternalError.value)
            result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e))
            result.status = ManagementObject.set_exception_details(result=result.status, e=e)

        result.message_id = request.message_id
        return result
    def get_broker_query_model(self, *, request: GetBrokerQueryModelRequestAvro) -> ResultBrokerQueryModelAvro:
        result = ResultBrokerQueryModelAvro()
        result.status = ResultAvro()
        result.message_id = request.message_id

        try:
            if request.guid is None:
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())
                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))

            graph_format = GraphFormat(request.graph_format)

            result = mo.get_broker_query_model(broker=ID(uid=request.broker_id), caller=auth,
                                               id_token=request.get_id_token(), graph_format=graph_format)

        except Exception as e:
            result.status.set_code(ErrorCodes.ErrorInternalError.value)
            result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e))
            result.status = ManagementObject.set_exception_details(result=result.status, e=e)

        result.message_id = request.message_id
        return result
    def get_slices(self, *, request: GetSlicesRequestAvro) -> ResultSliceAvro:
        result = ResultSliceAvro()
        result.status = ResultAvro()
        result.message_id = request.message_id
        try:
            if request.guid is None:
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())
                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))
            slice_id = None
            if request.slice_id is not None:
                slice_id = ID(uid=request.slice_id)
            result = mo.get_slices(slice_id=slice_id, caller=auth, id_token=request.get_id_token(),
                                   slice_name=request.slice_name, email=request.get_email())

        except Exception as e:
            self.logger.error(traceback.format_exc())
            result.status.set_code(ErrorCodes.ErrorInternalError.value)
            result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e))
            result.status = ManagementObject.set_exception_details(result=result.status, e=e)

        result.message_id = request.message_id
        return result
    def get_delegations(self, *, request: GetDelegationsAvro) -> ResultDelegationAvro:
        result = ResultDelegationAvro()
        result.status = ResultAvro()
        result.message_id = request.message_id

        try:
            if request.guid is None:
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())
                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))

            if request.get_delegation_id() is not None:
                result = mo.get_delegations(caller=auth, did=ID(uid=request.get_delegation_id()),
                                            id_token=request.get_id_token(), state=request.delegation_state)

            elif request.get_slice_id() is not None:
                result = mo.get_delegations(caller=auth, slice_id=ID(uid=request.get_slice_id()),
                                            id_token=request.get_id_token(), state=request.delegation_state)

            else:
                result = mo.get_delegations(caller=auth, id_token=request.get_id_token(),
                                            state=request.delegation_state)

        except Exception as e:
            result.status.set_code(ErrorCodes.ErrorInternalError.value)
            result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e))
            result.status = ManagementObject.set_exception_details(result=result.status, e=e)

        result.message_id = request.message_id
        return result
示例#8
0
    def test_j_register_reservation_error(self):
        actor = self.prepare_actor()
        kernel = self.get_kernel_wrapper(actor=actor)
        db = actor.get_plugin().get_database()

        slice_obj = SliceFactory.create(slice_id=ID(), name="test_slice")
        kernel.register_slice(slice_object=slice_obj)

        # Set the database to null to cause errors while registering slices.
        actor.get_plugin().set_database(db=None)

        for i in range(10):
            rid = ID()
            reservation = ClientReservationFactory.create(
                rid=rid, slice_object=slice_obj)
            failed = False

            try:
                kernel.register_reservation(reservation=reservation)
            except Exception:
                failed = True

            self.assertTrue(failed)
            self.assertIsNone(kernel.get_reservation(rid=rid))
            self.enforceReservationNotInDatabase(db=db, rid=rid)
    def close_reservations(self, *, request: CloseReservationsAvro) -> ResultStringAvro:
        result = ResultStringAvro()
        result.status = ResultAvro()
        result.message_id = request.message_id

        try:
            if request.guid is None or (request.get_slice_id() is None and request.get_reservation_id() is None):
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())
                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))

            if request.get_slice_id() is not None:
                result.status = mo.close_slice_reservations(caller=auth, slice_id=ID(uid=request.slice_id),
                                                            id_token=request.id_token)
            else:
                result.status = mo.close_reservation(caller=auth, rid=ID(uid=request.reservation_id),
                                                     id_token=request.id_token)

        except Exception as e:
            result.status.set_code(ErrorCodes.ErrorInternalError.value)
            result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e))
            result.status = ManagementObject.set_exception_details(result=result.status, e=e)

        result.message_id = request.message_id
        return result
 def failed_rpc(self, *, request: FailedRpcAvro):
     rpc = None
     auth_token = Translate.translate_auth_from_avro(auth_avro=request.auth)
     try:
         failed_request_type = RPCRequestType(request.request_type)
         if request.reservation_id is not None and request.reservation_id != "":
             rpc = IncomingFailedRPC(
                 message_id=ID(uid=request.message_id),
                 failed_request_type=failed_request_type,
                 request_id=request.request_id,
                 failed_reservation_id=ID(uid=request.reservation_id),
                 error_details=request.error_details,
                 caller=auth_token)
         else:
             rpc = IncomingFailedRPC(
                 message_id=ID(uid=request.message_id),
                 failed_request_type=failed_request_type,
                 request_id=request.request_id,
                 failed_reservation_id=None,
                 error_details=request.error_details,
                 caller=auth_token)
     except Exception as e:
         self.logger.error("Invalid failedRequest request: {}".format(e))
         raise e
     self.do_dispatch(rpc=rpc)
    def vertex_to_registry_cache(self, *, peer: Peer):
        """
        Add peer to Registry Cache
        @param peer peer config
        @raises ConfigurationException in case of error
        """
        self.logger.debug("Adding vertex for {}".format(peer.get_name()))

        if peer.get_name() is None:
            raise ConfigurationException("Actor must specify a name")

        if peer.get_guid() is None:
            raise ConfigurationException("Actor must specify a guid")

        protocol = Constants.PROTOCOL_LOCAL
        kafka_topic = None
        if peer.get_kafka_topic() is not None:
            protocol = Constants.PROTOCOL_KAFKA
            kafka_topic = peer.get_kafka_topic()

        actor_type = peer.get_type().lower()

        entry = {
            RemoteActorCache.actor_name: peer.get_name(),
            RemoteActorCache.actor_guid: ID(uid=peer.get_guid()),
            RemoteActorCache.actor_type: actor_type,
            RemoteActorCache.actor_protocol: protocol
        }
        if kafka_topic is not None:
            entry[RemoteActorCache.actor_location] = kafka_topic

        RemoteActorCacheSingleton.get().add_partial_cache_entry(
            guid=ID(uid=peer.get_guid()), entry=entry)
    def make_actor_instance(*, actor_config: ActorConfig) -> ABCActorMixin:
        """
        Creates Actor instance
        @param actor_config actor config
        @raises ConfigurationException in case of error
        """
        actor_type = ActorType.get_actor_type_from_string(
            actor_type=actor_config.get_type())
        actor = None
        if actor_type == ActorType.Orchestrator:
            actor = Controller()
        elif actor_type == ActorType.Broker:
            actor = Broker()
        elif actor_type == ActorType.Authority:
            actor = Authority()
        else:
            raise ConfigurationException(
                f"Unsupported actor type: {actor_type}")

        actor_guid = ID()
        if actor_config.get_guid() is not None:
            actor_guid = ID(uid=actor_config.get_guid())
        auth_token = AuthToken(name=actor_config.get_name(), guid=actor_guid)
        actor.set_identity(token=auth_token)
        if actor_config.get_description() is not None:
            actor.set_description(description=actor_config.get_description())

        from fabric_cf.actor.core.container.globals import GlobalsSingleton
        actor.set_actor_clock(
            clock=GlobalsSingleton.get().get_container().get_actor_clock())

        return actor
示例#13
0
    def get_reservation_units(
            self, *,
            request: GetReservationUnitsRequestAvro) -> ResultUnitsAvro:
        result = ResultUnitsAvro()
        result.status = ResultAvro()
        result.message_id = request.message_id

        try:
            if request.guid is None or request.reservation_id is None:
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(
                    ErrorCodes.ErrorInvalidArguments.interpret())
                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))

            result = mo.get_reservation_units(
                caller=auth,
                rid=ID(uid=request.reservation_id),
                id_token=request.get_id_token())

        except Exception as e:
            result.status.set_code(ErrorCodes.ErrorInternalError.value)
            result.status.set_message(
                ErrorCodes.ErrorInternalError.interpret(exception=e))
            result.status = ManagementObject.set_exception_details(
                result=result.status, e=e)

        result.message_id = request.message_id
        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))
示例#15
0
    def get_reservations(self,
                         slice_id: str = None,
                         res_id: str = None,
                         email: str = None):
        try:
            res_list = []
            if slice_id is not None:
                res_list = self.db.get_reservations_by_slice_id(slice_id=ID(
                    uid=slice_id))
            elif res_id is not None:
                res_list = self.db.get_reservation(rid=ID(uid=res_id))
            elif email is not None:
                res_list = self.db.get_reservations_by_email(email=email)
            else:
                res_list = self.db.get_reservations()

            if res_list is not None and len(res_list) > 0:
                for r in res_list:
                    print(r)
                    print()
            else:
                print(f"No reservations found: {res_list}")
        except Exception as e:
            print(f"Exception occurred while fetching delegations: {e}")
            traceback.print_exc()
                def run(self):
                    result = ResultAvro()
                    rid = ID(uid=reservation.get_reservation_id())
                    r = self.actor.get_reservation(rid=rid)
                    if r is None:
                        result.set_code(
                            ErrorCodes.ErrorNoSuchReservation.value)
                        result.set_message(
                            ErrorCodes.ErrorNoSuchReservation.interpret())
                        return result

                    ManagementUtils.update_reservation(res_obj=r,
                                                       rsv_mng=reservation)
                    if isinstance(reservation, LeaseReservationAvro):
                        predecessors = reservation.get_redeem_predecessors()
                        for pred in predecessors:
                            if pred.get_reservation_id() is None:
                                self.logger.warning(
                                    "Redeem predecessor specified for rid={} "
                                    "but missing reservation id of predecessor"
                                    .format(rid))
                                continue

                            predid = ID(uid=pred.get_reservation_id())
                            pr = self.actor.get_reservation(rid=predid)

                            if pr is None:
                                self.logger.warning(
                                    "Redeem predecessor for rid={} with rid={} does not exist. "
                                    "Ignoring it!".format(rid, predid))
                                continue

                            if not isinstance(pr, ABCControllerReservation):
                                self.logger.warning(
                                    "Redeem predecessor for rid={} is not an IControllerReservation: "
                                    "class={}".format(rid, type(pr)))
                                continue

                            self.logger.debug(
                                "Setting redeem predecessor on reservation # {} pred={}"
                                .format(r.get_reservation_id(),
                                        pr.get_reservation_id()))
                            r.add_redeem_predecessor(reservation=pr)

                    try:
                        self.actor.get_plugin().get_database(
                        ).update_reservation(reservation=r)
                    except Exception as e:
                        self.logger.error(
                            "Could not commit slice update {}".format(e))
                        result.set_code(ErrorCodes.ErrorDatabaseError.value)
                        result.set_message(
                            ErrorCodes.ErrorDatabaseError.interpret(
                                exception=e))

                    self.actor.demand(rid=rid)

                    return result
示例#17
0
    def reset(self, *, properties: dict):
        self.id = ID(uid=properties[Constants.PROPERTY_ID])

        if Constants.PROPERTY_TYPE_ID in properties:
            self.type_id = ID(uid=properties[Constants.PROPERTY_TYPE_ID])

        self.load_protocols(properties=properties)

        self.serial = properties
    def get_reservations(self, *, request: GetReservationsRequestAvro) -> ResultReservationAvro:
        result = ResultReservationAvro()
        result.status = ResultAvro()
        result.message_id = request.message_id

        try:
            if request.guid is None:
                result.status.set_code(ErrorCodes.ErrorInvalidArguments.value)
                result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret())
                return result

            auth = Translate.translate_auth_from_avro(auth_avro=request.auth)
            mo = self.get_actor_mo(guid=ID(uid=request.guid))

            slice_id = None
            if request.slice_id is not None:
                slice_id = ID(uid=request.slice_id)

            rid = None
            if request.get_reservation_id() is not None:
                rid = ID(uid=request.get_reservation_id())

            if rid is not None:
                result = mo.get_reservations(caller=auth, rid=rid, id_token=request.get_id_token())

            elif slice_id is not None:

                if request.get_reservation_state() is not None and \
                        request.get_reservation_state() != Constants.ALL_RESERVATION_STATES:

                    result = mo.get_reservations(caller=auth, slice_id=slice_id,
                                                 state=request.get_reservation_state(),
                                                 id_token=request.get_id_token())

                else:
                    result = mo.get_reservations(caller=auth, slice_id=slice_id,
                                                 id_token=request.get_id_token())

            else:
                if request.get_reservation_state() is not None and \
                        request.get_reservation_state() != Constants.ALL_RESERVATION_STATES:

                    result = mo.get_reservations(caller=auth, state=request.get_reservation_state(),
                                                 id_token=request.get_id_token(), email=request.get_email())

                else:
                    result = mo.get_reservations(caller=auth, id_token=request.get_id_token(),
                                                 email=request.get_email())

        except Exception as e:
            result.status.set_code(ErrorCodes.ErrorInternalError.value)
            result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e))
            result.status = ManagementObject.set_exception_details(result=result.status, e=e)

        result.message_id = request.message_id
        return result
    def add_reservation_private(self, *, reservation: TicketReservationAvro):
        result = ResultAvro()
        slice_id = ID(uid=reservation.get_slice_id())
        rset = Converter.get_resource_set(res_mng=reservation)
        term = Term(start=ActorClock.from_milliseconds(
            milli_seconds=reservation.get_start()),
                    end=ActorClock.from_milliseconds(
                        milli_seconds=reservation.get_end()))

        broker = None

        if reservation.get_broker() is not None:
            broker = ID(uid=reservation.get_broker())

        rid = None
        if reservation.get_reservation_id() is not None:
            rid = ID(uid=reservation.get_reservation_id())
        else:
            rid = ID()
        rc = ClientReservationFactory.create(rid=rid,
                                             resources=rset,
                                             term=term)
        rc.set_renewable(renewable=reservation.is_renewable())

        if rc.get_state() != ReservationStates.Nascent or rc.get_pending_state(
        ) != ReservationPendingStates.None_:
            result.set_code(ErrorCodes.ErrorInvalidReservation.value)
            result.set_message(
                "Only reservations in Nascent.None can be added")
            return None, result

        slice_obj = self.client.get_slice(slice_id=slice_id)

        if slice_obj is None:
            result.set_code(ErrorCodes.ErrorNoSuchSlice.value)
            result.set_message(ErrorCodes.ErrorNoSuchSlice.interpret())
            return None, result

        rc.set_slice(slice_object=slice_obj)

        proxy = None

        if broker is None:
            proxy = self.client.get_default_broker()
        else:
            proxy = self.client.get_broker(guid=broker)

        if proxy is None:
            result.set_code(ErrorCodes.ErrorNoSuchBroker.value)
            result.set_message(ErrorCodes.ErrorNoSuchBroker.interpret())
            return None, result

        rc.set_broker(broker=proxy)
        self.client.register(reservation=rc)
        return rc.get_reservation_id(), result
示例#20
0
    def test_g_unregister_reservation(self):
        actor = self.prepare_actor()
        kernel = self.get_kernel_wrapper(actor=actor)
        db = actor.get_plugin().get_database()

        slice_obj = SliceFactory.create(slice_id=ID(), name="testslice")
        kernel.register_slice(slice_object=slice_obj)

        res_list = []

        for i in range(10):
            res = ClientReservationFactory.create(rid=ID())
            res.set_slice(slice_object=slice_obj)
            res_list.append(res)

            self.assertIsNone(
                kernel.get_reservation(rid=res.get_reservation_id()))
            self.enforceReservationNotInDatabase(db=db,
                                                 rid=res.get_reservation_id())

            failed = False

            try:
                kernel.unregister_reservation(rid=res.get_reservation_id())
            except Exception:
                failed = True

            self.assertTrue(failed)

            self.assertIsNone(
                kernel.get_reservation(rid=res.get_reservation_id()))
            self.enforceReservationNotInDatabase(db=db,
                                                 rid=res.get_reservation_id())
            kernel.register_reservation(reservation=res)
            self.assertIsNotNone(
                kernel.get_reservation(rid=res.get_reservation_id()))
            self.enforceReservationExistsInDatabase(
                db=db, rid=res.get_reservation_id())

        for res in res_list:
            self.assertIsNotNone(
                kernel.get_slice(slice_id=slice_obj.get_slice_id()))
            self.enforceSliceExistsInDatabase(
                db=db, slice_id=slice_obj.get_slice_id())
            res.fail(message="forced")
            kernel.unregister_reservation(rid=res.get_reservation_id())
            self.assertIsNone(
                kernel.get_reservation(rid=res.get_reservation_id()))
            self.enforceReservationExistsInDatabase(
                db=db, rid=res.get_reservation_id())

        check = kernel.get_reservations(slice_id=slice_obj.get_slice_id())
        self.assertIsNotNone(check)
        self.assertEqual(0, len(check))
 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 query_result(self, *, request: QueryResultAvro):
     rpc = None
     auth_token = Translate.translate_auth_from_avro(auth_avro=request.auth)
     try:
         query = request.properties
         rpc = IncomingQueryRPC(request_type=RPCRequestType.QueryResult,
                                message_id=ID(uid=request.get_message_id()),
                                query=query,
                                caller=auth_token,
                                request_id=ID(uid=request.request_id),
                                id_token=None)
     except Exception as e:
         self.logger.error("Invalid query_result request: {}".format(e))
         raise e
     self.do_dispatch(rpc=rpc)
    def add_client_slice(self, *, slice_mng: SliceAvro) -> ID:
        ret_val = None
        request = AddSliceAvro()
        request.guid = str(self.management_id)
        request.auth = self.auth
        request.callback_topic = self.callback_topic
        request.message_id = str(ID())
        request.slice_obj = slice_mng

        status, response = self.send_request(request)

        if status.code == 0:
            ret_val = ID(uid=response.get_result())

        return ret_val
    def process_neo4j(self, substrate_file: str, actor_name: str) -> Dict:
        """
        Create ARM and Inventory Slices
        """
        from fabric_cf.actor.core.container.globals import GlobalsSingleton
        self.container = GlobalsSingleton.get().get_container()

        result = self.substrate.get_inventory_slice_manager().create_inventory_slice(
            slice_id=ID(), name=actor_name,
            rtype=ResourceType(resource_type=Constants.PROPERTY_AGGREGATE_RESOURCE_MODEL))

        if result.code != InventorySliceManagerError.ErrorNone:
            raise AggregateResourceModelCreatorException(f"Could not create ARM: {actor_name}. error={result.code}")

        self.logger.debug(f"Created aggregate manager resource slice# {result.slice}")

        if result.slice.get_graph_id() is not None:
            # load the graph from Neo4j database
            self.logger.debug(f"Reloading an existing graph for resource slice# {result.slice}")
            self.arm_graph = FimHelper.get_arm_graph(graph_id=result.slice.get_graph_id())
            result.slice.set_graph(graph=self.arm_graph)
        else:
            self.arm_graph = FimHelper.get_arm_graph_from_file(filename=substrate_file)
            result.slice.set_graph(graph=self.arm_graph)
            self.substrate.get_inventory_slice_manager().update_inventory_slice(slice_obj=result.slice)
            self.logger.debug(f"Created new graph for resource slice# {result.slice}")

        for r in self.resources.values():
            self.logger.debug(f"Registering resource_handler for resource_type: {r.get_resource_type_label()} "
                              f"for Actor {actor_name}")
            self.register_handler(resource_config=r)

        return self.arm_graph.generate_adms()
    def create_sliver(self, name: str, pci_address: str, gpu_name: str) -> Unit:
        u = Unit(rid=ID(uid=name))
        sliver = NodeSliver()
        cap = Capacities(core=2, ram=6, disk=10)
        sliver.set_properties(type=NodeType.VM, site="UKY", capacity_allocations=cap)
        sliver.label_allocations = Labels(instance_parent="uky-w2.fabric-testbed.net")
        catalog = InstanceCatalog()
        instance_type = catalog.map_capacities_to_instance(cap=cap)
        cap_hints = CapacityHints(instance_type=instance_type)
        sliver.set_properties(capacity_hints=cap_hints,
                              capacity_allocations=catalog.get_instance_capacities(instance_type=instance_type))

        sliver.set_properties(name=name)

        sliver.set_properties(image_type='qcow2', image_ref='default_ubuntu_20')

        component = ComponentSliver()
        labels = Labels(bdf=pci_address)
        component.set_properties(type=ComponentType.GPU, model='Tesla T4', name=gpu_name, label_allocations=labels)
        sliver.attached_components_info = AttachedComponentsInfo()
        sliver.attached_components_info.add_device(device_info=component)

        u.set_sliver(sliver=sliver)
        u.set_resource_type(rtype=ResourceType(resource_type=NodeType.VM.name))
        return u
    def fill_request_by_id_message(self,
                                   request: RequestByIdRecord,
                                   id_token: str = None,
                                   email: str = None,
                                   slice_id: ID = None,
                                   slice_name: str = None,
                                   reservation_state: int = None,
                                   rid: ID = None,
                                   delegation_id: str = None,
                                   broker_id: ID = None):
        request.guid = str(self.management_id)
        request.auth = self.auth
        request.callback_topic = self.callback_topic
        request.message_id = str(ID())
        request.id_token = id_token
        request.email = email
        request.reservation_state = reservation_state
        request.delegation_id = delegation_id
        if slice_id is not None:
            request.slice_id = str(slice_id)
        if rid is not None:
            request.reservation_id = str(rid)
        if broker_id is not None:
            request.broker_id = str(broker_id)
        request.slice_name = slice_name

        return request
示例#27
0
    def test_d_remove_slice_empty(self):
        actor = self.prepare_actor()
        kernel = self.get_kernel_wrapper(actor=actor)
        db = actor.get_plugin().get_database()

        slice_list = []

        for i in range(10):
            slice_obj = SliceFactory.create(slice_id=ID(),
                                            name="Slice:{}".format(i))
            slice_obj.set_inventory(value=True)
            kernel.register_slice(slice_object=slice_obj)
            self.enforceSliceExistsInDatabase(
                db=db, slice_id=slice_obj.get_slice_id())
            slice_list.append(slice_obj)

        for s in slice_list:
            kernel.remove_slice(slice_id=s.get_slice_id())

            check = kernel.get_slice(slice_id=s.get_slice_id())
            self.assertIsNone(check)
            self.enforceSliceNotInDatabase(db=db, slice_id=s.get_slice_id())

            kernel.remove_slice(slice_id=s.get_slice_id())
            self.enforceSliceNotInDatabase(db=db, slice_id=s.get_slice_id())

            kernel.register_slice(slice_object=s)
            self.enforceSliceExistsInDatabase(db=db, slice_id=s.get_slice_id())
            self.assertIsNotNone(kernel.get_slice(slice_id=s.get_slice_id()))
示例#28
0
    def test_h_unregister_slice_empty(self):
        actor = self.prepare_actor()
        kernel = self.get_kernel_wrapper(actor=actor)
        db = actor.get_plugin().get_database()

        slices = []

        for i in range(10):
            slice_obj = SliceFactory.create(slice_id=ID(),
                                            name="Slice:{}".format(i))
            slices.append(slice_obj)
            kernel.register_slice(slice_object=slice_obj)

        for s in slices:
            kernel.unregister_slice(slice_id=s.get_slice_id())
            check = kernel.get_slice(slice_id=s.get_slice_id())
            self.assertIsNone(check)
            self.enforceSliceExistsInDatabase(db=db, slice_id=s.get_slice_id())

            failed = False
            try:
                kernel.unregister_slice(slice_id=s.get_slice_id())
            except Exception:
                failed = True

            self.assertTrue(failed)
            self.enforceSliceExistsInDatabase(db=db, slice_id=s.get_slice_id())
示例#29
0
    def reclaim_delegation_client(self, *, delegation_id: str = None, slice_object: ABCSlice = None,
                                  broker: ABCBrokerProxy = None, id_token: str = None) -> ABCDelegation:
        if delegation_id is None:
            raise BrokerException(error_code=ExceptionErrorCode.INVALID_ARGUMENT, msg="delegation_id")

        if broker is None:
            broker = self.get_default_broker()

        if slice_object is None:
            slice_object = self.get_default_slice()
            if slice_object is None:
                slice_object = SliceFactory.create(slice_id=ID(), name=self.identity.get_name())
                slice_object.set_owner(owner=self.identity)
                slice_object.set_inventory(value=True)

        delegation = BrokerDelegationFactory.create(did=delegation_id, slice_id=slice_object.get_slice_id(),
                                                    broker=broker)
        delegation.set_slice_object(slice_object=slice_object)
        delegation.set_exported(value=True)

        callback = ActorRegistrySingleton.get().get_callback(protocol=Constants.PROTOCOL_KAFKA,
                                                             actor_name=self.get_name())
        if callback is None:
            raise BrokerException(error_code=ExceptionErrorCode.NOT_SUPPORTED, msg="callback is None")

        delegation.prepare(callback=callback, logger=self.logger)
        delegation.validate_outgoing()

        self.wrapper.reclaim_delegation_request(delegation=delegation, caller=broker, callback=callback,
                                                id_token=id_token)

        return delegation
示例#30
0
    def get_slices(self,
                   email: str = None,
                   slice_id: str = None,
                   slice_name: str = None):
        try:
            if slice_id is not None:
                slice_obj = self.db.get_slice(slice_id=ID(uid=slice_id))
                slice_list = [slice_obj]
            elif email is not None:
                slice_list = self.db.get_slice_by_email(email=email)
            else:
                slice_list = self.db.get_slices()

            if slice_list is not None and len(slice_list) > 0:
                for s in slice_list:
                    show_slice = slice_name is None
                    if slice_name is not None:
                        show_slice = slice_name in s.get_name()
                    if show_slice:
                        print(s)
                        print()
            else:
                print(f"No slices found: {slice_list}")
        except Exception as e:
            print(f"Exception occurred while fetching slices: {e}")
            traceback.print_exc()