2 * ============LICENSE_START=======================================================
3 * SOActorServiceProvider
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.actor.so;
24 import com.google.common.collect.ImmutableList;
25 import com.google.common.collect.ImmutableMap;
26 import com.google.gson.reflect.TypeToken;
27 import java.lang.reflect.Type;
28 import java.util.Collections;
29 import java.util.List;
31 import org.onap.aai.domain.yang.CloudRegion;
32 import org.onap.aai.domain.yang.GenericVnf;
33 import org.onap.aai.domain.yang.ServiceInstance;
34 import org.onap.aai.domain.yang.Tenant;
35 import org.onap.policy.aai.AaiCqResponse;
36 import org.onap.policy.aai.AaiNqExtraProperty;
37 import org.onap.policy.aai.AaiNqInventoryResponseItem;
38 import org.onap.policy.aai.AaiNqResponseWrapper;
39 import org.onap.policy.controlloop.ControlLoopOperation;
40 import org.onap.policy.controlloop.VirtualControlLoopEvent;
41 import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
42 import org.onap.policy.controlloop.policy.Policy;
43 import org.onap.policy.so.SoCloudConfiguration;
44 import org.onap.policy.so.SoManager;
45 import org.onap.policy.so.SoModelInfo;
46 import org.onap.policy.so.SoOperationType;
47 import org.onap.policy.so.SoRelatedInstance;
48 import org.onap.policy.so.SoRelatedInstanceListElement;
49 import org.onap.policy.so.SoRequest;
50 import org.onap.policy.so.SoRequestDetails;
51 import org.onap.policy.so.SoRequestInfo;
52 import org.onap.policy.so.SoRequestParameters;
53 import org.onap.policy.so.util.Serialization;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
57 public class SoActorServiceProvider implements Actor {
58 private static final Logger logger = LoggerFactory.getLogger(SoActorServiceProvider.class);
60 // Strings for SO Actor
61 private static final String SO_ACTOR = "SO";
63 // Strings for targets
64 private static final String TARGET_VFC = "VFC";
66 // Strings for recipes
67 private static final String RECIPE_VF_MODULE_CREATE = "VF Module Create";
68 private static final String RECIPE_VF_MODULE_DELETE = "VF Module Delete";
70 private static final ImmutableList<String> recipes =
71 ImmutableList.of(RECIPE_VF_MODULE_CREATE, RECIPE_VF_MODULE_DELETE);
72 private static final ImmutableMap<String, List<String>> targets =
73 new ImmutableMap.Builder<String, List<String>>().put(RECIPE_VF_MODULE_CREATE, ImmutableList.of(TARGET_VFC))
74 .put(RECIPE_VF_MODULE_DELETE, ImmutableList.of(TARGET_VFC)).build();
76 // name of request parameters within policy payload
77 public static final String REQ_PARAM_NM = "requestParameters";
79 // name of configuration parameters within policy payload
80 public static final String CONFIG_PARAM_NM = "configurationParameters";
82 private static final String MODEL_NAME_PROPERTY_KEY = "model-ver.model-name";
83 private static final String MODEL_VERSION_PROPERTY_KEY = "model-ver.model-version";
84 private static final String MODEL_VERSION_ID_PROPERTY_KEY = "model-ver.model-version-id";
86 // used to decode configuration parameters via gson
87 private static final Type CONFIG_TYPE = new TypeToken<List<Map<String, String>>>() {}.getType();
89 // Static variables required to hold the IDs of the last service item, VNF item and VF Module.
91 // a multithreaded deployment this WILL break
92 private static String lastVNFItemVnfId;
93 private static String lastServiceItemServiceInstanceId;
94 private static String lastVfModuleItemVfModuleInstanceId;
97 public String actor() {
102 public List<String> recipes() {
103 return ImmutableList.copyOf(recipes);
107 public List<String> recipeTargets(String recipe) {
108 return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
112 public List<String> recipePayloads(String recipe) {
113 return Collections.emptyList();
117 * Constructs a SO request conforming to the lcm API. The actual request is constructed and then placed in a wrapper
118 * object used to send through DMAAP.
120 * @param onset the event that is reporting the alert for policy to perform an action
121 * @param operation the control loop operation specifying the actor, operation, target, etc.
122 * @param policy the policy the was specified from the yaml generated by CLAMP or through the Policy GUI/API
123 * @param aaiResponseWrapper wrapper for AAI vserver named-query response
124 * @return a SO request conforming to the lcm API using the DMAAP wrapper
126 public SoRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy,
127 AaiNqResponseWrapper aaiResponseWrapper) {
128 if (!SO_ACTOR.equals(policy.getActor()) || !recipes().contains(policy.getRecipe())) {
132 // A&AI named query should have been performed by now. If not, return null
133 if (aaiResponseWrapper == null) {
137 AaiNqInventoryResponseItem vnfItem;
138 AaiNqInventoryResponseItem vnfServiceItem;
139 AaiNqInventoryResponseItem tenantItem;
141 // Extract the items we're interested in from the response
143 vnfItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems()
144 .getInventoryResponseItems().get(0);
145 } catch (Exception e) {
146 logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper),
152 vnfServiceItem = vnfItem.getItems().getInventoryResponseItems().get(0);
153 } catch (Exception e) {
154 logger.error("VNF Service Item not found in AAI response {}",
155 Serialization.gsonPretty.toJson(aaiResponseWrapper), e);
160 tenantItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems()
161 .getInventoryResponseItems().get(1);
162 } catch (Exception e) {
163 logger.error("Tenant Item not found in AAI response {}",
164 Serialization.gsonPretty.toJson(aaiResponseWrapper), e);
168 // Find the index for base vf module and non-base vf module
169 AaiNqInventoryResponseItem baseItem = findVfModule(aaiResponseWrapper, true);
171 SoModelInfo soModelInfo = prepareSoModelInfo(policy);
173 // Report the error if either base vf module or non-base vf module is not found
174 if (baseItem == null || soModelInfo == null) {
175 logger.error("Either base or non-base vf module is not found from AAI response.");
179 // Construct SO Request for a policy's recipe
180 if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) {
181 return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem, soModelInfo);
182 } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
183 return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, soModelInfo, policy);
189 private SoModelInfo prepareSoModelInfo(Policy policy) {
191 SoModelInfo soModelInfo = new SoModelInfo();
192 if ((policy.getTarget() != null && (policy.getTarget().getModelCustomizationId() != null))
193 && (policy.getTarget().getModelInvariantId() != null) && (policy.getTarget().getModelName() != null)
194 && (policy.getTarget().getModelVersion() != null) && (policy.getTarget().getModelVersionId() != null)) {
196 soModelInfo.setModelCustomizationId(policy.getTarget().getModelCustomizationId());
197 soModelInfo.setModelInvariantId(policy.getTarget().getModelInvariantId());
198 soModelInfo.setModelName(policy.getTarget().getModelName());
199 soModelInfo.setModelVersion(policy.getTarget().getModelVersion());
200 soModelInfo.setModelVersionId(policy.getTarget().getModelVersionId());
209 * Construct SO request to create vf-module.
211 * @param aaiResponseWrapper the AAI response containing the VF modules
212 * @param policy the policy
213 * @param tenantItem tenant item from A&AI named-query response
214 * @param vnfItem vnf item from A&AI named-query response
215 * @param vnfServiceItem vnf service item from A&AI named-query response
216 * @param vfModuleItem vf module item from A&AI named-query response
217 * @return SO create vf-module request
219 private SoRequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy,
220 AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem,
221 AaiNqInventoryResponseItem vnfServiceItem, SoModelInfo vfModuleItem) {
222 SoRequest request = new SoRequest();
223 request.setOperationType(SoOperationType.SCALE_OUT);
226 // Do NOT send So the requestId, they do not support this field
228 request.setRequestDetails(new SoRequestDetails());
229 request.getRequestDetails().setRequestParameters(new SoRequestParameters());
230 request.getRequestDetails().getRequestParameters().setUserParams(null);
232 // cloudConfiguration
233 request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem));
235 request.getRequestDetails().setModelInfo(vfModuleItem);
238 request.getRequestDetails().setRequestInfo(constructRequestInfo());
239 String vfModuleName = aaiResponseWrapper.genVfModuleName();
240 request.getRequestDetails().getRequestInfo().setInstanceName(vfModuleName);
242 // relatedInstanceList
243 SoRelatedInstanceListElement relatedInstanceListElement1 = new SoRelatedInstanceListElement();
244 SoRelatedInstanceListElement relatedInstanceListElement2 = new SoRelatedInstanceListElement();
245 relatedInstanceListElement1.setRelatedInstance(new SoRelatedInstance());
246 relatedInstanceListElement2.setRelatedInstance(new SoRelatedInstance());
249 relatedInstanceListElement1.getRelatedInstance()
250 .setInstanceId(vnfServiceItem.getServiceInstance().getServiceInstanceId());
251 relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SoModelInfo());
252 relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service");
253 relatedInstanceListElement1.getRelatedInstance().getModelInfo()
254 .setModelInvariantId(vnfServiceItem.getServiceInstance().getModelInvariantId());
255 for (AaiNqExtraProperty prop : vnfServiceItem.getExtraProperties().getExtraProperty()) {
256 if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
257 relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue());
258 } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
259 relatedInstanceListElement1.getRelatedInstance().getModelInfo()
260 .setModelVersion(prop.getPropertyValue());
261 } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) {
262 relatedInstanceListElement1.getRelatedInstance().getModelInfo()
263 .setModelVersionId(prop.getPropertyValue());
268 relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getGenericVnf().getVnfId());
269 relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SoModelInfo());
270 relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf");
271 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
272 .setModelInvariantId(vnfItem.getGenericVnf().getModelInvariantId());
273 for (AaiNqExtraProperty prop : vnfItem.getExtraProperties().getExtraProperty()) {
274 if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
275 relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue());
276 } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
277 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
278 .setModelVersion(prop.getPropertyValue());
279 } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) {
280 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
281 .setModelVersionId(prop.getPropertyValue());
284 relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelCustomizationName(vnfItem
285 .getGenericVnf().getVnfType().substring(vnfItem.getGenericVnf().getVnfType().lastIndexOf('/') + 1));
286 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
287 .setModelCustomizationId(vnfItem.getGenericVnf().getModelCustomizationId());
289 // Insert the Service Item and VNF Item
290 request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1);
291 request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2);
293 // Request Parameters
294 buildRequestParameters(policy, request.getRequestDetails());
296 // Configuration Parameters
297 buildConfigurationParameters(policy, request.getRequestDetails());
298 // Save the instance IDs for the VNF and service to static fields
299 // vfModuleId is not required for the create vf-module
300 preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(),
301 vnfServiceItem.getServiceInstance().getServiceInstanceId(), null);
302 if (logger.isDebugEnabled()) {
303 logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
309 * Construct SO request to delete vf-module.
311 * @param tenantItem tenant item from A&AI named-query response
312 * @param vnfItem vnf item from A&AI named-query response
313 * @param vnfServiceItem vnf service item from A&AI named-query response
314 * @param vfModuleItem vf module item from A&AI named-query response
315 * @return SO delete vf-module request
317 private SoRequest constructDeleteRequest(AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem,
318 AaiNqInventoryResponseItem vnfServiceItem, SoModelInfo vfModuleItem, Policy policy) {
319 SoRequest request = new SoRequest();
320 request.setOperationType(SoOperationType.DELETE_VF_MODULE);
321 request.setRequestDetails(new SoRequestDetails());
322 request.getRequestDetails().setRelatedInstanceList(null);
323 request.getRequestDetails().setConfigurationParameters(null);
325 // cloudConfiguration
326 request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem));
328 request.getRequestDetails().setModelInfo(prepareSoModelInfo(policy));
330 request.getRequestDetails().setRequestInfo(constructRequestInfo());
331 // Save the instance IDs for the VNF, service and vfModule to static fields
332 preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(),
333 vnfServiceItem.getServiceInstance().getServiceInstanceId(), null);
335 if (logger.isDebugEnabled()) {
336 logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
342 * Construct requestInfo for the SO requestDetails.
344 * @return SO request information
346 private SoRequestInfo constructRequestInfo() {
347 SoRequestInfo soRequestInfo = new SoRequestInfo();
348 soRequestInfo.setSource("POLICY");
349 soRequestInfo.setSuppressRollback(false);
350 soRequestInfo.setRequestorId("policy");
351 return soRequestInfo;
355 * Construct cloudConfiguration for the SO requestDetails.
357 * @param tenantItem tenant item from A&AI named-query response
358 * @return SO cloud configuration
360 private SoCloudConfiguration constructCloudConfiguration(AaiNqInventoryResponseItem tenantItem) {
361 SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration();
362 cloudConfiguration.setTenantId(tenantItem.getTenant().getTenantId());
363 cloudConfiguration.setLcpCloudRegionId(
364 tenantItem.getItems().getInventoryResponseItems().get(0).getCloudRegion().getCloudRegionId());
365 return cloudConfiguration;
369 * This method is needed to get the serviceInstanceId and vnfInstanceId which is used in the asyncSORestCall.
371 * @param requestId the request Id
372 * @param callback callback method
373 * @param request the request
374 * @param url SO REST URL
375 * @param user username
376 * @param password password
378 public static void sendRequest(String requestId, SoManager.SoCallback callback, Object request, String url,
379 String user, String password) {
380 SoManager soManager = new SoManager(url, user, password);
381 soManager.asyncSoRestCall(requestId, callback, lastServiceItemServiceInstanceId, lastVNFItemVnfId,
382 lastVfModuleItemVfModuleInstanceId, (SoRequest) request);
386 * Find the base or non base VF module item in an AAI response. If there is more than one item, then the <i>last</i>
389 * @param aaiResponseWrapper the AAI response containing the VF modules
390 * @param baseFlag true if we are searching for the base, false if we are searching for the non base
391 * @return the base or non base VF module item or null if the module was not found
393 private AaiNqInventoryResponseItem findVfModule(AaiNqResponseWrapper aaiResponseWrapper, boolean baseFlag) {
394 List<AaiNqInventoryResponseItem> lst = aaiResponseWrapper.getVfModuleItems(baseFlag);
395 return (lst.isEmpty() ? null : lst.get(lst.size() - 1));
399 * Builds the request parameters from the policy payload.
401 * @param policy the policy
402 * @param request request into which to stick the request parameters
404 private void buildRequestParameters(Policy policy, SoRequestDetails request) {
405 // assume null until proven otherwise
406 request.setRequestParameters(null);
408 if (policy.getPayload() == null) {
412 String json = policy.getPayload().get(REQ_PARAM_NM);
417 request.setRequestParameters(Serialization.gsonPretty.fromJson(json, SoRequestParameters.class));
421 * Builds the configuration parameters from the policy payload.
423 * @param policy the policy
424 * @param request request into which to stick the configuration parameters
426 private void buildConfigurationParameters(Policy policy, SoRequestDetails request) {
427 // assume null until proven otherwise
428 request.setConfigurationParameters(null);
430 if (policy.getPayload() == null) {
434 String json = policy.getPayload().get(CONFIG_PARAM_NM);
439 request.setConfigurationParameters(Serialization.gsonPretty.fromJson(json, CONFIG_TYPE));
443 * This method is called to remember the last service instance ID, VNF Item VNF ID and vf module ID. Note these
444 * fields are static, beware for multithreaded deployments
446 * @param vnfInstanceId update the last VNF instance ID to this value
447 * @param serviceInstanceId update the last service instance ID to this value
448 * @param vfModuleId update the vfModule instance ID to this value
450 private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId,
451 final String vfModuleId) {
452 lastVNFItemVnfId = vnfInstanceId;
453 lastServiceItemServiceInstanceId = serviceInstanceId;
454 lastVfModuleItemVfModuleInstanceId = vfModuleId;
458 * Constructs a SO request conforming to the lcm API. The actual request is constructed and then placed in a wrapper
459 * object used to send through DMAAP.
461 * @param onset the event that is reporting the alert for policy to perform an action
462 * @param operation the control loop operation specifying the actor, operation, target, etc.
463 * @param policy the policy the was specified from the yaml generated by CLAMP or through the Policy GUI/API
464 * @param aaiCqResponse response from A&AI custom query
465 * @return a SO request conforming to the lcm API using the DMAAP wrapper
467 public SoRequest constructRequestCq(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy,
468 AaiCqResponse aaiCqResponse) {
469 if (!SO_ACTOR.equals(policy.getActor()) || !recipes().contains(policy.getRecipe())) {
473 // A&AI named query should have been performed by now. If not, return null
474 if (aaiCqResponse == null) {
479 ServiceInstance vnfServiceItem;
481 CloudRegion cloudRegionItem;
483 // Extract the items we're interested in from the response
485 vnfItem = aaiCqResponse.getDefaultGenericVnf();
486 } catch (Exception e) {
487 logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiCqResponse), e);
492 vnfServiceItem = aaiCqResponse.getServiceInstance();
493 } catch (Exception e) {
494 logger.error("VNF Service Item not found in AAI response {}",
495 Serialization.gsonPretty.toJson(aaiCqResponse), e);
500 tenantItem = aaiCqResponse.getDefaultTenant();
501 } catch (Exception e) {
502 logger.error("Tenant Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiCqResponse), e);
507 cloudRegionItem = aaiCqResponse.getDefaultCloudRegion();
508 } catch (Exception e) {
509 logger.error("Tenant Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiCqResponse), e);
513 SoModelInfo soModelInfo = prepareSoModelInfo(policy);
515 // Report the error vf module is not found
516 if (soModelInfo == null) {
517 logger.error("vf module is not found.");
521 // Construct SO Request for a policy's recipe
522 if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) {
523 return constructCreateRequestCq(aaiCqResponse, policy, tenantItem, vnfItem, vnfServiceItem, soModelInfo,
525 } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
526 return constructDeleteRequestCq(tenantItem, vnfItem, vnfServiceItem, soModelInfo, policy, cloudRegionItem);
533 * Construct the So request, based on Custom Query response from A&AI.
535 * @param aaiCqResponse Custom query response from A&AI
536 * @param policy policy information
537 * @param tenantItem Tenant from CQ response
538 * @param vnfItem Generic VNF from CQ response
539 * @param vnfServiceItem Service Instance from CQ response
540 * @param vfModuleItem VF Module from CustomQuery response
541 * @param cloudRegionItem Cloud Region from Custom query response
542 * @return SoRequest well formed So Request
544 private SoRequest constructCreateRequestCq(AaiCqResponse aaiCqResponse, Policy policy, Tenant tenantItem,
545 GenericVnf vnfItem, ServiceInstance vnfServiceItem, SoModelInfo vfModuleItem, CloudRegion cloudRegionItem) {
546 SoRequest request = new SoRequest();
547 request.setOperationType(SoOperationType.SCALE_OUT);
550 // Do NOT send So the requestId, they do not support this field
552 request.setRequestDetails(new SoRequestDetails());
553 request.getRequestDetails().setRequestParameters(new SoRequestParameters());
554 request.getRequestDetails().getRequestParameters().setUserParams(null);
556 // cloudConfiguration
557 request.getRequestDetails().setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem));
559 request.getRequestDetails().setModelInfo(vfModuleItem);
562 request.getRequestDetails().setRequestInfo(constructRequestInfo());
563 String vfModuleName = aaiCqResponse.getDefaultVfModule().getVfModuleName();
564 request.getRequestDetails().getRequestInfo().setInstanceName(vfModuleName);
566 // relatedInstanceList
567 SoRelatedInstanceListElement relatedInstanceListElement1 = new SoRelatedInstanceListElement();
568 SoRelatedInstanceListElement relatedInstanceListElement2 = new SoRelatedInstanceListElement();
569 relatedInstanceListElement1.setRelatedInstance(new SoRelatedInstance());
570 relatedInstanceListElement2.setRelatedInstance(new SoRelatedInstance());
572 // Service Item (Note that Model Name and Model Version are not available in A&AI schema for ServiceInstance)
573 relatedInstanceListElement1.getRelatedInstance().setInstanceId(vnfServiceItem.getServiceInstanceId());
574 relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SoModelInfo());
575 relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service");
576 relatedInstanceListElement1.getRelatedInstance().getModelInfo()
577 .setModelInvariantId(vnfServiceItem.getModelInvariantId());
578 relatedInstanceListElement1.getRelatedInstance().getModelInfo()
579 .setModelVersionId(vnfServiceItem.getModelVersionId());
582 // VNF Item (Note that Model Name, Model Version, and Model Customization Name are not available in A&AI schema
584 relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getVnfId());
585 relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SoModelInfo());
586 relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf");
587 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
588 .setModelInvariantId(vnfItem.getModelInvariantId());
589 relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersionId(vnfItem.getModelVersionId());
590 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
591 .setModelCustomizationId(vnfItem.getModelCustomizationId());
593 // Insert the Service Item and VNF Item
594 request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1);
595 request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2);
597 // Request Parameters
598 buildRequestParameters(policy, request.getRequestDetails());
600 // Configuration Parameters
601 buildConfigurationParameters(policy, request.getRequestDetails());
602 // Save the instance IDs for the VNF and service to static fields
603 // vfModuleId is not required for the create vf-module
604 preserveInstanceIds(vnfItem.getVnfId(), vnfServiceItem.getServiceInstanceId(), null);
605 if (logger.isDebugEnabled()) {
606 logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
612 * constructs delete request for So.
614 * @param tenantItem Tenant from A&AI CQ request
615 * @param vnfItem Generic VNF from A&AI CQ request
616 * @param vnfServiceItem ServiceInstance from A&AI CQ request
617 * @param vfModuleItem VFModule from A&AI CQ request
618 * @param policy policy information
619 * @param cloudRegionItem CloudRegion from A&AI CQ request
620 * @return SoRequest deleted
622 private SoRequest constructDeleteRequestCq(Tenant tenantItem, GenericVnf vnfItem, ServiceInstance vnfServiceItem,
623 SoModelInfo vfModuleItem, Policy policy, CloudRegion cloudRegionItem) {
624 SoRequest request = new SoRequest();
625 request.setOperationType(SoOperationType.DELETE_VF_MODULE);
626 request.setRequestDetails(new SoRequestDetails());
627 request.getRequestDetails().setRelatedInstanceList(null);
628 request.getRequestDetails().setConfigurationParameters(null);
630 // cloudConfiguration
631 request.getRequestDetails().setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem));
633 request.getRequestDetails().setModelInfo(prepareSoModelInfo(policy));
635 request.getRequestDetails().setRequestInfo(constructRequestInfo());
636 // Save the instance IDs for the VNF, service and vfModule to static fields
637 preserveInstanceIds(vnfItem.getVnfId(), vnfServiceItem.getServiceInstanceId(), null);
639 if (logger.isDebugEnabled()) {
640 logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
647 * Construct cloudConfiguration for the SO requestDetails. Overridden for custom query.
649 * @param tenantItem tenant item from A&AI named-query response
650 * @return SO cloud configuration
652 private SoCloudConfiguration constructCloudConfigurationCq(Tenant tenantItem, CloudRegion cloudRegionItem) {
653 SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration();
654 cloudConfiguration.setTenantId(tenantItem.getTenantId());
655 cloudConfiguration.setLcpCloudRegionId(cloudRegionItem.getCloudRegionId());
656 return cloudConfiguration;