2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2020 Wipro Limited.
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 java.util.List;
26 import java.util.concurrent.CompletableFuture;
27 import javax.ws.rs.client.Entity;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
30 import org.apache.commons.lang3.tuple.Pair;
31 import org.onap.aai.domain.yang.CloudRegion;
32 import org.onap.aai.domain.yang.GenericVnf;
33 import org.onap.aai.domain.yang.ModelVer;
34 import org.onap.aai.domain.yang.ServiceInstance;
35 import org.onap.aai.domain.yang.Tenant;
36 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
37 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
38 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
39 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
40 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
41 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
42 import org.onap.policy.so.SoModelInfo;
43 import org.onap.policy.so.SoOperationType;
44 import org.onap.policy.so.SoRelatedInstance;
45 import org.onap.policy.so.SoRelatedInstanceListElement;
46 import org.onap.policy.so.SoRequest;
47 import org.onap.policy.so.SoRequestDetails;
48 import org.onap.policy.so.SoRequestParameters;
49 import org.onap.policy.so.SoResponse;
52 * Operation to create a VF Module. When this completes successfully, it increments its VF
55 public class VfModuleCreate extends SoOperation {
56 public static final String NAME = "VF Module Create";
58 private static final String PATH_PREFIX = "/";
61 private static final List<String> PROPERTY_NAMES = List.of(
62 OperationProperties.AAI_SERVICE,
63 OperationProperties.AAI_SERVICE_MODEL,
64 OperationProperties.AAI_VNF,
65 OperationProperties.AAI_VNF_MODEL,
66 OperationProperties.AAI_DEFAULT_CLOUD_REGION,
67 OperationProperties.AAI_DEFAULT_TENANT,
68 OperationProperties.DATA_VF_COUNT);
72 * Constructs the object.
74 * @param params operation parameters
75 * @param config configuration for this operation
77 public VfModuleCreate(ControlLoopOperationParams params, HttpPollingConfig config) {
78 super(params, config, PROPERTY_NAMES, params.getTargetEntityIds());
81 // ensure we have the necessary parameters
86 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
88 // starting a whole new attempt - reset the count
91 Pair<String, SoRequest> pair = makeRequest();
92 String path = getPath() + pair.getLeft();
93 SoRequest request = pair.getRight();
95 String url = getClient().getBaseUrl() + path;
97 String strRequest = prettyPrint(request);
98 logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
100 Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
102 Map<String, Object> headers = createSimpleHeaders();
104 return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, headers));
108 * Increments the VF count that's stored in the context, if the request was
112 protected Status detmStatus(Response rawResponse, SoResponse response) {
113 Status status = super.detmStatus(rawResponse, response);
115 if (status == Status.SUCCESS) {
116 setVfCount(getVfCount() + 1);
125 * @return a pair containing the request URL and the new request
127 protected Pair<String, SoRequest> makeRequest() {
128 final SoModelInfo soModelInfo = prepareSoModelInfo();
129 final GenericVnf vnfItem = getVnfItem();
130 final ServiceInstance vnfServiceItem = getServiceInstance();
131 final Tenant tenantItem = getDefaultTenant();
132 final CloudRegion cloudRegionItem = getDefaultCloudRegion();
133 final ModelVer vnfModel = getVnfModel();
134 final ModelVer vnfServiceModel = getServiceModel();
136 SoRequest request = new SoRequest();
137 request.setOperationType(SoOperationType.SCALE_OUT);
141 // Do NOT send SO the requestId, they do not support this field
143 request.setRequestDetails(new SoRequestDetails());
144 request.getRequestDetails().setRequestParameters(new SoRequestParameters());
145 request.getRequestDetails().getRequestParameters().setUserParams(null);
147 // cloudConfiguration
148 request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem, cloudRegionItem));
151 request.getRequestDetails().setModelInfo(soModelInfo);
154 request.getRequestDetails().setRequestInfo(constructRequestInfo());
155 request.getRequestDetails().getRequestInfo().setInstanceName("vfModuleName");
157 // relatedInstanceList
158 SoRelatedInstanceListElement relatedInstanceListElement1 = new SoRelatedInstanceListElement();
159 SoRelatedInstanceListElement relatedInstanceListElement2 = new SoRelatedInstanceListElement();
160 relatedInstanceListElement1.setRelatedInstance(new SoRelatedInstance());
161 relatedInstanceListElement2.setRelatedInstance(new SoRelatedInstance());
164 relatedInstanceListElement1.getRelatedInstance().setInstanceId(vnfServiceItem.getServiceInstanceId());
165 relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SoModelInfo());
166 relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service");
167 relatedInstanceListElement1.getRelatedInstance().getModelInfo()
168 .setModelInvariantId(vnfServiceItem.getModelInvariantId());
169 relatedInstanceListElement1.getRelatedInstance().getModelInfo()
170 .setModelVersionId(vnfServiceItem.getModelVersionId());
171 relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName(vnfModel.getModelName());
172 relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelVersion(vnfModel.getModelVersion());
175 relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getVnfId());
176 relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SoModelInfo());
177 relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf");
178 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
179 .setModelInvariantId(vnfItem.getModelInvariantId());
180 relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersionId(vnfItem.getModelVersionId());
182 relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName(vnfServiceModel.getModelName());
183 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
184 .setModelVersion(vnfServiceModel.getModelVersion());
186 relatedInstanceListElement2.getRelatedInstance().getModelInfo()
187 .setModelCustomizationId(vnfItem.getModelCustomizationId());
189 // Insert the Service Item and VNF Item
190 request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1);
191 request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2);
193 // Request Parameters
194 buildRequestParameters().ifPresent(request.getRequestDetails()::setRequestParameters);
196 // Configuration Parameters
197 buildConfigurationParameters().ifPresent(request.getRequestDetails()::setConfigurationParameters);
200 String path = PATH_PREFIX + vnfServiceItem.getServiceInstanceId() + "/vnfs/" + vnfItem.getVnfId()
201 + "/vfModules/scaleOut";
203 return Pair.of(path, request);