Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / sdclistener / application / src / main / java / org / onap / ccsdk / cds / sdclistener / handler / BluePrintProcesssorHandler.java
1 /*
2  * Copyright © 2019 Bell Canada
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.sdclistener.handler;
18
19 import io.grpc.ManagedChannel;
20 import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
21 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput;
22 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc;
23 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc.BluePrintManagementServiceBlockingStub;
24 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.boot.context.properties.ConfigurationProperties;
28 import org.springframework.stereotype.Component;
29
30 @ConfigurationProperties("listenerservice")
31 @Component
32 public class BluePrintProcesssorHandler implements AutoCloseable {
33
34     private static final Logger LOGGER = LoggerFactory.getLogger(BluePrintProcesssorHandler.class);
35
36     private ManagedChannel channel;
37
38     /**
39      * Sending CBA archive to CDS backend to store into its Database.
40      *
41      * @param request BluePrintManagementInput object holds CBA archive, its version and blueprints.
42      * @param managedChannel - ManagedChannel object helps to access the server or application end point.
43      *
44      * @return A response object
45      */
46     public Status sendRequest(BluePrintUploadInput request, ManagedChannel managedChannel) {
47         LOGGER.info("Sending request to blueprint processor");
48
49         this.channel = managedChannel;
50
51         final BluePrintManagementServiceBlockingStub syncStub = BluePrintManagementServiceGrpc.newBlockingStub(channel);
52
53         // Send the request to CDS backend.
54         final BluePrintManagementOutput response = syncStub.uploadBlueprint(request);
55
56         return response.getStatus();
57     }
58
59     @Override
60     public void close() {
61         if (channel != null) {
62             channel.shutdown();
63         }
64         LOGGER.info("Stopping GRPC connection to CDS backend");
65     }
66
67 }