* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.openecomp.sdc.be.components.impl;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+import static org.openecomp.sdc.be.components.impl.CsarValidationUtils.TOSCA_METADATA_PATH_PATTERN;
+import static org.openecomp.sdc.be.components.impl.CsarValidationUtils.TOSCA_META_ENTRY_DEFINITIONS;
import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaMapElement;
import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement;
import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import fj.data.Either;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.json.simple.JSONObject;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.common.zip.ZipUtils;
+import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.yaml.snakeyaml.Yaml;
private final IGraphLockOperation graphLockOperation;
private final ToscaFunctionService toscaFunctionService;
private final DataTypeBusinessLogic dataTypeBusinessLogic;
- private ApplicationDataTypeCache applicationDataTypeCache;
private final ArtifactTypeOperation artifactTypeOperation;
-
private final GroupTypeImportManager groupTypeImportManager;
private final GroupTypeOperation groupTypeOperation;
- private InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
- private InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
-
private final CapabilityTypeImportManager capabilityTypeImportManager;
private final CapabilityTypeOperation capabilityTypeOperation;
+ private ApplicationDataTypeCache applicationDataTypeCache;
+ private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
+ private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
+ private final ModelOperation modelOperation;
public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic,
final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade,
final InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager,
final CapabilityTypeImportManager capabilityTypeImportManager,
- final CapabilityTypeOperation capabilityTypeOperation) {
+ final CapabilityTypeOperation capabilityTypeOperation,
+ final ModelOperation modelOperation) {
this.componentsUtils = componentsUtils;
this.toscaOperationFacade = toscaOperationFacade;
this.serviceBusinessLogic = serviceBusinessLogic;
this.interfaceLifecycleTypeImportManager = interfaceLifecycleTypeImportManager;
this.capabilityTypeImportManager = capabilityTypeImportManager;
this.capabilityTypeOperation = capabilityTypeOperation;
+ this.modelOperation = modelOperation;
}
@Autowired
this.applicationDataTypeCache = applicationDataTypeCache;
}
+ public Service updateServiceFromToscaTemplate(final String serviceId, final User modifier, final String data) {
+ final Either<Service, ResponseFormat> serviceResponseFormatEither = serviceBusinessLogic.getService(serviceId, modifier);
+ if (serviceResponseFormatEither.isRight()) {
+ throw new ByActionStatusComponentException(ActionStatus.SERVICE_NOT_FOUND, serviceId);
+ }
+ final Service serviceOriginal = serviceResponseFormatEither.left().value();
+ final Map<String, String> metadata = (Map<String, String>) new Yaml().loadAs(data, Map.class).get("metadata");
+ validateServiceMetadataBeforeCreate(serviceOriginal, metadata);
+
+ final Service newService = cloneServiceIdentifications(serviceOriginal);
+ final Map<String, byte[]> payload = new HashMap<>();
+ payload.put("Definitions/service-" + metadata.get("name") + "-template.yml", data.getBytes());
+ updateServiceMetadata(newService, metadata);
+ return createService(newService, AuditingActionEnum.UPDATE_SERVICE_TOSCA_TEMPLATE, modifier, payload, null);
+ }
+
+ public Service updateServiceFromToscaModel(final String serviceId, final User modifier, final @NotNull InputStream fileToUpload) {
+ final Either<Service, ResponseFormat> serviceResponseFormatEither = serviceBusinessLogic.getService(serviceId, modifier);
+ if (serviceResponseFormatEither.isRight()) {
+ throw new ByActionStatusComponentException(ActionStatus.SERVICE_NOT_FOUND, serviceId);
+ }
+ final Service serviceOriginal = serviceResponseFormatEither.left().value();
+ Map<String, byte[]> csar = null;
+ try {
+ csar = ZipUtils.readZip(fileToUpload.readAllBytes(), false);
+ } catch (final ZipException | IOException e) {
+ log.info("Failed to unzip received csar {}", serviceId, e);
+ }
+ if (csar == null) {
+ throw new ByActionStatusComponentException(ActionStatus.CSAR_NOT_FOUND);
+ }
+ final byte[] mainYamlBytes = readMainYamlFile(csar);
+ final Map<String, String> metadata = (Map<String, String>) new Yaml().loadAs(new String(mainYamlBytes), Map.class).get("metadata");
+ validateServiceMetadataBeforeCreate(serviceOriginal, metadata);
+ final Service newService = cloneServiceIdentifications(serviceOriginal);
+ updateServiceMetadata(newService, metadata);
+ return createService(newService, AuditingActionEnum.UPDATE_SERVICE_TOSCA_MODEL, modifier, csar, null);
+ }
+
+ private byte[] readMainYamlFile(final Map<String, byte[]> csar) {
+ final Pattern pattern = Pattern.compile(TOSCA_METADATA_PATH_PATTERN);
+ final Optional<String> keyOp = csar.keySet().stream().filter(k -> pattern.matcher(k).matches()).findAny();
+ if (keyOp.isEmpty()) {
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, TOSCA_METADATA_PATH_PATTERN, "");
+ }
+ final Properties props = new Properties();
+ try {
+ final String propStr = new String(csar.get(keyOp.get()));
+ props.load(new StringReader(propStr.replace("\\", "\\\\")));
+ } catch (IOException e) {
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, TOSCA_META_ENTRY_DEFINITIONS, "");
+ }
+ final String mainYamlFileName = props.getProperty(TOSCA_META_ENTRY_DEFINITIONS);
+ final byte[] mainYamlBytes = csar.get(mainYamlFileName);
+ if (mainYamlBytes == null) {
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, mainYamlFileName, "");
+ }
+ return mainYamlBytes;
+ }
+
+ private Service cloneServiceIdentifications(final Service serviceOriginal) {
+ final Service newService = new Service(serviceOriginal.getComponentMetadataDefinition());
+ newService.setCategories(serviceOriginal.getCategories());
+ newService.setInvariantUUID(serviceOriginal.getInvariantUUID());
+ newService.setUniqueId(serviceOriginal.getUniqueId());
+ newService.setName(serviceOriginal.getName());
+ newService.setUUID(serviceOriginal.getUUID());
+ return newService;
+ }
+
+ private void validateServiceMetadataBeforeCreate(final Service service, final Map<String, String> metadata) {
+ if (MapUtils.isEmpty(metadata)) {
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_SERVICE_METADATA);
+ }
+ final String uuid = metadata.get("UUID");
+ if (!service.getUUID().equals(uuid)) {
+ throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "UUID");
+ }
+ final String invariantUUID = metadata.get("invariantUUID");
+ if (!service.getInvariantUUID().equals(invariantUUID)) {
+ throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "invariantUUID");
+ }
+ final String name = metadata.get("name");
+ if (!service.getName().equals(name)) {
+ throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "name");
+ }
+ final String version = metadata.get("template_version");
+ if (!service.getVersion().equals(version)) {
+ throw new ByActionStatusComponentException(ActionStatus.UNCHANGEABLE_PROPERTY_ERROR, "template_version");
+ }
+ }
+
public Service createService(Service service, AuditingActionEnum auditingAction, User user, Map<String, byte[]> csarUIPayload,
String payloadName) {
log.debug("enter createService");
- service.setCreatorUserId(user.getUserId());
- service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- service.setVersion(INITIAL_VERSION);
- service.setConformanceLevel(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel());
- service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
+ if (AuditingActionEnum.CREATE_SERVICE.equals(auditingAction)) {
+ service.setCreatorUserId(user.getUserId());
+ service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ service.setVersion(INITIAL_VERSION);
+ service.setConformanceLevel(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel());
+ service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
+ }
try {
final var serviceBeforeCreate = serviceBusinessLogic.validateServiceBeforeCreate(service, user, auditingAction);
if (serviceBeforeCreate.isRight()) {
}
log.debug("enter createService,validateServiceBeforeCreate success");
String csarUUID = payloadName == null ? service.getCsarUUID() : payloadName;
- log.debug("enter createService,get csarUUID:{}", csarUUID);
- csarBusinessLogic.validateCsarBeforeCreate(service, csarUUID);
+ if (AuditingActionEnum.CREATE_SERVICE.equals(auditingAction)) {
+ log.debug("enter createService,get csarUUID:{}", csarUUID);
+ csarBusinessLogic.validateCsarBeforeCreate(service, csarUUID);
+ }
log.debug("CsarUUID is {} - going to create resource from CSAR", csarUUID);
- return createServiceFromCsar(service, user, csarUIPayload, csarUUID);
+ return createServiceFromCsar(service, user, csarUIPayload, csarUUID, auditingAction);
} catch (final ComponentException e) {
log.debug("Exception occurred when createService: {}", e.getMessage(), e);
throw e;
}
}
- protected Service createServiceFromCsar(Service service, User user, Map<String, byte[]> csarUIPayload, String csarUUID) {
+ private void updateServiceMetadata(final Service service, final Map<String, String> metadata) {
+ metadata.entrySet().forEach(s -> {
+ final Optional<Method> find =
+ Arrays.stream(service.getClass().getMethods()).filter(method -> method.getName().equalsIgnoreCase("set" + s.getKey())).findAny();
+ if (find.isPresent()) {
+ try {
+ find.get().invoke(service, s.getValue());
+ } catch (final Exception e) {
+ log.warn("Unable to set '{}' with value '{}'", s.getKey(), s.getValue());
+ }
+ }
+ });
+ }
+
+ protected Service createServiceFromCsar(Service service, User user, Map<String, byte[]> csarUIPayload, String csarUUID,
+ AuditingActionEnum auditingAction) {
log.trace("************* created successfully from YAML, resource TOSCA ");
try {
- final ServiceCsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID);
+ final ServiceCsarInfo csarInfo;
+ if (AuditingActionEnum.UPDATE_SERVICE_TOSCA_TEMPLATE.equals(auditingAction)) {
+ csarInfo = new ServiceCsarInfo(user, csarUUID, csarUIPayload, service.getName(), service.getModel(),
+ csarUIPayload.keySet().iterator().next(), new String(csarUIPayload.values().iterator().next()), true, modelOperation);
+ } else {
+ csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID, auditingAction);
+ }
final String serviceModel = service.getModel();
final Map<String, Object> dataTypesToCreate = getDatatypesToCreate(serviceModel, csarInfo);
if (MapUtils.isNotEmpty(dataTypesToCreate)) {
final List<NodeTypeDefinition> nodeTypesToCreate = getNodeTypesToCreate(serviceModel, csarInfo);
if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) {
- createNodeTypes(nodeTypesToCreate, serviceModel, csarInfo.getModifier());
+ ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic.getParsedToscaYamlInfo(csarInfo, service);
+ createNodeTypes(nodeTypesToCreate, parsedToscaYamlInfo.getInstances(), serviceModel, csarInfo.getModifier());
}
final Map<String, Object> groupTypesToCreate = getGroupTypesToCreate(serviceModel, csarInfo);
}
final Map<String, Object> capabilityTypesToCreate = getCapabilityTypesToCreate(serviceModel, csarInfo);
-
if (MapUtils.isNotEmpty(capabilityTypesToCreate)) {
capabilityTypeImportManager.createCapabilityTypes(new Yaml().dump(capabilityTypesToCreate), serviceModel, true);
}
throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value());
}
return createServiceFromYaml(service, csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(), nodeTypesInfo, csarInfo,
- findNodeTypesArtifactsToHandleRes.left().value(), true, false, null, user.getUserId());
+ findNodeTypesArtifactsToHandleRes.left().value(), true, false, null, user.getUserId(), auditingAction);
} catch (final ComponentException e) {
log.debug("Exception occurred when createServiceFromCsar,error is:{}", e.getMessage(), e);
throw e;
&& result.left().value().getProperties().size() != dataType.get("properties").size();
}
- private void createNodeTypes(List<NodeTypeDefinition> nodeTypesToCreate, String model, User user) {
+ private void createNodeTypes(List<NodeTypeDefinition> nodeTypesToCreate, Map<String, UploadComponentInstanceInfo> instancesFromCsar, String model,
+ User user) {
NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList();
List<NodeTypeMetadata> nodeTypeMetadataList = new ArrayList<>();
final Map<String, Object> allTypesToCreate = new HashMap<>();
nodeTypeMetadataList.add(nodeType.getNodeTypeMetadata());
});
nodeTypesMetadataList.setNodeMetadataList(nodeTypeMetadataList);
- resourceImportManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, user, model, true, false);
+ resourceImportManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, instancesFromCsar, user, model, true, false);
}
private List<NodeTypeDefinition> getNodeTypesToCreate(final String model, final ServiceCsarInfo csarInfo) {
private void combineInterfacesIntoToscaTemplate(Map<String, Map<String, Object>> newInterfaces,
Map<String, Map<String, Object>> existingInterfaces,
Map<String, Object> combinedMappedToscaTemplate) {
- Map<String, Map<String, Object>> combinedInterfaces = combineAdditionalInterfaces(existingInterfaces, newInterfaces);
+ Map<String, Map<String, Object>> combinedInterfaces = combineAdditionalInterfaces(newInterfaces, existingInterfaces);
if ((MapUtils.isEmpty(existingInterfaces) && MapUtils.isNotEmpty(combinedInterfaces))
|| (MapUtils.isNotEmpty(existingInterfaces) && !existingInterfaces.equals(combinedInterfaces))) {
combinedMappedToscaTemplate.put("interfaces", combinedInterfaces);
}
}
- private Map<String, Map<String, Object>> combineAdditionalInterfaces(Map<String, Map<String, Object>> existingInterfaces,
- Map<String, Map<String, Object>> newInterfaces) {
+ private Map<String, Map<String, Object>> combineAdditionalInterfaces(Map<String, Map<String, Object>> newInterfaces,
+ Map<String, Map<String, Object>> existingInterfaces) {
+ if (MapUtils.isNotEmpty(newInterfaces) && MapUtils.isNotEmpty(existingInterfaces) && newInterfaces.equals(existingInterfaces)) {
+ return new HashMap<>(existingInterfaces);
+ }
if (MapUtils.isEmpty(newInterfaces)) {
newInterfaces = new HashMap<>();
}
private List<Map<String, Object>> combineAdditionalRequirements(List<Map<String, Object>> newReqs,
List<Map<String, Object>> existingResourceReqs) {
+ if (CollectionUtils.isNotEmpty(newReqs) && CollectionUtils.isNotEmpty(existingResourceReqs) && newReqs.equals(existingResourceReqs)) {
+ return new ArrayList<>(existingResourceReqs);
+ }
if (CollectionUtils.isEmpty(existingResourceReqs)) {
existingResourceReqs = new ArrayList<>();
}
}
private Map<String, Object> combineEntries(Map<String, Object> newMap, Map<String, Object> existingMap) {
+ if (MapUtils.isNotEmpty(newMap) && MapUtils.isNotEmpty(existingMap) && newMap.equals(existingMap)) {
+ return new HashMap<>(existingMap);
+ }
if (MapUtils.isEmpty(newMap)) {
newMap = new HashMap<>();
}
protected Service createServiceFromYaml(Service service, String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo,
CsarInfo csarInfo,
- Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
- boolean shouldLock, boolean inTransaction, String nodeName, final String userId)
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
+ boolean shouldLock, boolean inTransaction, String nodeName, final String userId,
+ AuditingActionEnum auditingAction)
throws BusinessLogicException {
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
Service createdService;
csfyp.setNodeTypesInfo(nodeTypesInfo);
csfyp.setCsarInfo(csarInfo);
csfyp.setNodeName(nodeName);
- createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp, userId);
+ createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp, userId,
+ auditingAction);
log.debug("#createResourceFromYaml - The resource {} has been created ", service.getName());
} catch (ComponentException | BusinessLogicException e) {
log.debug("Create Service from yaml failed", e);
}
protected Service createServiceAndRIsFromYaml(Service service, boolean isNormative,
- Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp,
- final String userId)
+ final String userId, AuditingActionEnum auditingAction)
throws BusinessLogicException {
+
List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
String yamlName = csfyp.getYamlName();
ParsedToscaYamlInfo parsedToscaYamlInfo = csfyp.getParsedToscaYamlInfo();
if (shouldLock) {
Either<Boolean, ResponseFormat> lockResult = serviceBusinessLogic.lockComponentByName(service.getSystemName(), service, CREATE_RESOURCE);
if (lockResult.isRight()) {
- serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ComponentException(lockResult.right().value());
}
log.debug("name is locked {} status = {}", service.getSystemName(), lockResult);
service.setProperties(propertiesList);
}
log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
- service = serviceImportParseLogic.createServiceTransaction(service, csarInfo.getModifier(), isNormative);
+ service = serviceImportParseLogic.createServiceTransaction(service, csarInfo.getModifier(), isNormative, auditingAction);
log.trace("************* Going to add inputs from yaml {}", yamlName);
Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
service = serviceImportParseLogic.createInputsOnService(service, inputs);
log.trace("************* Finished to add inputs from yaml {}", yamlName);
- ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = parsedToscaYamlInfo.getSubstitutionFilterProperties();
+ ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties =
+ parsedToscaYamlInfo.getSubstitutionFilterProperties();
service = serviceImportParseLogic.createSubstitutionFilterOnService(service, substitutionFilterProperties);
log.trace("************* Added Substitution filter from interface yaml {}", yamlName);
Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances();
Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes
= groupBusinessLogic.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), service.getSystemName());
if (validateUpdateVfGroupNamesRes.isRight()) {
- serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
}
Map<String, GroupDefinition> groups;
}
Either<Service, ResponseFormat> createGroupsOnResource = createGroupsOnResource(service, groups);
if (createGroupsOnResource.isRight()) {
- serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ComponentException(createGroupsOnResource.right().value());
}
service = createGroupsOnResource.left().value();
Either<Service, ResponseFormat> createPoliciesOnResource = createPoliciesOnResource(service, parsedToscaYamlInfo.getPolicies());
if (createPoliciesOnResource.isRight()) {
- serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ComponentException(createPoliciesOnResource.right().value());
}
service = createPoliciesOnResource.left().value();
log.trace("************* Going to add artifacts from yaml {}", yamlName);
- NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToCreate);
Either<Service, ResponseFormat> createArtifactsEither = createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,
- createdArtifacts, yamlName, csarInfo, service, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock);
+ createdArtifacts, yamlName, csarInfo, service, inTransaction, shouldLock);
if (createArtifactsEither.isRight()) {
- serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ComponentException(createArtifactsEither.right().value());
}
service = serviceImportParseLogic.getServiceWithGroups(createArtifactsEither.left().value().getUniqueId());
ASDCKpiApi.countCreatedResourcesKPI();
return service;
- } catch (ComponentException | StorageException | BusinessLogicException e) {
+ } catch (Exception e) {
rollback = true;
serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw e;
if (CollectionUtils.isNotEmpty(inputs)) {
final List<ComponentInstance> componentInstances = component.getComponentInstances();
final String componentUniqueId = component.getUniqueId();
+ List<String> propertyMissingNames = new ArrayList<>();
for (final InputDefinition input : inputs) {
- if (isInputFromComponentInstanceProperty(input.getName(), componentInstances)) {
+ boolean isSubMapProp = false;
+ if (substitutionMappingProperties != null && !substitutionMappingProperties.isEmpty()) {
+ isSubMapProp = substitutionMappingProperties.entrySet().stream()
+ .anyMatch(stringEntry -> stringEntry.getValue().get(0).equals(input.getName()));
+ }
+ if (!isSubMapProp && isInputFromComponentInstanceProperty(input.getName(), componentInstances)) {
associateInputToComponentInstanceProperty(userId, input, componentInstances, componentUniqueId);
} else {
- associateInputToServiceProperty(userId, input, component, substitutionMappingProperties);
+ String propertyName = associateInputToServiceProperty(userId, input, component, substitutionMappingProperties);
+ if (StringUtils.isNotBlank(propertyName)) {
+ propertyMissingNames.add(propertyName);
+ }
}
}
-
+ if (CollectionUtils.isNotEmpty(propertyMissingNames)) {
+ throw new ComponentException(
+ componentsUtils.getResponseFormat(ActionStatus.MISSING_PROPERTIES_ERROR, propertyMissingNames.toString()));
+ }
Either<List<InputDefinition>, StorageOperationStatus> either = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId);
if (either.isRight()) {
throw new ComponentException(ActionStatus.GENERAL_ERROR);
private boolean isInputFromComponentInstanceProperty(final String inputName, final List<ComponentInstance> componentInstances) {
- AtomicBoolean isInputFromCIProp = new AtomicBoolean(false);
if (CollectionUtils.isNotEmpty(componentInstances)) {
- outer: for (ComponentInstance instance : componentInstances) {
+ for (ComponentInstance instance : componentInstances) {
for (PropertyDefinition instanceProperty : instance.getProperties()) {
if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
if (inputName.equals(getInputValueDataDefinition.getInputName())) {
- isInputFromCIProp.set(true);
- break outer;
+ return true;
}
}
}
}
}
}
- return isInputFromCIProp.get();
+ return false;
}
private void associateInputToComponentInstanceProperty(final String userId, final InputDefinition input,
String componentInstanceId = null;
ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
- outer: for (ComponentInstance instance : componentInstances) {
+ outer:
+ for (ComponentInstance instance : componentInstances) {
for (PropertyDefinition instanceProperty : instance.getProperties()) {
if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
}
}
- private void associateInputToServiceProperty(final String userId,
- final InputDefinition input, final Service component,
- final Map<String, List<String>> substitutionMappingProperties) {
+ private String associateInputToServiceProperty(final String userId,
+ final InputDefinition input, final Service component,
+ final Map<String, List<String>> substitutionMappingProperties) {
final List<PropertyDefinition> properties = component.getProperties();
if (CollectionUtils.isNotEmpty(properties) && MapUtils.isNotEmpty(substitutionMappingProperties)) {
AtomicReference<String> propertyNameFromInput = new AtomicReference<>(" ");
}
});
- final Optional<PropertyDefinition> propDefOptional = properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput.get()))
- .findFirst();
+ final Optional<PropertyDefinition> propDefOptional =
+ properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput.get()))
+ .findFirst();
if (propDefOptional.isPresent()) {
// From SELF
final String componentUniqueId = component.getUniqueId();
if (either.isRight()) {
throw new ComponentException(ActionStatus.GENERAL_ERROR);
}
+ } else {
+ input.setMappedToComponentProperty(false);
+ return propertyNameFromInput.get();
}
}
+ return "";
}
private void updateProperty(final PropertyDefinition propertyDefinition, final InputDefinition input, final String componentUniqueId) {
boolean inTransaction, boolean shouldLock) {
String nodeName = nodeTypeInfoToUpdateArtifacts.getNodeName();
Resource resource = preparedResource;
- Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = nodeTypeInfoToUpdateArtifacts
- .getNodeTypesArtifactsToHandle();
+ Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle =
+ nodeTypeInfoToUpdateArtifacts
+ .getNodeTypesArtifactsToHandle();
if (preparedResource.getResourceType() == ResourceTypeEnum.VF) {
if (nodeName != null && nodeTypesArtifactsToHandle.get(nodeName) != null && !nodeTypesArtifactsToHandle.get(nodeName).isEmpty()) {
Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = handleNodeTypeArtifacts(preparedResource,
vfCsarArtifactsToHandle = new EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class);
vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList.left().value());
} else {
- Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(
+ Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
+ findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(
component, artifactPathAndNameList.left().value(), csarInfo.getModifier());
if (findVfCsarArtifactsToHandleRes.isRight()) {
resStatus = Either.right(findVfCsarArtifactsToHandleRes.right().value());
protected Either<Service, ResponseFormat> createOrUpdateArtifacts(ArtifactOperationEnum operation, List<ArtifactDefinition> createdArtifacts,
String yamlFileName, CsarInfo csarInfo, Service preparedService,
- NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts,
boolean inTransaction, boolean shouldLock) {
Either<Service, ResponseFormat> createdCsarArtifactsEither = handleVfCsarArtifacts(preparedService, csarInfo, createdArtifacts,
new ArtifactOperationInfo(false, false, operation), shouldLock, inTransaction);
EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>> nodeTypeArtifactsToHandle = new EnumMap<>(
ArtifactsBusinessLogic.ArtifactOperationEnum.class);
Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
- Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat> nodeTypeArtifactsToHandleRes = Either
+ Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
+ nodeTypeArtifactsToHandleRes = Either
.left(nodeTypeArtifactsToHandle);
try {
List<CsarUtils.NonMetaArtifactInfo> artifactsToUpload = new ArrayList<>(artifactPathAndNameList);
.forEach(instanceProperty -> {
toscaFunctionService.updateFunctionWithDataFromSelfComponent(instanceProperty.getToscaFunction(),
updatedService, instancePropertyMap, instanceAttributeMap);
- instanceProperty.setValue(instanceProperty.getToscaFunction().getValue());
+ instanceProperty.setValue(StringEscapeUtils.unescapeJava(instanceProperty.getToscaFunction().getValue()));
})
);
}
instAttributes.put(resourceInstanceId, originResource.getAttributes());
addAttributeValueToResourceInstance(instAttributes, uploadComponentInstanceInfo.getAttributes());
}
- if (uploadComponentInstanceInfo.getUploadNodeFilterInfo() != null) {
+ if (uploadComponentInstanceInfo.getUploadNodeFilterInfo() == null) {
+ instNodeFilter.put(resourceInstanceId, new UploadNodeFilterInfo());
+ } else {
instNodeFilter.put(resourceInstanceId, uploadComponentInstanceInfo.getUploadNodeFilterInfo());
}
if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getInterfaces())) {
Map<String, OperationDataDefinition> operations = uploadInterfaceInfo.getOperations();
for (Map.Entry<String, OperationDataDefinition> operation : operations.entrySet()) {
- OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap().get(operation.getKey());
OperationDataDefinition instanceOperation = operation.getValue();
+ OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap()
+ .getOrDefault(operation.getKey(), new Operation(instanceOperation));
//Inputs
ListDataDefinition<OperationInputDefinition> instanceInputs = instanceOperation.getInputs();
- mergeOperationInputDefinitions(templateOperation.getInputs(), instanceInputs);
if (null != instanceInputs) {
+ mergeOperationInputDefinitions(templateOperation.getInputs(), instanceInputs);
component.getProperties()
.forEach(property -> instanceInputs.getListToscaDataDefinition().stream()
.filter(instanceInput ->
instanceInput.getToscaFunction() instanceof ToscaGetFunctionDataDefinition &&
property.getName().equals(instanceInput.getToscaFunction() != null ?
- ((ToscaGetFunctionDataDefinition) instanceInput.getToscaFunction()).getPropertyName() :
- null))
+ ((ToscaGetFunctionDataDefinition) instanceInput.getToscaFunction()).getPropertyName() : null))
.forEach(oldInput -> oldInput.setType(property.getType()))
);
+ templateOperation.setInputs(instanceInputs);
}
- templateOperation.setInputs(instanceInputs);
//Implementation
templateOperation.setImplementation(instanceOperation.getImplementation());
//Description