2 ~ Copyright © 2019 Bell Canada.
4 ~ Licensed under the Apache License, Version 2.0 (the "License");
5 ~ you may not use this file except in compliance with the License.
6 ~ You may obtain a copy of the License at
8 ~ http://www.apache.org/licenses/LICENSE-2.0
10 ~ Unless required by applicable law or agreed to in writing, software
11 ~ distributed under the License is distributed on an "AS IS" BASIS,
12 ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ~ See the License for the specific language governing permissions and
14 ~ limitations under the License.
16 import * as fs from 'fs';
17 import * as uuidv1 from 'uuid/v1';
18 const grpc = require('grpc');
19 import * as protoLoader from '@grpc/proto-loader';
20 import { processorApiConfig } from '../config/app-config';
22 const PROTO_PATH = processorApiConfig.grpc.bluePrintManagement.protoPath;
24 // Suggested options for similarity to existing grpc.load behavior
25 const packageDefinition: protoLoader.PackageDefinition = protoLoader.loadSync(
35 const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
36 // The protoDescriptor object has the full package hierarchy
38 const stub = new protoDescriptor.org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintManagementService(
39 "" + processorApiConfig.grpc.host + ":" + processorApiConfig.grpc.port + "",
40 grpc.credentials.createInsecure());
42 const metadata = new grpc.Metadata();
43 metadata.add('Authorization', processorApiConfig.grpc.authToken);
45 class BlueprintManagementServiceGrpcClient {
47 async uploadBlueprint(filePath: string, actionName: string): Promise<any> {
51 timestamp: new Date(),
52 originatorId: "cds-ui",
54 subRequestId: "1234-56",
57 chunk: fs.readFileSync(filePath)
61 blueprintName: "cds.zip",
62 actionName: actionName
66 let removeTempFile = () => {
67 fs.unlink(filePath, (err: any) => {
74 return new Promise<any>((resolve, reject) => {
75 stub.uploadBlueprint(input, metadata, (err: any, output: any) => {
89 async downloadBlueprint(blueprintName: string,blueprintVersion: string): Promise<any> {
93 timestamp: new Date(),
94 originatorId: "cds-ui",
96 subRequestId: "1234-56",
100 blueprintName: blueprintName,
101 blueprintVersion: blueprintVersion
105 return new Promise<any>((resolve, reject) => {
106 stub.downloadBlueprint(input, metadata, (err: any, output: any) => {
118 export const bluePrintManagementServiceGrpcClient = new BlueprintManagementServiceGrpcClient();