def proceedWithChoice(self, index, agent):
     if agent:
         self.unit.setVariable("activeAgent", agent, None)
     choicesAvailableForUnitsLock.acquire()
     del choicesAvailableForUnits[self.jobChainLink.UUID]
     choicesAvailableForUnitsLock.release()
     
     #get the one at index, and go with it.
     choiceIndex, description, replacementDic2 = self.choices[int(index)]
     rd = replacementDic(eval(replacementDic2))
     if self.jobChainLink.passVar != None:
         if isinstance(self.jobChainLink.passVar, list):
             found = False
             for passVar in self.jobChainLink.passVar:
                 if isinstance(self.jobChainLink.passVar, replacementDic):
                     new = {}
                     new.update(self.jobChainLink.passVar.dic)
                     new.update(rd.dic)
                     rd.dic = [new]
                     found = True
                     break
             if not found:
                 self.jobChainLink.passVar.append(rd)
                 rd = self.jobChainLink.passVar 
     else:
         rd = [rd]
     self.jobChainLink.linkProcessingComplete(0, rd)
    def proceedWithChoice(self, index, agent):
        if agent:
            self.unit.setVariable("activeAgent", agent, None)
        choicesAvailableForUnitsLock.acquire()
        del choicesAvailableForUnits[self.jobChainLink.UUID]
        choicesAvailableForUnitsLock.release()
        #while archivematicaMCP.transferDMovedFromCounter.value != 0:
        #    print "Waiting for all files to finish updating their location in the database"
        #    print transferD.movedFrom
        #    time.sleep(1)

        #get the one at index, and go with it.
        choiceIndex, description, replacementDic2 = self.choices[int(index)]
        rd = replacementDic(eval(replacementDic2))
        if self.jobChainLink.passVar != None:
            if isinstance(self.jobChainLink.passVar, list):
                found = False
                for passVar in self.jobChainLink.passVar:
                    if isinstance(self.jobChainLink.passVar, replacementDic):
                        new = {}
                        new.update(self.jobChainLink.passVar.dic)
                        new.update(rd.dic)
                        rd.dic = [new]
                        found = True
                        break
                if not found:
                    self.jobChainLink.passVar.append(rd)
                    rd = self.jobChainLink.passVar
        else:
            rd = [rd]
        self.jobChainLink.linkProcessingComplete(0, rd)
 def proceedWithChoice(self, index):
     choicesAvailableForUnitsLock.acquire()
     del choicesAvailableForUnits[self.jobChainLink.UUID]
     choicesAvailableForUnitsLock.release()
     #while archivematicaMCP.transferDMovedFromCounter.value != 0:
     #    print "Waiting for all files to finish updating their location in the database"
     #    print transferD.movedFrom
     #    time.sleep(1)
     
     #get the one at index, and go with it.
     choiceIndex, description, replacementDic2 = self.choices[int(index)]
     rd = replacementDic(eval(replacementDic2))
     if self.jobChainLink.passVar != None:
         if isinstance(self.jobChainLink.passVar, list):
             found = False
             for passVar in self.jobChainLink.passVar:
                 if isinstance(self.jobChainLink.passVar, replacementDic):
                     new = {}
                     new.update(self.jobChainLink.passVar.dic)
                     new.update(rd.dic)
                     rd.dic = [new]
                     found = True
                     break
             if not found:
                 self.jobChainLink.passVar.append(rd)
                 rd = self.jobChainLink.passVar 
     else:
         rd = [rd]
     self.jobChainLink.linkProcessingComplete(0, rd)
     
Example #4
0
    def proceedWithChoice(self, index, agent):
        if agent:
            self.unit.setVariable("activeAgent", agent, None)
        choicesAvailableForUnitsLock.acquire()
        del choicesAvailableForUnits[self.jobChainLink.UUID]
        choicesAvailableForUnitsLock.release()

        #get the one at index, and go with it.
        choiceIndex, description, replacementDic2 = self.choices[int(index)]
        rd = replacementDic(eval(replacementDic2))
        if self.jobChainLink.passVar != None:
            if isinstance(self.jobChainLink.passVar, list):
                found = False
                for passVar in self.jobChainLink.passVar:
                    if isinstance(self.jobChainLink.passVar, replacementDic):
                        new = {}
                        new.update(self.jobChainLink.passVar.dic)
                        new.update(rd.dic)
                        rd.dic = [new]
                        found = True
                        break
                if not found:
                    self.jobChainLink.passVar.append(rd)
                    rd = self.jobChainLink.passVar
        else:
            rd = [rd]
        self.jobChainLink.linkProcessingComplete(0, rd)
Example #5
0
    def __init__(self, jobChainLink, pk, unit):
        super(linkTaskManagerReplacementDicFromChoice,
              self).__init__(jobChainLink, pk, unit)

        self.choices = []
        dicts = MicroServiceChoiceReplacementDic.objects.filter(
            choiceavailableatlink=str(jobChainLink.pk))
        for i, dic in enumerate(dicts):
            self.choices.append((i, dic.description, dic.replacementdic))

        preConfiguredChain = self.checkForPreconfiguredXML()
        if preConfiguredChain != None:
            if preConfiguredChain != waitingOnTimer:
                self.jobChainLink.setExitMessage("Completed successfully")
                rd = ReplacementDict.fromstring(preConfiguredChain)
                self.update_passvar_replacement_dict(rd)
                self.jobChainLink.linkProcessingComplete(
                    0, passVar=self.jobChainLink.passVar)
            else:
                LOGGER.info('Waiting on delay to resume processing on unit %s',
                            unit)
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage('Awaiting decision')
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()
Example #6
0
    def __init__(self, jobChainLink, pk, unit):
        super(linkTaskManagerReplacementDicFromChoice,
              self).__init__(jobChainLink, pk, unit)

        self.choices = []
        dicts = MicroServiceChoiceReplacementDic.objects.filter(
            choiceavailableatlink=str(jobChainLink.pk))
        for i, dic in enumerate(dicts):
            self.choices.append((i, dic.description, dic.replacementdic))

        # There are MicroServiceChoiceReplacementDic links with no
        # replacements (``self.choices`` has zero elements at this point). This
        # is true for the following chain links:
        #
        #   - ``Choose Config for Archivists Toolkit DIP Upload``
        #   - ``Choose config for AtoM DIP upload``
        #   - ``Choose Config for ArchivesSpace DIP Upload``
        #
        # The only purpose of these links is to  load settings from the
        # Dashboard configuration store (``DashboardSetting``), e.g.
        # connection details or credentials that are needed to perform the
        # upload of the DIP to the remote system.
        #
        # Once the settings are loaded, we proceed with the next chain link
        # automatically instead of prompting the user with a single choice
        # which was considered inconvenient and confusing. In the future, it
        # should be possible to prompt the user only if we want to have the
        # user decide between multiple configurations, e.g. more than one
        # AtoM instance is available and the user wants to decide which one is
        # going to be used.
        rdict = self._get_dashboard_setting_choice()
        if rdict and not self.choices:
            LOGGER.debug('Found Dashboard settings for this task, proceed.')
            self.update_passvar_replacement_dict(rdict)
            self.jobChainLink.linkProcessingComplete(
                0, passVar=self.jobChainLink.passVar)
            return

        preConfiguredChain = self.checkForPreconfiguredXML()
        if preConfiguredChain is not None:
            if preConfiguredChain != waitingOnTimer:
                self.jobChainLink.setExitMessage(
                    Job.STATUS_COMPLETED_SUCCESSFULLY)
                rd = ReplacementDict.fromstring(preConfiguredChain)
                self.update_passvar_replacement_dict(rd)
                self.jobChainLink.linkProcessingComplete(
                    0, passVar=self.jobChainLink.passVar)
            else:
                LOGGER.info('Waiting on delay to resume processing on unit %s',
                            unit)
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage(Job.STATUS_AWAITING_DECISION)
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()
    def __init__(self, jobChainLink, pk, unit):
        self.choices = []
        self.pk = pk
        self.jobChainLink = jobChainLink
        self.UUID = uuid.uuid4().__str__()
        self.unit = unit
        sql = """SELECT replacementDic, description FROM MicroServiceChoiceReplacementDic WHERE choiceAvailableAtLink = '%s'""" % (
            jobChainLink.pk.__str__())
        c, sqlLock = databaseInterface.querySQL(sql)
        row = c.fetchone()
        choiceIndex = 0
        while row != None:
            print row
            replacementDic_ = row[0]
            description_ = row[1]
            self.choices.append((choiceIndex, description_, replacementDic_))
            row = c.fetchone()
            choiceIndex += 1
        sqlLock.release()
        #print "choices", self.choices

        preConfiguredChain = self.checkForPreconfiguredXML()
        if preConfiguredChain != None:
            if preConfiguredChain != waitingOnTimer:
                #time.sleep(archivematicaMCP.config.getint('MCPServer', "waitOnAutoApprove"))
                #print "checking for xml file for processing rules. TODO"
                self.jobChainLink.setExitMessage("Completed successfully")
                #jobChain.jobChain(self.unit, preConfiguredChain)
                rd = replacementDic(eval(preConfiguredChain))
                if self.jobChainLink.passVar != None:
                    if isinstance(self.jobChainLink.passVar, list):
                        found = False
                        for passVar in self.jobChainLink.passVar:
                            if isinstance(self.jobChainLink.passVar,
                                          replacementDic):
                                new = {}
                                new.update(self.jobChainLink.passVar.dic)
                                new.update(rd.dic)
                                rd.dic = [new]
                                found = True
                                break
                        if not found:
                            self.jobChainLink.passVar.append(rd)
                            rd = self.jobChainLink.passVar
                else:
                    rd = [rd]
                self.jobChainLink.linkProcessingComplete(0, rd)
            else:
                print "waiting on delay to resume processing on unit:", unit
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage('Awaiting decision')
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()
Example #8
0
    def __init__(self, jobChainLink, pk, unit):
        super(linkTaskManagerReplacementDicFromChoice,
              self).__init__(jobChainLink, pk, unit)

        self.choices = []
        dicts = MicroServiceChoiceReplacementDic.objects.filter(
            choiceavailableatlink=str(jobChainLink.pk))
        for i, dic in enumerate(dicts):
            self.choices.append((i, dic.description, dic.replacementdic))

        # This is an attempt to find a choice in DashboardSettings for the
        # chain link that the current MicroServiceChoiceReplacementDic is
        # taking us. We're looking up the setting dict by the module name
        # that the StandardTaskConfig wants to execute, e.g. upload-qubit_v0.0.
        #
        # Not implemented yet, but this could enable us to store more than a
        # configuration set a specific chain link.
        #
        # DashboardSettings does not belong to MCPServer. We currently have
        # direct access to the database but that may not be always possible.
        try:
            mscl = MicroServiceChainLink.objects.get(id=jobChainLink.pk)
            task_id = mscl.defaultnextchainlink.currenttask.tasktypepkreference
            stc = StandardTaskConfig.objects.get(id=task_id)
        except (MicroServiceChainLink.DoesNotExist,
                StandardTaskConfig.DoesNotExist, AttributeError):
            pass
        else:
            args = DashboardSetting.objects.get_dict(stc.execute)
            if args:
                args = {
                    '%{}%'.format(key): value
                    for key, value in args.items()
                }
                self.choices.append(
                    (len(self.choices), stc.execute, str(args)))

        preConfiguredChain = self.checkForPreconfiguredXML()
        if preConfiguredChain is not None:
            if preConfiguredChain != waitingOnTimer:
                self.jobChainLink.setExitMessage(
                    Job.STATUS_COMPLETED_SUCCESSFULLY)
                rd = ReplacementDict.fromstring(preConfiguredChain)
                self.update_passvar_replacement_dict(rd)
                self.jobChainLink.linkProcessingComplete(
                    0, passVar=self.jobChainLink.passVar)
            else:
                LOGGER.info('Waiting on delay to resume processing on unit %s',
                            unit)
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage(Job.STATUS_AWAITING_DECISION)
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()
    def __init__(self, jobChainLink, pk, unit):
        self.choices = []
        self.pk = pk
        self.jobChainLink = jobChainLink
        self.UUID = uuid.uuid4().__str__()
        self.unit = unit
        sql = """SELECT replacementDic, description FROM MicroServiceChoiceReplacementDic WHERE choiceAvailableAtLink = """ + jobChainLink.pk.__str__()
        c, sqlLock = databaseInterface.querySQL(sql)
        row = c.fetchone()
        choiceIndex = 0
        while row != None:
            print row
            replacementDic_ = row[0]
            description_ = row[1]
            self.choices.append((choiceIndex, description_, replacementDic_))
            row = c.fetchone()
            choiceIndex += 1
        sqlLock.release()
        #print "choices", self.choices

        preConfiguredChain = self.checkForPreconfiguredXML()
        if preConfiguredChain != None:
            if preConfiguredChain != waitingOnTimer:
                #time.sleep(archivematicaMCP.config.getint('MCPServer', "waitOnAutoApprove"))
                #print "checking for xml file for processing rules. TODO"
                self.jobChainLink.setExitMessage("Completed successfully")
                #jobChain.jobChain(self.unit, preConfiguredChain)
                rd = replacementDic(eval(preConfiguredChain))
                if self.jobChainLink.passVar != None:
                    if isinstance(self.jobChainLink.passVar, list):
                        found = False
                        for passVar in self.jobChainLink.passVar:
                            if isinstance(self.jobChainLink.passVar, replacementDic):
                                new = {}
                                new.update(self.jobChainLink.passVar.dic)
                                new.update(rd.dic)
                                rd.dic = [new]
                                found = True
                                break
                        if not found:
                            self.jobChainLink.passVar.append(rd)
                            rd = self.jobChainLink.passVar 
                else:
                    rd = [rd]
                self.jobChainLink.linkProcessingComplete(0, rd)
            else:
                print "waiting on delay to resume processing on unit:", unit
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage('Awaiting decision')
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()
Example #10
0
    def proceedWithChoice(self, index, agent):
        if agent:
            self.unit.setVariable("activeAgent", agent, None)
        choicesAvailableForUnitsLock.acquire()
        del choicesAvailableForUnits[self.jobChainLink.UUID]
        choicesAvailableForUnitsLock.release()

        #get the one at index, and go with it.
        choiceIndex, description, replacementDic2 = self.choices[int(index)]
        rd = ReplacementDict.fromstring(replacementDic2)
        self.update_passvar_replacement_dict(rd)
        self.jobChainLink.linkProcessingComplete(
            0, passVar=self.jobChainLink.passVar)
Example #11
0
    def proceedWithChoice(self, index, user_id):
        if user_id:
            agent_id = UserProfile.objects.get(user_id=int(user_id)).agent_id
            agent_id = str(agent_id)
            self.unit.setVariable("activeAgent", agent_id, None)

        choicesAvailableForUnitsLock.acquire()
        del choicesAvailableForUnits[self.jobChainLink.UUID]
        choicesAvailableForUnitsLock.release()

        # get the one at index, and go with it.
        __, __, items = self.choices[int(index)]
        self.update_passvar_replacement_dict(ReplacementDict(items))
        self.jobChainLink.linkProcessingComplete(0, passVar=self.jobChainLink.passVar)
    def __init__(self, jobChainLink, unit):
        super(linkTaskManagerGetUserChoiceFromMicroserviceGeneratedList,
              self).__init__(jobChainLink, unit)

        self._populate_choices()

        preConfiguredIndex = self.checkForPreconfiguredXML()
        if preConfiguredIndex is not None:
            self.jobChainLink.setExitMessage(Job.STATUS_COMPLETED_SUCCESSFULLY)
            self.proceedWithChoice(index=preConfiguredIndex, user_id=None)
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage(Job.STATUS_AWAITING_DECISION)
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()
Example #13
0
    def __init__(self, jobChainLink, pk, unit):
        super(linkTaskManagerGetUserChoiceFromMicroserviceGeneratedList,
              self).__init__(jobChainLink, pk, unit)
        self.choices = []
        stc = StandardTaskConfig.objects.get(id=str(pk))
        key = stc.execute

        choiceIndex = 0
        if isinstance(self.jobChainLink.passVar, list):
            for item in self.jobChainLink.passVar:
                LOGGER.debug('%s is ChoicesDict: %s', item,
                             isinstance(item, ChoicesDict))
                if isinstance(item, ChoicesDict):
                    # For display, convert the ChoicesDict passVar into a list
                    # of tuples: (index, description, replacement dict string)
                    for description, value in item.items():
                        replacementDic_ = str({key: value})
                        self.choices.append(
                            (choiceIndex, description, replacementDic_))
                        choiceIndex += 1
                    break
            else:
                LOGGER.error("ChoicesDict not found in passVar: %s",
                             self.jobChainLink.passVar)
                raise Exception("ChoicesDict not found in passVar: {}".format(
                    self.jobChainLink.passVar))
        else:
            LOGGER.error("passVar is %s instead of expected list",
                         type(self.jobChainLink.passVar))
            raise Exception("passVar is {} instead of expected list".format(
                type(self.jobChainLink.passVar)))

        LOGGER.info('Choices: %s', self.choices)

        preConfiguredIndex = self.checkForPreconfiguredXML()
        if preConfiguredIndex is not None:
            self.jobChainLink.setExitMessage("Completed successfully")
            self.proceedWithChoice(index=preConfiguredIndex, user_id=None)
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage('Awaiting decision')
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()
Example #14
0
    def proceedWithChoice(self, index, user_id):
        if user_id:
            agent_id = UserProfile.objects.get(user_id=int(user_id)).agent_id
            agent_id = str(agent_id)
            self.unit.setVariable("activeAgent", agent_id, None)

        choicesAvailableForUnitsLock.acquire()
        try:
            del choicesAvailableForUnits[self.jobChainLink.UUID]
        except KeyError:
            pass
        choicesAvailableForUnitsLock.release()

        # get the one at index, and go with it.
        _, _, replace_dict = self.choices[int(index)]
        rd = ReplacementDict.fromstring(replace_dict)
        self.update_passvar_replacement_dict(rd)
        self.jobChainLink.linkProcessingComplete(
            0, passVar=self.jobChainLink.passVar)
    def __init__(self, jobChainLink, pk, unit):
        self.choices = []
        self.pk = pk
        self.jobChainLink = jobChainLink
        self.UUID = uuid.uuid4().__str__()
        self.unit = unit
        sql = sql = """SELECT execute FROM StandardTasksConfigs where pk = '%s'""" % (
            pk)
        c, sqlLock = databaseInterface.querySQL(sql)
        row = c.fetchone()
        choiceIndex = 0
        while row != None:
            print row
            key = row[0]
            #self.choices.append((choiceIndex, description_, replacementDic_))
            row = c.fetchone()
            #choiceIndex += 1
        sqlLock.release()
        if isinstance(self.jobChainLink.passVar, list):
            found = False
            for item in self.jobChainLink.passVar:
                print >> sys.stderr
                print >> sys.stderr
                print >> sys.stderr
                print >> sys.stderr, isinstance(item, choicesDic), item
                if isinstance(item, choicesDic):
                    for description_, value in item.dic.iteritems():
                        replacementDic_ = {key: value}.__str__()
                        self.choices.append(
                            (choiceIndex, description_, replacementDic_))
                        choiceIndex += 1
                    found = True
                    break
            if not found:
                print >> sys.stderr, "self.jobChainLink.passVar", self.jobChainLink.passVar
                throw(exception2)
        else:
            throw(exception)

        print "choices", self.choices

        preConfiguredChain = self.checkForPreconfiguredXML()
        if preConfiguredChain != None:
            if preConfiguredChain != waitingOnTimer:
                #time.sleep(archivematicaMCP.config.getint('MCPServer', "waitOnAutoApprove"))
                #print "checking for xml file for processing rules. TODO"
                self.jobChainLink.setExitMessage("Completed successfully")
                #jobChain.jobChain(self.unit, preConfiguredChain)
                rd = replacementDic(eval(preConfiguredChain))
                if self.jobChainLink.passVar != None:
                    if isinstance(self.jobChainLink.passVar, list):
                        found = False
                        for passVar in self.jobChainLink.passVar:
                            if isinstance(self.jobChainLink.passVar,
                                          replacementDic):
                                new = {}
                                new.update(self.jobChainLink.passVar.dic)
                                new.update(rd.dic)
                                rd.dic = [new]
                                found = True
                                break
                        if not found:
                            self.jobChainLink.passVar.append(rd)
                            rd = self.jobChainLink.passVar
                else:
                    rd = [rd]
                self.jobChainLink.linkProcessingComplete(0, rd)
            else:
                print "waiting on delay to resume processing on unit:", unit
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage('Awaiting decision')
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()
    def __init__(self, jobChainLink, pk, unit):
        self.choices = []
        self.pk = pk
        self.jobChainLink = jobChainLink
        self.UUID = uuid.uuid4().__str__()
        self.unit = unit
        sql = """SELECT execute FROM StandardTasksConfigs where pk = """ + pk.__str__()
        c, sqlLock = databaseInterface.querySQL(sql)
        row = c.fetchone()
        choiceIndex = 0
        while row != None:
            print row
            key = row[0]
            #self.choices.append((choiceIndex, description_, replacementDic_))
            row = c.fetchone()
            #choiceIndex += 1
        sqlLock.release()
        if isinstance(self.jobChainLink.passVar, list):
            found = False
            for item in self.jobChainLink.passVar:
                print >>sys.stderr
                print >>sys.stderr
                print >>sys.stderr
                print >>sys.stderr, isinstance(item, choicesDic), item
                if isinstance(item, choicesDic):
                    for description_, value in item.dic.iteritems():
                        replacementDic_ = {key: value}.__str__()
                        self.choices.append((choiceIndex, description_, replacementDic_))
                        choiceIndex += 1
                    found = True
                    break
            if not found:
                print >>sys.stderr, "self.jobChainLink.passVar", self.jobChainLink.passVar
                throw(exception2)
        else:
            throw(exception)

        print "choices", self.choices

        preConfiguredChain = self.checkForPreconfiguredXML()
        if preConfiguredChain != None:
            if preConfiguredChain != waitingOnTimer:
                #time.sleep(archivematicaMCP.config.getint('MCPServer', "waitOnAutoApprove"))
                #print "checking for xml file for processing rules. TODO"
                self.jobChainLink.setExitMessage("Completed successfully")
                #jobChain.jobChain(self.unit, preConfiguredChain)
                rd = replacementDic(eval(preConfiguredChain))
                if self.jobChainLink.passVar != None:
                    if isinstance(self.jobChainLink.passVar, list):
                        found = False
                        for passVar in self.jobChainLink.passVar:
                            if isinstance(self.jobChainLink.passVar, replacementDic):
                                new = {}
                                new.update(self.jobChainLink.passVar.dic)
                                new.update(rd.dic)
                                rd.dic = [new]
                                found = True
                                break
                        if not found:
                            self.jobChainLink.passVar.append(rd)
                            rd = self.jobChainLink.passVar 
                else:
                    rd = [rd]
                self.jobChainLink.linkProcessingComplete(0, rd)
            else:
                print "waiting on delay to resume processing on unit:", unit
        else:
            choicesAvailableForUnitsLock.acquire()
            self.jobChainLink.setExitMessage('Awaiting decision')
            choicesAvailableForUnits[self.jobChainLink.UUID] = self
            choicesAvailableForUnitsLock.release()