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.
17 package org.onap.ccsdk.cds.sdclistener.handler;
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;
30 @ConfigurationProperties("listenerservice")
32 public class BlueprintProcesssorHandler implements AutoCloseable {
34 private static final Logger LOGGER = LoggerFactory.getLogger(BlueprintProcesssorHandler.class);
36 private ManagedChannel channel;
39 * Sending CBA archive to CDS backend to store into its Database.
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.
44 * @return A response object
46 public Status sendRequest(BlueprintUploadInput request, ManagedChannel managedChannel) {
47 LOGGER.info("Sending request to blueprint processor");
49 this.channel = managedChannel;
51 final BlueprintManagementServiceBlockingStub syncStub = BlueprintManagementServiceGrpc.newBlockingStub(channel);
53 // Send the request to CDS backend.
54 final BlueprintManagementOutput response = syncStub.uploadBlueprint(request);
56 return response.getStatus();
61 if (channel != null) {
64 LOGGER.info("Stopping GRPC connection to CDS backend");