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;
27 import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
28 import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse;
29 import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
30 import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse;
31 import org.onap.so.adapters.vnfrest.QueryVolumeGroupResponse;
32 import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest;
33 import org.onap.so.adapters.vnfrest.RollbackVolumeGroupResponse;
34 import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest;
35 import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse;
36 import org.onap.so.client.RestClient;
37 import org.onap.so.client.adapter.rest.AdapterRestClient;
38 import org.springframework.stereotype.Component;
41 public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient {
43 private final VnfVolumeAdapterRestProperties props;
45 public VnfVolumeAdapterClientImpl() {
46 this.props = new VnfVolumeAdapterRestProperties();
50 public CreateVolumeGroupResponse createVNFVolumes(CreateVolumeGroupRequest req) throws VnfAdapterClientException {
52 return this.getAdapterRestClient("").post(req, CreateVolumeGroupResponse.class);
53 } catch (InternalServerErrorException e) {
54 throw new VnfAdapterClientException(e.getMessage());
59 public DeleteVolumeGroupResponse deleteVNFVolumes(String aaiVolumeGroupId, DeleteVolumeGroupRequest req)
60 throws VnfAdapterClientException {
62 return this.getAdapterRestClient("/" + aaiVolumeGroupId).delete(req, DeleteVolumeGroupResponse.class);
63 } catch (InternalServerErrorException e) {
64 throw new VnfAdapterClientException(e.getMessage());
69 public RollbackVolumeGroupResponse rollbackVNFVolumes(String aaiVolumeGroupId, RollbackVolumeGroupRequest req)
70 throws VnfAdapterClientException {
72 return this.getAdapterRestClient("/" + aaiVolumeGroupId + "/rollback").delete(req,
73 RollbackVolumeGroupResponse.class);
74 } catch (InternalServerErrorException e) {
75 throw new VnfAdapterClientException(e.getMessage());
80 public UpdateVolumeGroupResponse updateVNFVolumes(String aaiVolumeGroupId, UpdateVolumeGroupRequest req)
81 throws VnfAdapterClientException {
83 return this.getAdapterRestClient("/" + aaiVolumeGroupId).put(req, UpdateVolumeGroupResponse.class);
84 } catch (InternalServerErrorException e) {
85 throw new VnfAdapterClientException(e.getMessage());
90 public QueryVolumeGroupResponse queryVNFVolumes(String aaiVolumeGroupId, String cloudSiteId, String tenantId,
91 String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId)
92 throws VnfAdapterClientException {
94 String path = buildQueryPath(aaiVolumeGroupId, cloudSiteId, tenantId, volumeGroupStackId, skipAAI,
95 requestId, serviceInstanceId);
96 return this.getAdapterRestClient(path).get(QueryVolumeGroupResponse.class).get();
97 } catch (InternalServerErrorException e) {
98 throw new VnfAdapterClientException(e.getMessage());
102 protected String buildQueryPath(String aaiVolumeGroupId, String cloudSiteId, String tenantId,
103 String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId) {
104 javax.ws.rs.core.UriBuilder builder = this.getUri("/" + aaiVolumeGroupId);
105 builder.queryParam("cloudSiteId", cloudSiteId).queryParam("tenantId", tenantId)
106 .queryParam("volumeGroupStackId", volumeGroupStackId).queryParam("skipAAI", skipAAI)
107 .queryParam("msoRequest.requestId", requestId)
108 .queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
109 return builder.build().toString();
112 protected UriBuilder getUri(String path) {
113 return UriBuilder.fromPath(path);
116 protected RestClient getAdapterRestClient(String path) {
117 return new AdapterRestClient(props, this.getUri(path).build(), MediaType.APPLICATION_JSON,
118 MediaType.APPLICATION_JSON);