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.CreateVfModuleRequest;
27 import org.onap.so.adapters.vnfrest.CreateVfModuleResponse;
28 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
29 import org.onap.so.adapters.vnfrest.DeleteVfModuleResponse;
30 import org.onap.so.adapters.vnfrest.QueryVfModuleResponse;
31 import org.onap.so.adapters.vnfrest.RollbackVfModuleRequest;
32 import org.onap.so.adapters.vnfrest.RollbackVfModuleResponse;
33 import org.onap.so.adapters.vnfrest.UpdateVfModuleRequest;
34 import org.onap.so.adapters.vnfrest.UpdateVfModuleResponse;
35 import org.onap.so.client.adapter.rest.AdapterRestClient;
36 import org.springframework.stereotype.Component;
39 public class VnfAdapterClientImpl implements VnfAdapterClient {
41 private static final String VF_MODULES = "/vf-modules/";
43 private VnfAdapterRestProperties props;
45 public VnfAdapterClientImpl() {
46 this.props = new VnfAdapterRestProperties();
49 public VnfAdapterClientImpl(VnfAdapterRestProperties props) {
54 public CreateVfModuleResponse createVfModule(String aaiVnfId, CreateVfModuleRequest req)
55 throws VnfAdapterClientException {
57 return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + "/vf-modules").build()).post(req,
58 CreateVfModuleResponse.class);
59 } catch (InternalServerErrorException e) {
60 throw new VnfAdapterClientException(e.getMessage());
65 public RollbackVfModuleResponse rollbackVfModule(String aaiVnfId, String aaiVfModuleId, RollbackVfModuleRequest req)
66 throws VnfAdapterClientException {
68 return new AdapterRestClient(this.props,
69 this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId + "/rollback").build()).delete(req,
70 RollbackVfModuleResponse.class);
71 } catch (InternalServerErrorException e) {
72 throw new VnfAdapterClientException(e.getMessage());
77 public DeleteVfModuleResponse deleteVfModule(String aaiVnfId, String aaiVfModuleId, DeleteVfModuleRequest req)
78 throws VnfAdapterClientException {
80 return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId).build())
81 .delete(req, DeleteVfModuleResponse.class);
82 } catch (InternalServerErrorException e) {
83 throw new VnfAdapterClientException(e.getMessage());
88 public UpdateVfModuleResponse updateVfModule(String aaiVnfId, String aaiVfModuleId, UpdateVfModuleRequest req)
89 throws VnfAdapterClientException {
91 return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId).build())
92 .put(req, UpdateVfModuleResponse.class);
93 } catch (InternalServerErrorException e) {
94 throw new VnfAdapterClientException(e.getMessage());
99 public QueryVfModuleResponse queryVfModule(String aaiVnfId, String aaiVfModuleId, String cloudSiteId,
100 String tenantId, String vfModuleName, boolean skipAAI, String requestId, String serviceInstanceId)
101 throws VnfAdapterClientException {
102 UriBuilder builder = this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId);
103 if (cloudSiteId != null) {
104 builder.queryParam("cloudSiteId", cloudSiteId);
106 if (tenantId != null) {
107 builder.queryParam("tenantId", tenantId);
109 if (vfModuleName != null) {
110 builder.queryParam("vfModuleName", vfModuleName);
113 builder.queryParam("skipAAI", skipAAI);
115 if (requestId != null) {
116 builder.queryParam("msoRequest.requestId", requestId);
118 if (serviceInstanceId != null) {
119 builder.queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
122 return new AdapterRestClient(this.props, builder.build(), MediaType.APPLICATION_JSON,
123 MediaType.APPLICATION_JSON).get(QueryVfModuleResponse.class).get();
124 } catch (InternalServerErrorException e) {
125 throw new VnfAdapterClientException(e.getMessage());
129 public UriBuilder getUri(String path) {
130 return UriBuilder.fromPath(path);