Exemplo n.º 1
0
 def validate(self, task, part_info, params):
     returns = task.post(self.child["validate"], params)
     ret = []
     for k, v in returns.items():
         if serialize_object(params[k]) != serialize_object(v):
             ret.append(ParameterTweakInfo(k, v))
     return ret
Exemplo n.º 2
0
 def validate(self, task, part_info, params):
     returns = task.post(self.child["validate"], params)
     ret = []
     for k, v in returns.items():
         if serialize_object(params[k]) != serialize_object(v):
             ret.append(ParameterTweakInfo(k, v))
     return ret
Exemplo n.º 3
0
 def validate(self, context, part_info, params):
     child = context.block_view(self.params.mri)
     returns = child.validate(**params)
     ret = []
     for k, v in returns.items():
         if serialize_object(params[k]) != serialize_object(v):
             ret.append(ParameterTweakInfo(k, v))
     return ret
Exemplo n.º 4
0
 def validate(self, context, **kwargs):
     # type: (AContext, **Any) -> UParameterTweakInfos
     child = context.block_view(self.mri)
     returns = child.validate(**kwargs)
     ret = []
     for k, v in serialize_object(returns).items():
         if serialize_object(kwargs[k]) != v:
             ret.append(ParameterTweakInfo(k, v))
     return ret
 def _send_to_client(self, response):
     if isinstance(response.context, MalcWebSocketHandler):
         message = json.dumps(serialize_object(response))
         response.context.write_message(message)
     else:
         if isinstance(response, Return):
             message = json.dumps(serialize_object(response.value))
             response.context.finish(message + "\n")
         else:
             if isinstance(response, Error):
                 message = response.message
             else:
                 message = "Unknown response %s" % type(response)
             response.context.set_status(500, message)
             response.context.write_error(500)
Exemplo n.º 6
0
    def send_put(self, mri, attribute_name, value):
        """Abstract method to dispatch a Put to the server

        Args:
            mri (str): The mri of the Block
            attribute_name (str): The name of the Attribute within the Block
            value: The value to put
        """
        path = attribute_name + ".value"
        typ, value = convert_to_type_tuple_value(serialize_object(value))
        if isinstance(typ, tuple):
            # Structure, make into a Value
            _, typeid, fields = typ
            value = Value(Type(fields, typeid), value)
        try:
            self._ctxt.put(mri, {path: value}, path)
        except RemoteError:
            if attribute_name == "exports":
                # TODO: use a tag instead of a name
                # This will change the structure of the block
                # Wait for reconnect
                self._queues[mri].get(timeout=DEFAULT_TIMEOUT)
            else:
                # Not expected, raise
                raise
Exemplo n.º 7
0
 def load(self, context, structure):
     # type: (AContext, AStructure) -> None
     child = context.block_view(self.mri)
     iterations = {}  # type: Dict[int, Dict[str, Tuple[Attribute, Any]]]
     for k, v in structure.items():
         try:
             attr = getattr(child, k)
         except KeyError:
             self.log.warning("Cannot restore non-existant attr %s" % k)
         else:
             tag = get_config_tag(attr.meta.tags)
             if tag:
                 iteration = int(tag.split(":")[1])
                 iterations.setdefault(iteration, {})[k] = (attr, v)
             else:
                 self.log.warning(
                     "Attr %s is not config tagged, not restoring" % k)
     # Do this first so that any callbacks that happen in the put know
     # not to notify controller
     self.saved_structure = structure
     for name, params in sorted(iterations.items()):
         # Call each iteration as a separate operation, only putting the
         # ones that need to change
         to_set = {}
         for k, (attr, v) in params.items():
             try:
                 np.testing.assert_equal(serialize_object(attr.value), v)
             except AssertionError:
                 to_set[k] = v
         child.put_attribute_values(to_set)
Exemplo n.º 8
0
 def save(self, task):
     part_structure = OrderedDict()
     for k in self.child:
         attr = self.child[k]
         if isinstance(attr, Attribute) and "config" in attr.meta.tags:
             part_structure[k] = serialize_object(attr.value)
     return part_structure
Exemplo n.º 9
0
    def send_to_server(self, request):
        """Dispatch a request to the server

        Args:
            request(Request): The message to pass to the server
        """
        message = json.dumps(serialize_object(request))
        self.conn.result().write_message(message)
Exemplo n.º 10
0
 def save(self, context):
     child = context.block_view(self.params.mri)
     part_structure = OrderedDict()
     for k in child:
         attr = getattr(child, k)
         if isinstance(attr, Attribute) and "config" in attr.meta.tags:
             part_structure[k] = serialize_object(attr.value)
     self.saved_structure = part_structure
     return part_structure
Exemplo n.º 11
0
 def save(self, context):
     # type: (AContext) -> AStructure
     child = context.block_view(self.mri)
     part_structure = OrderedDict()
     for k in child:
         attr = getattr(child, k)
         if isinstance(attr, Attribute) and get_config_tag(attr.meta.tags):
             part_structure[k] = serialize_object(attr.value)
     self.saved_structure = part_structure
     return part_structure
Exemplo n.º 12
0
 def handle_post_response(response):
     # type: (Response) -> None
     if isinstance(response, Return):
         if add_wrapper:
             # Method gave us return unpacked (bare string or other type)
             # so we must wrap it in a structure to send it
             ret = {"return": response.value}
         else:
             ret = response.value
         serialized = serialize_object(ret)
         v = convert_dict_to_value(serialized)
         op.done(v)
     else:
         if isinstance(response, Error):
             message = stringify_error(response.message)
         else:
             message = "BadResponse: %s" % response.to_dict()
         op.done(error=message)
Exemplo n.º 13
0
 def load(self, context, structure):
     child = context.block_view(self.params.mri)
     part_structure = structure.get(self.name, {})
     params = {}
     for k, v in part_structure.items():
         try:
             attr = getattr(child, k)
         except AttributeError:
             self.log.warning("Cannot restore non-existant attr %s" % k)
         else:
             try:
                 np.testing.assert_equal(serialize_object(attr.value), v)
             except AssertionError:
                 params[k] = v
     # Do this first so that any callbacks that happen in the put know
     # not to notify controller
     self.saved_structure = part_structure
     if params:
         child.put_attribute_values(params)
Exemplo n.º 14
0
    def send_post(self, mri, method_name, **params):
        """Abstract method to dispatch a Post to the server

        Args:
            mri (str): The mri of the Block
            method_name (str): The name of the Method within the Block
            params: The parameters to send

        Returns:
            The return results from the server
        """
        typ, parameters = convert_to_type_tuple_value(serialize_object(params))
        uri = NTURI(typ[2])

        uri = uri.wrap(path="%s.%s" % (mri, method_name),
                       kws=parameters,
                       scheme="pva")
        value = self._ctxt.rpc(mri, uri, timeout=None)
        return convert_value_to_dict(value)