Загрузить файл с Angular 7 в HDFS с помощью webhdfs - PullRequest
0 голосов
/ 21 октября 2019

Мне нужно загрузить файл из приложения Angular 7 в HDFS с помощью webhdfs.

Сначала я просто пытаюсь получить статус папки.

Но при этом ничего не получаетсявсе в ответ.

app.component.ts

import { Component } from '@angular/core';

import { RestService } from './services/rest.service';
import { Comments } from './classes/comments';
import { Posts } from './classes/posts';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'restClient';

  constructor(private _restService: RestService) {}

  lstComments:Comments[];
  objPosts:Posts;

  ngOnInit() {
    console.log('hello');

  }

  handleHdfs() {
    console.log('HDFS');

    let url = "http://<MY-IP>";
    let port = 9870; 
    let dir_path = "home/hduser/write"; 
    let path = "/webhdfs/v1/" + dir_path + "?op=LISTSTATUS&user.name=hdfs";
    let full_url = url + ':' + port + path;

    console.log(full_url);

    this._restService.hdfsPost(full_url).subscribe(
      data=> {
        console.log("data");
      }
    )
  }

}

rest.service.ts

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient, HttpErrorResponse } from '@angular/common/http'; 
import { Posts } from '../classes/posts';
import { HttpHeaders } from '@angular/common/http'; 
import { catchError } from 'rxjs/operators';
import { throwError } from 'rxjs';


@Injectable() 
export class RestService {

    httpHeaders = new HttpHeaders({'Content-Type' : 'application/json'}); 

    constructor(private httpClient: HttpClient) {}

    hdfsPost(url:string): Observable<any> {
        return this.httpClient.post(url, null, {headers:this.httpHeaders, responseType: 'json'});
    }

}

Это служба отдыха, но с пакетом webhdfs npm, где япопробуйте прочитать файл.

rest.service.ts

public hdfsPost(url:string): Observable<any> {
           let hdfs = this.aa.createClient({
            user: "hduser",
            host: "http://<MY-IP>",
            port: 9870, 
            path: "webhdfs/v1"
            // path: "webhdfs/v1/home/hduser/write?op=LISTSTATUS&user.name=hdfs"
        });


        var remoteFileStream = hdfs.createReadStream('/home/hduser/write/myCSV.csv');

        remoteFileStream.on('error', function onError (err) {
        // Do something with the error
        });

        remoteFileStream.on('data', function onChunk (chunk) {
        // Do something with the data chunk
        });

        remoteFileStream.on('finish', function onFinish () {
        // Upload is done
        });

        return this.httpClient.post(url, null, {headers:this.httpHeaders, observe: 'response'});
      }

Опять нет ответа.

Любая помощь / советы будут высоко оценены.

Я буду публиковать свои успехи.

Спасибо

...