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.vnf;
23 import javax.ws.rs.InternalServerErrorException;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.UriBuilder;
26 import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
27 import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse;
28 import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
29 import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse;
30 import org.onap.so.adapters.vnfrest.QueryVolumeGroupResponse;
31 import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest;
32 import org.onap.so.adapters.vnfrest.RollbackVolumeGroupResponse;
33 import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest;
34 import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse;
35 import org.onap.so.client.RestClient;
36 import org.onap.so.client.adapter.rest.AdapterRestClient;
37 import org.springframework.stereotype.Component;
40 public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient {
42 private final VnfVolumeAdapterRestProperties props;
44 public VnfVolumeAdapterClientImpl() {
45 this.props = new VnfVolumeAdapterRestProperties();
49 public CreateVolumeGroupResponse createVNFVolumes(CreateVolumeGroupRequest req) throws VnfAdapterClientException {
51 return this.getAdapterRestClient("").post(req, CreateVolumeGroupResponse.class);
52 } catch (InternalServerErrorException e) {
53 throw new VnfAdapterClientException(e.getMessage());
58 public DeleteVolumeGroupResponse deleteVNFVolumes(String aaiVolumeGroupId, DeleteVolumeGroupRequest req)
59 throws VnfAdapterClientException {
61 return this.getAdapterRestClient("/" + aaiVolumeGroupId).delete(req, DeleteVolumeGroupResponse.class);
62 } catch (InternalServerErrorException e) {
63 throw new VnfAdapterClientException(e.getMessage());
68 public RollbackVolumeGroupResponse rollbackVNFVolumes(String aaiVolumeGroupId, RollbackVolumeGroupRequest req)
69 throws VnfAdapterClientException {
71 return this.getAdapterRestClient("/" + aaiVolumeGroupId + "/rollback").delete(req,
72 RollbackVolumeGroupResponse.class);
73 } catch (InternalServerErrorException e) {
74 throw new VnfAdapterClientException(e.getMessage());
79 public UpdateVolumeGroupResponse updateVNFVolumes(String aaiVolumeGroupId, UpdateVolumeGroupRequest req)
80 throws VnfAdapterClientException {
82 return this.getAdapterRestClient("/" + aaiVolumeGroupId).put(req, UpdateVolumeGroupResponse.class);
83 } catch (InternalServerErrorException e) {
84 throw new VnfAdapterClientException(e.getMessage());
89 public QueryVolumeGroupResponse queryVNFVolumes(String aaiVolumeGroupId, String cloudSiteId, String tenantId,
90 String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId)
91 throws VnfAdapterClientException {
93 String path = buildQueryPath(aaiVolumeGroupId, cloudSiteId, tenantId, volumeGroupStackId, skipAAI,
94 requestId, serviceInstanceId);
95 return this.getAdapterRestClient(path).get(QueryVolumeGroupResponse.class).get();
96 } catch (InternalServerErrorException e) {
97 throw new VnfAdapterClientException(e.getMessage());
101 protected String buildQueryPath(String aaiVolumeGroupId, String cloudSiteId, String tenantId,
102 String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId) {
103 javax.ws.rs.core.UriBuilder builder = this.getUri("/" + aaiVolumeGroupId);
104 builder.queryParam("cloudSiteId", cloudSiteId).queryParam("tenantId", tenantId)
105 .queryParam("volumeGroupStackId", volumeGroupStackId).queryParam("skipAAI", skipAAI)
106 .queryParam("msoRequest.requestId", requestId)
107 .queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
108 return builder.build().toString();
111 protected UriBuilder getUri(String path) {
112 return UriBuilder.fromPath(path);
115 protected RestClient getAdapterRestClient(String path) {
116 return new AdapterRestClient(props, this.getUri(path).build(), MediaType.APPLICATION_JSON,
117 MediaType.APPLICATION_JSON);