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 package org.onap.ccsdk.cds.sdclistener.handler;
18 import io.grpc.ManagedChannel;
19 import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
20 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput;
21 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc;
22 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc.BluePrintManagementServiceBlockingStub;
23 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.boot.context.properties.ConfigurationProperties;
27 import org.springframework.stereotype.Component;
29 @ConfigurationProperties("listenerservice")
31 public class BluePrintProcesssorHandler implements AutoCloseable {
33 private static final Logger LOGGER = LoggerFactory.getLogger(BluePrintProcesssorHandler.class);
35 private ManagedChannel channel;
38 * Sending CBA archive to CDS backend to store into its Database.
40 * @param request BluePrintManagementInput object holds CBA archive, its version and blueprints.
41 * @param managedChannel - ManagedChannel object helps to access the server or application end point.
42 * @return A response object
44 public Status sendRequest(BluePrintUploadInput request, ManagedChannel managedChannel) {
45 LOGGER.info("Sending request to blueprint processor");
47 this.channel = managedChannel;
49 final BluePrintManagementServiceBlockingStub syncStub = BluePrintManagementServiceGrpc.newBlockingStub(channel);
51 // Send the request to CDS backend.
52 final BluePrintManagementOutput response = syncStub.uploadBlueprint(request);
54 return response.getStatus();
59 if (channel != null) {
62 LOGGER.info("Stopping GRPC connection to CDS backend");