2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.client.sniro;
23 import java.util.LinkedHashMap;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.onap.so.bpmn.core.UrnPropertiesReader;
27 import org.onap.so.client.exception.BadResponseException;
28 import org.onap.so.client.sdnc.BaseClient;
29 import org.onap.so.client.sniro.beans.ManagerProperties;
30 import org.onap.so.client.sniro.beans.SniroConductorRequest;
31 import org.onap.so.client.sniro.beans.SniroManagerRequest;
32 import org.onap.so.logger.MsoLogger;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.http.HttpHeaders;
35 import org.springframework.http.MediaType;
36 import org.springframework.stereotype.Component;
38 import com.fasterxml.jackson.core.JsonProcessingException;
42 public class SniroClient {
44 private static final MsoLogger log = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SniroClient.class);
47 private ManagerProperties managerProperties;
50 private SniroValidator validator;
54 * Makes a rest call to sniro manager to perform homing and licensing for a
57 * @param homingRequest
59 * @throws JsonProcessingException
62 public void postDemands(SniroManagerRequest homingRequest) throws BadResponseException, JsonProcessingException{
63 log.trace("Started Sniro Client Post Demands");
64 String url = managerProperties.getHost() + managerProperties.getUri().get("v2");
65 log.debug("Post demands url: " + url);
66 log.debug("Post demands payload: " + homingRequest.toJsonString());
68 HttpHeaders header = new HttpHeaders();
69 header.setContentType(MediaType.APPLICATION_JSON);
70 header.set("Authorization", managerProperties.getHeaders().get("auth"));
71 header.set("X-patchVersion", managerProperties.getHeaders().get("patchVersion"));
72 header.set("X-minorVersion", managerProperties.getHeaders().get("minorVersion"));
73 header.set("X-latestVersion", managerProperties.getHeaders().get("latestVersion"));
74 BaseClient<String, LinkedHashMap<?, ?>> baseClient = new BaseClient<>();
76 baseClient.setTargetUrl(url);
77 baseClient.setHttpHeader(header);
79 LinkedHashMap<?, ?> response = baseClient.post(homingRequest.toJsonString());
80 validator.validateDemandsResponse(response);
81 log.trace("Completed Sniro Client Post Demands");
85 * Makes a rest call to sniro conductor to notify them of successful or unsuccessful vnf
86 * creation for previously homed resources
88 * TODO Temporarily being used in groovy therefore can not utilize autowire. Once java "release"
89 * subflow is developed it will be refactored to use autowire.
91 * @param releaseRequest
93 * @throws BadResponseException
95 public void postRelease(SniroConductorRequest releaseRequest) throws BadResponseException {
96 log.trace("Started Sniro Client Post Release");
97 String url = UrnPropertiesReader.getVariable("sniro.conductor.host") + UrnPropertiesReader.getVariable("sniro.conductor.uri");
98 log.debug("Post release url: " + url);
99 log.debug("Post release payload: " + releaseRequest.toJsonString());
101 HttpHeaders header = new HttpHeaders();
102 header.setContentType(MediaType.APPLICATION_JSON);
103 header.set("Authorization", UrnPropertiesReader.getVariable("sniro.conductor.headers.auth"));
104 BaseClient<String, LinkedHashMap<?, ?>> baseClient = new BaseClient<>();
106 baseClient.setTargetUrl(url);
107 baseClient.setHttpHeader(header);
109 LinkedHashMap<?, ?> response = baseClient.post(releaseRequest.toJsonString());
110 SniroValidator v = new SniroValidator();
111 v.validateReleaseResponse(response);
112 log.trace("Completed Sniro Client Post Release");