diff options
Diffstat (limited to 'ms/controllerblueprints/modules/service')
19 files changed, 427 insertions, 276 deletions
diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json new file mode 100644 index 00000000..661a9503 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json @@ -0,0 +1,44 @@ +{ + "description": "This is Database Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": true, + "type": "string", + "constraints": [ + { + "valid_values": [ + "SQL", + "PLSQL" + ] + } + ] + }, + "query": { + "required": true, + "type": "string" + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json new file mode 100644 index 00000000..13e234e1 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json @@ -0,0 +1,18 @@ +{ + "description": "This is Default Resource Source Node Type", + "version": "1.0.0", + "properties": { + "key": { + "required": false, + "type": "string" + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json new file mode 100644 index 00000000..126ea30b --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json @@ -0,0 +1,18 @@ +{ + "description": "This is Input Resource Source Node Type", + "version": "1.0.0", + "properties": { + "key": { + "required": false, + "type": "string" + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json new file mode 100644 index 00000000..f8dd8b6f --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json @@ -0,0 +1,61 @@ +{ + "description": "This is Rest Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "JSON", + "constraints": [ + { + "valid_values": [ + "JSON" + ] + } + ] + }, + "url-path": { + "required": true, + "type": "string" + }, + "path": { + "required": true, + "type": "string" + }, + "expression-type": { + "required": false, + "type": "string", + "default": "JSON_PATH", + "constraints": [ + { + "valid_values": [ + "JSON_PATH", + "JSON_POINTER" + ] + } + ] + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json new file mode 100644 index 00000000..2ef553e2 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json @@ -0,0 +1,5 @@ +{ + "description": "TOSCA base type for Resource Sources", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json index 86252354..cd4e282b 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json @@ -1,20 +1,25 @@ {
"name": "bundle-id",
- "description": "name of the ",
+ "property" :{
+ "description": "name of the ",
+ "type": "string"
+ },
"resource-type": "ONAP",
"resource-path": "vnf/bundle-id",
"updated-by": "brindasanth@onap.com",
- "data-type": "String",
"tags": "bundle-id, brindasanth@onap.com",
- "source": {
+ "sources": {
"db": {
- "query": "SELECT bundle-id FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
- "input-key-mapping": {
- "profile_name": "profile_name"
- },
- "output-key-mapping": {
- "db-country": "country",
- "db-state": "state"
+ "type": "source-db",
+ "properties": {
+ "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
+ "input-key-mapping": {
+ "profile_name": "profile_name"
+ },
+ "output-key-mapping": {
+ "db-country": "country",
+ "db-state": "state"
+ }
}
}
},
diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json index 35736b66..610e8fc0 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json @@ -1,17 +1,19 @@ {
"name": "action-name",
+ "property" :{
+ "description": "name of the ",
+ "type": "string"
+ },
"resource-path": "action-name",
"resource-type": "ONAP",
- "description": "To be provided",
- "valid-values": null,
- "sample-value": null,
"updated-by": "brindasanth@onap.com",
- "tags": null,
- "default": null,
- "data-type": "string",
- "source": {
+ "tags": "action-name, brindasanth",
+ "sources": {
"input": {
- "key": "action-name"
+ "type": "source-input",
+ "properties": {
+ "key": "action-name"
+ }
}
}
}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json index c6c0f985..e7e06000 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json @@ -1,14 +1,19 @@ {
- "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com",
- "name": "v4-ip-type",
- "description": "To be provided",
- "updated-by": "brindasanth@onap.com",
- "resource-type": "ONAP",
- "resource-path": "vnf/v4-ip-type",
- "data-type": "string",
- "source": {
- "input": {
-
- }
- }
+ "name": "v4-ip-type",
+ "property": {
+ "description": "name of the ",
+ "type": "string"
+ },
+ "resource-path": "vnf/v4-ip-type",
+ "resource-type": "ONAP",
+ "updated-by": "brindasanth@onap.com",
+ "tags": "v4-ip-type, source-input, brindasanth",
+ "sources": {
+ "input": {
+ "type": "source-input",
+ "properties": {
+ "key": "v4-ip-type"
+ }
+ }
+ }
}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/pom.xml b/ms/controllerblueprints/modules/service/pom.xml index 6a40a4a7..9efadd18 100644 --- a/ms/controllerblueprints/modules/service/pom.xml +++ b/ms/controllerblueprints/modules/service/pom.xml @@ -2,6 +2,8 @@ <!--
~ Copyright © 2017-2018 AT&T Intellectual Property.
~
+ ~ Modifications Copyright © 2018 IBM.
+ ~
~ 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
@@ -67,10 +69,25 @@ <!--</dependency>-->
<dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-test</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index 6b09c81f..2c443783 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java @@ -1,5 +1,6 @@ /*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse;
@@ -102,7 +103,7 @@ public class AutoResourceMappingService { ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName());
if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) {
- DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), DictionaryDefinition.class);
+ ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class);
if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName())
&& StringUtils.isBlank(resourceAssignment.getDictionaryName())) {
@@ -186,7 +187,7 @@ public class AutoResourceMappingService { }
if (dictionaries != null) {
for (ResourceDictionary resourcedictionary : dictionaries) {
- DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), DictionaryDefinition.class);
+ ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class);
PropertyDefinition property = new PropertyDefinition();
property.setRequired(true);
ResourceAssignment resourceAssignment = new ResourceAssignment();
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java deleted file mode 100644 index a2e5b104..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java +++ /dev/null @@ -1,100 +0,0 @@ -/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- *
- * 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.
- */
-
-package org.onap.ccsdk.apps.controllerblueprints.service;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.*;
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerRepoService;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
-import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository;
-import org.springframework.stereotype.Service;
-
-import java.util.Optional;
-
-/**
- * BluePrintEnhancerRepoDBService
- *
- * @author Brinda Santh
- */
-@Service
-public class BluePrintEnhancerRepoDBService implements BluePrintEnhancerRepoService {
-
- private ModelTypeRepository modelTypeRepository;
-
- public BluePrintEnhancerRepoDBService(ModelTypeRepository modelTypeRepository) {
- this.modelTypeRepository = modelTypeRepository;
- }
-
-
- @Override
- public NodeType getNodeType(String nodeTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(nodeTypeName), "NodeType name is missing");
- String content = getModelDefinitions(nodeTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "NodeType content is missing");
- return JacksonUtils.readValue(content, NodeType.class);
- }
-
-
- @Override
- public DataType getDataType(String dataTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(dataTypeName), "DataType name is missing");
- String content = getModelDefinitions(dataTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "DataType content is missing");
- return JacksonUtils.readValue(content, DataType.class);
- }
-
-
- @Override
- public ArtifactType getArtifactType(String artifactTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(artifactTypeName), "ArtifactType name is missing");
- String content = getModelDefinitions(artifactTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "ArtifactType content is missing");
- return JacksonUtils.readValue(content, ArtifactType.class);
- }
-
-
- @Override
- public RelationshipType getRelationshipType(String relationshipTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(relationshipTypeName), "RelationshipType name is missing");
- String content = getModelDefinitions(relationshipTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "RelationshipType content is missing");
- return JacksonUtils.readValue(content, RelationshipType.class);
- }
-
-
- @Override
- public CapabilityDefinition getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(capabilityDefinitionName), "CapabilityDefinition name is missing");
- String content = getModelDefinitions(capabilityDefinitionName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "CapabilityDefinition content is missing");
- return JacksonUtils.readValue(content, CapabilityDefinition.class);
- }
-
- private String getModelDefinitions(String modelName) throws BluePrintException {
- String modelDefinition = null;
- Optional<ModelType> modelTypedb = modelTypeRepository.findByModelName(modelName);
- if (modelTypedb.isPresent()) {
- modelDefinition = modelTypedb.get().getDefinition();
- } else {
- throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName));
- }
- return modelDefinition;
- }
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java index afd12f21..0cf846c7 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java @@ -1,5 +1,6 @@ /*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +25,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
import org.onap.ccsdk.apps.controllerblueprints.core.data.*;
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService;
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerRepoService;
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService;
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
import org.slf4j.Logger;
@@ -48,7 +49,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private HashMap<String, DataType> recipeDataTypes = new HashMap<>();
- public BluePrintEnhancerService(BluePrintEnhancerRepoService bluePrintEnhancerRepoDBService) {
+ public BluePrintEnhancerService(BluePrintRepoService bluePrintEnhancerRepoDBService) {
super(bluePrintEnhancerRepoDBService);
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java new file mode 100644 index 00000000..4c11d8c6 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java @@ -0,0 +1,94 @@ +/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
+import org.onap.ccsdk.apps.controllerblueprints.core.data.*;
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService;
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
+import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository;
+import org.springframework.stereotype.Service;
+import reactor.core.publisher.Mono;
+
+import java.util.Optional;
+
+/**
+ * BluePrintRepoDBService
+ *
+ * @author Brinda Santh
+ */
+@Service
+public class BluePrintRepoDBService implements BluePrintRepoService {
+
+ private ModelTypeRepository modelTypeRepository;
+
+ public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) {
+ this.modelTypeRepository = modelTypeRepository;
+ }
+
+ @Override
+ public Mono<NodeType> getNodeType(String nodeTypeName) throws BluePrintException {
+ return getModelType(nodeTypeName, NodeType.class);
+ }
+
+ @Override
+ public Mono<DataType> getDataType(String dataTypeName) throws BluePrintException {
+ return getModelType(dataTypeName, DataType.class);
+ }
+
+ @Override
+ public Mono<ArtifactType> getArtifactType(String artifactTypeName) throws BluePrintException {
+ return getModelType(artifactTypeName, ArtifactType.class);
+ }
+
+ @Override
+ public Mono<RelationshipType> getRelationshipType(String relationshipTypeName) throws BluePrintException {
+ return getModelType(relationshipTypeName, RelationshipType.class);
+ }
+
+ @Override
+ public Mono<CapabilityDefinition> getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException {
+ return getModelType(capabilityDefinitionName, CapabilityDefinition.class);
+ }
+
+ private <T> Mono<T> getModelType(String modelName, Class<T> valueClass) throws BluePrintException {
+ Preconditions.checkArgument(StringUtils.isNotBlank(modelName),
+ "Failed to get model from repo, model name is missing");
+
+ return getModelDefinitions(modelName).map(content -> {
+ Preconditions.checkArgument(StringUtils.isNotBlank(content),
+ String.format("Failed to get model content for model name (%s)", modelName));
+ return JacksonUtils.readValue(content, valueClass);
+ }
+ );
+ }
+
+ private Mono<String> getModelDefinitions(String modelName) throws BluePrintException {
+ String modelDefinition = null;
+ Optional<ModelType> modelTypeDb = modelTypeRepository.findByModelName(modelName);
+ if (modelTypeDb.isPresent()) {
+ modelDefinition = modelTypeDb.get().getDefinition();
+ } else {
+ throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName));
+ }
+ return Mono.just(modelDefinition);
+ }
+}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 9ab319cb..3a5c4fde 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -1,5 +1,6 @@ /*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service;
+import com.google.common.base.Preconditions;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@@ -26,7 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType; import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType;
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType;
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
@@ -160,26 +162,21 @@ public class DataBaseInitService { fileName = file.getFilename();
log.trace("Loading : {}", fileName);
String definitionContent = getResourceContent(file);
- DictionaryDefinition dictionaryDefinition =
- JacksonUtils.readValue(definitionContent, DictionaryDefinition.class);
+ ResourceDefinition dictionaryDefinition =
+ JacksonUtils.readValue(definitionContent, ResourceDefinition.class);
if (dictionaryDefinition != null) {
+ Preconditions.checkNotNull(dictionaryDefinition.getProperty(), "Failed to get Property Definition");
ResourceDictionary resourceDictionary = new ResourceDictionary();
resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath());
resourceDictionary.setName(dictionaryDefinition.getName());
resourceDictionary.setDefinition(definitionContent);
- if (dictionaryDefinition.getValidValues() != null)
- resourceDictionary
- .setValidValues(String.valueOf(dictionaryDefinition.getValidValues()));
-
- if (dictionaryDefinition.getSampleValue() != null)
- resourceDictionary
- .setValidValues(String.valueOf(dictionaryDefinition.getSampleValue()));
-
resourceDictionary.setResourceType(dictionaryDefinition.getResourceType());
- resourceDictionary.setDataType(dictionaryDefinition.getDataType());
- resourceDictionary.setEntrySchema(dictionaryDefinition.getEntrySchema());
- resourceDictionary.setDescription(dictionaryDefinition.getDescription());
+ resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription());
+ resourceDictionary.setDataType(dictionaryDefinition.getProperty().getType());
+ if(dictionaryDefinition.getProperty().getEntrySchema() != null){
+ resourceDictionary.setEntrySchema(dictionaryDefinition.getProperty().getEntrySchema().getType());
+ }
resourceDictionary.setUpdatedBy(dictionaryDefinition.getUpdatedBy());
if (StringUtils.isBlank(dictionaryDefinition.getTags())) {
resourceDictionary.setTags(
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java index b9567db1..629b94c0 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java @@ -1,5 +1,6 @@ /*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +17,13 @@ package org.onap.ccsdk.apps.controllerblueprints.service;
+import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
+import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema;
+import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository;
import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator;
@@ -40,19 +44,23 @@ public class ResourceDictionaryService { private ResourceDictionaryRepository resourceDictionaryRepository;
+ private ResourceDictionaryValidationService resourceDictionaryValidationService;
+
/**
* This is a DataDictionaryService, used to save and get the Resource Mapping stored in database
- *
+ *
* @param dataDictionaryRepository
- *
+ * @param resourceDictionaryValidationService
*/
- public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository) {
+ public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository,
+ ResourceDictionaryValidationService resourceDictionaryValidationService) {
this.resourceDictionaryRepository = dataDictionaryRepository;
+ this.resourceDictionaryValidationService = resourceDictionaryValidationService;
}
/**
* This is a getDataDictionaryByName service
- *
+ *
* @param name
* @return DataDictionary
* @throws BluePrintException
@@ -67,7 +75,7 @@ public class ResourceDictionaryService { /**
* This is a searchResourceDictionaryByNames service
- *
+ *
* @param names
* @return List<ResourceDictionary>
* @throws BluePrintException
@@ -83,7 +91,7 @@ public class ResourceDictionaryService { /**
* This is a searchResourceDictionaryByTags service
- *
+ *
* @param tags
* @return List<ResourceDictionary>
* @throws BluePrintException
@@ -98,63 +106,64 @@ public class ResourceDictionaryService { /**
* This is a saveDataDictionary service
- *
+ *
* @param resourceDictionary
* @return DataDictionary
* @throws BluePrintException
*/
public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary)
throws BluePrintException {
- if (resourceDictionary != null) {
- ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);
-
- DictionaryDefinition dictionaryDefinition =
- JacksonUtils.readValue(resourceDictionary.getDefinition(), DictionaryDefinition.class);
-
- if (dictionaryDefinition == null) {
- throw new BluePrintException(
- "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition());
- }
-
- dictionaryDefinition.setName(resourceDictionary.getName());
- dictionaryDefinition.setResourcePath(resourceDictionary.getResourcePath());
- dictionaryDefinition.setResourceType(resourceDictionary.getResourceType());
- dictionaryDefinition.setDataType(resourceDictionary.getDataType());
- dictionaryDefinition.setEntrySchema(resourceDictionary.getEntrySchema());
- dictionaryDefinition.setTags(resourceDictionary.getTags());
- dictionaryDefinition.setDescription(resourceDictionary.getDescription());
- dictionaryDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());
-
- String definitionContent = JacksonUtils.getJson(dictionaryDefinition, true);
- resourceDictionary.setDefinition(definitionContent);
-
- Optional<ResourceDictionary> dbResourceDictionaryData =
- resourceDictionaryRepository.findByName(resourceDictionary.getName());
- if (dbResourceDictionaryData.isPresent()) {
- ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get();
-
- dbResourceDictionary.setName(resourceDictionary.getName());
- dbResourceDictionary.setDefinition(resourceDictionary.getDefinition());
- dbResourceDictionary.setDescription(resourceDictionary.getDescription());
- dbResourceDictionary.setResourceType(resourceDictionary.getResourceType());
- dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath());
- dbResourceDictionary.setDataType(resourceDictionary.getDataType());
- dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema());
- dbResourceDictionary.setTags(resourceDictionary.getTags());
- dbResourceDictionary.setValidValues(resourceDictionary.getValidValues());
- resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary);
- } else {
- resourceDictionary = resourceDictionaryRepository.save(resourceDictionary);
- }
+ Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing");
+ Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()),
+ "Resource Dictionary definition information is missing");
+
+ ResourceDefinition resourceDefinition =
+ JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);
+ // Validate the Resource Definitions
+ resourceDictionaryValidationService.validate(resourceDefinition);
+
+ resourceDictionary.setResourceType(resourceDefinition.getResourceType());
+ resourceDictionary.setResourcePath(resourceDefinition.getResourcePath());
+ resourceDictionary.setTags(resourceDefinition.getTags());
+ resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());
+ // Set the Property Definitions
+ PropertyDefinition propertyDefinition = resourceDefinition.getProperty();
+ resourceDictionary.setDescription(propertyDefinition.getDescription());
+ resourceDictionary.setDataType(propertyDefinition.getType());
+ if(propertyDefinition.getEntrySchema() != null){
+ resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType());
+ }
+
+ String definitionContent = JacksonUtils.getJson(resourceDefinition, true);
+ resourceDictionary.setDefinition(definitionContent);
+
+ ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);
+
+ Optional<ResourceDictionary> dbResourceDictionaryData =
+ resourceDictionaryRepository.findByName(resourceDictionary.getName());
+ if (dbResourceDictionaryData.isPresent()) {
+ ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get();
+
+ dbResourceDictionary.setName(resourceDictionary.getName());
+ dbResourceDictionary.setDefinition(resourceDictionary.getDefinition());
+ dbResourceDictionary.setDescription(resourceDictionary.getDescription());
+ dbResourceDictionary.setResourceType(resourceDictionary.getResourceType());
+ dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath());
+ dbResourceDictionary.setTags(resourceDictionary.getTags());
+ dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy());
+ dbResourceDictionary.setDataType(resourceDictionary.getDataType());
+ dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema());
+ resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary);
} else {
- throw new BluePrintException("Resource Dictionary information is missing");
+ resourceDictionary = resourceDictionaryRepository.save(resourceDictionary);
}
+
return resourceDictionary;
}
/**
* This is a deleteResourceDictionary service
- *
+ *
* @param name
* @throws BluePrintException
*/
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java new file mode 100644 index 00000000..7de7fc4c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java @@ -0,0 +1,31 @@ +/* + * Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.service; + +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDictionaryDefaultValidationService; +import org.springframework.stereotype.Service; + +@Service +public class ResourceDictionaryValidationService extends ResourceDictionaryDefaultValidationService { + + private BluePrintRepoService bluePrintRepoService; + + public ResourceDictionaryValidationService(BluePrintRepoService bluePrintRepoService) { + super(bluePrintRepoService); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java index 85f256ea..1201f6b4 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java @@ -1,5 +1,6 @@ /*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +20,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType;
import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityDefinition;
import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType;
@@ -53,54 +53,6 @@ public class ModelTypeValidator { return validTypes;
}
- @Deprecated
- private static List<String> getValidModelDerivedFrom(String definitionType) {
- List<String> validTypes = new ArrayList<>();
- if (StringUtils.isNotBlank(definitionType)) {
- if (BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE.equalsIgnoreCase(definitionType)) {
- validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_DG);
- validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT);
- validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_VNF);
- validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT);
- } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE.equalsIgnoreCase(definitionType)) {
- validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_NETCONF);
- validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_SSH);
- validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_SFTP);
- validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_CHEF);
- validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_ANSIBLEF);
- } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE.equalsIgnoreCase(definitionType)) {
- validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON);
- validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_HOSTED_ON);
- validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO);
- validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ATTACH_TO);
- validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROUTES_TO);
- }
-
- }
- return validTypes;
- }
-
- /**
- * This is a validateNodeType
- *
- * @param definitionType
- * @param derivedFrom
- * @return boolean
- * @throws BluePrintException
- */
- public static boolean validateNodeType(String definitionType, String derivedFrom) throws BluePrintException {
- boolean valid = true;
- if (!BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)
- && !BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE.equalsIgnoreCase(definitionType)) {
- List<String> validTypes = getValidModelDerivedFrom(definitionType);
- if (!validTypes.contains(derivedFrom)) {
- throw new BluePrintException(
- "Not Valid Model Type (" + derivedFrom + "), It sould be " + validTypes);
- }
- }
- return valid;
- }
-
/**
* This is a validateModelTypeDefinition
*
@@ -187,8 +139,6 @@ public class ModelTypeValidator { validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition());
- validateNodeType(modelType.getDefinitionType(), modelType.getDerivedFrom());
-
} else {
throw new BluePrintException("Model Type Information is missing.");
}
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java index 73d6eca9..8257dc36 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java @@ -1,5 +1,6 @@ /*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,14 +51,6 @@ public class ResourceDictionaryRestTest { @Autowired
protected ResourceDictionaryRest resourceDictionaryRest;
- @Before
- public void setUp() {
- SourceDeserializer.registerSource("db", SourceDb.class);
- SourceDeserializer.registerSource("input", SourceInput.class);
- SourceDeserializer.registerSource("mdsal", SourceMdsal.class);
- SourceDeserializer.registerSource("default", SourceDefault.class);
- }
-
@Test
public void test01SaveDataDictionary() throws Exception {
String definition = IOUtils.toString(
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json index 2b392054..198823bb 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json +++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json @@ -1,19 +1,19 @@ {
- "name": "v4-aggregat-list",
- "description": "This collection v4-aggregate list",
- "valid-values": null,
- "sample-value": null,
- "updated-by": "Brinda Santh (bs2796)",
- "resource-type": "ONAP",
- "resource-path": "/v4-aggregat-list",
- "data-type": "list",
- "entry-schema": "dt-v4-aggregate",
- "tags": null,
- "default": null,
- "source": {
- "input": {
-
- }
- },
- "candidate-dependency": null
+ "name": "ipaddress",
+ "property": {
+ "description": "name of the ",
+ "type": "list",
+ "entry_schema": {
+ "type": "dt-v4-aggregate"
+ }
+ },
+ "updated-by": "Brinda Santh (bs2796)",
+ "resource-type": "ONAP",
+ "resource-path": "/v4-aggregat-list",
+ "tags": "ipaddress",
+ "sources": {
+ "input": {
+ "type": "source-input"
+ }
+ }
}
\ No newline at end of file |