summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationCache.java5
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java89
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java5
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java126
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java12
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java84
8 files changed, 236 insertions, 94 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
index 01f6cd1b40..bf9f4d79a6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
@@ -36,7 +36,6 @@ public class DataTypeDefinition extends DataTypeDataDefinition {
private DataTypeDefinition derivedFrom;
private List<PropertyConstraint> constraints;
private List<PropertyDefinition> properties;
- private String model;
public DataTypeDefinition(final DataTypeDataDefinition dataTypeDataDefinition) {
super(dataTypeDataDefinition);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationCache.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationCache.java
index d0a071909c..bfb20a2f14 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationCache.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationCache.java
@@ -22,10 +22,11 @@ package org.openecomp.sdc.be.model.cache;
import fj.data.Either;
import java.util.Map;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
public interface ApplicationCache<T> {
- Either<Map<String, T>, JanusGraphOperationStatus> getAll();
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> getAll(final String model);
- Either<T, JanusGraphOperationStatus> get(String uniqueId);
+ Either<T, JanusGraphOperationStatus> get(final String model, final String uniqueId);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java
index a1bafbc6f2..070ebf72e3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.model.cache;
import fj.data.Either;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -43,6 +44,7 @@ import org.openecomp.sdc.be.config.Configuration.ApplicationL1CacheInfo;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.operations.impl.DataTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.resources.data.DataTypeData;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
@@ -64,13 +66,16 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
private final ScheduledExecutorService scheduledPollingService;
@Getter(AccessLevel.PACKAGE)
private ScheduledFuture<?> scheduledFuture = null;
- private Map<String, DataTypeDefinition> dataTypesCacheMap = new HashMap<>();
+ private Map<String, Map<String, DataTypeDefinition>> dataTypesByModelCacheMap = new HashMap<>();
+ private final DataTypeOperation dataTypeOperation;
private int firstRunDelayInSec = 30;
private int pollingIntervalInSec = 60;
- public ApplicationDataTypeCache(final PropertyOperation propertyOperation, final ApplicationEventPublisher applicationEventPublisher) {
+ public ApplicationDataTypeCache(final PropertyOperation propertyOperation, final ApplicationEventPublisher applicationEventPublisher,
+ final DataTypeOperation dataTypeOperation) {
this.propertyOperation = propertyOperation;
this.applicationEventPublisher = applicationEventPublisher;
+ this.dataTypeOperation = dataTypeOperation;
scheduledPollingService = Executors
.newScheduledThreadPool(1, new BasicThreadFactory.Builder().namingPattern("ApplicationDataTypeCacheThread-%d").build());
}
@@ -156,32 +161,34 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
}
}
- private Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> getAllDataTypesFromGraph() {
+ private Either<Map<String, Map<String, DataTypeDefinition>>, JanusGraphOperationStatus> getAllDataTypesFromGraph() {
return propertyOperation.getAllDataTypes();
}
- @Override
- public Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> getAll() {
+ public Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> getAll(final String model) {
try {
readWriteLock.readLock().lock();
- if (MapUtils.isEmpty(dataTypesCacheMap)) {
- return getAllDataTypesFromGraph();
+ if (MapUtils.isEmpty(dataTypesByModelCacheMap)) {
+ final var dataTypesFound = getAllDataTypesFromGraph();
+ if (dataTypesFound.isRight()) {
+ return Either.right(dataTypesFound.right().value());
+ }
+ dataTypesByModelCacheMap = dataTypesFound.left().value();
}
- return Either.left(new HashMap<>(dataTypesCacheMap));
+ return Either.left(getDataTypeDefinitionMapByModel(model));
} finally {
readWriteLock.readLock().unlock();
}
}
@Override
- public Either<DataTypeDefinition, JanusGraphOperationStatus> get(String uniqueId) {
+ public Either<DataTypeDefinition, JanusGraphOperationStatus> get(final String model, final String uniqueId) {
try {
readWriteLock.readLock().lock();
- if (MapUtils.isEmpty(dataTypesCacheMap)) {
+ if (MapUtils.isEmpty(dataTypesByModelCacheMap)) {
return propertyOperation.getDataTypeByUid(uniqueId);
}
-
- final Optional<DataTypeDefinition> dataTypeDefinition = dataTypesCacheMap.values().stream()
+ final Optional<DataTypeDefinition> dataTypeDefinition = getDataTypeDefinitionMapByModel(model).values().stream()
.filter(p -> p.getUniqueId().equals(uniqueId)).findFirst();
if (dataTypeDefinition.isEmpty()) {
return propertyOperation.getDataTypeByUid(uniqueId);
@@ -192,6 +199,10 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
}
}
+ private Map<String, DataTypeDefinition> getDataTypeDefinitionMapByModel(final String model) {
+ return dataTypesByModelCacheMap.containsKey(model) ? dataTypesByModelCacheMap.get(model) : new HashMap<>();
+ }
+
@Override
public void run() {
try {
@@ -218,10 +229,9 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
private boolean hasDataTypesChanged() {
final List<DataTypeData> dataTypeListFromDatabase = findAllDataTypesLazy();
- final Map<String, DataTypeDefinition> dataTypesCacheCopyMap = copyDataTypeCache();
-
- if (dataTypeListFromDatabase.size() != dataTypesCacheCopyMap.size()) {
- log.debug("Total of cached data types '{}' differs from the actual '{}'", dataTypeListFromDatabase.size(), dataTypesCacheCopyMap.size());
+ final int dataTypesCacheCopyMap = dataTypesCacheMapSize();
+ if (dataTypeListFromDatabase.size() != dataTypesCacheCopyMap) {
+ log.debug("Total of cached data types '{}' differs from the actual '{}'", dataTypeListFromDatabase.size(), dataTypesCacheCopyMap);
return true;
}
@@ -230,13 +240,23 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
return false;
}
- return hasDataTypesChanged(dataTypeListFromDatabase, dataTypesCacheCopyMap);
+ return hasDataTypesChanged(dataTypeListFromDatabase, copyDataTypeCache());
}
- private boolean hasDataTypesChanged(final List<DataTypeData> dataTypeListFromDatabase, final Map<String, DataTypeDefinition> dataTypesCacheCopyMap) {
+ private int dataTypesCacheMapSize() {
+ var count = 0;
+ for (var i = 0; i < copyDataTypeCache().size(); i++) {
+ count += new ArrayList<>(copyDataTypeCache().values()).get(i).size();
+
+ }
+ return count;
+ }
+
+ private boolean hasDataTypesChanged(final List<DataTypeData> dataTypeListFromDatabase, final Map<String, Map<String, DataTypeDefinition>> dataTypesCacheCopyMap) {
return dataTypeListFromDatabase.stream().map(DataTypeData::getDataTypeDataDefinition).anyMatch(actualDataTypeDefinition -> {
final String dataTypeName = actualDataTypeDefinition.getName();
- final DataTypeDefinition cachedDataTypeDefinition = dataTypesCacheCopyMap.get(dataTypeName);
+ final String model = actualDataTypeDefinition.getModel();
+ final DataTypeDefinition cachedDataTypeDefinition = dataTypesCacheCopyMap.get(model).get(dataTypeName);
if (cachedDataTypeDefinition == null) {
log.debug("Datatype '{}' is not present in the cache. ", dataTypeName);
return true;
@@ -245,8 +265,8 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
final long cachedCreationTime = cachedDataTypeDefinition.getCreationTime() == null ? 0 : cachedDataTypeDefinition.getCreationTime();
final long actualCreationTime = actualDataTypeDefinition.getCreationTime() == null ? 0 : actualDataTypeDefinition.getCreationTime();
if (cachedCreationTime != actualCreationTime) {
- log.debug("Datatype '{}' was updated. Cache/database creation time '{}'/'{}'.",
- dataTypeName, cachedCreationTime, actualCreationTime);
+ log.debug("Datatype '{}' with model '{}' was updated. Cache/database creation time '{}'/'{}'.",
+ dataTypeName, model, cachedCreationTime, actualCreationTime);
return true;
}
final long cachedModificationTime =
@@ -263,23 +283,23 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
});
}
- private Map<String, DataTypeDefinition> copyDataTypeCache() {
+ private Map<String, Map<String, DataTypeDefinition>> copyDataTypeCache() {
try {
readWriteLock.readLock().lock();
- return new HashMap<>(this.dataTypesCacheMap);
+ return new HashMap<>(this.dataTypesByModelCacheMap);
} finally {
readWriteLock.readLock().unlock();
}
}
private void refreshDataTypesCache() {
- final Map<String, DataTypeDefinition> dataTypesDefinitionMap = findAllDataTypesEager();
+ final Map<String, Map<String, DataTypeDefinition>> dataTypesDefinitionMap = findAllDataTypesEager();
if (dataTypesDefinitionMap.isEmpty()) {
return;
}
try {
readWriteLock.writeLock().lock();
- dataTypesCacheMap = dataTypesDefinitionMap;
+ dataTypesByModelCacheMap = dataTypesDefinitionMap;
onDataChangeEventEmit();
BeEcompErrorManager.getInstance()
.logInternalFlowError("ReplaceDataTypesCache", "Succeed to replace the data types cache", ErrorSeverity.INFO);
@@ -288,10 +308,10 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
}
}
- private Map<String, DataTypeDefinition> findAllDataTypesEager() {
+ private Map<String, Map<String, DataTypeDefinition>> findAllDataTypesEager() {
log.trace("Fetching data types from database, eager mode");
final long startTime = System.currentTimeMillis();
- final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = propertyOperation.getAllDataTypes();
+ final Either<Map<String, Map<String, DataTypeDefinition>>, JanusGraphOperationStatus> allDataTypes = propertyOperation.getAllDataTypes();
log.trace("Finish fetching data types from database. Took {}ms", (System.currentTimeMillis() - startTime));
if (allDataTypes.isRight()) {
final JanusGraphOperationStatus status = allDataTypes.right().value();
@@ -306,16 +326,9 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
private List<DataTypeData> findAllDataTypesLazy() {
log.trace("Fetching data types from database, lazy mode");
final long startTime = System.currentTimeMillis();
- final Either<List<DataTypeData>, JanusGraphOperationStatus> allDataTypes = propertyOperation.getAllDataTypeNodes();
+ final List<DataTypeData> allDataTypes = dataTypeOperation.getAllDataTypeNodes();
log.trace("Finish fetching data types from database. Took {}ms", (System.currentTimeMillis() - startTime));
- if (allDataTypes.isRight()) {
- final JanusGraphOperationStatus status = allDataTypes.right().value();
- var errorMsg= String.format("Failed to fetch data types from database. Status is %s", status);
- log.error(EcompLoggerErrorCode.UNKNOWN_ERROR, ApplicationDataTypeCache.class.getName(), errorMsg);
- BeEcompErrorManager.getInstance().logInternalConnectionError(APPLICATION_DATA_TYPES_CACHE, errorMsg, ErrorSeverity.ERROR);
- return Collections.emptyList();
- }
- return allDataTypes.left().value();
+ return allDataTypes;
}
private void onDataChangeEventEmit() {
@@ -329,9 +342,9 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
public static class DataTypesCacheChangedEvent extends ApplicationEvent {
@Getter
- private final Map<String, DataTypeDefinition> newData;
+ private final Map<String, Map<String, DataTypeDefinition>> newData;
- public DataTypesCacheChangedEvent(final Object source, final Map<String, DataTypeDefinition> newData) {
+ public DataTypesCacheChangedEvent(final Object source, final Map<String, Map<String, DataTypeDefinition>> newData) {
super(source);
this.newData = newData;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java
index 1097e5d204..97dd3ea718 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java
@@ -70,7 +70,7 @@ public class ComponentInstanceOperation extends AbstractOperation {
@Autowired
private IInputsOperation inputOperation;
@Autowired
- private ApplicationDataTypeCache dataTypeCache;
+ private ApplicationDataTypeCache applicationDataTypeCache;
public ComponentInstanceOperation() {
super();
@@ -408,7 +408,8 @@ public class ComponentInstanceOperation extends AbstractOperation {
innerType = propDef.getType();
}
log.debug("Before validateAndUpdatePropertyValue");
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll();
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes =
+ applicationDataTypeCache.getAll(resourceInstanceInput.getModel());
if (allDataTypes.isRight()) {
JanusGraphOperationStatus status = allDataTypes.right().value();
BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance",
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
new file mode 100644
index 0000000000..158cb2569b
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
@@ -0,0 +1,126 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.model.operations.impl;
+
+import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.resources.data.DataTypeData;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component("dataType-operation")
+public class DataTypeOperation extends AbstractOperation {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DataTypeOperation.class);
+
+ private final ModelOperation modelOperation;
+
+ @Autowired
+ public DataTypeOperation(final HealingJanusGraphGenericDao janusGraphGenericDao,
+ final ModelOperation modelOperation) {
+ this.janusGraphGenericDao = janusGraphGenericDao;
+ this.modelOperation = modelOperation;
+ }
+
+ public List<DataTypeData> getAllDataTypeNodes() {
+ final List<DataTypeData> dataTypesFound = new ArrayList<>();
+ final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypesWithNullModel =
+ janusGraphGenericDao.getByCriteria(NodeTypeEnum.DataType, null, DataTypeData.class);
+
+ final var dataTypesValidated = validateDataType(getAllDataTypesWithNullModel, null);
+ if (CollectionUtils.isNotEmpty(dataTypesValidated)) {
+ dataTypesFound.addAll(dataTypesValidated);
+ }
+
+ final List<DataTypeData> allDataTypeNodesWithModel = getAllDataTypesWithModel();
+ if(CollectionUtils.isNotEmpty(allDataTypeNodesWithModel)) {
+ dataTypesFound.addAll(allDataTypeNodesWithModel);
+ }
+ return dataTypesFound;
+ }
+
+ public List<DataTypeData> getAllDataTypesWithModel() {
+ final List<DataTypeData> dataTypesWithModel = new ArrayList<>();
+ modelOperation.findAllModels()
+ .forEach(model -> {
+ final var modelName = model.getName();
+ final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypesByModel = janusGraphGenericDao
+ .getByCriteriaForModel(NodeTypeEnum.DataType, null, modelName, DataTypeData.class);
+ final var dataTypesValidated = validateDataType(getAllDataTypesByModel, modelName);
+ dataTypesWithModel.addAll(dataTypesValidated);
+ });
+ return dataTypesWithModel;
+ }
+
+ private List<DataTypeData> validateDataType(final Either<List<DataTypeData>, JanusGraphOperationStatus> getDataTypes, final String modelName) {
+ if (getDataTypes.isRight() && getDataTypes.right().value() == JanusGraphOperationStatus.NOT_FOUND) {
+ return Collections.emptyList();
+ }
+ if (getDataTypes.isRight()) {
+ final var status = getDataTypes.right().value();
+ if (LOGGER.isErrorEnabled()) {
+ final var errorMsg= String.format("Failed to fetch data types from database with model %s. Status is %s", modelName, status);
+ LOGGER.error(String.valueOf(EcompLoggerErrorCode.UNKNOWN_ERROR), DataTypeOperation.class.getName(), errorMsg);
+ BeEcompErrorManager.getInstance().logInternalConnectionError(DataTypeOperation.class.getName(), errorMsg, ErrorSeverity.ERROR);
+ }
+ return Collections.emptyList();
+ }
+ return getDataTypes.left().value();
+ }
+
+ public Map<String, Map<String, DataTypeDefinition>> mapDataTypesDefinitionByModel(final Map<String, DataTypeDefinition> allDataTypes) {
+ final Map<String, DataTypeDefinition> dataTypesWithNullModelMap = new HashMap<>();
+ final Map<String, DataTypeDefinition> dataTypesWithModelMap = new HashMap<>();
+ final Map<String, Map<String, DataTypeDefinition>> dataTypesMappedByModel = new HashMap<>();
+ allDataTypes.values().stream().forEach(dataTypeDefinition -> {
+ final var model = dataTypeDefinition.getModel();
+ final var dataTypeDefinitionName = dataTypeDefinition.getName();
+ if (model == null) {
+ dataTypesWithNullModelMap.put(dataTypeDefinitionName, dataTypeDefinition);
+ } else {
+ dataTypesWithModelMap.put(dataTypeDefinitionName, dataTypeDefinition);
+ if (dataTypesMappedByModel.containsKey(model)) {
+ dataTypesMappedByModel.get(model).put(dataTypeDefinitionName, dataTypeDefinition);
+ } else {
+ dataTypesMappedByModel.put(model, dataTypesWithModelMap);
+ }
+ }
+ });
+ if(MapUtils.isNotEmpty(dataTypesWithNullModelMap)) {
+ dataTypesMappedByModel.put(null, dataTypesWithNullModelMap);
+ }
+ return dataTypesMappedByModel;
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
index 45df37c4b8..c463af691c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
@@ -76,7 +76,7 @@ public class GroupInstanceOperation extends AbstractOperation implements IGroupI
@Autowired
PropertyOperation propertyOperation;
@javax.annotation.Resource
- private ApplicationDataTypeCache dataTypeCache;
+ private ApplicationDataTypeCache applicationDataTypeCache;
public Either<List<GroupInstance>, StorageOperationStatus> getAllGroupInstances(String parentId, NodeTypeEnum parentType) {
Either<List<GroupInstance>, StorageOperationStatus> result = null;
@@ -285,7 +285,8 @@ public class GroupInstanceOperation extends AbstractOperation implements IGroupI
innerType = propDef.getType();
}
log.debug("Before validateAndUpdatePropertyValue");
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll();
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes =
+ applicationDataTypeCache.getAll(groupInstanceProperty.getModel());
if (allDataTypes.isRight()) {
JanusGraphOperationStatus status = allDataTypes.right().value();
BeEcompErrorManager.getInstance()
@@ -388,7 +389,8 @@ public class GroupInstanceOperation extends AbstractOperation implements IGroupI
innerType = propDef.getType();
}
// Specific Update Logic
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll();
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes =
+ applicationDataTypeCache.getAll(groupInstanceProerty.getModel());
if (allDataTypes.isRight()) {
JanusGraphOperationStatus status = allDataTypes.right().value();
BeEcompErrorManager.getInstance()
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java
index effdbebf4c..b9378b8eca 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java
@@ -72,15 +72,15 @@ public class GroupOperation extends AbstractOperation implements IGroupOperation
private final TopologyTemplateOperation topologyTemplateOperation;
private final PropertyOperation propertyOperation;
private final GroupTypeOperation groupTypeOperation;
- private final ApplicationDataTypeCache dataTypeCache;
+ private final ApplicationDataTypeCache applicationDataTypeCache;
public GroupOperation(JanusGraphDao janusGraphDao, TopologyTemplateOperation topologyTemplateOperation, PropertyOperation propertyOperation,
- GroupTypeOperation groupTypeOperation, ApplicationDataTypeCache dataTypeCache) {
+ GroupTypeOperation groupTypeOperation, ApplicationDataTypeCache applicationDataTypeCache) {
this.janusGraphDao = janusGraphDao;
this.topologyTemplateOperation = topologyTemplateOperation;
this.propertyOperation = propertyOperation;
this.groupTypeOperation = groupTypeOperation;
- this.dataTypeCache = dataTypeCache;
+ this.applicationDataTypeCache = applicationDataTypeCache;
}
private GroupDefinition convertGroupDataToGroupDefinition(GroupData groupData) {
@@ -485,7 +485,7 @@ public class GroupOperation extends AbstractOperation implements IGroupOperation
StorageOperationStatus result = null;
String innerType =
property.getSchema() == null ? null : property.getSchema().getProperty() == null ? null : property.getSchema().getProperty().getType();
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll();
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(property.getModel());
Either<Object, Boolean> isValid = null;
if (allDataTypes.isRight()) {
JanusGraphOperationStatus status = allDataTypes.right().value();
@@ -493,8 +493,8 @@ public class GroupOperation extends AbstractOperation implements IGroupOperation
result = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status);
}
if (result == null) {
- isValid = propertyOperation
- .validateAndUpdatePropertyValue(property.getType(), property.getValue(), innerType, allDataTypes.left().value());
+ isValid = propertyOperation.validateAndUpdatePropertyValue(property.getType(), property.getValue(), innerType,
+ allDataTypes.left().value());
if (isValid.isRight()) {
log.debug("Failed to validate property value {}. Status is {}. ", property.getValue(), StorageOperationStatus.INVALID_PROPERTY);
result = StorageOperationStatus.INVALID_PROPERTY;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index 1f4fca0685..726efcf847 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -21,6 +21,20 @@ package org.openecomp.sdc.be.model.operations.impl;
import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.Maps;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import fj.data.Either;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -82,6 +96,7 @@ import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
import org.openecomp.sdc.be.resources.data.DataTypeData;
+import org.openecomp.sdc.be.resources.data.ModelData;
import org.openecomp.sdc.be.resources.data.PropertyData;
import org.openecomp.sdc.be.resources.data.PropertyValueData;
import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
@@ -89,20 +104,6 @@ import org.openecomp.sdc.be.resources.data.UniqueIdData;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.fasterxml.jackson.core.ObjectCodec;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.collect.Maps;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-import fj.data.Either;
@Component("property-operation")
public class PropertyOperation extends AbstractOperation implements IPropertyOperation {
@@ -120,11 +121,14 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
private static final String UPDATE_DATA_TYPE = "UpdateDataType";
private static Logger log = Logger.getLogger(PropertyOperation.class.getName());
private DerivedFromOperation derivedFromOperation;
+ private DataTypeOperation dataTypeOperation;
@Autowired
- public PropertyOperation(HealingJanusGraphGenericDao janusGraphGenericDao, DerivedFromOperation derivedFromOperation) {
+ public PropertyOperation(HealingJanusGraphGenericDao janusGraphGenericDao, DerivedFromOperation derivedFromOperation,
+ DataTypeOperation dataTypeOperation) {
this.janusGraphGenericDao = janusGraphGenericDao;
this.derivedFromOperation = derivedFromOperation;
+ this.dataTypeOperation = dataTypeOperation;
}
public PropertyDefinition convertPropertyDataToPropertyDefinition(PropertyData propertyDataResult, String propertyName, String resourceId) {
@@ -1506,28 +1510,21 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return Either.left(true);
}
- public Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> getAllDataTypes() {
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> result = Either.left(dataTypes);
- Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypes = janusGraphGenericDao
- .getByCriteria(NodeTypeEnum.DataType, null, DataTypeData.class);
- if (getAllDataTypes.isRight()) {
- JanusGraphOperationStatus status = getAllDataTypes.right().value();
- if (status != JanusGraphOperationStatus.NOT_FOUND) {
- return Either.right(status);
- } else {
- return result;
- }
- }
- List<DataTypeData> list = getAllDataTypes.left().value();
+ public Either<Map<String, Map<String, DataTypeDefinition>>, JanusGraphOperationStatus> getAllDataTypes() {
+ final Map<String, Map<String, DataTypeDefinition>> dataTypes = new HashMap<>();
+ Either<Map<String, Map<String, DataTypeDefinition>>, JanusGraphOperationStatus> result = Either.left(dataTypes);
+ final Map<String, DataTypeDefinition> allDataTypesFound = new HashMap<>();
+ final List<DataTypeData> list = dataTypeOperation.getAllDataTypeNodes();
if (list != null) {
log.trace("Number of data types to load is {}", list.size());
List<String> collect = list.stream().map(p -> p.getDataTypeDataDefinition().getName()).collect(Collectors.toList());
log.trace("The data types to load are {}", collect);
for (DataTypeData dataTypeData : list) {
- log.trace("Going to fetch data type {}. uid is {}", dataTypeData.getDataTypeDataDefinition().getName(), dataTypeData.getUniqueId());
+ final String dataTypeName = dataTypeData.getDataTypeDataDefinition().getName();
+ final String dataTypeUniqueId = dataTypeData.getUniqueId();
+ log.trace("Going to fetch data type {}. uid is {}", dataTypeName, dataTypeUniqueId);
Either<DataTypeDefinition, JanusGraphOperationStatus> dataTypeByUid = this
- .getAndAddDataTypeByUid(dataTypeData.getUniqueId(), dataTypes);
+ .getAndAddDataTypeByUid(dataTypeUniqueId, allDataTypesFound);
if (dataTypeByUid.isRight()) {
JanusGraphOperationStatus status = dataTypeByUid.right().value();
if (status == JanusGraphOperationStatus.NOT_FOUND) {
@@ -1535,13 +1532,14 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
return Either.right(status);
}
+ result = Either.left(dataTypeOperation.mapDataTypesDefinitionByModel(allDataTypesFound));
}
}
if (log.isTraceEnabled()) {
if (result.isRight()) {
log.trace("After fetching all data types {}", result);
} else {
- Map<String, DataTypeDefinition> map = result.left().value();
+ Map<String, Map<String, DataTypeDefinition>> map = result.left().value();
if (map != null) {
String types = map.keySet().stream().collect(Collectors.joining(",", "[", "]"));
log.trace("After fetching all data types {} ", types);
@@ -1577,7 +1575,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
log.error(FAILED_TO_FETCH_PROPERTIES_OF_DATA_TYPE, uniqueId);
return Either.right(propertiesStatus);
}
- allDataTypes.put(dataTypeDefinition.getName(), dataTypeDefinition);
+ allDataTypes.put(dataTypeDefinition.getUniqueId(), dataTypeDefinition);
String derivedFrom = dataTypeDefinition.getDerivedFromName();
if (allDataTypes.containsKey(derivedFrom)) {
DataTypeDefinition parentDataTypeDefinition = allDataTypes.get(derivedFrom);
@@ -1606,26 +1604,28 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
DataTypeDefinition parentDataTypeDefinition = dataTypeByUid.left().value();
dataTypeDefinition.setDerivedFrom(parentDataTypeDefinition);
+ final var model = getModel(uniqueId);
+ if (StringUtils.isNotEmpty(model)) {
+ dataTypeDefinition.setModel(model);
+ }
}
result = Either.left(dataTypeDefinition);
return result;
}
+ private String getModel(final String uniqueId) {
+ final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> model = janusGraphGenericDao.getParentNode(
+ UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.DataType), uniqueId, GraphEdgeLabels.MODEL_ELEMENT,
+ NodeTypeEnum.Model, ModelData.class);
+ return model.isLeft() ? model.left().value().getLeft().getName() : StringUtils.EMPTY;
+ }
+
public Either<String, JanusGraphOperationStatus> checkInnerType(PropertyDataDefinition propDataDef) {
String propertyType = propDataDef.getType();
ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
return getInnerType(type, propDataDef::getSchema);
}
- public Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypeNodes() {
- final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypes =
- janusGraphGenericDao.getByCriteria(NodeTypeEnum.DataType, null, DataTypeData.class);
- if (getAllDataTypes.isRight() && getAllDataTypes.right().value() == JanusGraphOperationStatus.NOT_FOUND) {
- return Either.left(Collections.emptyList());
- }
- return getAllDataTypes;
- }
-
public Either<Object, Boolean> validateAndUpdatePropertyValue(String propertyType, String value, boolean isValidate, String innerType,
Map<String, DataTypeDefinition> dataTypes) {
log.trace("Going to validate property value and its type. type = {}, value = {}", propertyType, value);