示例#1
0
 def __init__(self, rid: str, cid: str, manager: ResponseManager, **kwargs):
     super(RestTask,
           self).__init__(rid=rid, cid=cid,
                          **kwargs)  # **{ "rid":rid, "cid":cid, **kwargs }
     self.logger = PC2Logger.getLogger()
     self.manager: ResponseManager = manager
     self._exception = None
示例#2
0
 def __init__(self, **kwargs):
     self.logger = PC2Logger.getLogger()
     self._parms = kwargs
     self._rid = self.getAssignParm("rid")
     self._cid = self.getAssignParm("cid")
     self._clients = kwargs.get("clients", "").split(",")
     self._pollPeriod = float(kwargs.get("pollPeriod", 1.0))
示例#3
0
 def __init__(self, **kwargs):
     self.logger = PC2Logger.getLogger()
     self.cert_dir = os.path.expanduser( kwargs.get("certificate_path", "~/.pc2/zmq" ) )
     self.public_keys_dir = os.path.join( self.cert_dir, 'public_keys' )
     self.secret_keys_dir = os.path.join( self.cert_dir, 'private_keys' )
     if not ( os.path.exists(self.public_keys_dir) and os.path.exists(self.secret_keys_dir) ):
         raise Exception( f"Must copy the contents of the zmq server certificates directory to {self.cert_dir}")
示例#4
0
 def __init__(self, **kwargs):
     super(DemoModule, self).__init__()
     self.logger = PC2Logger.getLogger()
     self.process = "demo"
     self.handlers = {}
     self.processManager = None
     self._epas = ["demo*"]
     atexit.register(self.shutdown, "ShutdownHook Called")
示例#5
0
 def __init__(self, settingsFilePath: str, **kwargs):
     Cmd.__init__(self)
     self.parms = kwargs
     self.logger = PC2Logger.getLogger()
     settings: str = self.abs_path(settingsFilePath)
     self.core = PC2Core(settings)
     self.client: PC2Client = self.core.getClient()
     self.results: Dict[str, TaskHandle] = {}
示例#6
0
文件: base.py 项目: nasa-nccs-cds/pc2
 def __init__(self, htype: str, **kwargs):
     self.logger = PC2Logger.getLogger()
     self.parms = kwargs
     self.name = self['name']
     self.type: str = htype
     htype1 = self.parms.pop("type")
     assert htype1 == htype, "Sanity check of Handler type failed: {} vs {}".format(
         htype1, htype)
示例#7
0
文件: base.py 项目: nasa-nccs-cds/pc2
 def __init__(self, _core: PC2CoreBase, **kwargs):
     Thread.__init__(self)
     self.logger = PC2Logger.getLogger()
     self.core = _core
     self.registeredRequests = set()
     self.requestQueue = queue.Queue()
     self.active_workflows: Dict[str, PC2Workflow] = {}
     self.completed_workflows: Dict[str, PC2Workflow] = {}
     self._active = True
示例#8
0
 def __init__(self, **kwargs):
     self.logger = PC2Logger.getLogger()
     self.nodes: Dict[str, DGNode] = {}
     self.graph = kwargs.get("graph", nx.DiGraph())
     for node in kwargs.get("nodes", []):
         self.add(node)
     self._allow_multiple_outputs = kwargs.get("allow_multiple_outputs",
                                               False)
     self._connected = False
示例#9
0
 def __init__(self, _context: zmq.Context, _response_port: int, **kwargs):
     super(PC2ZMQResponder, self).__init__()
     self.logger = PC2Logger.getLogger()
     self.context: zmq.Context = _context
     self.response_port = _response_port
     self.executing_jobs: Dict[str, PC2Response] = {}
     self.status_reports: Dict[str, str] = {}
     self.client_address = kwargs.get("client_address", "*")
     self.getKeyDir(**kwargs)
     self.socket: zmq.Socket = self.initSocket()
示例#10
0
 def __init__(self, core: Optional[PC2CoreBase], settings: Dict[str, Dict],
              **kwargs):
     self.logger = PC2Logger.getLogger()
     self._core = core
     self._handlers: Dict[str, PC2Factory] = {}
     self._app_handler: PC2Factory = None
     self._internal_clients = str2bool(
         kwargs.get("internal_clients", 'true'))
     self._parms = kwargs
     self._constructors: Dict[str, Callable[[], PC2Factory]] = {}
     self.configSpec: Dict[str, Dict] = settings
     self._init()
示例#11
0
 def __init__(self, cid: str, host_address: str, **kwargs):
     Thread.__init__(self)
     self.logger = PC2Logger.getLogger()
     self.host_address = host_address
     self.active = True
     self.cid = cid
     self.debug = False
     self.setName('PC2 zeromq client Response Thread')
     self.setDaemon(True)
     self.poll_freq = kwargs.get("poll_freq", 0.5)
     self.timeout = kwargs.get("timeout", 60.0)
     self.statusMap: Dict[str, Status] = {}
     self.active_requests = set()
示例#12
0
 def __init__(self, rid: str, cid: str, refs: Dict,
              wpsRequest: WPSExecuteRequest, **kwargs):
     super(RestTask, self).__init__(rid=rid, cid=cid, **kwargs)
     self.logger = PC2Logger.getLogger()
     self.statusUrl: str = refs.get("status", None)
     self.fileUrl: str = refs.get("file", None)
     self.dataUrl: str = refs.get("data", None)
     self.dapUrl: str = refs.get("dap", None)
     self.wpsRequest: WPSExecuteRequest = wpsRequest
     self._exception = None
     self._statMessage = None
     self._status = Status.UNKNOWN
     self.cacheDir: str = self.createCache(**kwargs)
示例#13
0
 def __init__(self, core: PC2Core, **kwargs):
     PC2ServerApp.__init__(self, core, **kwargs)
     self.logger = PC2Logger.getLogger()
     self.active = True
     self.parms = self.getConfigParms('server')
     self.client_address = self.parms.get("client_address", "*")
     self.request_port = self.parms.get("request_port", 4556)
     self.response_port = self.parms.get("response_port", 4557)
     self.logger.info(
         f"Initializing PC2App with parameters {self.parms}, response_port = {self.response_port}"
     )
     self.active_handlers = {}
     self.getCertDirs()
示例#14
0
 def __init__(self, context: zmq.Context, connector: ConnectionMode, rid: str, host: str, port: int, status: Status, cache_dir: str, **kwargs ):
     Thread.__init__(self)
     self.context = context
     self._connector = connector
     self.logger = PC2Logger.getLogger()
     self.host = host
     self.port = port
     self.requestId = rid
     self.active = True
     self.mstate = MessageState.RESULT
     self.setName('PC2 zeromq client Response Thread')
     self.cached_results: queue.Queue[TaskResult] = queue.Queue()
     self.setDaemon(True)
     self.cacheDir = os.path.expanduser( cache_dir )
     self.log("Created RM, cache dir = " + self.cacheDir )
     self._status = status
     self._exception = None
示例#15
0
 def __init__(self, cid: str, manager: ResponseManager, **kwargs):
     super(zmqTask,self).__init__( rid=manager.requestId, cid=cid, **kwargs )
     self.logger = PC2Logger.getLogger()
     self.manager = manager
示例#16
0
 def __init__(self, **kwargs):
     self.parms = kwargs
     self.logger = PC2Logger.getLogger()
示例#17
0
 def __init__(self, inputs: List[str], outputs: List[str] = None, **kwargs):
     self.logger = PC2Logger.getLogger()
     self.params: Dict[str, Any] = kwargs
     self.id = self.get("id", UID.randomId(6))
     self._inputs = inputs
     self._outputs = outputs if outputs is not None else [UID.randomId(6)]
示例#18
0
class PC2Client:
    __metaclass__ = abc.ABCMeta
    logger = PC2Logger.getLogger()

    def __init__(self, type: str, **kwargs):
        cid = kwargs.get("cid")
        self.cid = cid if cid else UID.randomId(6)
        self.type: str = type
        self.name: str = kwargs.get("name")
        self.cache_dir: str = kwargs.get("cache_dir", "~/.edas/cache")
        self.parms = {**kwargs, "cid": self.cid, "type": type}
        self.priority: float = float(self.parm("priority", "0"))
        self.active = False
        self._moduleSpecs: List[ModuleSpec] = None
        self.clients = {self.cid}

    @property
    def handle(self):
        return f"{self.name}:{self.cid}"

    def activate(self):
        self.active = True
        self.init()

    def exit(self):
        self.active = False
        self._shutdown()

    def init(self):
        if self._moduleSpecs is None:
            moduleData = self.capabilities("epas")
            if "error" in moduleData:
                raise Exception("Error accessing module data: " +
                                moduleData["message"])
            self.logger.info("ModuleSpecs: " + str(moduleData))
            self._moduleSpecs = [
                ModuleSpec(epaSpec) for epaSpec in moduleData["epas"]
            ]
            self.activate()

    @abc.abstractmethod
    @pc2request
    def request(self,
                request: Dict,
                inputs: List[TaskResult] = None,
                **kwargs) -> TaskHandle:
        pass

    @abc.abstractmethod
    def status(self, **kwargs) -> Status:
        pass

    @abc.abstractmethod
    def capabilities(self, type: str, **kwargs) -> Dict:
        pass

    @abc.abstractmethod
    def _shutdown(self):
        pass

    @property
    def moduleSpecs(self) -> List[str]:
        return [str(eps) for eps in self._moduleSpecs]

    def handles(self, epa: str, **kwargs) -> bool:
        for moduleSpec in self._moduleSpecs:
            if moduleSpec.handles(epa, **kwargs): return True
        return False

    def __getitem__(self, key: str) -> str:
        result = self.parms.get(key, None)
        assert result is not None, "Missing required parameter in {}: {}, params: {}\n  * {} ".format(
            self.__class__.__name__, key, str(self.parms),
            "\n  * ".join(traceback.format_stack()))
        return result

    def parm(self, key: str, default: str = None) -> Optional[str]:
        return self.parms.get(key, default)

    def updateMetadata(self, requestSpec: Dict) -> Dict:
        requestDict = dict(requestSpec)
        source_client = requestDict.get("cid")
        requestDict["rid"] = requestSpec.get("rid", UID.randomId(6))
        if source_client: self.clients.add(source_client)
        requestDict["cid"] = self.cid
        requestDict["clients"] = ",".join(self.clients)
        return requestDict

    def hasClient(self, cid: str) -> bool:
        return cid in self.clients
示例#19
0
 def __init__(self, name: str ):
     self.logger = PC2Logger.getLogger()
     self._name = name
     self.id = self._name
     self._process: subprocess.Popen = None
示例#20
0
 def __init__ (self ):
     self.logger = PC2Logger.getLogger()
     self._process: subprocess.Popen = None
     self.logger = PC2Logger.getLogger()
示例#21
0
 def __init__(self, manager: AsyncResult, **kwargs):
     TaskHandle.__init__(self, **kwargs)
     self.logger = PC2Logger.getLogger()
     self.manager: AsyncResult = manager
     self._exception = None
示例#22
0
 def __init__(self, epaSpec: str):
     self.logger = PC2Logger.getLogger()
     self._epaSpec = epaSpec
示例#23
0
 def __init__(self, result: TaskResult, **kwargs):
     TaskHandle.__init__(self, **kwargs)
     self.logger = PC2Logger.getLogger()
     self.result: TaskResult = result
     self._exception = None
示例#24
0
文件: base.py 项目: nasa-nccs-cds/pc2
 def __init__(self, core: PC2CoreBase):
     PC2AppBase.__init__(self, core)
     self.logger = PC2Logger.getLogger()
     self.parms = self.getConfigParms('pc2')
示例#25
0
文件: base.py 项目: nasa-nccs-cds/pc2
 def __init__(self, configSpec: Union[str, Dict[str, Dict]], **kwargs):
     self.logger = PC2Logger.getLogger()
     self.config = self.getSettings(configSpec)
     self.parms = self.getConfigParms('pc2')
     self.id = UID.randomId(8)
示例#26
0
 def __init__(self, name: str, app: PC2AppBase, **kwargs):
     self.logger = PC2Logger.getLogger()
     self.parms = kwargs
     self.name = name
     self.app: PC2AppBase = app
示例#27
0
 def __init__(self, ID: str):
     self.logger = PC2Logger.getLogger()
     self._messages = []
     self._error: ErrorRecord = None
     self._status = Status.IDLE
     self._id = ID