1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/*-
* ============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.mapper;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.PostConstruct;
import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
import org.onap.so.bpmn.core.UrnPropertiesReader;
import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
import org.onap.so.entity.MsoRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriUtils;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@Component
public class VnfAdapterObjectMapper {
private ObjectMapper mapper = new ObjectMapper();
@PostConstruct
public void init () {
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
}
public CreateVolumeGroupRequest createVolumeGroupRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf, VolumeGroup volumeGroup, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
CreateVolumeGroupRequest createVolumeGroupRequest = new CreateVolumeGroupRequest();
createVolumeGroupRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
createVolumeGroupRequest.setTenantId(cloudRegion.getTenantId());
createVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
createVolumeGroupRequest.setVolumeGroupName(volumeGroup.getVolumeGroupName());
createVolumeGroupRequest.setVnfType(genericVnf.getVnfType());
createVolumeGroupRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
createVolumeGroupRequest.setVfModuleType(volumeGroup.getModelInfoVfModule().getModelName());
createVolumeGroupRequest.setModelCustomizationUuid(volumeGroup.getModelInfoVfModule().getModelCustomizationUUID());
createVolumeGroupRequest.setVolumeGroupParams(createVolumeGroupParams(requestContext,genericVnf, volumeGroup, sdncVfModuleQueryResponse));
createVolumeGroupRequest.setSkipAAI(true);
createVolumeGroupRequest.setSuppressBackout(orchestrationContext.getIsRollbackEnabled());
createVolumeGroupRequest.setFailIfExists(true);
createVolumeGroupRequest.setMsoRequest(createMsoRequest(requestContext, serviceInstance));
String messageId = getRandomUuid();
createVolumeGroupRequest.setMessageId(messageId);
createVolumeGroupRequest.setNotificationUrl(createCallbackUrl("VNFAResponse", messageId));
return createVolumeGroupRequest;
}
public DeleteVolumeGroupRequest deleteVolumeGroupRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, ServiceInstance serviceInstance, VolumeGroup volumeGroup) throws IOException {
DeleteVolumeGroupRequest deleteVolumeGroupRequest = new DeleteVolumeGroupRequest();
deleteVolumeGroupRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
deleteVolumeGroupRequest.setTenantId(cloudRegion.getTenantId());
deleteVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
deleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
deleteVolumeGroupRequest.setSkipAAI(true);
deleteVolumeGroupRequest.setMsoRequest(createMsoRequest(requestContext, serviceInstance));
String messageId = getRandomUuid();
deleteVolumeGroupRequest.setMessageId(messageId);
deleteVolumeGroupRequest.setNotificationUrl(createCallbackUrl("VNFAResponse", messageId));
return deleteVolumeGroupRequest;
}
public Map<String, String> createVolumeGroupParams(RequestContext requestContext,GenericVnf genericVnf, VolumeGroup volumeGroup, String sdncVfModuleQueryResponse) throws JsonParseException, JsonMappingException, IOException {
Map<String, String> volumeGroupParams = new HashMap<>();
final String USER_PARAM_NAME_KEY = "name";
final String USER_PARAM_VALUE_KEY = "value";
// sdncVfModuleQueryResponse will not be available in aLaCarte case
if (sdncVfModuleQueryResponse != null) {
GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = mapper.readValue(sdncVfModuleQueryResponse, GenericResourceApiVfmoduletopologyVfModuleTopology.class);
buildParamsMapFromSdncParams(volumeGroupParams, vfModuleTopology.getVfModuleParameters());
}
if(null != requestContext.getRequestParameters() && null != requestContext.getRequestParameters().getUserParams()) {
List<Map<String, Object>> userParams = requestContext.getRequestParameters().getUserParams();
for (Map<String, Object> userParamsMap : userParams) {
if ( userParamsMap.containsKey(USER_PARAM_NAME_KEY) && (userParamsMap.get(USER_PARAM_NAME_KEY) instanceof String)
&& userParamsMap.containsKey(USER_PARAM_VALUE_KEY) && (userParamsMap.get(USER_PARAM_VALUE_KEY) instanceof String)) {
volumeGroupParams.put((String) userParamsMap.get(USER_PARAM_NAME_KEY), (String) userParamsMap.get(USER_PARAM_VALUE_KEY));
}
}
}
volumeGroupParams.put("vnf_id", genericVnf.getVnfId());
volumeGroupParams.put("vnf_name", genericVnf.getVnfName());
volumeGroupParams.put("vf_module_id", volumeGroup.getVolumeGroupId());
volumeGroupParams.put("vf_module_name", volumeGroup.getVolumeGroupName());
return volumeGroupParams;
}
public MsoRequest createMsoRequest(RequestContext requestContext, ServiceInstance serviceInstance) {
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId(requestContext.getMsoRequestId());
msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
return msoRequest;
}
private void buildParamsMapFromSdncParams(Map<String,String> volumeGroupParams, GenericResourceApiParam sdncParameters) {
if (sdncParameters != null) {
List<GenericResourceApiParamParam> sdncParametersList = sdncParameters.getParam();
if (sdncParametersList != null) {
for (int i = 0; i < sdncParametersList.size(); i++) {
GenericResourceApiParamParam param = sdncParametersList.get(i);
String parameterName = param.getName();
String parameterValue = param.getValue();
volumeGroupParams.put(parameterName, parameterValue);
}
}
}
}
protected String getRandomUuid() {
return UUID.randomUUID().toString();
}
protected String createCallbackUrl(String messageType, String correlator) throws UnsupportedEncodingException {
String endpoint = getProperty("mso.workflow.message.endpoint");
while (endpoint.endsWith("/")) {
endpoint = endpoint.substring(0, endpoint.length()-1);
}
return endpoint + "/" + UriUtils.encodePathSegment(messageType, "UTF-8") + "/" + UriUtils.encodePathSegment(correlator, "UTF-8");
}
protected String getProperty(String key) {
return UrnPropertiesReader.getVariable(key);
}
}
|