<s> from nailgun . api . v1 . validators . base import BasicValidator <EOL> from nailgun . api . v1 . validators . json_schema import base_types <EOL> from nailgun . api . v1 . validators . json_schema import tasks <EOL> from nailgun import consts <EOL> from nailgun import errors <EOL> from nailgun import objects <EOL> from nailgun . orchestrator import orchestrator_graph <EOL> class GraphSolverTasksValidator ( BasicValidator ) : <EOL> @ classmethod <EOL> def validate_update ( cls , data , instance ) : <EOL> parsed = cls . validate ( data ) <EOL> cls . validate_schema ( parsed , tasks . TASKS_SCHEMA ) <EOL> return parsed <EOL> class TaskDeploymentValidator ( BasicValidator ) : <EOL> @ classmethod <EOL> def validate_tasks ( cls , tasks , cluster , graph_type ) : <EOL> """<STR_LIT>""" <EOL> cls . validate_schema ( tasks , base_types . STRINGS_ARRAY ) <EOL> deployment_tasks = objects . Cluster . get_deployment_tasks ( <EOL> cluster , graph_type ) <EOL> graph = orchestrator_graph . GraphSolver ( ) <EOL> graph . add_tasks ( deployment_tasks ) <EOL> non_existent_tasks = set ( tasks ) - set ( graph . nodes ( ) ) <EOL> if non_existent_tasks : <EOL> raise errors . InvalidData ( <EOL> '<STR_LIT>' . format ( <EOL> '<STR_LIT:U+002C>' . join ( non_existent_tasks ) ) ) <EOL> return tasks <EOL> @ classmethod <EOL> def validate_tasks_types ( cls , types ) : <EOL> """<STR_LIT>""" <EOL> cls . validate_schema ( types , base_types . STRINGS_ARRAY ) <EOL> non_existent_types = set ( types ) - set ( consts . INTERNAL_TASKS ) <EOL> if non_existent_types : <EOL> raise errors . InvalidData ( "<STR_LIT>" . format ( <EOL> '<STR_LIT:U+002C>' . join ( non_existent_types ) ) ) <EOL> return types <EOL> class GraphSolverVisualizationValidator ( TaskDeploymentValidator ) : <EOL> @ classmethod <EOL> def validate ( cls , data , cluster , graph_type ) : <EOL> """<STR_LIT>""" <EOL> tasks = list ( set ( data . split ( '<STR_LIT:U+002C>' ) ) ) <EOL> return cls . validate_tasks ( tasks , cluster , graph_type ) <EOL> @ classmethod <EOL> def validate_task_presence ( cls , task , graph ) : <EOL> """<STR_LIT>""" <EOL> if not graph . has_node ( task ) : <EOL> raise errors . InvalidData ( <EOL> '<STR_LIT>' . format ( task ) ) <EOL> return task </s>
