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
Exemple #2
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
Exemple #3
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 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
 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
 def getURL(self):
     dataid = self.id
     if self.pwd == '':
         pwd_c = ''
     else:
         pwd_c = CommonMethod.encryption(self.pwd)
         pwd_c = pwd_c.replace('\n', '')
     url = "http://" + self.ip + ":" + str(
         self.port) + "/data/" + dataid + "?pwd=" + pwd_c
     return str(url)
 def uploadDataByFile(self, tag, filepath):
     data = {"gd_tag": tag}
     files = {"myfile": open(filepath, "rb")}
     r = requests.post("http://" + self.ip + ":" + str(self.port) +
                       "/geodata?type=file",
                       data,
                       files=files)
     jsData = json.loads(r.text)
     if jsData["result"] == "suc":
         return CommonMethod.getJsonValue(jsData, "data")
     return ""
Exemple #8
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
 def ConvertJson2Log(jsLogs):
     logs = []
     for index, item in enumerate(jsLogs):
         log = RunningLog(CommonMethod.getJsonValue(item, "Type"),
                          CommonMethod.getJsonValue(item, "State"),
                          CommonMethod.getJsonValue(item, "Event"),
                          int(CommonMethod.getJsonValue(item, "Flag")),
                          CommonMethod.getJsonValue(item, "Message"),
                          CommonMethod.getJsonValue(item, "Datetime"))
         logs.append(log)
     return logs
 def AppendJson2Log(logs, jsLogs):
     count = len(logs)
     for index, item in enumerate(jsLogs):
         if index < count:
             continue
         log = RunningLog(CommonMethod.getJsonValue(item, "Type"),
                          CommonMethod.getJsonValue(item, "State"),
                          CommonMethod.getJsonValue(item, "Event"),
                          int(CommonMethod.getJsonValue(item, "Flag")),
                          CommonMethod.getJsonValue(item, "Message"),
                          CommonMethod.getJsonValue(item, "DateTime"))
         logs.append(log)
Exemple #11
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
Exemple #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
Exemple #13
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))
Exemple #14
0
 def start(self):
     jsData = HttpHelper.Request_put_sync(
         self.ip, self.port, '/modelser/' + self.id + '?ac=start')
     if CommonMethod.getJsonValue(jsData, 'result') == 'suc':
         return 1
     return -1
Exemple #15
0
 def createDataConfigurationItem(self, state, eventname, dataid):
     if CommonMethod.IsGUID(state):
         return DataConfigrationItem(state, "", eventname, dataid)
     else:
         return DataConfigrationItem("", state, eventname, dataid)
Exemple #16
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
Exemple #17
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