diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java new file mode 100644 index 0000000000..0e0fd3bb5d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.adapter.vnf; + +import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriBuilder; + +import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.QueryVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.RollbackVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse; +import org.onap.so.client.RestClient; +import org.onap.so.client.adapter.rest.AdapterRestClient; +import org.springframework.stereotype.Component; + +@Component +public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient { + + private final VnfVolumeAdapterRestProperties props; + + public VnfVolumeAdapterClientImpl() { + this.props = new VnfVolumeAdapterRestProperties(); + } + + @Override + public CreateVolumeGroupResponse createVNFVolumes(CreateVolumeGroupRequest req) throws VnfAdapterClientException { + try { + return this.getAdapterRestClient("").post(req, CreateVolumeGroupResponse.class); + } catch (InternalServerErrorException e) { + throw new VnfAdapterClientException(e.getMessage()); + } + } + + @Override + public DeleteVolumeGroupResponse deleteVNFVolumes(String aaiVolumeGroupId, DeleteVolumeGroupRequest req) + throws VnfAdapterClientException { + try { + return this.getAdapterRestClient("/" + aaiVolumeGroupId).delete(req, DeleteVolumeGroupResponse.class); + } catch (InternalServerErrorException e) { + throw new VnfAdapterClientException(e.getMessage()); + } + } + + @Override + public RollbackVolumeGroupResponse rollbackVNFVolumes(String aaiVolumeGroupId, RollbackVolumeGroupRequest req) + throws VnfAdapterClientException { + try { + return this.getAdapterRestClient("/" + aaiVolumeGroupId + "/rollback").delete(req, + RollbackVolumeGroupResponse.class); + } catch (InternalServerErrorException e) { + throw new VnfAdapterClientException(e.getMessage()); + } + } + + @Override + public UpdateVolumeGroupResponse updateVNFVolumes(String aaiVolumeGroupId, UpdateVolumeGroupRequest req) + throws VnfAdapterClientException { + try { + return this.getAdapterRestClient("/" + aaiVolumeGroupId).put(req, UpdateVolumeGroupResponse.class); + } catch (InternalServerErrorException e) { + throw new VnfAdapterClientException(e.getMessage()); + } + } + + @Override + public QueryVolumeGroupResponse queryVNFVolumes(String aaiVolumeGroupId, String cloudSiteId, String tenantId, + String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId) + throws VnfAdapterClientException { + try { + String path = buildQueryPath(aaiVolumeGroupId, cloudSiteId, tenantId, volumeGroupStackId, skipAAI, + requestId, serviceInstanceId); + return this.getAdapterRestClient(path).get(QueryVolumeGroupResponse.class).get(); + } catch (InternalServerErrorException e) { + throw new VnfAdapterClientException(e.getMessage()); + } + } + + protected String buildQueryPath(String aaiVolumeGroupId, String cloudSiteId, String tenantId, + String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId) { + javax.ws.rs.core.UriBuilder builder = this.getUri("/" + aaiVolumeGroupId); + builder.queryParam("cloudSiteId", cloudSiteId).queryParam("tenantId", tenantId) + .queryParam("volumeGroupStackId", volumeGroupStackId).queryParam("skipAAI", skipAAI) + .queryParam("msoRequest.requestId", requestId) + .queryParam("msoRequest.serviceInstanceId", serviceInstanceId); + return builder.build().toString(); + } + + protected UriBuilder getUri(String path) { + return UriBuilder.fromPath(path); + } + + protected RestClient getAdapterRestClient(String path) { + return new AdapterRestClient(props, this.getUri(path).build(), MediaType.APPLICATION_JSON, + MediaType.APPLICATION_JSON); + } +} |