6b03b6da2034934bd4ec28679fba40447f65dc16
[ccsdk/cds.git] /
1 /*
2  * Copyright (C) 2019 Bell Canada. All rights reserved.
3  *
4  * NOTICE:  All the intellectual and technical concepts contained herein are
5  * proprietary to Bell Canada and are protected by trade secret or copyright law.
6  * Unauthorized copying of this file, via any medium is strictly prohibited.
7  */
8
9 package org.onap.ccsdk.cds.cdssdclistener.handler;
10
11 import io.grpc.ManagedChannel;
12 import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
13 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput;
14 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc;
15 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc.BluePrintManagementServiceBlockingStub;
16 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.springframework.boot.context.properties.ConfigurationProperties;
20 import org.springframework.stereotype.Component;
21
22 @ConfigurationProperties("listenerservice")
23 @Component
24 public class BluePrintProcesssorHandler implements AutoCloseable {
25
26     private static final Logger LOGGER = LoggerFactory.getLogger(BluePrintProcesssorHandler.class);
27
28     private ManagedChannel channel;
29
30     /**
31      * Sending CBA archive to CDS backend to store into its Database.
32      *
33      * @param request BluePrintManagementInput object holds CBA archive, its version and blueprints.
34      * @param managedChannel - ManagedChannel object helps to access the server or application end point.
35      * @return A response object
36      */
37     public Status sendRequest(BluePrintUploadInput request, ManagedChannel managedChannel) {
38         LOGGER.info("Sending request to blueprint processor");
39
40         this.channel = managedChannel;
41
42         final BluePrintManagementServiceBlockingStub syncStub = BluePrintManagementServiceGrpc.newBlockingStub(channel);
43
44         // Send the request to CDS backend.
45         final BluePrintManagementOutput response = syncStub.uploadBlueprint(request);
46
47         return response.getStatus();
48     }
49
50     @Override
51     public void close() {
52         if (channel != null) {
53             channel.shutdown();
54         }
55         LOGGER.info("Stopping GRPC connection to CDS backend");
56     }
57 }