2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.adapter.network;
23 import javax.ws.rs.InternalServerErrorException;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.UriBuilder;
27 import org.onap.so.adapters.nwrest.CreateNetworkRequest;
28 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
29 import org.onap.so.adapters.nwrest.DeleteNetworkRequest;
30 import org.onap.so.adapters.nwrest.DeleteNetworkResponse;
31 import org.onap.so.adapters.nwrest.QueryNetworkResponse;
32 import org.onap.so.adapters.nwrest.RollbackNetworkRequest;
33 import org.onap.so.adapters.nwrest.RollbackNetworkResponse;
34 import org.onap.so.adapters.nwrest.UpdateNetworkRequest;
35 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
36 import org.onap.so.client.adapter.rest.AdapterRestClient;
37 import org.springframework.stereotype.Component;
40 public class NetworkAdapterClientImpl implements NetworkAdapterClient {
42 private final NetworkAdapterRestProperties props;
44 public NetworkAdapterClientImpl() {
45 this.props = new NetworkAdapterRestProperties();
49 public CreateNetworkResponse createNetwork(CreateNetworkRequest req) throws NetworkAdapterClientException{
51 return new AdapterRestClient(this.props, this.getUri("").build()).post(req,
52 CreateNetworkResponse.class);
53 } catch (InternalServerErrorException e) {
54 throw new NetworkAdapterClientException(e.getMessage());
59 public DeleteNetworkResponse deleteNetwork(String aaiNetworkId, DeleteNetworkRequest req) throws NetworkAdapterClientException {
61 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req,
62 DeleteNetworkResponse.class);
63 } catch (InternalServerErrorException e) {
64 throw new NetworkAdapterClientException(e.getMessage());
69 public RollbackNetworkResponse rollbackNetwork(String aaiNetworkId, RollbackNetworkRequest req) throws NetworkAdapterClientException {
71 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req,
72 RollbackNetworkResponse.class);
73 } catch (InternalServerErrorException e) {
74 throw new NetworkAdapterClientException(e.getMessage());
79 public QueryNetworkResponse queryNetwork(String aaiNetworkId, String cloudSiteId, String tenantId,
80 String networkStackId, boolean skipAAI, String requestId, String serviceInstanceId) throws NetworkAdapterClientException {
81 UriBuilder builder = this.getUri("/" + aaiNetworkId);
82 if (cloudSiteId != null) {
83 builder.queryParam("cloudSiteId", cloudSiteId);
85 if (tenantId != null) {
86 builder.queryParam("tenantId", tenantId);
88 if (networkStackId != null) {
89 builder.queryParam("networkStackId", networkStackId);
92 builder.queryParam("skipAAI", skipAAI);
94 if (requestId != null) {
95 builder.queryParam("msoRequest.requestId", requestId);
97 if (serviceInstanceId != null) {
98 builder.queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
101 return new AdapterRestClient(this.props, builder.build(), MediaType.APPLICATION_XML, MediaType.APPLICATION_XML)
102 .get(QueryNetworkResponse.class).get();
103 } catch (InternalServerErrorException e) {
104 throw new NetworkAdapterClientException(e.getMessage());
109 public UpdateNetworkResponse updateNetwork(String aaiNetworkId, UpdateNetworkRequest req) throws NetworkAdapterClientException {
111 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).put(req,
112 UpdateNetworkResponse.class);
113 } catch (InternalServerErrorException e) {
114 throw new NetworkAdapterClientException(e.getMessage());
118 protected UriBuilder getUri(String path) {
119 return UriBuilder.fromPath(path);