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.CreateVfModuleRequest;
28 import org.onap.so.adapters.vnfrest.CreateVfModuleResponse;
29 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
30 import org.onap.so.adapters.vnfrest.DeleteVfModuleResponse;
31 import org.onap.so.adapters.vnfrest.QueryVfModuleResponse;
32 import org.onap.so.adapters.vnfrest.RollbackVfModuleRequest;
33 import org.onap.so.adapters.vnfrest.RollbackVfModuleResponse;
34 import org.onap.so.adapters.vnfrest.UpdateVfModuleRequest;
35 import org.onap.so.adapters.vnfrest.UpdateVfModuleResponse;
36 import org.onap.so.client.adapter.rest.AdapterRestClient;
37 import org.springframework.stereotype.Component;
40 public class VnfAdapterClientImpl implements VnfAdapterClient {
42 private static final String VF_MODULES = "/vf-modules/";
44 private VnfAdapterRestProperties props;
46 public VnfAdapterClientImpl() {
47 this.props = new VnfAdapterRestProperties();
50 public VnfAdapterClientImpl(VnfAdapterRestProperties props) {
55 public CreateVfModuleResponse createVfModule(String aaiVnfId, CreateVfModuleRequest req)
56 throws VnfAdapterClientException {
58 return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + "/vf-modules").build()).post(req,
59 CreateVfModuleResponse.class);
60 } catch (InternalServerErrorException e) {
61 throw new VnfAdapterClientException(e.getMessage());
66 public RollbackVfModuleResponse rollbackVfModule(String aaiVnfId, String aaiVfModuleId, RollbackVfModuleRequest req)
67 throws VnfAdapterClientException {
69 return new AdapterRestClient(this.props,
70 this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId + "/rollback").build()).delete(req,
71 RollbackVfModuleResponse.class);
72 } catch (InternalServerErrorException e) {
73 throw new VnfAdapterClientException(e.getMessage());
78 public DeleteVfModuleResponse deleteVfModule(String aaiVnfId, String aaiVfModuleId, DeleteVfModuleRequest req)
79 throws VnfAdapterClientException {
81 return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId).build())
82 .delete(req, DeleteVfModuleResponse.class);
83 } catch (InternalServerErrorException e) {
84 throw new VnfAdapterClientException(e.getMessage());
89 public UpdateVfModuleResponse updateVfModule(String aaiVnfId, String aaiVfModuleId, UpdateVfModuleRequest req)
90 throws VnfAdapterClientException {
92 return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId).build())
93 .put(req, UpdateVfModuleResponse.class);
94 } catch (InternalServerErrorException e) {
95 throw new VnfAdapterClientException(e.getMessage());
100 public QueryVfModuleResponse queryVfModule(String aaiVnfId, String aaiVfModuleId, String cloudSiteId,
101 String tenantId, String vfModuleName, boolean skipAAI, String requestId, String serviceInstanceId)
102 throws VnfAdapterClientException {
103 UriBuilder builder = this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId);
104 if (cloudSiteId != null) {
105 builder.queryParam("cloudSiteId", cloudSiteId);
107 if (tenantId != null) {
108 builder.queryParam("tenantId", tenantId);
110 if (vfModuleName != null) {
111 builder.queryParam("vfModuleName", vfModuleName);
114 builder.queryParam("skipAAI", skipAAI);
116 if (requestId != null) {
117 builder.queryParam("msoRequest.requestId", requestId);
119 if (serviceInstanceId != null) {
120 builder.queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
123 return new AdapterRestClient(this.props, builder.build(), MediaType.APPLICATION_JSON,
124 MediaType.APPLICATION_JSON).get(QueryVfModuleResponse.class).get();
125 } catch (InternalServerErrorException e) {
126 throw new VnfAdapterClientException(e.getMessage());
130 public UriBuilder getUri(String path) {
131 return UriBuilder.fromPath(path);