Exemplo n.º 1
0
    def post(self, target_path):
        args = post_parser.parse_args()
        if args['type'] == 'file':
            print "full_path:",target_path
            file_name = os.path.basename(target_path)
            file_path = os.path.dirname(target_path)
            print "file_name:",file_name
            print "file_path:",file_path

            file_size = args['file_size']
            block_size = args['block_size']
            if block_size != config.BlockSize :
                return __error__("block_size mismatch")
            print "file_size:"+str(file_size)

            return naming.addFile(__adapt_path__(file_path), file_name, file_size, block_size)
            # return {
            #     'status':"ok",
            #     'data':{ 
            #         'fid':"fid-test", 
            #         'block_num':2,
            #         'block_list':[
            #             {
            #                 'servers':["127.0.0.1:20001"],
            #                 'bid':"bid-test-0",
            #                 'index':0
            #             },
            #             {
            #                 'servers':["127.0.0.1:20001"],
            #                 'bid':"bid-test-1", 
            #                 'index':1
            #             },
            #         ]
            #     }
            # }
        elif args['type'] == 'directory':
            print "create directory ", target_path
            # app.logger.debug("path:"+target_path)
            # return {'status':"ok"}
            return naming.createDir(__adapt_path__(target_path))
        elif args['type'] == 'storage_server':
            host = args['host']
            port = args['port']
            space = args['storage_space']
            block_num = space/config.BlockSize
            server_name = host+":"+str(port)
            print server_name,block_num
            naming.addServer(server_name, block_num)
            return {"status":"ok"}
        else:
            return __error__("invalid type")
Exemplo n.º 2
0
        args = put_parser.parse_args()
        
        if args['type'] == 'file':
            if not args['file_size'] or not args['block_size'] or int(args['block_size']) != config.BlockSize:
                return  {'status':"error", "message":"invalid input"}
            file_size = args['file_size']
            file_name = os.path.basename(target_path)
            file_path = os.path.dirname(target_path)
            return naming.appendFile(__adapt_path__(file_path), file_name, file_size, config.BlockSize)
        elif args['type'] == 'storage_server':
            server_name = args['server_name']
            print server_name
            naming.getHeartBeat(server_name)
        else:
            return __error__("invalid type")



api.add_resource(Naming, '/<path:target_path>')


if __name__ == '__main__':

    naming.createDir("root")

    check = naming_manager.HeartBeatChecker()
    check.setDaemon(True)
    check.start()

    app.run(port=config.NamingServerPort,debug=True)