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.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.stereotype.Component;
42 public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient {
44 private static final Logger logger = LoggerFactory.getLogger(VnfVolumeAdapterClientImpl.class);
46 private final VnfVolumeAdapterRestProperties props;
48 public VnfVolumeAdapterClientImpl() {
49 this.props = new VnfVolumeAdapterRestProperties();
53 public CreateVolumeGroupResponse createVNFVolumes(CreateVolumeGroupRequest req) throws VnfAdapterClientException {
55 return this.getAdapterRestClient("").post(req, CreateVolumeGroupResponse.class);
56 } catch (InternalServerErrorException e) {
57 logger.error("InternalServerErrorException in createVNFVolumes", e);
58 throw new VnfAdapterClientException(e.getMessage());
63 public DeleteVolumeGroupResponse deleteVNFVolumes(String aaiVolumeGroupId, DeleteVolumeGroupRequest req)
64 throws VnfAdapterClientException {
66 return this.getAdapterRestClient("/" + aaiVolumeGroupId).delete(req, DeleteVolumeGroupResponse.class);
67 } catch (InternalServerErrorException e) {
68 logger.error("InternalServerErrorException in deleteVNFVolumes", e);
69 throw new VnfAdapterClientException(e.getMessage());
74 public RollbackVolumeGroupResponse rollbackVNFVolumes(String aaiVolumeGroupId, RollbackVolumeGroupRequest req)
75 throws VnfAdapterClientException {
77 return this.getAdapterRestClient("/" + aaiVolumeGroupId + "/rollback").delete(req,
78 RollbackVolumeGroupResponse.class);
79 } catch (InternalServerErrorException e) {
80 logger.error("InternalServerErrorException in rollbackVNFVolumes", e);
81 throw new VnfAdapterClientException(e.getMessage());
86 public UpdateVolumeGroupResponse updateVNFVolumes(String aaiVolumeGroupId, UpdateVolumeGroupRequest req)
87 throws VnfAdapterClientException {
89 return this.getAdapterRestClient("/" + aaiVolumeGroupId).put(req, UpdateVolumeGroupResponse.class);
90 } catch (InternalServerErrorException e) {
91 logger.error("InternalServerErrorException in updateVNFVolumes", e);
92 throw new VnfAdapterClientException(e.getMessage());
97 public QueryVolumeGroupResponse queryVNFVolumes(String aaiVolumeGroupId, String cloudSiteId, String tenantId,
98 String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId)
99 throws VnfAdapterClientException {
101 String path = buildQueryPath(aaiVolumeGroupId, cloudSiteId, tenantId, volumeGroupStackId, skipAAI,
102 requestId, serviceInstanceId);
103 return this.getAdapterRestClient(path).get(QueryVolumeGroupResponse.class).get();
104 } catch (InternalServerErrorException e) {
105 logger.error("InternalServerErrorException in queryVNFVolumes", e);
106 throw new VnfAdapterClientException(e.getMessage());
110 protected String buildQueryPath(String aaiVolumeGroupId, String cloudSiteId, String tenantId,
111 String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId) {
112 javax.ws.rs.core.UriBuilder builder = this.getUri("/" + aaiVolumeGroupId);
113 builder.queryParam("cloudSiteId", cloudSiteId).queryParam("tenantId", tenantId)
114 .queryParam("volumeGroupStackId", volumeGroupStackId).queryParam("skipAAI", skipAAI)
115 .queryParam("msoRequest.requestId", requestId)
116 .queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
117 return builder.build().toString();
120 protected UriBuilder getUri(String path) {
121 return UriBuilder.fromPath(path);
124 protected RestClient getAdapterRestClient(String path) {
125 return new AdapterRestClient(props, this.getUri(path).build(), MediaType.APPLICATION_JSON,
126 MediaType.APPLICATION_JSON);