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.core.ParameterizedTypeReference;
35 import org.springframework.http.HttpHeaders;
36 import org.springframework.http.MediaType;
37 import org.springframework.stereotype.Component;
39 import com.fasterxml.jackson.core.JsonProcessingException;
43 public class SniroClient {
45 private static final MsoLogger log = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SniroClient.class);
48 private ManagerProperties managerProperties;
51 private SniroValidator validator;
55 * Makes a rest call to sniro manager to perform homing and licensing for a
58 * @param homingRequest
60 * @throws JsonProcessingException
63 public void postDemands(SniroManagerRequest homingRequest) throws BadResponseException, JsonProcessingException{
64 log.trace("Started Sniro Client Post Demands");
65 String url = managerProperties.getHost() + managerProperties.getUri().get("v2");
66 log.debug("Post demands url: " + url);
67 log.debug("Post demands payload: " + homingRequest.toJsonString());
69 HttpHeaders header = new HttpHeaders();
70 header.setContentType(MediaType.APPLICATION_JSON);
71 header.set("Authorization", managerProperties.getHeaders().get("auth"));
72 header.set("X-patchVersion", managerProperties.getHeaders().get("patchVersion"));
73 header.set("X-minorVersion", managerProperties.getHeaders().get("minorVersion"));
74 header.set("X-latestVersion", managerProperties.getHeaders().get("latestVersion"));
75 BaseClient<String, LinkedHashMap<?, ?>> baseClient = new BaseClient<>();
77 baseClient.setTargetUrl(url);
78 baseClient.setHttpHeader(header);
80 LinkedHashMap<?, ?> response = baseClient.post(homingRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {});
81 validator.validateDemandsResponse(response);
82 log.trace("Completed Sniro Client Post Demands");
86 * Makes a rest call to sniro conductor to notify them of successful or unsuccessful vnf
87 * creation for previously homed resources
89 * TODO Temporarily being used in groovy therefore can not utilize autowire. Once java "release"
90 * subflow is developed it will be refactored to use autowire.
92 * @param releaseRequest
94 * @throws BadResponseException
96 public void postRelease(SniroConductorRequest releaseRequest) throws BadResponseException {
97 log.trace("Started Sniro Client Post Release");
98 String url = UrnPropertiesReader.getVariable("sniro.conductor.host") + UrnPropertiesReader.getVariable("sniro.conductor.uri");
99 log.debug("Post release url: " + url);
100 log.debug("Post release payload: " + releaseRequest.toJsonString());
102 HttpHeaders header = new HttpHeaders();
103 header.setContentType(MediaType.APPLICATION_JSON);
104 header.set("Authorization", UrnPropertiesReader.getVariable("sniro.conductor.headers.auth"));
105 BaseClient<String, LinkedHashMap<?, ?>> baseClient = new BaseClient<>();
107 baseClient.setTargetUrl(url);
108 baseClient.setHttpHeader(header);
110 LinkedHashMap<?, ?> response = baseClient.post(releaseRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {});
111 SniroValidator v = new SniroValidator();
112 v.validateReleaseResponse(response);
113 log.trace("Completed Sniro Client Post Release");