Example #1
0
 def _compile(self, item, parent=None):
     """Compiles a item (pattern, task) into a graph + tree node."""
     item_compiler = misc.match_type(item, self._matchers)
     if item_compiler is not None:
         self._pre_item_compile(item)
         graph, node = item_compiler.compile(item, parent=parent)
         self._post_item_compile(item, graph, node)
         return graph, node
     else:
         raise TypeError("Unknown object '%s' (%s) requested to compile"
                         % (item, type(item)))
Example #2
0
    def ensure_atoms(self, atoms):
        """Ensure there is an atomdetail for **each** of the given atoms.

        Returns list of atomdetail uuids for each atom processed.
        """
        atom_ids = []
        missing_ads = []
        for i, atom in enumerate(atoms):
            match = misc.match_type(atom, self._ensure_matchers)
            if not match:
                raise TypeError("Unknown atom '%s' (%s) requested to ensure" %
                                (atom, type(atom)))
            atom_detail_cls, kind = match
            atom_name = atom.name
            if not atom_name:
                raise ValueError("%s name must be non-empty" % (kind))
            try:
                atom_id = self._atom_name_to_uuid[atom_name]
            except KeyError:
                missing_ads.append((i, atom, atom_detail_cls))
                # This will be later replaced with the uuid that is created...
                atom_ids.append(None)
            else:
                ad = self._flowdetail.find(atom_id)
                if not isinstance(ad, atom_detail_cls):
                    raise exceptions.Duplicate(
                        "Atom detail '%s' already exists in flow"
                        " detail '%s'" % (atom_name, self._flowdetail.name))
                else:
                    atom_ids.append(ad.uuid)
                    self._set_result_mapping(atom_name, atom.save_as)
        if missing_ads:
            needs_to_be_created_ads = []
            for (i, atom, atom_detail_cls) in missing_ads:
                ad = self._create_atom_detail(
                    atom.name,
                    atom_detail_cls,
                    atom_version=misc.get_version_string(atom))
                needs_to_be_created_ads.append((i, atom, ad))
            # Add the atom detail(s) to a clone, which upon success will be
            # updated into the contained flow detail; if it does not get saved
            # then no update will happen.
            source, clone = self._fetch_flowdetail(clone=True)
            for (_i, _atom, ad) in needs_to_be_created_ads:
                clone.add(ad)
            self._with_connection(self._save_flow_detail, source, clone)
            # Insert the needed data, and get outta here...
            for (i, atom, ad) in needs_to_be_created_ads:
                atom_name = atom.name
                atom_ids[i] = ad.uuid
                self._atom_name_to_uuid[atom_name] = ad.uuid
                self._set_result_mapping(atom_name, atom.save_as)
                self._failures.setdefault(atom_name, {})
        return atom_ids
Example #3
0
    def ensure_atoms(self, atoms):
        """Ensure there is an atomdetail for **each** of the given atoms.

        Returns list of atomdetail uuids for each atom processed.
        """
        atom_ids = []
        missing_ads = []
        for i, atom in enumerate(atoms):
            match = misc.match_type(atom, self._ensure_matchers)
            if not match:
                raise TypeError("Unknown atom '%s' (%s) requested to ensure"
                                % (atom, type(atom)))
            atom_detail_cls, kind = match
            atom_name = atom.name
            if not atom_name:
                raise ValueError("%s name must be non-empty" % (kind))
            try:
                atom_id = self._atom_name_to_uuid[atom_name]
            except KeyError:
                missing_ads.append((i, atom, atom_detail_cls))
                # This will be later replaced with the uuid that is created...
                atom_ids.append(None)
            else:
                ad = self._flowdetail.find(atom_id)
                if not isinstance(ad, atom_detail_cls):
                    raise exceptions.Duplicate(
                        "Atom detail '%s' already exists in flow"
                        " detail '%s'" % (atom_name, self._flowdetail.name))
                else:
                    atom_ids.append(ad.uuid)
                    self._set_result_mapping(atom_name, atom.save_as)
        if missing_ads:
            needs_to_be_created_ads = []
            for (i, atom, atom_detail_cls) in missing_ads:
                ad = self._create_atom_detail(
                    atom.name, atom_detail_cls,
                    atom_version=misc.get_version_string(atom))
                needs_to_be_created_ads.append((i, atom, ad))
            # Add the atom detail(s) to a clone, which upon success will be
            # updated into the contained flow detail; if it does not get saved
            # then no update will happen.
            source, clone = self._fetch_flowdetail(clone=True)
            for (_i, _atom, ad) in needs_to_be_created_ads:
                clone.add(ad)
            self._with_connection(self._save_flow_detail, source, clone)
            # Insert the needed data, and get outta here...
            for (i, atom, ad) in needs_to_be_created_ads:
                atom_name = atom.name
                atom_ids[i] = ad.uuid
                self._atom_name_to_uuid[atom_name] = ad.uuid
                self._set_result_mapping(atom_name, atom.save_as)
                self._failures.setdefault(atom_name, {})
        return atom_ids
Example #4
0
    def ensure_atom(self, atom):
        """Ensure that there is an atomdetail in storage for the given atom.

        Returns uuid for the atomdetail that is/was created.
        """
        match = misc.match_type(atom, self._ensure_matchers)
        if not match:
            raise TypeError("Unknown atom '%s' (%s) requested to ensure"
                            % (atom, type(atom)))
        else:
            detail_cls, kind = match
            atom_id = self._ensure_atom_detail(kind, detail_cls, atom.name,
                                               misc.get_version_string(atom),
                                               atom.save_as)
            return atom_id