2 * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.be.components.impl;
19 import static java.util.stream.Collectors.joining;
20 import static java.util.stream.Collectors.toList;
21 import static java.util.stream.Collectors.toMap;
22 import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
23 import static org.openecomp.sdc.be.components.impl.CsarValidationUtils.TOSCA_METADATA_PATH_PATTERN;
24 import static org.openecomp.sdc.be.components.impl.CsarValidationUtils.TOSCA_META_ENTRY_DEFINITIONS;
25 import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaMapElement;
26 import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement;
27 import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
28 import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
30 import com.google.gson.Gson;
31 import com.google.gson.JsonElement;
32 import com.google.gson.JsonObject;
33 import com.google.gson.JsonParser;
34 import fj.data.Either;
35 import java.io.IOException;
36 import java.io.InputStream;
37 import java.io.StringReader;
38 import java.lang.reflect.Method;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.Collections;
43 import java.util.EnumMap;
44 import java.util.HashMap;
45 import java.util.HashSet;
46 import java.util.Iterator;
47 import java.util.LinkedHashMap;
48 import java.util.List;
50 import java.util.Map.Entry;
51 import java.util.Optional;
52 import java.util.Properties;
54 import java.util.TreeSet;
55 import java.util.concurrent.atomic.AtomicReference;
56 import java.util.regex.Pattern;
57 import java.util.stream.Collectors;
58 import javax.validation.constraints.NotNull;
61 import org.apache.commons.collections.CollectionUtils;
62 import org.apache.commons.collections.MapUtils;
63 import org.apache.commons.lang3.StringEscapeUtils;
64 import org.apache.commons.lang3.StringUtils;
65 import org.apache.commons.lang3.tuple.ImmutablePair;
66 import org.json.simple.JSONObject;
67 import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
68 import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
69 import org.openecomp.sdc.be.components.csar.CsarInfo;
70 import org.openecomp.sdc.be.components.csar.ServiceCsarInfo;
71 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
72 import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
73 import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
74 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
75 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
76 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
77 import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
78 import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils;
79 import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter;
80 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
81 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
82 import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
83 import org.openecomp.sdc.be.config.BeEcompErrorManager;
84 import org.openecomp.sdc.be.config.ConfigurationManager;
85 import org.openecomp.sdc.be.dao.api.ActionStatus;
86 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
87 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
88 import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
89 import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction;
90 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
91 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
92 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
93 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
94 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
95 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
96 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
97 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
98 import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction;
99 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
100 import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
101 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
102 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
103 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
104 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
105 import org.openecomp.sdc.be.impl.ComponentsUtils;
106 import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts;
107 import org.openecomp.sdc.be.model.ArtifactDefinition;
108 import org.openecomp.sdc.be.model.ArtifactTypeDefinition;
109 import org.openecomp.sdc.be.model.AttributeDefinition;
110 import org.openecomp.sdc.be.model.CapabilityDefinition;
111 import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
112 import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
113 import org.openecomp.sdc.be.model.Component;
114 import org.openecomp.sdc.be.model.ComponentInstance;
115 import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
116 import org.openecomp.sdc.be.model.ComponentInstanceInput;
117 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
118 import org.openecomp.sdc.be.model.ComponentParametersView;
119 import org.openecomp.sdc.be.model.DataTypeDefinition;
120 import org.openecomp.sdc.be.model.DistributionStatusEnum;
121 import org.openecomp.sdc.be.model.GroupDefinition;
122 import org.openecomp.sdc.be.model.GroupTypeDefinition;
123 import org.openecomp.sdc.be.model.InputDefinition;
124 import org.openecomp.sdc.be.model.InterfaceDefinition;
125 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
126 import org.openecomp.sdc.be.model.LifecycleStateEnum;
127 import org.openecomp.sdc.be.model.NodeTypeDefinition;
128 import org.openecomp.sdc.be.model.NodeTypeInfo;
129 import org.openecomp.sdc.be.model.NodeTypeMetadata;
130 import org.openecomp.sdc.be.model.NodeTypesMetadataList;
131 import org.openecomp.sdc.be.model.Operation;
132 import org.openecomp.sdc.be.model.OutputDefinition;
133 import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
134 import org.openecomp.sdc.be.model.PolicyDefinition;
135 import org.openecomp.sdc.be.model.PropertyDefinition;
136 import org.openecomp.sdc.be.model.RelationshipImpl;
137 import org.openecomp.sdc.be.model.RelationshipInfo;
138 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
139 import org.openecomp.sdc.be.model.RequirementDefinition;
140 import org.openecomp.sdc.be.model.Resource;
141 import org.openecomp.sdc.be.model.Service;
142 import org.openecomp.sdc.be.model.UploadAttributeInfo;
143 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
144 import org.openecomp.sdc.be.model.UploadInterfaceInfo;
145 import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
146 import org.openecomp.sdc.be.model.UploadPropInfo;
147 import org.openecomp.sdc.be.model.UploadReqInfo;
148 import org.openecomp.sdc.be.model.UploadResourceInfo;
149 import org.openecomp.sdc.be.model.User;
150 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
151 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
152 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
153 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
154 import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata;
155 import org.openecomp.sdc.be.model.operations.StorageException;
156 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
157 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
158 import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation;
159 import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
160 import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
161 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
162 import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
163 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
164 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
165 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
166 import org.openecomp.sdc.be.tosca.CsarUtils;
167 import org.openecomp.sdc.be.tosca.ToscaExportHandler;
168 import org.openecomp.sdc.be.ui.model.OperationUi;
169 import org.openecomp.sdc.be.utils.TypeUtils;
170 import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
171 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
172 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
173 import org.openecomp.sdc.common.api.Constants;
174 import org.openecomp.sdc.common.datastructure.Wrapper;
175 import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
176 import org.openecomp.sdc.common.log.wrappers.Logger;
177 import org.openecomp.sdc.common.util.ValidationUtils;
178 import org.openecomp.sdc.common.zip.ZipUtils;
179 import org.openecomp.sdc.common.zip.exception.ZipException;
180 import org.openecomp.sdc.exception.ResponseFormat;
181 import org.springframework.beans.factory.annotation.Autowired;
182 import org.yaml.snakeyaml.Yaml;
186 @org.springframework.stereotype.Component("serviceImportBusinessLogic")
187 public class ServiceImportBusinessLogic {
189 protected static final String CREATE_RESOURCE = "Create Resource";
190 private static final String INITIAL_VERSION = "0.1";
191 private static final String IN_RESOURCE = " in resource {} ";
192 private static final String COMPONENT_INSTANCE_WITH_NAME = "component instance with name ";
193 private static final String COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE = "component instance with name {} in resource {} ";
194 private static final String CERTIFICATION_ON_IMPORT = "certification on import";
195 private static final String VALIDATE_DERIVED_BEFORE_UPDATE = "validate derived before update";
196 private static final String PLACE_HOLDER_RESOURCE_TYPES = "validForResourceTypes";
197 private static final String CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES = "Create Resource - validateCapabilityTypesCreate";
198 private static final String CATEGORY_IS_EMPTY = "Resource category is empty";
199 private static final Logger log = Logger.getLogger(ServiceImportBusinessLogic.class);
201 private final ComponentsUtils componentsUtils;
202 private final ToscaOperationFacade toscaOperationFacade;
203 private final ServiceBusinessLogic serviceBusinessLogic;
204 private final CsarBusinessLogic csarBusinessLogic;
205 private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic;
206 private final LifecycleBusinessLogic lifecycleBusinessLogic;
207 private final CompositionBusinessLogic compositionBusinessLogic;
208 private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic;
209 private final ServiceImportParseLogic serviceImportParseLogic;
210 private final GroupBusinessLogic groupBusinessLogic;
211 private final PolicyBusinessLogic policyBusinessLogic;
212 private final ResourceImportManager resourceImportManager;
213 private final JanusGraphDao janusGraphDao;
214 private final ArtifactsBusinessLogic artifactsBusinessLogic;
215 private final ArtifactTypeImportManager artifactTypeImportManager;
216 private final IGraphLockOperation graphLockOperation;
217 private final ToscaFunctionService toscaFunctionService;
218 private final DataTypeBusinessLogic dataTypeBusinessLogic;
219 private final ArtifactTypeOperation artifactTypeOperation;
220 private final GroupTypeImportManager groupTypeImportManager;
221 private final GroupTypeOperation groupTypeOperation;
222 private final CapabilityTypeImportManager capabilityTypeImportManager;
223 private final CapabilityTypeOperation capabilityTypeOperation;
224 private ApplicationDataTypeCache applicationDataTypeCache;
225 private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
226 private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
227 private final ModelOperation modelOperation;
229 public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic,
230 final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade,
231 final ServiceBusinessLogic serviceBusinessLogic, final CsarBusinessLogic csarBusinessLogic,
232 final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic,
233 final LifecycleBusinessLogic lifecycleBusinessLogic, final CompositionBusinessLogic compositionBusinessLogic,
234 final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic,
235 final ServiceImportParseLogic serviceImportParseLogic, final PolicyBusinessLogic policyBusinessLogic,
236 final ResourceImportManager resourceImportManager, final JanusGraphDao janusGraphDao,
237 final IGraphLockOperation graphLockOperation, final ToscaFunctionService toscaFunctionService,
238 final DataTypeBusinessLogic dataTypeBusinessLogic, final ArtifactTypeOperation artifactTypeOperation,
239 final ArtifactTypeImportManager artifactTypeImportManager, final GroupTypeImportManager groupTypeImportManager,
240 final GroupTypeOperation groupTypeOperation,
241 final InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
242 final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager,
243 final CapabilityTypeImportManager capabilityTypeImportManager,
244 final CapabilityTypeOperation capabilityTypeOperation,
245 final ModelOperation modelOperation) {
246 this.componentsUtils = componentsUtils;
247 this.toscaOperationFacade = toscaOperationFacade;
248 this.serviceBusinessLogic = serviceBusinessLogic;
249 this.csarBusinessLogic = csarBusinessLogic;
250 this.csarArtifactsAndGroupsBusinessLogic = csarArtifactsAndGroupsBusinessLogic;
251 this.lifecycleBusinessLogic = lifecycleBusinessLogic;
252 this.compositionBusinessLogic = compositionBusinessLogic;
253 this.resourceDataMergeBusinessLogic = resourceDataMergeBusinessLogic;
254 this.serviceImportParseLogic = serviceImportParseLogic;
255 this.groupBusinessLogic = groupBusinessLogic;
256 this.policyBusinessLogic = policyBusinessLogic;
257 this.resourceImportManager = resourceImportManager;
258 this.janusGraphDao = janusGraphDao;
259 this.artifactsBusinessLogic = artifactsBusinessLogic;
260 this.graphLockOperation = graphLockOperation;
261 this.toscaFunctionService = toscaFunctionService;
262 this.dataTypeBusinessLogic = dataTypeBusinessLogic;
263 this.artifactTypeOperation = artifactTypeOperation;
264 this.artifactTypeImportManager = artifactTypeImportManager;
265 this.groupTypeImportManager = groupTypeImportManager;
266 this.groupTypeOperation = groupTypeOperation;
267 this.interfaceLifecycleTypeOperation = interfaceLifecycleTypeOperation;
268 this.interfaceLifecycleTypeImportManager = interfaceLifecycleTypeImportManager;
269 this.capabilityTypeImportManager = capabilityTypeImportManager;
270 this.capabilityTypeOperation = capabilityTypeOperation;
271 this.modelOperation = modelOperation;
275 public void setApplicationDataTypeCache(ApplicationDataTypeCache applicationDataTypeCache) {
276 this.applicationDataTypeCache = applicationDataTypeCache;
279 public Service updateServiceFromToscaTemplate(final String serviceId, final User modifier, final String data) {
280 final Either<Service, ResponseFormat> serviceResponseFormatEither = serviceBusinessLogic.getService(serviceId, modifier);
281 if (serviceResponseFormatEither.isRight()) {
282 throw new ByActionStatusComponentException(ActionStatus.SERVICE_NOT_FOUND, serviceId);
284 final Service serviceOriginal = serviceResponseFormatEither.left().value();
285 final Map<String, String> metadata = (Map<String, String>) new Yaml().loadAs(data, Map.class).get("metadata");
286 validateServiceMetadataBeforeCreate(serviceOriginal, metadata);
288 final Service newService = cloneServiceIdentifications(serviceOriginal);
289 final Map<String, byte[]> payload = new HashMap<>();
290 payload.put("Definitions/service-" + metadata.get("name") + "-template.yml", data.getBytes());
291 updateServiceMetadata(newService, metadata);
292 return createService(newService, AuditingActionEnum.UPDATE_SERVICE_TOSCA_TEMPLATE, modifier, payload, null);
295 public Service updateServiceFromToscaModel(final String serviceId, final User modifier, final @NotNull InputStream fileToUpload) {
296 final Either<Service, ResponseFormat> serviceResponseFormatEither = serviceBusinessLogic.getService(serviceId, modifier);
297 if (serviceResponseFormatEither.isRight()) {
298 throw new ByActionStatusComponentException(ActionStatus.SERVICE_NOT_FOUND, serviceId);
300 final Service serviceOriginal = serviceResponseFormatEither.left().value();
301 Map<String, byte[]> csar = null;
303 csar = ZipUtils.readZip(fileToUpload.readAllBytes(), false);
304 } catch (final ZipException | IOException e) {
305 log.info("Failed to unzip received csar {}", serviceId, e);
308 throw new ByActionStatusComponentException(ActionStatus.CSAR_NOT_FOUND);
310 final byte[] mainYamlBytes = readMainYamlFile(csar);
311 final Map<String, String> metadata = (Map<String, String>) new Yaml().loadAs(new String(mainYamlBytes), Map.class).get("metadata");
312 validateServiceMetadataBeforeCreate(serviceOriginal, metadata);
313 final Service newService = cloneServiceIdentifications(serviceOriginal);
314 updateServiceMetadata(newService, metadata);
315 return createService(newService, AuditingActionEnum.UPDATE_SERVICE_TOSCA_MODEL, modifier, csar, null);
318 private byte[] readMainYamlFile(final Map<String, byte[]> csar) {
319 final Pattern pattern = Pattern.compile(TOSCA_METADATA_PATH_PATTERN);
320 final Optional<String> keyOp = csar.keySet().stream().filter(k -> pattern.matcher(k).matches()).findAny();
321 if (keyOp.isEmpty()) {
322 throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, TOSCA_METADATA_PATH_PATTERN, "");
324 final Properties props = new Properties();
326 final String propStr = new String(csar.get(keyOp.get()));
327 props.load(new StringReader(propStr.replace("\\", "\\\\")));
328 } catch (IOException e) {
329 throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, TOSCA_META_ENTRY_DEFINITIONS, "");
331 final String mainYamlFileName = props.getProperty(TOSCA_META_ENTRY_DEFINITIONS);
332 final byte[] mainYamlBytes = csar.get(mainYamlFileName);
333 if (mainYamlBytes == null) {
334 throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, mainYamlFileName, "");
336 return mainYamlBytes;
339 private Service cloneServiceIdentifications(final Service serviceOriginal) {
340 final Service newService = new Service(serviceOriginal.getComponentMetadataDefinition());
341 newService.setCategories(serviceOriginal.getCategories());
342 newService.setInvariantUUID(serviceOriginal.getInvariantUUID());
343 newService.setUniqueId(serviceOriginal.getUniqueId());
344 newService.setName(serviceOriginal.getName());
345 newService.setUUID(serviceOriginal.getUUID());
349 private void validateServiceMetadataBeforeCreate(final Service service, final Map<String, String> metadata) {
350 if (MapUtils.isEmpty(metadata)) {
351 throw new ByActionStatusComponentException(ActionStatus.MISSING_SERVICE_METADATA);
353 final String uuid = metadata.get("UUID");
354 if (!service.getUUID().equals(uuid)) {
355 throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "UUID");
357 final String invariantUUID = metadata.get("invariantUUID");
358 if (!service.getInvariantUUID().equals(invariantUUID)) {
359 throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "invariantUUID");
361 final String name = metadata.get("name");
362 if (!service.getName().equals(name)) {
363 throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "name");
365 final String version = metadata.get("template_version");
366 if (!service.getVersion().equals(version)) {
367 throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "template_version");
371 public Service createService(Service service, AuditingActionEnum auditingAction, User user, Map<String, byte[]> csarUIPayload,
372 String payloadName) {
373 log.debug("enter createService");
374 if (AuditingActionEnum.CREATE_SERVICE.equals(auditingAction)) {
375 service.setCreatorUserId(user.getUserId());
376 service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
377 service.setVersion(INITIAL_VERSION);
378 service.setConformanceLevel(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel());
379 service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
382 final var serviceBeforeCreate = serviceBusinessLogic.validateServiceBeforeCreate(service, user, auditingAction);
383 if (serviceBeforeCreate.isRight()) {
384 throw new ComponentException(ActionStatus.GENERAL_ERROR);
386 log.debug("enter createService,validateServiceBeforeCreate success");
387 String csarUUID = payloadName == null ? service.getCsarUUID() : payloadName;
388 if (AuditingActionEnum.CREATE_SERVICE.equals(auditingAction)) {
389 log.debug("enter createService,get csarUUID:{}", csarUUID);
390 csarBusinessLogic.validateCsarBeforeCreate(service, csarUUID);
392 log.debug("CsarUUID is {} - going to create resource from CSAR", csarUUID);
393 return createServiceFromCsar(service, user, csarUIPayload, csarUUID, auditingAction);
394 } catch (final ComponentException e) {
395 log.debug("Exception occurred when createService: {}", e.getMessage(), e);
397 } catch (final Exception e) {
398 log.debug("Exception occurred when createService: {}", e.getMessage(), e);
399 throw new ComponentException(ActionStatus.GENERAL_ERROR);
403 private void updateServiceMetadata(final Service service, final Map<String, String> metadata) {
404 metadata.entrySet().forEach(s -> {
405 final Optional<Method> find =
406 Arrays.stream(service.getClass().getMethods()).filter(method -> method.getName().equalsIgnoreCase("set" + s.getKey())).findAny();
407 if (find.isPresent()) {
409 find.get().invoke(service, s.getValue());
410 } catch (final Exception e) {
411 log.warn("Unable to set '{}' with value '{}'", s.getKey(), s.getValue());
417 protected Service createServiceFromCsar(Service service, User user, Map<String, byte[]> csarUIPayload, String csarUUID,
418 AuditingActionEnum auditingAction) {
419 log.trace("************* created successfully from YAML, resource TOSCA ");
421 final ServiceCsarInfo csarInfo;
422 if (AuditingActionEnum.UPDATE_SERVICE_TOSCA_TEMPLATE.equals(auditingAction)) {
423 csarInfo = new ServiceCsarInfo(user, csarUUID, csarUIPayload, service.getName(), service.getModel(),
424 csarUIPayload.keySet().iterator().next(), new String(csarUIPayload.values().iterator().next()), true, modelOperation);
426 csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID, auditingAction);
428 final String serviceModel = service.getModel();
429 final Map<String, Object> dataTypesToCreate = getDatatypesToCreate(serviceModel, csarInfo);
430 if (MapUtils.isNotEmpty(dataTypesToCreate)) {
431 dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), serviceModel, true);
432 dataTypesToCreate.keySet().forEach(key ->
433 applicationDataTypeCache.reload(serviceModel, UniqueIdBuilder.buildDataTypeUid(serviceModel, key))
437 final Map<String, Object> artifactTypesToCreate = getArtifactTypesToCreate(serviceModel, csarInfo);
438 if (MapUtils.isNotEmpty(artifactTypesToCreate)) {
439 artifactTypeImportManager.createArtifactTypes(new Yaml().dump(artifactTypesToCreate), serviceModel, true);
442 final List<NodeTypeDefinition> nodeTypesToCreate = getNodeTypesToCreate(serviceModel, csarInfo);
443 if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) {
444 ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic.getParsedToscaYamlInfo(csarInfo, service);
445 createNodeTypes(nodeTypesToCreate, parsedToscaYamlInfo.getInstances(), serviceModel, csarInfo.getModifier());
448 final Map<String, Object> groupTypesToCreate = getGroupTypesToCreate(serviceModel, csarInfo);
449 if (MapUtils.isNotEmpty(groupTypesToCreate)) {
450 final Map<String, ToscaTypeMetadata> toscaTypeMetadata = fillToscaTypeMetadata(groupTypesToCreate);
451 final ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(new Yaml().dump(groupTypesToCreate), toscaTypeMetadata);
452 groupTypeImportManager.createGroupTypes(toscaTypeImportData, serviceModel, true);
455 final Map<String, Object> interfaceTypesToCreate = getInterfaceTypesToCreate(serviceModel, csarInfo);
456 if (MapUtils.isNotEmpty(interfaceTypesToCreate)) {
457 interfaceLifecycleTypeImportManager.createLifecycleTypes(new Yaml().dump(interfaceTypesToCreate), serviceModel, true);
460 final Map<String, Object> capabilityTypesToCreate = getCapabilityTypesToCreate(serviceModel, csarInfo);
461 if (MapUtils.isNotEmpty(capabilityTypesToCreate)) {
462 capabilityTypeImportManager.createCapabilityTypes(new Yaml().dump(capabilityTypesToCreate), serviceModel, true);
465 Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
466 Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes
467 = serviceImportParseLogic.findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service);
468 if (findNodeTypesArtifactsToHandleRes.isRight()) {
469 log.debug("failed to find node types for update with artifacts during import csar {}. ", csarInfo.getCsarUUID());
470 throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value());
472 return createServiceFromYaml(service, csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(), nodeTypesInfo, csarInfo,
473 findNodeTypesArtifactsToHandleRes.left().value(), true, false, null, user.getUserId(), auditingAction);
474 } catch (final ComponentException e) {
475 log.debug("Exception occurred when createServiceFromCsar,error is:{}", e.getMessage(), e);
477 } catch (final Exception e) {
478 log.debug("Exception occurred when createServiceFromCsar,error is:{}", e.getMessage(), e);
479 throw new ComponentException(ActionStatus.GENERAL_ERROR);
483 private Map<String, ToscaTypeMetadata> fillToscaTypeMetadata(final Map<String, Object> groupTypesToCreate) {
484 final Map<String, ToscaTypeMetadata> toscaTypeMetadata = new HashMap<>();
485 groupTypesToCreate.entrySet().forEach(entry -> {
486 final ToscaTypeMetadata metadata = new ToscaTypeMetadata();
487 metadata.setIcon(getIconFromGroupType(entry.getValue()));
488 metadata.setDisplayName(extractDisplayName(entry.getKey()));
489 toscaTypeMetadata.put(entry.getKey(), metadata);
491 return toscaTypeMetadata;
494 private String extractDisplayName(final String key) {
495 final String[] split = key.split("\\.");
496 return split[split.length - 1];
499 private String getIconFromGroupType(final Object value) {
500 final Either<GroupTypeDefinition, StorageOperationStatus> groupType = groupTypeOperation.getLatestGroupTypeByType(
501 (String) ((LinkedHashMap) value).get(ToscaTagNamesEnum.DERIVED_FROM.getElementName()), null);
502 if (groupType.isLeft()) {
503 return groupType.left().value().getIcon();
508 private Map<String, Object> getGroupTypesToCreate(final String model, final CsarInfo csarInfo) {
509 final Map<String, Object> groupTypesToCreate = new HashMap<>();
510 final Map<String, Object> groupTypes = csarInfo.getGroupTypes();
511 if (MapUtils.isNotEmpty(groupTypes)) {
512 for (final Entry<String, Object> entry : groupTypes.entrySet()) {
513 final Either<GroupTypeDefinition, StorageOperationStatus> result
514 = groupTypeOperation.getGroupTypeByUid(UniqueIdBuilder.buildGroupTypeUid(model, entry.getKey(), "1.0"));
515 if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
516 groupTypesToCreate.put(entry.getKey(), entry.getValue());
517 log.info("Deploying new group type {} to model {} from package {}", entry.getKey(), model, csarInfo.getCsarUUID());
521 return groupTypesToCreate;
524 private Map<String, Object> getCapabilityTypesToCreate(final String model, final CsarInfo csarInfo) {
525 final Map<String, Object> capabilityTypesToCreate = new HashMap<>();
526 final Map<String, Object> capabilityTypes = csarInfo.getCapabilityTypes();
527 if (MapUtils.isNotEmpty(capabilityTypes)) {
528 for (final Entry<String, Object> entry : capabilityTypes.entrySet()) {
529 final Either<CapabilityTypeDefinition, StorageOperationStatus> result
530 = capabilityTypeOperation.getCapabilityType(UniqueIdBuilder.buildCapabilityTypeUid(model, entry.getKey()));
531 if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
532 capabilityTypesToCreate.put(entry.getKey(), entry.getValue());
533 log.info("Deploying new capability type {} to model {} from package {}", entry.getKey(), model, csarInfo.getCsarUUID());
537 return capabilityTypesToCreate;
540 private Map<String, Object> getDatatypesToCreate(final String model, final CsarInfo csarInfo) {
541 final Map<String, Object> dataTypesToCreate = new HashMap<>();
543 for (final Entry<String, Object> dataTypeEntry : csarInfo.getDataTypes().entrySet()) {
544 final Either<DataTypeDefinition, JanusGraphOperationStatus> result = applicationDataTypeCache.get(model,
545 UniqueIdBuilder.buildDataTypeUid(model, dataTypeEntry.getKey()));
546 if (result.isRight() && result.right().value().equals(JanusGraphOperationStatus.NOT_FOUND)) {
547 dataTypesToCreate.put(dataTypeEntry.getKey(), dataTypeEntry.getValue());
548 log.info("Deploying unknown type {} to model {} from package {}", dataTypeEntry.getKey(), model, csarInfo.getCsarUUID());
550 if (hasNewProperties(result, (Map<String, Map<String, Object>>) dataTypeEntry.getValue())) {
551 dataTypesToCreate.put(dataTypeEntry.getKey(), dataTypeEntry.getValue());
552 log.info("Deploying new version of type {} to model {} from package {}", dataTypeEntry.getKey(), model, csarInfo.getCsarUUID());
555 return dataTypesToCreate;
558 private Map<String, Object> getArtifactTypesToCreate(final String model, final CsarInfo csarInfo) {
559 final Map<String, Object> artifactTypesToCreate = new HashMap<>();
560 final Map<String, Object> artifactTypesMap = csarInfo.getArtifactTypes();
561 if (MapUtils.isNotEmpty(artifactTypesMap)) {
562 for (final Entry<String, Object> artifactTypeEntry : artifactTypesMap.entrySet()) {
563 final Either<ArtifactTypeDefinition, StorageOperationStatus> result =
564 artifactTypeOperation.getArtifactTypeByUid(UniqueIdBuilder.buildArtifactTypeUid(model, artifactTypeEntry.getKey()));
565 if (result.isRight() && StorageOperationStatus.NOT_FOUND.equals(result.right().value())) {
566 artifactTypesToCreate.put(artifactTypeEntry.getKey(), artifactTypeEntry.getValue());
567 log.info("Deploying new artifact type={}, to model={}, from package={}",
568 artifactTypeEntry.getKey(), model, csarInfo.getCsarUUID());
572 return artifactTypesToCreate;
575 private Map<String, Object> getInterfaceTypesToCreate(final String model, final CsarInfo csarInfo) {
576 final Map<String, Object> interfaceTypesToCreate = new HashMap<>();
577 Map<String, Object> interfacetypeMap = csarInfo.getInterfaceTypes();
579 interfacetypeMap.entrySet().forEach(interfacetypeDef -> {
580 Either<InterfaceDefinition, StorageOperationStatus> interfaceDefinition =
581 interfaceLifecycleTypeOperation.getInterface(UniqueIdBuilder.buildInterfaceTypeUid(model, interfacetypeDef.getKey()));
582 if (interfaceDefinition.isRight() && interfaceDefinition.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
583 interfaceTypesToCreate.put(interfacetypeDef.getKey(), interfacetypeDef.getValue());
586 return interfaceTypesToCreate;
589 private boolean hasNewProperties(final Either<DataTypeDefinition, JanusGraphOperationStatus> result,
590 final Map<String, Map<String, Object>> dataType) {
591 return result.isLeft() && dataType.containsKey("properties") && result.left().value().getProperties() != null
592 && result.left().value().getProperties().size() != dataType.get("properties").size();
595 private void createNodeTypes(List<NodeTypeDefinition> nodeTypesToCreate, Map<String, UploadComponentInstanceInfo> instancesFromCsar, String model,
597 NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList();
598 List<NodeTypeMetadata> nodeTypeMetadataList = new ArrayList<>();
599 final Map<String, Object> allTypesToCreate = new HashMap<>();
600 nodeTypesToCreate.forEach(nodeType -> {
601 allTypesToCreate.put(nodeType.getMappedNodeType().getKey(), nodeType.getMappedNodeType().getValue());
602 nodeTypeMetadataList.add(nodeType.getNodeTypeMetadata());
604 nodeTypesMetadataList.setNodeMetadataList(nodeTypeMetadataList);
605 resourceImportManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, instancesFromCsar, user, model, true, false);
608 private List<NodeTypeDefinition> getNodeTypesToCreate(final String model, final ServiceCsarInfo csarInfo) {
609 List<NodeTypeDefinition> namesOfNodeTypesToCreate = new ArrayList<>();
611 for (final NodeTypeDefinition nodeTypeDefinition : csarInfo.getNodeTypesUsed()) {
612 Either<Component, StorageOperationStatus> result = toscaOperationFacade
613 .getLatestByToscaResourceName(nodeTypeDefinition.getMappedNodeType().getKey(), model);
614 if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
615 namesOfNodeTypesToCreate.add(nodeTypeDefinition);
616 } else if (result.isLeft()) {
617 Resource latestResource = (Resource) result.left().value();
618 Entry<String, Object> existingMappedToscaTemplate = getResourceToscaTemplate(latestResource.getUniqueId(),
619 latestResource.getToscaArtifacts().get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE), csarInfo.getModifier().getUserId());
620 Map<String, Object> newMappedToscaTemplate = (Map<String, Object>) nodeTypeDefinition.getMappedNodeType().getValue();
621 Map<String, Object> combinedMappedToscaTemplate =
622 getNewChangesToToscaTemplate(newMappedToscaTemplate, (Map<String, Object>) existingMappedToscaTemplate.getValue());
623 if (!combinedMappedToscaTemplate.equals(existingMappedToscaTemplate.getValue())) {
624 if (latestResource.getComponentMetadataDefinition().getMetadataDataDefinition().isNormative()) {
625 nodeTypeDefinition.getNodeTypeMetadata().setNormative(true);
627 existingMappedToscaTemplate.setValue(combinedMappedToscaTemplate);
628 nodeTypeDefinition.setMappedNodeType(existingMappedToscaTemplate);
629 namesOfNodeTypesToCreate.add(nodeTypeDefinition);
633 return namesOfNodeTypesToCreate;
636 private Entry<String, Object> getResourceToscaTemplate(String uniqueId, ArtifactDefinition assetToscaTemplate, String userId) {
637 String assetToToscaTemplate = assetToscaTemplate.getUniqueId();
638 ImmutablePair<String, byte[]> toscaTemplate = artifactsBusinessLogic.
639 handleDownloadRequestById(uniqueId, assetToToscaTemplate, userId, ComponentTypeEnum.RESOURCE, null, null);
640 Map<String, Object> mappedToscaTemplate = new Yaml().load(new String(toscaTemplate.right));
641 Either<Map<String, Object>, ImportUtils.ResultStatusEnum> eitherNodeTypes =
642 findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES);
643 if (eitherNodeTypes.isRight()) {
644 throw new ComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE);
646 return eitherNodeTypes.left().value().entrySet().iterator().next();
649 private Map<String, Object> getNewChangesToToscaTemplate(Map<String, Object> newMappedToscaTemplate,
650 Map<String, Object> existingMappedToscaTemplate) {
651 Map<String, Object> combinedMappedToscaTemplate = new HashMap<>(existingMappedToscaTemplate);
652 combinePropertiesIntoToscaTemplate((Map<String, Object>) newMappedToscaTemplate.get("properties"),
653 (Map<String, Object>) existingMappedToscaTemplate.get("properties"), combinedMappedToscaTemplate);
654 combineAttributesIntoToscaTemplate((Map<String, Object>) newMappedToscaTemplate.get("attributes"),
655 (Map<String, Object>) existingMappedToscaTemplate.get("attributes"), combinedMappedToscaTemplate);
656 combineRequirementsIntoToscaTemplate((List<Map<String, Object>>) newMappedToscaTemplate.get("requirements"),
657 (List<Map<String, Object>>) existingMappedToscaTemplate.get("requirements"), combinedMappedToscaTemplate);
658 combineCapabilitiesIntoToscaTemplate((Map<String, Object>) newMappedToscaTemplate.get("capabilities"),
659 (Map<String, Object>) existingMappedToscaTemplate.get("capabilities"), combinedMappedToscaTemplate);
660 combineInterfacesIntoToscaTemplate((Map<String, Map<String, Object>>) newMappedToscaTemplate.get("interfaces"),
661 (Map<String, Map<String, Object>>) existingMappedToscaTemplate.get("interfaces"), combinedMappedToscaTemplate);
662 return combinedMappedToscaTemplate;
665 private void combineInterfacesIntoToscaTemplate(Map<String, Map<String, Object>> newInterfaces,
666 Map<String, Map<String, Object>> existingInterfaces,
667 Map<String, Object> combinedMappedToscaTemplate) {
668 Map<String, Map<String, Object>> combinedInterfaces = combineAdditionalInterfaces(newInterfaces, existingInterfaces);
669 if ((MapUtils.isEmpty(existingInterfaces) && MapUtils.isNotEmpty(combinedInterfaces))
670 || (MapUtils.isNotEmpty(existingInterfaces) && !existingInterfaces.equals(combinedInterfaces))) {
671 combinedMappedToscaTemplate.put("interfaces", combinedInterfaces);
675 private void combineCapabilitiesIntoToscaTemplate(Map<String, Object> newCapabilities, Map<String, Object> existingCapabilities,
676 Map<String, Object> combinedMappedToscaTemplate) {
677 Map<String, Object> combinedCapabilities = combineEntries(newCapabilities, existingCapabilities);
678 if ((MapUtils.isEmpty(existingCapabilities) && MapUtils.isNotEmpty(combinedCapabilities)) ||
679 (MapUtils.isNotEmpty(existingCapabilities) && !combinedCapabilities.equals(existingCapabilities))) {
680 combinedMappedToscaTemplate.put("capabilities", combinedCapabilities);
684 private void combineRequirementsIntoToscaTemplate(List<Map<String, Object>> newRequirements, List<Map<String, Object>> existingRequirements,
685 Map<String, Object> combinedMappedToscaTemplate) {
686 List<Map<String, Object>> combinedRequirements = combineAdditionalRequirements(newRequirements, existingRequirements);
687 if ((CollectionUtils.isEmpty(existingRequirements) && CollectionUtils.isNotEmpty(combinedRequirements))
688 || (CollectionUtils.isNotEmpty(existingRequirements) && !combinedRequirements.equals(existingRequirements))) {
689 combinedMappedToscaTemplate.put("requirements", combinedRequirements);
693 private void combineAttributesIntoToscaTemplate(Map<String, Object> newAttributes, Map<String, Object> existingAttributes,
694 Map<String, Object> combinedMappedToscaTemplate) {
695 Map<String, Object> combinedAttributes = combineEntries(newAttributes, existingAttributes);
696 if ((MapUtils.isEmpty(existingAttributes) && MapUtils.isNotEmpty(combinedAttributes)) ||
697 (MapUtils.isNotEmpty(existingAttributes) && !combinedAttributes.equals(existingAttributes))) {
698 combinedMappedToscaTemplate.put("attributes", combinedAttributes);
702 private void combinePropertiesIntoToscaTemplate(Map<String, Object> newProperties, Map<String, Object> existingProperties,
703 Map<String, Object> combinedMappedToscaTemplate) {
704 Map<String, Object> combinedProperties = combineEntries(newProperties, existingProperties);
705 if ((MapUtils.isEmpty(existingProperties) && MapUtils.isNotEmpty(combinedProperties)) ||
706 (MapUtils.isNotEmpty(existingProperties) && !combinedProperties.equals(existingProperties))) {
707 combinedMappedToscaTemplate.put("properties", combinedProperties);
711 private Map<String, Map<String, Object>> combineAdditionalInterfaces(Map<String, Map<String, Object>> newInterfaces,
712 Map<String, Map<String, Object>> existingInterfaces) {
713 if (MapUtils.isNotEmpty(newInterfaces) && MapUtils.isNotEmpty(existingInterfaces) && newInterfaces.equals(existingInterfaces)) {
714 return new HashMap<>(existingInterfaces);
716 if (MapUtils.isEmpty(newInterfaces)) {
717 newInterfaces = new HashMap<>();
719 Map<String, Map<String, Object>> combinedEntries = new HashMap<>(newInterfaces);
720 if (MapUtils.isEmpty(existingInterfaces)) {
721 return combinedEntries;
723 existingInterfaces.entrySet().forEach(interfaceDef -> {
724 combinedEntries.entrySet().stream().filter((interFace) -> interFace.getValue().get("type").equals((interfaceDef.getValue()).get("type")))
725 .findFirst().ifPresentOrElse((interFace) -> {
726 interFace.getValue().putAll(interfaceDef.getValue());
728 combinedEntries.put(interfaceDef.getKey(), interfaceDef.getValue());
731 return combinedEntries;
734 private List<Map<String, Object>> combineAdditionalRequirements(List<Map<String, Object>> newReqs,
735 List<Map<String, Object>> existingResourceReqs) {
736 if (CollectionUtils.isNotEmpty(newReqs) && CollectionUtils.isNotEmpty(existingResourceReqs) && newReqs.equals(existingResourceReqs)) {
737 return new ArrayList<>(existingResourceReqs);
739 if (CollectionUtils.isEmpty(existingResourceReqs)) {
740 existingResourceReqs = new ArrayList<>();
742 Set<Map<String, Object>> combinedReqs = new TreeSet<>((map1, map2) ->
743 map1.keySet().equals(map2.keySet()) ? 0 : map1.keySet().iterator().next().compareTo(map2.keySet().iterator().next()));
744 combinedReqs.addAll(existingResourceReqs);
745 if (CollectionUtils.isEmpty(newReqs)) {
746 return new ArrayList<>(combinedReqs);
748 combinedReqs.addAll(newReqs);
749 return new ArrayList<>(combinedReqs);
752 private Map<String, Object> combineEntries(Map<String, Object> newMap, Map<String, Object> existingMap) {
753 if (MapUtils.isNotEmpty(newMap) && MapUtils.isNotEmpty(existingMap) && newMap.equals(existingMap)) {
754 return new HashMap<>(existingMap);
756 if (MapUtils.isEmpty(newMap)) {
757 newMap = new HashMap<>();
759 Map<String, Object> combinedEntries = new HashMap<>(newMap);
760 if (MapUtils.isEmpty(existingMap)) {
761 return combinedEntries;
763 combinedEntries.putAll(existingMap);
764 return combinedEntries;
767 protected Service createServiceFromYaml(Service service, String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo,
769 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
770 boolean shouldLock, boolean inTransaction, String nodeName, final String userId,
771 AuditingActionEnum auditingAction)
772 throws BusinessLogicException {
773 List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
774 Service createdService;
775 CreateServiceFromYamlParameter csfyp = new CreateServiceFromYamlParameter();
777 ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic
778 .getParsedToscaYamlInfo(topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, nodeName, service);
779 log.debug("#createResourceFromYaml - Going to create resource {} and RIs ", service.getName());
780 csfyp.setYamlName(yamlName);
781 csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
782 csfyp.setCreatedArtifacts(createdArtifacts);
783 csfyp.setTopologyTemplateYaml(topologyTemplateYaml);
784 csfyp.setNodeTypesInfo(nodeTypesInfo);
785 csfyp.setCsarInfo(csarInfo);
786 csfyp.setNodeName(nodeName);
787 createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp, userId,
789 log.debug("#createResourceFromYaml - The resource {} has been created ", service.getName());
790 } catch (ComponentException | BusinessLogicException e) {
791 log.debug("Create Service from yaml failed", e);
793 } catch (StorageException e) {
794 log.debug("create Service From Yaml failed,get StorageException:{}", e);
797 return createdService;
800 protected Service createServiceAndRIsFromYaml(Service service, boolean isNormative,
801 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
802 boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp,
803 final String userId, AuditingActionEnum auditingAction)
804 throws BusinessLogicException {
806 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
807 String yamlName = csfyp.getYamlName();
808 ParsedToscaYamlInfo parsedToscaYamlInfo = csfyp.getParsedToscaYamlInfo();
809 List<ArtifactDefinition> createdArtifacts = csfyp.getCreatedArtifacts();
810 String topologyTemplateYaml = csfyp.getTopologyTemplateYaml();
811 Map<String, NodeTypeInfo> nodeTypesInfo = csfyp.getNodeTypesInfo();
812 CsarInfo csarInfo = csfyp.getCsarInfo();
813 String nodeName = csfyp.getNodeName();
815 Either<Boolean, ResponseFormat> lockResult = serviceBusinessLogic.lockComponentByName(service.getSystemName(), service, CREATE_RESOURCE);
816 if (lockResult.isRight()) {
817 throw new ComponentException(lockResult.right().value());
819 log.debug("name is locked {} status = {}", service.getSystemName(), lockResult);
821 boolean rollback = false;
823 log.trace("************* Adding properties to service from interface yaml {}", yamlName);
824 Map<String, PropertyDefinition> properties = parsedToscaYamlInfo.getProperties();
825 if (properties != null && !properties.isEmpty()) {
826 final List<PropertyDefinition> propertiesList = new ArrayList<>();
827 properties.forEach((propertyName, propertyDefinition) -> {
828 propertyDefinition.setName(propertyName);
829 propertiesList.add(propertyDefinition);
831 service.setProperties(propertiesList);
833 log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
834 service = serviceImportParseLogic.createServiceTransaction(service, csarInfo.getModifier(), isNormative, auditingAction);
835 log.trace("************* Going to add inputs from yaml {}", yamlName);
836 Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
837 service = serviceImportParseLogic.createInputsOnService(service, inputs);
838 log.trace("************* Finished to add inputs from yaml {}", yamlName);
839 ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties =
840 parsedToscaYamlInfo.getSubstitutionFilterProperties();
841 service = serviceImportParseLogic.createSubstitutionFilterOnService(service, substitutionFilterProperties);
842 log.trace("************* Added Substitution filter from interface yaml {}", yamlName);
843 Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances();
844 log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
845 service = createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap, topologyTemplateYaml,
846 nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName);
847 log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
848 log.trace("************* Going to add outputs from yaml {}", yamlName);
849 Map<String, OutputDefinition> outputs = parsedToscaYamlInfo.getOutputs();
850 service = serviceImportParseLogic.createOutputsOnService(service, outputs, userId);
851 log.trace("************* Finished to add outputs from yaml {}", yamlName);
853 Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes
854 = groupBusinessLogic.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), service.getSystemName());
855 if (validateUpdateVfGroupNamesRes.isRight()) {
856 throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
858 Map<String, GroupDefinition> groups;
859 log.trace("************* Going to add groups from yaml {}", yamlName);
860 if (!validateUpdateVfGroupNamesRes.left().value().isEmpty()) {
861 groups = validateUpdateVfGroupNamesRes.left().value();
863 groups = parsedToscaYamlInfo.getGroups();
865 Either<Service, ResponseFormat> createGroupsOnResource = createGroupsOnResource(service, groups);
866 if (createGroupsOnResource.isRight()) {
867 throw new ComponentException(createGroupsOnResource.right().value());
869 service = createGroupsOnResource.left().value();
871 Either<Service, ResponseFormat> createPoliciesOnResource = createPoliciesOnResource(service, parsedToscaYamlInfo.getPolicies());
872 if (createPoliciesOnResource.isRight()) {
873 throw new ComponentException(createPoliciesOnResource.right().value());
875 service = createPoliciesOnResource.left().value();
876 log.trace("************* Going to add artifacts from yaml {}", yamlName);
877 Either<Service, ResponseFormat> createArtifactsEither = createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,
878 createdArtifacts, yamlName, csarInfo, service, inTransaction, shouldLock);
879 if (createArtifactsEither.isRight()) {
880 throw new ComponentException(createArtifactsEither.right().value());
882 service = serviceImportParseLogic.getServiceWithGroups(createArtifactsEither.left().value().getUniqueId());
883 service = updateInputs(service, userId, parsedToscaYamlInfo.getSubstitutionMappingProperties());
885 ASDCKpiApi.countCreatedResourcesKPI();
887 } catch (Exception e) {
889 serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
892 if (!inTransaction) {
894 janusGraphDao.rollback();
896 janusGraphDao.commit();
900 graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Service);
905 private Service updateInputs(final Service component, final String userId, final Map<String, List<String>> substitutionMappingProperties) {
906 final List<InputDefinition> inputs = component.getInputs();
907 if (CollectionUtils.isNotEmpty(inputs)) {
908 final List<ComponentInstance> componentInstances = component.getComponentInstances();
909 final String componentUniqueId = component.getUniqueId();
910 List<String> propertyMissingNames = new ArrayList<>();
911 for (final InputDefinition input : inputs) {
912 boolean isSubMapProp = false;
913 if (substitutionMappingProperties != null && !substitutionMappingProperties.isEmpty()) {
914 isSubMapProp = substitutionMappingProperties.entrySet().stream()
915 .anyMatch(stringEntry -> stringEntry.getValue().get(0).equals(input.getName()));
917 if (!isSubMapProp && isInputFromComponentInstanceProperty(input.getName(), componentInstances)) {
918 associateInputToComponentInstanceProperty(userId, input, componentInstances, componentUniqueId);
920 String propertyName = associateInputToServiceProperty(userId, input, component, substitutionMappingProperties);
921 if (StringUtils.isNotBlank(propertyName)) {
922 propertyMissingNames.add(propertyName);
926 if (CollectionUtils.isNotEmpty(propertyMissingNames)) {
927 throw new ComponentException(
928 componentsUtils.getResponseFormat(ActionStatus.MISSING_PROPERTIES_ERROR, propertyMissingNames.toString()));
930 Either<List<InputDefinition>, StorageOperationStatus> either = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId);
931 if (either.isRight()) {
932 throw new ComponentException(ActionStatus.GENERAL_ERROR);
939 private boolean isInputFromComponentInstanceProperty(final String inputName, final List<ComponentInstance> componentInstances) {
941 if (CollectionUtils.isNotEmpty(componentInstances)) {
942 for (ComponentInstance instance : componentInstances) {
943 for (PropertyDefinition instanceProperty : instance.getProperties()) {
944 if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
945 for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
946 if (inputName.equals(getInputValueDataDefinition.getInputName())) {
957 private void associateInputToComponentInstanceProperty(final String userId, final InputDefinition input,
958 final List<ComponentInstance> componentInstances,
959 String componentUniqueId) {
961 String componentInstanceId = null;
962 ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
965 for (ComponentInstance instance : componentInstances) {
966 for (PropertyDefinition instanceProperty : instance.getProperties()) {
967 if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
968 for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
969 if (input.getName().equals(getInputValueDataDefinition.getInputName())) {
970 componentInstanceId = instance.getUniqueId();
971 componentInstanceProperty = new ComponentInstanceProperty(instanceProperty);
979 //unmapping instance property declared inputs from substitution mapping
980 input.setMappedToComponentProperty(false);
983 updateInput(input, componentInstanceProperty, userId, componentInstanceId);
985 final Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> either =
986 toscaOperationFacade.updateComponentInstancePropsToComponent(Collections.singletonMap(componentInstanceId,
987 Collections.singletonList(componentInstanceProperty)), componentUniqueId);
988 if (either.isRight()) {
989 throw new ComponentException(ActionStatus.GENERAL_ERROR);
993 private String associateInputToServiceProperty(final String userId,
994 final InputDefinition input, final Service component,
995 final Map<String, List<String>> substitutionMappingProperties) {
996 final List<PropertyDefinition> properties = component.getProperties();
997 if (CollectionUtils.isNotEmpty(properties) && MapUtils.isNotEmpty(substitutionMappingProperties)) {
998 AtomicReference<String> propertyNameFromInput = new AtomicReference<>(" ");
999 substitutionMappingProperties.entrySet().forEach(stringEntry -> {
1000 if (stringEntry.getValue().get(0).equals(input.getName())) {
1001 propertyNameFromInput.set(stringEntry.getKey());
1005 final Optional<PropertyDefinition> propDefOptional =
1006 properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput.get()))
1008 if (propDefOptional.isPresent()) {
1010 final String componentUniqueId = component.getUniqueId();
1011 final PropertyDefinition propertyDefinition = propDefOptional.get();
1012 updateProperty(propertyDefinition, input, componentUniqueId);
1013 final JSONObject jsonObject = new JSONObject();
1014 jsonObject.put(ToscaGetFunctionType.GET_INPUT.getFunctionName(), input.getName());
1015 propertyDefinition.setValue(jsonObject.toJSONString());
1016 updateInput(input, propertyDefinition, userId, componentUniqueId);
1018 final Either<PropertyDefinition, StorageOperationStatus> either
1019 = toscaOperationFacade.updatePropertyOfComponent(component, propertyDefinition);
1020 if (either.isRight()) {
1021 throw new ComponentException(ActionStatus.GENERAL_ERROR);
1024 input.setMappedToComponentProperty(false);
1025 return propertyNameFromInput.get();
1031 private void updateProperty(final PropertyDefinition propertyDefinition, final InputDefinition input, final String componentUniqueId) {
1032 propertyDefinition.setParentUniqueId(componentUniqueId);
1033 final GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
1034 getInputValueDataDefinition.setInputId(input.getUniqueId());
1035 getInputValueDataDefinition.setInputName(input.getName());
1036 getInputValueDataDefinition.setPropName(propertyDefinition.getName());
1037 propertyDefinition.setGetInputValues(Collections.singletonList(getInputValueDataDefinition));
1040 private void updateInput(final InputDefinition input, final PropertyDefinition propertyDefinition,
1041 final String userId, final String componentUniqueId) {
1042 input.setProperties(Collections.singletonList(new ComponentInstanceProperty(propertyDefinition)));
1043 input.setInstanceUniqueId(componentUniqueId);
1044 input.setOwnerId(userId);
1045 input.setPropertyId(propertyDefinition.getUniqueId());
1046 input.setParentPropertyType(propertyDefinition.getType());
1049 protected Either<Resource, ResponseFormat> createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum operation,
1050 List<ArtifactDefinition> createdArtifacts, String yamlFileName,
1051 CsarInfo csarInfo, Resource preparedResource,
1052 NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts,
1053 boolean inTransaction, boolean shouldLock) {
1054 String nodeName = nodeTypeInfoToUpdateArtifacts.getNodeName();
1055 Resource resource = preparedResource;
1056 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle =
1057 nodeTypeInfoToUpdateArtifacts
1058 .getNodeTypesArtifactsToHandle();
1059 if (preparedResource.getResourceType() == ResourceTypeEnum.VF) {
1060 if (nodeName != null && nodeTypesArtifactsToHandle.get(nodeName) != null && !nodeTypesArtifactsToHandle.get(nodeName).isEmpty()) {
1061 Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = handleNodeTypeArtifacts(preparedResource,
1062 nodeTypesArtifactsToHandle.get(nodeName), createdArtifacts, csarInfo.getModifier(), inTransaction, true);
1063 if (handleNodeTypeArtifactsRes.isRight()) {
1064 return Either.right(handleNodeTypeArtifactsRes.right().value());
1068 Either<Resource, ResponseFormat> createdCsarArtifactsEither = handleVfCsarArtifacts(preparedResource, csarInfo, createdArtifacts,
1069 new ArtifactOperationInfo(false, false, operation), shouldLock, inTransaction);
1070 log.trace("************* Finished to add artifacts from yaml {}", yamlFileName);
1071 if (createdCsarArtifactsEither.isRight()) {
1072 return createdCsarArtifactsEither;
1074 resource = createdCsarArtifactsEither.left().value();
1076 return Either.left(resource);
1079 protected Either<Resource, ResponseFormat> handleVfCsarArtifacts(Resource resource, CsarInfo csarInfo, List<ArtifactDefinition> createdArtifacts,
1080 ArtifactOperationInfo artifactOperation, boolean shouldLock,
1081 boolean inTransaction) {
1082 if (csarInfo.getCsar() != null) {
1083 createOrUpdateSingleNonMetaArtifactToComstants(resource, csarInfo, artifactOperation, shouldLock, inTransaction);
1084 Either<Resource, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock,
1085 inTransaction, artifactOperation);
1086 if (eitherCreateResult.isRight()) {
1087 return Either.right(eitherCreateResult.right().value());
1089 Either<Resource, StorageOperationStatus> eitherGerResource = toscaOperationFacade.getToscaElement(resource.getUniqueId());
1090 if (eitherGerResource.isRight()) {
1091 ResponseFormat responseFormat = componentsUtils
1092 .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
1093 return Either.right(responseFormat);
1095 resource = eitherGerResource.left().value();
1096 Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils
1097 .getArtifactsMeta(csarInfo.getCsar(), csarInfo.getCsarUUID(), componentsUtils);
1098 if (artifacsMetaCsarStatus.isLeft()) {
1099 return getResourceResponseFormatEither(resource, csarInfo, createdArtifacts, artifactOperation, shouldLock, inTransaction,
1100 artifacsMetaCsarStatus);
1102 return csarArtifactsAndGroupsBusinessLogic.deleteVFModules(resource, csarInfo, shouldLock, inTransaction);
1105 return Either.left(resource);
1108 protected void createOrUpdateSingleNonMetaArtifactToComstants(Resource resource, CsarInfo csarInfo, ArtifactOperationInfo artifactOperation,
1109 boolean shouldLock, boolean inTransaction) {
1110 String vendorLicenseModelId = null;
1111 String vfLicenseModelId = null;
1112 if (artifactOperation.getArtifactOperationEnum() == ArtifactOperationEnum.UPDATE) {
1113 Map<String, ArtifactDefinition> deploymentArtifactsMap = resource.getDeploymentArtifacts();
1114 if (deploymentArtifactsMap != null && !deploymentArtifactsMap.isEmpty()) {
1115 for (Map.Entry<String, ArtifactDefinition> artifactEntry : deploymentArtifactsMap.entrySet()) {
1116 if (artifactEntry.getValue().getArtifactName().equalsIgnoreCase(Constants.VENDOR_LICENSE_MODEL)) {
1117 vendorLicenseModelId = artifactEntry.getValue().getUniqueId();
1119 if (artifactEntry.getValue().getArtifactName().equalsIgnoreCase(Constants.VF_LICENSE_MODEL)) {
1120 vfLicenseModelId = artifactEntry.getValue().getUniqueId();
1125 createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VENDOR_LICENSE_MODEL,
1126 Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
1127 Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME, Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId,
1128 artifactOperation, null, true, shouldLock, inTransaction);
1129 createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL,
1130 ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VF_LICENSE_LABEL, Constants.VF_LICENSE_DISPLAY_NAME,
1131 Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, artifactOperation, null, true, shouldLock, inTransaction);
1134 private Either<Resource, ResponseFormat> getResourceResponseFormatEither(Resource resource, CsarInfo csarInfo,
1135 List<ArtifactDefinition> createdArtifacts,
1136 ArtifactOperationInfo artifactOperation, boolean shouldLock,
1137 boolean inTransaction,
1138 Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus) {
1140 String artifactsFileName = artifacsMetaCsarStatus.left().value().getKey();
1141 String artifactsContents = artifacsMetaCsarStatus.left().value().getValue();
1142 Either<Resource, ResponseFormat> createArtifactsFromCsar;
1143 if (ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum())) {
1144 createArtifactsFromCsar = csarArtifactsAndGroupsBusinessLogic
1145 .createResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts);
1147 Either<Component, ResponseFormat> result = csarArtifactsAndGroupsBusinessLogic
1148 .updateResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock,
1150 if ((result.left().value() instanceof Resource) && result.isLeft()) {
1151 Resource service1 = (Resource) result.left().value();
1152 createArtifactsFromCsar = Either.left(service1);
1154 createArtifactsFromCsar = Either.right(result.right().value());
1157 if (createArtifactsFromCsar.isRight()) {
1158 log.debug("Couldn't create artifacts from artifacts.meta");
1159 return Either.right(createArtifactsFromCsar.right().value());
1161 return Either.left(createArtifactsFromCsar.left().value());
1162 } catch (Exception e) {
1163 log.debug("Exception occured in getResourceResponseFormatEither, message:{}", e.getMessage(), e);
1164 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
1168 private <T extends Component> Either<T, ResponseFormat> createOrUpdateNonMetaArtifactsComp(CsarInfo csarInfo, T component,
1169 List<ArtifactDefinition> createdArtifacts,
1170 boolean shouldLock, boolean inTransaction,
1171 ArtifactOperationInfo artifactOperation) {
1172 Either<T, ResponseFormat> resStatus = null;
1173 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
1175 Either<List<CsarUtils.NonMetaArtifactInfo>, String> artifactPathAndNameList = getValidArtifactNames(csarInfo, collectedWarningMessages);
1176 if (artifactPathAndNameList.isRight()) {
1177 return Either.right(
1178 getComponentsUtils().getResponseFormatByArtifactId(ActionStatus.ARTIFACT_NAME_INVALID, artifactPathAndNameList.right().value()));
1180 EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>> vfCsarArtifactsToHandle = null;
1181 if (ArtifactsBusinessLogic.ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum())) {
1182 vfCsarArtifactsToHandle = new EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class);
1183 vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList.left().value());
1185 Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
1186 findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(
1187 component, artifactPathAndNameList.left().value(), csarInfo.getModifier());
1188 if (findVfCsarArtifactsToHandleRes.isRight()) {
1189 resStatus = Either.right(findVfCsarArtifactsToHandleRes.right().value());
1191 if (resStatus == null) {
1192 vfCsarArtifactsToHandle = findVfCsarArtifactsToHandleRes.left().value();
1195 if (resStatus == null && vfCsarArtifactsToHandle != null) {
1196 resStatus = processCsarArtifacts(csarInfo, component, createdArtifacts, shouldLock, inTransaction, resStatus,
1197 vfCsarArtifactsToHandle);
1199 if (resStatus == null) {
1200 resStatus = Either.left(component);
1202 } catch (Exception e) {
1203 resStatus = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
1204 log.debug("Exception occured in createNonMetaArtifacts, message:{}", e.getMessage(), e);
1206 CsarUtils.handleWarningMessages(collectedWarningMessages);
1211 protected Either<Resource, ResponseFormat> createOrUpdateNonMetaArtifacts(CsarInfo csarInfo, Resource resource,
1212 List<ArtifactDefinition> createdArtifacts, boolean shouldLock,
1213 boolean inTransaction, ArtifactOperationInfo artifactOperation) {
1214 return createOrUpdateNonMetaArtifactsComp(csarInfo, resource, createdArtifacts, shouldLock, inTransaction, artifactOperation);
1217 protected <T extends Component> Either<T, ResponseFormat> processCsarArtifacts(CsarInfo csarInfo, Component comp,
1218 List<ArtifactDefinition> createdArtifacts, boolean shouldLock,
1219 boolean inTransaction, Either<T, ResponseFormat> resStatus,
1220 EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>> vfCsarArtifactsToHandle) {
1221 for (Map.Entry<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>> currArtifactOperationPair : vfCsarArtifactsToHandle
1223 Optional<ResponseFormat> optionalCreateInDBError = currArtifactOperationPair.getValue().stream().map(
1224 e -> createOrUpdateSingleNonMetaArtifact(comp, csarInfo, e.getPath(), e.getArtifactName(), e.getArtifactType(),
1225 e.getArtifactGroupType(), e.getArtifactLabel(), e.getDisplayName(), CsarUtils.ARTIFACT_CREATED_FROM_CSAR, e.getArtifactUniqueId(),
1226 new ArtifactOperationInfo(false, false, currArtifactOperationPair.getKey()), createdArtifacts, e.isFromCsar(), shouldLock,
1227 inTransaction)).filter(Either::isRight).map(e -> e.right().value()).findAny();
1228 if (optionalCreateInDBError.isPresent()) {
1229 resStatus = Either.right(optionalCreateInDBError.get());
1236 protected Either<Boolean, ResponseFormat> createOrUpdateSingleNonMetaArtifact(Component component, CsarInfo csarInfo, String artifactPath,
1237 String artifactFileName, String artifactType,
1238 ArtifactGroupTypeEnum artifactGroupType, String artifactLabel,
1239 String artifactDisplayName, String artifactDescription,
1240 String artifactId, ArtifactOperationInfo operation,
1241 List<ArtifactDefinition> createdArtifacts, boolean isFromCsar,
1242 boolean shouldLock, boolean inTransaction) {
1243 byte[] artifactFileBytes = null;
1244 if (csarInfo.getCsar().containsKey(artifactPath)) {
1245 artifactFileBytes = csarInfo.getCsar().get(artifactPath);
1247 Either<Boolean, ResponseFormat> result = Either.left(true);
1248 if (operation.getArtifactOperationEnum() == ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE
1249 || operation.getArtifactOperationEnum() == ArtifactsBusinessLogic.ArtifactOperationEnum.DELETE) {
1250 if (serviceImportParseLogic.isArtifactDeletionRequired(artifactId, artifactFileBytes, isFromCsar)) {
1251 Either<ArtifactDefinition, ResponseFormat> handleDelete = artifactsBusinessLogic
1252 .handleDelete(component.getUniqueId(), artifactId, csarInfo.getModifier(), component, shouldLock, inTransaction);
1253 if (handleDelete.isRight()) {
1254 result = Either.right(handleDelete.right().value());
1258 if (org.apache.commons.lang.StringUtils.isEmpty(artifactId) && artifactFileBytes != null) {
1259 operation = new ArtifactOperationInfo(false, false, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE);
1262 if (artifactFileBytes != null) {
1263 Map<String, Object> vendorLicenseModelJson = ArtifactUtils
1264 .buildJsonForUpdateArtifact(artifactId, artifactFileName, artifactType, artifactGroupType, artifactLabel, artifactDisplayName,
1265 artifactDescription, artifactFileBytes, null, isFromCsar);
1266 Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherNonMetaArtifacts = csarArtifactsAndGroupsBusinessLogic
1267 .createOrUpdateCsarArtifactFromJson(component, csarInfo.getModifier(), vendorLicenseModelJson, operation);
1268 serviceImportParseLogic.addNonMetaCreatedArtifactsToSupportRollback(operation, createdArtifacts, eitherNonMetaArtifacts);
1269 if (eitherNonMetaArtifacts.isRight()) {
1270 BeEcompErrorManager.getInstance().logInternalFlowError("UploadLicenseArtifact",
1271 "Failed to upload license artifact: " + artifactFileName + "With csar uuid: " + csarInfo.getCsarUUID(),
1272 BeEcompErrorManager.ErrorSeverity.WARNING);
1273 return Either.right(eitherNonMetaArtifacts.right().value());
1279 private Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource,
1280 Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
1281 List<ArtifactDefinition> createdArtifacts, User user,
1282 boolean inTransaction, boolean ignoreLifecycleState) {
1283 List<ArtifactDefinition> handleNodeTypeArtifactsRequestRes;
1284 Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = null;
1285 Either<Resource, ResponseFormat> changeStateResponse;
1287 changeStateResponse = checkoutResource(nodeTypeResource, user, inTransaction);
1288 if (changeStateResponse.isRight()) {
1289 return Either.right(changeStateResponse.right().value());
1291 nodeTypeResource = changeStateResponse.left().value();
1292 List<ArtifactDefinition> handledNodeTypeArtifacts = new ArrayList<>();
1293 log.debug("************* Going to handle artifacts of node type resource {}. ", nodeTypeResource.getName());
1294 for (Map.Entry<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> curOperationEntry : nodeTypeArtifactsToHandle
1296 ArtifactsBusinessLogic.ArtifactOperationEnum curOperation = curOperationEntry.getKey();
1297 List<ArtifactDefinition> curArtifactsToHandle = curOperationEntry.getValue();
1298 if (curArtifactsToHandle != null && !curArtifactsToHandle.isEmpty()) {
1299 log.debug("************* Going to {} artifact to vfc {}", curOperation.name(), nodeTypeResource.getName());
1300 handleNodeTypeArtifactsRequestRes = artifactsBusinessLogic
1301 .handleArtifactsRequestForInnerVfcComponent(curArtifactsToHandle, nodeTypeResource, user, createdArtifacts,
1302 new ArtifactOperationInfo(false, ignoreLifecycleState, curOperation), false, inTransaction);
1303 if (ArtifactsBusinessLogic.ArtifactOperationEnum.isCreateOrLink(curOperation)) {
1304 createdArtifacts.addAll(handleNodeTypeArtifactsRequestRes);
1306 handledNodeTypeArtifacts.addAll(handleNodeTypeArtifactsRequestRes);
1309 handleNodeTypeArtifactsRes = Either.left(handledNodeTypeArtifacts);
1310 } catch (Exception e) {
1311 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
1312 handleNodeTypeArtifactsRes = Either.right(responseFormat);
1313 log.debug("Exception occured when handleVfcArtifacts, error is:{}", e.getMessage(), e);
1315 return handleNodeTypeArtifactsRes;
1318 private Either<Resource, ResponseFormat> checkoutResource(Resource resource, User user, boolean inTransaction) {
1319 Either<Resource, ResponseFormat> checkoutResourceRes;
1321 if (!resource.getComponentMetadataDefinition().getMetadataDataDefinition().getState()
1322 .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
1323 Either<? extends Component, ResponseFormat> checkoutRes = lifecycleBusinessLogic
1324 .changeComponentState(resource.getComponentType(), resource.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT,
1325 new LifecycleChangeInfoWithAction(CERTIFICATION_ON_IMPORT,
1326 LifecycleChangeInfoWithAction.LifecycleChanceActionEnum.CREATE_FROM_CSAR), inTransaction, true);
1327 if (checkoutRes.isRight()) {
1328 checkoutResourceRes = Either.right(checkoutRes.right().value());
1330 checkoutResourceRes = Either.left((Resource) checkoutRes.left().value());
1333 checkoutResourceRes = Either.left(resource);
1335 } catch (Exception e) {
1336 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
1337 checkoutResourceRes = Either.right(responseFormat);
1338 log.debug("Exception occured when checkoutResource {} , error is:{}", resource.getName(), e.getMessage(), e);
1340 return checkoutResourceRes;
1343 protected Either<Service, ResponseFormat> createOrUpdateArtifacts(ArtifactOperationEnum operation, List<ArtifactDefinition> createdArtifacts,
1344 String yamlFileName, CsarInfo csarInfo, Service preparedService,
1345 boolean inTransaction, boolean shouldLock) {
1346 Either<Service, ResponseFormat> createdCsarArtifactsEither = handleVfCsarArtifacts(preparedService, csarInfo, createdArtifacts,
1347 new ArtifactOperationInfo(false, false, operation), shouldLock, inTransaction);
1348 log.trace("************* Finished to add artifacts from yaml {}", yamlFileName);
1349 if (createdCsarArtifactsEither.isRight()) {
1350 return createdCsarArtifactsEither;
1352 return Either.left(createdCsarArtifactsEither.left().value());
1355 protected Either<Service, ResponseFormat> handleVfCsarArtifacts(Service service, CsarInfo csarInfo, List<ArtifactDefinition> createdArtifacts,
1356 ArtifactOperationInfo artifactOperation, boolean shouldLock,
1357 boolean inTransaction) {
1358 if (csarInfo.getCsar() != null) {
1359 String vendorLicenseModelId = null;
1360 String vfLicenseModelId = null;
1361 if (artifactOperation.getArtifactOperationEnum() == ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE) {
1362 Map<String, ArtifactDefinition> deploymentArtifactsMap = service.getDeploymentArtifacts();
1363 if (deploymentArtifactsMap != null && !deploymentArtifactsMap.isEmpty()) {
1364 for (Map.Entry<String, ArtifactDefinition> artifactEntry : deploymentArtifactsMap.entrySet()) {
1365 if (artifactEntry.getValue().getArtifactName().equalsIgnoreCase(Constants.VENDOR_LICENSE_MODEL)) {
1366 vendorLicenseModelId = artifactEntry.getValue().getUniqueId();
1368 if (artifactEntry.getValue().getArtifactName().equalsIgnoreCase(Constants.VF_LICENSE_MODEL)) {
1369 vfLicenseModelId = artifactEntry.getValue().getUniqueId();
1374 createOrUpdateSingleNonMetaArtifact(service, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VENDOR_LICENSE_MODEL,
1375 Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
1376 Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME, Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId,
1377 artifactOperation, null, true, shouldLock, inTransaction);
1378 createOrUpdateSingleNonMetaArtifact(service, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL,
1379 ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VF_LICENSE_LABEL,
1380 Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, artifactOperation, null, true, shouldLock,
1382 Either<Service, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, service, createdArtifacts, shouldLock,
1383 inTransaction, artifactOperation);
1384 if (eitherCreateResult.isRight()) {
1385 return Either.right(eitherCreateResult.right().value());
1387 Either<Service, StorageOperationStatus> eitherGerResource = toscaOperationFacade.getToscaElement(service.getUniqueId());
1388 if (eitherGerResource.isRight()) {
1389 ResponseFormat responseFormat = componentsUtils
1390 .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), service,
1391 ComponentTypeEnum.SERVICE);
1392 return Either.right(responseFormat);
1394 service = eitherGerResource.left().value();
1395 Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils
1396 .getArtifactsMeta(csarInfo.getCsar(), csarInfo.getCsarUUID(), componentsUtils);
1397 if (artifacsMetaCsarStatus.isLeft()) {
1398 String artifactsFileName = artifacsMetaCsarStatus.left().value().getKey();
1399 String artifactsContents = artifacsMetaCsarStatus.left().value().getValue();
1400 Either<Service, ResponseFormat> createArtifactsFromCsar;
1401 if (ArtifactsBusinessLogic.ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum())) {
1402 createArtifactsFromCsar = csarArtifactsAndGroupsBusinessLogic
1403 .createResourceArtifactsFromCsar(csarInfo, service, artifactsContents, artifactsFileName, createdArtifacts);
1405 Either<Component, ResponseFormat> result = csarArtifactsAndGroupsBusinessLogic
1406 .updateResourceArtifactsFromCsar(csarInfo, service, artifactsContents, artifactsFileName, createdArtifacts, shouldLock,
1408 if ((result.left().value() instanceof Service) && result.isLeft()) {
1409 Service service1 = (Service) result.left().value();
1410 createArtifactsFromCsar = Either.left(service1);
1412 createArtifactsFromCsar = Either.right(result.right().value());
1415 if (createArtifactsFromCsar.isRight()) {
1416 log.debug("Couldn't create artifacts from artifacts.meta");
1417 return Either.right(createArtifactsFromCsar.right().value());
1419 return Either.left(createArtifactsFromCsar.left().value());
1421 return csarArtifactsAndGroupsBusinessLogic.deleteVFModules(service, csarInfo, shouldLock, inTransaction);
1424 return Either.left(service);
1427 protected Either<Service, ResponseFormat> createOrUpdateNonMetaArtifacts(CsarInfo csarInfo, Service resource,
1428 List<ArtifactDefinition> createdArtifacts, boolean shouldLock,
1429 boolean inTransaction, ArtifactOperationInfo artifactOperation) {
1430 return createOrUpdateNonMetaArtifactsComp(csarInfo, resource, createdArtifacts, shouldLock, inTransaction, artifactOperation);
1433 protected Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandle(
1434 Component component, List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList, User user) {
1435 List<ArtifactDefinition> existingArtifacts = new ArrayList<>();
1436 if (component.getDeploymentArtifacts() != null && !component.getDeploymentArtifacts().isEmpty()) {
1437 existingArtifacts.addAll(component.getDeploymentArtifacts().values());
1439 if (component.getArtifacts() != null && !component.getArtifacts().isEmpty()) {
1440 existingArtifacts.addAll(component.getArtifacts().values());
1442 existingArtifacts = existingArtifacts.stream().filter(this::isNonMetaArtifact).collect(toList());
1443 List<String> artifactsToIgnore = new ArrayList<>();
1444 if (component.getGroups() != null) {
1445 component.getGroups().forEach(g -> {
1446 if (g.getArtifacts() != null && !g.getArtifacts().isEmpty()) {
1447 artifactsToIgnore.addAll(g.getArtifacts());
1451 existingArtifacts = existingArtifacts.stream().filter(a -> !artifactsToIgnore.contains(a.getUniqueId())).collect(toList());
1452 return organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifacts, component, user);
1455 private boolean isNonMetaArtifact(ArtifactDefinition artifact) {
1456 boolean result = true;
1457 if (artifact.getMandatory() || artifact.getArtifactName() == null || !isValidArtifactType(artifact)) {
1463 private boolean isValidArtifactType(ArtifactDefinition artifact) {
1464 final String artifactType = artifact.getArtifactType();
1465 return artifactType != null
1466 && !ArtifactTypeEnum.VENDOR_LICENSE.getType().equals(ArtifactTypeEnum.findType(artifactType))
1467 && !ArtifactTypeEnum.VF_LICENSE.getType().equals(ArtifactTypeEnum.findType(artifactType));
1470 protected Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat> organizeVfCsarArtifactsByArtifactOperation(
1471 List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList, List<ArtifactDefinition> existingArtifactsToHandle, Component component,
1473 EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>> nodeTypeArtifactsToHandle = new EnumMap<>(
1474 ArtifactsBusinessLogic.ArtifactOperationEnum.class);
1475 Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
1476 Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
1477 nodeTypeArtifactsToHandleRes = Either
1478 .left(nodeTypeArtifactsToHandle);
1480 List<CsarUtils.NonMetaArtifactInfo> artifactsToUpload = new ArrayList<>(artifactPathAndNameList);
1481 List<CsarUtils.NonMetaArtifactInfo> artifactsToUpdate = new ArrayList<>();
1482 List<CsarUtils.NonMetaArtifactInfo> artifactsToDelete = new ArrayList<>();
1483 for (CsarUtils.NonMetaArtifactInfo currNewArtifact : artifactPathAndNameList) {
1484 ArtifactDefinition foundArtifact;
1485 if (!existingArtifactsToHandle.isEmpty()) {
1486 foundArtifact = existingArtifactsToHandle.stream().filter(a -> a.getArtifactName().equals(currNewArtifact.getArtifactName()))
1487 .findFirst().orElse(null);
1488 if (foundArtifact != null) {
1489 if (ArtifactTypeEnum.findType(foundArtifact.getArtifactType()).equals(currNewArtifact.getArtifactType())) {
1490 if (!foundArtifact.getArtifactChecksum().equals(currNewArtifact.getArtifactChecksum())) {
1491 currNewArtifact.setArtifactUniqueId(foundArtifact.getUniqueId());
1492 artifactsToUpdate.add(currNewArtifact);
1494 existingArtifactsToHandle.remove(foundArtifact);
1495 artifactsToUpload.remove(currNewArtifact);
1497 log.debug("Can't upload two artifact with the same name {}.", currNewArtifact.getArtifactName());
1498 ResponseFormat responseFormat = ResponseFormatManager.getInstance()
1499 .getResponseFormat(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, currNewArtifact.getArtifactName(),
1500 currNewArtifact.getArtifactType(), foundArtifact.getArtifactType());
1501 AuditingActionEnum auditingAction = artifactsBusinessLogic.detectAuditingType(
1502 new ArtifactOperationInfo(false, false, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE),
1503 foundArtifact.getArtifactChecksum());
1504 artifactsBusinessLogic.handleAuditing(auditingAction, component, component.getUniqueId(), user, null, null,
1505 foundArtifact.getUniqueId(), responseFormat, component.getComponentType(), null);
1506 responseWrapper.setInnerElement(responseFormat);
1512 if (responseWrapper.isEmpty()) {
1513 for (ArtifactDefinition currArtifact : existingArtifactsToHandle) {
1514 if (currArtifact.getIsFromCsar()) {
1515 artifactsToDelete.add(new CsarUtils.NonMetaArtifactInfo(currArtifact.getArtifactName(), null,
1516 ArtifactTypeEnum.findType(currArtifact.getArtifactType()), currArtifact.getArtifactGroupType(), null,
1517 currArtifact.getUniqueId(), currArtifact.getIsFromCsar()));
1519 artifactsToUpdate.add(new CsarUtils.NonMetaArtifactInfo(currArtifact.getArtifactName(), null,
1520 ArtifactTypeEnum.findType(currArtifact.getArtifactType()), currArtifact.getArtifactGroupType(), null,
1521 currArtifact.getUniqueId(), currArtifact.getIsFromCsar()));
1525 if (responseWrapper.isEmpty()) {
1526 if (!artifactsToUpload.isEmpty()) {
1527 nodeTypeArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactsToUpload);
1529 if (!artifactsToUpdate.isEmpty()) {
1530 nodeTypeArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE, artifactsToUpdate);
1532 if (!artifactsToDelete.isEmpty()) {
1533 nodeTypeArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.DELETE, artifactsToDelete);
1536 if (!responseWrapper.isEmpty()) {
1537 nodeTypeArtifactsToHandleRes = Either.right(responseWrapper.getInnerElement());
1539 } catch (Exception e) {
1540 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
1541 responseWrapper.setInnerElement(responseFormat);
1542 log.debug("Exception occured when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage(), e);
1543 nodeTypeArtifactsToHandleRes = Either.right(responseWrapper.getInnerElement());
1545 return nodeTypeArtifactsToHandleRes;
1548 protected Either<List<CsarUtils.NonMetaArtifactInfo>, String> getValidArtifactNames(CsarInfo csarInfo,
1549 Map<String, Set<List<String>>> collectedWarningMessages) {
1550 List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = csarInfo.getCsar().entrySet().stream()
1551 .filter(e -> Pattern.compile(VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN).matcher(e.getKey()).matches())
1552 .map(e -> CsarUtils.validateNonMetaArtifact(e.getKey(), e.getValue(), collectedWarningMessages)).filter(Either::isLeft)
1553 .map(e -> e.left().value()).collect(toList());
1554 Pattern englishNumbersAndUnderScoresOnly = Pattern.compile(CsarUtils.VALID_ENGLISH_ARTIFACT_NAME);
1555 for (CsarUtils.NonMetaArtifactInfo nonMetaArtifactInfo : artifactPathAndNameList) {
1556 if (!englishNumbersAndUnderScoresOnly.matcher(nonMetaArtifactInfo.getDisplayName()).matches()) {
1557 return Either.right(nonMetaArtifactInfo.getArtifactName());
1560 return Either.left(artifactPathAndNameList);
1563 protected Either<Service, ResponseFormat> createGroupsOnResource(Service service, Map<String, GroupDefinition> groups) {
1564 if (groups != null && !groups.isEmpty()) {
1565 List<GroupDefinition> groupsAsList = updateGroupsMembersUsingResource(groups, service);
1566 serviceImportParseLogic.handleGroupsProperties(service, groups);
1567 serviceImportParseLogic.fillGroupsFinalFields(groupsAsList);
1568 Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.createGroups(service, groupsAsList, true);
1569 if (createGroups.isRight()) {
1570 return Either.right(createGroups.right().value());
1573 return Either.left(service);
1575 return getServiceResponseFormatEither(service);
1578 private Either<Service, ResponseFormat> createPoliciesOnResource(final Service service,
1579 final Map<String, PolicyDefinition> policies) {
1580 if (MapUtils.isEmpty(policies)) {
1581 return Either.left(service);
1583 Map<String, List<ComponentInstanceAttribute>> componentInstancesAttributes = service.getComponentInstancesAttributes();
1584 final Map<String, List<AttributeDefinition>> instanceAttributeMap = new HashMap<>();
1585 if (MapUtils.isNotEmpty(componentInstancesAttributes)) {
1586 instanceAttributeMap.putAll(componentInstancesAttributes
1587 .entrySet().stream()
1588 .collect(toMap(Entry::getKey, entry -> entry.getValue().stream().map(AttributeDefinition.class::cast).collect(toList()))));
1590 policies.values().stream()
1591 .map(PolicyDataDefinition::getProperties)
1592 .flatMap(Collection::stream)
1593 .filter(PropertyDataDefinition::isToscaFunction)
1594 .forEach(policyDefinition -> toscaFunctionService
1595 .updateFunctionWithDataFromSelfComponent(policyDefinition.getToscaFunction(), service, service.getComponentInstancesProperties(),
1596 instanceAttributeMap)
1598 policyBusinessLogic.createPolicies(service, policies);
1599 return getServiceResponseFormatEither(service);
1602 private Either<Service, ResponseFormat> getServiceResponseFormatEither(Service service) {
1603 Either<Service, StorageOperationStatus> updatedResource = toscaOperationFacade.getToscaElement(service.getUniqueId());
1604 if (updatedResource.isRight()) {
1605 ResponseFormat responseFormat = componentsUtils
1606 .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), service,
1607 ComponentTypeEnum.SERVICE);
1608 return Either.right(responseFormat);
1610 return Either.left(updatedResource.left().value());
1613 protected List<GroupDefinition> updateGroupsMembersUsingResource(Map<String, GroupDefinition> groups, Service component) {
1614 List<GroupDefinition> result = new ArrayList<>();
1615 List<ComponentInstance> componentInstances = component.getComponentInstances();
1616 if (groups != null) {
1617 for (Map.Entry<String, GroupDefinition> entry : groups.entrySet()) {
1618 String groupName = entry.getKey();
1619 GroupDefinition groupDefinition = entry.getValue();
1620 GroupDefinition updatedGroupDefinition = new GroupDefinition(groupDefinition);
1621 updatedGroupDefinition.setMembers(null);
1622 Map<String, String> members = groupDefinition.getMembers();
1623 if (members != null) {
1624 serviceImportParseLogic.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
1626 result.add(updatedGroupDefinition);
1632 protected Resource createRIAndRelationsFromYaml(String yamlName, Resource resource,
1633 Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap,
1634 String topologyTemplateYaml, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
1635 Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
1636 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
1639 log.debug("************* Going to create all nodes {}", yamlName);
1640 handleNodeTypes(yamlName, resource, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
1641 csarInfo, nodeName);
1642 log.debug("************* Going to create all resource instances {}", yamlName);
1643 resource = createResourceInstances(yamlName, resource, uploadComponentInstanceInfoMap, csarInfo.getCreatedNodes());
1644 log.debug("************* Finished to create all resource instances {}", yamlName);
1645 resource = createResourceInstancesRelations(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap);
1646 log.debug("************* Going to create positions {}", yamlName);
1647 compositionBusinessLogic.setPositionsForComponentInstances(resource, csarInfo.getModifier().getUserId());
1648 log.debug("************* Finished to set positions {}", yamlName);
1650 } catch (Exception e) {
1651 throw new ComponentException(ActionStatus.GENERAL_ERROR);
1655 protected Resource createResourceInstancesRelations(User user, String yamlName, Resource resource,
1656 Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
1657 log.debug("#createResourceInstancesRelations - Going to create relations ");
1658 List<ComponentInstance> componentInstancesList = resource.getComponentInstances();
1659 if (((MapUtils.isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)) &&
1660 resource.getResourceType() != ResourceTypeEnum.PNF)) { // PNF can have no resource instances
1661 log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ",
1662 resource.getUniqueId(), yamlName);
1663 BeEcompErrorManager.getInstance()
1664 .logInternalDataError("createResourceInstancesRelations", "No instances found in a resource or nn yaml template. ",
1665 BeEcompErrorManager.ErrorSeverity.ERROR);
1666 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName));
1668 Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>();
1669 Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>();
1670 Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>();
1671 Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>();
1672 Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>();
1673 Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>();
1674 Map<String, Resource> originCompMap = new HashMap<>();
1675 List<RequirementCapabilityRelDef> relations = new ArrayList<>();
1676 Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
1677 Map<String, UploadNodeFilterInfo> instNodeFilter = new HashMap<>();
1678 Map<String, Map<String, InterfaceDefinition>> instInterfaces = new HashMap<>();
1679 log.debug("enter ServiceImportBusinessLogic createResourceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. ");
1680 final ApplicationDataTypeCache applicationDataTypeCache = serviceBusinessLogic.applicationDataTypeCache;
1681 if (applicationDataTypeCache != null) {
1682 Resource finalResource = resource;
1683 uploadResInstancesMap.values().forEach(
1684 i -> processComponentInstance(yamlName, finalResource, componentInstancesList,
1685 componentsUtils.getAllDataTypes(applicationDataTypeCache, finalResource.getModel()), instProperties, instCapabilities,
1686 instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter,
1687 instInterfaces, i));
1689 serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties);
1690 serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, resource, instInputs);
1691 serviceImportParseLogic.associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts);
1692 serviceImportParseLogic.associateArtifactsToInstances(yamlName, resource, instArtifacts);
1693 serviceImportParseLogic.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements);
1694 serviceImportParseLogic.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes);
1695 resource = serviceImportParseLogic.getResourceAfterCreateRelations(resource);
1696 serviceImportParseLogic.addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, relations);
1697 serviceImportParseLogic.associateResourceInstances(yamlName, resource, relations);
1698 handleSubstitutionMappings(resource, uploadResInstancesMap);
1699 log.debug("************* in create relations, getResource start");
1700 Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId());
1701 log.debug("************* in create relations, getResource end");
1702 if (eitherGetResource.isRight()) {
1703 throw new ComponentException(
1704 componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource));
1706 return eitherGetResource.left().value();
1709 protected void processProperty(Resource resource, Map<String, DataTypeDefinition> allDataTypes,
1710 Map<String, InputDefinition> currPropertiesMap, List<ComponentInstanceInput> instPropList,
1711 List<UploadPropInfo> propertyList) {
1712 UploadPropInfo propertyInfo = propertyList.get(0);
1713 String propName = propertyInfo.getName();
1714 if (!currPropertiesMap.containsKey(propName)) {
1715 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, propName));
1717 processProperty(allDataTypes, currPropertiesMap, instPropList, propertyInfo, propName, resource.getInputs());
1720 private void processProperty(Map<String, DataTypeDefinition> allDataTypes, Map<String, InputDefinition> currPropertiesMap,
1721 List<ComponentInstanceInput> instPropList, UploadPropInfo propertyInfo, String propName,
1722 List<InputDefinition> inputs2) {
1723 InputDefinition curPropertyDef = currPropertiesMap.get(propName);
1724 ComponentInstanceInput property = null;
1725 String value = null;
1726 List<GetInputValueDataDefinition> getInputs = null;
1727 boolean isValidate = true;
1728 if (propertyInfo.getValue() != null) {
1729 getInputs = propertyInfo.getGet_input();
1730 isValidate = getInputs == null || getInputs.isEmpty();
1732 value = getPropertyJsonStringValue(propertyInfo.getValue(), curPropertyDef.getType());
1734 value = getPropertyJsonStringValue(propertyInfo.getValue(), TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
1737 property = new ComponentInstanceInput(curPropertyDef, value, null);
1738 String validPropertyVAlue = serviceBusinessLogic.validatePropValueBeforeCreate(property, value, isValidate, allDataTypes);
1739 property.setValue(validPropertyVAlue);
1740 if (isNotEmpty(getInputs)) {
1741 List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
1742 for (GetInputValueDataDefinition getInput : getInputs) {
1743 List<InputDefinition> inputs = inputs2;
1744 if (CollectionUtils.isEmpty(inputs)) {
1745 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
1747 Optional<InputDefinition> optional = inputs.stream().filter(p -> p.getName().equals(getInput.getInputName())).findAny();
1748 if (!optional.isPresent()) {
1749 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
1751 InputDefinition input = optional.get();
1752 getInput.setInputId(input.getUniqueId());
1753 getInputValues.add(getInput);
1754 GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
1755 processGetInput(getInputValues, inputs, getInputIndex);
1757 property.setGetInputValues(getInputValues);
1759 instPropList.add(property);
1760 currPropertiesMap.remove(property.getName());
1763 protected void handleSubstitutionMappings(Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
1764 if (resource.getResourceType() == ResourceTypeEnum.VF) {
1765 Either<Resource, StorageOperationStatus> getResourceRes = toscaOperationFacade.getToscaFullElement(resource.getUniqueId());
1766 if (getResourceRes.isRight()) {
1767 ResponseFormat responseFormat = componentsUtils
1768 .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), resource);
1769 throw new ComponentException(responseFormat);
1771 getResourceRes = updateCalculatedCapReqWithSubstitutionMappings(getResourceRes.left().value(), uploadResInstancesMap);
1772 if (getResourceRes.isRight()) {
1773 ResponseFormat responseFormat = componentsUtils
1774 .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), resource);
1775 throw new ComponentException(responseFormat);
1780 protected Resource createResourceInstances(String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
1781 Map<String, Resource> nodeNamespaceMap) {
1782 Either<Resource, ResponseFormat> eitherResource = null;
1783 log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName);
1784 if (MapUtils.isEmpty(uploadResInstancesMap) && resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances
1785 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
1786 throw new ComponentException(responseFormat);
1788 Map<String, Resource> existingNodeTypeMap = new HashMap<>();
1789 if (MapUtils.isNotEmpty(nodeNamespaceMap)) {
1790 nodeNamespaceMap.forEach((k, v) -> existingNodeTypeMap.put(v.getToscaResourceName(), v));
1792 Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
1793 uploadResInstancesMap.values()
1794 .forEach(i -> createAndAddResourceInstance(i, yamlName, resource, nodeNamespaceMap, existingNodeTypeMap, resourcesInstancesMap));
1795 if (MapUtils.isNotEmpty(resourcesInstancesMap)) {
1797 toscaOperationFacade.associateComponentInstancesToComponent(resource, resourcesInstancesMap, false, false);
1798 } catch (StorageException exp) {
1799 if (exp.getStorageOperationStatus() != null && exp.getStorageOperationStatus() != StorageOperationStatus.OK) {
1800 log.debug("Failed to add component instances to container component {}", resource.getName());
1801 ResponseFormat responseFormat = componentsUtils
1802 .getResponseFormat(componentsUtils.convertFromStorageResponse(exp.getStorageOperationStatus()));
1803 eitherResource = Either.right(responseFormat);
1804 throw new ByResponseFormatComponentException(eitherResource.right().value());
1808 log.debug("*************Going to get resource {}", resource.getUniqueId());
1809 Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade
1810 .getToscaElement(resource.getUniqueId(), serviceImportParseLogic.getComponentWithInstancesFilter());
1811 log.debug("*************finished to get resource {}", resource.getUniqueId());
1812 if (eitherGetResource.isRight()) {
1813 ResponseFormat responseFormat = componentsUtils
1814 .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource);
1815 throw new ComponentException(responseFormat);
1817 if (CollectionUtils.isEmpty(eitherGetResource.left().value().getComponentInstances()) &&
1818 resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances
1819 log.debug("Error when create resource instance from csar. ComponentInstances list empty");
1820 BeEcompErrorManager.getInstance().logBeDaoSystemError("Error when create resource instance from csar. ComponentInstances list empty");
1821 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
1823 return eitherGetResource.left().value();
1826 protected void handleNodeTypes(String yamlName, Resource resource, String topologyTemplateYaml, boolean needLock,
1827 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
1828 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
1831 for (Map.Entry<String, NodeTypeInfo> nodeTypeEntry : nodeTypesInfo.entrySet()) {
1832 if (nodeTypeEntry.getValue().isNested()) {
1833 handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
1834 nodeTypeEntry.getKey());
1835 log.trace("************* finished to create node {}", nodeTypeEntry.getKey());
1838 Map<String, Object> mappedToscaTemplate = null;
1839 if (org.apache.commons.lang.StringUtils.isNotEmpty(nodeName) && MapUtils.isNotEmpty(nodeTypesInfo) && nodeTypesInfo
1840 .containsKey(nodeName)) {
1841 mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate();
1843 if (MapUtils.isEmpty(mappedToscaTemplate)) {
1844 mappedToscaTemplate = (Map<String, Object>) new Yaml().load(topologyTemplateYaml);
1846 createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock, nodeTypesArtifactsToHandle,
1847 nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo);
1848 } catch (ComponentException e) {
1849 ResponseFormat responseFormat =
1850 e.getResponseFormat() != null ? e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
1851 componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
1853 } catch (StorageException e) {
1854 ResponseFormat responseFormat = componentsUtils
1855 .getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
1856 componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
1858 } catch (Exception e) {
1859 log.debug("Exception occured when handleNodeTypes, error is:{}", e.getMessage(), e);
1860 throw new ComponentException(ActionStatus.GENERAL_ERROR);
1864 protected Resource handleNestedVfc(Service service,
1865 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
1866 List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
1869 String yamlName = nodesInfo.get(nodeName).getTemplateFileName();
1870 Map<String, Object> nestedVfcJsonMap = nodesInfo.get(nodeName).getMappedToscaTemplate();
1871 createResourcesFromYamlNodeTypesList(yamlName, service, nestedVfcJsonMap, false, nodesArtifactsToHandle, createdArtifacts, nodesInfo,
1873 log.debug("************* Finished to create node types from yaml {}", yamlName);
1874 if (nestedVfcJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE.getElementName())) {
1875 log.debug("************* Going to handle complex VFC from yaml {}", yamlName);
1876 return handleComplexVfc(nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName);
1878 return new Resource();
1879 } catch (Exception e) {
1880 log.debug("Exception occured when handleNestedVFc, error is:{}", e.getMessage(), e);
1881 throw new ComponentException(ActionStatus.GENERAL_ERROR);
1885 protected Resource handleNestedVfc(Resource resource,
1886 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
1887 List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
1889 String yamlName = nodesInfo.get(nodeName).getTemplateFileName();
1890 Map<String, Object> nestedVfcJsonMap = nodesInfo.get(nodeName).getMappedToscaTemplate();
1891 log.debug("************* Going to create node types from yaml {}", yamlName);
1892 createResourcesFromYamlNodeTypesList(yamlName, resource, nestedVfcJsonMap, false, nodesArtifactsToHandle, createdArtifacts, nodesInfo,
1894 if (nestedVfcJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE.getElementName())) {
1895 log.debug("************* Going to handle complex VFC from yaml {}", yamlName);
1896 resource = handleComplexVfc(resource, nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName);
1901 protected Resource handleComplexVfc(Resource resource,
1902 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
1903 List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
1904 String nodeName, String yamlName) {
1905 Resource oldComplexVfc = null;
1906 Resource newComplexVfc = serviceImportParseLogic.buildValidComplexVfc(resource, csarInfo, nodeName, nodesInfo);
1907 Either<Resource, StorageOperationStatus> oldComplexVfcRes = toscaOperationFacade
1908 .getFullLatestComponentByToscaResourceName(newComplexVfc.getToscaResourceName());
1909 if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() == StorageOperationStatus.NOT_FOUND) {
1910 oldComplexVfcRes = toscaOperationFacade.getFullLatestComponentByToscaResourceName(
1911 serviceImportParseLogic.buildNestedToscaResourceName(ResourceTypeEnum.VF.name(), csarInfo.getVfResourceName(), nodeName).getRight());
1913 if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() != StorageOperationStatus.NOT_FOUND) {
1914 throw new ComponentException(ActionStatus.GENERAL_ERROR);
1915 } else if (oldComplexVfcRes.isLeft()) {
1916 log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
1917 Either<Boolean, ResponseFormat> eitherValidation = serviceImportParseLogic
1918 .validateNestedDerivedFromDuringUpdate(oldComplexVfcRes.left().value(), newComplexVfc,
1919 ValidationUtils.hasBeenCertified(oldComplexVfcRes.left().value().getVersion()));
1920 if (eitherValidation.isLeft()) {
1921 oldComplexVfc = oldComplexVfcRes.left().value();
1924 newComplexVfc = handleComplexVfc(nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName, oldComplexVfc,
1926 csarInfo.getCreatedNodesToscaResourceNames().put(nodeName, newComplexVfc.getToscaResourceName());
1927 LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(CERTIFICATION_ON_IMPORT,
1928 LifecycleChangeInfoWithAction.LifecycleChanceActionEnum.CREATE_FROM_CSAR);
1929 log.debug("Going to certify cvfc {}. ", newComplexVfc.getName());
1930 final Resource result = serviceImportParseLogic
1931 .propagateStateToCertified(csarInfo.getModifier(), newComplexVfc, lifecycleChangeInfo, true, false, true);
1932 csarInfo.getCreatedNodes().put(nodeName, result);
1933 csarInfo.removeNodeFromQueue();
1937 private Map<String, Resource> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource, Map<String, Object> mappedToscaTemplate,
1939 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
1940 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
1941 Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo) {
1942 Either<String, ImportUtils.ResultStatusEnum> toscaVersion = findFirstToscaStringElement(mappedToscaTemplate,
1943 TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION);
1944 if (toscaVersion.isRight()) {
1945 throw new ComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE);
1947 Map<String, Object> mapToConvert = new HashMap<>();
1948 mapToConvert.put(TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), toscaVersion.left().value());
1949 Map<String, Object> nodeTypes = serviceImportParseLogic.getNodeTypesFromTemplate(mappedToscaTemplate);
1950 createNodeTypes(yamlName, resource, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, mapToConvert,
1952 return csarInfo.getCreatedNodes();
1955 protected void createNodeTypes(String yamlName, Resource resource, boolean needLock,
1956 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
1957 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
1958 Map<String, Object> mapToConvert, Map<String, Object> nodeTypes) {
1959 Iterator<Map.Entry<String, Object>> nodesNameValueIter = nodeTypes.entrySet().iterator();
1960 Resource vfcCreated = null;
1961 while (nodesNameValueIter.hasNext()) {
1962 Map.Entry<String, Object> nodeType = nodesNameValueIter.next();
1963 Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle =
1964 nodeTypesArtifactsToHandle == null || nodeTypesArtifactsToHandle.isEmpty() ? null : nodeTypesArtifactsToHandle.get(nodeType.getKey());
1965 if (nodeTypesInfo.containsKey(nodeType.getKey())) {
1966 log.trace("************* Going to handle nested vfc {}", nodeType.getKey());
1967 vfcCreated = handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
1969 log.trace("************* Finished to handle nested vfc {}", nodeType.getKey());
1970 } else if (csarInfo.getCreatedNodesToscaResourceNames() != null && !csarInfo.getCreatedNodesToscaResourceNames()
1971 .containsKey(nodeType.getKey())) {
1972 log.trace("************* Going to create node {}", nodeType.getKey());
1973 ImmutablePair<Resource, ActionStatus> resourceCreated = createNodeTypeResourceFromYaml(yamlName, nodeType, csarInfo.getModifier(),
1974 mapToConvert, resource, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, true, csarInfo, true);
1975 log.debug("************* Finished to create node {}", nodeType.getKey());
1976 vfcCreated = resourceCreated.getLeft();
1977 csarInfo.getCreatedNodesToscaResourceNames().put(nodeType.getKey(), vfcCreated.getToscaResourceName());
1979 if (vfcCreated != null) {
1980 csarInfo.getCreatedNodes().put(nodeType.getKey(), vfcCreated);
1982 mapToConvert.remove(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName());
1986 protected ImmutablePair<Resource, ActionStatus> createNodeTypeResourceFromYaml(String yamlName, Map.Entry<String, Object> nodeNameValue,
1987 User user, Map<String, Object> mapToConvert, Resource resourceVf,
1989 Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
1990 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
1991 boolean forceCertificationAllowed, CsarInfo csarInfo,
1993 final var validatedUser = serviceBusinessLogic.validateUser(user, "CheckIn Resource", resourceVf, AuditingActionEnum.CHECKIN_RESOURCE,
1995 UploadResourceInfo resourceMetaData = serviceImportParseLogic.fillResourceMetadata(yamlName, resourceVf, nodeNameValue.getKey(),
1997 String singleVfcYaml = serviceImportParseLogic.buildNodeTypeYaml(nodeNameValue, mapToConvert, resourceMetaData.getResourceType(), csarInfo);
1998 return serviceImportParseLogic.createResourceFromNodeType(singleVfcYaml, resourceMetaData, validatedUser, true, needLock,
1999 nodeTypeArtifactsToHandle,
2000 nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeNameValue.getKey(), isNested);
2003 protected Service createRIAndRelationsFromYaml(String yamlName, Service service,
2004 Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap,
2005 String topologyTemplateYaml, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
2006 Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
2007 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
2009 log.debug("************* Going to create all nodes {}", yamlName);
2010 handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts,
2011 nodeTypesInfo, csarInfo, nodeName);
2012 List<PropertyDefinition> serviceProperties = null != service ? service.getProperties() : Collections.emptyList();
2013 if (MapUtils.isNotEmpty(uploadComponentInstanceInfoMap)) {
2014 log.debug("************* Going to create all resource instances {}", yamlName);
2015 service = createServiceInstances(yamlName, service, uploadComponentInstanceInfoMap, csarInfo.getCreatedNodes());
2016 log.debug("************* Going to create all relations {}", yamlName);
2017 service = createServiceInstancesRelations(csarInfo.getModifier(), yamlName, service, uploadComponentInstanceInfoMap, serviceProperties);
2018 log.debug("************* Going to create positions {}", yamlName);
2019 compositionBusinessLogic.setPositionsForComponentInstances(service, csarInfo.getModifier().getUserId());
2020 log.debug("************* Finished to set positions {}", yamlName);
2025 protected Service createServiceInstancesRelations(User user, String yamlName, Service service,
2026 Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
2027 List<PropertyDefinition> serviceProperties) {
2028 log.debug("#createResourceInstancesRelations - Going to create relations ");
2029 List<ComponentInstance> componentInstancesList = service.getComponentInstances();
2030 if (MapUtils.isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)) { // PNF can have no resource instances
2031 log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ",
2032 service.getUniqueId(), yamlName);
2033 BeEcompErrorManager.getInstance()
2034 .logInternalDataError("createResourceInstancesRelations", "No instances found in a component or nn yaml template. ",
2035 BeEcompErrorManager.ErrorSeverity.ERROR);
2036 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName));
2038 Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>();
2039 Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>();
2040 Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>();
2041 Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>();
2042 Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>();
2043 Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>();
2044 Map<String, Resource> originCompMap = new HashMap<>();
2045 List<RequirementCapabilityRelDef> relations = new ArrayList<>();
2046 Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
2047 Map<String, UploadNodeFilterInfo> instNodeFilter = new HashMap<>();
2048 Map<String, Map<String, InterfaceDefinition>> instInterfaces = new HashMap<>();
2049 log.debug("enter ServiceImportBusinessLogic createServiceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. ");
2050 final ApplicationDataTypeCache applicationDataTypeCache = serviceBusinessLogic.applicationDataTypeCache;
2051 if (applicationDataTypeCache != null) {
2052 final Map<String, DataTypeDefinition> allDataTypesMap =
2053 componentsUtils.getAllDataTypes(applicationDataTypeCache, service.getModel());
2054 final Service service1 = service;
2055 service1.setProperties(serviceProperties);
2056 uploadResInstancesMap.values().forEach(
2057 i -> processComponentInstance(yamlName, service1, componentInstancesList,
2058 allDataTypesMap, instProperties,
2059 instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs,
2060 instNodeFilter, instInterfaces, i)
2063 updatePropertyToscaFunctionData(service, instProperties, instAttributes);
2064 serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, service, instProperties);
2065 serviceImportParseLogic.associateComponentInstanceInterfacesToComponent(
2070 serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, service, instInputs);
2071 serviceImportParseLogic.associateCINodeFilterToComponent(yamlName, service, instNodeFilter);
2072 serviceImportParseLogic.associateDeploymentArtifactsToInstances(user, yamlName, service, instDeploymentArtifacts);
2073 serviceImportParseLogic.associateArtifactsToInstances(yamlName, service, instArtifacts);
2074 serviceImportParseLogic.associateOrAddCalculatedCapReq(yamlName, service, instCapabilities, instRequirements);
2075 log.debug("enter createServiceInstancesRelations test,instRequirements:{},instCapabilities:{}", instRequirements, instCapabilities);
2076 serviceImportParseLogic.associateInstAttributeToComponentToInstances(yamlName, service, instAttributes);
2077 ToscaElement serviceTemplate = ModelConverter.convertToToscaElement(service);
2078 Map<String, ListCapabilityDataDefinition> capabilities = serviceTemplate.getCapabilities();
2079 Map<String, ListRequirementDataDefinition> requirements = serviceTemplate.getRequirements();
2080 serviceImportParseLogic.associateCapabilitiesToService(yamlName, service, capabilities);
2081 serviceImportParseLogic.associateRequirementsToService(yamlName, service, requirements);
2082 service = getResourceAfterCreateRelations(service);
2083 addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations);
2084 serviceImportParseLogic.associateResourceInstances(yamlName, service, relations);
2085 log.debug("************* in create relations, getResource start");
2086 Either<Service, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(service.getUniqueId());
2087 log.debug("************* in create relations, getResource end");
2088 if (eitherGetResource.isRight()) {
2089 throw new ComponentException(componentsUtils
2090 .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), service,
2091 service.getComponentType()));
2093 return eitherGetResource.left().value();
2096 private void updatePropertyToscaFunctionData(final Component service,
2097 final Map<String, List<ComponentInstanceProperty>> instancePropertyMap,
2098 final Map<String, List<AttributeDefinition>> instanceAttributeMap) {
2099 final Component updatedService =
2100 toscaOperationFacade.getToscaElement(service.getUniqueId()).left()
2101 .on(storageOperationStatus -> {
2102 final ActionStatus status = componentsUtils.convertFromStorageResponse(storageOperationStatus);
2103 final ResponseFormat responseFormat =
2104 componentsUtils.getResponseFormatByComponent(status, service, service.getComponentType());
2105 throw new ComponentException(responseFormat);
2108 instancePropertyMap.values().forEach(instancePropertyList ->
2109 instancePropertyList.stream()
2110 .filter(PropertyDataDefinition::isToscaFunction)
2111 .forEach(instanceProperty -> {
2112 toscaFunctionService.updateFunctionWithDataFromSelfComponent(instanceProperty.getToscaFunction(),
2113 updatedService, instancePropertyMap, instanceAttributeMap);
2114 instanceProperty.setValue(StringEscapeUtils.unescapeJava(instanceProperty.getToscaFunction().getValue()));
2119 protected void processComponentInstance(String yamlName, Component component, List<ComponentInstance> componentInstancesList,
2120 Map<String, DataTypeDefinition> allDataTypes,
2121 Map<String, List<ComponentInstanceProperty>> instProperties,
2122 Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties,
2123 Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements,
2124 Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts,
2125 Map<String, Map<String, ArtifactDefinition>> instArtifacts,
2126 Map<String, List<AttributeDefinition>> instAttributes, Map<String, Resource> originCompMap,
2127 Map<String, List<ComponentInstanceInput>> instInputs,
2128 Map<String, UploadNodeFilterInfo> instNodeFilter,
2129 Map<String, Map<String, InterfaceDefinition>> instInterfaces,
2130 UploadComponentInstanceInfo uploadComponentInstanceInfo) {
2131 log.debug("enter ServiceImportBusinessLogic processComponentInstance");
2132 Optional<ComponentInstance> currentCompInstanceOpt = componentInstancesList.stream()
2133 .filter(i -> i.getName().equals(uploadComponentInstanceInfo.getName())).findFirst();
2134 if (currentCompInstanceOpt.isEmpty()) {
2135 log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, uploadComponentInstanceInfo.getName(), component.getUniqueId());
2136 BeEcompErrorManager.getInstance()
2137 .logInternalDataError(COMPONENT_INSTANCE_WITH_NAME + uploadComponentInstanceInfo.getName() + IN_RESOURCE, component.getUniqueId(),
2138 BeEcompErrorManager.ErrorSeverity.ERROR);
2139 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
2140 throw new ComponentException(responseFormat);
2142 ComponentInstance currentCompInstance = currentCompInstanceOpt.get();
2143 String resourceInstanceId = currentCompInstance.getUniqueId();
2144 Resource originResource = getOriginResource(yamlName, originCompMap, currentCompInstance);
2145 if (MapUtils.isNotEmpty(originResource.getRequirements())) {
2146 instRequirements.put(currentCompInstance, originResource.getRequirements());
2148 if (MapUtils.isNotEmpty(originResource.getCapabilities())) {
2149 processComponentInstanceCapabilities(allDataTypes, instCapabilties, uploadComponentInstanceInfo, currentCompInstance, originResource);
2151 if (originResource.getDeploymentArtifacts() != null && !originResource.getDeploymentArtifacts().isEmpty()) {
2152 instDeploymentArtifacts.put(resourceInstanceId, originResource.getDeploymentArtifacts());
2154 if (originResource.getArtifacts() != null && !originResource.getArtifacts().isEmpty()) {
2155 instArtifacts.put(resourceInstanceId, originResource.getArtifacts());
2157 if (originResource.getAttributes() != null && !originResource.getAttributes().isEmpty()) {
2158 instAttributes.put(resourceInstanceId, originResource.getAttributes());
2159 addAttributeValueToResourceInstance(instAttributes, uploadComponentInstanceInfo.getAttributes());
2160 instAttributes.get(resourceInstanceId).addAll(addImplicitAttributeValues(originResource, uploadComponentInstanceInfo));
2162 if (uploadComponentInstanceInfo.getUploadNodeFilterInfo() == null) {
2163 instNodeFilter.put(resourceInstanceId, new UploadNodeFilterInfo());
2165 instNodeFilter.put(resourceInstanceId, uploadComponentInstanceInfo.getUploadNodeFilterInfo());
2167 if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getInterfaces())) {
2169 ResponseFormat addInterfacesToRiRes = addInterfaceValuesToRi(
2170 uploadComponentInstanceInfo,
2173 currentCompInstance,
2176 if (addInterfacesToRiRes.getStatus() != 200) {
2177 throw new ComponentException(addInterfacesToRiRes);
2180 if (originResource.getResourceType() != ResourceTypeEnum.VF) {
2181 ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, component, originResource,
2182 currentCompInstance, instProperties, allDataTypes);
2183 if (addPropertiesValueToRiRes.getStatus() != 200) {
2184 throw new ComponentException(addPropertiesValueToRiRes);
2187 addInputsValuesToRi(uploadComponentInstanceInfo, component, originResource, currentCompInstance, instInputs, allDataTypes);
2191 private List<AttributeDefinition> addImplicitAttributeValues(Resource originResource, UploadComponentInstanceInfo uploadComponentInstanceInfo) {
2192 if (uploadComponentInstanceInfo.getAttributes() == null) {
2193 return Collections.emptyList();
2195 List<String> origAttributes = originResource.getAttributes().stream().map(AttributeDefinition::getName).collect(toList());
2196 Map<String, UploadAttributeInfo> uploadAttributes = uploadComponentInstanceInfo.getAttributes();
2197 List<String> newAttributesToAdd =
2198 uploadAttributes.keySet().stream().filter(newAttribute -> !origAttributes.contains(newAttribute))
2200 List<PropertyDefinition> propsToAddAsAttributes =
2201 originResource.getProperties().stream().filter(prop -> newAttributesToAdd.contains(prop.getName())).collect(toList());
2202 propsToAddAsAttributes.stream().forEach(prop -> {
2203 Object value = uploadAttributes.get(prop.getName()).getValue();
2204 if (value instanceof Collection<?> || value instanceof Map<?, ?>) {
2205 Gson gson = new Gson();
2206 String json = gson.toJson(value);
2207 prop.setValue(json);
2209 prop.setValue(String.valueOf(value));
2212 List<AttributeDefinition> attributesToAdd = new ArrayList<>();
2213 for (PropertyDefinition prop: propsToAddAsAttributes) {
2214 attributesToAdd.add(getPropertyAsAttribute(prop));
2216 return attributesToAdd;
2219 private AttributeDefinition getPropertyAsAttribute(PropertyDefinition property) {
2220 AttributeDefinition attribute = new AttributeDefinition();
2221 attribute.setName(property.getName());
2222 attribute.setType(property.getType());
2223 attribute.setSchema(property.getSchema());
2224 attribute.setValue(property.getValue());
2225 attribute.setDefaultValue(property.getDefaultValue());
2229 protected void addInputsValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo, Component component, Resource originResource,
2230 ComponentInstance currentCompInstance, Map<String, List<ComponentInstanceInput>> instInputs,
2231 Map<String, DataTypeDefinition> allDataTypes) {
2232 Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
2234 if (MapUtils.isNotEmpty(propMap)) {
2235 Map<String, InputDefinition> currPropertiesMap = new HashMap<>();
2236 List<ComponentInstanceInput> instPropList = new ArrayList<>();
2237 if (CollectionUtils.isEmpty(originResource.getInputs())) {
2238 log.debug("failed to find properties ");
2239 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
2241 originResource.getInputs().forEach(p -> serviceImportParseLogic.addInput(currPropertiesMap, p));
2242 for (List<UploadPropInfo> propertyList : propMap.values()) {
2243 processProperty(component, allDataTypes, currPropertiesMap, instPropList, propertyList);
2245 currPropertiesMap.values().forEach(p -> instPropList.add(new ComponentInstanceInput(p)));
2246 instInputs.put(currentCompInstance.getUniqueId(), instPropList);
2248 } catch (Exception e) {
2249 log.debug("failed to add Inputs Values To Ri");
2250 throw new ComponentException(ActionStatus.GENERAL_ERROR);
2254 protected void processProperty(Component component, Map<String, DataTypeDefinition> allDataTypes,
2255 Map<String, InputDefinition> currPropertiesMap, List<ComponentInstanceInput> instPropList,
2256 List<UploadPropInfo> propertyList) {
2257 UploadPropInfo propertyInfo = propertyList.get(0);
2258 String propName = propertyInfo.getName();
2259 if (!currPropertiesMap.containsKey(propName)) {
2260 log.debug("failed to find property {} ", propName);
2261 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, propName));
2263 processProperty(allDataTypes, currPropertiesMap, instPropList, propertyInfo, propName, component.getInputs());
2266 protected void processGetInput(List<GetInputValueDataDefinition> getInputValues, List<InputDefinition> inputs,
2267 GetInputValueDataDefinition getInputIndex) {
2268 Optional<InputDefinition> optional;
2269 if (getInputIndex != null) {
2270 optional = inputs.stream().filter(p -> p.getName().equals(getInputIndex.getInputName())).findAny();
2271 if (!optional.isPresent()) {
2272 log.debug("Failed to find input {} ", getInputIndex.getInputName());
2273 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
2275 InputDefinition inputIndex = optional.get();
2276 getInputIndex.setInputId(inputIndex.getUniqueId());
2277 getInputValues.add(getInputIndex);
2281 private void addAttributeValueToResourceInstance(Map<String, List<AttributeDefinition>> instAttributes,
2282 Map<String, UploadAttributeInfo> attributeMap) {
2283 if (attributeMap == null) {
2286 attributeMap.forEach((attributeName, attributeValue) -> instAttributes.values()
2287 .forEach(value -> value.stream().filter(attr -> attr.getName().equals(attributeName)).forEach(attr -> {
2288 if (attributeValue.getValue() instanceof Collection<?> || attributeValue.getValue() instanceof Map<?, ?>) {
2289 Gson gson = new Gson();
2290 String json = gson.toJson(attributeValue.getValue());
2291 attr.setValue(json);
2293 attr.setValue(String.valueOf(attributeValue.getValue()));
2298 protected ResponseFormat addPropertyValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo, Component component,
2299 Resource originResource, ComponentInstance currentCompInstance,
2300 Map<String, List<ComponentInstanceProperty>> instProperties,
2301 Map<String, DataTypeDefinition> allDataTypes) {
2302 Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
2303 Map<String, PropertyDefinition> currPropertiesMap = new HashMap<>();
2304 List<PropertyDefinition> originalPropertyList = originResource.getProperties();
2305 if (MapUtils.isNotEmpty(propMap) && CollectionUtils.isEmpty(originalPropertyList)) {
2306 log.debug("failed to find properties ");
2307 return componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND);
2309 if (CollectionUtils.isEmpty(originalPropertyList)) {
2310 return componentsUtils.getResponseFormat(ActionStatus.OK);
2312 originalPropertyList.stream()
2313 .filter(property -> !currPropertiesMap.containsKey(property.getName()))
2314 .forEach(property -> currPropertiesMap.put(property.getName(), property));
2315 List<ComponentInstanceProperty> instPropList = new ArrayList<>();
2316 if (MapUtils.isNotEmpty(propMap)) {
2317 for (final List<UploadPropInfo> propertyList : propMap.values()) {
2318 UploadPropInfo propertyInfo = propertyList.get(0);
2319 String propName = propertyInfo.getName();
2320 if (!currPropertiesMap.containsKey(propName)) {
2321 log.debug("failed to find property {} ", propName);
2322 return componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, propName);
2324 PropertyDefinition curPropertyDef = currPropertiesMap.get(propName);
2325 String value = null;
2326 final List<GetInputValueDataDefinition> getInputs = new ArrayList<>();
2327 boolean isValidate = true;
2328 if (propertyInfo.getValue() != null) {
2329 getInputs.addAll(propertyInfo.getGet_input());
2330 isValidate = getInputs.isEmpty();
2332 value = getPropertyJsonStringValue(propertyInfo.getValue(), curPropertyDef.getType());
2334 value = getPropertyJsonStringValue(propertyInfo.getValue(), TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
2337 final var property = new ComponentInstanceProperty(curPropertyDef, value, null);
2338 String validatedPropValue = serviceBusinessLogic.validatePropValueBeforeCreate(property, value, true, allDataTypes);
2340 addSubPropertyYamlToscaFunctions(validatedPropValue, value, property.getType(), propertyInfo, allDataTypes);
2342 if (CollectionUtils.isNotEmpty(propertyInfo.getSubPropertyToscaFunctions())) {
2343 validatedPropValue = value;
2346 property.setValue(validatedPropValue);
2348 if (tryHandlingAsYamlToscaFunction(validatedPropValue, value, propertyInfo)) {
2350 final Object yamlValue = new Yaml().loadAs(value, Object.class);
2351 CustomYamlFunction toscaFunction = new CustomYamlFunction();
2352 toscaFunction.setYamlValue(yamlValue);
2353 property.setToscaFunction(toscaFunction);
2354 } catch (Exception exception) {
2355 log.info("Cannot create YAML value for {}", propName);
2358 property.setToscaFunction(propertyInfo.getToscaFunction());
2360 property.setSubPropertyToscaFunctions(propertyInfo.getSubPropertyToscaFunctions());
2361 if (!getInputs.isEmpty() && CollectionUtils.isEmpty(property.getSubPropertyToscaFunctions())) {
2362 final List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
2363 for (final GetInputValueDataDefinition getInput : getInputs) {
2364 final List<InputDefinition> inputs = component.getInputs();
2365 if (inputs == null || inputs.isEmpty()) {
2366 log.debug("Failed to add property {} to instance. Inputs list is empty ", property);
2367 serviceBusinessLogic.rollbackWithException(ActionStatus.INPUTS_NOT_FOUND,
2368 property.getGetInputValues().stream().map(GetInputValueDataDefinition::getInputName).collect(toList()).toString());
2370 InputDefinition input = serviceImportParseLogic.findInputByName(inputs, getInput);
2371 getInput.setInputId(input.getUniqueId());
2372 getInputValues.add(getInput);
2373 GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
2374 if (getInputIndex != null) {
2375 input = serviceImportParseLogic.findInputByName(inputs, getInputIndex);
2376 getInputIndex.setInputId(input.getUniqueId());
2377 getInputValues.add(getInputIndex);
2380 property.setGetInputValues(getInputValues);
2382 instPropList.add(property);
2383 currPropertiesMap.remove(property.getName());
2386 if (!currPropertiesMap.isEmpty()) {
2387 for (PropertyDefinition value : currPropertiesMap.values()) {
2388 instPropList.add(new ComponentInstanceProperty(value));
2391 instProperties.put(currentCompInstance.getUniqueId(), instPropList);
2392 return componentsUtils.getResponseFormat(ActionStatus.OK);
2395 private boolean tryHandlingAsYamlToscaFunction(String validatedPropValue, String value, UploadPropInfo propertyInfo) {
2396 return StringUtils.isEmpty(validatedPropValue) && StringUtils.isNotEmpty(value) && propertyInfo.getToscaFunction() == null
2397 && CollectionUtils.isEmpty(propertyInfo.getSubPropertyToscaFunctions());
2400 private void addSubPropertyYamlToscaFunctions(final String validatedPropValue, final String value, final String propertyType,
2401 final UploadPropInfo propertyInfo, final Map<String, DataTypeDefinition> allDataTypes) {
2402 if (StringUtils.isNotEmpty(validatedPropValue) || StringUtils.isEmpty(value) || ToscaPropertyType.isValidType(propertyType) != null) {
2406 final JsonObject jsonObject = JsonParser.parseString(value).getAsJsonObject();
2408 final DataTypeDefinition dataTypeDefinition = allDataTypes.get(propertyType);
2409 final List<String> propertyNames =
2410 dataTypeDefinition.getProperties().stream().map(PropertyDataDefinition::getName).collect(Collectors.toList());
2412 boolean hasSubPropertyValues = jsonObject.entrySet().stream().allMatch(entry -> propertyNames.contains(entry.getKey()));
2414 if (hasSubPropertyValues) {
2415 for (final PropertyDefinition prop : dataTypeDefinition.getProperties()) {
2416 if (propertyInfo.getSubPropertyToscaFunctions().stream()
2417 .anyMatch(subPropertyToscaFunction -> subPropertyToscaFunction.getSubPropertyPath().get(0).equals(prop.getName()))) {
2420 Optional<SubPropertyToscaFunction> subPropertyToscaFunction = createSubPropertyYamlToscaFunction(jsonObject, prop, allDataTypes);
2421 if (subPropertyToscaFunction.isPresent()) {
2422 propertyInfo.getSubPropertyToscaFunctions().add(subPropertyToscaFunction.get());
2426 } catch (Exception exception) {
2427 log.info("Cannot create YAML value for {}", value);
2431 private Optional<SubPropertyToscaFunction> createSubPropertyYamlToscaFunction(final JsonObject jsonObject, final PropertyDefinition prop,
2432 final Map<String, DataTypeDefinition> allDataTypes) {
2433 JsonElement propJsonElement = jsonObject.get(prop.getName());
2434 if (propJsonElement != null) {
2435 final String subPropValue = propJsonElement.toString();
2436 final ComponentInstanceProperty subProperty = new ComponentInstanceProperty(prop, subPropValue, null);
2437 final String validateSubPropValue =
2438 serviceBusinessLogic.validatePropValueBeforeCreate(subProperty, subPropValue, true, allDataTypes);
2440 if (StringUtils.isEmpty(validateSubPropValue) && StringUtils.isNotEmpty(subPropValue)) {
2442 Object yamlValue = new Yaml().loadAs(subPropValue, Object.class);
2443 SubPropertyToscaFunction subPropertyToscaFunction = new SubPropertyToscaFunction();
2444 CustomYamlFunction toscaFunction = new CustomYamlFunction();
2445 toscaFunction.setYamlValue(yamlValue);
2446 subPropertyToscaFunction.setToscaFunction(toscaFunction);
2447 subPropertyToscaFunction.setSubPropertyPath(Collections.singletonList(prop.getName()));
2448 return Optional.of(subPropertyToscaFunction);
2449 } catch (Exception exception) {
2450 log.info("Cannot create YAML value for {}", subPropValue);
2454 return Optional.empty();
2457 protected ResponseFormat addInterfaceValuesToRi(
2458 UploadComponentInstanceInfo uploadComponentInstanceInfo,
2459 Component component,
2460 Resource originResource, ComponentInstance currentCompInstance,
2461 Map<String, Map<String, InterfaceDefinition>> instInterfaces
2463 Map<String, UploadInterfaceInfo> instanceInterfacesMap = uploadComponentInstanceInfo.getInterfaces();
2464 Map<String, InterfaceDefinition> currInterfacesMap = new HashMap<>();
2465 Map<String, InterfaceDefinition> interfacesFromNodeType = originResource.getInterfaces();
2466 if ((MapUtils.isNotEmpty(instanceInterfacesMap)) && (MapUtils.isEmpty(interfacesFromNodeType))) {
2467 log.debug("failed to find interfaces ");
2468 return componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT);
2470 if (interfacesFromNodeType == null || interfacesFromNodeType.isEmpty()) {
2471 return componentsUtils.getResponseFormat(ActionStatus.OK);
2473 for (Map.Entry<String, InterfaceDefinition> entryInstances : interfacesFromNodeType.entrySet()) {
2474 String interfaceName = entryInstances.getKey().substring(entryInstances.getKey().lastIndexOf(".") + 1);
2475 if (!currInterfacesMap.containsKey(interfaceName)) {
2476 currInterfacesMap.put(interfaceName, entryInstances.getValue());
2480 Map<String, InterfaceDefinition> instInterfacesMap = new HashMap<>();
2481 if (MapUtils.isNotEmpty(instanceInterfacesMap)) {
2482 for (UploadInterfaceInfo uploadInterfaceInfo : instanceInterfacesMap.values()) {
2483 String interfaceName = uploadInterfaceInfo.getName();
2484 if (!currInterfacesMap.containsKey(interfaceName)) {
2485 log.debug("failed to find interface {} ", interfaceName);
2486 return componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceName);
2488 InterfaceDefinition currentInterfaceDef = currInterfacesMap.get(interfaceName);
2489 Map<String, OperationDataDefinition> operationsToAdd = new HashMap<>();
2491 Map<String, OperationDataDefinition> operations = uploadInterfaceInfo.getOperations();
2492 for (Map.Entry<String, OperationDataDefinition> operation : operations.entrySet()) {
2493 OperationDataDefinition instanceOperation = operation.getValue();
2494 OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap()
2495 .getOrDefault(operation.getKey(), new Operation(instanceOperation));
2497 ListDataDefinition<OperationInputDefinition> instanceInputs = instanceOperation.getInputs();
2498 if (null != instanceInputs) {
2499 mergeOperationInputDefinitions(templateOperation.getInputs(), instanceInputs);
2500 component.getProperties()
2501 .forEach(property -> instanceInputs.getListToscaDataDefinition().stream()
2502 .filter(instanceInput ->
2503 instanceInput.getToscaFunction() instanceof ToscaGetFunctionDataDefinition &&
2504 property.getName().equals(instanceInput.getToscaFunction() != null ?
2505 ((ToscaGetFunctionDataDefinition) instanceInput.getToscaFunction()).getPropertyName() : null))
2506 .forEach(oldInput -> oldInput.setType(property.getType()))
2508 templateOperation.setInputs(instanceInputs);
2511 templateOperation.setImplementation(instanceOperation.getImplementation());
2513 templateOperation.setDescription(instanceOperation.getDescription());
2514 templateOperation.setMilestones(instanceOperation.getMilestones());
2515 operationsToAdd.put(operation.getKey(), templateOperation);
2517 InterfaceDefinition interfaceDef = new InterfaceDefinition();
2518 interfaceDef.setModel(component.getModel());
2519 interfaceDef.setType(currentInterfaceDef.getType());
2520 interfaceDef.setUniqueId(currentInterfaceDef.getType());
2521 interfaceDef.setDescription(uploadInterfaceInfo.getDescription());
2522 interfaceDef.setOperations(operationsToAdd);
2523 instInterfacesMap.put(currentInterfaceDef.getType(), interfaceDef);
2524 currInterfacesMap.remove(interfaceName);
2527 if (!currInterfacesMap.isEmpty()) {
2528 for (InterfaceDefinition value : currInterfacesMap.values()) {
2529 instInterfacesMap.put(value.getUniqueId(), value);
2532 instInterfaces.put(currentCompInstance.getUniqueId(), instInterfacesMap);
2533 return componentsUtils.getResponseFormat(ActionStatus.OK);
2536 private void mergeOperationInputDefinitions(ListDataDefinition<OperationInputDefinition> inputsFromNodeType,
2537 ListDataDefinition<OperationInputDefinition> instanceInputs) {
2538 if (inputsFromNodeType == null || CollectionUtils.isEmpty(inputsFromNodeType.getListToscaDataDefinition()) || instanceInputs == null
2539 || CollectionUtils.isEmpty(instanceInputs.getListToscaDataDefinition())) {
2542 instanceInputs.getListToscaDataDefinition().forEach(
2543 instanceInput -> inputsFromNodeType.getListToscaDataDefinition().stream().filter(
2544 templateInput -> templateInput.getName().equals(instanceInput.getName())
2546 newInstanceInput -> {
2547 instanceInput.setSourceProperty(newInstanceInput.getSourceProperty());
2548 instanceInput.setSource(newInstanceInput.getSource());
2549 instanceInput.setType(newInstanceInput.getType());
2553 instanceInputs.getListToscaDataDefinition().stream()
2554 .filter(instanceInput -> inputsFromNodeType.getListToscaDataDefinition().stream().noneMatch(
2555 inputFromNodeType -> inputFromNodeType.getName().equals(instanceInput.getName())
2557 .forEach(oldInput -> oldInput.setType("string"));
2560 protected void processComponentInstanceCapabilities(Map<String, DataTypeDefinition> allDataTypes,
2561 Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties,
2562 UploadComponentInstanceInfo uploadComponentInstanceInfo,
2563 ComponentInstance currentCompInstance, Resource originResource) {
2564 log.debug("enter processComponentInstanceCapabilities");
2565 Map<String, List<CapabilityDefinition>> originCapabilities;
2566 if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getCapabilities())) {
2567 originCapabilities = new HashMap<>();
2568 Map<String, Map<String, UploadPropInfo>> newPropertiesMap = new HashMap<>();
2569 originResource.getCapabilities().forEach((k, v) -> serviceImportParseLogic.addCapabilities(originCapabilities, k, v));
2570 uploadComponentInstanceInfo.getCapabilities().values()
2571 .forEach(l -> serviceImportParseLogic.addCapabilitiesProperties(newPropertiesMap, l));
2572 updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap);
2574 originCapabilities = originResource.getCapabilities();
2576 instCapabilties.put(currentCompInstance, originCapabilities);
2579 protected void updateCapabilityPropertiesValues(Map<String, DataTypeDefinition> allDataTypes,
2580 Map<String, List<CapabilityDefinition>> originCapabilities,
2581 Map<String, Map<String, UploadPropInfo>> newPropertiesMap) {
2582 originCapabilities.values().stream().flatMap(Collection::stream).filter(c -> newPropertiesMap.containsKey(c.getName()))
2583 .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()), allDataTypes));
2586 protected void updatePropertyValues(List<ComponentInstanceProperty> properties, Map<String, UploadPropInfo> newProperties,
2587 Map<String, DataTypeDefinition> allDataTypes) {
2588 properties.forEach(p -> updatePropertyValue(p, newProperties.get(p.getName()), allDataTypes));
2591 protected String updatePropertyValue(ComponentInstanceProperty property, UploadPropInfo propertyInfo,
2592 Map<String, DataTypeDefinition> allDataTypes) {
2593 String value = null;
2594 List<GetInputValueDataDefinition> getInputs = null;
2595 boolean isValidate = true;
2596 if (null != propertyInfo && propertyInfo.getValue() != null) {
2597 getInputs = propertyInfo.getGet_input();
2598 isValidate = getInputs == null || getInputs.isEmpty();
2600 value = getPropertyJsonStringValue(propertyInfo.getValue(), property.getType());
2602 value = getPropertyJsonStringValue(propertyInfo.getValue(), TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
2605 property.setValue(value);
2606 return serviceBusinessLogic.validatePropValueBeforeCreate(property, value, isValidate, allDataTypes);
2609 protected Resource getOriginResource(String yamlName, Map<String, Resource> originCompMap, ComponentInstance currentCompInstance) {
2610 Resource originResource;
2611 log.debug("after enter ServiceImportBusinessLogic processComponentInstance, enter getOriginResource");
2612 if (!originCompMap.containsKey(currentCompInstance.getComponentUid())) {
2613 Either<Resource, StorageOperationStatus> getOriginResourceRes = toscaOperationFacade
2614 .getToscaFullElement(currentCompInstance.getComponentUid());
2615 if (getOriginResourceRes.isRight()) {
2616 ResponseFormat responseFormat = componentsUtils
2617 .getResponseFormat(componentsUtils.convertFromStorageResponse(getOriginResourceRes.right().value()), yamlName);
2618 throw new ComponentException(responseFormat);
2620 originResource = getOriginResourceRes.left().value();
2621 originCompMap.put(originResource.getUniqueId(), originResource);
2623 originResource = originCompMap.get(currentCompInstance.getComponentUid());
2625 return originResource;
2628 protected Either<Resource, StorageOperationStatus> updateCalculatedCapReqWithSubstitutionMappings(Resource resource,
2629 Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
2630 Either<Resource, StorageOperationStatus> updateRes = null;
2631 Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities = new HashMap<>();
2632 Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements = new HashMap<>();
2633 StorageOperationStatus status = toscaOperationFacade.deleteAllCalculatedCapabilitiesRequirements(resource.getUniqueId());
2634 if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
2635 log.debug("Failed to delete all calculated capabilities and requirements of resource {} upon update. Status is {}",
2636 resource.getUniqueId(), status);
2637 updateRes = Either.right(status);
2639 if (updateRes == null) {
2640 fillUpdatedInstCapabilitiesRequirements(resource.getComponentInstances(), uploadResInstancesMap, updatedInstCapabilities,
2641 updatedInstRequirements);
2642 status = toscaOperationFacade.associateOrAddCalculatedCapReq(updatedInstCapabilities, updatedInstRequirements, resource);
2643 if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
2644 updateRes = Either.right(status);
2647 if (updateRes == null) {
2648 updateRes = Either.left(resource);
2653 protected void fillUpdatedInstCapabilitiesRequirements(List<ComponentInstance> componentInstances,
2654 Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
2655 Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities,
2656 Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements) {
2657 componentInstances.stream().forEach(i -> {
2658 fillUpdatedInstCapabilities(updatedInstCapabilities, i, uploadResInstancesMap.get(i.getName()).getCapabilitiesNamesToUpdate());
2659 fillUpdatedInstRequirements(updatedInstRequirements, i, uploadResInstancesMap.get(i.getName()).getRequirementsNamesToUpdate());
2663 protected void fillUpdatedInstCapabilities(Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilties,
2664 ComponentInstance instance, Map<String, String> capabilitiesNamesToUpdate) {
2665 Map<String, List<CapabilityDefinition>> updatedCapabilities = new HashMap<>();
2666 Set<String> updatedCapNames = new HashSet<>();
2667 if (MapUtils.isNotEmpty(capabilitiesNamesToUpdate)) {
2668 for (Map.Entry<String, List<CapabilityDefinition>> requirements : instance.getCapabilities().entrySet()) {
2669 updatedCapabilities.put(requirements.getKey(), requirements.getValue().stream().filter(
2670 c -> capabilitiesNamesToUpdate.containsKey(c.getName()) && !updatedCapNames.contains(capabilitiesNamesToUpdate.get(c.getName())))
2672 c.setParentName(c.getName());
2673 c.setName(capabilitiesNamesToUpdate.get(c.getName()));
2674 updatedCapNames.add(c.getName());
2676 }).collect(toList()));
2679 if (MapUtils.isNotEmpty(updatedCapabilities)) {
2680 updatedInstCapabilties.put(instance, updatedCapabilities);
2684 protected void fillUpdatedInstRequirements(Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements,
2685 ComponentInstance instance, Map<String, String> requirementsNamesToUpdate) {
2686 Map<String, List<RequirementDefinition>> updatedRequirements = new HashMap<>();
2687 Set<String> updatedReqNames = new HashSet<>();
2688 if (MapUtils.isNotEmpty(requirementsNamesToUpdate)) {
2689 for (Map.Entry<String, List<RequirementDefinition>> requirements : instance.getRequirements().entrySet()) {
2690 updatedRequirements.put(requirements.getKey(), requirements.getValue().stream().filter(
2691 r -> requirementsNamesToUpdate.containsKey(r.getName()) && !updatedReqNames.contains(requirementsNamesToUpdate.get(r.getName())))
2693 r.setParentName(r.getName());
2694 r.setName(requirementsNamesToUpdate.get(r.getName()));
2695 updatedReqNames.add(r.getName());
2697 }).collect(toList()));
2700 if (MapUtils.isNotEmpty(updatedRequirements)) {
2701 updatedInstRequirements.put(instance, updatedRequirements);
2705 protected void addRelationsToRI(String yamlName, Service service, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
2706 List<ComponentInstance> componentInstancesList, List<RequirementCapabilityRelDef> relations) {
2707 for (Map.Entry<String, UploadComponentInstanceInfo> entry : uploadResInstancesMap.entrySet()) {
2708 UploadComponentInstanceInfo uploadComponentInstanceInfo = entry.getValue();
2709 ComponentInstance currentCompInstance = null;
2710 for (ComponentInstance compInstance : componentInstancesList) {
2711 if (compInstance.getName().equals(uploadComponentInstanceInfo.getName())) {
2712 currentCompInstance = compInstance;
2716 if (currentCompInstance == null) {
2717 log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, uploadComponentInstanceInfo.getName(), service.getUniqueId());
2718 BeEcompErrorManager.getInstance()
2719 .logInternalDataError(COMPONENT_INSTANCE_WITH_NAME + uploadComponentInstanceInfo.getName() + IN_RESOURCE, service.getUniqueId(),
2720 BeEcompErrorManager.ErrorSeverity.ERROR);
2721 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
2722 throw new ComponentException(responseFormat);
2724 ResponseFormat addRelationToRiRes = addRelationToRI(yamlName, service, entry.getValue(), relations);
2725 if (addRelationToRiRes.getStatus() != 200) {
2726 throw new ComponentException(addRelationToRiRes);
2731 protected ResponseFormat addRelationToRI(String yamlName, Service service, UploadComponentInstanceInfo nodesInfoValue,
2732 List<RequirementCapabilityRelDef> relations) {
2733 List<ComponentInstance> componentInstancesList = service.getComponentInstances();
2734 ComponentInstance currentCompInstance = null;
2735 for (ComponentInstance compInstance : componentInstancesList) {
2736 if (compInstance.getName().equals(nodesInfoValue.getName())) {
2737 currentCompInstance = compInstance;
2741 if (currentCompInstance == null) {
2742 log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, nodesInfoValue.getName(), service.getUniqueId());
2743 BeEcompErrorManager.getInstance()
2744 .logInternalDataError(COMPONENT_INSTANCE_WITH_NAME + nodesInfoValue.getName() + IN_RESOURCE, service.getUniqueId(),
2745 BeEcompErrorManager.ErrorSeverity.ERROR);
2746 return componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
2748 String resourceInstanceId = currentCompInstance.getUniqueId();
2749 Map<String, List<UploadReqInfo>> regMap = nodesInfoValue.getRequirements();
2750 if (regMap != null) {
2751 Iterator<Map.Entry<String, List<UploadReqInfo>>> nodesRegValue = regMap.entrySet().iterator();
2752 while (nodesRegValue.hasNext()) {
2753 Map.Entry<String, List<UploadReqInfo>> nodesRegInfoEntry = nodesRegValue.next();
2754 List<UploadReqInfo> uploadRegInfoList = nodesRegInfoEntry.getValue();
2755 for (UploadReqInfo uploadRegInfo : uploadRegInfoList) {
2756 log.debug("Going to create relation {}", uploadRegInfo.getName());
2757 String regName = uploadRegInfo.getName();
2758 RequirementCapabilityRelDef regCapRelDef = new RequirementCapabilityRelDef();
2759 regCapRelDef.setFromNode(resourceInstanceId);
2760 log.debug("try to find available requirement {} ", regName);
2761 Either<RequirementDefinition, ResponseFormat> eitherReqStatus = serviceImportParseLogic
2762 .findAvailableRequirement(regName, yamlName, nodesInfoValue, currentCompInstance, uploadRegInfo.getCapabilityName());
2763 if (eitherReqStatus.isRight()) {
2764 log.debug("failed to find available requirement {} status is {}", regName, eitherReqStatus.right().value());
2765 return eitherReqStatus.right().value();
2767 RequirementDefinition validReq = eitherReqStatus.left().value();
2768 List<CapabilityRequirementRelationship> reqAndRelationshipPairList = regCapRelDef.getRelationships();
2769 if (reqAndRelationshipPairList == null) {
2770 reqAndRelationshipPairList = new ArrayList<>();
2772 RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
2773 reqAndRelationshipPair.setRequirement(regName);
2774 reqAndRelationshipPair.setRequirementOwnerId(validReq.getOwnerId());
2775 reqAndRelationshipPair.setRequirementUid(validReq.getUniqueId());
2776 RelationshipImpl relationship = new RelationshipImpl();
2777 relationship.setType(validReq.getCapability());
2778 reqAndRelationshipPair.setRelationships(relationship);
2779 ComponentInstance currentCapCompInstance = null;
2780 for (ComponentInstance compInstance : componentInstancesList) {
2781 if (compInstance.getName().equals(uploadRegInfo.getNode())) {
2782 currentCapCompInstance = compInstance;
2786 if (currentCapCompInstance == null) {
2787 log.debug("The component instance with name {} not found on resource {} ", uploadRegInfo.getNode(), service.getUniqueId());
2788 BeEcompErrorManager.getInstance()
2789 .logInternalDataError(COMPONENT_INSTANCE_WITH_NAME + uploadRegInfo.getNode() + IN_RESOURCE, service.getUniqueId(),
2790 BeEcompErrorManager.ErrorSeverity.ERROR);
2791 return componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
2793 regCapRelDef.setToNode(currentCapCompInstance.getUniqueId());
2794 log.debug("try to find aviable Capability req name is {} ", validReq.getName());
2795 CapabilityDefinition aviableCapForRel = serviceImportParseLogic
2796 .findAvailableCapabilityByTypeOrName(validReq, currentCapCompInstance, uploadRegInfo);
2797 if (aviableCapForRel == null) {
2798 BeEcompErrorManager.getInstance().logInternalDataError(
2799 "aviable capability was not found. req name is " + validReq.getName() + " component instance is " + currentCapCompInstance
2800 .getUniqueId(), service.getUniqueId(), BeEcompErrorManager.ErrorSeverity.ERROR);
2801 return componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
2803 reqAndRelationshipPair.setCapability(aviableCapForRel.getName());
2804 reqAndRelationshipPair.setCapabilityUid(aviableCapForRel.getUniqueId());
2805 reqAndRelationshipPair.setCapabilityOwnerId(aviableCapForRel.getOwnerId());
2806 CapabilityRequirementRelationship capReqRel = new CapabilityRequirementRelationship();
2807 capReqRel.setRelation(reqAndRelationshipPair);
2808 if (StringUtils.isNotEmpty(uploadRegInfo.getRelationshipTemplate())) {
2809 capReqRel.setOperations(getOperations(nodesInfoValue.getOperations(), uploadRegInfo.getRelationshipTemplate()));
2811 reqAndRelationshipPairList.add(capReqRel);
2812 regCapRelDef.setRelationships(reqAndRelationshipPairList);
2813 relations.add(regCapRelDef);
2817 return componentsUtils.getResponseFormat(ActionStatus.OK, yamlName);
2820 private List<OperationUi> getOperations(final Map<String, List<OperationUi>> operations, final String relationshipTemplate) {
2821 final List<OperationUi> operationUiList = new ArrayList<>();
2822 operations.forEach((operationKey, operationValues) -> {
2823 if (operationKey.equals(relationshipTemplate)) {
2824 operationUiList.addAll(operationValues);
2827 return operationUiList;
2830 protected Service getResourceAfterCreateRelations(Service service) {
2831 ComponentParametersView parametersView = serviceImportParseLogic.getComponentFilterAfterCreateRelations();
2832 Either<Service, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(service.getUniqueId(), parametersView);
2833 if (eitherGetResource.isRight()) {
2834 serviceImportParseLogic.throwComponentExceptionByResource(eitherGetResource.right().value(), service);
2836 return eitherGetResource.left().value();
2839 protected Service createServiceInstances(String yamlName, Service service, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
2840 Map<String, Resource> nodeNamespaceMap) {
2841 Either<Resource, ResponseFormat> eitherResource = null;
2842 log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName);
2843 if (MapUtils.isEmpty(uploadResInstancesMap)) { // PNF can have no resource instances
2844 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
2845 throw new ComponentException(responseFormat);
2847 Map<String, Resource> existingNodeTypeMap = new HashMap<>();
2848 if (MapUtils.isNotEmpty(nodeNamespaceMap)) {
2849 nodeNamespaceMap.forEach((k, v) -> existingNodeTypeMap.put(v.getToscaResourceName(), v));
2851 Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
2852 uploadResInstancesMap.values()
2853 .forEach(i -> createAndAddResourceInstance(i, yamlName, service, nodeNamespaceMap, existingNodeTypeMap, resourcesInstancesMap));
2854 if (MapUtils.isNotEmpty(resourcesInstancesMap)) {
2856 toscaOperationFacade.associateComponentInstancesToComponent(service, resourcesInstancesMap, false, false);
2857 } catch (StorageException exp) {
2858 if (exp.getStorageOperationStatus() != null && exp.getStorageOperationStatus() != StorageOperationStatus.OK) {
2859 log.debug("Failed to add component instances to container component {}", service.getName());
2860 ResponseFormat responseFormat = componentsUtils
2861 .getResponseFormat(componentsUtils.convertFromStorageResponse(exp.getStorageOperationStatus()));
2862 eitherResource = Either.right(responseFormat);
2863 throw new ComponentException(eitherResource.right().value());
2867 Either<Service, StorageOperationStatus> eitherGetResource = toscaOperationFacade
2868 .getToscaElement(service.getUniqueId(), serviceImportParseLogic.getComponentWithInstancesFilter());
2869 log.debug("*************finished to get resource {}", service.getUniqueId());
2870 if (eitherGetResource.isRight()) {
2871 ResponseFormat responseFormat = componentsUtils
2872 .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), service,
2873 ComponentTypeEnum.SERVICE);
2874 throw new ComponentException(responseFormat);
2876 if (CollectionUtils.isEmpty(eitherGetResource.left().value().getComponentInstances())) { // PNF can have no resource instances
2877 log.debug("Error when create resource instance from csar. ComponentInstances list empty");
2878 BeEcompErrorManager.getInstance().logBeDaoSystemError("Error when create resource instance from csar. ComponentInstances list empty");
2879 throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
2881 return eitherGetResource.left().value();
2884 protected void createAndAddResourceInstance(UploadComponentInstanceInfo uploadComponentInstanceInfo, String yamlName, Component component,
2885 Map<String, Resource> nodeNamespaceMap, Map<String, Resource> existingnodeTypeMap,
2886 Map<ComponentInstance, Resource> resourcesInstancesMap) {
2887 log.debug("*************Going to create resource instances {}", uploadComponentInstanceInfo.getName());
2889 if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
2890 uploadComponentInstanceInfo.setType(nodeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName());
2892 Resource refResource =
2893 validateResourceInstanceBeforeCreate(yamlName, component.getModel(), uploadComponentInstanceInfo, existingnodeTypeMap);
2894 ComponentInstance componentInstance = new ComponentInstance();
2895 componentInstance.setComponentUid(refResource.getUniqueId());
2896 Collection<String> directives = uploadComponentInstanceInfo.getDirectives();
2897 if (directives != null && !directives.isEmpty()) {
2898 componentInstance.setDirectives(new ArrayList<>(directives));
2900 UploadNodeFilterInfo uploadNodeFilterInfo = uploadComponentInstanceInfo.getUploadNodeFilterInfo();
2901 if (uploadNodeFilterInfo != null) {
2903 .setNodeFilter(new CINodeFilterUtils().getNodeFilterDataDefinition(uploadNodeFilterInfo, componentInstance.getUniqueId()));
2905 ComponentTypeEnum containerComponentType = component.getComponentType();
2906 NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
2907 if (containerNodeType.equals(NodeTypeEnum.Resource) && MapUtils.isNotEmpty(uploadComponentInstanceInfo.getCapabilities()) && MapUtils
2908 .isNotEmpty(refResource.getCapabilities())) {
2909 serviceImportParseLogic.setCapabilityNamesTypes(refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities());
2910 Map<String, List<CapabilityDefinition>> validComponentInstanceCapabilities = serviceImportParseLogic
2911 .getValidComponentInstanceCapabilities(refResource.getUniqueId(), refResource.getCapabilities(),
2912 uploadComponentInstanceInfo.getCapabilities());
2913 componentInstance.setCapabilities(validComponentInstanceCapabilities);
2915 if (!existingnodeTypeMap.containsKey(uploadComponentInstanceInfo.getType())) {
2916 ResponseFormat responseFormat = componentsUtils
2917 .getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(),
2918 uploadComponentInstanceInfo.getType());
2919 throw new ComponentException(responseFormat);
2921 Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType());
2922 componentInstance.setName(uploadComponentInstanceInfo.getName());
2923 componentInstance.setIcon(origResource.getIcon());
2924 componentInstance.setMinOccurrences(uploadComponentInstanceInfo.getMinOccurrences());
2925 componentInstance.setMaxOccurrences(uploadComponentInstanceInfo.getMaxOccurrences());
2926 componentInstance.setInstanceCount(uploadComponentInstanceInfo.getInstanceCount());
2927 resourcesInstancesMap.put(componentInstance, origResource);
2928 } catch (final ComponentException e) {
2930 } catch (final Exception e) {
2931 throw new ComponentException(ActionStatus.GENERAL_ERROR, e.getMessage());
2935 protected Resource validateResourceInstanceBeforeCreate(String yamlName, String model, UploadComponentInstanceInfo uploadComponentInstanceInfo,
2936 Map<String, Resource> nodeNamespaceMap) {
2937 Resource refResource;
2939 if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
2940 refResource = nodeNamespaceMap.get(uploadComponentInstanceInfo.getType());
2942 final Either<Component, StorageOperationStatus> resourceEither =
2943 toscaOperationFacade.getLatestByToscaResourceName(uploadComponentInstanceInfo.getType(), model);
2944 if (resourceEither.isRight()) {
2945 ResponseFormat responseFormat = componentsUtils
2946 .getResponseFormat(componentsUtils.convertFromStorageResponse(resourceEither.right().value()));
2947 throw new ComponentException(responseFormat);
2949 refResource = (Resource) resourceEither.left().value();
2950 nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
2952 String componentState = refResource.getComponentMetadataDefinition().getMetadataDataDefinition().getState();
2953 if (componentState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
2954 ResponseFormat responseFormat = componentsUtils
2955 .getResponseFormat(ActionStatus.ILLEGAL_COMPONENT_STATE, refResource.getComponentType().getValue(), refResource.getName(),
2957 throw new ComponentException(responseFormat);
2959 if (!ModelConverter.isAtomicComponent(refResource) && refResource.getResourceType() != ResourceTypeEnum.VF) {
2960 log.debug("validateResourceInstanceBeforeCreate - ref resource type is ", refResource.getResourceType());
2961 ResponseFormat responseFormat = componentsUtils
2962 .getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(),
2963 uploadComponentInstanceInfo.getType());
2964 throw new ComponentException(responseFormat);
2967 } catch (final ComponentException e) {
2969 } catch (final Exception e) {
2970 throw new ComponentException(ActionStatus.GENERAL_ERROR, e.getMessage());
2974 protected void handleServiceNodeTypes(String yamlName, Service service, String topologyTemplateYaml, boolean needLock,
2975 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
2976 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo,
2977 CsarInfo csarInfo, String nodeName) {
2979 for (Map.Entry<String, NodeTypeInfo> nodeTypeEntry : nodeTypesInfo.entrySet()) {
2980 boolean isResourceNotExisted = validateResourceNotExisted(nodeTypeEntry.getKey());
2981 if (nodeTypeEntry.getValue().isNested() && isResourceNotExisted) {
2982 handleNestedVF(service, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
2983 nodeTypeEntry.getKey());
2984 log.trace("************* finished to create node {}", nodeTypeEntry.getKey());
2987 Map<String, Object> mappedToscaTemplate = null;
2988 if (org.apache.commons.lang.StringUtils.isNotEmpty(nodeName) && MapUtils.isNotEmpty(nodeTypesInfo) && nodeTypesInfo
2989 .containsKey(nodeName)) {
2990 mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate();
2992 if (MapUtils.isEmpty(mappedToscaTemplate)) {
2993 mappedToscaTemplate = (Map<String, Object>) new Yaml().load(topologyTemplateYaml);
2995 createResourcesFromYamlNodeTypesList(yamlName, service, mappedToscaTemplate, needLock, nodeTypesArtifactsToHandle,
2996 nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo);
2997 } catch (ComponentException | StorageException e) {
2999 } catch (Exception e) {
3000 log.debug("Exception occured when handleServiceNodeTypes, error is:{}", e.getMessage(), e);
3001 throw new ComponentException(ActionStatus.GENERAL_ERROR);
3005 protected boolean validateResourceNotExisted(String type) {
3007 Either<Resource, StorageOperationStatus> latestResource = toscaOperationFacade.getLatestResourceByToscaResourceName(type);
3008 return latestResource.isRight();
3009 } catch (Exception e) {
3010 log.debug("Exception occured when validateResourceNotExisted, error is:{}", e.getMessage(), e);
3011 throw new ComponentException(ActionStatus.GENERAL_ERROR);
3015 protected Resource handleNestedVF(Service service,
3016 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
3017 List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
3020 String yamlName = nodesInfo.get(nodeName).getTemplateFileName();
3021 Map<String, Object> nestedVfcJsonMap = nodesInfo.get(nodeName).getMappedToscaTemplate();
3022 createResourcesFromYamlNodeTypesList(yamlName, service, nestedVfcJsonMap, false, nodesArtifactsToHandle, createdArtifacts, nodesInfo,
3024 log.debug("************* Finished to create node types from yaml {}", yamlName);
3025 if (nestedVfcJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE.getElementName())) {
3026 log.debug("************* Going to handle complex VFC from yaml {}", yamlName);
3027 return handleComplexVfc(nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName);
3029 return new Resource();
3030 } catch (Exception e) {
3031 log.debug("Exception occured when handleNestedVF, error is:{}", e.getMessage(), e);
3032 throw new ComponentException(ActionStatus.GENERAL_ERROR);
3036 protected Resource handleComplexVfc(
3037 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
3038 List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo, String nodeName, String yamlName) {
3040 Resource oldComplexVfc = null;
3041 Resource newComplexVfc = serviceImportParseLogic.buildValidComplexVfc(csarInfo, nodeName, nodesInfo);
3042 Either<Resource, StorageOperationStatus> oldComplexVfcRes = toscaOperationFacade
3043 .getFullLatestComponentByToscaResourceName(newComplexVfc.getToscaResourceName());
3044 if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() == StorageOperationStatus.NOT_FOUND) {
3045 oldComplexVfcRes = toscaOperationFacade.getFullLatestComponentByToscaResourceName(
3046 serviceImportParseLogic.buildNestedToscaResourceName(ResourceTypeEnum.VF.name(), csarInfo.getVfResourceName(), nodeName)
3049 if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() != StorageOperationStatus.NOT_FOUND) {
3050 log.debug("Failed to fetch previous complex VFC by tosca resource name {}. Status is {}. ", newComplexVfc.getToscaResourceName(),
3051 oldComplexVfcRes.right().value());
3052 throw new ComponentException(ActionStatus.GENERAL_ERROR);
3053 } else if (oldComplexVfcRes.isLeft()) {
3054 log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
3055 Either<Boolean, ResponseFormat> eitherValidation = serviceImportParseLogic
3056 .validateNestedDerivedFromDuringUpdate(oldComplexVfcRes.left().value(), newComplexVfc,
3057 ValidationUtils.hasBeenCertified(oldComplexVfcRes.left().value().getVersion()));
3058 if (eitherValidation.isLeft()) {
3059 oldComplexVfc = oldComplexVfcRes.left().value();
3062 newComplexVfc = handleComplexVfc(nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName, oldComplexVfc,
3064 csarInfo.getCreatedNodesToscaResourceNames().put(nodeName, newComplexVfc.getToscaResourceName());
3065 LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(CERTIFICATION_ON_IMPORT,
3066 LifecycleChangeInfoWithAction.LifecycleChanceActionEnum.CREATE_FROM_CSAR);
3067 log.debug("Going to certify cvfc {}. ", newComplexVfc.getName());
3068 final Resource result = serviceImportParseLogic
3069 .propagateStateToCertified(csarInfo.getModifier(), newComplexVfc, lifecycleChangeInfo, true, false, true);
3070 csarInfo.getCreatedNodes().put(nodeName, result);
3071 csarInfo.removeNodeFromQueue();
3073 } catch (Exception e) {
3074 log.debug("Exception occured when handleComplexVfc, error is:{}", e.getMessage(), e);
3075 throw new ComponentException(ActionStatus.GENERAL_ERROR);
3079 protected Resource handleComplexVfc(
3080 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
3081 List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo, String nodeName, String yamlName,
3082 Resource oldComplexVfc, Resource newComplexVfc) {
3083 Resource handleComplexVfcRes;
3085 Map<String, Object> mappedToscaTemplate = nodesInfo.get(nodeName).getMappedToscaTemplate();
3086 String yamlContent = new String(csarInfo.getCsar().get(yamlName));
3087 Map<String, NodeTypeInfo> newNodeTypesInfo = nodesInfo.entrySet().stream()
3088 .collect(toMap(Map.Entry::getKey, e -> e.getValue().getUnmarkedCopy()));
3089 CsarInfo.markNestedVfc(mappedToscaTemplate, newNodeTypesInfo);
3090 if (oldComplexVfc == null) {
3091 handleComplexVfcRes = createResourceFromYaml(newComplexVfc, yamlContent, yamlName, newNodeTypesInfo, csarInfo, nodesArtifactsToHandle,
3092 false, true, nodeName);
3094 handleComplexVfcRes = updateResourceFromYaml(oldComplexVfc, newComplexVfc, AuditingActionEnum.UPDATE_RESOURCE_METADATA,
3095 createdArtifacts, yamlContent, yamlName, csarInfo, newNodeTypesInfo, nodesArtifactsToHandle, nodeName, true);
3097 return handleComplexVfcRes;
3098 } catch (Exception e) {
3099 log.debug("Exception occured when handleComplexVfc, error is:{}", e.getMessage(), e);
3100 throw new ComponentException(ActionStatus.GENERAL_ERROR);
3104 protected Resource updateResourceFromYaml(Resource oldRresource, Resource newRresource, AuditingActionEnum actionEnum,
3105 List<ArtifactDefinition> createdArtifacts, String yamlFileName, String yamlFileContent,
3106 CsarInfo csarInfo, Map<String, NodeTypeInfo> nodeTypesInfo,
3107 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
3108 String nodeName, boolean isNested) {
3109 boolean inTransaction = true;
3110 boolean shouldLock = false;
3111 Resource preparedResource = null;
3112 ParsedToscaYamlInfo uploadComponentInstanceInfoMap = null;
3114 uploadComponentInstanceInfoMap = csarBusinessLogic
3115 .getParsedToscaYamlInfo(yamlFileContent, yamlFileName, nodeTypesInfo, csarInfo, nodeName, oldRresource);
3116 Map<String, UploadComponentInstanceInfo> instances = uploadComponentInstanceInfoMap.getInstances();
3117 if (MapUtils.isEmpty(instances) && newRresource.getResourceType() != ResourceTypeEnum.PNF) {
3118 throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlFileName);
3120 preparedResource = updateExistingResourceByImport(newRresource, oldRresource, csarInfo.getModifier(), inTransaction, shouldLock,
3122 log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContent);
3123 serviceImportParseLogic.handleResourceGenericType(preparedResource);
3124 handleNodeTypes(yamlFileName, preparedResource, yamlFileContent, shouldLock, nodeTypesArtifactsToHandle, createdArtifacts, nodeTypesInfo,
3125 csarInfo, nodeName);
3126 preparedResource = serviceImportParseLogic.createInputsOnResource(preparedResource, uploadComponentInstanceInfoMap.getInputs());
3127 preparedResource = createResourceInstances(yamlFileName, preparedResource, instances, csarInfo.getCreatedNodes());
3128 preparedResource = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, instances);
3129 } catch (ComponentException e) {
3130 ResponseFormat responseFormat =
3131 e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
3132 log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat);
3134 .auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum);
3136 } catch (StorageException e) {
3137 ResponseFormat responseFormat = componentsUtils
3138 .getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
3139 log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat);
3141 .auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum);
3144 Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNames(
3145 uploadComponentInstanceInfoMap.getGroups(), preparedResource.getSystemName());
3146 if (validateUpdateVfGroupNamesRes.isRight()) {
3147 throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
3149 Map<String, GroupDefinition> groups;
3150 if (!validateUpdateVfGroupNamesRes.left().value().isEmpty()) {
3151 groups = validateUpdateVfGroupNamesRes.left().value();
3153 groups = uploadComponentInstanceInfoMap.getGroups();
3155 serviceImportParseLogic.handleGroupsProperties(preparedResource, groups);
3156 preparedResource = serviceImportParseLogic.updateGroupsOnResource(preparedResource, groups);
3157 NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToHandle);
3158 Either<Resource, ResponseFormat> updateArtifactsEither = createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE,
3159 createdArtifacts, yamlFileName, csarInfo, preparedResource, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock);
3160 if (updateArtifactsEither.isRight()) {
3161 log.debug("failed to update artifacts {}", updateArtifactsEither.right().value());
3162 throw new ComponentException(updateArtifactsEither.right().value());
3164 preparedResource = serviceImportParseLogic.getResourceWithGroups(updateArtifactsEither.left().value().getUniqueId());
3165 ActionStatus mergingPropsAndInputsStatus = resourceDataMergeBusinessLogic.mergeResourceEntities(oldRresource, preparedResource);
3166 if (mergingPropsAndInputsStatus != ActionStatus.OK) {
3167 ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(mergingPropsAndInputsStatus, preparedResource);
3168 throw new ComponentException(responseFormat);
3170 compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, csarInfo.getModifier().getUserId());
3171 return preparedResource;
3174 protected Resource createResourceFromYaml(Resource resource, String topologyTemplateYaml, String yamlName,
3175 Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
3176 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
3177 boolean shouldLock, boolean inTransaction, String nodeName) {
3178 List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
3179 Resource createdResource;
3181 ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic
3182 .getParsedToscaYamlInfo(topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, nodeName, resource);
3183 if (MapUtils.isEmpty(parsedToscaYamlInfo.getInstances()) && resource.getResourceType() != ResourceTypeEnum.PNF) {
3184 throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
3186 log.debug("#createResourceFromYaml - Going to create resource {} and RIs ", resource.getName());
3187 createdResource = createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo, AuditingActionEnum.IMPORT_RESOURCE, false,
3188 createdArtifacts, topologyTemplateYaml, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName);
3189 log.debug("#createResourceFromYaml - The resource {} has been created ", resource.getName());
3190 } catch (ComponentException e) {
3191 ResponseFormat responseFormat =
3192 e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
3193 componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
3195 } catch (StorageException e) {
3196 ResponseFormat responseFormat = componentsUtils
3197 .getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
3198 componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
3201 return createdResource;
3204 protected Resource createResourceAndRIsFromYaml(String yamlName, Resource resource, ParsedToscaYamlInfo parsedToscaYamlInfo,
3205 AuditingActionEnum actionEnum, boolean isNormative, List<ArtifactDefinition> createdArtifacts,
3206 String topologyTemplateYaml, Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
3207 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
3208 boolean shouldLock, boolean inTransaction, String nodeName) {
3209 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
3211 Either<Boolean, ResponseFormat> lockResult = serviceBusinessLogic
3212 .lockComponentByName(resource.getSystemName(), resource, CREATE_RESOURCE);
3213 if (lockResult.isRight()) {
3214 serviceImportParseLogic.rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
3215 throw new ComponentException(lockResult.right().value());
3217 log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
3220 log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
3221 Resource genericResource = serviceBusinessLogic.fetchAndSetDerivedFromGenericType(resource);
3222 resource = createResourceTransaction(resource, csarInfo.getModifier(), isNormative);
3223 log.trace("************* Going to add inputs from yaml {}", yamlName);
3224 Map<String, Object> yamlMap = ImportUtils.loadYamlAsStrictMap(csarInfo.getMainTemplateContent());
3225 Map<String, Object> metadata = (Map<String, Object>) yamlMap.get("metadata");
3226 String type = (String) metadata.get("type");
3227 if (resource.shouldGenerateInputs() && !"Service".equalsIgnoreCase(type)) {
3228 serviceBusinessLogic.generateAndAddInputsFromGenericTypeProperties(resource, genericResource);
3230 Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
3231 resource = serviceImportParseLogic.createInputsOnResource(resource, inputs);
3232 Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances();
3233 resource = createRIAndRelationsFromYaml(yamlName, resource, uploadComponentInstanceInfoMap, topologyTemplateYaml,
3234 nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName);
3235 log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
3236 // validate update vf module group names
3237 Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNames(
3238 parsedToscaYamlInfo.getGroups(), resource.getSystemName());
3239 if (validateUpdateVfGroupNamesRes.isRight()) {
3240 serviceImportParseLogic.rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
3241 throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
3243 Map<String, GroupDefinition> groups;
3244 log.trace("************* Going to add groups from yaml {}", yamlName);
3245 if (!validateUpdateVfGroupNamesRes.left().value().isEmpty()) {
3246 groups = validateUpdateVfGroupNamesRes.left().value();
3248 groups = parsedToscaYamlInfo.getGroups();
3250 Either<Resource, ResponseFormat> createGroupsOnResource = createGroupsOnResource(resource, groups);
3251 if (createGroupsOnResource.isRight()) {
3252 serviceImportParseLogic.rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
3253 throw new ComponentException(createGroupsOnResource.right().value());
3255 resource = createGroupsOnResource.left().value();
3256 log.trace("************* Going to add artifacts from yaml {}", yamlName);
3257 NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToCreate);
3258 Either<Resource, ResponseFormat> createArtifactsEither = createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,
3259 createdArtifacts, yamlName, csarInfo, resource, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock);
3260 if (createArtifactsEither.isRight()) {
3261 serviceImportParseLogic.rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
3262 throw new ComponentException(createArtifactsEither.right().value());
3264 resource = serviceImportParseLogic.getResourceWithGroups(createArtifactsEither.left().value().getUniqueId());
3265 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
3266 componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, actionEnum);
3267 ASDCKpiApi.countCreatedResourcesKPI();
3269 } catch (ComponentException | StorageException e) {
3270 serviceImportParseLogic.rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
3273 if (!inTransaction) {
3274 janusGraphDao.commit();
3277 graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(), NodeTypeEnum.Resource);
3282 protected Either<Resource, ResponseFormat> createGroupsOnResource(Resource resource, Map<String, GroupDefinition> groups) {
3283 if (groups != null && !groups.isEmpty()) {
3284 List<GroupDefinition> groupsAsList = updateGroupsMembersUsingResource(groups, resource);
3285 serviceImportParseLogic.handleGroupsProperties(resource, groups);
3286 serviceImportParseLogic.fillGroupsFinalFields(groupsAsList);
3287 Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.createGroups(resource, groupsAsList, true);
3288 if (createGroups.isRight()) {
3289 return Either.right(createGroups.right().value());
3292 return Either.left(resource);
3294 Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade.getToscaElement(resource.getUniqueId());
3295 if (updatedResource.isRight()) {
3296 ResponseFormat responseFormat = componentsUtils
3297 .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource);
3298 return Either.right(responseFormat);
3300 return Either.left(updatedResource.left().value());
3303 protected List<GroupDefinition> updateGroupsMembersUsingResource(Map<String, GroupDefinition> groups, Resource component) {
3304 List<GroupDefinition> result = new ArrayList<>();
3305 List<ComponentInstance> componentInstances = component.getComponentInstances();
3306 if (groups != null) {
3307 for (Map.Entry<String, GroupDefinition> entry : groups.entrySet()) {
3308 String groupName = entry.getKey();
3309 GroupDefinition groupDefinition = entry.getValue();
3310 GroupDefinition updatedGroupDefinition = new GroupDefinition(groupDefinition);
3311 updatedGroupDefinition.setMembers(null);
3312 Map<String, String> members = groupDefinition.getMembers();
3313 if (members != null) {
3314 updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
3316 result.add(updatedGroupDefinition);
3322 protected void updateGroupMembers(Map<String, GroupDefinition> groups, GroupDefinition updatedGroupDefinition, Resource component,
3323 List<ComponentInstance> componentInstances, String groupName, Map<String, String> members) {
3324 Set<String> compInstancesNames = members.keySet();
3325 if (CollectionUtils.isEmpty(componentInstances)) {
3326 String membersAstString = compInstancesNames.stream().collect(joining(","));
3327 log.debug("The members: {}, in group: {}, cannot be found in component {}. There are no component instances.", membersAstString,
3328 groupName, component.getNormalizedName());
3329 throw new ComponentException(componentsUtils
3330 .getResponseFormat(ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName, component.getNormalizedName(),
3331 serviceImportParseLogic.getComponentTypeForResponse(component)));
3333 Map<String, String> memberNames = componentInstances.stream().collect(toMap(ComponentInstance::getName, ComponentInstance::getUniqueId));
3334 memberNames.putAll(groups.keySet().stream().collect(toMap(g -> g, g -> "")));
3335 Map<String, String> relevantInstances = memberNames.entrySet().stream().filter(n -> compInstancesNames.contains(n.getKey()))
3336 .collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
3337 if (relevantInstances == null || relevantInstances.size() != compInstancesNames.size()) {
3338 List<String> foundMembers = new ArrayList<>();
3339 if (relevantInstances != null) {
3340 foundMembers = relevantInstances.keySet().stream().collect(toList());
3342 compInstancesNames.removeAll(foundMembers);
3343 String membersAstString = compInstancesNames.stream().collect(joining(","));
3344 throw new ComponentException(componentsUtils
3345 .getResponseFormat(ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName, component.getNormalizedName(),
3346 serviceImportParseLogic.getComponentTypeForResponse(component)));
3348 updatedGroupDefinition.setMembers(relevantInstances);
3351 protected Resource createResourceTransaction(Resource resource, User user, boolean isNormative) {
3352 Either<Boolean, StorageOperationStatus> eitherValidation = toscaOperationFacade
3353 .validateComponentNameExists(resource.getName(), resource.getResourceType(), resource.getComponentType());
3354 if (eitherValidation.isRight()) {
3355 ResponseFormat errorResponse = componentsUtils
3356 .getResponseFormat(componentsUtils.convertFromStorageResponse(eitherValidation.right().value()));
3357 throw new ComponentException(errorResponse);
3359 if (Boolean.TRUE.equals(eitherValidation.left().value())) {
3360 log.debug("resource with name: {}, already exists", resource.getName());
3361 ResponseFormat errorResponse = componentsUtils
3362 .getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
3363 throw new ComponentException(errorResponse);
3365 log.debug("send resource {} to dao for create", resource.getName());
3366 serviceImportParseLogic.createArtifactsPlaceHolderData(resource, user);
3368 log.debug("enrich resource with creator, version and state");
3369 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
3370 resource.setVersion(INITIAL_VERSION);
3371 resource.setHighestVersion(true);
3372 if (resource.getResourceType() != null && resource.getResourceType() != ResourceTypeEnum.VF) {
3373 resource.setAbstract(false);
3376 return toscaOperationFacade.createToscaComponent(resource).left()
3377 .on(r -> serviceImportParseLogic.throwComponentExceptionByResource(r, resource));
3380 protected ImmutablePair<Resource, ActionStatus> updateExistingResourceByImport(Resource newResource, Resource oldResource, User user,
3381 boolean inTransaction, boolean needLock, boolean isNested) {
3382 String lockedResourceId = oldResource.getUniqueId();
3383 log.debug("found resource: name={}, id={}, version={}, state={}", oldResource.getName(), lockedResourceId, oldResource.getVersion(),
3384 oldResource.getLifecycleState());
3385 ImmutablePair<Resource, ActionStatus> resourcePair = null;
3387 serviceBusinessLogic.lockComponent(lockedResourceId, oldResource, needLock, "Update Resource by Import");
3388 oldResource = serviceImportParseLogic.prepareResourceForUpdate(oldResource, newResource, user, inTransaction, false);
3389 serviceImportParseLogic.mergeOldResourceMetadataWithNew(oldResource, newResource);
3390 serviceImportParseLogic.validateResourceFieldsBeforeUpdate(oldResource, newResource, inTransaction, isNested);
3391 serviceImportParseLogic.validateCapabilityTypesCreate(user, serviceImportParseLogic.getCapabilityTypeOperation(), newResource,
3392 AuditingActionEnum.IMPORT_RESOURCE, inTransaction);
3393 createNewResourceToOldResource(newResource, oldResource, user);
3394 Either<Resource, StorageOperationStatus> overrideResource = toscaOperationFacade.overrideComponent(newResource, oldResource);
3395 if (overrideResource.isRight()) {
3396 ResponseFormat responseFormat = new ResponseFormat();
3397 serviceBusinessLogic.throwComponentException(responseFormat);
3399 log.debug("Resource updated successfully!!!");
3400 resourcePair = new ImmutablePair<>(overrideResource.left().value(), ActionStatus.OK);
3401 return resourcePair;
3403 if (resourcePair == null) {
3404 BeEcompErrorManager.getInstance().logBeSystemError("Change LifecycleState - Certify");
3405 janusGraphDao.rollback();
3406 } else if (!inTransaction) {
3407 janusGraphDao.commit();
3410 log.debug("unlock resource {}", lockedResourceId);
3411 graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
3416 protected void createNewResourceToOldResource(Resource newResource, Resource oldResource, User user) {
3417 newResource.setContactId(newResource.getContactId().toLowerCase());
3418 newResource.setCreatorUserId(user.getUserId());
3419 newResource.setCreatorFullName(user.getFullName());
3420 newResource.setLastUpdaterUserId(user.getUserId());
3421 newResource.setLastUpdaterFullName(user.getFullName());
3422 newResource.setUniqueId(oldResource.getUniqueId());
3423 newResource.setVersion(oldResource.getVersion());
3424 newResource.setInvariantUUID(oldResource.getInvariantUUID());
3425 newResource.setLifecycleState(oldResource.getLifecycleState());
3426 newResource.setUUID(oldResource.getUUID());
3427 newResource.setNormalizedName(oldResource.getNormalizedName());
3428 newResource.setSystemName(oldResource.getSystemName());
3429 if (oldResource.getCsarUUID() != null) {
3430 newResource.setCsarUUID(oldResource.getCsarUUID());
3432 if (oldResource.getCsarVersionId() != null) {
3433 newResource.setCsarVersionId(oldResource.getCsarVersionId());
3435 if (oldResource.getImportedToscaChecksum() != null) {
3436 newResource.setImportedToscaChecksum(oldResource.getImportedToscaChecksum());
3438 if (newResource.getDerivedFromGenericType() == null || newResource.getDerivedFromGenericType().isEmpty()) {
3439 newResource.setDerivedFromGenericType(oldResource.getDerivedFromGenericType());
3441 if (newResource.getDerivedFromGenericVersion() == null || newResource.getDerivedFromGenericVersion().isEmpty()) {
3442 newResource.setDerivedFromGenericVersion(oldResource.getDerivedFromGenericVersion());
3444 if (newResource.getToscaArtifacts() == null || newResource.getToscaArtifacts().isEmpty()) {
3445 serviceBusinessLogic.setToscaArtifactsPlaceHolders(newResource, user);
3447 if (newResource.getInterfaces() == null || newResource.getInterfaces().isEmpty()) {
3448 newResource.setInterfaces(oldResource.getInterfaces());
3450 if (CollectionUtils.isEmpty(newResource.getProperties())) {
3451 newResource.setProperties(oldResource.getProperties());
3453 if (newResource.getModel() == null) {
3454 newResource.setModel(oldResource.getModel());
3458 protected Map<String, Resource> createResourcesFromYamlNodeTypesList(String yamlName, Service service, Map<String, Object> mappedToscaTemplate,
3460 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
3461 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
3462 Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo) {
3464 Either<String, ImportUtils.ResultStatusEnum> toscaVersion = findFirstToscaStringElement(mappedToscaTemplate,
3465 TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION);
3466 if (toscaVersion.isRight()) {
3467 throw new ComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE);
3469 Map<String, Object> mapToConvert = new HashMap<>();
3470 mapToConvert.put(TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), toscaVersion.left().value());
3471 Map<String, Object> nodeTypes = serviceImportParseLogic.getNodeTypesFromTemplate(mappedToscaTemplate);
3472 createNodeTypes(yamlName, service, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
3473 mapToConvert, nodeTypes);
3474 return csarInfo.getCreatedNodes();
3475 } catch (Exception e) {
3476 log.debug("Exception occured when createResourcesFromYamlNodeTypesList,error is:{}", e.getMessage(), e);
3477 throw new ComponentException(ActionStatus.GENERAL_ERROR);
3481 protected void createNodeTypes(String yamlName, Service service, boolean needLock,
3482 Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
3483 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
3484 Map<String, Object> mapToConvert, Map<String, Object> nodeTypes) {
3485 Iterator<Map.Entry<String, Object>> nodesNameValueIter = nodeTypes.entrySet().iterator();
3486 Resource vfcCreated = null;
3487 while (nodesNameValueIter.hasNext()) {
3488 Map.Entry<String, Object> nodeType = nodesNameValueIter.next();
3489 String nodeTypeKey = nodeType.getKey();
3490 Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle =
3491 nodeTypesArtifactsToHandle == null || nodeTypesArtifactsToHandle.isEmpty() ? null : nodeTypesArtifactsToHandle.get(nodeTypeKey);
3492 if (nodeTypesInfo.containsKey(nodeTypeKey)) {
3493 vfcCreated = handleNestedVfc(service, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
3495 log.trace("************* Finished to handle nested vfc {}", nodeTypeKey);
3496 } else if (csarInfo.getCreatedNodesToscaResourceNames() != null && !csarInfo.getCreatedNodesToscaResourceNames()
3497 .containsKey(nodeTypeKey)) {
3498 ImmutablePair<Resource, ActionStatus> resourceCreated = serviceImportParseLogic
3499 .createNodeTypeResourceFromYaml(yamlName, nodeType, csarInfo.getModifier(), mapToConvert, service, needLock,
3500 nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, true, csarInfo, true);
3501 log.debug("************* Finished to create node {}", nodeTypeKey);
3502 vfcCreated = resourceCreated.getLeft();
3503 csarInfo.getCreatedNodesToscaResourceNames().put(nodeTypeKey, vfcCreated.getName());
3505 if (vfcCreated != null) {
3506 csarInfo.getCreatedNodes().put(nodeTypeKey, vfcCreated);
3508 mapToConvert.remove(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName());