Exemplo n.º 1
0
def selectModel():

    A = zk.get('/selectModel/param/A')
    b = zk.get('/selectModel/param/b')
    p = zk.get('/selectModel/param/p')



    log.logSend("INFO device " + localhost + " get model selector parameters")

    p = pickle.loads(p[0])



    best_predicted_arm = np.argmax(p)

    if best_predicted_arm == 0:
        ftp = FTPClient.ftpconnect("127.0.0.1", "ftp***", "Guest***")
        FTPClient.downloadfile(ftp, "vgg16-397923af.pth", "/home/huchuanwen/bishe/collaborativeDL/ftp/test/vgg16.pth")

    print(best_predicted_arm)

    log.logSend("INFO device " + localhost + " select model vgg16")

    zk.stop()

    N = p.size
    x = np.arange(N)
    label = ("VGG16","alexnet","resnet-18")
    plt.bar(x, p, width=0.5,label="models",tick_label=label)
    plt.legend()
    plt.show()
Exemplo n.º 2
0
def selectModel():
    # 配置信息
    conf = configparser.ConfigParser()
    conf.read('../conf/inf.conf')

    kafkaHost = conf.get("ssd.kafkaServer", "hosts")

    localhost = conf.get('ssd.local', 'host')

    producer = KafkaProducer(bootstrap_servers=kafkaHost)  # 连接kafka

    consoleChanel = conf.get("ssd.kafkaServer", "consoleChanel")
    zk = KazooClient(hosts="10.4.10.239:2181")
    zk.start()

    p = zk.get('/selectModel/param/p')

    # print(p)
    producer.send(consoleChanel, ("INFO device " + localhost +
                                  " get model selector parameters").encode())

    p = pickle.loads(p[0])

    best_predicted_arm = np.argmax(p)

    if best_predicted_arm == 0:
        ftp = FTPClient.ftpconnect("127.0.0.1", "ftp***", "Guest***")
        FTPClient.downloadfile(
            ftp, "vgg16-397923af.pth",
            "/home/huchuanwen/bishe/collaborativeDL/ftp/test/vgg16.pth")

    print(best_predicted_arm)

    producer.send(consoleChanel, ("INFO device " + localhost +
                                  " select model vgg16").encode())

    zk.stop()
 def processPacket(self, packet):
     global user_input
     global workingDirectory
     data = self.__repositoryPacketHandler.readPacket(packet)
     if (data['packet_type'] == PACKET_T.ADDED_IMAGE_ID) :
         print("The new image ID is: {0}".format(data['addedImageID']))
         print("Please write it down. You'll need it later")
     elif (data['packet_type'] == PACKET_T.RETR_REQUEST_ERROR or data['packet_type'] == PACKET_T.RETR_ERROR) :
         print("Retrieve error: " + str(data['errorDescription']))
     elif (data['packet_type'] == PACKET_T.RETR_REQUEST_RECVD) :
         print("The image repository says: retrieve request received")
     elif (data['packet_type'] == PACKET_T.RETR_START) :
         print("Downloading file...")
         ftpClient = FTPClient()
         ftpClient.connect(self.__ip_address, data['FTPServerPort'], 5, data['username'], data['password'])
         ftpClient.retrieveFile(data['fileName'], workingDirectory, data['serverDirectory']) 
         ftpClient.disconnect()
         print("Transfer completed")
     elif (data['packet_type'] == PACKET_T.STOR_REQUEST_ERROR or data['packet_type'] == PACKET_T.STOR_ERROR) :
         print("Store error: " + str(data['errorCode']))
         user_input = False
     elif (data['packet_type'] == PACKET_T.STOR_REQUEST_RECVD) :
         print("The image repository says: store request received")
     elif (data['packet_type'] == PACKET_T.STOR_START) :
         print("Uploading file...")
         ftpClient = FTPClient()
         ftpClient.connect(self.__ip_address, data['FTPServerPort'], 100, data['username'], data['password'])
         if (data['fileName'] == '') :
             fileName = raw_input('File to upload (its name MUST be the given image ID): ')
         else :
             fileName = data['fileName']
         ftpClient.storeFile(fileName, workingDirectory, data['serverDirectory']) 
         ftpClient.disconnect()
         print("Transfer completed")
         user_input = False
     elif (data['packet_type'] == PACKET_T.DELETE_REQUEST_RECVD):
         print("The image repository says: delete request received")
     elif (data['packet_type'] == PACKET_T.STATUS_DATA):
         print("Image repository disk usage: {0} KB free, {1} KB available".format(data["FreeDiskSpace"], data["TotalDiskSpace"]))   
     elif (data['packet_type'] == PACKET_T.IMAGE_EDITION_CANCELLED):
         print("The image repository says: image edition cancelled")  
     else:
         print("Error: a packet from an unexpected type has been received " + str(data['packet_type']))
Exemplo n.º 4
0
 def processPacket(self, packet):
     """
     Processes a packet sent from the image repository
     Args:
         packet: the incoming packet to process
     Returns:
         Nothing
     """
     data = self.__repositoryPacketHandler.readPacket(packet)
     if (data["packet_type"] == IR_PACKET_T.RETR_REQUEST_RECVD
             or data["packet_type"] == IR_PACKET_T.STOR_REQUEST_RECVD):
         return
     elif (data["packet_type"] == IR_PACKET_T.RETR_REQUEST_ERROR
           or data["packet_type"] == IR_PACKET_T.RETR_ERROR
           or data["packet_type"] == IR_PACKET_T.STOR_REQUEST_ERROR
           or data["packet_type"] == IR_PACKET_T.STOR_ERROR):
         self.__errorDescription = data["errorDescription"]
         self.__image_not_found = True
     elif (data["packet_type"] == IR_PACKET_T.RETR_START):
         try:
             ftpClient = FTPClient()
             ftpClient.connect(self.__ftpServerIP, data['FTPServerPort'],
                               self.__ftpTimeout, data['username'],
                               data['password'])
             ftpClient.retrieveFile(data['fileName'],
                                    self.__transferDirectory,
                                    data['serverDirectory'])
             ftpClient.disconnect()
         except Exception:
             self.__errorDescription = ERROR_DESC_T.VMSRVR_FTP_RETR_TRANSFER_ERROR
     elif (data["packet_type"] == IR_PACKET_T.STOR_START):
         try:
             ftpClient = FTPClient()
             ftpClient.connect(self.__ftpServerIP, data['FTPServerPort'],
                               self.__ftpTimeout, data['username'],
                               data['password'])
             ftpClient.storeFile(self.__sourceFilePath,
                                 self.__transferDirectory,
                                 data['serverDirectory'])
             ftpClient.disconnect()
         except Exception:
             self.__errorDescription = ERROR_DESC_T.VMSRVR_FTP_RETR_TRANSFER_ERROR
     elif (data["packet_type"] == IR_PACKET_T.ADDED_IMAGE_ID):
         self.__imageID = data["addedImageID"]
     self.__operation_completed = True
 def processPacket(self, packet):
     """
     Processes a packet sent from the image repository
     Args:
         packet: the incoming packet to process
     Returns:
         Nothing
     """
     data = self.__repositoryPacketHandler.readPacket(packet)
     if (data["packet_type"] == IR_PACKET_T.RETR_REQUEST_RECVD or
         data["packet_type"] == IR_PACKET_T.STOR_REQUEST_RECVD) :
         return
     elif (data["packet_type"] == IR_PACKET_T.RETR_REQUEST_ERROR or data["packet_type"] == IR_PACKET_T.RETR_ERROR or
           data["packet_type"] == IR_PACKET_T.STOR_REQUEST_ERROR or data["packet_type"] == IR_PACKET_T.STOR_ERROR) :
         self.__errorDescription = data["errorDescription"]
         self.__image_not_found = True
     elif (data["packet_type"] == IR_PACKET_T.RETR_START) :
         try :
             ftpClient = FTPClient()
             ftpClient.connect(self.__ftpServerIP, data['FTPServerPort'], self.__ftpTimeout, data['username'], data['password'])
             ftpClient.retrieveFile(data['fileName'], self.__transferDirectory, data['serverDirectory']) 
             ftpClient.disconnect()
         except Exception:
             self.__errorDescription = ERROR_DESC_T.VMSRVR_FTP_RETR_TRANSFER_ERROR
     elif (data["packet_type"] == IR_PACKET_T.STOR_START) :
         try :
             ftpClient = FTPClient()
             ftpClient.connect(self.__ftpServerIP, data['FTPServerPort'], self.__ftpTimeout, data['username'], data['password'])
             ftpClient.storeFile(self.__sourceFilePath, self.__transferDirectory, data['serverDirectory'])
             ftpClient.disconnect()
         except Exception:
             self.__errorDescription = ERROR_DESC_T.VMSRVR_FTP_RETR_TRANSFER_ERROR
     elif (data["packet_type"] == IR_PACKET_T.ADDED_IMAGE_ID):
         self.__imageID = data["addedImageID"]                  
     self.__operation_completed = True