def cosmos_append(self, file_name, line): # First, check that the file exists, creating it otherwise if not self._cosmos_file_exists(file_name): self._cosmos_create(file_name) # Step 1: interact with the namenode url = self.cosmos_url + '/webhdfs/v1' + self.base_dir + '/' + file_name + '?op=append&user.name=' + self.cosmos_user r = do_post(self.logger, url) if r.status_code != 307: raise Exception('expecting 307 but getting ' + str(r.status_code)) # Step 2: interact with the datanode headers = {'Content-Type': 'application/octet-stream'} url = self.cosmos_url + '/webhdfs/v1' + self.base_dir + '/' + file_name + '?op=append&user.name=' + self.cosmos_user + '&data=true' r = do_post(self.logger, url, line, headers) if r.status_code != 200: raise Exception('expecting 200 but getting ' + str(r.status_code))
def cosmos_append(self, file_name, line): # First, check that the file exists, creating it otherwise if not self._cosmos_file_exists(file_name): self._cosmos_create(file_name) # Step 1: interact with the namenode url = self.cosmos_url + '/webhdfs/v1' + self.base_dir + '/' + file_name + '?op=append&user.name=' + self.cosmos_user r = do_post(self.logger, url) if r.status_code != 307: raise Exception('expecting 307 but getting ' + str(r.status_code)) # Grab datanode from Location header actual_datanode = self._resolve_datanode(r.headers['Location']) # Step 2: interact with the datanode url = 'http://' + actual_datanode + '/webhdfs/v1' + self.base_dir + '/' + file_name + '?op=append&user.name=' + self.cosmos_user r = do_post(self.logger, url, line) if r.status_code != 200: raise Exception('expecting 200 but getting ' + str(r.status_code))