import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
+import org.openecomp.sdc.be.components.csar.ServiceCsarInfo;
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.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.be.ui.model.OperationUi;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.beans.factory.annotation.Autowired;
import org.yaml.snakeyaml.Yaml;
@Getter
private final ArtifactsBusinessLogic artifactsBusinessLogic;
private final IGraphLockOperation graphLockOperation;
private final ToscaFunctionService toscaFunctionService;
+ private final PropertyOperation propertyOperation;
+ private final DataTypeBusinessLogic dataTypeBusinessLogic;
+ private ApplicationDataTypeCache applicationDataTypeCache;
public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic,
final ArtifactsBusinessLogic artifactsBusinessLogic,
final ServiceImportParseLogic serviceImportParseLogic,
final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic,
final PolicyBusinessLogic policyBusinessLogic, final JanusGraphDao janusGraphDao,
- final IGraphLockOperation graphLockOperation, final ToscaFunctionService toscaFunctionService) {
+ final IGraphLockOperation graphLockOperation, final ToscaFunctionService toscaFunctionService,
+ final PropertyOperation propertyOperation, final DataTypeBusinessLogic dataTypeBusinessLogic) {
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
this.uiComponentDataConverter = uiComponentDataConverter;
this.componentsUtils = componentsUtils;
this.artifactsBusinessLogic = artifactsBusinessLogic;
this.graphLockOperation = graphLockOperation;
this.toscaFunctionService = toscaFunctionService;
+ this.propertyOperation = propertyOperation;
+ this.dataTypeBusinessLogic = dataTypeBusinessLogic;
+ }
+
+ @Autowired
+ public void setApplicationDataTypeCache(ApplicationDataTypeCache applicationDataTypeCache) {
+ this.applicationDataTypeCache = applicationDataTypeCache;
}
public Service createService(Service service, AuditingActionEnum auditingAction, User user, Map<String, byte[]> csarUIPayload,
protected Service createServiceFromCsar(Service service, User user, Map<String, byte[]> csarUIPayload, String csarUUID) {
log.trace("************* created successfully from YAML, resource TOSCA ");
try {
- CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID);
+ ServiceCsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID);
+
+ final Map<String, Object> dataTypesToCreate = getDatatypesToCreate(service.getModel(), csarInfo);
+ if (MapUtils.isNotEmpty(dataTypesToCreate)) {
+ dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), service.getModel(), true);
+ }
+
Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = serviceImportParseLogic
.findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service);
throw new ComponentException(ActionStatus.GENERAL_ERROR);
}
}
+
+ private Map<String, Object> getDatatypesToCreate(final String model, final CsarInfo csarInfo) {
+ final Map<String, Object> dataTypesToCreate = new HashMap<>();
+
+ for (final Entry<String, Object> dataTypeEntry : csarInfo.getDataTypes().entrySet()){
+ final Either<DataTypeDefinition, JanusGraphOperationStatus> result = applicationDataTypeCache.get(model, UniqueIdBuilder.buildDataTypeUid(model, dataTypeEntry.getKey()));
+ if (result.isRight() && result.right().value().equals(JanusGraphOperationStatus.NOT_FOUND)) {
+ dataTypesToCreate.put(dataTypeEntry.getKey(), dataTypeEntry.getValue());
+ log.info("Deploying unknown type " + dataTypeEntry.getKey() + " to model " + model + " from package " + csarInfo.getCsarUUID());
+ }
+ }
+ return dataTypesToCreate;
+ }
protected Service createServiceFromYaml(Service service, String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo,
CsarInfo csarInfo,
mapToConvert.put(TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), toscaVersion.left().value());
Map<String, Object> nodeTypes = serviceImportParseLogic.getNodeTypesFromTemplate(mappedToscaTemplate);
createNodeTypes(yamlName, service, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
- mapToConvert, nodeTypes);
+ mapToConvert, nodeTypes);
return csarInfo.getCreatedNodes();
} catch (Exception e) {
log.debug("Exception occured when createResourcesFromYamlNodeTypesList,error is:{}", e.getMessage(), e);