Beispiel #1
0
 def testify(self, timeout=7200):
     path = "/modelser/testify/" + self.id
     jsData = HttpHelper.Request_get_sync(self.ip, self.port, path)
     if jsData["status"] == 1:
         title = None
         testifies = jsData["testifies"]
         for index, item in enumerate(testifies):
             title = item["title"]
             break
         if title == None:
             return -2  #! Error in read testify title
         jsData = HttpHelper.Request_put_sync(
             self.ip, self.port,
             "/modelser/testify/" + self.id + "?path=" + title)
         if jsData["status"] == 1:
             inputs = jsData["dataInputs"][0]['inputs']
             list_data = []
             for index, item in enumerate(inputs):
                 list_data.append(
                     DataConfigrationItem(item["StateId"], "",
                                          item["Event"], item["DataId"]))
             recordid = self.invoke(list_data)
             if recordid != -1:
                 jsData = HttpHelper.Request_get_sync(
                     self.ip, self.port, "/modelserrun/json/" + recordid)
                 msr = None
                 if jsData["result"] == "suc":
                     jsMsr = jsData["data"]
                     jsData = HttpHelper.Request_get_sync(
                         self.ip, self.port, "/modelins/json/" +
                         CommonMethod.getJsonValue(jsMsr, "msr_guid"))
                     mis = None
                     if jsData["result"] == "suc" and int(
                             jsData["code"]) == 1:
                         jsMis = jsData["data"]
                         mis = ModelServiceInstance(
                             self.ip, self.port,
                             str(CommonMethod.getJsonValue(jsMis, "state")),
                             str(CommonMethod.getJsonValue(jsMis, "event")),
                             str(CommonMethod.getJsonValue(jsMis, "guid")),
                             str(CommonMethod.getJsonValue(jsMis, "start")),
                             str(
                                 CommonMethod.getJsonValue(
                                     CommonMethod.getJsonValue(jsMis, "ms"),
                                     "_id")))
                         if mis.wait4Status(4, timeout) < 0:
                             mis.kill()
                             return -6  # Timeout
                         if mis.status == 4:
                             return 1
                         else:
                             return -5  #Error in running model service
                 return -4  #! Record can not be found
             return -3  #! Error in read testify files
     return -1  #! Error in read testify files
Beispiel #2
0
 def getModelServiceByID(self, msid):
     jsData = HttpHelper.Request_get_sync(self.ip, self.port,
                                          "/modelser/json/" + msid)
     ms = None
     if CommonMethod.getJsonValue(jsData, "result") == "suc":
         jsMs = CommonMethod.getJsonValue(jsData, "data")
         model = CommonMethod.getJsonValue(jsMs, "ms_model")
         if model == "":
             return None
         user = CommonMethod.getJsonValue(jsMs, "ms_user")
         if user == "":
             user = {"u_name": "", "u_email": ""}
         ms = ModelService(
             self.ip, self.port, CommonMethod.getJsonValue(jsMs, "_id"),
             CommonMethod.getJsonValue(model, "m_name"),
             CommonMethod.getJsonValue(model, "m_type"),
             CommonMethod.getJsonValue(model, "m_url"),
             CommonMethod.getJsonValue(model, "p_id"),
             CommonMethod.getJsonValue(model, "m_id"),
             CommonMethod.getJsonValue(model, "m_register"),
             CommonMethod.getJsonValue(jsMs, "ms_des"),
             CommonMethod.getJsonValue(jsMs, "ms_xml"),
             CommonMethod.getJsonValue(jsMs, "mv_num"),
             int(CommonMethod.getJsonValue(jsMs, "ms_platform")),
             CommonMethod.getJsonValue(jsMs, "ms_update"),
             CommonMethod.getJsonValue(jsMs, "ms_img"),
             CommonMethod.getJsonValue(user, "u_name"),
             CommonMethod.getJsonValue(user, "u_email"),
             int(CommonMethod.getJsonValue(jsMs, "ms_status")),
             int(CommonMethod.getJsonValue(jsMs, "ms_limited")),
             int(CommonMethod.getJsonValue(jsMs, "ms_permission")))
     return ms
 def upload(self, datapath, tag="", security=False):
     md5 = CommonMethod.getFileMd5(datapath)
     path = "/data?md5=" + md5
     jsData = HttpHelper.Request_get_sync(self.ip, self.port, path)
     data = None
     if jsData['result'] == 'suc':
         if (jsData['data'] != ''):
             pwd = jsData['data']['d_pwd']
             pwd = CommonMethod.decryption(CommonMethod.decryption(pwd))
             data = ExData(self.ip, self.port, str(jsData['data']['id']),
                           pwd)
         else:
             data = {"datatag": tag, "pwd": "true"}
             files = {"datafile": open(datapath, "rb")}
             r = requests.post("http://" + self.ip + ":" + str(self.port) +
                               "/data",
                               data,
                               files=files)
             jsData = json.loads(r.text)
             if jsData['result'] == 'suc':
                 pwd = jsData['data']['d_pwd']
                 pwd = CommonMethod.decryption(CommonMethod.decryption(pwd))
                 data = ExData(self.ip, self.port,
                               str(jsData['data']['id']), pwd)
     return data
Beispiel #4
0
 def isExist(self):
     jsData = HttpHelper.Request_get_sync(self.ip, self.port, "/geodata/json/" + self.id)
     if CommonMethod.getJsonValue(jsData, "result") == "suc" :
         if CommonMethod.getJsonValue(jsData, "data") == "":
             return False
         return True
     return False
Beispiel #5
0
 def refresh(self):
     path = "/modelser/json" + self.id
     jsData = HttpHelper.Request_get_sync(self.ip, self.port, path)
     if jsData["result"] == "suc":
         jsMs = jsData["data"]
         self.status = int(CommonMethod.getJsonValue(jsMs, "ms_status"))
         self.limitation = int(CommonMethod.getJsonValue(
             jsMs, "ms_limited"))
         return 1
     return -1
 def createTask(self, pid, dxserver=None, username="******"):
     resJson = HttpHelper.Request_get_sync(self.ip, self.port,
                                           '/server?pid=' + pid)
     if resJson['result'] != 'suc' or resJson['code'] != 1:
         return None
     if dxserver == None:
         resJson = HttpHelper.Request_get_sync(self.ip, self.port,
                                               '/dxserver?ac=recommend')
         if resJson['result'] == 'suc' and len(resJson['data']) > 0:
             type = resJson['data']['type']
             if type == 1:
                 dxserver = GeoDataExServer(resJson['data']['ds_ip'],
                                            int(resJson['data']['ds_port']))
             else:
                 dxserver = GeoDataServiceServer(
                     resJson['data']['ds_ip'],
                     int(resJson['data']['ds_port']), username)
         else:
             return None
     return Task(self.ip, self.port, pid, dxserver, username)
Beispiel #7
0
 def invoke(self, list_data):
     path = "/modelser/" + self.id + "?ac=run&inputdata=["
     for index, item in enumerate(list_data):
         path += "{\"StateId\":\"" + item.stateid + "\",\"StateName\":\"" + item.statename + "\",\"Event\":\"" + item.eventname + "\",\"DataId\":\"" + item.dataid + "\",\"Destoryed\":\"" + str(
             item.destoryed) + "\"},"
     path = path.rstrip(',')
     path += "]"
     jsData = HttpHelper.Request_get_sync(self.ip, self.port, path)
     recordid = -1
     if jsData["result"] == "suc":
         recordid = jsData["data"]
     return recordid
Beispiel #8
0
 def getModelServiceRunningRecordByID(self, msrid):
     jsData = HttpHelper.Request_get_sync(self.ip, self.port,
                                          "/modelserrun/json/" + msrid)
     msr = None
     if jsData["result"] == "suc":
         jsMsr = jsData["data"]
         msr = ModelServiceRunningRecord(
             self.ip, self.port, CommonMethod.getJsonValue(jsMsr, "_id"),
             CommonMethod.getJsonValue(
                 CommonMethod.getJsonValue(jsMsr, "msr_ms"), "_id"),
             CommonMethod.getJsonValue(jsMsr, "msr_guid"),
             int(CommonMethod.getJsonValue(jsMsr, "msr_status")))
     return msr
Beispiel #9
0
 def getDataByID(self, dataid):
     jsData = HttpHelper.Request_get_sync(self.ip, self.port,
                                          "/geodata/json/" + dataid)
     dat = None
     if jsData["result"] == "suc" and jsData["data"] != "":
         jsGData = jsData["data"]
         dat = Data(CommonMethod.getJsonValue(jsGData, "gd_id"),
                    CommonMethod.getJsonValue(jsGData, "gd_tag"),
                    CommonMethod.getJsonValue(jsGData, "gd_type"),
                    int(CommonMethod.getJsonValue(jsGData, "gd_size")),
                    CommonMethod.getJsonValue(jsGData, "gd_value"),
                    CommonMethod.getJsonValue(jsGData, "gd_datetime"),
                    self.ip, self.port)
     return dat
 def refresh(self):
     resJson = HttpHelper.Request_get_sync(self.ip, self.port,
                                           '/task/' + self.tid)
     if resJson['result'] == 'suc':
         self.status = resJson['data']['t_status']
         for item in resJson['data']['t_outputs']:
             dataItem = {
                 "StateName": item["StateName"],
                 "Event": item["Event"],
                 "Url": item["Url"],
                 "Tag": item["Tag"]
             }
             self.outputdata.append(dataItem)
     return self.status
 def refresh(self):
     jsData = HttpHelper.Request_get_sync(self.ip, self.port,
                                          "/modelins/json/" + self.guid)
     if jsData["result"] == "suc":
         jsMis = jsData["data"]
         if jsMis != None:
             self.state = CommonMethod.getJsonValue(jsMis, "state")
             self.event = CommonMethod.getJsonValue(jsMis, "event")
             self.status = ModelServiceInstance.ConvertString2Status(
                 CommonMethod.getJsonValue(jsMis, "status"))
             RunningLog.AppendJson2Log(
                 self.logs, CommonMethod.getJsonValue(jsMis, "log"))
             self.statusDes = CommonMethod.getJsonValue(jsMis, "statusDes")
         else:
             self.status = INSTA_FINISHED
Beispiel #12
0
 def getModelServiceInstanceByGUID(self, guid):
     jsData = HttpHelper.Request_get_sync(self.ip, self.port,
                                          "/modelins/json/" + guid)
     mis = None
     if jsData["result"] == "suc" and int(jsData["code"]) == 1:
         jsMis = jsData["data"]
         mis = ModelServiceInstance(
             self.ip, self.port,
             str(CommonMethod.getJsonValue(jsMis, "state")),
             str(CommonMethod.getJsonValue(jsMis, "event")),
             str(CommonMethod.getJsonValue(jsMis, "guid")),
             str(CommonMethod.getJsonValue(jsMis, "start")),
             str(
                 CommonMethod.getJsonValue(
                     CommonMethod.getJsonValue(jsMis, "ms"), "_id")))
     return mis
Beispiel #13
0
 def getModelServicesList(self, start=0, count=-1):
     query = ''
     if count < 1:
         query = ''
     else:
         query = ("?start=" + str(start) + "&count=" + str(count))
     jsData = HttpHelper.Request_get_sync(self.ip, self.port,
                                          "/modelser/json/all" + query)
     mslist = []
     if CommonMethod.getJsonValue(jsData, "result") == "suc":
         jsMss = CommonMethod.getJsonValue(jsData, "data")
         for index, item in enumerate(jsMss):
             model = CommonMethod.getJsonValue(item, "ms_model")
             if model == "":
                 continue
             user = CommonMethod.getJsonValue(item, "ms_user")
             if user == "":
                 user = {"u_name": "", "u_email": ""}
             try:
                 if CommonMethod.getJsonValue(item, "ms_limited") == "":
                     item['ms_limited'] = u'0'
                 ms = ModelService(
                     self.ip, self.port,
                     CommonMethod.getJsonValue(item, "_id"),
                     CommonMethod.getJsonValue(model, "m_name"),
                     CommonMethod.getJsonValue(model, "m_type"),
                     CommonMethod.getJsonValue(model, "m_url"),
                     CommonMethod.getJsonValue(model, "p_id"),
                     CommonMethod.getJsonValue(model, "m_id"),
                     CommonMethod.getJsonValue(model, "m_register"),
                     CommonMethod.getJsonValue(item, "ms_des"),
                     CommonMethod.getJsonValue(item, "mv_xml"),
                     CommonMethod.getJsonValue(item, "mv_num"),
                     int(CommonMethod.getJsonValue(item, "ms_platform")),
                     CommonMethod.getJsonValue(item, "ms_update"),
                     CommonMethod.getJsonValue(item, "ms_img"),
                     CommonMethod.getJsonValue(user, "u_name"),
                     CommonMethod.getJsonValue(user, "u_email"),
                     int(CommonMethod.getJsonValue(item, "ms_status")),
                     int(CommonMethod.getJsonValue(item, "ms_limited")),
                     int(CommonMethod.getJsonValue(item, "ms_permission")))
                 mslist.append(ms)
             except ZeroDivisionError as ex:
                 print(str(ex))
     return mslist
Beispiel #14
0
 def refresh(self):
     jsData = HttpHelper.Request_get_sync(self.ip, self.port,
                                          "/modelserrun/json/" + self.id)
     if jsData["result"] == "suc":
         msr = CommonMethod.getJsonValue(jsData, "data")
         self.status = int(CommonMethod.getJsonValue(msr, "msr_status"))
         self.timespan = float(CommonMethod.getJsonValue(msr, "msr_span"))
         self.standout = CommonMethod.getJsonValue(
             CommonMethod.getJsonValue(msr, "msr_runninginfo"), "StdErr")
         self.standerr = CommonMethod.getJsonValue(
             CommonMethod.getJsonValue(msr, "msr_runninginfo"), "StdOut")
         self.invokeerr = CommonMethod.getJsonValue(
             CommonMethod.getJsonValue(msr, "msr_runninginfo"), "InvokeErr")
         self.inputs = []
         for index, item in enumerate(
                 CommonMethod.getJsonValue(msr, "msr_input")):
             self.inputs.append(DataConfigrationItem.MakeUpDataItem(item))
         self.outputs = []
         for index, item in enumerate(
                 CommonMethod.getJsonValue(msr, "msr_output")):
             self.outputs.append(DataConfigrationItem.MakeUpDataItem(item))
Beispiel #15
0
 def connect(self):
     jsData = HttpHelper.Request_get_sync(self.ip, self.port, "/ping")
     if (jsData['data'] == 'OK'):
         return True
     else:
         return False