Beispiel #1
0
 def requires_emit(self, resolver: Resolver, queue: QueueScheduler) -> Dict[object, ResultVariable]:
     try:
         resv = resolver.for_namespace(self.implements.constraint.namespace)
         return self.implements.constraint.requires_emit(resv, queue)
     except NotFoundException as e:
         e.set_statement(self.implements)
         raise e
Beispiel #2
0
    def execute(self, requires: Dict[object, object], instance: Resolver,
                queue: QueueScheduler) -> object:
        """
        Evaluate this statement
        """
        LOGGER.log(LOG_LEVEL_TRACE,
                   "executing subconstructor for %s implement %s", self.type,
                   self.implements.location)
        condition = self.implements.constraint.execute(requires, instance,
                                                       queue)
        try:
            inmanta_type.Bool().validate(condition)
        except RuntimeException as e:
            e.set_statement(self.implements)
            e.msg = (
                "Invalid value `%s`: the condition for a conditional implementation can only be a boolean expression"
                % condition)
            raise e
        if not condition:
            return None

        myqueue = queue.for_tracker(ImplementsTracker(self, instance))

        implementations = self.implements.implementations

        for impl in implementations:
            if instance.add_implementation(impl):
                # generate a subscope/namespace for each loop
                xc = ExecutionContext(
                    impl.statements,
                    instance.for_namespace(impl.statements.namespace))
                xc.emit(myqueue)

        return None
Beispiel #3
0
    def requires_emit(self, resolver: Resolver, queue: QueueScheduler) -> Dict[object, ResultVariable]:
        # direct
        preout = [x for x in self._direct_attributes.items()]
        preout.extend([x for x in self.type.get_entity().get_default_values().items()])

        out2 = {rk: rv for (k, v) in self.type.get_defaults().items()
                for (rk, rv) in v.requires_emit(resolver.for_namespace(v.get_namespace()), queue).items()}

        out = {rk: rv for (k, v) in preout for (rk, rv) in v.requires_emit(resolver, queue).items()}
        out.update(out2)

        return out
Beispiel #4
0
 def execute(self, requires: Dict[object, object], resolver: Resolver,
             queue: QueueScheduler) -> object:
     """
     Evaluate this statement.
     """
     cond: object = self.condition.execute(requires, resolver, queue)
     if isinstance(cond, Unknown):
         return None
     try:
         inmanta_type.Bool().validate(cond)
     except RuntimeException as e:
         e.set_statement(self)
         e.msg = "Invalid value `%s`: the condition for an if statement can only be a boolean expression" % cond
         raise e
     branch: BasicBlock = self.if_branch if cond else self.else_branch
     xc = ExecutionContext(branch, resolver.for_namespace(branch.namespace))
     xc.emit(queue)
     return None
Beispiel #5
0
    def execute(self, requires: Dict[object, ResultVariable], instance: Resolver, queue: QueueScheduler) -> object:
        """
            Evaluate this statement
        """
        expr = self.implements.constraint
        if not expr.execute(requires, instance, queue):
            return None

        myqueue = queue.for_tracker(ImplementsTracker(self, instance))

        implementations = self.implements.implementations

        for impl in implementations:
            if instance.add_implementation(impl):
                # generate a subscope/namespace for each loop
                xc = ExecutionContext(impl.statements, instance.for_namespace(impl.statements.namespace))
                xc.emit(myqueue)

        return None