From b35d55e3f57630551f0b773674bd1f5c44585ede Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Thu, 9 Aug 2018 20:47:29 +0000 Subject: Controller Blueprints MS Creating the base directory structure for Controller Blueprints MicroService Change-Id: I1ccf7fc76446048af3b2822f9155bb634657aee3 Issue-ID: CCSDK-410 Signed-off-by: Singal, Kapil (ks220y) --- .../dict/util/ResourceDictionaryUtilsTest.java | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java new file mode 100644 index 000000000..22b01c4a8 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java @@ -0,0 +1,165 @@ +/* + * 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.resource.dict.util; + + +import com.fasterxml.jackson.databind.JsonNode; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; +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.*; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class ResourceDictionaryUtilsTest { + private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class); + + @Test + public void validateSingleInputSource() { + try { + log.info(" **************** Validating validateSingleSource *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); + dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); + + Map source = new HashMap<>(); + SourceInput sourceInput = new SourceInput(); + source.put(ConfigModelConstant.SOURCE_INPUT, JacksonUtils.jsonNodeFromObject(sourceInput)); + dictionaryDefinition.setSource(source); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); + Assert.assertNotNull("Resource assignment input source is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment input source property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment input source property type is missing ", + resourceAssignment.getProperty().getType()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void validateSingleDbSource() { + try { + log.info(" **************** Validating validateSingleSource *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-db-key"); + DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); + dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); + + Map source = new HashMap<>(); + SourceDb sourceDb = new SourceDb(); + source.put(ConfigModelConstant.SOURCE_DB, JacksonUtils.jsonNodeFromObject(sourceDb)); + dictionaryDefinition.setSource(source); + + Map dependency = new HashMap<>(); + DictionaryDependency dependencyDb = new DictionaryDependency(); + dependencyDb.setNames(Arrays.asList("vnf-id", "vnf-name")); + dependency.put(ConfigModelConstant.SOURCE_DB, dependencyDb); + dictionaryDefinition.setDependency(dependency); + + DecryptionRule decryptionRule = new DecryptionRule(); + decryptionRule.setDecryptType("sample Type"); + decryptionRule.setPath("$."); + decryptionRule.setRule("Sample Rule"); + decryptionRule.setSources(Arrays.asList("vnf-id")); + dictionaryDefinition.setDecryptionRules(Arrays.asList(decryptionRule)); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); + Assert.assertNotNull("Resource assignment db source source is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment db source source property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment db source source property type is missing ", + resourceAssignment.getProperty().getType()); + + Assert.assertNotNull("Resource assignment db dependecy is missing ", resourceAssignment.getDependencies()); + Assert.assertEquals("Resource assignment db dependecy count mismatch ", 2, + resourceAssignment.getDependencies().size()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testSourceDefault() { + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + + DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); + dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); + + Map source = new HashMap<>(); + SourceDefault sourceDefault = new SourceDefault(); + source.put(ConfigModelConstant.SOURCE_DEFAULT, JacksonUtils.jsonNodeFromObject(sourceDefault)); + dictionaryDefinition.setSource(source); + + Map dependency = new HashMap<>(); + DictionaryDependency dependencyDefault = new DictionaryDependency(); + dependencyDefault.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); + dependency.put(ConfigModelConstant.SOURCE_DEFAULT, dependencyDefault); + dictionaryDefinition.setDependency(dependency); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); + + Assert.assertNotNull("Resource assignment default source is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment default source property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment default source property type is missing ", + resourceAssignment.getProperty().getType()); + } + + @Test + public void testSourceMdsal() { + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); + dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); + + Map source = new HashMap<>(); + SourceMdsal sourceMdsal = new SourceMdsal(); + source.put(ConfigModelConstant.SOURCE_MDSAL, JacksonUtils.jsonNodeFromObject(sourceMdsal)); + dictionaryDefinition.setSource(source); + + Map dependency = new HashMap<>(); + DictionaryDependency dependencyMdsal = new DictionaryDependency(); + dependencyMdsal.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); + dependency.put(ConfigModelConstant.SOURCE_MDSAL, dependencyMdsal); + dictionaryDefinition.setDependency(dependency); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); + + Assert.assertNotNull("Resource assignment mdsal source is missing ", resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment mdsal source property is missing ", resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment mdsal source property type is missing ", + resourceAssignment.getProperty().getType()); + } + +} -- cgit 1.2.3-korg From 5285007a4e66bc18c69cef96aa32326a139d7642 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 21 Aug 2018 04:11:57 +0000 Subject: Controller Blueprints Microservice Define Controllerblueprint API DataType and Error definitions for Config model, Service Template, Model Type and Resource Dictionary Services Change-Id: I12d8d87292ec101601b0cfb7ba9670730973e318 Issue-ID: CCSDK-469 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- ms/controllerblueprints/README.md | 9 +++ .../artifact_type/artifact-bpmn-camunda.json | 8 +++ .../artifact_type/artifact-directed-graph.json | 9 +++ .../opt/app/onap/config/application.properties | 3 + .../ApplicationExceptionHandler.java | 42 +++++++++++++ .../apps/controllerblueprints/CorsConfig.java | 27 +++++---- .../ControllerBluprintsApplicationTest.java | 22 +++++-- .../src/test/resources/application.properties | 2 +- .../application/src/test/resources/logback.xml | 3 +- .../artifact_type/artifact-bpmn-camunda.json | 8 +++ .../artifact_type/artifact-directed-graph.json | 9 +++ .../core/ConfigModelConstant.kt | 5 -- .../core/data/BluePrintModel.kt | 9 ++- .../core/utils/JacksonUtils.kt | 7 +++ .../load/resource_dictionary/db-source.json | 31 ++++++++++ .../load/resource_dictionary/default-source.json | 14 +++++ .../load/resource_dictionary/input-source.json | 17 ++++++ .../load/resource_dictionary/mdsal-source.json | 36 +++++++++++ .../resource/dict/ResourceAssignment.java | 6 +- .../resource/dict/ResourceDictionaryConstants.java | 24 ++++++++ .../resource/dict/data/DictionaryDefinition.java | 11 ++-- .../resource/dict/data/ResourceSource.java | 22 +++++++ .../resource/dict/data/SourceDb.java | 2 +- .../resource/dict/data/SourceDefault.java | 2 +- .../resource/dict/data/SourceDeserializer.java | 67 +++++++++++++++++++++ .../resource/dict/data/SourceInput.java | 3 +- .../resource/dict/data/SourceMdsal.java | 3 +- .../dict/utils/ResourceDictionaryUtils.java | 10 ++-- .../dict/util/DictionaryDefinitionTest.java | 70 ++++++++++++++++++++++ .../dict/util/ResourceDictionaryUtilsTest.java | 27 ++++----- .../load/resource_dictionary/action-name.json | 17 ------ .../load/resource_dictionary/bundle-id.json | 32 ---------- .../load/resource_dictionary/db-source.json | 31 ++++++++++ .../load/resource_dictionary/input-source.json | 17 ++++++ .../load/resource_dictionary/v4-ip-type.json | 4 +- .../service/ApplicationRegistrationService.java | 39 ++++++++++++ .../service/common/ErrorMessage.java | 32 ++++++---- .../service/domain/ConfigModel.java | 8 ++- .../service/domain/ConfigModelContent.java | 6 +- .../service/domain/ModelType.java | 12 +++- .../service/domain/ResourceDictionary.java | 11 ++++ .../service/rs/ConfigModelRest.java | 21 ++++--- .../service/rs/ModelTypeRest.java | 11 ++-- .../service/rs/ResourceDictionaryRest.java | 11 ++-- .../service/rs/ServiceTemplateRest.java | 13 ++-- .../service/rs/ResourceDictionaryRestTest.java | 6 +- 46 files changed, 625 insertions(+), 154 deletions(-) create mode 100644 ms/controllerblueprints/application/load/model_type/artifact_type/artifact-bpmn-camunda.json create mode 100644 ms/controllerblueprints/application/load/model_type/artifact_type/artifact-directed-graph.json create mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java create mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json create mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java delete mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/action-name.json delete mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/bundle-id.json create mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json create mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/README.md b/ms/controllerblueprints/README.md index e69de29bb..070a54169 100755 --- a/ms/controllerblueprints/README.md +++ b/ms/controllerblueprints/README.md @@ -0,0 +1,9 @@ +Application VM Arguments : + +-Dlogging.config=etc/logback.xml +-Dspring.config.location=opt/app/onap/config/ +-Dspring.datasource.url=jdbc:mysql://127.0.0.1:3306/sdnctl +-Dspring.datasource.username=sdnctl +-Dspring.datasource.password=sdnctl +-Dblueprints.load.initial-data=true + diff --git a/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-bpmn-camunda.json b/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-bpmn-camunda.json new file mode 100644 index 000000000..ac76b4f4f --- /dev/null +++ b/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-bpmn-camunda.json @@ -0,0 +1,8 @@ +{ + "description": " Camunda BPM File", + "version": "1.0.0", + "file_ext": [ + "bpmn" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-directed-graph.json b/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-directed-graph.json new file mode 100644 index 000000000..7ab3a5434 --- /dev/null +++ b/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-directed-graph.json @@ -0,0 +1,9 @@ +{ + "description": "Directed Graph File", + "version": "1.0.0", + "file_ext": [ + "json", + "xml" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/opt/app/onap/config/application.properties b/ms/controllerblueprints/application/opt/app/onap/config/application.properties index 9fa8e04cf..f075b578e 100644 --- a/ms/controllerblueprints/application/opt/app/onap/config/application.properties +++ b/ms/controllerblueprints/application/opt/app/onap/config/application.properties @@ -20,6 +20,9 @@ logging.level.org.springframework.web=INFO logging.level.org.hibernate.SQL=warn logging.level.org.hibernate.type.descriptor.sql=debug +#To Remove Null in JSON API Response +spring.jackson.default-property-inclusion=non_null + spring.jpa.properties.hibernate.show_sql=true spring.jpa.properties.hibernate.use_sql_comments=true spring.jpa.properties.hibernate.format_sql=true diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java new file mode 100644 index 000000000..d02be5c26 --- /dev/null +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java @@ -0,0 +1,42 @@ +/* + * 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; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.common.ErrorMessage; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.WebRequest; + +@ControllerAdvice +@RestController +public class ApplicationExceptionHandler { + @ExceptionHandler(Exception.class) + public final ResponseEntity handleAllExceptions(Exception ex, WebRequest request) { + ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getLocalizedMessage()); + return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler(BluePrintException.class) + public final ResponseEntity handleBlueprintException(BluePrintException ex, WebRequest request) { + ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), ex.getCode(), ex.getLocalizedMessage()); + return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); + } +} diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java index 5d682ed50..d00d2c845 100644 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java @@ -20,8 +20,9 @@ package org.onap.ccsdk.apps.controllerblueprints; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; +import java.util.Arrays; /** * CorsConfig.java Purpose: Provide Configuration Generator CorsConfig Information @@ -29,7 +30,7 @@ import org.springframework.web.filter.CorsFilter; * @author Brinda Santh * @version 1.0 */ -//@Configuration +@Configuration public class CorsConfig { /** * This is a CORS Implementation for different Orgin GUI to access. @@ -37,15 +38,17 @@ public class CorsConfig { * @return CorsFilter */ @Bean - public CorsFilter corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOrigin("*"); - config.addAllowedHeader("*"); - config.addAllowedMethod("*"); - source.registerCorsConfiguration("/**", config); - return new CorsFilter(source); + CorsWebFilter corsWebFilter() { + CorsConfiguration corsConfig = new CorsConfiguration(); + corsConfig.setAllowedOrigins(Arrays.asList("*")); + corsConfig.setMaxAge(8000L); + corsConfig.addAllowedMethod("*"); + + UrlBasedCorsConfigurationSource source = + new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", corsConfig); + + return new CorsWebFilter(source); } diff --git a/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java b/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java index 95639bd32..26b943b61 100644 --- a/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java +++ b/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java @@ -16,17 +16,18 @@ package org.onap.ccsdk.apps.controllerblueprints; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -46,8 +47,21 @@ public class ControllerBluprintsApplicationTest { @Test public void testConfigModel() { - ResponseEntity entity = this.restTemplate - .getForEntity("/api/v1/config-model/1", String.class); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + ResponseEntity entity = this.restTemplate + .exchange("/api/v1/config-model/1", HttpMethod.GET, new HttpEntity<>(headers),ConfigModel.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + Assert.assertNotNull("failed to get response Config model",entity.getBody()); + } + + @Test + public void testConfigModelFailure() { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + ResponseEntity entity = this.restTemplate + .exchange("/api/v1/config-model-not-found/1", HttpMethod.GET, new HttpEntity<>(headers),ConfigModel.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + Assert.assertNotNull("failed to get response Config model",entity.getBody()); } } diff --git a/ms/controllerblueprints/application/src/test/resources/application.properties b/ms/controllerblueprints/application/src/test/resources/application.properties index 55ffeaf16..a147034f8 100644 --- a/ms/controllerblueprints/application/src/test/resources/application.properties +++ b/ms/controllerblueprints/application/src/test/resources/application.properties @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # - +spring.jackson.default-property-inclusion=non_null #Load Blueprints # blueprints.load.initial-data may be overridden by ENV variables blueprints.load.initial-data=true diff --git a/ms/controllerblueprints/application/src/test/resources/logback.xml b/ms/controllerblueprints/application/src/test/resources/logback.xml index b9b97dc89..53388bc9e 100644 --- a/ms/controllerblueprints/application/src/test/resources/logback.xml +++ b/ms/controllerblueprints/application/src/test/resources/logback.xml @@ -24,8 +24,7 @@ - - + diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json new file mode 100644 index 000000000..ac76b4f4f --- /dev/null +++ b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json @@ -0,0 +1,8 @@ +{ + "description": " Camunda BPM File", + "version": "1.0.0", + "file_ext": [ + "bpmn" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json new file mode 100644 index 000000000..7ab3a5434 --- /dev/null +++ b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json @@ -0,0 +1,9 @@ +{ + "description": "Directed Graph File", + "version": "1.0.0", + "file_ext": [ + "json", + "xml" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt index bb5a78fd9..978269125 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt @@ -42,11 +42,6 @@ object ConfigModelConstant { const val CAPABILITY_PROPERTY_MAPPING = "mapping" - const val SOURCE_INPUT = "input" - const val SOURCE_DEFAULT = "default" - const val SOURCE_MDSAL = "mdsal" - const val SOURCE_DB = "db" - const val PROPERTY_RECIPE_NAMES = "action-names" } diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt index 6d677ffae..a10f6d30c 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -155,7 +155,7 @@ class PropertyDefinition { var id: String? = null var description: String? = null var required: Boolean? = null - var type: String? = null + lateinit var type: String @get:JsonProperty("default") var defaultValue: Any? = null var status: String? = null @@ -202,7 +202,7 @@ class OperationDefinition { } class Implementation { - var primary: String? = null + lateinit var primary: String var dependencies: MutableList? = null } @@ -240,6 +240,11 @@ class TriggerDefinition { var description: String? = null @get:JsonProperty("event_type") lateinit var eventType: String + @get:JsonProperty("target_filter") + var targetFilter: EventFilterDefinition? = null + var condition: ConditionClause? = null + var constraint: ConditionClause? = null + var method: String? = null lateinit var action: String } diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 95b2af7b7..9621382c3 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -49,6 +49,13 @@ object JacksonUtils { return jacksonObjectMapper().readValue(content, valueType) } + @JvmStatic + fun readValueFromFile(fileName: String, valueType: Class): T? { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) + return readValue(content, valueType) + } + @JvmStatic fun jsonNodeFromObject(from: kotlin.Any): JsonNode = jacksonObjectMapper().convertValue(from, JsonNode::class.java) diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json new file mode 100644 index 000000000..8b97cdeb7 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json @@ -0,0 +1,31 @@ +{ + "name": "bundle-id", + "description": "name of the ", + "resource-type": "ONAP", + "resource-path": "vnf/bundle-id", + "updated-by": "brindasanth@onap.com", + "data-type": "String", + "tags": "bundle-id, brindasanth@onap.com", + "source": { + "db": { + "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" + } + } + }, + "decryption-rules": [ + { + "sources": [ + "input" + ], + "path": "/.", + "rule": "LOCAL-Decrypt", + "decrypt-type": "AES128" + } + ] +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json new file mode 100644 index 000000000..ac23292ed --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json @@ -0,0 +1,14 @@ +{ + "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": { + "default": { + + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json new file mode 100644 index 000000000..35736b663 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json @@ -0,0 +1,17 @@ +{ + "name": "action-name", + "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": { + "input": { + "key": "action-name" + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json new file mode 100644 index 000000000..c103f94dc --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json @@ -0,0 +1,36 @@ +{ + "tags": "oam-local-ipv4-address, tosca.datatypes.Root, data_type, st1848@att.com", + "name": "oam-local-ipv4-address", + "description": "based on service-instance-id,network-role,v4-ip-type and vm-type get the ipv4-gateway-prefix from the SDN-GC mdsal", + "updated-by": "st1848@att.com", + "resource-type": "ATT", + "resource-path": "vnf/oam-local-ipv4-address", + "data-type": "string", + "source": { + "mdsal": { + "base": "sdnc-gc", + "type": "JSON", + "url-path": "config/L3VNF-API:services/service-list/$service-instance-id/service-data/vnf-topology-information/vnf-assignments/vnf-vms/$vm-type/vm-networks/$network-role/v4-assigned-ip-list/$v4-ip-type", + "path": "/v4-assigned-ip-list/0/v4-ip-prefix", + "input-key-mapping": { + "service-instance-id": "service-instance-id", + "network-role": "network-role", + "v4-ip-type": "v4-ip-type", + "vm-type": "vm-type" + }, + "output-key-mapping": { + "oam-local-ipv4-address": "v4-ip-prefix" + } + } + }, + "candidate-dependency": { + "mdsal": { + "names": [ + "service-instance-id", + "network-role", + "v4-ip-type", + "vm-type" + ] + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java index 15576b906..f85e5ebcd 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java @@ -30,10 +30,10 @@ import java.util.List; * @version 1.0 */ public class ResourceAssignment { - + @JsonProperty(value = "name", required = true) private String name; - @JsonProperty("property") + @JsonProperty(value = "property", required = true) private PropertyDefinition property; @JsonProperty("input-param") @@ -58,7 +58,7 @@ public class ResourceAssignment { private String message; @JsonProperty("updated-date") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private Date updatedDate; @JsonProperty("updated-by") diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java new file mode 100644 index 000000000..1af42c590 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java @@ -0,0 +1,24 @@ +/* + * 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.resource.dict; + +public class ResourceDictionaryConstants { + public static final String SOURCE_INPUT= "input"; + public static final String SOURCE_DEFAULT = "default"; + public static final String SOURCE_DB = "db"; + public static final String SOURCE_MDSAL = "mdsal"; +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java index 4dc9c89a1..7c2d926f0 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java @@ -17,7 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.util.List; import java.util.Map; @@ -29,6 +29,7 @@ import java.util.Map; public class DictionaryDefinition { @JsonProperty(value = "name", required = true) private String name; + @JsonProperty(value = "description") private String description; @@ -39,6 +40,7 @@ public class DictionaryDefinition { private String sampleValue; private String tags; + @JsonProperty(value = "updated-by") private String updatedBy; @@ -58,7 +60,8 @@ public class DictionaryDefinition { private Object defaultValue; @JsonProperty(value = "source", required = true) - private Map source; + @JsonDeserialize(using = SourceDeserializer.class, keyAs = String.class, contentAs = ResourceSource.class) + private Map source; @JsonProperty("candidate-dependency") private Map dependency; @@ -154,11 +157,11 @@ public class DictionaryDefinition { this.defaultValue = defaultValue; } - public Map getSource() { + public Map getSource() { return source; } - public void setSource(Map source) { + public void setSource(Map source) { this.source = source; } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java new file mode 100644 index 000000000..735832cb1 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java @@ -0,0 +1,22 @@ +/* + * 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.resource.dict.data; + +import java.io.Serializable; + +public interface ResourceSource extends Serializable { +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java index 23d404605..724d0224e 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java @@ -24,7 +24,7 @@ import java.util.Map; * SourceDb * @author Brinda Santh */ -public class SourceDb { +public class SourceDb implements ResourceSource{ @JsonProperty(value = "base", required = true) private String base; @JsonProperty(value = "type", required = true) diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java index 0a4351cca..d165192e9 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java @@ -20,7 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; * SourceDefault * @author Brinda Santh */ -public class SourceDefault { +public class SourceDefault implements ResourceSource { private String key; diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java new file mode 100644 index 000000000..86476e1c2 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java @@ -0,0 +1,67 @@ +/* + * 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.resource.dict.data; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.base.Preconditions; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class SourceDeserializer extends JsonDeserializer> { + + private static final Logger log = LoggerFactory.getLogger(SourceDeserializer.class); + + private Class keyAs; + + private Class contentAs; + + private static Map> registry = new HashMap>(); + + public static void registerSource(String uniqueAttribute, Class sourceClass) { + registry.put(uniqueAttribute, sourceClass); + } + + @Override + public Map deserialize(JsonParser p, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + ObjectMapper mapper = (ObjectMapper) p.getCodec(); + ObjectNode root = (ObjectNode) mapper.readTree(p); + Map sources = new HashMap(); + root.fields().forEachRemaining((node) -> { + String key = node.getKey(); + JsonNode valueNode = node.getValue(); + Preconditions.checkArgument(StringUtils.isNotBlank(key), "missing source key"); + Preconditions.checkArgument(registry.containsKey(key), key +" source not registered"); + if (StringUtils.isNotBlank(key) && registry.containsKey(key)) { + Class sourceClass = registry.get(key); + ResourceSource resourceSource = JacksonUtils.readValue(valueNode.toString(), sourceClass); + sources.put(key, resourceSource); + } + }); + return sources; + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java index 82cb769da..87184f223 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java @@ -20,7 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; * SourceInput * @author Brinda Santh */ -public class SourceInput { +public class SourceInput implements ResourceSource { private String key; @@ -33,5 +33,4 @@ public class SourceInput { } - } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java index 9eb233e76..8a066e91a 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Map; -public class SourceMdsal { +public class SourceMdsal implements ResourceSource { @JsonProperty(value = "base", required = true) private String base; @@ -93,5 +93,4 @@ public class SourceMdsal { } - } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java index 9d51d8213..4f9467f05 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java @@ -16,15 +16,15 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils; -import com.fasterxml.jackson.databind.JsonNode; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDependency; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.ResourceSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +63,7 @@ public class ResourceDictionaryUtils { // Overwrite the Property Definitions from Dictionary setProperty(resourceAssignment, dictionaryDefinition); - Map dictionarySource = dictionaryDefinition.getSource(); + Map dictionarySource = dictionaryDefinition.getSource(); Map dictionaryDependencyMap = dictionaryDefinition.getDependency(); if (MapUtils.isNotEmpty(dictionarySource)) { @@ -82,7 +82,7 @@ public class ResourceDictionaryUtils { } } } else { - resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_INPUT); + resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_INPUT); } log.info("auto map resourceAssignment : {}", resourceAssignment); } @@ -98,7 +98,7 @@ public class ResourceDictionaryUtils { } } - private static String findFirstSource(Map dictionarySource) { + private static String findFirstSource(Map dictionarySource) { String source = null; if (MapUtils.isNotEmpty(dictionarySource)) { source = dictionarySource.keySet().stream().findFirst().get(); diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java new file mode 100644 index 000000000..851ba1256 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java @@ -0,0 +1,70 @@ +/* + * 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.resource.dict.util; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DictionaryDefinitionTest { + private Logger log = LoggerFactory.getLogger(DictionaryDefinitionTest.class); + String basePath = "load/resource_dictionary"; + + @Before + public void setup(){ + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DB, SourceDb.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_INPUT, SourceInput.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_MDSAL, SourceMdsal.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DEFAULT,SourceDefault.class); + } + + @Test + public void testDictionaryDefinitionInputSource(){ + + String fileName = basePath + "/input-source.json"; + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", dictionaryDefinition); + } + + @Test + public void testDictionaryDefinitionDefaultSource(){ + + String fileName = basePath + "/default-source.json"; + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", dictionaryDefinition); + } + + @Test + public void testDictionaryDefinitionDBSource(){ + + String fileName = basePath + "/db-source.json"; + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", dictionaryDefinition); + } + + @Test + public void testDictionaryDefinitionMDSALSource(){ + String fileName = basePath + "/mdsal-source.json"; + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", dictionaryDefinition); + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java index 22b01c4a8..0c9a1c5d8 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java @@ -17,13 +17,11 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.util; -import com.fasterxml.jackson.databind.JsonNode; import org.junit.Assert; import org.junit.Test; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; -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.ResourceDictionaryConstants; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; import org.slf4j.Logger; @@ -45,9 +43,9 @@ public class ResourceDictionaryUtilsTest { DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - Map source = new HashMap<>(); + Map source = new HashMap<>(); SourceInput sourceInput = new SourceInput(); - source.put(ConfigModelConstant.SOURCE_INPUT, JacksonUtils.jsonNodeFromObject(sourceInput)); + source.put(ResourceDictionaryConstants.SOURCE_INPUT, sourceInput); dictionaryDefinition.setSource(source); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); @@ -72,15 +70,16 @@ public class ResourceDictionaryUtilsTest { DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - Map source = new HashMap<>(); + Map source = new HashMap<>(); SourceDb sourceDb = new SourceDb(); - source.put(ConfigModelConstant.SOURCE_DB, JacksonUtils.jsonNodeFromObject(sourceDb)); + sourceDb.setBase("sdnc_connection"); + source.put(ResourceDictionaryConstants.SOURCE_DB, sourceDb); dictionaryDefinition.setSource(source); Map dependency = new HashMap<>(); DictionaryDependency dependencyDb = new DictionaryDependency(); dependencyDb.setNames(Arrays.asList("vnf-id", "vnf-name")); - dependency.put(ConfigModelConstant.SOURCE_DB, dependencyDb); + dependency.put(ResourceDictionaryConstants.SOURCE_DB, dependencyDb); dictionaryDefinition.setDependency(dependency); DecryptionRule decryptionRule = new DecryptionRule(); @@ -115,15 +114,15 @@ public class ResourceDictionaryUtilsTest { DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - Map source = new HashMap<>(); + Map source = new HashMap<>(); SourceDefault sourceDefault = new SourceDefault(); - source.put(ConfigModelConstant.SOURCE_DEFAULT, JacksonUtils.jsonNodeFromObject(sourceDefault)); + source.put(ResourceDictionaryConstants.SOURCE_DEFAULT, sourceDefault); dictionaryDefinition.setSource(source); Map dependency = new HashMap<>(); DictionaryDependency dependencyDefault = new DictionaryDependency(); dependencyDefault.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); - dependency.put(ConfigModelConstant.SOURCE_DEFAULT, dependencyDefault); + dependency.put(ResourceDictionaryConstants.SOURCE_DEFAULT, dependencyDefault); dictionaryDefinition.setDependency(dependency); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); @@ -143,15 +142,15 @@ public class ResourceDictionaryUtilsTest { DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - Map source = new HashMap<>(); + Map source = new HashMap<>(); SourceMdsal sourceMdsal = new SourceMdsal(); - source.put(ConfigModelConstant.SOURCE_MDSAL, JacksonUtils.jsonNodeFromObject(sourceMdsal)); + source.put(ResourceDictionaryConstants.SOURCE_MDSAL,sourceMdsal); dictionaryDefinition.setSource(source); Map dependency = new HashMap<>(); DictionaryDependency dependencyMdsal = new DictionaryDependency(); dependencyMdsal.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); - dependency.put(ConfigModelConstant.SOURCE_MDSAL, dependencyMdsal); + dependency.put(ResourceDictionaryConstants.SOURCE_MDSAL, dependencyMdsal); dictionaryDefinition.setDependency(dependency); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/action-name.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/action-name.json deleted file mode 100644 index 92b64e629..000000000 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/action-name.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "action-name", - "resource-path": "action-name", - "resource-type": "ONAP", - "description": "To be provided", - "valid-values": null, - "sample-value": null, - "updated-by": "ym9479@onap.com", - "tags": null, - "default": null, - "data-type": "string", - "source": { - "input": { - "key": "action-name" - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/bundle-id.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/bundle-id.json deleted file mode 100644 index f9678f5ff..000000000 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/bundle-id.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "bundle-id", - "description": "name of the ", - "resource-type": "ONAP", - "resource-path": "vnf/bundle-id", - "updated-by": "ym9479@onap.com", - "data-type": "String", - "tags": "bundle-id, ym9479@onap.com", - "source": { - "db": { - "path": "$key-value", - "input-key-mapping": { - "key-value": "$resource-group-key" - }, - "output-key-mapping": { - "bundle-id": "bundle-id" - } - }, - "input": { - } - }, - "decryption-rules": [ - { - "sources": [ - "input" - ], - "path": "/.", - "rule": "LOCAL-Decrypt", - "decrypt-type": "AES128" - } - ] -} \ 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 new file mode 100644 index 000000000..862523544 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json @@ -0,0 +1,31 @@ +{ + "name": "bundle-id", + "description": "name of the ", + "resource-type": "ONAP", + "resource-path": "vnf/bundle-id", + "updated-by": "brindasanth@onap.com", + "data-type": "String", + "tags": "bundle-id, brindasanth@onap.com", + "source": { + "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" + } + } + }, + "decryption-rules": [ + { + "sources": [ + "input" + ], + "path": "/.", + "rule": "LOCAL-Decrypt", + "decrypt-type": "AES128" + } + ] +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json new file mode 100644 index 000000000..35736b663 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json @@ -0,0 +1,17 @@ +{ + "name": "action-name", + "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": { + "input": { + "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 03254b78a..c6c0f9851 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,8 +1,8 @@ { - "tags": "v4-ip-type, tosca.datatypes.Root, data_type, ym9479@onap.com", + "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", "name": "v4-ip-type", "description": "To be provided", - "updated-by": "ym9479@onap.com", + "updated-by": "brindasanth@onap.com", "resource-type": "ONAP", "resource-path": "vnf/v4-ip-type", "data-type": "string", diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java new file mode 100644 index 000000000..074f18d05 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java @@ -0,0 +1,39 @@ +/* + * 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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component +public class ApplicationRegistrationService { + + @PostConstruct + public void register(){ + registerDictionarySources(); + } + + public void registerDictionarySources(){ + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DB, SourceDb.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_INPUT, SourceInput.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_MDSAL, SourceMdsal.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DEFAULT,SourceDefault.class); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java index f7a802e46..431641265 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java @@ -16,24 +16,25 @@ package org.onap.ccsdk.apps.controllerblueprints.service.common; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import java.io.Serializable; +import java.util.Date; @JsonInclude(Include.NON_NULL) public class ErrorMessage implements Serializable { - private Integer httpStatus; private String message; private Integer code; - private String developerMessage; + private String debugMessage; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + private Date timestamp = new Date(); - public Integer getHttpStatus() { - return httpStatus; - } - - public void setHttpStatus(Integer httpStatus) { - this.httpStatus = httpStatus; + public ErrorMessage(String message, Integer code, String debugMessage){ + this.message = message; + this.code = code; + this.debugMessage = debugMessage; } public String getMessage() { @@ -52,12 +53,19 @@ public class ErrorMessage implements Serializable { this.code = code; } - public String getDeveloperMessage() { - return developerMessage; + public String getDebugMessage() { + return debugMessage; } - public void setDeveloperMessage(String developerMessage) { - this.developerMessage = developerMessage; + public void setDebugMessage(String developerMessage) { + this.debugMessage = developerMessage; } + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java index 224960fa5..45382815c 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonManagedReference; +import io.swagger.annotations.ApiModelProperty; import org.hibernate.annotations.Proxy; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -82,6 +83,7 @@ public class ConfigModel implements Serializable { @NotNull @Column(name = "artifact_version") + @ApiModelProperty(required=true) private String artifactVersion; @Lob @@ -91,7 +93,7 @@ public class ConfigModel implements Serializable { @Column(name = "internal_version") private Integer internalVersion; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -99,19 +101,23 @@ public class ConfigModel implements Serializable { @NotNull @Column(name = "artifact_name") + @ApiModelProperty(required=true) private String artifactName; @NotNull @Column(name = "published") + @ApiModelProperty(required=true) private String published; @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java index f7bd554df..0c05ef959 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -46,10 +47,12 @@ public class ConfigModelContent { @NotNull @Column(name = "name") + @ApiModelProperty(required=true) private String name; @NotNull @Column(name = "content_type") + @ApiModelProperty(required=true) private String contentType; @@ -65,10 +68,11 @@ public class ConfigModelContent { @NotNull @Lob @Column(name = "content") + @ApiModelProperty(required=true) private String content; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "updated_date") diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index ed6340a65..61e4d1189 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -40,36 +42,43 @@ public class ModelType implements Serializable { @Id @NotNull @Column(name = "model_name", nullable = false) + @ApiModelProperty(required=true) private String modelName; @NotNull @Column(name = "derived_from") + @ApiModelProperty(required=true) private String derivedFrom; @NotNull @Column(name = "definition_type") + @ApiModelProperty(required=true) private String definitionType; @NotNull @Lob @Column(name = "definition") + @ApiModelProperty(required=true) private String definition; @NotNull @Lob @Column(name = "description") + @ApiModelProperty(required=true) private String description; @NotNull @Column(name = "version") + @ApiModelProperty(required=true) private String version; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; - // @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -77,6 +86,7 @@ public class ModelType implements Serializable { @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @Override diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index adb018841..0d5879db8 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -39,18 +41,22 @@ public class ResourceDictionary implements Serializable { @Id @NotNull @Column(name = "name") + @ApiModelProperty(required=true) private String name; @NotNull @Column(name = "resource_path") + @ApiModelProperty(required=true) private String resourcePath; @NotNull @Column(name = "resource_type") + @ApiModelProperty(required=true) private String resourceType; @NotNull @Column(name = "data_type") + @ApiModelProperty(required=true) private String dataType; @Column(name = "entry_schema") @@ -67,18 +73,22 @@ public class ResourceDictionary implements Serializable { @NotNull @Lob @Column(name = "definition") + @ApiModelProperty(required=true) private String definition; @NotNull @Lob @Column(name = "description") + @ApiModelProperty(required=true) private String description; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -86,6 +96,7 @@ public class ResourceDictionary implements Serializable { @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @Override diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java index 94324a808..62b683032 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java @@ -19,8 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -29,7 +28,7 @@ import java.util.List; * {@inheritDoc} */ @RestController -@RequestMapping("/api/v1/config-model") +@RequestMapping(value = "/api/v1/config-model") public class ConfigModelRest { private ConfigModelService configModelService; @@ -44,7 +43,7 @@ public class ConfigModelRest { } - @GetMapping(path = "/initial/{name}") + @GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException { try { @@ -54,7 +53,7 @@ public class ConfigModelRest { } } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException { try { @@ -69,11 +68,11 @@ public class ConfigModelRest { try { this.configModelService.deleteConfigModel(id); } catch (Exception e) { - throw new BluePrintException(4000, e.getMessage(), e); + throw new BluePrintException(2400, e.getMessage(), e); } } - @GetMapping(path = "/publish/{id}") + @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { @@ -83,7 +82,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/{id}") + @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { @@ -93,7 +92,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/by-name/{name}/version/{version}") + @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name, @PathVariable(value = "version") String version) throws BluePrintException { @@ -104,7 +103,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException { try { @@ -114,7 +113,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/clone/{id}") + @GetMapping(path = "/clone/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 2fa64316f..f6e5c274f 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.*; @@ -29,7 +30,7 @@ import java.util.List; * {@inheritDoc} */ @RestController -@RequestMapping("/api/v1/model-type") +@RequestMapping(value = "/api/v1/model-type") public class ModelTypeRest { private ModelTypeService modelTypeService; @@ -43,7 +44,7 @@ public class ModelTypeRest { this.modelTypeService = modelTypeService; } - @GetMapping(path = "/{name}") + @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { try { return modelTypeService.getModelTypeByName(name); @@ -52,7 +53,7 @@ public class ModelTypeRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public List searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException { try { return modelTypeService.searchModelTypes(tags); @@ -61,7 +62,7 @@ public class ModelTypeRest { } } - @GetMapping(path = "/by-definition/{definitionType}") + @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException { try { @@ -71,7 +72,7 @@ public class ModelTypeRest { } } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index dfb06bba5..795738cb1 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -19,8 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -44,7 +43,7 @@ public class ResourceDictionaryRest { this.resourceDictionaryService = dataDictionaryService; } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { @@ -64,7 +63,7 @@ public class ResourceDictionaryRest { } } - @GetMapping(path = "/{name}") + @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { try { @@ -74,7 +73,7 @@ public class ResourceDictionaryRest { } } - @PostMapping(path = "/by-names") + @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByNames(@RequestBody List names) throws BluePrintException { @@ -85,7 +84,7 @@ public class ResourceDictionaryRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java index d8ea1941b..a22285b88 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java @@ -23,8 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.service.ServiceTemplateService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -47,7 +46,7 @@ public class ServiceTemplateRest { this.serviceTemplateService = serviceTemplateService; } - @PostMapping(path = "/enrich") + @PostMapping(path = "/enrich", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ServiceTemplate enrichServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { try { @@ -57,7 +56,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/validate") + @PostMapping(path = "/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ServiceTemplate validateServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { try { @@ -67,7 +66,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/auto-map") + @PostMapping(path = "/resource-assignment/auto-map", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody AutoMapResponse autoMap(@RequestBody List resourceAssignments) throws BluePrintException { try { @@ -77,7 +76,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/validate") + @PostMapping(path = "/resource-assignment/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List validateResourceAssignments(@RequestBody List resourceAssignments) throws BluePrintException { @@ -88,7 +87,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/generate") + @PostMapping(path = "/resource-assignment/generate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) throws BluePrintException { 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 afe9b426f..73d6eca99 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 @@ -24,6 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +52,10 @@ public class ResourceDictionaryRestTest { @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 -- cgit 1.2.3-korg From 7b23a92a3d079940193eaf141ff8494851b49d61 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Fri, 24 Aug 2018 22:48:32 -0400 Subject: Controller Blueprints Microservice Create resource definition and Create Source Node Type definitions for Input, default, db, mdsal and component sources. Change-Id: Icc49cb4be2e8700b61c281ff2d01c365321bb311 Issue-ID: CCSDK-487 Signed-off-by: Brinda Santh --- .../core/BluePrintProcessorException.kt | 49 ++++++ .../core/OrchestratorException.kt | 48 ------ .../core/service/BluePrintRuntimeService.kt | 5 +- .../node_type/source-component-java.json | 31 ++++ .../load/model_type/node_type/source-db.json | 44 ++++++ .../load/model_type/node_type/source-default.json | 18 +++ .../load/model_type/node_type/source-input.json | 18 +++ .../load/model_type/node_type/source-rest.json | 62 ++++++++ .../node_type/tosca.nodes.ResourceSource.json | 5 + .../load/resource_dictionary/db-source.json | 25 +-- .../load/resource_dictionary/default-source.json | 28 ++-- .../load/resource_dictionary/input-source.json | 16 +- .../load/resource_dictionary/mdsal-source.json | 54 +++---- .../resource/dict/ResourceAssignment.java | 167 --------------------- .../resource/dict/data/DictionaryDefinition.java | 2 + .../resource/dict/data/DictionaryDependency.java | 2 + .../resource/dict/data/SourceDb.java | 2 + .../resource/dict/data/SourceDefault.java | 2 + .../resource/dict/data/SourceDeserializer.java | 3 +- .../resource/dict/data/SourceInput.java | 2 + .../resource/dict/data/SourceMdsal.java | 3 +- .../resource/dict/ResourceAssignmentProcessor.kt | 34 +++++ .../resource/dict/ResourceDefinition.kt | 95 ++++++++++++ .../dict/util/DictionaryDefinitionTest.java | 70 --------- .../resource/dict/util/ResourceDefinitionTest.java | 61 ++++++++ .../dict/util/ResourceDictionaryUtilsTest.java | 18 ++- 26 files changed, 517 insertions(+), 347 deletions(-) create mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/OrchestratorException.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDefinitionTest.java (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt new file mode 100644 index 000000000..50717031d --- /dev/null +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt @@ -0,0 +1,49 @@ +/* + * 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.core +/** + * + * + * @author Brinda Santh + */ +class BluePrintProcessorException : Exception { + var code: Int = 100 + + constructor(message: String, cause: Throwable) : super(message, cause) + constructor(message: String) : super(message) + constructor(cause: Throwable) : super(cause) + constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) + + constructor(code: Int, cause: Throwable) : super(cause) { + this.code = code + } + + constructor(code: Int, message: String) : super(message) { + this.code = code + } + + constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { + this.code = code + } + + constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) + : super(String.format(message, *args), cause) { + this.code = code + } +} + diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/OrchestratorException.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/OrchestratorException.kt deleted file mode 100644 index 68abad154..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/OrchestratorException.kt +++ /dev/null @@ -1,48 +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.core -/** - * - * - * @author Brinda Santh - */ -class OrchestratorException : Exception { - var code: Int = 100 - - constructor(message: String, cause: Throwable) : super(message, cause) - constructor(message: String) : super(message) - constructor(cause: Throwable) : super(cause) - constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) - - constructor(code: Int, cause: Throwable) : super(cause) { - this.code = code - } - - constructor(code: Int, message: String) : super(message) { - this.code = code - } - - constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { - this.code = code - } - - constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) - : super(String.format(message, *args), cause) { - this.code = code - } -} - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index 213f5f401..08152313b 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -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. @@ -20,7 +21,7 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.NullNode import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.OrchestratorException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition @@ -154,7 +155,7 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) val artifactDefinition: ArtifactDefinition = nodeTemplate.artifacts?.get(artifactName) - ?: throw OrchestratorException(String.format("failed to get artifat definition {} from the node template" + ?: throw BluePrintProcessorException(String.format("failed to get artifat definition {} from the node template" , artifactName)) val propertyAssignmentExpression = PropertyAssignmentService( context, this) return propertyAssignmentExpression.artifactContent(artifactDefinition) diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json new file mode 100644 index 000000000..95a9801dc --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json @@ -0,0 +1,31 @@ +{ + "description": "This is Custom Java Component Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": false, + "type": "string", + "default" : "DYNAMIC", + "constraints": [ + { + "validValues": [ + "DYNAMIC" + ] + } + ] + }, + "class-name": { + "required": true, + "type": "string", + "description" : "Fully Qualified Class Name ( + . + )" + }, + "key-dependencies": { + "required": false, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json new file mode 100644 index 000000000..7ebeaa82c --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/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": [ + { + "validValues": [ + "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": false, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json new file mode 100644 index 000000000..dd0bffcc1 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/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": false, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json new file mode 100644 index 000000000..99c4691c4 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/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": false, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json new file mode 100644 index 000000000..e77020ec9 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json @@ -0,0 +1,62 @@ +{ + "description": "This is Rest Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "JSON", + "constraints": [ + { + "validValues": [ + "XML", + "JSON" + ] + } + ] + }, + "url-path": { + "required": true, + "type": "string" + }, + "path": { + "required": true, + "type": "string" + }, + "expression-type": { + "required": false, + "type": "string", + "default": "JSON_PATH", + "constraints": [ + { + "validValues": [ + "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": false, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json new file mode 100644 index 000000000..2ef553e24 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/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/resource-dict/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json index 8b97cdeb7..cd4e282b4 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json +++ b/ms/controllerblueprints/modules/resource-dict/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 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" + "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/resource-dict/load/resource_dictionary/default-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json index ac23292ed..91921b640 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json @@ -1,14 +1,18 @@ { - "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": { - "default": { - - } - } + "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", + "name": "v4-ip-type", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "resource-type": "ONAP", + "resource-path": "vnf/v4-ip-type", + "sources": { + "default": { + "type": "source-default", + "properties": { + } + } + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json index 35736b663..c34c252b3 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json +++ b/ms/controllerblueprints/modules/resource-dict/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": { + "sources": { "input": { - "key": "action-name" + "type": "source-input", + "properties": { + "key": "action-name" + } } } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json index c103f94dc..73d835c10 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json @@ -1,36 +1,36 @@ { - "tags": "oam-local-ipv4-address, tosca.datatypes.Root, data_type, st1848@att.com", + "tags": "oam-local-ipv4-address", "name": "oam-local-ipv4-address", - "description": "based on service-instance-id,network-role,v4-ip-type and vm-type get the ipv4-gateway-prefix from the SDN-GC mdsal", - "updated-by": "st1848@att.com", + "property" :{ + "description": "based on service-instance-id,network-role,v4-ip-type and vm-type get the ipv4-gateway-prefix from the SDN-GC mdsal", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", "resource-type": "ATT", "resource-path": "vnf/oam-local-ipv4-address", - "data-type": "string", - "source": { + "sources": { "mdsal": { - "base": "sdnc-gc", - "type": "JSON", - "url-path": "config/L3VNF-API:services/service-list/$service-instance-id/service-data/vnf-topology-information/vnf-assignments/vnf-vms/$vm-type/vm-networks/$network-role/v4-assigned-ip-list/$v4-ip-type", - "path": "/v4-assigned-ip-list/0/v4-ip-prefix", - "input-key-mapping": { - "service-instance-id": "service-instance-id", - "network-role": "network-role", - "v4-ip-type": "v4-ip-type", - "vm-type": "vm-type" - }, - "output-key-mapping": { - "oam-local-ipv4-address": "v4-ip-prefix" + "type": "source-rest", + "properties": { + "type": "JSON", + "url-path": "config/L3VNF-API:services/service-list/$service-instance-id/service-data/vnf-topology-information/vnf-assignments/vnf-vms/$vm-type/vm-networks/$network-role/v4-assigned-ip-list/$v4-ip-type", + "path": "/v4-assigned-ip-list/0/v4-ip-prefix", + "input-key-mapping": { + "service-instance-id": "service-instance-id", + "network-role": "network-role", + "v4-ip-type": "v4-ip-type", + "vm-type": "vm-type" + }, + "output-key-mapping": { + "oam-local-ipv4-address": "v4-ip-prefix" + }, + "key-dependency": [ + "service-instance-id", + "network-role", + "v4-ip-type", + "vm-type" + ] } } - }, - "candidate-dependency": { - "mdsal": { - "names": [ - "service-instance-id", - "network-role", - "v4-ip-type", - "vm-type" - ] - } } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java deleted file mode 100644 index f85e5ebcd..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java +++ /dev/null @@ -1,167 +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.resource.dict; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; - -import java.util.Date; -import java.util.List; - -/** - * ResourceAssignment.java Purpose: Provide ResourceAssignment Custom TOSCO Model POJO bean. - * - * @author Brinda Santh - * @version 1.0 - */ -public class ResourceAssignment { - @JsonProperty(value = "name", required = true) - private String name; - - @JsonProperty(value = "property", required = true) - private PropertyDefinition property; - - @JsonProperty("input-param") - private Boolean inputParameter; - - @JsonProperty("dictionary-name") - private String dictionaryName; - - @JsonProperty("dictionary-source") - private String dictionarySource; - - @JsonProperty("dependencies") - private List dependencies; - - @JsonProperty("version") - private int version; - - @JsonProperty("status") - private String status; - - @JsonProperty("message") - private String message; - - @JsonProperty("updated-date") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - private Date updatedDate; - - @JsonProperty("updated-by") - private String updatedBy; - - @Override - public String toString() { - StringBuilder builder = new StringBuilder("["); - builder.append("name = " + name); - builder.append(", source = " + dictionarySource); - if (dependencies != null) { - builder.append(", dependencies = " + dependencies); - } - builder.append("]"); - return builder.toString(); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public PropertyDefinition getProperty() { - return property; - } - - public void setProperty(PropertyDefinition property) { - this.property = property; - } - - public Boolean getInputParameter() { - return inputParameter; - } - - public void setInputParameter(Boolean inputParameter) { - this.inputParameter = inputParameter; - } - - public String getDictionaryName() { - return dictionaryName; - } - - public void setDictionaryName(String dictionaryName) { - this.dictionaryName = dictionaryName; - } - - public String getDictionarySource() { - return dictionarySource; - } - - public void setDictionarySource(String dictionarySource) { - this.dictionarySource = dictionarySource; - } - - public List getDependencies() { - return dependencies; - } - - public void setDependencies(List dependencies) { - this.dependencies = dependencies; - } - - public int getVersion() { - return version; - } - - public void setVersion(int version) { - this.version = version; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public Date getUpdatedDate() { - return updatedDate; - } - - public void setUpdatedDate(Date updatedDate) { - this.updatedDate = updatedDate; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java index 7c2d926f0..92178673e 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.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. @@ -26,6 +27,7 @@ import java.util.Map; * DictionaryDefinition.java Purpose: * @author Brinda Santh */ +@Deprecated public class DictionaryDefinition { @JsonProperty(value = "name", required = true) private String name; diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDependency.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDependency.java index acb710584..6ffbca264 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDependency.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDependency.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,6 +23,7 @@ import java.util.List; * DictionaryDependency * @author Brinda Santh */ +@Deprecated public class DictionaryDependency { private List names; diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java index 724d0224e..fbeab52f0 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.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,6 +25,7 @@ import java.util.Map; * SourceDb * @author Brinda Santh */ +@Deprecated public class SourceDb implements ResourceSource{ @JsonProperty(value = "base", required = true) private String base; diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java index d165192e9..e0f83bb89 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.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. @@ -20,6 +21,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; * SourceDefault * @author Brinda Santh */ +@Deprecated public class SourceDefault implements ResourceSource { private String key; diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java index 86476e1c2..a097c56d9 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.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. @@ -29,7 +30,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.HashMap; import java.util.Map; - +@Deprecated public class SourceDeserializer extends JsonDeserializer> { private static final Logger log = LoggerFactory.getLogger(SourceDeserializer.class); diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java index 87184f223..8ab16ecbc 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.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. @@ -20,6 +21,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; * SourceInput * @author Brinda Santh */ +@Deprecated public class SourceInput implements ResourceSource { private String key; diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java index 8a066e91a..379f6e915 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.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. @@ -23,7 +24,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Map; - +@Deprecated public class SourceMdsal implements ResourceSource { @JsonProperty(value = "base", required = true) diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt new file mode 100644 index 000000000..a6802f677 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt @@ -0,0 +1,34 @@ +/* + * 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.resource.dict + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException + +interface ResourceAssignmentProcessor { + + @Throws(BluePrintProcessorException::class) + fun validate(resourceAssignment: ResourceAssignment, context : MutableMap) + + @Throws(BluePrintProcessorException::class) + fun process(resourceAssignment: ResourceAssignment, context : MutableMap) + + @Throws(BluePrintProcessorException::class) + fun errorHandle(resourceAssignment: ResourceAssignment, context : MutableMap) + + @Throws(BluePrintProcessorException::class) + fun reTrigger(resourceAssignment: ResourceAssignment, context : MutableMap) +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt new file mode 100644 index 000000000..c2c8094b9 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt @@ -0,0 +1,95 @@ +/* + * 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.resource.dict + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.annotation.JsonProperty +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DecryptionRule +import java.io.Serializable +import java.util.* + +open class ResourceDefinition{ + + @JsonProperty(value = "name", required = true) + lateinit var name: String + + @JsonProperty(value = "property", required = true) + lateinit var property : PropertyDefinition + + var tags: String? = null + + @JsonProperty(value = "updated-by") + lateinit var updatedBy: String + + @JsonProperty(value = "resource-type", required = true) + lateinit var resourceType: String + + @JsonProperty(value = "resource-path", required = true) + lateinit var resourcePath: String + + @JsonProperty(value = "sources", required = true) + var sources: MutableMap? = null + + @JsonProperty("decryption-rules") + var decryptionRules: MutableList? = null + +} + +open class ResourceAssignment { + + @JsonProperty(value = "name", required = true) + lateinit var name: String + + @JsonProperty(value = "property") + var property: PropertyDefinition? = null + + @JsonProperty("input-param") + var inputParameter: Boolean = false + + @JsonProperty("dictionary-name") + var dictionaryName: String? = null + + @JsonProperty("dictionary-source") + var dictionarySource: String? = null + + @JsonProperty("dependencies") + var dependencies: MutableList? = null + + @JsonProperty("version") + var version: Int = 0 + + @JsonProperty("status") + var status: String? = null + + @JsonProperty("message") + var message: String? = null + + @JsonProperty("updated-date") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + var updatedDate: Date? = null + + @JsonProperty("updated-by") + var updatedBy: String? = null +} + +/** + * Interface for Source Definitions (ex Input Source, + * Default Source, Database Source, Rest Sources, etc) + */ +interface ResourceSource : Serializable diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java deleted file mode 100644 index 851ba1256..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java +++ /dev/null @@ -1,70 +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.resource.dict.util; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DictionaryDefinitionTest { - private Logger log = LoggerFactory.getLogger(DictionaryDefinitionTest.class); - String basePath = "load/resource_dictionary"; - - @Before - public void setup(){ - SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DB, SourceDb.class); - SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_INPUT, SourceInput.class); - SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_MDSAL, SourceMdsal.class); - SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DEFAULT,SourceDefault.class); - } - - @Test - public void testDictionaryDefinitionInputSource(){ - - String fileName = basePath + "/input-source.json"; - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", dictionaryDefinition); - } - - @Test - public void testDictionaryDefinitionDefaultSource(){ - - String fileName = basePath + "/default-source.json"; - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", dictionaryDefinition); - } - - @Test - public void testDictionaryDefinitionDBSource(){ - - String fileName = basePath + "/db-source.json"; - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", dictionaryDefinition); - } - - @Test - public void testDictionaryDefinitionMDSALSource(){ - String fileName = basePath + "/mdsal-source.json"; - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", dictionaryDefinition); - } -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDefinitionTest.java new file mode 100644 index 000000000..c71843804 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDefinitionTest.java @@ -0,0 +1,61 @@ +/* + * 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.resource.dict.util; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ResourceDefinitionTest { + private Logger log = LoggerFactory.getLogger(ResourceDefinitionTest.class); + String basePath = "load/resource_dictionary"; + + @Test + public void testDictionaryDefinitionInputSource(){ + + String fileName = basePath + "/input-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDefaultSource(){ + + String fileName = basePath + "/default-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDBSource(){ + + String fileName = basePath + "/db-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionMDSALSource(){ + String fileName = basePath + "/mdsal-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", resourceDefinition); + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java index 0c9a1c5d8..b6ac103ee 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.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. @@ -20,6 +21,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.util; import org.junit.Assert; import org.junit.Test; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; @@ -37,9 +39,11 @@ public class ResourceDictionaryUtilsTest { @Test public void validateSingleInputSource() { try { - log.info(" **************** Validating validateSingleSource *****************"); ResourceAssignment resourceAssignment = new ResourceAssignment(); resourceAssignment.setName("test-input-key"); + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType("string"); + resourceAssignment.setProperty(propertyDefinition); DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); @@ -64,9 +68,12 @@ public class ResourceDictionaryUtilsTest { @Test public void validateSingleDbSource() { try { - log.info(" **************** Validating validateSingleSource *****************"); ResourceAssignment resourceAssignment = new ResourceAssignment(); resourceAssignment.setName("test-db-key"); + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType("string"); + resourceAssignment.setProperty(propertyDefinition); + DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); @@ -110,6 +117,9 @@ public class ResourceDictionaryUtilsTest { public void testSourceDefault() { ResourceAssignment resourceAssignment = new ResourceAssignment(); resourceAssignment.setName("test-input-key"); + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType("string"); + resourceAssignment.setProperty(propertyDefinition); DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); @@ -139,6 +149,10 @@ public class ResourceDictionaryUtilsTest { public void testSourceMdsal() { ResourceAssignment resourceAssignment = new ResourceAssignment(); resourceAssignment.setName("test-input-key"); + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType("string"); + resourceAssignment.setProperty(propertyDefinition); + DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); -- cgit 1.2.3-korg From 48c15ed0d02d98acac81773d84e928d0bd5ff07d Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 26 Aug 2018 16:20:04 -0400 Subject: Controller Blueprints Microservice Add Standardized resource definition in Initial data loading and Dictionary management services. Change-Id: Ib33ba2ecf3cb1e1fb9b5dea71532e6bc8280bcbb Issue-ID: CCSDK-487 Signed-off-by: Brinda Santh --- .../core/data/BluePrintModel.kt | 19 ++- .../load/model_type/node_type/source-db.json | 4 +- .../load/model_type/node_type/source-default.json | 2 +- .../load/model_type/node_type/source-input.json | 2 +- .../load/model_type/node_type/source-rest.json | 7 +- .../resource/dict/ResourceDictionaryConstants.java | 5 + .../dict/utils/ResourceDictionaryUtils.java | 129 --------------- .../resource/dict/ResourceDefinition.kt | 2 +- .../resource/dict/utils/ResourceDictionaryUtils.kt | 62 +++++++ .../dict/util/ResourceDictionaryUtilsTest.java | 178 --------------------- .../dict/utils/ResourceDictionaryUtilsTest.java | 79 +++++++++ .../load/model_type/node_type/source-db.json | 44 +++++ .../load/model_type/node_type/source-default.json | 18 +++ .../load/model_type/node_type/source-input.json | 18 +++ .../load/model_type/node_type/source-rest.json | 61 +++++++ .../node_type/tosca.nodes.ResourceSource.json | 5 + .../load/resource_dictionary/db-source.json | 25 +-- .../load/resource_dictionary/input-source.json | 16 +- .../load/resource_dictionary/v4-ip-type.json | 29 ++-- .../service/AutoResourceMappingService.java | 7 +- .../service/DataBaseInitService.java | 25 ++- .../service/ResourceDictionaryService.java | 37 +++-- .../service/rs/ResourceDictionaryRestTest.java | 9 +- .../resourcedictionary/default_definition.json | 34 ++-- 24 files changed, 409 insertions(+), 408 deletions(-) delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt index a10f6d30c..b78a594f7 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -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,6 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.core.data import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.JsonNode +import io.swagger.annotations.ApiModelProperty /** * @@ -59,7 +61,7 @@ A constraint clause defines an operation along with one or more compatible value */ class ConstraintClause { @get:JsonProperty("equal") - var equal: Any? = null + var equal: JsonNode? = null @get:JsonProperty("greater_than") var greaterThan: Any? = null @get:JsonProperty("greater_or_equal") @@ -71,15 +73,15 @@ class ConstraintClause { @get:JsonProperty("in_range") var inRange: Any? = null @get:JsonProperty("valid_values") - var validValues: MutableList? = null + var validValues: MutableList? = null @get:JsonProperty("length") var length: Any? = null @get:JsonProperty("min_length") var minLength: Any? = null @get:JsonProperty("max_length") var maxLength: Any? = null - @get:JsonProperty("pattern") var pattern: String? = null + var schema: String? = null } /* @@ -157,12 +159,13 @@ class PropertyDefinition { var required: Boolean? = null lateinit var type: String @get:JsonProperty("default") - var defaultValue: Any? = null + var defaultValue: JsonNode? = null var status: String? = null var constraints: MutableList? = null @get:JsonProperty("entry_schema") var entrySchema: EntrySchema? = null - var value: Any? = null + @get:ApiModelProperty(notes = "Property Value, It may be raw JSON or primitive data type values") + var value: JsonNode? = null } @@ -182,7 +185,7 @@ class AttributeDefinition { var description: String? = null lateinit var type: String @JsonProperty("default") - var _default: Any? = null + var _default: JsonNode? = null var status: String? = null @JsonProperty("entry_schema") var entry_schema: String? = null @@ -346,7 +349,7 @@ A Data Type definition defines the schema for new named datatypes in TOSCA. */ class DataType : EntityType(){ - var constraints: MutableList>? = null + var constraints: MutableList? = null } /* @@ -481,7 +484,7 @@ class SubstitutionMapping { class EntrySchema { lateinit var type: String - var constraints: MutableList>? = null + var constraints: MutableList? = null } class InterfaceAssignment { diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json index 7ebeaa82c..661a9503b 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json @@ -7,7 +7,7 @@ "type": "string", "constraints": [ { - "validValues": [ + "valid_values": [ "SQL", "PLSQL" ] @@ -33,7 +33,7 @@ } }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json index dd0bffcc1..13e234e1b 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json @@ -7,7 +7,7 @@ "type": "string" }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json index 99c4691c4..126ea30bd 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json @@ -7,7 +7,7 @@ "type": "string" }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json index e77020ec9..f8dd8b6fc 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json @@ -8,8 +8,7 @@ "default": "JSON", "constraints": [ { - "validValues": [ - "XML", + "valid_values": [ "JSON" ] } @@ -29,7 +28,7 @@ "default": "JSON_PATH", "constraints": [ { - "validValues": [ + "valid_values": [ "JSON_PATH", "JSON_POINTER" ] @@ -51,7 +50,7 @@ } }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java index 1af42c590..96ab1ee1a 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.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. @@ -21,4 +22,8 @@ public class ResourceDictionaryConstants { public static final String SOURCE_DEFAULT = "default"; public static final String SOURCE_DB = "db"; public static final String SOURCE_MDSAL = "mdsal"; + + public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping"; + public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"; + public static final String PROPERTY_KEY_DEPENDENCY = "key-dependency"; } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java deleted file mode 100644 index 4f9467f05..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java +++ /dev/null @@ -1,129 +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.resource.dict.utils; - -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema; -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDependency; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.ResourceSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; - -/** - * ResourceDictionaryUtils.java Purpose to provide ResourceDictionaryUtils - * - * @author Brinda Santh - * @version 1.0 - */ -public class ResourceDictionaryUtils { - - private ResourceDictionaryUtils() { - // Do nothing - } - - private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtils.class); - - /** - * This Method is to assign the source name to the Dictionary Definition Check to see if the source - * definition is not present then assign, if more than one source then assign only one first source. - * - * @param resourceAssignment - * @param dictionaryDefinition - */ - @SuppressWarnings("squid:S3776") - public static void populateSourceMapping(ResourceAssignment resourceAssignment, - DictionaryDefinition dictionaryDefinition) { - - if (resourceAssignment != null && dictionaryDefinition != null - && StringUtils.isBlank(resourceAssignment.getDictionarySource())) { - - // Overwrite the Property Definitions from Dictionary - setProperty(resourceAssignment, dictionaryDefinition); - - Map dictionarySource = dictionaryDefinition.getSource(); - Map dictionaryDependencyMap = dictionaryDefinition.getDependency(); - - if (MapUtils.isNotEmpty(dictionarySource)) { - String source = findFirstSource(dictionarySource); - - // Populate and Assign First Source - if (StringUtils.isNotBlank(source)) { - // Set Dictionary Source - resourceAssignment.setDictionarySource(source); - - if (MapUtils.isNotEmpty(dictionaryDependencyMap)) { - // Set Dependencies - DictionaryDependency dictionaryDependency = dictionaryDependencyMap.get(source); - if (dictionaryDependency != null) { - resourceAssignment.setDependencies(dictionaryDependency.getNames()); - } - } - } else { - resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_INPUT); - } - log.info("auto map resourceAssignment : {}", resourceAssignment); - } - } - } - - public static Optional resolve(Supplier resolver) { - try { - T result = resolver.get(); - return Optional.ofNullable(result); - } catch (NullPointerException e) { - return Optional.empty(); - } - } - - private static String findFirstSource(Map dictionarySource) { - String source = null; - if (MapUtils.isNotEmpty(dictionarySource)) { - source = dictionarySource.keySet().stream().findFirst().get(); - } - return source; - } - - /** - * Overriding ResourceAssignment Properties with properties defined in Dictionary - */ - private static void setProperty(ResourceAssignment resourceAssignment, DictionaryDefinition dictionaryDefinition) { - if (StringUtils.isNotBlank(dictionaryDefinition.getDataType())) { - PropertyDefinition property = resourceAssignment.getProperty(); - if (property == null) { - property = new PropertyDefinition(); - } - property.setDefaultValue(dictionaryDefinition.getDefaultValue()); - property.setType(dictionaryDefinition.getDataType()); - if (StringUtils.isNotBlank(dictionaryDefinition.getEntrySchema())) { - EntrySchema entrySchema = new EntrySchema(); - entrySchema.setType(dictionaryDefinition.getEntrySchema()); - property.setEntrySchema(entrySchema); - } - resourceAssignment.setProperty(property); - } - } - -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt index c2c8094b9..525ed9a42 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt @@ -44,7 +44,7 @@ open class ResourceDefinition{ lateinit var resourcePath: String @JsonProperty(value = "sources", required = true) - var sources: MutableMap? = null + lateinit var sources: MutableMap @JsonProperty("decryption-rules") var decryptionRules: MutableList? = null diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt new file mode 100644 index 000000000..e08c09c8e --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -0,0 +1,62 @@ +/* + * 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.resource.dict.utils + +import org.apache.commons.collections.MapUtils +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import org.slf4j.LoggerFactory + + +object ResourceDictionaryUtils { + private val log = LoggerFactory.getLogger(ResourceDictionaryUtils::class.java) + + @JvmStatic + fun populateSourceMapping(resourceAssignment: ResourceAssignment, + resourceDefinition: ResourceDefinition) { + + if (StringUtils.isBlank(resourceAssignment.dictionarySource)) { + + if (MapUtils.isNotEmpty(resourceDefinition.sources)) { + val source = findFirstSource(resourceDefinition.sources) + + // Populate and Assign First Source + if (StringUtils.isNotBlank(source)) { + // Set Dictionary Source + resourceAssignment.dictionarySource = source + } else { + resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT + } + log.info("auto map resourceAssignment : {}", resourceAssignment) + }else { + resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT + } + } + } + + @JvmStatic + fun findFirstSource(sources: Map): String? { + var source: String? = null + if (MapUtils.isNotEmpty(sources)) { + source = sources.keys.stream().findFirst().get() + } + return source + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java deleted file mode 100644 index b6ac103ee..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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.resource.dict.util; - - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -public class ResourceDictionaryUtilsTest { - private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class); - - @Test - public void validateSingleInputSource() { - try { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType("string"); - resourceAssignment.setProperty(propertyDefinition); - DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); - dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - - Map source = new HashMap<>(); - SourceInput sourceInput = new SourceInput(); - source.put(ResourceDictionaryConstants.SOURCE_INPUT, sourceInput); - dictionaryDefinition.setSource(source); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - Assert.assertNotNull("Resource assignment input source is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment input source property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment input source property type is missing ", - resourceAssignment.getProperty().getType()); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void validateSingleDbSource() { - try { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-db-key"); - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType("string"); - resourceAssignment.setProperty(propertyDefinition); - - DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); - dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - - Map source = new HashMap<>(); - SourceDb sourceDb = new SourceDb(); - sourceDb.setBase("sdnc_connection"); - source.put(ResourceDictionaryConstants.SOURCE_DB, sourceDb); - dictionaryDefinition.setSource(source); - - Map dependency = new HashMap<>(); - DictionaryDependency dependencyDb = new DictionaryDependency(); - dependencyDb.setNames(Arrays.asList("vnf-id", "vnf-name")); - dependency.put(ResourceDictionaryConstants.SOURCE_DB, dependencyDb); - dictionaryDefinition.setDependency(dependency); - - DecryptionRule decryptionRule = new DecryptionRule(); - decryptionRule.setDecryptType("sample Type"); - decryptionRule.setPath("$."); - decryptionRule.setRule("Sample Rule"); - decryptionRule.setSources(Arrays.asList("vnf-id")); - dictionaryDefinition.setDecryptionRules(Arrays.asList(decryptionRule)); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - Assert.assertNotNull("Resource assignment db source source is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment db source source property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment db source source property type is missing ", - resourceAssignment.getProperty().getType()); - - Assert.assertNotNull("Resource assignment db dependecy is missing ", resourceAssignment.getDependencies()); - Assert.assertEquals("Resource assignment db dependecy count mismatch ", 2, - resourceAssignment.getDependencies().size()); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testSourceDefault() { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType("string"); - resourceAssignment.setProperty(propertyDefinition); - - DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); - dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - - Map source = new HashMap<>(); - SourceDefault sourceDefault = new SourceDefault(); - source.put(ResourceDictionaryConstants.SOURCE_DEFAULT, sourceDefault); - dictionaryDefinition.setSource(source); - - Map dependency = new HashMap<>(); - DictionaryDependency dependencyDefault = new DictionaryDependency(); - dependencyDefault.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); - dependency.put(ResourceDictionaryConstants.SOURCE_DEFAULT, dependencyDefault); - dictionaryDefinition.setDependency(dependency); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - - Assert.assertNotNull("Resource assignment default source is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment default source property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment default source property type is missing ", - resourceAssignment.getProperty().getType()); - } - - @Test - public void testSourceMdsal() { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType("string"); - resourceAssignment.setProperty(propertyDefinition); - - DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); - dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - - Map source = new HashMap<>(); - SourceMdsal sourceMdsal = new SourceMdsal(); - source.put(ResourceDictionaryConstants.SOURCE_MDSAL,sourceMdsal); - dictionaryDefinition.setSource(source); - - Map dependency = new HashMap<>(); - DictionaryDependency dependencyMdsal = new DictionaryDependency(); - dependencyMdsal.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); - dependency.put(ResourceDictionaryConstants.SOURCE_MDSAL, dependencyMdsal); - dictionaryDefinition.setDependency(dependency); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - - Assert.assertNotNull("Resource assignment mdsal source is missing ", resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment mdsal source property is missing ", resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment mdsal source property type is missing ", - resourceAssignment.getProperty().getType()); - } - -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java new file mode 100644 index 000000000..2a207e09b --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -0,0 +1,79 @@ +/* + * 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.resource.dict.utils; + + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +public class ResourceDictionaryUtilsTest { + private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class); + + @Test + public void testPopulateSourceMapping() { + + ResourceAssignment resourceAssignment = new ResourceAssignment(); + ResourceDefinition resourceDefinition = new ResourceDefinition(); + Map sources = new HashMap<>(); + resourceDefinition.setSources(sources); + // To Check Empty Source + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource()); + + // To Check First Source + resourceAssignment.setDictionarySource(null); + sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate()); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource()); + + // To Check Assigned Source + resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_DB); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_DB, resourceAssignment.getDictionarySource()); + + } + + @Test + public void testFindFirstSource() { + //To check if Empty Source + Map sources = new HashMap<>(); + String firstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertNull("Source populated, which is not expected.", firstSource); + + // TO check the first Source + sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate()); + String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource); + + // TO check the multiple Source + sources.put(ResourceDictionaryConstants.SOURCE_DB, new NodeTemplate()); + String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource); + + } + +} 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 000000000..661a9503b --- /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 000000000..13e234e1b --- /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 000000000..126ea30bd --- /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 000000000..f8dd8b6fc --- /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 000000000..2ef553e24 --- /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 862523544..cd4e282b4 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 35736b663..c34c252b3 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": { + "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 c6c0f9851..349183bd9 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": null, + "sources": { + "input": { + "type": "source-input", + "properties": { + "key": "v4-ip-type" + } + } + } } \ No newline at end of file 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 6b09c81ff..2c443783e 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/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 9ab319cb7..3a5c4fde8 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 b9567db13..4bb87d7fc 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. @@ -18,8 +19,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service; 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; @@ -108,24 +111,32 @@ public class ResourceDictionaryService { if (resourceDictionary != null) { ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); - DictionaryDefinition dictionaryDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition resourceDefinition = + JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); - if (dictionaryDefinition == null) { + if (resourceDefinition == 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()); + resourceDefinition.setName(resourceDictionary.getName()); + resourceDefinition.setResourcePath(resourceDictionary.getResourcePath()); + resourceDefinition.setResourceType(resourceDictionary.getResourceType()); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(resourceDictionary.getDataType()); + propertyDefinition.setDescription(resourceDictionary.getDescription()); + if(StringUtils.isNotBlank(resourceDictionary.getEntrySchema())){ + EntrySchema entrySchema = new EntrySchema(); + entrySchema.setType(resourceDictionary.getEntrySchema()); + propertyDefinition.setEntrySchema(entrySchema); + }else{ + propertyDefinition.setEntrySchema(null); + } + resourceDefinition.setTags(resourceDictionary.getTags()); + resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); - String definitionContent = JacksonUtils.getJson(dictionaryDefinition, true); + String definitionContent = JacksonUtils.getJson(resourceDefinition, true); resourceDictionary.setDefinition(definitionContent); Optional dbResourceDictionaryData = 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 73d6eca99..8257dc365 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 2b392054d..986ba7066 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": "v4-aggregat-list", + "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": null, + "sources": { + "input": { + "type": "source-input" + } + } } \ No newline at end of file -- cgit 1.2.3-korg From ee9f2dd72054056547ce7e9e96e8e9fb0eef4902 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 26 Aug 2018 22:10:50 -0400 Subject: Controller Blueprints Microservice Add resource dictionary validation implementation services, validation repository services and Junit Test cases. Change-Id: Ia746b86b7d9098eabe5e643dcba558ef9aa7160f Issue-ID: CCSDK-487 Signed-off-by: Brinda Santh --- .../core/BluePrintConstants.kt | 10 ++ .../core/ConfigModelConstant.kt | 5 +- .../core/service/BluePrintEnhancerRepoService.kt | 92 ------------------- .../core/service/BluePrintEnhancerService.kt | 9 +- .../core/service/BluePrintRepoService.kt | 93 +++++++++++++++++++ .../core/service/BluePrintRuntimeService.kt | 4 +- .../BluePrintEnhancerRepoFileServiceTest.kt | 51 ----------- .../core/service/BluePrintEnhancerServiceTest.kt | 3 +- .../core/service/BluePrintRepoFileServiceTest.kt | 52 +++++++++++ .../resource/dict/ResourceDictionaryConstants.java | 1 + .../service/ResourceDictionaryValidationService.kt | 80 ++++++++++++++++ .../ResourceDictionaryValidationServiceTest.java | 42 +++++++++ .../service/BluePrintEnhancerRepoDBService.java | 100 -------------------- .../service/BluePrintEnhancerService.java | 5 +- .../service/BluePrintRepoDBService.java | 101 +++++++++++++++++++++ .../service/ResourceDictionaryService.java | 26 ++++-- .../ResourceDictionaryValidationService.java | 31 +++++++ .../service/validator/ModelTypeValidator.java | 52 +---------- 18 files changed, 440 insertions(+), 317 deletions(-) delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoService.kt create mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoFileServiceTest.kt create mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt index 1bdd53073..85f1579e2 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt @@ -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. @@ -73,12 +74,21 @@ object BluePrintConstants { const val MODEL_TYPE_RELATIONSHIPS_ATTACH_TO = "tosca.relationships.AttachesTo" const val MODEL_TYPE_RELATIONSHIPS_ROUTES_TO = "tosca.relationships.RoutesTo" + const val MODEL_TYPE_NODE_DG = "tosca.nodes.DG" + const val MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component" + const val MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf" + @Deprecated("Artifacts will be attached to Node Template") + const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact" + const val MODEL_TYPE_NODE_RESOURCE_SOURCE = "tosca.nodes.ResourceSource" + const val MODEL_TYPE_NODES_COMPONENT_JAVA: String = "tosca.nodes.component.Java" const val MODEL_TYPE_NODES_COMPONENT_BUNDLE: String = "tosca.nodes.component.Bundle" const val MODEL_TYPE_NODES_COMPONENT_SCRIPT: String = "tosca.nodes.component.Script" const val MODEL_TYPE_NODES_COMPONENT_PYTHON: String = "tosca.nodes.component.Python" const val MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT: String = "tosca.nodes.component.JavaScript" + const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic" + const val EXPRESSION_GET_INPUT: String = "get_input" const val EXPRESSION_GET_ATTRIBUTE: String = "get_attribute" const val EXPRESSION_GET_ARTIFACT: String = "get_artifact" diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt index 978269125..845922040 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt @@ -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. @@ -26,12 +27,8 @@ object ConfigModelConstant { const val MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON" const val MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE" - const val MODEL_TYPE_DATA_TYPE = "tosca.datatypes.Root" const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic" - const val MODEL_TYPE_NODE_DG = "tosca.nodes.DG" - const val MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component" - const val MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf" const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact" const val MODEL_TYPE_CAPABILITY_NETCONF = "tosca.capability.Netconf" diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoService.kt deleted file mode 100644 index 5369d509b..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoService.kt +++ /dev/null @@ -1,92 +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.core.service - -import org.apache.commons.io.FileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import java.io.File -import java.io.Serializable -import java.nio.charset.Charset - -/** - * BluePrintEnhancerRepoFileService - * @author Brinda Santh - * - */ - -interface BluePrintEnhancerRepoService : Serializable { - - @Throws(BluePrintException::class) - fun getNodeType(nodeTypeName: String): NodeType? - - @Throws(BluePrintException::class) - fun getDataType(dataTypeName: String): DataType? - - @Throws(BluePrintException::class) - fun getArtifactType(artifactTypeName: String): ArtifactType? - - @Throws(BluePrintException::class) - fun getRelationshipType(relationshipTypeName: String): RelationshipType? - - @Throws(BluePrintException::class) - fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? - -} - - -class BluePrintEnhancerRepoFileService(val basePath: String) : BluePrintEnhancerRepoService { - - val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) - val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) - val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) - val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) - val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) - val extension = ".json" - - override fun getDataType(dataTypeName: String): DataType? { - val content = FileUtils.readFileToString(File(dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(dataTypeName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) - } - - override fun getNodeType(nodeTypeName: String): NodeType? { - val content = FileUtils.readFileToString(File(nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(nodeTypeName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) - } - - override fun getArtifactType(artifactTypeName: String): ArtifactType? { - val content = FileUtils.readFileToString(File(artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(artifactTypeName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) - } - - override fun getRelationshipType(relationshipTypeName: String): RelationshipType? { - val content = FileUtils.readFileToString(File(relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(relationshipTypeName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) - } - - override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? { - val content = FileUtils.readFileToString(File(capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(capabilityDefinitionName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt index 8f1728762..64fc57fcd 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt @@ -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. @@ -44,7 +45,7 @@ interface BluePrintEnhancerService : Serializable { fun enhance(fileName: String, basePath: String): ServiceTemplate } -open class BluePrintEnhancerDefaultService(val bluePrintEnhancerRepoService: BluePrintEnhancerRepoService) : BluePrintEnhancerService { +open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRepoService) : BluePrintEnhancerService { private val log: Logger = LoggerFactory.getLogger(BluePrintEnhancerDefaultService::class.java) @@ -216,21 +217,21 @@ open class BluePrintEnhancerDefaultService(val bluePrintEnhancerRepoService: Blu } open fun populateNodeType(nodeTypeName: String): NodeType { - val nodeType = bluePrintEnhancerRepoService.getNodeType(nodeTypeName) + val nodeType = bluePrintRepoService.getNodeType(nodeTypeName) ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName)) serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) return nodeType } open fun populateArtifactType(artifactTypeName: String): ArtifactType { - val artifactType = bluePrintEnhancerRepoService.getArtifactType(artifactTypeName) + val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName) ?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName)) serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) return artifactType } open fun populateDataTypes(dataTypeName: String): DataType { - val dataType = bluePrintEnhancerRepoService.getDataType(dataTypeName) + val dataType = bluePrintRepoService.getDataType(dataTypeName) ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName)) serviceTemplate.dataTypes?.put(dataTypeName, dataType) return dataType diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt new file mode 100644 index 000000000..a529a85f8 --- /dev/null +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt @@ -0,0 +1,93 @@ +/* + * 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.core.service + +import org.apache.commons.io.FileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import java.io.File +import java.io.Serializable +import java.nio.charset.Charset + +/** + * BluePrintRepoFileService + * @author Brinda Santh + * + */ + +interface BluePrintRepoService : Serializable { + + @Throws(BluePrintException::class) + fun getNodeType(nodeTypeName: String): NodeType? + + @Throws(BluePrintException::class) + fun getDataType(dataTypeName: String): DataType? + + @Throws(BluePrintException::class) + fun getArtifactType(artifactTypeName: String): ArtifactType? + + @Throws(BluePrintException::class) + fun getRelationshipType(relationshipTypeName: String): RelationshipType? + + @Throws(BluePrintException::class) + fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? + +} + + +class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService { + + val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + val extension = ".json" + + override fun getDataType(dataTypeName: String): DataType? { + val content = FileUtils.readFileToString(File(dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(dataTypeName).plus(extension)), Charset.defaultCharset()) + return JacksonUtils.readValue(content) + } + + override fun getNodeType(nodeTypeName: String): NodeType? { + val content = FileUtils.readFileToString(File(nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(nodeTypeName).plus(extension)), Charset.defaultCharset()) + return JacksonUtils.readValue(content) + } + + override fun getArtifactType(artifactTypeName: String): ArtifactType? { + val content = FileUtils.readFileToString(File(artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(artifactTypeName).plus(extension)), Charset.defaultCharset()) + return JacksonUtils.readValue(content) + } + + override fun getRelationshipType(relationshipTypeName: String): RelationshipType? { + val content = FileUtils.readFileToString(File(relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(relationshipTypeName).plus(extension)), Charset.defaultCharset()) + return JacksonUtils.readValue(content) + } + + override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? { + val content = FileUtils.readFileToString(File(capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(capabilityDefinitionName).plus(extension)), Charset.defaultCharset()) + return JacksonUtils.readValue(content) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index 08152313b..b03fdf92b 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -65,8 +65,8 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment) } else { // Assign default value to the Operation - nodeTypeProperty.defaultValue?.let { - resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!) + nodeTypeProperty.defaultValue?.let { defaultValue -> + resolvedValue = defaultValue } } // Set for Return of method diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoFileServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoFileServiceTest.kt deleted file mode 100644 index ef4384ff2..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoFileServiceTest.kt +++ /dev/null @@ -1,51 +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.core.service - -import org.junit.Test -import kotlin.test.assertNotNull - -/** - * BluePrintEnhancerRepoFileServiceTest - * @author Brinda Santh - * - */ -class BluePrintEnhancerRepoFileServiceTest { - - val basePath = "load/model_type" - - @Test - fun testGetDataType() { - val bluePrintEnhancerRepoFileService = BluePrintEnhancerRepoFileService(basePath) - val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate") - assertNotNull(dataType, "Failed to get DataType from repo") - } - - @Test - fun testGetNodeType() { - val bluePrintEnhancerRepoFileService = BluePrintEnhancerRepoFileService(basePath) - val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment") - assertNotNull(nodeType, "Failed to get NodeType from repo") - } - - @Test - fun testGetArtifactType() { - val bluePrintEnhancerRepoFileService = BluePrintEnhancerRepoFileService(basePath) - val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity") - assertNotNull(nodeType, "Failed to get ArtifactType from repo") - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt index 6fc18532e..8e6d5efdf 100644 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt +++ b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt @@ -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. @@ -30,7 +31,7 @@ class BluePrintEnhancerServiceTest { @Test fun testEnrichBlueprint() { - val bluePrintEnhancerRepoFileService = BluePrintEnhancerRepoFileService(basePath) + val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val bluePrintEnhancerService: BluePrintEnhancerService = BluePrintEnhancerDefaultService(bluePrintEnhancerRepoFileService) val serviceTemplate = ServiceTemplateUtils.getServiceTemplate("load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json") diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt new file mode 100644 index 000000000..574eae6d3 --- /dev/null +++ b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -0,0 +1,52 @@ +/* + * 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.core.service + +import org.junit.Test +import kotlin.test.assertNotNull + +/** + * BluePrintRepoFileServiceTest + * @author Brinda Santh + * + */ +class BluePrintRepoFileServiceTest { + + val basePath = "load/model_type" + + @Test + fun testGetDataType() { + val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) + val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate") + assertNotNull(dataType, "Failed to get DataType from repo") + } + + @Test + fun testGetNodeType() { + val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) + val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment") + assertNotNull(nodeType, "Failed to get NodeType from repo") + } + + @Test + fun testGetArtifactType() { + val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) + val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity") + assertNotNull(nodeType, "Failed to get ArtifactType from repo") + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java index 96ab1ee1a..ddbd88bda 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java @@ -23,6 +23,7 @@ public class ResourceDictionaryConstants { public static final String SOURCE_DB = "db"; public static final String SOURCE_MDSAL = "mdsal"; + public static final String PROPERTY_TYPE = "type"; public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping"; public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"; public static final String PROPERTY_KEY_DEPENDENCY = "key-dependency"; diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt new file mode 100644 index 000000000..cef1f1580 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt @@ -0,0 +1,80 @@ +/* + * 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.resource.dict.service + +import com.fasterxml.jackson.databind.JsonNode +import com.google.common.base.Preconditions +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.slf4j.LoggerFactory +import java.io.Serializable + +interface ResourceDictionaryValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceDefinition: ResourceDefinition) + +} + +open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService: BluePrintRepoService) : ResourceDictionaryValidationService { + + private val log = LoggerFactory.getLogger(ResourceDictionaryDefaultValidationService::class.java) + + override fun validate(resourceDefinition: ResourceDefinition) { + Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") + + resourceDefinition.sources.forEach { (name, nodeTemplate) -> + val sourceType = nodeTemplate.type + + val sourceNodeType = bluePrintRepoService.getNodeType(sourceType) + ?: throw BluePrintException(format("Failed to get node type definition for source({})", sourceType)) + + // Validate Property Name, expression, values and Data Type + validateNodeTemplateProperties(nodeTemplate, sourceNodeType) + } + } + + + open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) { + nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } + } + + + open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, + properties: MutableMap) { + properties.forEach { propertyName, propertyAssignment -> + val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] + ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) + // Check and Validate if Expression Node + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyDefinition, propertyName, propertyAssignment) + } + } + } + + open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, jsonNode: JsonNode) { + //log.info("validating Property {}, name ({}) value ({})", propertyDefinition, propertyName, jsonNode) + //TODO + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java new file mode 100644 index 000000000..6eebdb2f0 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java @@ -0,0 +1,42 @@ +/* + * 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.resource.dict.service; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; + +public class ResourceDictionaryValidationServiceTest { + private String basePath = "load/model_type"; + String dictionaryPath = "load/resource_dictionary"; + + @Test + public void testValidate() throws Exception { + BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); + + String fileName = dictionaryPath + "/db-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition); + + ResourceDictionaryValidationService resourceDictionaryValidationService = + new ResourceDictionaryDefaultValidationService(bluePrintRepoFileService); + resourceDictionaryValidationService.validate(resourceDefinition); + + } +} 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 a2e5b104c..000000000 --- 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 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 afd12f219..0cf846c7a 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 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 000000000..4a26119c0 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java @@ -0,0 +1,101 @@ +/* + * 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 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 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 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/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java index 4bb87d7fc..5420dd390 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 @@ -43,19 +43,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 @@ -70,7 +74,7 @@ public class ResourceDictionaryService { /** * This is a searchResourceDictionaryByNames service - * + * * @param names * @return List * @throws BluePrintException @@ -86,7 +90,7 @@ public class ResourceDictionaryService { /** * This is a searchResourceDictionaryByTags service - * + * * @param tags * @return List * @throws BluePrintException @@ -101,7 +105,7 @@ public class ResourceDictionaryService { /** * This is a saveDataDictionary service - * + * * @param resourceDictionary * @return DataDictionary * @throws BluePrintException @@ -113,6 +117,8 @@ public class ResourceDictionaryService { ResourceDefinition resourceDefinition = JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + // Check the Source already Present + resourceDictionaryValidationService.validate(resourceDefinition); if (resourceDefinition == null) { throw new BluePrintException( @@ -126,11 +132,11 @@ public class ResourceDictionaryService { PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType(resourceDictionary.getDataType()); propertyDefinition.setDescription(resourceDictionary.getDescription()); - if(StringUtils.isNotBlank(resourceDictionary.getEntrySchema())){ + if (StringUtils.isNotBlank(resourceDictionary.getEntrySchema())) { EntrySchema entrySchema = new EntrySchema(); entrySchema.setType(resourceDictionary.getEntrySchema()); propertyDefinition.setEntrySchema(entrySchema); - }else{ + } else { propertyDefinition.setEntrySchema(null); } resourceDefinition.setTags(resourceDictionary.getTags()); @@ -165,7 +171,7 @@ public class ResourceDictionaryService { /** * 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 000000000..7de7fc4c3 --- /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 85f256ea7..1201f6b49 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 getValidModelDerivedFrom(String definitionType) { - List 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 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."); } -- cgit 1.2.3-korg From 2b5c7e5b12440f35009d17d008b4061445b0524c Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 27 Aug 2018 13:53:21 +0000 Subject: Controller Blueprints Microservice Add junit test case for input, default and rest resource definition validation. Change-Id: I5ee37891768e5985bc7a4df6f6b917396f439bf2 Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../load/resource_dictionary/mdsal-source.json | 2 +- .../resource/dict/ResourceDictionaryConstants.java | 2 +- .../resource/dict/ResourceDefinitionTest.java | 60 +++++++++++++++++++++ .../ResourceDictionaryValidationServiceTest.java | 24 +++++++-- .../resource/dict/util/ResourceDefinitionTest.java | 61 ---------------------- 5 files changed, 81 insertions(+), 68 deletions(-) create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDefinitionTest.java (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json index 73d835c10..413d90446 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json @@ -24,7 +24,7 @@ "output-key-mapping": { "oam-local-ipv4-address": "v4-ip-prefix" }, - "key-dependency": [ + "key-dependencies": [ "service-instance-id", "network-role", "v4-ip-type", diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java index ddbd88bda..48b89bd6d 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java @@ -26,5 +26,5 @@ public class ResourceDictionaryConstants { public static final String PROPERTY_TYPE = "type"; public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping"; public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"; - public static final String PROPERTY_KEY_DEPENDENCY = "key-dependency"; + public static final String PROPERTY_KEY_DEPENDENCIES = "key-dependencies"; } diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java new file mode 100644 index 000000000..3e68d0991 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java @@ -0,0 +1,60 @@ +/* + * 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.resource.dict; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ResourceDefinitionTest { + private Logger log = LoggerFactory.getLogger(ResourceDefinitionTest.class); + String basePath = "load/resource_dictionary"; + + @Test + public void testDictionaryDefinitionInputSource(){ + + String fileName = basePath + "/input-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDefaultSource(){ + + String fileName = basePath + "/default-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDBSource(){ + + String fileName = basePath + "/db-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionMDSALSource(){ + String fileName = basePath + "/mdsal-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", resourceDefinition); + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java index 6eebdb2f0..b50c0e44b 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java @@ -25,18 +25,32 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition public class ResourceDictionaryValidationServiceTest { private String basePath = "load/model_type"; String dictionaryPath = "load/resource_dictionary"; + BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); @Test - public void testValidate() throws Exception { - BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); + public void testValidateSource() throws Exception { + + String inputFileName = dictionaryPath + "/db-source.json"; + testValidate(inputFileName); + + String dbFileName = dictionaryPath + "/db-source.json"; + testValidate(dbFileName); + + String defaultFileName = dictionaryPath + "/default-source.json"; + testValidate(defaultFileName); + + String restFileName = dictionaryPath + "/mdsal-source.json"; + testValidate(restFileName); + } + + private void testValidate(String fileName) throws Exception { - String fileName = dictionaryPath + "/db-source.json"; ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition); + Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); ResourceDictionaryValidationService resourceDictionaryValidationService = new ResourceDictionaryDefaultValidationService(bluePrintRepoFileService); resourceDictionaryValidationService.validate(resourceDefinition); - + Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); } } diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDefinitionTest.java deleted file mode 100644 index c71843804..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDefinitionTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.resource.dict.util; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ResourceDefinitionTest { - private Logger log = LoggerFactory.getLogger(ResourceDefinitionTest.class); - String basePath = "load/resource_dictionary"; - - @Test - public void testDictionaryDefinitionInputSource(){ - - String fileName = basePath + "/input-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionDefaultSource(){ - - String fileName = basePath + "/default-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionDBSource(){ - - String fileName = basePath + "/db-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionMDSALSource(){ - String fileName = basePath + "/mdsal-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", resourceDefinition); - } -} -- cgit 1.2.3-korg From afee4df36caa1a979586c8badf160c3ff49b97a0 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 28 Aug 2018 23:58:12 +0000 Subject: Controller Blueprints Microservice Add Resource Assignment Validation Service and their Test cases. Change-Id: I106be2bfc03115867041ca341947a4662cf126c4 Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../core/service/BluePrintRepoService.kt | 12 +- .../core/utils/JacksonUtils.kt | 18 ++- .../core/service/BluePrintRepoFileServiceTest.kt | 5 +- .../service/ResourceAssignmentValidationService.kt | 133 +++++++++++++++++++++ .../service/ResourceDictionaryValidationService.kt | 14 ++- .../ResourceAssignmentValidationServiceTest.kt | 56 +++++++++ .../src/test/resources/validation/cyclic.json | 111 +++++++++++++++++ .../src/test/resources/validation/duplicate.json | 110 +++++++++++++++++ .../src/test/resources/validation/success.json | 110 +++++++++++++++++ .../service/BluePrintRepoDBService.java | 22 ++-- .../service/repository/ModelTypeRepository.java | 25 ++-- 11 files changed, 583 insertions(+), 33 deletions(-) create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt index 8c4446183..8c2547324 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt @@ -61,12 +61,12 @@ class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService { private val log: Logger = LoggerFactory.getLogger(BluePrintRepoFileService::class.java) - val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) - val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) - val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) - val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) - val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) - val extension = ".json" + private val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + private val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + private val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + private val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + private val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + private val extension = ".json" override fun getDataType(dataTypeName: String): Mono? { val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 697a71001..886c3d2aa 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -102,6 +102,20 @@ object JacksonUtils { return objectMapper.readValue>(content, javaType) } + @JvmStatic + fun getListFromFile(fileName: String, valueType: Class): List? { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) + return getListFromJson(content, valueType) + } + + @JvmStatic + fun getListFromClassPathFile(fileName: String, valueType: Class): List? { + val content: String = IOUtils.toString(JacksonUtils::class.java.classLoader.getResourceAsStream(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(String.format("Failed to read json file : %s", fileName)) + return getListFromJson(content, valueType) + } + @JvmStatic fun getMapFromJson(content: String, valueType: Class): MutableMap? { val objectMapper = jacksonObjectMapper() @@ -110,13 +124,13 @@ object JacksonUtils { } @JvmStatic - fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode) : Boolean { + fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean { if (BluePrintTypes.validPrimitiveTypes().contains(type)) { return checkJsonNodeValueOfPrimitiveType(type, jsonNode) } else if (BluePrintTypes.validCollectionTypes().contains(type)) { return checkJsonNodeValueOfCollectionType(type, jsonNode) } - return false; + return false } @JvmStatic diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt index 4731935e6..081f4fe3b 100644 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt +++ b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -29,31 +29,28 @@ import kotlin.test.assertNotNull class BluePrintRepoFileServiceTest { val basePath = "load/model_type" + private val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) @Test fun testGetDataType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate") assertNotNull(dataType, "Failed to get DataType from repo") } @Test fun testGetNodeType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment") assertNotNull(nodeType, "Failed to get NodeType from repo") } @Test fun testGetArtifactType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity") assertNotNull(nodeType, "Failed to get ArtifactType from repo") } @Test(expected = FileNotFoundException::class) fun testModelNotFound() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found") assertNotNull(dataType, "Failed to get DataType from repo") } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt new file mode 100644 index 000000000..6809831f9 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -0,0 +1,133 @@ +/* + * 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.resource.dict.service + +import org.apache.commons.lang3.text.StrBuilder +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator +import org.slf4j.LoggerFactory +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang3.StringUtils +import java.io.Serializable +/** + * ResourceAssignmentValidationService. + * + * @author Brinda Santh + */ +interface ResourceAssignmentValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceAssignments: List): Boolean +} + +/** + * ResourceAssignmentValidationDefaultService. + * + * @author Brinda Santh + */ +open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValidationService { + private val log = LoggerFactory.getLogger(ResourceAssignmentValidator::class.java) + open var resourceAssignments: List = arrayListOf() + open var resourceAssignmentMap: MutableMap = hashMapOf() + open val validationMessage = StrBuilder() + + override fun validate(resourceAssignments: List): Boolean { + this.resourceAssignments = resourceAssignments + validateSources(resourceAssignments) + validateDuplicateDictionaryKeys() + validateCyclicDependency() + if (StringUtils.isNotBlank(validationMessage)) { + throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString()) + } + return true + } + + open fun validateSources(resourceAssignments: List) { + log.info("validating resource assignment sources") + } + + open fun validateDuplicateDictionaryKeys() { + val uniqueDictionaryKeys = hashSetOf() + + this.resourceAssignments.forEach { resourceAssignment -> + // Check Duplicate Names + if (!resourceAssignmentMap.containsKey(resourceAssignment.name)) { + resourceAssignmentMap[resourceAssignment.name] = resourceAssignment + } else { + validationMessage.appendln(String.format("Duplicate Assignment Template Key (%s) is Present", + resourceAssignment.name)) + } + // Check duplicate Dictionary Keys + if (!uniqueDictionaryKeys.contains(resourceAssignment.dictionaryName!!)) { + uniqueDictionaryKeys.add(resourceAssignment.dictionaryName!!) + } else { + validationMessage.appendln( + String.format("Duplicate Assignment Dictionary Key (%s) present with Template Key (%s)", + resourceAssignment.dictionaryName, resourceAssignment.name)) + } + } + } + + open fun validateCyclicDependency() { + val startResourceAssignment = ResourceAssignment() + startResourceAssignment.name = "*" + + val topologySorting = TopologicalSortingUtils() + this.resourceAssignmentMap.forEach { assignmentKey, assignment -> + if (CollectionUtils.isNotEmpty(assignment.dependencies)) { + for (dependency in assignment.dependencies!!) { + topologySorting.add(resourceAssignmentMap[dependency]!!, assignment) + } + } else { + topologySorting.add(startResourceAssignment, assignment) + } + } + + if (!topologySorting.isDag) { + val graph = getTopologicalGraph(topologySorting) + validationMessage.appendln("Cyclic Dependency :$graph") + } + } + + open fun getTopologicalGraph(topologySorting: TopologicalSortingUtils): String { + val s = StringBuilder() + val neighbors = topologySorting.getNeighbors() + + neighbors.forEach { v, vs -> + if (v.name == "*") { + s.append("\n * -> [") + for (resourceAssignment in vs) { + s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name + + "),") + } + s.append("]") + } else { + s.append("\n (" + v.dictionaryName + ":" + v.name + ") -> [") + for (resourceAssignment in vs) { + s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name + + "),") + } + s.append("]") + } + } + return s.toString() + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt index 81bb37d02..e4835a06d 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt @@ -31,15 +31,23 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.slf4j.LoggerFactory import java.io.Serializable - +/** + * ResourceDictionaryValidationService. + * + * @author Brinda Santh + */ interface ResourceDictionaryValidationService : Serializable { @Throws(BluePrintException::class) fun validate(resourceDefinition: ResourceDefinition) } - -open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService: BluePrintRepoService) : ResourceDictionaryValidationService { +/** + * ResourceDictionaryDefaultValidationService. + * + * @author Brinda Santh + */ +open class ResourceDictionaryDefaultValidationService(private val bluePrintRepoService: BluePrintRepoService) : ResourceDictionaryValidationService { private val log = LoggerFactory.getLogger(ResourceDictionaryDefaultValidationService::class.java) diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt new file mode 100644 index 000000000..4d8301f4e --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt @@ -0,0 +1,56 @@ +/* + * 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.resource.dict.service + +import org.junit.Assert +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory +/** + * ResourceAssignmentValidationServiceTest. + * + * @author Brinda Santh + */ +class ResourceAssignmentValidationServiceTest { + private val log = LoggerFactory.getLogger(ResourceAssignmentValidationServiceTest::class.java) + @Test + fun testValidateSuccess() { + log.info("**************** testValidateSuccess *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + val result = resourceAssignmentValidator.validate(assignments!!) + Assert.assertTrue("Failed to Validate", result) + } + + @Test(expected = BluePrintException::class) + fun testValidateDuplicate() { + log.info(" **************** testValidateDuplicate *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/duplicate.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + resourceAssignmentValidator.validate(assignments!!) + } + + @Test(expected = BluePrintException::class) + fun testValidateCyclic() { + log.info(" **************** testValidateCyclic *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/cyclic.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + resourceAssignmentValidator.validate(assignments!!) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json new file mode 100644 index 000000000..d837dc5d8 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json @@ -0,0 +1,111 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "managed-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac", + "managed-ip1" + ] + } +] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json new file mode 100644 index 000000000..330324cda --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json @@ -0,0 +1,110 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac" + ] + } +] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json new file mode 100644 index 000000000..3215d06d7 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json @@ -0,0 +1,110 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "managed-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac" + ] + } +] 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 index ae4fed9f4..c4aebe52c 100644 --- 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 @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; 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; @@ -36,36 +37,37 @@ import java.util.Optional; * @author Brinda Santh */ @Service +@SuppressWarnings("unused") public class BluePrintRepoDBService implements BluePrintRepoService { private ModelTypeRepository modelTypeRepository; - + @SuppressWarnings("unused") public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) { this.modelTypeRepository = modelTypeRepository; } @Override - public Mono getNodeType(String nodeTypeName) throws BluePrintException { + public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { return getModelType(nodeTypeName, NodeType.class); } @Override - public Mono getDataType(String dataTypeName) throws BluePrintException { + public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { return getModelType(dataTypeName, DataType.class); } @Override - public Mono getArtifactType(String artifactTypeName) throws BluePrintException { + public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { return getModelType(artifactTypeName, ArtifactType.class); } @Override - public Mono getRelationshipType(String relationshipTypeName) throws BluePrintException { + public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { return getModelType(relationshipTypeName, RelationshipType.class); } @Override - public Mono getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { + public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { return getModelType(capabilityDefinitionName, CapabilityDefinition.class); } @@ -73,15 +75,15 @@ public class BluePrintRepoDBService implements BluePrintRepoService { 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 getModelDefinition(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 getModelDefinitions(String modelName) throws BluePrintException { + private Mono getModelDefinition(String modelName) throws BluePrintException { String modelDefinition; Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); if (modelTypeDb.isPresent()) { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java index 51ae752f9..27823ef33 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java @@ -37,15 +37,23 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByModelName method * - * @param modelName + * @param modelName Model Name * @return Optional */ Optional findByModelName(String modelName); + /** + * This is a findByModelNameIn method + * + * @param modelNames Model Names + * @return List + */ + List findByModelNameIn(List modelNames); + /** * This is a findByDerivedFrom method * - * @param derivedFrom + * @param derivedFrom Derived From * @return List */ List findByDerivedFrom(String derivedFrom); @@ -54,15 +62,16 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByDerivedFromIn method * - * @param derivedFroms + * @param derivedFroms Derived Froms * @return List */ + @SuppressWarnings("unused") List findByDerivedFromIn(List derivedFroms); /** * This is a findByDefinitionType method * - * @param definitionType + * @param definitionType Definition Type * @return List */ List findByDefinitionType(String definitionType); @@ -70,16 +79,17 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByDefinitionTypeIn method * - * @param definitionTypes + * @param definitionTypes Definition Types * @return List */ + @SuppressWarnings("unused") List findByDefinitionTypeIn(List definitionTypes); /** * This is a findByTagsContainingIgnoreCase method * - * @param tags + * @param tags Tags * @return Optional */ List findByTagsContainingIgnoreCase(String tags); @@ -88,8 +98,7 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a deleteByModelName method * - * @param modelName - * @return Optional + * @param modelName ModelName */ void deleteByModelName(String modelName); -- cgit 1.2.3-korg From e10032c90bfcf5c56fc3200e89b142b782eac88f Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Tue, 28 Aug 2018 22:46:02 -0400 Subject: Controller Blueprints Microservice Add resource assignment json data to input property convertor utlity and their test cases. Change-Id: Ie4557048e85df38c75ac3d31ff62d4fce0662d9f Issue-ID: CCSDK-488 Signed-off-by: Brinda Santh --- .../core/service/BluePrintRuntimeService.kt | 143 +++++++++++---------- .../resource/dict/ResourceDictionaryConstants.java | 30 ----- .../resource/dict/ResourceDictionaryConstants.kt | 32 +++++ .../service/ResourceDefinitionValidationService.kt | 113 ++++++++++++++++ .../service/ResourceDictionaryValidationService.kt | 114 ---------------- .../resource/dict/utils/ResourceDictionaryUtils.kt | 15 +++ .../ResourceDefinitionValidationServiceTest.java | 56 ++++++++ .../ResourceDictionaryValidationServiceTest.java | 56 -------- .../dict/utils/ResourceDictionaryUtilsTest.java | 15 +++ .../resources/data/resource-assignment-input.json | 10 ++ .../ResourceDefinitionValidationService.java | 29 +++++ .../service/ResourceDictionaryService.java | 67 ++++------ .../ResourceDictionaryValidationService.java | 31 ----- 13 files changed, 370 insertions(+), 341 deletions(-) delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index b03fdf92b..5a8d5428a 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -26,6 +26,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.slf4j.Logger import org.slf4j.LoggerFactory /** @@ -33,14 +34,14 @@ import org.slf4j.LoggerFactory * * @author Brinda Santh */ -class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var context: MutableMap = hashMapOf()) { +open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var context: MutableMap = hashMapOf()) { private val logger: Logger = LoggerFactory.getLogger(this::class.toString()) /* Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing */ - fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { + open fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { logger.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName) val propertyAssignmentValue: MutableMap = hashMapOf() @@ -76,7 +77,7 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex return propertyAssignmentValue } - fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, + open fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap { logger.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " + "operationName({})", nodeTemplateName, interfaceName, operationName) @@ -105,7 +106,7 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex var resolvedValue: JsonNode = NullNode.getInstance() if (propertyAssignment != null) { // Resolve the Expressing - val propertyAssignmentExpression = PropertyAssignmentService( context, this) + val propertyAssignmentExpression = PropertyAssignmentService(context, this) resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment) } else { // Assign default value to the Operation @@ -122,8 +123,8 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex } - fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, - interfaceName: String, operationName: String, componentContext: MutableMap): Unit { + open fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, + interfaceName: String, operationName: String, componentContext: MutableMap) { logger.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " + "operationName({})", nodeTemplateName, interfaceName, operationName) @@ -150,125 +151,127 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex } } - fun resolveNodeTemplateArtifact(nodeTemplateName: String, + open fun resolveNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): String { val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) val artifactDefinition: ArtifactDefinition = nodeTemplate.artifacts?.get(artifactName) ?: throw BluePrintProcessorException(String.format("failed to get artifat definition {} from the node template" , artifactName)) - val propertyAssignmentExpression = PropertyAssignmentService( context, this) + val propertyAssignmentExpression = PropertyAssignmentService(context, this) return propertyAssignmentExpression.artifactContent(artifactDefinition) } - fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode): Unit { - val path = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) { + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() logger.trace("setting input path ({}), values ({})", path, value) context[path] = value } - fun setWorkflowInputValue(workflowName: String, propertyName: String, value: JsonNode): Unit { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_WORKFLOWS).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(workflowName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setWorkflowInputValue(workflowName: String, propertyName: String, value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_WORKFLOWS).append(BluePrintConstants.PATH_DIVIDER).append(workflowName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() context[path] = value } - fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode): Unit { + open fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() context[path] = value } - fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode): Unit { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INTERFACES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OPERATIONS).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() logger.trace("setting operation property path ({}), values ({})", path, value) context[path] = value } - fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode): Unit { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INTERFACES).append(interfaceName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OPERATIONS).append(operationName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() context[path] = value } - fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode): Unit { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INTERFACES).append(interfaceName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OPERATIONS).append(operationName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OUTPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() context[path] = value } - fun getInputValue(propertyName: String): JsonNode { - val path = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getInputValue(propertyName: String): JsonNode { + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as? JsonNode ?: NullNode.instance } - fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INTERFACES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OPERATIONS).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as JsonNode } - fun getPropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getPropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as JsonNode } - fun getRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_REQUIREMENTS).append(requirementName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_REQUIREMENTS).append(requirementName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as JsonNode } - fun getCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_CAPABILITIES).append(capabilityName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_CAPABILITIES).append(capabilityName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as JsonNode } - fun assignInputs(jsonNode: JsonNode): Unit { + open fun assignInputs(jsonNode: JsonNode) { logger.info("assignInputs from input JSON ({})", jsonNode.toString()) bluePrintContext.inputs?.forEach { propertyName, property -> - val valueNode: JsonNode = jsonNode.at("/" + propertyName) ?: NullNode.getInstance() + val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() setInputValue(propertyName, property, valueNode) } } - fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode): Unit { + open fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) { logger.info("assign workflow {} input value ({})", workflowName, jsonNode.toString()) bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, property -> - val valueNode: JsonNode = jsonNode.at("/" + propertyName) ?: NullNode.getInstance() + val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() setWorkflowInputValue(workflowName, propertyName, valueNode) } } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java deleted file mode 100644 index 48b89bd6d..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.resource.dict; - -public class ResourceDictionaryConstants { - public static final String SOURCE_INPUT= "input"; - public static final String SOURCE_DEFAULT = "default"; - public static final String SOURCE_DB = "db"; - public static final String SOURCE_MDSAL = "mdsal"; - - public static final String PROPERTY_TYPE = "type"; - public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping"; - public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"; - public static final String PROPERTY_KEY_DEPENDENCIES = "key-dependencies"; -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt new file mode 100644 index 000000000..9b89f6f40 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -0,0 +1,32 @@ +/* + * 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.resource.dict +/** + * ResourceDictionaryConstants + * + * @author Brinda Santh + */ +object ResourceDictionaryConstants { + const val SOURCE_INPUT = "input" + const val SOURCE_DEFAULT = "default" + const val SOURCE_DB = "db" + + const val PROPERTY_TYPE = "type" + const val PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping" + const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping" + const val PROPERTY_KEY_DEPENDENCIES = "key-dependencies" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt new file mode 100644 index 000000000..1defa538c --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt @@ -0,0 +1,113 @@ +/* + * Copyright © 2018 IBM. + * Modifications 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.resource.dict.service + +import com.fasterxml.jackson.databind.JsonNode +import com.google.common.base.Preconditions +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService +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.ResourceDefinition +import org.slf4j.LoggerFactory +import java.io.Serializable +/** + * ResourceDefinitionValidationService. + * + * @author Brinda Santh + */ +interface ResourceDefinitionValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceDefinition: ResourceDefinition) + +} +/** + * ResourceDefinitionValidationService. + * + * @author Brinda Santh + */ +open class ResourceDefinitionDefaultValidationService(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService { + + private val log = LoggerFactory.getLogger(ResourceDefinitionValidationService::class.java) + + override fun validate(resourceDefinition: ResourceDefinition) { + Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") + log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name) + + resourceDefinition.sources.forEach { (name, nodeTemplate) -> + val sourceType = nodeTemplate.type + + val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block() + ?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, sourceType)) + + // Validate Property Name, expression, values and Data Type + validateNodeTemplateProperties(nodeTemplate, sourceNodeType) + } + } + + + open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) { + nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } + } + + + open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, + properties: MutableMap) { + properties.forEach { propertyName, propertyAssignment -> + val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] + ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) + // Check and Validate if Expression Node + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyDefinition, propertyName, propertyAssignment) + } else { + throw BluePrintException(format("property({}) of expression ({}) is not supported", + propertyName, propertyAssignment)) + } + } + } + + open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) { + val propertyType = propertyDefinition.type + val isValid : Boolean + + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { + isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) + + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + + isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) + } else { + bluePrintRepoService.getDataType(propertyType) + ?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository", + propertyName, propertyType)) + isValid = true + } + + check(isValid) { + throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})", + propertyName, propertyType, propertyAssignment)) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt deleted file mode 100644 index e4835a06d..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications 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.resource.dict.service - -import com.fasterxml.jackson.databind.JsonNode -import com.google.common.base.Preconditions -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.format -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService -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.ResourceDefinition -import org.slf4j.LoggerFactory -import java.io.Serializable -/** - * ResourceDictionaryValidationService. - * - * @author Brinda Santh - */ -interface ResourceDictionaryValidationService : Serializable { - - @Throws(BluePrintException::class) - fun validate(resourceDefinition: ResourceDefinition) - -} -/** - * ResourceDictionaryDefaultValidationService. - * - * @author Brinda Santh - */ -open class ResourceDictionaryDefaultValidationService(private val bluePrintRepoService: BluePrintRepoService) : ResourceDictionaryValidationService { - - private val log = LoggerFactory.getLogger(ResourceDictionaryDefaultValidationService::class.java) - - override fun validate(resourceDefinition: ResourceDefinition) { - Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") - log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name) - - resourceDefinition.sources.forEach { (name, nodeTemplate) -> - val sourceType = nodeTemplate.type - - val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block() - ?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, sourceType)) - - // Validate Property Name, expression, values and Data Type - validateNodeTemplateProperties(nodeTemplate, sourceNodeType) - } - } - - - open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) { - nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } - } - - - open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, - properties: MutableMap) { - properties.forEach { propertyName, propertyAssignment -> - val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] - ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) - // Check and Validate if Expression Node - val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) - if (!expressionData.isExpression) { - checkPropertyValue(propertyDefinition, propertyName, propertyAssignment) - } else { - throw BluePrintException(format("property({}) of expression ({}) is not supported", - propertyName, propertyAssignment)) - } - } - } - - open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) { - val propertyType = propertyDefinition.type - var isValid = false - - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) - - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - - isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) - } else { - bluePrintRepoService.getDataType(propertyType) - ?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository", - propertyName, propertyType)) - - isValid = true; - } - - check(isValid) { - throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})", - propertyName, propertyType, propertyAssignment)) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt index e08c09c8e..733a443fd 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -16,8 +16,11 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode import org.apache.commons.collections.MapUtils import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition @@ -59,4 +62,16 @@ object ResourceDictionaryUtils { } return source } + + @JvmStatic + fun assignInputs(data: JsonNode, context: MutableMap) { + log.trace("assignInputs from input JSON ({})", data.toString()) + data.fields().forEach { field -> + val valueNode: JsonNode = data.at("/".plus(field.key)) ?: NullNode.getInstance() + + val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(field.key) + log.trace("setting path ({}), values ({})", path, valueNode) + context[path] = valueNode + } + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java new file mode 100644 index 000000000..ef305627f --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java @@ -0,0 +1,56 @@ +/* + * 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.resource.dict.service; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; + +public class ResourceDefinitionValidationServiceTest { + private String basePath = "load/model_type"; + private String dictionaryPath = "load/resource_dictionary"; + private BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); + + @Test + public void testValidateSource() throws Exception { + + String inputFileName = dictionaryPath + "/db-source.json"; + testValidate(inputFileName); + + String dbFileName = dictionaryPath + "/db-source.json"; + testValidate(dbFileName); + + String defaultFileName = dictionaryPath + "/default-source.json"; + testValidate(defaultFileName); + + String restFileName = dictionaryPath + "/mdsal-source.json"; + testValidate(restFileName); + } + + private void testValidate(String fileName) throws Exception { + + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); + + ResourceDefinitionValidationService resourceDictionaryValidationService = + new ResourceDefinitionDefaultValidationService(bluePrintRepoFileService); + resourceDictionaryValidationService.validate(resourceDefinition); + Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java deleted file mode 100644 index b50c0e44b..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.resource.dict.service; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; - -public class ResourceDictionaryValidationServiceTest { - private String basePath = "load/model_type"; - String dictionaryPath = "load/resource_dictionary"; - BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); - - @Test - public void testValidateSource() throws Exception { - - String inputFileName = dictionaryPath + "/db-source.json"; - testValidate(inputFileName); - - String dbFileName = dictionaryPath + "/db-source.json"; - testValidate(dbFileName); - - String defaultFileName = dictionaryPath + "/default-source.json"; - testValidate(defaultFileName); - - String restFileName = dictionaryPath + "/mdsal-source.json"; - testValidate(restFileName); - } - - private void testValidate(String fileName) throws Exception { - - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); - - ResourceDictionaryValidationService resourceDictionaryValidationService = - new ResourceDictionaryDefaultValidationService(bluePrintRepoFileService); - resourceDictionaryValidationService.validate(resourceDefinition); - Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); - } -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java index 2a207e09b..5c22f6543 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -18,9 +18,12 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils; +import com.fasterxml.jackson.databind.JsonNode; import org.junit.Assert; import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; +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.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; @@ -76,4 +79,16 @@ public class ResourceDictionaryUtilsTest { } + @Test + public void testAssignInputs() { + JsonNode data = JacksonUtils.jsonNodeFromClassPathFile("data/resource-assignment-input.json"); + Map context = new HashMap<>(); + ResourceDictionaryUtils.assignInputs(data, context); + String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue"); + log.info("populated context {}", context); + Assert.assertTrue(String.format("failed to get variable : %s",path),context.containsKey(path)); + + } + + } diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json new file mode 100644 index 000000000..d79c90682 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json @@ -0,0 +1,10 @@ +{ + "intValue" : 1, + "floatValue" : 1.34, + "booleanValue" : true, + "stringValue" : "sample-String", + "timeValue" : "2018-09-29", + "arrayStringValue" : ["one", "two"], + "mapValue" : {"profile_name1":"profile_name1", + "profile_name2":"profile_name2"} +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java new file mode 100644 index 000000000..d3bf42302 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java @@ -0,0 +1,29 @@ +/* + * 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.ResourceDefinitionDefaultValidationService; +import org.springframework.stereotype.Service; + +@Service +public class ResourceDefinitionValidationService extends ResourceDefinitionDefaultValidationService { + + public ResourceDefinitionValidationService(BluePrintRepoService bluePrintRepoService) { + super(bluePrintRepoService); + } +} 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 85e701b41..ccf4ffcc7 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 @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import com.google.common.base.Preconditions; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; @@ -43,16 +44,16 @@ public class ResourceDictionaryService { private ResourceDictionaryRepository resourceDictionaryRepository; - private ResourceDictionaryValidationService resourceDictionaryValidationService; + private ResourceDefinitionValidationService resourceDictionaryValidationService; /** * This is a DataDictionaryService, used to save and get the Resource Mapping stored in database * - * @param dataDictionaryRepository - * @param resourceDictionaryValidationService + * @param dataDictionaryRepository dataDictionaryRepository + * @param resourceDictionaryValidationService resourceDictionaryValidationService */ public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository, - ResourceDictionaryValidationService resourceDictionaryValidationService) { + ResourceDefinitionValidationService resourceDictionaryValidationService) { this.resourceDictionaryRepository = dataDictionaryRepository; this.resourceDictionaryValidationService = resourceDictionaryValidationService; } @@ -60,58 +61,49 @@ public class ResourceDictionaryService { /** * This is a getDataDictionaryByName service * - * @param name + * @param name name * @return DataDictionary - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ResourceDictionary getResourceDictionaryByName(String name) throws BluePrintException { - if (StringUtils.isNotBlank(name)) { - return resourceDictionaryRepository.findByName(name).get(); + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); + Optional resourceDictionaryDb = resourceDictionaryRepository.findByName(name); + if (resourceDictionaryDb.isPresent()) { + return resourceDictionaryDb.get(); } else { - throw new BluePrintException("Resource Mapping Name Information is missing."); + throw new BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)); } } /** * This is a searchResourceDictionaryByNames service * - * @param names + * @param names names * @return List - * @throws BluePrintException */ - public List searchResourceDictionaryByNames(List names) - throws BluePrintException { - if (names != null && !names.isEmpty()) { - return resourceDictionaryRepository.findByNameIn(names); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchResourceDictionaryByNames(List names) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide"); + return resourceDictionaryRepository.findByNameIn(names); } /** * This is a searchResourceDictionaryByTags service * - * @param tags + * @param tags tags * @return List - * @throws BluePrintException */ - public List searchResourceDictionaryByTags(String tags) throws BluePrintException { - if (StringUtils.isNotBlank(tags)) { - return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchResourceDictionaryByTags(String tags) { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide"); + return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); } /** * This is a saveDataDictionary service * - * @param resourceDictionary + * @param resourceDictionary resourceDictionary * @return DataDictionary - * @throws BluePrintException */ - public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) - throws BluePrintException { + public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()), "Resource Dictionary definition information is missing"); @@ -130,7 +122,7 @@ public class ResourceDictionaryService { PropertyDefinition propertyDefinition = resourceDefinition.getProperty(); resourceDictionary.setDescription(propertyDefinition.getDescription()); resourceDictionary.setDataType(propertyDefinition.getType()); - if(propertyDefinition.getEntrySchema() != null){ + if (propertyDefinition.getEntrySchema() != null) { resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); } @@ -164,15 +156,10 @@ public class ResourceDictionaryService { /** * This is a deleteResourceDictionary service * - * @param name - * @throws BluePrintException + * @param name name */ - public void deleteResourceDictionary(String name) throws BluePrintException { - if (name != null) { - resourceDictionaryRepository.deleteByName(name); - } else { - throw new BluePrintException("Resource Mapping Id Information is missing."); - } - + public void deleteResourceDictionary(String name) { + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); + resourceDictionaryRepository.deleteByName(name); } } 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 deleted file mode 100644 index 7de7fc4c3..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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); - } -} -- cgit 1.2.3-korg From 905d8bf666e0667774bebccfabce65e3497e9c32 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 30 Aug 2018 14:17:06 +0000 Subject: Controller Blueprints Microservice Add Resource Seuencing validation and Optimise resource assignment validation logics Change-Id: I6f31ca5dbeb6f6aa89959b7d96fbfad25468b3a4 Issue-ID: CCSDK-416 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../core/utils/JacksonUtils.kt | 7 + .../validator/ResourceAssignmentValidator.java | 163 --------------------- .../resource/dict/ResourceDefinition.kt | 15 +- .../service/ResourceAssignmentValidationService.kt | 84 ++++++----- .../dict/utils/BulkResourceSequencingUtils.kt | 108 ++++++++++++++ .../utils/BulkResourceSequencingUtilsTest.java | 37 +++++ .../dict/utils/ResourceDictionaryUtilsTest.java | 6 +- .../service/ConfigModelCreateService.java | 39 +++-- .../ResourceAssignmentValidationService.java | 29 ++++ .../service/ServiceTemplateService.java | 22 ++- .../validator/ServiceTemplateValidator.java | 47 +++++- .../validator/ServiceTemplateValidationTest.java | 19 ++- .../test/resources/enhance/enhance-template.json | 5 +- .../test/resources/enhance/enhanced-template.json | 2 +- 14 files changed, 337 insertions(+), 246 deletions(-) delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/validator/ResourceAssignmentValidator.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index c41124ed3..9eef1cad5 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -58,6 +58,13 @@ object JacksonUtils { return readValue(content, valueType) } + @JvmStatic + fun readValueFromClassPathFile(fileName: String, valueType: Class): T? { + val content: String = IOUtils.toString(JacksonUtils::class.java.classLoader.getResourceAsStream(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(String.format("Failed to read json file : %s", fileName)) + return readValue(content, valueType) + } + @JvmStatic fun jsonNodeFromObject(from: kotlin.Any): JsonNode = jacksonObjectMapper().convertValue(from, JsonNode::class.java) diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/validator/ResourceAssignmentValidator.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/validator/ResourceAssignmentValidator.java deleted file mode 100644 index c9b37c269..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/validator/ResourceAssignmentValidator.java +++ /dev/null @@ -1,163 +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.resource.dict.validator; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.text.StrBuilder; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; -import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityAssignment; -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -/** - * ResourceAssignmentValidator.java Purpose: - * - * @author Brinda Santh - */ -public class ResourceAssignmentValidator { - private static final Logger log = LoggerFactory.getLogger(ResourceAssignmentValidator.class); - private List assignments; - private Map resourceAssignmentMap = new HashMap<>(); - private StrBuilder validationMessage = new StrBuilder(); - - public ResourceAssignmentValidator(List assignments) { - this.assignments = assignments; - } - - public ResourceAssignmentValidator(NodeTemplate nodeTemplate) throws BluePrintException { - - if (nodeTemplate != null && nodeTemplate.getCapabilities() != null) { - CapabilityAssignment capabilityAssignment = - nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) { - Object mappingObject = - capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - if (mappingObject != null) { - String mappingContent = JacksonUtils.getJson(mappingObject); - if (StringUtils.isNotBlank(mappingContent)) { - this.assignments = - JacksonUtils.getListFromJson(mappingContent, ResourceAssignment.class); - } else { - validationMessage - .appendln(String.format("Failed to transform Mapping Content (%s) ", mappingContent)); - throw new BluePrintException( - String.format("Failed to transform Mapping Content (%s) ", mappingContent)); - } - } - } - } - } - - /** - * This is a validateResourceAssignment to validate the Topology Template - * - * @return boolean - * @throws BluePrintException BluePrintException - */ - public boolean validateResourceAssignment() throws BluePrintException { - if (assignments != null && !assignments.isEmpty()) { - validateDuplicateDictionaryKeys(); - validateCyclicDependency(); - if (validationMessage.length() > 0) { - throw new BluePrintException("Resource Assignment Validation :" + validationMessage.toString()); - } - } - return true; - } - - @SuppressWarnings("squid:S3776") - private void validateDuplicateDictionaryKeys() { - this.assignments.forEach(resourceMapping -> { - if (resourceMapping != null) { - if (!resourceAssignmentMap.containsKey(resourceMapping.getName())) { - resourceAssignmentMap.put(resourceMapping.getName(), resourceMapping); - } else { - validationMessage.appendln(String.format("Duplicate Assignment Template Key (%s) is Present", - resourceMapping.getName())); - } - } - }); - - if (!assignments.isEmpty()) { - Set uniqueSet = new HashSet<>(); - for (ResourceAssignment resourceAssignment : assignments) { - if (resourceAssignment != null) { - boolean added = uniqueSet.add(resourceAssignment.getDictionaryName()); - if (!added) { - validationMessage.appendln( - String.format("Duplicate Assignment Dictionary Key (%s) present with Template Key (%s)", - resourceAssignment.getDictionaryName(), resourceAssignment.getName())); - } - } - } - } - } - - private void validateCyclicDependency() { - TopologicalSortingUtils topologySorting = new TopologicalSortingUtils<>(); - this.resourceAssignmentMap.forEach((mappingKey, mapping) -> { - if (mapping != null) { - if (mapping.getDependencies() != null && !mapping.getDependencies().isEmpty()) { - for (String dependency : mapping.getDependencies()) { - topologySorting.add(resourceAssignmentMap.get(dependency), mapping); - } - } else { - topologySorting.add(null, mapping); - } - } - }); - - if (!topologySorting.isDag()) { - String graph = getTopologicalGraph(topologySorting); - validationMessage.appendln("Cyclic Dependency :" + graph); - } - } - - - public String getTopologicalGraph(TopologicalSortingUtils topologySorting) { - StringBuilder s = new StringBuilder(); - if (topologySorting != null) { - Map> neighbors = topologySorting.getNeighbors(); - - neighbors.forEach((v, vs) -> { - if (v == null) { - s.append("\n * -> ["); - for (ResourceAssignment resourceAssignment : vs) { - s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName() - + "),"); - } - s.append("]"); - } else { - s.append("\n (" + v.getDictionaryName() + ":" + v.getName() + ") -> ["); - for (ResourceAssignment resourceAssignment : vs) { - s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName() - + "),"); - } - s.append("]"); - } - }); - } - return s.toString(); - } -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt index 2287c6c8c..b4d68cbca 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt @@ -18,18 +18,19 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict import com.fasterxml.jackson.annotation.JsonFormat import com.fasterxml.jackson.annotation.JsonProperty +import org.apache.commons.lang3.builder.ToStringBuilder import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition import java.io.Serializable import java.util.* -open class ResourceDefinition{ +open class ResourceDefinition { @JsonProperty(value = "name", required = true) lateinit var name: String @JsonProperty(value = "property", required = true) - lateinit var property : PropertyDefinition + lateinit var property: PropertyDefinition var tags: String? = null @@ -81,6 +82,16 @@ open class ResourceAssignment { @JsonProperty("updated-by") var updatedBy: String? = null + + override fun toString(): String { + return StringBuilder() + .append("[") + .append("name=", name) + .append(", dictionaryName=", dictionaryName) + .append(", dictionarySource=", dictionarySource) + .append("]") + .toString() + } } /** diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt index 6a78ac852..4578aca7d 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -22,7 +22,6 @@ import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator import org.slf4j.LoggerFactory import java.io.Serializable @@ -43,18 +42,21 @@ interface ResourceAssignmentValidationService : Serializable { * @author Brinda Santh */ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValidationService { - private val log = LoggerFactory.getLogger(ResourceAssignmentValidator::class.java) - open var resourceAssignments: List = arrayListOf() - open var resourceAssignmentMap: MutableMap = hashMapOf() + private val log = LoggerFactory.getLogger(ResourceAssignmentValidationDefaultService::class.java) + + open var resourceAssignmentMap: Map = hashMapOf() open val validationMessage = StrBuilder() override fun validate(resourceAssignments: List): Boolean { - this.resourceAssignments = resourceAssignments - validateSources(resourceAssignments) - validateDuplicateDictionaryKeys() - validateCyclicDependency() - if (StringUtils.isNotBlank(validationMessage)) { - throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString()) + try { + validateSources(resourceAssignments) + validateTemplateNDictionaryKeys(resourceAssignments) + validateCyclicDependency(resourceAssignments) + if (StringUtils.isNotBlank(validationMessage)) { + throw BluePrintException("Resource Assignment Validation Failure") + } + } catch (e: Exception) { + throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString(), e) } return true } @@ -63,40 +65,54 @@ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValida log.info("validating resource assignment sources") } - open fun validateDuplicateDictionaryKeys() { - val uniqueDictionaryKeys = hashSetOf() + open fun validateTemplateNDictionaryKeys(resourceAssignments: List) { - this.resourceAssignments.forEach { resourceAssignment -> - // Check Duplicate Names - if (!resourceAssignmentMap.containsKey(resourceAssignment.name)) { - resourceAssignmentMap[resourceAssignment.name] = resourceAssignment - } else { - validationMessage.appendln(String.format("Duplicate Assignment Template Key (%s) is Present", - resourceAssignment.name)) - } - // Check duplicate Dictionary Keys - if (!uniqueDictionaryKeys.contains(resourceAssignment.dictionaryName!!)) { - uniqueDictionaryKeys.add(resourceAssignment.dictionaryName!!) - } else { - validationMessage.appendln( - String.format("Duplicate Assignment Dictionary Key (%s) present with Template Key (%s)", - resourceAssignment.dictionaryName, resourceAssignment.name)) - } + resourceAssignmentMap = resourceAssignments.map { it.name to it }.toMap() + + val duplicateKeyNames = resourceAssignments.groupBy { it.name } + .filter { it.value.size > 1 } + .map { it.key } + + if (duplicateKeyNames.isNotEmpty()) { + validationMessage.appendln(String.format("Duplicate Assignment Template Keys (%s) is Present", duplicateKeyNames)) + } + + val duplicateDictionaryKeyNames = resourceAssignments.groupBy { it.dictionaryName } + .filter { it.value.size > 1 } + .map { it.key } + if (duplicateDictionaryKeyNames.isNotEmpty()) { + validationMessage.appendln(String.format("Duplicate Assignment Dictionary Keys (%s) is Present", duplicateDictionaryKeyNames)) + } + + val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten() + + log.info("Resource assignment definitions : {}", resourceAssignmentMap.keys) + log.info("Resource assignment Dictionary dependencies : {}", dependenciesNames) + + val notPresentDictionaries = dependenciesNames.filter { !resourceAssignmentMap.containsKey(it) }.distinct() + if (notPresentDictionaries.isNotEmpty()) { + validationMessage.appendln(String.format("No assignments for Dictionary Keys (%s)", notPresentDictionaries)) + } + + if (StringUtils.isNotBlank(validationMessage)) { + throw BluePrintException("Resource Assignment Validation Failure") } } - open fun validateCyclicDependency() { + open fun validateCyclicDependency(resourceAssignments: List) { val startResourceAssignment = ResourceAssignment() startResourceAssignment.name = "*" val topologySorting = TopologicalSortingUtils() - this.resourceAssignmentMap.forEach { assignmentKey, assignment -> - if (CollectionUtils.isNotEmpty(assignment.dependencies)) { - for (dependency in assignment.dependencies!!) { - topologySorting.add(resourceAssignmentMap[dependency]!!, assignment) + + resourceAssignmentMap.map { it.value }.map { resourceAssignment -> + if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { + resourceAssignment.dependencies!!.map { + log.info("Topological Graph link from {} to {}", it, resourceAssignment.name) + topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment) } } else { - topologySorting.add(startResourceAssignment, assignment) + topologySorting.add(startResourceAssignment, resourceAssignment) } } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt new file mode 100644 index 000000000..82fbd3ac1 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt @@ -0,0 +1,108 @@ +/* + * 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.resource.dict.utils + +import org.apache.commons.collections.CollectionUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory +import java.util.ArrayList +/** + * BulkResourceSequencingUtils. + * + * @author Brinda Santh + */ +object BulkResourceSequencingUtils { + private val log = LoggerFactory.getLogger(BulkResourceSequencingUtils::class.java) + + @JvmStatic + fun process(resourceAssignments: MutableList): List> { + val resourceAssignmentMap: MutableMap = hashMapOf() + val sequenceBatchResourceAssignment = ArrayList>() + log.info("Assignments ({})", resourceAssignments) + // Prepare Map + resourceAssignments.forEach { resourceAssignment -> + log.trace("Processing Key ({})", resourceAssignment.name) + resourceAssignmentMap.put(resourceAssignment.name, resourceAssignment) + } + + val startResourceAssignment = ResourceAssignment() + startResourceAssignment.name = "*" + + // Preepare Sorting Map + val topologySorting = TopologicalSortingUtils() + resourceAssignmentMap.forEach { _, resourceAssignment -> + if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { + for (dependency in resourceAssignment.dependencies!!) { + topologySorting.add(resourceAssignmentMap[dependency]!!, resourceAssignment) + } + } else { + topologySorting.add(startResourceAssignment, resourceAssignment) + } + } + + val sequencedResourceAssignments: MutableList = topologySorting.topSort()!! as MutableList + log.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments) + + var batchResourceAssignment: MutableList? = null + var batchAssignmentName: MutableList? = null + + // Prepare Sorting + sequencedResourceAssignments.forEachIndexed { index, resourceAssignment -> + + var previousResourceAssignment: ResourceAssignment? = null + + if (index > 0) { + previousResourceAssignment = sequencedResourceAssignments[index - 1] + } + + var dependencyPresence = false + if (batchAssignmentName != null && resourceAssignment.dependencies != null) { + dependencyPresence = CollectionUtils.containsAny(batchAssignmentName, resourceAssignment.dependencies) + } + + log.trace("({}) -> Checking ({}), with ({}), result ({})", resourceAssignment.name, + batchAssignmentName, resourceAssignment.dependencies, dependencyPresence) + + if (previousResourceAssignment != null && resourceAssignment.dictionarySource != null + && resourceAssignment.dictionarySource!!.equals(previousResourceAssignment.dictionarySource, true) + && !dependencyPresence) { + batchResourceAssignment!!.add(resourceAssignment) + batchAssignmentName!!.add(resourceAssignment.name) + } else { + if (batchResourceAssignment != null) { + sequenceBatchResourceAssignment.add(batchResourceAssignment!!) + log.trace("Created old Set ({})", batchAssignmentName) + } + batchResourceAssignment = arrayListOf() + batchResourceAssignment!!.add(resourceAssignment) + + batchAssignmentName = arrayListOf() + batchAssignmentName!!.add(resourceAssignment.name) + } + + if (index == sequencedResourceAssignments.size - 1) { + log.trace("Created old Set ({})", batchAssignmentName) + sequenceBatchResourceAssignment.add(batchResourceAssignment!!) + } + } + log.info("Batched Sequence : ({})", sequenceBatchResourceAssignment) + + return sequenceBatchResourceAssignment + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java new file mode 100644 index 000000000..c7444dbae --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java @@ -0,0 +1,37 @@ +/* + * 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.resource.dict.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import java.util.List; +/** + * BulkResourceSequencingUtils. + * + * @author Brinda Santh + */ +public class BulkResourceSequencingUtilsTest { + + @Test + public void testProcess(){ + List assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment.class); + Assert.assertNotNull("failed to get ResourceAssignment from validation/success.json ", assignments); + BulkResourceSequencingUtils.process(assignments); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java index 5c22f6543..5ee561713 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -32,7 +32,11 @@ import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; - +/** + * ResourceDictionaryUtilsTest. + * + * @author Brinda Santh + */ public class ResourceDictionaryUtilsTest { private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index f52137191..9c1a045cd 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -21,6 +21,7 @@ import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; @@ -290,31 +291,29 @@ public class ConfigModelCreateService { * @return ConfigModel * @throws BluePrintException BluePrintException */ - public ConfigModel publishConfigModel(Long id) throws BluePrintException { + public ConfigModel publishConfigModel(@NotNull Long id) throws BluePrintException { ConfigModel dbConfigModel = null; - if (id != null) { - Optional dbConfigModelOptional = configModelRepository.findById(id); - if (dbConfigModelOptional.isPresent()) { - dbConfigModel = dbConfigModelOptional.get(); - List configModelContents = dbConfigModel.getConfigModelContents(); - if (configModelContents != null && !configModelContents.isEmpty()) { - for (ConfigModelContent configModelContent : configModelContents) { - if (configModelContent.getContentType() - .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { - ServiceTemplate serviceTemplate = JacksonUtils - .readValue(configModelContent.getContent(), ServiceTemplate.class); - if (serviceTemplate != null) { - validateServiceTemplate(serviceTemplate); - } + Optional dbConfigModelOptional = configModelRepository.findById(id); + if (dbConfigModelOptional.isPresent()) { + dbConfigModel = dbConfigModelOptional.get(); + List configModelContents = dbConfigModel.getConfigModelContents(); + if (configModelContents != null && !configModelContents.isEmpty()) { + for (ConfigModelContent configModelContent : configModelContents) { + if (configModelContent.getContentType() + .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { + ServiceTemplate serviceTemplate = JacksonUtils + .readValue(configModelContent.getContent(), ServiceTemplate.class); + if (serviceTemplate != null) { + validateServiceTemplate(serviceTemplate); } } } - dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y); - configModelRepository.save(dbConfigModel); - log.info("Config model ({}) published successfully.", id); - } - + dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y); + configModelRepository.save(dbConfigModel); + log.info("Config model ({}) published successfully.", id); + } else { + throw new BluePrintException(String.format("Couldn't get Config model for id :(%s)", id)); } return dbConfigModel; } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java new file mode 100644 index 000000000..1228e2eeb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java @@ -0,0 +1,29 @@ +/* + * 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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService; +import org.springframework.stereotype.Service; +/** + * ResourceAssignmentValidationService. + * + * @author Brinda Santh + */ +@Service +public class ResourceAssignmentValidationService extends ResourceAssignmentValidationDefaultService { + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java index 70cee3c9e..3e3c8e286 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; @@ -45,21 +44,24 @@ public class ServiceTemplateService { private ConfigModelCreateService configModelCreateService; private BluePrintEnhancerService bluePrintEnhancerService; + private ResourceAssignmentValidationService resourceAssignmentValidationService; /** * This is a SchemaGeneratorService constructor * - * @param dataDictionaryRepository dataDictionaryRepository - * @param configModelCreateService configModelCreateService - * @param bluePrintEnhancerService bluePrintEnhancerService + * @param dataDictionaryRepository dataDictionaryRepository + * @param configModelCreateService configModelCreateService + * @param bluePrintEnhancerService bluePrintEnhancerService + * @param resourceAssignmentValidationService resourceAssignmentValidationService */ public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository, ConfigModelCreateService configModelCreateService, - BluePrintEnhancerService bluePrintEnhancerService) { + BluePrintEnhancerService bluePrintEnhancerService, + ResourceAssignmentValidationService resourceAssignmentValidationService) { this.dataDictionaryRepository = dataDictionaryRepository; this.configModelCreateService = configModelCreateService; this.bluePrintEnhancerService = bluePrintEnhancerService; - + this.resourceAssignmentValidationService = resourceAssignmentValidationService; } /** @@ -105,13 +107,7 @@ public class ServiceTemplateService { */ public List validateResourceAssignments(List resourceAssignments) throws BluePrintException { - try { - ResourceAssignmentValidator resourceAssignmentValidator = - new ResourceAssignmentValidator(resourceAssignments); - resourceAssignmentValidator.validateResourceAssignment(); - } catch (BluePrintException e) { - throw new BluePrintException(e.getMessage(), e); - } + resourceAssignmentValidationService.validate(resourceAssignments); return resourceAssignments; } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java index 848a32f5b..42adf1a3e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java @@ -17,16 +17,23 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; import com.google.common.base.Preconditions; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; +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.CapabilityAssignment; import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -62,7 +69,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /** * This is a validateServiceTemplate * - * @param serviceTemplate + * @param serviceTemplate serviceTemplate * @return boolean * @throws BluePrintException BluePrintException */ @@ -76,7 +83,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /** * This is a getMetaData to get the key information during the * - * @return Map + * @return Map */ public Map getMetaData() { return metaData; @@ -104,9 +111,37 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) throws BluePrintException { String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom(); - if ("tosca.nodes.Artifact".equals(derivedFrom)) { - ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(nodeTemplate); - resourceAssignmentValidator.validateResourceAssignment(); + + if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) { + List resourceAssignment = getResourceAssignments(nodeTemplate); + ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationDefaultService(); + resourceAssignmentValidationService.validate(resourceAssignment); + } + } + + private List getResourceAssignments(@NotNull NodeTemplate nodeTemplate) { + + List resourceAssignment = null; + + if (MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) { + + CapabilityAssignment capabilityAssignment = + nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); + if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) { + Object mappingObject = + capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); + if (mappingObject != null) { + String mappingContent = JacksonUtils.getJson(mappingObject); + Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent), + String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)); + + resourceAssignment = JacksonUtils.getListFromJson(mappingContent, ResourceAssignment.class); + + Preconditions.checkNotNull(resourceAssignment, + String.format("Failed to get resource assignment info from the content (%s) ", mappingContent)); + } + } } + return resourceAssignment; } } diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java index 0ef544525..e41e90a2d 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java @@ -20,6 +20,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,9 +42,22 @@ public class ServiceTemplateValidationTest { @Test public void validateServiceTemplate() throws Exception { - String file = "load/blueprints/baseconfiguration/Definitions/activation-blueprint.json"; + validateServiceTemplate("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json"); + validateServiceTemplate("load/blueprints/vrr-test/Definitions/vrr-test.json"); + } + + //@Test + public void validateEnhancedServiceTemplate() throws Exception { + ServiceTemplate serviceTemplate = JacksonUtils + .readValueFromClassPathFile("enhance/enhanced-template.json", ServiceTemplate.class); + ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); + Boolean valid = serviceTemplateValidator.validateServiceTemplate(serviceTemplate); + Assert.assertTrue("Failed to validate blueprints", valid); + } + + private void validateServiceTemplate(String fileName) throws Exception { String serviceTemplateContent = - FileUtils.readFileToString(new File(file), Charset.defaultCharset()); + FileUtils.readFileToString(new File(fileName), Charset.defaultCharset()); ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); Assert.assertNotNull("Failed to validate blueprints", serviceTemplateValidator); diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json index a4ba930e5..fedf1da21 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json +++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json @@ -232,10 +232,7 @@ "dictionary-name": "wan-aggregate-ipv4-addresses", "dictionary-source": "mdsal", "dependencies": [ - "service-instance-id", - "oam-network-role", - "oam-v4-ip-type ", - "oam-vm-type" + "service-instance-id" ], "version": 0 }, diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json index e00330961..0633c64d0 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json +++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json @@ -738,7 +738,7 @@ "input-param" : false, "dictionary-name" : "wan-aggregate-ipv4-addresses", "dictionary-source" : "mdsal", - "dependencies" : [ "service-instance-id", "oam-network-role", "oam-v4-ip-type ", "oam-vm-type" ], + "dependencies" : [ "service-instance-id" ], "version" : 0 }, { "name" : "hostname", -- cgit 1.2.3-korg From 5dbc79162b53a0e97be4561719ae0e181944d2c8 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 31 Aug 2018 19:52:48 +0000 Subject: Controller Blueprints Microservice Add resource assignment enhancer, resource definition repo functions and code improvements. Change-Id: I751bf8149a36f80c20d48b86344cd6bd3054ed21 Issue-ID: CCSDK-431 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../ControllerBluprintsApplicationTest.java | 6 +- .../core/BluePrintConstants.kt | 2 + .../core/service/BluePrintEnhancerService.kt | 37 +++++-- .../core/service/BluePrintRepoService.kt | 32 ++---- .../core/utils/JacksonReactorUtils.kt | 108 +++++++++++++++++++++ .../core/utils/JacksonUtils.kt | 58 +++++------ .../core/service/BluePrintRepoFileServiceTest.kt | 10 +- .../core/utils/JacksonReactorUtilsTest.kt | 51 ++++++++++ .../load/resource_dictionary/db-source.json | 2 +- .../load/resource_dictionary/default-source.json | 2 +- .../load/resource_dictionary/input-source.json | 2 +- .../load/resource_dictionary/mdsal-source.json | 2 +- .../resource/dict/ResourceDictionaryConstants.kt | 2 + .../service/ResourceAssignmentEnhancerService.kt | 86 ++++++++++++++++ .../service/ResourceAssignmentValidationService.kt | 5 +- .../dict/service/ResourceDefinitionRepoService.kt | 61 ++++++++++++ .../service/ResourceDefinitionValidationService.kt | 5 +- .../dict/utils/BulkResourceSequencingUtils.kt | 5 +- .../resource/dict/utils/ResourceDictionaryUtils.kt | 5 +- .../resource/dict/ResourceDefinitionTest.java | 8 +- .../ResourceAssignmentEnhancerServiceTest.java | 48 +++++++++ .../ResourceAssignmentValidationServiceTest.kt | 5 +- .../service/ResourceDefinitionRepoServiceTest.java | 36 +++++++ .../dict/utils/ResourceDictionaryUtilsTest.java | 7 +- .../src/test/resources/enrich/simple-enrich.json | 37 +++++++ .../service/AutoResourceMappingService.java | 6 +- .../service/BluePrintEnhancerService.java | 10 +- .../service/ConfigModelCreateService.java | 6 +- .../service/ConfigModelService.java | 60 ++++++------ .../service/DataBaseInitService.java | 10 +- .../service/SchemaGeneratorService.java | 6 +- .../service/ServiceTemplateService.java | 2 +- .../service/domain/ConfigModelContent.java | 11 +-- .../service/domain/ModelType.java | 21 ++-- .../service/domain/ResourceDictionary.java | 27 +++--- .../service/utils/ConfigModelUtils.java | 6 +- .../service/common/SchemaGeneratorServiceTest.java | 6 +- .../service/rs/ConfigModelRestTest.java | 6 +- .../service/rs/ModelTypeRestTest.java | 6 +- .../service/rs/ResourceDictionaryRestTest.java | 6 +- .../service/rs/ServiceTemplateRestTest.java | 6 +- .../validator/ServiceTemplateValidationTest.java | 6 +- 42 files changed, 628 insertions(+), 195 deletions(-) create mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt create mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/enrich/simple-enrich.json (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java b/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java index 26b943b61..32d06d2ec 100644 --- a/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java +++ b/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java @@ -21,8 +21,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class ControllerBluprintsApplicationTest { - private static Logger log = LoggerFactory.getLogger(ControllerBluprintsApplicationTest.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ControllerBluprintsApplicationTest.class); @Autowired private TestRestTemplate restTemplate; diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt index 85f1579e2..2e3edb65e 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt @@ -54,6 +54,8 @@ object BluePrintConstants { const val PATH_ATTRIBUTES: String = "attributes" const val PATH_ARTIFACTS: String = "artifacts" + const val MODEL_DIR_MODEL_TYPE: String = "model_type" + const val MODEL_DEFINITION_TYPE_NODE_TYPE: String = "node_type" const val MODEL_DEFINITION_TYPE_ARTIFACT_TYPE: String = "artifact_type" const val MODEL_DEFINITION_TYPE_CAPABILITY_TYPE: String = "capability_type" diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt index c90d65974..f38c317e7 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt @@ -23,6 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.* import org.onap.ccsdk.apps.controllerblueprints.core.format import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils import java.io.Serializable /** @@ -35,14 +36,23 @@ interface BluePrintEnhancerService : Serializable { @Throws(BluePrintException::class) fun enhance(content: String): ServiceTemplate - @Throws(BluePrintException::class) - fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate - /** * Read Blueprint from CSAR structure Directory */ @Throws(BluePrintException::class) fun enhance(fileName: String, basePath: String): ServiceTemplate + + @Throws(BluePrintException::class) + fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate + + @Throws(BluePrintException::class) + fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) + + @Throws(BluePrintException::class) + fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) + + @Throws(BluePrintException::class) + fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) } open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRepoService) : BluePrintEnhancerService { @@ -51,20 +61,25 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe lateinit var serviceTemplate: ServiceTemplate + @Throws(BluePrintException::class) override fun enhance(content: String): ServiceTemplate { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + return JacksonReactorUtils.readValueFromFile(content, ServiceTemplate::class.java).map { serviceTemplate -> + enhance(serviceTemplate!!) + }.block()!! } + @Throws(BluePrintException::class) override fun enhance(fileName: String, basePath: String): ServiceTemplate { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } + @Throws(BluePrintException::class) override fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate { this.serviceTemplate = serviceTemplate initialCleanUp() enrichTopologyTemplate(serviceTemplate) - // log.info("Enriched Blueprint :\n {}", JacksonUtils.getJson(serviceTemplate, true)) + // log.info("Enriched Blueprint :\n {}", JacksonUtils.getJson(serviceTemplate, true)) return this.serviceTemplate } @@ -79,6 +94,7 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe } + @Throws(BluePrintException::class) open fun enrichTopologyTemplate(serviceTemplate: ServiceTemplate) { serviceTemplate.topologyTemplate?.let { topologyTemplate -> enrichTopologyTemplateInputs(topologyTemplate) @@ -86,6 +102,7 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe } } + @Throws(BluePrintException::class) open fun enrichTopologyTemplateInputs(topologyTemplate: TopologyTemplate) { topologyTemplate.inputs?.let { inputs -> enrichPropertyDefinitions(inputs) @@ -99,7 +116,7 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe } @Throws(BluePrintException::class) - open fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) { + override fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) { val nodeTypeName = nodeTemplate.type // Get NodeType from Repo and Update Service Template val nodeType = populateNodeType(nodeTypeName) @@ -111,7 +128,8 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe enrichNodeTemplateArtifactDefinition(nodeTemplateName, nodeTemplate) } - open fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) { + @Throws(BluePrintException::class) + override fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) { // NodeType Property Definitions enrichNodeTypeProperties(nodeTypeName, nodeType) @@ -132,7 +150,7 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) { - nodeType.requirements?.forEach { requirementDefinitionName, requirementDefinition -> + nodeType.requirements?.forEach { _, requirementDefinition -> // Populate Requirement Node requirementDefinition.node?.let { requirementNodeTypeName -> // Get Requirement NodeType from Repo and Update Service Template @@ -187,7 +205,8 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe } } - open fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) { + @Throws(BluePrintException::class) + override fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) { val propertyType = propertyDefinition.type if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt index 8d2557cdb..e1d1eac71 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt @@ -17,15 +17,12 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service -import com.google.common.base.Preconditions -import org.apache.commons.io.FileUtils -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.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils import reactor.core.publisher.Mono import java.io.File import java.io.Serializable @@ -57,15 +54,15 @@ interface BluePrintRepoService : Serializable { } -class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService { +open class BluePrintRepoFileService(modelTypePath: String) : BluePrintRepoService { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRepoFileService::class.toString()) - private val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) - private val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) - private val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) - private val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) - private val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + private val dataTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + private val nodeTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + private val artifactTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + private val capabilityTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + private val relationshipTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) private val extension = ".json" override fun getDataType(dataTypeName: String): Mono? { @@ -98,17 +95,6 @@ class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService { } private fun getModelType(fileName: String, valueType: Class): Mono { - return getFileContent(fileName).map { content -> - Preconditions.checkArgument(StringUtils.isNotBlank(content), - String.format("Failed to get model content for file (%s)", fileName)) - - JacksonUtils.readValue(content, valueType) - ?: throw BluePrintException(String.format("Failed to get model file from content for file (%s)", fileName)) - - } - } - - private fun getFileContent(fileName: String): Mono { - return Mono.just(FileUtils.readFileToString(File(fileName), Charset.defaultCharset())) + return JacksonReactorUtils.readValueFromFile(fileName, valueType) } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt new file mode 100644 index 000000000..0ed901702 --- /dev/null +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt @@ -0,0 +1,108 @@ +/* + * 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.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import reactor.core.publisher.Mono +import reactor.core.publisher.toMono + +object JacksonReactorUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @JvmStatic + fun getContent(fileName: String): Mono { + return JacksonUtils.getContent(fileName).toMono() + } + + @JvmStatic + fun getClassPathFileContent(fileName: String): Mono { + return JacksonUtils.getClassPathFileContent(fileName).toMono() + } + + @JvmStatic + fun readValue(content: String, valueType: Class): Mono { + return Mono.just(jacksonObjectMapper().readValue(content, valueType)) + } + + @JvmStatic + fun jsonNode(content: String): Mono { + return Mono.just(jacksonObjectMapper().readTree(content)) + } + + @JvmStatic + fun getJson(any: kotlin.Any, pretty: Boolean = false): Mono { + return Mono.just(JacksonUtils.getJson(any, pretty)) + } + + @JvmStatic + fun getListFromJson(content: String, valueType: Class): Mono> { + val objectMapper = jacksonObjectMapper() + val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType) + return objectMapper.readValue>(content, javaType).toMono() + } + + @JvmStatic + fun readValueFromFile(fileName: String, valueType: Class): Mono { + return getContent(fileName) + .flatMap { content -> + readValue(content, valueType) + } + } + + @JvmStatic + fun readValueFromClassPathFile(fileName: String, valueType: Class): Mono { + return getClassPathFileContent(fileName) + .flatMap { content -> + readValue(content, valueType) + } + } + + @JvmStatic + fun jsonNodeFromFile(fileName: String): Mono { + return getContent(fileName) + .flatMap { content -> + jsonNode(content) + } + } + + @JvmStatic + fun jsonNodeFromClassPathFile(fileName: String): Mono { + return getClassPathFileContent(fileName) + .flatMap { content -> + jsonNode(content) + } + } + + @JvmStatic + fun getListFromFile(fileName: String, valueType: Class): Mono> { + return getContent(fileName) + .flatMap { content -> + getListFromJson(content, valueType) + } + } + + @JvmStatic + fun getListFromClassPathFile(fileName: String, valueType: Class): Mono> { + return getClassPathFileContent(fileName) + .flatMap { content -> + getListFromJson(content, valueType) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 7e72744c9..5075e7261 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -23,9 +23,6 @@ import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.SerializationFeature -import com.fasterxml.jackson.databind.node.ArrayNode -import com.fasterxml.jackson.databind.node.NullNode -import com.fasterxml.jackson.databind.node.ObjectNode import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.apache.commons.io.FileUtils import org.apache.commons.io.IOUtils @@ -52,6 +49,17 @@ object JacksonUtils { return jacksonObjectMapper().readValue(content, valueType) } + @JvmStatic + fun getContent(fileName: String): String { + return File(fileName).readText(Charsets.UTF_8) + } + + @JvmStatic + fun getClassPathFileContent(fileName: String): String { + return IOUtils.toString(JacksonUtils::class.java.classLoader + .getResourceAsStream(fileName), Charset.defaultCharset()) + } + @JvmStatic fun readValueFromFile(fileName: String, valueType: Class): T? { val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) @@ -61,8 +69,7 @@ object JacksonUtils { @JvmStatic fun readValueFromClassPathFile(fileName: String, valueType: Class): T? { - val content: String = IOUtils.toString(JacksonUtils::class.java.classLoader.getResourceAsStream(fileName), Charset.defaultCharset()) - ?: throw BluePrintException(String.format("Failed to read json file : %s", fileName)) + val content: String = getClassPathFileContent(fileName) return readValue(content, valueType) } @@ -71,8 +78,7 @@ object JacksonUtils { @JvmStatic fun jsonNodeFromClassPathFile(fileName: String): JsonNode { - val content: String = IOUtils.toString(JacksonUtils::class.java.classLoader.getResourceAsStream(fileName), Charset.defaultCharset()) - ?: throw BluePrintException(String.format("Failed to read json file : %s", fileName)) + val content: String = getClassPathFileContent(fileName) return jsonNode(content) } @@ -119,8 +125,7 @@ object JacksonUtils { @JvmStatic fun getListFromClassPathFile(fileName: String, valueType: Class): List? { - val content: String = IOUtils.toString(JacksonUtils::class.java.classLoader.getResourceAsStream(fileName), Charset.defaultCharset()) - ?: throw BluePrintException(String.format("Failed to read json file : %s", fileName)) + val content: String = getClassPathFileContent(fileName) return getListFromJson(content, valueType) } @@ -144,39 +149,25 @@ object JacksonUtils { @JvmStatic fun checkJsonNodeValueOfPrimitiveType(primitiveType: String, jsonNode: JsonNode): Boolean { when (primitiveType) { - BluePrintConstants.DATA_TYPE_STRING -> { - return jsonNode.isTextual - } - BluePrintConstants.DATA_TYPE_BOOLEAN -> { - return jsonNode.isBoolean - } - BluePrintConstants.DATA_TYPE_INTEGER -> { - return jsonNode.isInt - } - BluePrintConstants.DATA_TYPE_FLOAT -> { - return jsonNode.isDouble - } - BluePrintConstants.DATA_TYPE_TIMESTAMP -> { - return jsonNode.isTextual - } - else -> - return false + BluePrintConstants.DATA_TYPE_STRING -> return jsonNode.isTextual + BluePrintConstants.DATA_TYPE_BOOLEAN -> return jsonNode.isBoolean + BluePrintConstants.DATA_TYPE_INTEGER -> return jsonNode.isInt + BluePrintConstants.DATA_TYPE_FLOAT -> return jsonNode.isDouble + BluePrintConstants.DATA_TYPE_TIMESTAMP -> return jsonNode.isTextual + else -> return false } } @JvmStatic fun checkJsonNodeValueOfCollectionType(type: String, jsonNode: JsonNode): Boolean { when (type) { - BluePrintConstants.DATA_TYPE_LIST -> - return jsonNode.isArray - BluePrintConstants.DATA_TYPE_MAP -> - return jsonNode.isContainerNode - else -> - return false + BluePrintConstants.DATA_TYPE_LIST -> return jsonNode.isArray + BluePrintConstants.DATA_TYPE_MAP -> return jsonNode.isContainerNode + else -> return false } } - +/* @JvmStatic fun populatePrimitiveValues(key: String, value: Any, primitiveType: String, objectNode: ObjectNode) { if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { @@ -253,4 +244,5 @@ object JacksonUtils { objectNode.set(key, nodeValue) } } + */ } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt index 081f4fe3b..88aea919e 100644 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt +++ b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -28,30 +28,30 @@ import kotlin.test.assertNotNull */ class BluePrintRepoFileServiceTest { - val basePath = "load/model_type" + private val basePath = "load/model_type" private val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) @Test fun testGetDataType() { - val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate") + val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate")?.block() assertNotNull(dataType, "Failed to get DataType from repo") } @Test fun testGetNodeType() { - val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment") + val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment")?.block() assertNotNull(nodeType, "Failed to get NodeType from repo") } @Test fun testGetArtifactType() { - val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity") + val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")?.block() assertNotNull(nodeType, "Failed to get ArtifactType from repo") } @Test(expected = FileNotFoundException::class) fun testModelNotFound() { - val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found") + val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found")?.block() assertNotNull(dataType, "Failed to get DataType from repo") } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt new file mode 100644 index 000000000..d13caa52c --- /dev/null +++ b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt @@ -0,0 +1,51 @@ +/* + * 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.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import java.io.FileNotFoundException +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class JacksonReactorUtilsTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + @Test + fun testReadValues() { + + val serviceTemplate = JacksonReactorUtils.readValueFromFile("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json", + ServiceTemplate::class.java).block() + + assertNotNull(serviceTemplate, "Failed to simple transform Service Template") + assertEquals(true, serviceTemplate is ServiceTemplate, "failed to get Service Template instance") + + val jsonContent = JacksonReactorUtils.getJson(serviceTemplate!!, true).block() + assertNotNull(jsonContent, "Failed to get json content") + + val jsonNode = JacksonReactorUtils.jsonNodeFromFile("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json") + .block() + assertNotNull(jsonContent, "Failed to get json Node") + } + + @Test(expected = FileNotFoundException::class) + fun testReadValuesFailure() { + JacksonReactorUtils.jsonNodeFromFile("load/blueprints/not-found.json") + .block() + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json index c53a6dd3f..92b16a212 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json @@ -1,5 +1,5 @@ { - "name": "bundle-id", + "name": "db-source", "property" :{ "description": "name of the ", "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json index 91921b640..1c47f37b2 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json @@ -1,6 +1,6 @@ { "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", - "name": "v4-ip-type", + "name": "default-source", "property" :{ "description": "name of the ", "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json index c34c252b3..676d92f86 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json @@ -1,5 +1,5 @@ { - "name": "action-name", + "name": "input-source", "property" :{ "description": "name of the ", "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json index 413d90446..b49146a0e 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json @@ -1,6 +1,6 @@ { "tags": "oam-local-ipv4-address", - "name": "oam-local-ipv4-address", + "name": "mdsal-source", "property" :{ "description": "based on service-instance-id,network-role,v4-ip-type and vm-type get the ipv4-gateway-prefix from the SDN-GC mdsal", "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt index 9b89f6f40..aa6a9fb65 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -25,6 +25,8 @@ object ResourceDictionaryConstants { const val SOURCE_DEFAULT = "default" const val SOURCE_DB = "db" + const val MODEL_DIR_RESOURCE_DEFINITION: String = "resource_dictionary" + const val PROPERTY_TYPE = "type" const val PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping" const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping" diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt new file mode 100644 index 000000000..c5a78a9c9 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt @@ -0,0 +1,86 @@ +/* + * 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.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import com.att.eelf.configuration.EELFManager + +/** + * ResourceAssignmentEnhancerService. + * + * @author Brinda Santh + */ +interface ResourceAssignmentEnhancerService { + + @Throws(BluePrintException::class) + fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, + resourceAssignments: List) + + @Throws(BluePrintException::class) + fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate +} + +/** + * ResourceAssignmentEnhancerDefaultService. + * + * @author Brinda Santh + */ +open class ResourceAssignmentEnhancerDefaultService(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) + : ResourceAssignmentEnhancerService { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java) + + /** + * Get the defined source instance from the ResourceAssignment, + * then get the NodeType of the Sources assigned + */ + override fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, + resourceAssignments: List) { + + // Iterate the Resource Assignment and + resourceAssignments.map { resourceAssignment -> + val dictionaryName = resourceAssignment.dictionaryName!! + val dictionarySource = resourceAssignment.dictionarySource!! + log.info("Enriching Assignment name({}), dictionary name({}), source({})", resourceAssignment.name, + dictionaryName, dictionarySource) + // Get the Resource Definition from Repo + val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) + + val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource) + + // Enrich as NodeTemplate + bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate!!) + } + } + + override fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate { + val bluePrintEnhancerService = BluePrintEnhancerDefaultService(resourceDefinitionRepoService) + bluePrintEnhancerService.serviceTemplate = ServiceTemplate() + bluePrintEnhancerService.initialCleanUp() + enhanceBluePrint(bluePrintEnhancerService, resourceAssignments) + return bluePrintEnhancerService.serviceTemplate + } + + private fun getResourceDefinition(name: String): ResourceDefinition { + return resourceDefinitionRepoService.getResourceDefinition(name)!!.block()!! + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt index 4578aca7d..228b39e29 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -16,13 +16,14 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service +import com.att.eelf.configuration.EELFLogger import org.apache.commons.collections.CollectionUtils import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.slf4j.LoggerFactory +import com.att.eelf.configuration.EELFManager import java.io.Serializable /** @@ -42,7 +43,7 @@ interface ResourceAssignmentValidationService : Serializable { * @author Brinda Santh */ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValidationService { - private val log = LoggerFactory.getLogger(ResourceAssignmentValidationDefaultService::class.java) + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java) open var resourceAssignmentMap: Map = hashMapOf() open val validationMessage = StrBuilder() diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt new file mode 100644 index 000000000..d51338caf --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt @@ -0,0 +1,61 @@ +/* + * 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.resource.dict.service + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import reactor.core.publisher.Mono +/** + * ResourceDefinitionRepoService. + * + * @author Brinda Santh + */ +interface ResourceDefinitionRepoService : BluePrintRepoService { + + fun getResourceDefinition(resourceDefinitionName: String): Mono? +} + +/** + * ResourceDefinitionFileRepoService. + * + * @author Brinda Santh + */ +open class ResourceDefinitionFileRepoService : BluePrintRepoFileService, + ResourceDefinitionRepoService { + + private var resourceDefinitionPath: String + private val extension = ".json" + + constructor(basePath: String) : this(basePath, + basePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(BluePrintConstants.MODEL_DIR_MODEL_TYPE)) + + constructor(basePath: String, modelTypePath: String) : super(modelTypePath) { + resourceDefinitionPath = basePath.plus("/resource_dictionary") + } + + override fun getResourceDefinition(resourceDefinitionName: String): Mono? { + + val fileName = resourceDefinitionPath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(resourceDefinitionName).plus(extension) + + return JacksonReactorUtils.readValueFromFile(fileName, ResourceDefinition::class.java) + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt index 1defa538c..14855d4b6 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service +import com.att.eelf.configuration.EELFLogger import com.fasterxml.jackson.databind.JsonNode import com.google.common.base.Preconditions import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException @@ -29,7 +30,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpression 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.ResourceDefinition -import org.slf4j.LoggerFactory +import com.att.eelf.configuration.EELFManager import java.io.Serializable /** * ResourceDefinitionValidationService. @@ -49,7 +50,7 @@ interface ResourceDefinitionValidationService : Serializable { */ open class ResourceDefinitionDefaultValidationService(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService { - private val log = LoggerFactory.getLogger(ResourceDefinitionValidationService::class.java) + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidationService::class.java) override fun validate(resourceDefinition: ResourceDefinition) { Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt index 82fbd3ac1..747639c89 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt @@ -16,10 +16,11 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils +import com.att.eelf.configuration.EELFLogger import org.apache.commons.collections.CollectionUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.slf4j.LoggerFactory +import com.att.eelf.configuration.EELFManager import java.util.ArrayList /** * BulkResourceSequencingUtils. @@ -27,7 +28,7 @@ import java.util.ArrayList * @author Brinda Santh */ object BulkResourceSequencingUtils { - private val log = LoggerFactory.getLogger(BulkResourceSequencingUtils::class.java) + private val log: EELFLogger = EELFManager.getInstance().getLogger(BulkResourceSequencingUtils::class.java) @JvmStatic fun process(resourceAssignments: MutableList): List> { diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt index 733a443fd..a3456cd43 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -16,6 +16,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils +import com.att.eelf.configuration.EELFLogger import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.NullNode import org.apache.commons.collections.MapUtils @@ -25,11 +26,11 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants -import org.slf4j.LoggerFactory +import com.att.eelf.configuration.EELFManager object ResourceDictionaryUtils { - private val log = LoggerFactory.getLogger(ResourceDictionaryUtils::class.java) + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDictionaryUtils::class.java) @JvmStatic fun populateSourceMapping(resourceAssignment: ResourceAssignment, diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java index 3e68d0991..fde800057 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java @@ -20,12 +20,12 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict; import org.junit.Assert; import org.junit.Test; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; public class ResourceDefinitionTest { - private Logger log = LoggerFactory.getLogger(ResourceDefinitionTest.class); - String basePath = "load/resource_dictionary"; + private EELFLogger log = EELFManager.getInstance().getLogger(ResourceDefinitionTest.class); + private String basePath = "load/resource_dictionary"; @Test public void testDictionaryDefinitionInputSource(){ diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java new file mode 100644 index 000000000..57c8509d1 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java @@ -0,0 +1,48 @@ +/* + * 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.resource.dict.service; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; + +import java.util.List; + +/** + * ResourceAssignmentEnhancerService. + * + * @author Brinda Santh + */ +public class ResourceAssignmentEnhancerServiceTest { + + @Test + public void testEnhanceBluePrint() throws BluePrintException { + + List resourceAssignments = JacksonReactorUtils + .getListFromClassPathFile("enrich/simple-enrich.json", ResourceAssignment.class).block(); + Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments); + ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load"); + ResourceAssignmentEnhancerService resourceAssignmentEnhancerService = + new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService); + ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments); + Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate); + } +} + diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt index 4d8301f4e..6216d5bf0 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt @@ -16,19 +16,20 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service +import com.att.eelf.configuration.EELFLogger import org.junit.Assert import org.junit.Test import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.slf4j.LoggerFactory +import com.att.eelf.configuration.EELFManager /** * ResourceAssignmentValidationServiceTest. * * @author Brinda Santh */ class ResourceAssignmentValidationServiceTest { - private val log = LoggerFactory.getLogger(ResourceAssignmentValidationServiceTest::class.java) + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java) @Test fun testValidateSuccess() { log.info("**************** testValidateSuccess *****************") diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java new file mode 100644 index 000000000..1772277df --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java @@ -0,0 +1,36 @@ +/* + * 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.resource.dict.service; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; + +public class ResourceDefinitionRepoServiceTest { + + @Test + public void testGetResourceDefinition() throws Exception{ + ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load"); + ResourceDefinition resourceDefinition = resourceDefinitionRepoService + .getResourceDefinition("db-source").block(); + Assert.assertNotNull("Failed to get Resource Definition db-source", resourceDefinition); + + NodeType nodeType = resourceDefinitionRepoService.getNodeType("source-db").block(); + Assert.assertNotNull("Failed to get Node Type source-db", resourceDefinition); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java index 5ee561713..13bf8195e 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -27,8 +27,8 @@ 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.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.util.HashMap; import java.util.Map; @@ -38,12 +38,13 @@ import java.util.Map; * @author Brinda Santh */ public class ResourceDictionaryUtilsTest { - private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class); + private static final EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); @Test public void testPopulateSourceMapping() { ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("sample-assignment"); ResourceDefinition resourceDefinition = new ResourceDefinition(); Map sources = new HashMap<>(); resourceDefinition.setSources(sources); diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/enrich/simple-enrich.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/enrich/simple-enrich.json new file mode 100644 index 000000000..641da80a2 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/enrich/simple-enrich.json @@ -0,0 +1,37 @@ +[ + { + "name": "rs-db-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "db-source", + "dictionary-source": "db", + "dependencies": [ + "input-source" + ] + }, + { + "name": "ra-default-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "default-source", + "dictionary-source": "default", + "dependencies": [] + }, + { + "name": "ra-input-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "input-source", + "dictionary-source": "input", + "dependencies": [] + } +] 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 5eba4fc7f..428c52451 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 @@ -29,8 +29,8 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDict import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -49,7 +49,7 @@ import java.util.Map; @SuppressWarnings("unused") public class AutoResourceMappingService { - private static Logger log = LoggerFactory.getLogger(AutoResourceMappingService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(AutoResourceMappingService.class); private ResourceDictionaryRepository dataDictionaryRepository; 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 28be75e66..8e98f9477 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 @@ -29,8 +29,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDe 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; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -46,7 +46,7 @@ import java.util.Map; @Service public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { - private static Logger log = LoggerFactory.getLogger(BluePrintEnhancerService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); private Map recipeDataTypes = new HashMap<>(); @@ -55,7 +55,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { } @Override - public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) { + public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException{ super.enrichTopologyTemplate(serviceTemplate); // Update the Recipe Inputs and DataTypes @@ -143,7 +143,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { } private Map getCapabilityMappingProperties(String nodeTemplateName, - NodeTemplate nodeTemplate) { + NodeTemplate nodeTemplate) throws BluePrintException { Map dataTypeProperties = null; if (nodeTemplate != null && MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index 9c1a045cd..3c92f7e94 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -31,8 +31,8 @@ import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConsta import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.io.IOException; @@ -52,7 +52,7 @@ import java.util.Optional; @Service public class ConfigModelCreateService { - private static Logger log = LoggerFactory.getLogger(ConfigModelCreateService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelCreateService.class); private ConfigModelRepository configModelRepository; private ConfigModelValidatorService configModelValidatorService; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java index b729e3e6d..534394a3e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java @@ -29,8 +29,8 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -49,7 +49,7 @@ import java.util.Optional; @Service public class ConfigModelService { - private static Logger log = LoggerFactory.getLogger(ConfigModelService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelService.class); private ConfigModelRepository configModelRepository; private ConfigModelContentRepository configModelContentRepository; @@ -57,14 +57,14 @@ public class ConfigModelService { /** * This is a ConfigModelService constructor. - * - * @param configModelRepository - * @param configModelContentRepository - * @param configModelCreateService + * + * @param configModelRepository configModelRepository + * @param configModelContentRepository configModelContentRepository + * @param configModelCreateService configModelCreateService */ public ConfigModelService(ConfigModelRepository configModelRepository, - ConfigModelContentRepository configModelContentRepository, - ConfigModelCreateService configModelCreateService) { + ConfigModelContentRepository configModelContentRepository, + ConfigModelCreateService configModelCreateService) { this.configModelRepository = configModelRepository; this.configModelContentRepository = configModelContentRepository; this.configModelCreateService = configModelCreateService; @@ -72,10 +72,10 @@ public class ConfigModelService { /** * This is a getInitialConfigModel method - * - * @param templateName + * + * @param templateName templateName * @return ConfigModel - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ConfigModel getInitialConfigModel(String templateName) throws BluePrintException { ConfigModel configModel = null; @@ -100,10 +100,10 @@ public class ConfigModelService { /** * This is a saveConfigModel method - * - * @param configModel + * + * @param configModel configModel * @return ConfigModel - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { return this.configModelCreateService.saveConfigModel(configModel); @@ -111,10 +111,10 @@ public class ConfigModelService { /** * This is a publishConfigModel method - * - * @param id + * + * @param id id * @return ConfigModel - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ConfigModel publishConfigModel(Long id) throws BluePrintException { return this.configModelCreateService.publishConfigModel(id); @@ -122,8 +122,8 @@ public class ConfigModelService { /** * This is a searchConfigModels method - * - * @param tags + * + * @param tags tags * @return ConfigModel */ public List searchConfigModels(String tags) { @@ -138,9 +138,9 @@ public class ConfigModelService { /** * This is a getConfigModelByNameAndVersion method - * - * @param name - * @param version + * + * @param name name + * @param version version * @return ConfigModel */ public ConfigModel getConfigModelByNameAndVersion(String name, String version) { @@ -159,8 +159,8 @@ public class ConfigModelService { /** * This is a getConfigModel method - * - * @param id + * + * @param id id * @return ConfigModel */ public ConfigModel getConfigModel(Long id) { @@ -176,9 +176,9 @@ public class ConfigModelService { /** * This method returns clone of the given model id, by masking the other unrelated fields - * - * @param id - * @return + * + * @param id id + * @return ConfigModel */ public ConfigModel getCloneConfigModel(Long id) { @@ -232,8 +232,8 @@ public class ConfigModelService { /** * This is a deleteConfigModel method - * - * @param id + * + * @param id id */ @Transactional 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 89d482962..4e7c3911c 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 @@ -22,6 +22,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.StrBuilder; +import org.jetbrains.annotations.NotNull; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType; @@ -33,8 +34,8 @@ 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; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -58,7 +59,7 @@ import java.util.List; @ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true") public class DataBaseInitService { - private static Logger log = LoggerFactory.getLogger(DataBaseInitService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(DataBaseInitService.class); @Value("${blueprints.load.path}") private String modelLoadPath; private ModelTypeService modelTypeService; @@ -91,6 +92,7 @@ public class DataBaseInitService { } @PostConstruct + @SuppressWarnings("unused") private void initDatabase() { log.info("loading Blueprints from DIR : {}", modelLoadPath); dataTypePath = modelLoadPath + "/model_type/data_type"; @@ -263,7 +265,7 @@ public class DataBaseInitService { } } - private void loadDataType(Resource file, StrBuilder errorBuilder) { + private void loadDataType(@NotNull Resource file, StrBuilder errorBuilder) { try { log.trace("Loading Data Type: {}", file.getFilename()); String dataKey = file.getFilename().replace(".json", ""); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java index a75651f19..04a95fd12 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java @@ -24,8 +24,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.common.SwaggerGenerator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.util.HashMap; import java.util.Map; @@ -39,7 +39,7 @@ import java.util.Map; */ public class SchemaGeneratorService { - private static Logger log = LoggerFactory.getLogger(SchemaGeneratorService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorService.class); private Map dataTypes; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java index 3e3c8e286..898647eaa 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -81,7 +81,7 @@ public class ServiceTemplateService { * @param serviceTemplate serviceTemplate * @return ServiceTemplate */ - public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) { + public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { this.bluePrintEnhancerService.enhance(serviceTemplate); return serviceTemplate; } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java index 60b3ed6b0..ae374a786 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -76,12 +76,11 @@ public class ConfigModelContent { @Override public String toString() { - StringBuilder builder = new StringBuilder("["); - builder.append("id = " + id); - builder.append(", name = " + name); - builder.append(", contentType = " + contentType); - builder.append("]"); - return builder.toString(); + String builder = "[" + "id = " + id + + ", name = " + name + + ", contentType = " + contentType + + "]"; + return builder; } @Override diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index eaa335b3e..cb8d229f3 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -82,17 +82,16 @@ public class ModelType implements Serializable { @Override public String toString() { - StringBuilder buffer = new StringBuilder("["); - buffer.append(", modelName = " + modelName); - buffer.append(", derivedFrom = " + derivedFrom); - buffer.append(", definitionType = " + definitionType); - buffer.append(", description = " + description); - buffer.append(", creationDate = " + creationDate); - buffer.append(", version = " + version); - buffer.append(", updatedBy = " + updatedBy); - buffer.append(", tags = " + tags); - buffer.append("]"); - return buffer.toString(); + String buffer = "[" + ", modelName = " + modelName + + ", derivedFrom = " + derivedFrom + + ", definitionType = " + definitionType + + ", description = " + description + + ", creationDate = " + creationDate + + ", version = " + version + + ", updatedBy = " + updatedBy + + ", tags = " + tags + + "]"; + return buffer; } public String getModelName() { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index 487586842..c88462202 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -92,20 +92,19 @@ public class ResourceDictionary implements Serializable { @Override public String toString() { - StringBuilder buffer = new StringBuilder("["); - buffer.append(", name = " + name); - buffer.append(", resourcePath = " + resourcePath); - buffer.append(", resourceType = " + resourceType); - buffer.append(", dataType = " + dataType); - buffer.append(", entrySchema = " + entrySchema); - buffer.append(", validValues = " + validValues); - buffer.append(", definition =" + definition); - buffer.append(", description = " + description); - buffer.append(", updatedBy = " + updatedBy); - buffer.append(", tags = " + tags); - buffer.append(", creationDate = " + creationDate); - buffer.append("]"); - return buffer.toString(); + String buffer = "[" + ", name = " + name + + ", resourcePath = " + resourcePath + + ", resourceType = " + resourceType + + ", dataType = " + dataType + + ", entrySchema = " + entrySchema + + ", validValues = " + validValues + + ", definition =" + definition + + ", description = " + description + + ", updatedBy = " + updatedBy + + ", tags = " + tags + + ", creationDate = " + creationDate + + "]"; + return buffer; } public String getResourcePath() { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java index bfc89b4ee..dc24c3bfe 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java @@ -27,8 +27,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData; import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.io.File; import java.io.IOException; @@ -43,7 +43,7 @@ public class ConfigModelUtils { } - private static Logger log = LoggerFactory.getLogger(ConfigModelUtils.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelUtils.class); public static ConfigModel getConfigModel(String blueprintPath) throws Exception { Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "Blueprint Path is missing"); diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java index f846e9a11..b70651fba 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java @@ -22,8 +22,8 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.service.SchemaGeneratorService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.io.File; import java.nio.charset.Charset; @@ -32,7 +32,7 @@ import java.nio.charset.Charset; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class SchemaGeneratorServiceTest { - private static Logger log = LoggerFactory.getLogger(SchemaGeneratorServiceTest.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorServiceTest.class); @Test public void test01GenerateSwaggerData() throws Exception { diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java index a4a787b08..4fa827c2a 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java @@ -22,8 +22,8 @@ import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -38,7 +38,7 @@ import java.util.List; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ConfigModelRestTest { - private static Logger log = LoggerFactory.getLogger(ConfigModelRestTest.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelRestTest.class); @Autowired ConfigModelRest configModelRest; diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java index 08bfeb10c..8e88f0a69 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java @@ -23,8 +23,8 @@ import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -40,7 +40,7 @@ import java.util.List; @ContextConfiguration(classes = {TestApplication.class}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ModelTypeRestTest { - private static Logger log = LoggerFactory.getLogger(ModelTypeRestTest.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeRestTest.class); @Autowired ModelTypeRest modelTypeRest; 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 ec036eef3..8bb1f0b89 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 @@ -25,8 +25,8 @@ import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -44,7 +44,7 @@ import java.util.List; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResourceDictionaryRestTest { - private static Logger log = LoggerFactory.getLogger(ResourceDictionaryRestTest.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryRestTest.class); @Autowired protected ResourceDictionaryRest resourceDictionaryRest; diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java index fdc68e4e5..217eb8f06 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java @@ -30,8 +30,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -49,7 +49,7 @@ import java.util.List; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ServiceTemplateRestTest { - private static Logger log = LoggerFactory.getLogger(ServiceTemplateRestTest.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ServiceTemplateRestTest.class); @Autowired ModelTypeRest modelTypeRest; diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java index e41e90a2d..93ea4c498 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java @@ -23,15 +23,15 @@ import org.junit.Test; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.io.File; import java.nio.charset.Charset; import java.util.List; public class ServiceTemplateValidationTest { - private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ServiceTemplateValidationTest.class); @Test public void testBluePrintDirs() { -- cgit 1.2.3-korg From 04709b1e651181fd3f1212e3641ca211738aece9 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 4 Sep 2018 20:24:35 +0000 Subject: Controller Blueprints Microservice Refactor controller blueprint core and resource dictionary modules to components module. Change-Id: If5ba5e35e9c95bc19bc78fb10bd62d6551ba7aca Issue-ID: CCSDK-514 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../Definitions/activation-blueprint.json | 411 -------------- .../Mappings/baseconfig-mapping.json | 3 - .../baseconfiguration/Plans/ActivateProcess.bpmn | 66 --- .../Scripts/SamplePythonComponentNode.py | 8 - .../baseconfiguration/Scripts/__init__.py | 0 .../baseconfiguration/TOSCA-Metadata/TOSCA.meta | 8 - .../Templates/baseconfig-template.vtl | 1 - .../load/blueprints/baseconfiguration/__init__.py | 0 .../Definitions/sample-nodetype.json | 34 -- .../Definitions/simple-baseconfig.json | 345 ------------ .../Mappings/baseconfig-mapping.json | 3 - .../simple-baseconfig/Plans/ActivateProcess.bpmn | 66 --- .../Scripts/SamplePythonComponentNode.py | 8 - .../simple-baseconfig/Scripts/__init__.py | 0 .../simple-baseconfig/TOSCA-Metadata/TOSCA.meta | 8 - .../Templates/base-config-template.vtl | 40 -- .../Templates/baseconfig-template.vtl | 1 - .../Templates/licence-template.vtl | 4 - .../load/blueprints/simple-baseconfig/__init__.py | 0 .../artifact_type/artifact-bpmn-camunda.json | 8 - .../artifact_type/artifact-directed-graph.json | 9 - .../artifact_type/artifact-mapping-resource.json | 8 - .../artifact_type/artifact-script-python.json | 8 - .../artifact_type/artifact-template-velocity.json | 8 - .../tosca.artifacts.Implementation.json | 5 - .../model_type/data_type/datatype-property.json | 27 - .../data_type/datatype-resource-assignment.json | 46 -- .../load/model_type/data_type/dt-license-key.json | 11 - .../load/model_type/data_type/dt-v4-aggregate.json | 15 - .../data_type/tosca.datatypes.Credential.json | 31 -- .../node_type/artifact-config-template.json | 37 -- .../node_type/component-config-generator.json | 72 --- .../node_type/component-netconf-executor.json | 79 --- .../node_type/component-resource-assignment.json | 68 --- .../model_type/node_type/dg-activate-netconf.json | 66 --- .../model_type/node_type/dg-config-generator.json | 65 --- .../node_type/dg-resource-assign-activate.json | 70 --- .../node_type/dg-resource-assignment.json | 65 --- .../model_type/node_type/vnf-netconf-device.json | 42 -- ms/controllerblueprints/modules/core/pom.xml | 66 --- .../core/BluePrintConstants.kt | 142 ----- .../core/BluePrintException.kt | 49 -- .../core/BluePrintProcessorException.kt | 49 -- .../controllerblueprints/core/BluePrintTypes.kt | 91 --- .../core/ConfigModelConstant.kt | 44 -- .../controllerblueprints/core/CustomFunctions.kt | 75 --- .../core/data/BluePrintExpressionData.kt | 70 --- .../core/data/BluePrintModel.kt | 612 --------------------- .../core/factory/BluePrintEnhancerFactory.kt | 45 -- .../core/factory/BluePrintParserFactory.kt | 51 -- .../core/factory/BluePrintValidatorFactory.kt | 45 -- .../core/service/BluePrintChainedService.kt | 117 ---- .../core/service/BluePrintContext.kt | 177 ------ .../core/service/BluePrintEnhancerService.kt | 259 --------- .../core/service/BluePrintExpressionService.kt | 176 ------ .../core/service/BluePrintParserService.kt | 62 --- .../core/service/BluePrintRepoService.kt | 100 ---- .../core/service/BluePrintRuntimeService.kt | 278 ---------- .../core/service/BluePrintValidatorService.kt | 360 ------------ .../core/service/PropertyAssignmentService.kt | 200 ------- .../core/utils/BluePrintMetadataUtils.kt | 95 ---- .../core/utils/BluePrintRuntimeUtils.kt | 55 -- .../core/utils/JacksonReactorUtils.kt | 108 ---- .../core/utils/JacksonUtils.kt | 248 --------- .../core/utils/ResourceResolverUtils.kt | 62 --- .../core/utils/ServiceTemplateUtils.kt | 44 -- .../core/utils/TopologicalSortingUtils.kt | 131 ----- .../core/CustomFunctionsTest.kt | 35 -- .../core/service/BluePrintContextTest.kt | 70 --- .../core/service/BluePrintEnhancerServiceTest.kt | 41 -- .../core/service/BluePrintExpressionServiceTest.kt | 109 ---- .../core/service/BluePrintParserFactoryTest.kt | 42 -- .../core/service/BluePrintRepoFileServiceTest.kt | 57 -- .../core/service/BluePrintRuntimeServiceTest.kt | 131 ----- .../BluePrintValidatorDefaultServiceTest.kt | 49 -- .../core/utils/BluePrintMetadataUtilsTest.kt | 40 -- .../core/utils/JacksonReactorUtilsTest.kt | 51 -- .../core/utils/JacksonUtilsTest.kt | 93 ---- .../core/utils/TopologicalSortingUtilsTest.kt | 36 -- .../src/test/resources/componentnode/default.json | 100 ---- .../core/src/test/resources/data/alltype-data.json | 10 - .../src/test/resources/data/default-context.json | 5 - .../resources/dictionary/dictionary_schema.json | 261 --------- .../src/test/resources/properties/convert.json | 33 -- .../src/test/resources/properties/default.json | 16 - ms/controllerblueprints/modules/pom.xml | 2 - .../node_type/source-component-java.json | 31 -- .../load/model_type/node_type/source-db.json | 44 -- .../load/model_type/node_type/source-default.json | 18 - .../load/model_type/node_type/source-input.json | 18 - .../load/model_type/node_type/source-rest.json | 61 -- .../node_type/tosca.nodes.ResourceSource.json | 5 - .../load/resource_dictionary/db-source.json | 26 - .../load/resource_dictionary/default-source.json | 18 - .../load/resource_dictionary/input-source.json | 19 - .../load/resource_dictionary/mdsal-source.json | 36 -- .../modules/resource-dict/pom.xml | 47 -- .../resource/dict/ResourceAssignmentProcessor.kt | 34 -- .../resource/dict/ResourceDefinition.kt | 100 ---- .../resource/dict/ResourceDictionaryConstants.kt | 34 -- .../service/ResourceAssignmentEnhancerService.kt | 86 --- .../service/ResourceAssignmentValidationService.kt | 151 ----- .../dict/service/ResourceDefinitionRepoService.kt | 61 -- .../service/ResourceDefinitionValidationService.kt | 114 ---- .../dict/utils/BulkResourceSequencingUtils.kt | 109 ---- .../resource/dict/utils/ResourceDictionaryUtils.kt | 78 --- .../resource/dict/ResourceDefinitionTest.java | 60 -- .../ResourceAssignmentEnhancerServiceTest.java | 48 -- .../ResourceAssignmentValidationServiceTest.kt | 57 -- .../service/ResourceDefinitionRepoServiceTest.java | 36 -- .../ResourceDefinitionValidationServiceTest.java | 56 -- .../utils/BulkResourceSequencingUtilsTest.java | 37 -- .../dict/utils/ResourceDictionaryUtilsTest.java | 99 ---- .../resources/data/resource-assignment-input.json | 10 - .../src/test/resources/enrich/simple-enrich.json | 37 -- .../src/test/resources/validation/cyclic.json | 111 ---- .../src/test/resources/validation/duplicate.json | 110 ---- .../src/test/resources/validation/success.json | 110 ---- 118 files changed, 8599 deletions(-) delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Scripts/__init__.py delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/__init__.py delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Definitions/sample-nodetype.json delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Mappings/baseconfig-mapping.json delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Plans/ActivateProcess.bpmn delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Scripts/SamplePythonComponentNode.py delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Scripts/__init__.py delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/TOSCA-Metadata/TOSCA.meta delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/base-config-template.vtl delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/baseconfig-template.vtl delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/licence-template.vtl delete mode 100644 ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/__init__.py delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-mapping-resource.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-script-python.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-template-velocity.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/tosca.artifacts.Implementation.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/data_type/datatype-property.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/data_type/datatype-resource-assignment.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/data_type/dt-license-key.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/data_type/dt-v4-aggregate.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/data_type/tosca.datatypes.Credential.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/artifact-config-template.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/component-config-generator.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/component-netconf-executor.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/component-resource-assignment.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/dg-activate-netconf.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/dg-config-generator.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/dg-resource-assign-activate.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/dg-resource-assignment.json delete mode 100644 ms/controllerblueprints/modules/core/load/model_type/node_type/vnf-netconf-device.json delete mode 100644 ms/controllerblueprints/modules/core/pom.xml delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintParserFactory.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt delete mode 100644 ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserFactoryTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt delete mode 100644 ms/controllerblueprints/modules/core/src/test/resources/componentnode/default.json delete mode 100644 ms/controllerblueprints/modules/core/src/test/resources/data/alltype-data.json delete mode 100644 ms/controllerblueprints/modules/core/src/test/resources/data/default-context.json delete mode 100644 ms/controllerblueprints/modules/core/src/test/resources/dictionary/dictionary_schema.json delete mode 100644 ms/controllerblueprints/modules/core/src/test/resources/properties/convert.json delete mode 100644 ms/controllerblueprints/modules/core/src/test/resources/properties/default.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/pom.xml delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/enrich/simple-enrich.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json b/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json deleted file mode 100644 index 635e177a1..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json +++ /dev/null @@ -1,411 +0,0 @@ -{ - "metadata": { - "template_author": "Brinda Santh Muthuramalingam", - "author-email": "brindasanth@gmail.com", - "user-groups" : "ADMIN, OPERATION", - "template_name": "baseconfiguration", - "template_version": "1.0.0", - "template_tags": "brinda, tosca" - }, - "topology_template": { - "inputs": { - "request-id": { - "required": true, - "type": "string" - }, - "action-name": { - "required": true, - "type": "string" - }, - "scope-type": { - "required": true, - "type": "string" - }, - "hostname": { - "required": true, - "type": "string" - } - }, - "node_templates": { - "activate-process": { - "type": "bpmn-activate", - "properties": { - "process-name": { "get_input" : "action-name" }, - "version" : { "get_property" : ["SELF", "process-name"] }, - "content": { "get_artifact" : ["SELF", "activate-process"] } - }, - "artifacts": { - "activate-process": { - "type": "artifact-bpmn-camunda", - "file": "Plans/ActivateProcess.bpmn" - } - } - }, - "resource-assignment": { - "type": "component-resource-assignment", - "properties":{ - "request-id": ["1234", "1234"] - }, - "interfaces": { - "DefaultComponentNode": { - "operations": { - "process": { - "inputs": { - "action-name": { "get_input" : "action-name" }, - "resource-type": "vnf-type", - "request-id": { "get_input" : "request-id" }, - "resource-id": { "get_input" : "hostname" }, - "template-content": { "get_artifact" : ["SELF", "baseconfig-template"] }, - "mapping-content": { "get_artifact" : ["SELF", "baseconfig-mapping"] } - }, - "outputs": { - "resource-assignment-params": "", - "status": "" - } - } - } - } - }, - "artifacts": { - "baseconfig-template": { - "type": "artifact-template-velocity", - "file": "Templates/baseconfig-template.vtl" - }, - "baseconfig-mapping": { - "type": "artifact-mapping-resource", - "file": "Mappings/baseconfig-mapping.json" - } - } - }, - "resource-assignment-py": { - "type": "component-resource-assignment", - "properties":{ - "request-id": ["1234", "1234"] - }, - "interfaces": { - "DefaultComponentNode": { - "operations": { - "process": { - "implementation" :{ - "primary" : "component-script" - }, - "inputs": { - "action-name": { "get_input" : "action-name" } - }, - "outputs": { - "resource-assignment-params": "", - "status": "" - } - } - } - } - }, - "artifacts": { - "component-script": { - "type": "artifact-script-python", - "file": "Scripts/baseconfig-template.vtl" - } - } - } - }, - "workflows":{ - "activate-process":{ - "steps" : { - "call-resource-assignment" : { - "description" : "Invoke Resource Assignment Component", - "target" : "resource-assignment", - "activities" : [ - { - "call_operation": "ResourceAssignmentNode.process" - } - ], - "on_success" : [ - "download-baseconfig" - ] - }, - "download-baseconfig" : { - "description" : "Call Download Base Config Component", - "target" : "activate-netconf", - "activities" : [ - { - "call_operation": "NetconfTransactionNode.process" - } - ], - "on_success" : [ - "download-licence" - ] - }, - "download-licence" : { - "description" : "Call Download Licence Component", - "target" : "activate-netconf", - "activities" : [ - { - "call_operation": "NetconfTransactionNode.process" - } - ] - } - } - } - } - }, - "artifact_types": { - "artifact-template-velocity": { - "description": " Velocity Template used for Configuration", - "version": "1.0.0", - "file_ext": [ - "vtl" - ], - "derived_from": "tosca.artifacts.Implementation" - }, - "artifact-mapping-resource": { - "description": " Velocity Template Resource Mapping File used along with Configuration template", - "version": "1.0.0", - "file_ext": [ - "json" - ], - "derived_from": "tosca.artifacts.Implementation" - }, - "artifact-script-kotlin": { - "description": " Kotlin Script Template used for Configuration", - "version": "1.0.0", - "file_ext": [ - "kt" - ], - "derived_from": "tosca.artifacts.Implementation" - }, - "artifact-script-python": { - "description": " Kotlin Script Template used for Configuration", - "version": "1.0.0", - "file_ext": [ - "py" - ], - "derived_from": "tosca.artifacts.Implementation" - }, - "artifact-bpmn-camunda": { - "description": " Camunda BPM File", - "version": "1.0.0", - "file_ext": [ - "bpmn" - ], - "derived_from": "tosca.artifacts.Implementation" - }, - "artifact-component-jar": { - "description": "Component Jar", - "version": "1.0.0", - "file_ext": [ - "jar" - ], - "derived_from": "tosca.artifacts.Implementation" - } - }, - "node_types": { - "bpmn-activate": { - "description": "This is BPMN Activate node type", - "version": "1.0.0", - "properties": { - "content": { - "required": false, - "type": "string" - }, - "process-name": { - "required": false, - "type": "string" - }, - "version": { - "required": false, - "type": "string", - "default" : "LATEST" - } - }, - "derived_from": "tosca.nodes.Component" - }, - "tosca.nodes.Component": { - "description": "This is Resource Assignment Component API", - "version": "1.0.0", - "properties": { - "type": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": false, - "type": "string" - } - }, - "interfaces": { - "DefaultOperation": { - "operations": { - "validate": { - "inputs": { - "action-name": { - "description": "validate for action", - "required": false, - "type": "string" - } - } - } - } - } - }, - "artifacts" :{ - "component-jar": { - "description": "Component Jar", - "type": "artifact-component-jar", - "file": "Component/basecomponent.jar" - } - }, - "derived_from": "tosca.nodes.Root" - }, - "tosca.nodes.component.Python": { - "description": "This is Resource Assignment Python Component API", - "version": "1.0.0", - "properties": { - "type": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": false, - "type": "string" - } - }, - "interfaces": { - "DefaultOperation": { - "operations": { - "validate": { - "inputs": { - "action-name": { - "description": "validate for action", - "required": false, - "type": "string" - } - } - } - } - } - }, - "artifacts" :{ - "component-jar": { - "description": "Component Jar", - "type": "artifact-component-jar", - "file": "Component/basecomponent.jar" - } - }, - "derived_from": "tosca.nodes.Root" - }, - "component-resource-assignment": { - "description": "This is Resource Assignment Component API", - "version": "1.0.0", - "properties": { - "request-id": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": true, - "type": "string" - } - }, - "interfaces": { - "DefaultComponentNode": { - "operations": { - "process": { - "inputs": { - "action-name": { - "description": "Recipe Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", - "required": false, - "type": "string" - }, - "resource-type": { - "required": false, - "type": "string" - }, - "request-id": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": true, - "type": "string" - }, - "resource-id": { - "description": "Id used to pull the data content from the data base. Either template-data or resource-id should be present", - "required": true, - "type": "string" - }, - "template-content": { - "description": "Id used to pull the data content from the data base. Either template-data or resource-id should be present", - "required": true, - "type": "string" - }, - "mapping-content": { - "description": "Id used to pull the data content from the data base. Either template-data or resource-id should be present", - "required": true, - "type": "string" - } - }, - "outputs": { - "resource-assignment-params": { - "required": true, - "type": "string" - }, - "status": { - "required": true, - "type": "string" - } - } - } - } - } - }, - "derived_from": "tosca.nodes.Component" - }, - "component-resource-assignment-python": { - "description": "This is Resource Assignment Component API", - "version": "1.0.0", - "properties": { - "request-id": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": true, - "type": "string" - } - }, - "interfaces": { - "DefaultComponentNode": { - "operations": { - "process": { - "inputs": { - "action-name": { - "description": "Recipe Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", - "required": false, - "type": "string" - } - }, - "outputs": { - "resource-assignment-params": { - "required": true, - "type": "string" - }, - "status": { - "required": true, - "type": "string" - } - } - } - } - } - }, - "derived_from": "tosca.nodes.component.Python" - } - }, - "data_types": { - "sample-property" : { - "description": "This is sample data type", - "version": "1.0.0", - "properties": { - "content": { - "required": false, - "type": "string" - }, - "process-name": { - "required": false, - "type": "string" - }, - "version": { - "required": false, - "type": "string", - "default" : "LATEST" - } - }, - "derived_from" : "tosca.datatypes.Root" - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json b/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json deleted file mode 100644 index 6abfb51bd..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "assignments": "Sample Assignments" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn b/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn deleted file mode 100644 index 5e94c0f8e..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn +++ /dev/null @@ -1,66 +0,0 @@ - - - - - SequenceFlow_0l0dq58 - - - SequenceFlow_1ay0k6p - - - - - - - - - - SequenceFlow_0l0dq58 - SequenceFlow_1ay0k6p - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py b/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py deleted file mode 100644 index eb198c79a..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py +++ /dev/null @@ -1,8 +0,0 @@ -from com.brvith.orchestrator.core.interfaces import ComponentNode - -class SamplePythonComponentNode(ComponentNode): - def prepare(self, context, componentContext): - return None - - def prepare(self, context, componentContext): - return None \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Scripts/__init__.py b/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Scripts/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta b/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta deleted file mode 100644 index fb38c1594..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta +++ /dev/null @@ -1,8 +0,0 @@ -TOSCA-Meta-File-Version: 1.0.0 -CSAR-Version: 1.0 -Created-By: Brinda Santh M -Entry-Definitions: Definitions/activation-blueprint.json -Template-Tags: Brinda Santh, activation-blueprint - -Name: Plans/ActivateProcess.bpmn -Content-Type: application/vnd.oasis.bpmn diff --git a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl b/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl deleted file mode 100644 index 026c59176..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl +++ /dev/null @@ -1 +0,0 @@ -This is Sample Velocity Template \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/__init__.py b/ms/controllerblueprints/modules/core/load/blueprints/baseconfiguration/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Definitions/sample-nodetype.json b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Definitions/sample-nodetype.json deleted file mode 100644 index 6d469ea84..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Definitions/sample-nodetype.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "description": "This is Resource Assignment Component API", - "version": "1.0.0", - "properties": { - "type": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": false, - "type": "string" - } - }, - "interfaces": { - "DefaultOperation": { - "operations": { - "validate": { - "inputs": { - "action-name": { - "description": "validate for action", - "required": false, - "type": "string" - } - } - } - } - } - }, - "artifacts" :{ - "component-jar": { - "description": "Component Jar", - "type": "artifact-component-jar", - "file": "Component/basecomponent.jar" - } - }, - "derived_from": "tosca.nodes.Root" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json deleted file mode 100644 index e78f32f02..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json +++ /dev/null @@ -1,345 +0,0 @@ -{ - "metadata": { - "template_author": "Brinda Santh", - "template_name": "simple-baseconfig", - "template_version": "1.0.0", - "service-type": "Sample Service", - "release": "1806", - "vnf-type": "VPE" - }, - "topology_template": { - "inputs": { - "request-id": { - "required": true, - "type": "string" - }, - "service-instance-id": { - "required": true, - "type": "string" - }, - "scope-type": { - "required": true, - "type": "string" - }, - "action-name": { - "required": true, - "type": "string" - }, - "hostname": { - "required": true, - "type": "string" - } - }, - "node_templates": { - "vpe-netconf-device": { - "capabilities": { - "netconf": { - "properties": { - "login-key": "sdnc", - "login-account": "sndc-local", - "source": "local", - "target-ip-address": "{\"get_attribute\":\"lo0-local-ipv4-address\"}", - "port-number": 22, - "connection-time-out": 30 - } - } - }, - "type": "vnf-netconf-device" - }, - "activate-netconf-component": { - "capabilities": { - "component-node": {} - }, - "requirements": { - "netconf-connection": { - "capability": "netconf", - "node": "vpe-netconf-device", - "relationship": "tosca.relationships.ConnectsTo" - } - }, - "interfaces": { - "org-openecomp-sdnc-netconf-adaptor-service-NetconfExecutorNode": { - "operations": { - "process": { - "inputs": { - "action-name": "{ \"get_input\" : \"action-name\" }", - "service-template-name": "{ \"get_attribute\" : \"template_name\" }", - "service-template-version": "{ \"get_attribute\" : \"service-template-version\" }", - "resource-type": "vnf-type", - "request-id": "{ \"get_input\" : \"request-id\" }", - "resource-id": "{ \"get_input\" : \"hostname\" }", - "execution-script": "execution-script" - }, - "outputs": { - "response-data": "{ \"get_attribute\" : \"netconf-executor-baseconfig.response-data\" }", - "status": "{ \"get_attribute\" : \"netconf-executor-baseconfig.status\" }" - }, - "implementation" : { - "primary" : "file://netconf_adaptor/DefaultBaseLicenceConfig.py" - } - } - } - } - }, - "type": "component-netconf-executor" - }, - "resource-assignment-ra-component": { - "capabilities": { - "component-node": {} - }, - "interfaces": { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { - "operations": { - "process": { - "inputs": { - "template-names": [ - "base-config-template", - "licence-template" - ], - "action-name": "{ \"get_input\" : \"action-name\" }", - "service-template-name": "{ \"get_attribute\" : \"template_name\" }", - "service-template-version": "{ \"get_attribute\" : \"service-template-version\" }", - "resource-type": "vnf-type", - "request-id": "{ \"get_input\" : \"request-id\" }", - "resource-id": "{ \"get_input\" : \"hostname\" }" - }, - "outputs": { - "resource-assignment-params": "success", - "status": "status" - } - } - } - } - }, - "type": "component-resource-assignment" - }, - "resource-assignment-action": { - "properties": { - "mode": "sync", - "version": "LATEST", - "is-start-flow": "false" - }, - "requirements": { - "component-dependency": { - "capability": "component-node", - "node": "resource-assignment-ra-component", - "relationship": "tosca.relationships.DependsOn" - } - }, - "capabilities": { - "dg-node": {}, - "content": { - "properties": { - "type": "json" - } - } - }, - "interfaces": { - "CONFIG": { - "operations": { - "ResourceAssignment": { - "inputs": { - "params": [] - } - } - } - } - }, - "type": "dg-resource-assignment" - }, - "activate-action": { - "properties": { - "mode": "sync", - "version": "LATEST", - "is-start-flow": "false" - }, - "requirements": { - "component-dependency": { - "capability": "component-node", - "node": "activate-netconf-component", - "relationship": "tosca.relationships.DependsOn" - } - }, - "capabilities": { - "dg-node": {}, - "content": { - "properties": { - "type": "json" - } - } - }, - "interfaces": { - "CONFIG": { - "operations": { - "ActivateNetconf": { - "inputs": { - "params": [] - } - } - } - } - }, - "type": "dg-activate-netconf" - }, - "base-config-template": { - "capabilities": { - "content": { - "properties": { - "content": "db://base-config-template" - } - }, - "mapping": { - "properties": { - "mapping": [ - { - "name": "bundle-mac", - "property": { - "description": "", - "required": true, - "type": "string", - "status": "", - "constraints": [ - {} - ], - "entry_schema": { - "type": "" - } - }, - "input-param": false, - "dictionary-name": "bundle-mac", - "dictionary-source": "db", - "dependencies": [ - "hostname" - ], - "version": 0 - }, - { - "name": "wan-aggregate-ipv4-addresses", - "property": { - "description": "", - "required": true, - "type": "list", - "status": "", - "constraints": [ - {} - ], - "entry_schema": { - "type": "dt-v4-aggregate" - } - }, - "input-param": false, - "dictionary-name": "wan-aggregate-ipv4-addresses", - "dictionary-source": "mdsal", - "dependencies": [ - "service-instance-id", - "oam-network-role", - "oam-v4-ip-type ", - "oam-vm-type" - ], - "version": 0 - }, - { - "name": "hostname", - "property": { - "required": true, - "type": "string" - }, - "dictionary-name": "hostname", - "dictionary-source": "input", - "version": 0, - "input-param": false - }, - { - "name": "service", - "property": { - "required": true, - "type": "string" - }, - "dictionary-name": "service", - "dictionary-source": "input", - "version": 0, - "input-param": false - }, - { - "name": "service-instance-id", - "property": { - "required": true, - "type": "string" - }, - "dictionary-name": "service-instance-id", - "dictionary-source": "input", - "version": 0, - "input-param": false - } - ] - } - } - }, - "properties": { - "action-names": [ - "resource-assignment-action" - ] - }, - "type": "artifact-config-template" - }, - "licence-template": { - "capabilities": { - "content": { - "properties": { - "content": "db://licence-template" - } - }, - "mapping": { - "properties": { - "mapping": [ - { - "name": "licenses", - "property": { - "description": "", - "required": true, - "type": "list", - "status": "", - "constraints": [ - {} - ], - "entry_schema": { - "type": "dt-license-key" - } - }, - "input-param": false, - "dictionary-name": "licenses", - "dictionary-source": "mdsal", - "dependencies": [ - "service-instance-id" - ], - "version": 0 - }, - { - "name": "service-instance-id", - "property": { - "required": true, - "type": "string" - }, - "dictionary-name": "service-instance-id", - "dictionary-source": "input", - "version": 0, - "input-param": false - } - ] - } - } - }, - "properties": { - "action-names": [ - "resource-assignment-action" - ] - }, - "type": "artifact-config-template" - } - } - }, - "node_types": { - }, - "data_types": { - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Mappings/baseconfig-mapping.json b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Mappings/baseconfig-mapping.json deleted file mode 100644 index 6abfb51bd..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Mappings/baseconfig-mapping.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "assignments": "Sample Assignments" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Plans/ActivateProcess.bpmn b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Plans/ActivateProcess.bpmn deleted file mode 100644 index 5e94c0f8e..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Plans/ActivateProcess.bpmn +++ /dev/null @@ -1,66 +0,0 @@ - - - - - SequenceFlow_0l0dq58 - - - SequenceFlow_1ay0k6p - - - - - - - - - - SequenceFlow_0l0dq58 - SequenceFlow_1ay0k6p - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Scripts/SamplePythonComponentNode.py b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Scripts/SamplePythonComponentNode.py deleted file mode 100644 index eb198c79a..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Scripts/SamplePythonComponentNode.py +++ /dev/null @@ -1,8 +0,0 @@ -from com.brvith.orchestrator.core.interfaces import ComponentNode - -class SamplePythonComponentNode(ComponentNode): - def prepare(self, context, componentContext): - return None - - def prepare(self, context, componentContext): - return None \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Scripts/__init__.py b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Scripts/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/TOSCA-Metadata/TOSCA.meta b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/TOSCA-Metadata/TOSCA.meta deleted file mode 100644 index d7ae5e8a2..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/TOSCA-Metadata/TOSCA.meta +++ /dev/null @@ -1,8 +0,0 @@ -TOSCA-Meta-File-Version: 1.0.0 -CSAR-Version: 1.0 -Created-By: Brinda Santh M -Entry-Definitions: Definitions/simple-baseconfig.json -Template-Tags: vrr-test, Brinda Santh - -Name: Plans/ActivateProcess.bpmn -Content-Type: application/vnd.oasis.bpmn diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/base-config-template.vtl b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/base-config-template.vtl deleted file mode 100644 index 92dba1024..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/base-config-template.vtl +++ /dev/null @@ -1,40 +0,0 @@ - - - - ${group-name} - - - <*> - - - - - - 224.0.1.40/32 - - - 224.0.1.39/32 - - - 224.0.0.0/4 - - - - - - - - - - <*> - - 1000 - - - - - - - - - \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/baseconfig-template.vtl b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/baseconfig-template.vtl deleted file mode 100644 index 026c59176..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/baseconfig-template.vtl +++ /dev/null @@ -1 +0,0 @@ -This is Sample Velocity Template \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/licence-template.vtl b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/licence-template.vtl deleted file mode 100644 index 626974f27..000000000 --- a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/Templates/licence-template.vtl +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/__init__.py b/ms/controllerblueprints/modules/core/load/blueprints/simple-baseconfig/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json deleted file mode 100644 index ac76b4f4f..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "description": " Camunda BPM File", - "version": "1.0.0", - "file_ext": [ - "bpmn" - ], - "derived_from": "tosca.artifacts.Implementation" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json deleted file mode 100644 index 7ab3a5434..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "description": "Directed Graph File", - "version": "1.0.0", - "file_ext": [ - "json", - "xml" - ], - "derived_from": "tosca.artifacts.Implementation" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-mapping-resource.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-mapping-resource.json deleted file mode 100644 index 0a3261b09..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-mapping-resource.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "description": " Velocity Template Resource Mapping File used along with Configuration template", - "version": "1.0.0", - "file_ext": [ - "json" - ], - "derived_from": "tosca.artifacts.Implementation" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-script-python.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-script-python.json deleted file mode 100644 index b48d2b628..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-script-python.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "description": " Kotlin Script Template used for Configuration", - "version": "1.0.0", - "file_ext": [ - "py" - ], - "derived_from": "tosca.artifacts.Implementation" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-template-velocity.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-template-velocity.json deleted file mode 100644 index 9395d3970..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-template-velocity.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "description": " Velocity Template used for Configuration", - "version": "1.0.0", - "file_ext": [ - "vtl" - ], - "derived_from": "tosca.artifacts.Implementation" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/tosca.artifacts.Implementation.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/tosca.artifacts.Implementation.json deleted file mode 100644 index 5a7c95684..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/tosca.artifacts.Implementation.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "description": "TOSCA base type for implementation artifacts", - "version": "1.0.0", - "derived_from": "tosca.artifacts.Root" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/data_type/datatype-property.json b/ms/controllerblueprints/modules/core/load/model_type/data_type/datatype-property.json deleted file mode 100644 index 5584b10ea..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/data_type/datatype-property.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "version": "1.0.0", - "description": "This is Entry point Input Data Type, which is dynamic datatype, The parameter names will be populated during the Design time for each inputs", - "properties": { - "type": { - "required": true, - "type": "string" - }, - "description": { - "required": false, - "type": "string" - }, - "required": { - "required": false, - "type": "boolean" - }, - "default": { - "required": false, - "type": "string" - }, - "entry_schema": { - "required": false, - "type": "string" - } - }, - "derived_from": "tosca.datatypes.Root" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/data_type/datatype-resource-assignment.json b/ms/controllerblueprints/modules/core/load/model_type/data_type/datatype-resource-assignment.json deleted file mode 100644 index cc9816ebb..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/data_type/datatype-resource-assignment.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "version": "1.0.0", - "description": "This is Resource Assignment Data Type", - "properties": { - "property": { - "required": true, - "type": "datatype-property" - }, - "input-param": { - "required": true, - "type": "boolean" - }, - "dictionary-name": { - "required": false, - "type": "string" - }, - "dictionary-source": { - "required": false, - "type": "string" - }, - "dependencies": { - "required": true, - "type": "list", - "entry_schema": { - "type": "string" - } - }, - "status": { - "required": false, - "type": "string" - }, - "message": { - "required": false, - "type": "string" - }, - "updated-date": { - "required": false, - "type": "string" - }, - "updated-by": { - "required": false, - "type": "string" - } - }, - "derived_from": "tosca.datatypes.Root" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/data_type/dt-license-key.json b/ms/controllerblueprints/modules/core/load/model_type/data_type/dt-license-key.json deleted file mode 100644 index e9c312b79..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/data_type/dt-license-key.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "1.0.0", - "description": "This is dt-plicense-key Data Type", - "properties": { - "license-key": { - "required": true, - "type": "string" - } - }, - "derived_from": "tosca.datatypes.Root" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/data_type/dt-v4-aggregate.json b/ms/controllerblueprints/modules/core/load/model_type/data_type/dt-v4-aggregate.json deleted file mode 100644 index 842a7f805..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/data_type/dt-v4-aggregate.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": "1.0.0", - "description": "This is dt-v4-aggregate Data Type", - "properties": { - "ipv4-address": { - "required": true, - "type": "string" - }, - "ipv4-plen": { - "required": false, - "type": "integer" - } - }, - "derived_from": "tosca.datatypes.Root" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/data_type/tosca.datatypes.Credential.json b/ms/controllerblueprints/modules/core/load/model_type/data_type/tosca.datatypes.Credential.json deleted file mode 100644 index 820a55168..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/data_type/tosca.datatypes.Credential.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "version": "1.0.0", - "description": "Credential", - "properties": { - "protocol": { - "required": false, - "type": "string" - }, - "token_type": { - "required": true, - "type": "string", - "default" : "password" - }, - "token": { - "required": false, - "type": "string" - }, - "keys": { - "required": false, - "type": "list", - "entry_schema": { - "type": "string" - } - }, - "user": { - "required": false, - "type": "string" - } - }, - "derived_from": "tosca.datatypes.Root" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/artifact-config-template.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/artifact-config-template.json deleted file mode 100644 index be9bbfc0e..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/artifact-config-template.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "description": "This is Configuration Velocity Template", - "version": "1.0.0", - "properties": { - "action-names": { - "required": true, - "type": "list", - "entry_schema": { - "type": "string" - } - } - }, - "capabilities": { - "content": { - "type": "tosca.capability.Content", - "properties": { - "content": { - "required": true, - "type": "string" - } - } - }, - "mapping": { - "type": "tosca.capability.Mapping", - "properties": { - "mapping": { - "required": false, - "type": "list", - "entry_schema": { - "type": "datatype-resource-assignment" - } - } - } - } - }, - "derived_from": "tosca.nodes.Artifact" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/component-config-generator.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/component-config-generator.json deleted file mode 100644 index 764f9e890..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/component-config-generator.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "description": "This is Generate Configuration Component API", - "version": "1.0.0", - "capabilities": { - "component-node": { - "type": "tosca.capabilities.Node" - } - }, - "interfaces": { - "org-openecomp-sdnc-config-generator-service-ConfigGeneratorNode": { - "operations": { - "process": { - "inputs": { - "template-data": { - "description": "Conditional : JSON string which is used to mash with template. Either template-data or ( resource-id and resource-type ) should be present", - "required": false, - "type": "string" - }, - "template-content": { - "description": "Conditional : Dynamic Template used to generate Configuration.", - "required": false, - "type": "string" - }, - "resource-type": { - "description": "Conditional : resource-type used to pull the data content from the data base. Either template-data or ( resource-id and resource-type ) should be present", - "required": false, - "type": "string" - }, - "request-id": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": true, - "type": "string" - }, - "resource-id": { - "description": "Conditional : Id used to pull the data content from the data base. Either template-data or ( resource-id and resource-type ) should be present", - "required": false, - "type": "string" - }, - "action-name": { - "description": "Conditional : Action Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", - "required": false, - "type": "string" - }, - "template-name": { - "description": "Conditional : Name of the Artifact Node Template, to get the template Content. If template-content is present, then content wont be reterived from the Artifact Node Template.", - "required": true, - "type": "string" - } - }, - "outputs": { - "generated-config": { - "description": "Generated Configuration for the Template adn Resource Data", - "required": true, - "type": "string" - }, - "mask-info": { - "description": "If template contains mask encription keys, then this mask-info field will be generated, This JSON Content alligns to the bean org.onap.ccsdk.apps.controllerblueprints.core.data.custom.MaskInfo ", - "required": false, - "type": "string" - }, - "status": { - "description": "Status of the Component Execution ( success or failure )", - "required": true, - "type": "string" - } - } - } - } - } - }, - "derived_from": "tosca.nodes.Component" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/component-netconf-executor.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/component-netconf-executor.json deleted file mode 100644 index aed667aaf..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/component-netconf-executor.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "description": "This is Netconf Transaction Configuration Component API", - "version": "1.0.0", - "capabilities": { - "component-node": { - "type": "tosca.capabilities.Node" - } - }, - "requirements": { - "netconf-connection": { - "capability": "netconf", - "node": "vnf-netconf-device", - "relationship": "tosca.relationships.ConnectsTo" - } - }, - "interfaces": { - "org-openecomp-sdnc-netconf-adaptor-service-NetconfExecutorNode": { - "operations": { - "process": { - "inputs": { - "request-id": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": true, - "type": "string" - }, - "service-template-name": { - "description": "Service Template Name", - "required": true, - "type": "string" - }, - "service-template-version": { - "description": "Service Template Version", - "required": true, - "type": "string" - }, - "action-name": { - "description": "Action Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", - "required": false, - "type": "string" - }, - "resource-type": { - "description": "Resource Type to get from Database, Either (message & mask-info ) or( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", - "required": false, - "type": "string" - }, - "resource-id": { - "description": "Resource Id to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", - "required": false, - "type": "string" - }, - "reservation-id": { - "description": "Reservation Id used to send to NPM", - "required": false, - "type": "string" - }, - "execution-script": { - "description": "Python Script to Execute for this Component action, It should refer any one of Prython Artifact Definition for this Node Template.", - "required": true, - "type": "string" - } - }, - "outputs": { - "response-data": { - "description": "Execution Response Data in JSON format.", - "required": false, - "type": "string" - }, - "status": { - "description": "Status of the Component Execution ( success or failure )", - "required": true, - "type": "string" - } - } - } - } - } - }, - "derived_from": "tosca.nodes.Component" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/component-resource-assignment.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/component-resource-assignment.json deleted file mode 100644 index 34c028482..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/component-resource-assignment.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "description": "This is Resource Assignment Component API", - "version": "1.0.0", - "capabilities": { - "component-node": { - "type": "tosca.capabilities.Node" - } - }, - "interfaces": { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { - "operations": { - "process": { - "inputs": { - "service-template-name": { - "description": "Service Template Name.", - "required": true, - "type": "string" - }, - "service-template-version": { - "description": "Service Template Version.", - "required": true, - "type": "string" - }, - "resource-type": { - "description": "Request type.", - "required": true, - "type": "string" - }, - "template-names": { - "description": "Name of the artifact Node Templates, to get the template Content.", - "required": true, - "type": "list", - "entry_schema": { - "type": "string" - } - }, - "request-id": { - "description": "Request Id, Unique Id for the request.", - "required": true, - "type": "string" - }, - "resource-id": { - "description": "Resource Id.", - "required": true, - "type": "string" - }, - "action-name": { - "description": "Action Name of the process", - "required": true, - "type": "string" - } - }, - "outputs": { - "resource-assignment-params": { - "required": true, - "type": "string" - }, - "status": { - "required": true, - "type": "string" - } - } - } - } - } - }, - "derived_from": "tosca.nodes.Component" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-activate-netconf.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-activate-netconf.json deleted file mode 100644 index c638df00c..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-activate-netconf.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "description": "This is Download Netconf Directed Graph", - "version": "1.0.0", - "properties": { - "mode": { - "required": false, - "type": "string", - "default": "sync" - }, - "version": { - "required": false, - "type": "string", - "default": "LATEST" - }, - "is-start-flow": { - "required": false, - "type": "boolean", - "default": "false" - } - }, - "capabilities": { - "dg-node": { - "type": "tosca.capabilities.Node" - }, - "content": { - "type": "tosca.capability.Content", - "properties": { - "type": { - "required": false, - "type": "string", - "default": "json" - }, - "content": { - "required": true, - "type": "string" - } - } - } - }, - "requirements": { - "component-dependency": { - "capability": "component-node", - "node": "component-netconf-executor", - "relationship": "tosca.relationships.DependsOn" - } - }, - "interfaces": { - "CONFIG": { - "operations": { - "ActivateNetconf": { - "inputs": { - "params": { - "required": false, - "type": "list", - "entry_schema": { - "type": "datatype-property" - } - } - } - } - } - } - }, - - "derived_from": "tosca.nodes.DG" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-config-generator.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-config-generator.json deleted file mode 100644 index 28bace0f0..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-config-generator.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "description": "This is Activate DG for Config Generator Directed Graph", - "version": "1.0.0", - "properties": { - "mode": { - "required": false, - "type": "string", - "default": "sync" - }, - "version": { - "required": false, - "type": "string", - "default": "LATEST" - }, - "is-start-flow": { - "required": false, - "type": "boolean", - "default": "false" - } - }, - "capabilities": { - "dg-node": { - "type": "tosca.capabilities.Node" - }, - "content": { - "type": "tosca.capability.Content", - "properties": { - "type": { - "required": false, - "type": "string", - "default": "json" - }, - "content": { - "required": true, - "type": "string" - } - } - } - }, - "requirements": { - "component-dependency": { - "capability": "component-node", - "node": "component-config-generator", - "relationship": "tosca.relationships.DependsOn" - } - }, - "interfaces": { - "CONFIG": { - "operations": { - "GenerateConfiguration": { - "inputs": { - "params": { - "required": false, - "type": "list", - "entry_schema": { - "type": "datatype-property" - } - } - } - } - } - } - }, - "derived_from": "tosca.nodes.DG" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-resource-assign-activate.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-resource-assign-activate.json deleted file mode 100644 index e98fa5a67..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-resource-assign-activate.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "description": "This is Resource Assign and Activate Netconf Directed Graph", - "version": "1.0.0", - "properties": { - "mode": { - "required": false, - "type": "string", - "default": "sync" - }, - "version": { - "required": false, - "type": "string", - "default": "LATEST" - }, - "is-start-flow": { - "required": false, - "type": "boolean", - "default": "false" - } - }, - "capabilities": { - "dg-node": { - "type": "tosca.capabilities.Node" - }, - "content": { - "type": "tosca.capability.Content", - "properties": { - "type": { - "required": false, - "type": "string", - "default": "json" - }, - "content": { - "required": false, - "type": "string" - } - } - } - }, - "requirements": { - "ra-component": { - "capability": "component-node", - "node": "component-resource-assignment", - "relationship": "tosca.relationships.DependsOn" - }, - "netconf-component": { - "capability": "component-node", - "node": "component-netconf-executor", - "relationship": "tosca.relationships.DependsOn" - } - }, - "interfaces": { - "CONFIG": { - "operations": { - "ResourceAssignAndActivate": { - "inputs": { - "params": { - "required": false, - "type": "list", - "entry_schema": { - "type": "datatype-property" - } - } - } - } - } - } - }, - "derived_from": "tosca.nodes.DG" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-resource-assignment.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-resource-assignment.json deleted file mode 100644 index 36fbb6861..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/dg-resource-assignment.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "description": "This is Resource Assignment Directed Graph", - "version": "1.0.0", - "properties": { - "mode": { - "required": false, - "type": "string", - "default": "sync" - }, - "version": { - "required": false, - "type": "string", - "default": "LATEST" - }, - "is-start-flow": { - "required": false, - "type": "boolean", - "default": "false" - } - }, - "capabilities": { - "dg-node": { - "type": "tosca.capabilities.Node" - }, - "content": { - "type": "tosca.capability.Content", - "properties": { - "type": { - "required": false, - "type": "string", - "default": "json" - }, - "content": { - "required": false, - "type": "string" - } - } - } - }, - "requirements": { - "component-dependency": { - "capability": "component-node", - "node": "component-resource-assignment", - "relationship": "tosca.relationships.DependsOn" - } - }, - "interfaces": { - "CONFIG": { - "operations": { - "ResourceAssignment": { - "inputs": { - "params": { - "required": false, - "type": "list", - "entry_schema": { - "type": "datatype-property" - } - } - } - } - } - } - }, - "derived_from": "tosca.nodes.DG" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/node_type/vnf-netconf-device.json b/ms/controllerblueprints/modules/core/load/model_type/node_type/vnf-netconf-device.json deleted file mode 100644 index 54573bade..000000000 --- a/ms/controllerblueprints/modules/core/load/model_type/node_type/vnf-netconf-device.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "description": "This is VNF Device with Netconf Capability", - "version": "1.0.0", - "capabilities": { - "netconf": { - "type": "tosca.capability.Netconf", - "properties": { - "login-key": { - "required": true, - "type": "string", - "default": "sdnc" - }, - "login-account": { - "required": true, - "type": "string", - "default": "sdnc-tacacs" - }, - "source": { - "required": true, - "type": "string", - "default": "npm" - }, - "target-ip-address": { - "required": true, - "type": "string" - }, - "port-number": { - "required": true, - "type": "integer", - "default": 830 - }, - "connection-time-out": { - "required": false, - "type": "integer", - "default": 30 - } - } - } - }, - "derived_from": "tosca.nodes.Vnf" - -} diff --git a/ms/controllerblueprints/modules/core/pom.xml b/ms/controllerblueprints/modules/core/pom.xml deleted file mode 100644 index ba38de63c..000000000 --- a/ms/controllerblueprints/modules/core/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - 4.0.0 - - org.onap.ccsdk.apps.controllerblueprints - modules - 0.3.0-SNAPSHOT - - core - Controller Blueprints Core - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - - - com.fasterxml.jackson.module - jackson-module-jsonSchema - - - io.projectreactor - reactor-core - - - org.yaml - snakeyaml - - - org.jetbrains.kotlin - kotlin-test - test - - - junit - junit - - - - - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt deleted file mode 100644 index 4ae1f4d5d..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.core -/** - * BluePrintConstants - * - * @author Brinda Santh - */ -object BluePrintConstants { - - const val RESPONSE_HEADER_TRANSACTION_ID: String = "X-ONAP-RequestID" - const val RESPONSE_HEADER_MINOR_VERSION: String = "X-MinorVersion" - const val RESPONSE_HEADER_PATCH_VERSION: String = "X-PatchVersion" - const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion" - - const val TYPE_DEFAULT: String = "default" - - const val DATA_TYPE_STRING: String = "string" - const val DATA_TYPE_INTEGER: String = "integer" - const val DATA_TYPE_FLOAT: String = "float" - const val DATA_TYPE_BOOLEAN: String = "boolean" - const val DATA_TYPE_TIMESTAMP: String = "timestamp" - const val DATA_TYPE_NULL: String = "null" - const val DATA_TYPE_LIST: String = "list" - const val DATA_TYPE_MAP: String = "map" - - const val USER_SYSTEM: String = "System" - - const val MODEL_CONTENT_TYPE_JSON: String = "JSON" - const val MODEL_CONTENT_TYPE_YAML: String = "YAML" - const val MODEL_CONTENT_TYPE_YANG: String = "YANG" - const val MODEL_CONTENT_TYPE_SCHEMA: String = "SCHEMA" - - const val PATH_DIVIDER: String = "/" - const val PATH_INPUTS: String = "inputs" - const val PATH_NODE_WORKFLOWS: String = "workflows" - const val PATH_NODE_TEMPLATES: String = "node_templates" - const val PATH_CAPABILITIES: String = "capabilities" - const val PATH_REQUIREMENTS: String = "requirements" - const val PATH_INTERFACES: String = "interfaces" - const val PATH_OPERATIONS: String = "operations" - const val PATH_OUTPUTS: String = "outputs" - const val PATH_PROPERTIES: String = "properties" - const val PATH_ATTRIBUTES: String = "attributes" - const val PATH_ARTIFACTS: String = "artifacts" - - const val MODEL_DIR_MODEL_TYPE: String = "model_type" - - const val MODEL_DEFINITION_TYPE_NODE_TYPE: String = "node_type" - const val MODEL_DEFINITION_TYPE_ARTIFACT_TYPE: String = "artifact_type" - const val MODEL_DEFINITION_TYPE_CAPABILITY_TYPE: String = "capability_type" - const val MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE: String = "relationship_type" - const val MODEL_DEFINITION_TYPE_DATA_TYPE: String = "data_type" - - const val MODEL_TYPE_DATATYPES_ROOT: String = "tosca.datatypes.Root" - const val MODEL_TYPE_NODES_ROOT: String = "tosca.nodes.Root" - const val MODEL_TYPE_GROUPS_ROOT: String = "tosca.groups.Root" - const val MODEL_TYPE_RELATIONSHIPS_ROOT: String = "tosca.relationships.Root" - const val MODEL_TYPE_ARTIFACTS_ROOT: String = "tosca.artifacts.Root" - const val MODEL_TYPE_CAPABILITIES_ROOT: String = "tosca.capabilities.Root" - const val MODEL_TYPE_INTERFACES_ROOT: String = "tosca.interfaces.Root" - - const val MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON = "tosca.relationships.DependsOn" - const val MODEL_TYPE_RELATIONSHIPS_HOSTED_ON = "tosca.relationships.HostedOn" - const val MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO = "tosca.relationships.ConnectsTo" - const val MODEL_TYPE_RELATIONSHIPS_ATTACH_TO = "tosca.relationships.AttachesTo" - const val MODEL_TYPE_RELATIONSHIPS_ROUTES_TO = "tosca.relationships.RoutesTo" - - const val MODEL_TYPE_NODE_DG = "tosca.nodes.DG" - const val MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component" - const val MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf" - @Deprecated("Artifacts will be attached to Node Template") - const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact" - const val MODEL_TYPE_NODE_RESOURCE_SOURCE = "tosca.nodes.ResourceSource" - - const val MODEL_TYPE_NODES_COMPONENT_JAVA: String = "tosca.nodes.component.Java" - const val MODEL_TYPE_NODES_COMPONENT_BUNDLE: String = "tosca.nodes.component.Bundle" - const val MODEL_TYPE_NODES_COMPONENT_SCRIPT: String = "tosca.nodes.component.Script" - const val MODEL_TYPE_NODES_COMPONENT_PYTHON: String = "tosca.nodes.component.Python" - const val MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT: String = "tosca.nodes.component.JavaScript" - - const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic" - - const val EXPRESSION_GET_INPUT: String = "get_input" - const val EXPRESSION_GET_ATTRIBUTE: String = "get_attribute" - const val EXPRESSION_GET_ARTIFACT: String = "get_artifact" - const val EXPRESSION_GET_PROPERTY: String = "get_property" - const val EXPRESSION_GET_OPERATION_OUTPUT: String = "get_operation_output" - const val EXPRESSION_GET_NODE_OF_TYPE: String = "get_nodes_of_type" - - const val PROPERTY_BLUEPRINT_PROCESS_ID: String = "blueprint-process-id" - const val PROPERTY_BLUEPRINT_BASE_PATH: String = "blueprint-basePath" - const val PROPERTY_BLUEPRINT_RUNTIME: String = "blueprint-runtime" - const val PROPERTY_BLUEPRINT_INPUTS_DATA: String = "blueprint-inputs-data" - const val PROPERTY_BLUEPRINT_CONTEXT: String = "blueprint-context" - const val PROPERTY_BLUEPRINT_NAME: String = "template_name" - const val PROPERTY_BLUEPRINT_VERSION: String = "template_version" - - const val TOSCA_METADATA_ENTRY_DEFINITION_FILE: String = "TOSCA-Metadata/TOSCA.meta" - const val TOSCA_PLANS_DIR: String = "Plans" - const val TOSCA_SCRIPTS_DIR: String = "Scripts" - const val TOSCA_MAPPINGS_DIR: String = "Mappings" - const val TOSCA_TEMPLATES_DIR: String = "Templates" - - const val METADATA_USER_GROUPS = "user-groups" - const val METADATA_TEMPLATE_NAME = "template_name" - const val METADATA_TEMPLATE_VERSION = "template_version" - const val METADATA_TEMPLATE_AUTHOR = "template_author" - const val METADATA_TEMPLATE_TAGS = "template_tags" - - const val PAYLOAD_CONTENT = "payload-content" - const val PAYLOAD_DATA = "payload-data" - const val SELECTOR = "selector" - const val PROPERTY_CURRENT_INTERFACE = "current-interface" - const val PROPERTY_CURRENT_OPERATION = "current-operation" - const val PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation" - - const val PROPERTY_ACTION_NAME = "action" - - const val OPERATION_PROCESS = "process" - const val OPERATION_PREPARE = "prepare" - - const val BLUEPRINT_RETRIEVE_TYPE_DB = "db" - const val BLUEPRINT_RETRIEVE_TYPE_FILE = "file" - const val BLUEPRINT_RETRIEVE_TYPE_REPO = "repo" - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt deleted file mode 100644 index 5c386c214..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt +++ /dev/null @@ -1,49 +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.core -/** - * - * - * @author Brinda Santh - */ -class BluePrintException : Exception { - - var code: Int = 100 - - constructor(cause: Throwable) : super(cause) - constructor(message: String) : super(message) - constructor(message: String, cause: Throwable) : super(message, cause) - constructor(cause: Throwable, message: String, vararg args: Any?) : super(String.format(message, *args), cause) - - constructor(code: Int, cause: Throwable) : super(cause) { - this.code = code - } - - constructor(code: Int, message: String) : super(message) { - this.code = code - } - - constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { - this.code = code - } - - constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) - : super(String.format(message, *args), cause) { - this.code = code - } -} - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt deleted file mode 100644 index 50717031d..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.core -/** - * - * - * @author Brinda Santh - */ -class BluePrintProcessorException : Exception { - var code: Int = 100 - - constructor(message: String, cause: Throwable) : super(message, cause) - constructor(message: String) : super(message) - constructor(cause: Throwable) : super(cause) - constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) - - constructor(code: Int, cause: Throwable) : super(cause) { - this.code = code - } - - constructor(code: Int, message: String) : super(message) { - this.code = code - } - - constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { - this.code = code - } - - constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) - : super(String.format(message, *args), cause) { - this.code = code - } -} - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt deleted file mode 100644 index 33c811f4a..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt +++ /dev/null @@ -1,91 +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.core - -/** - * - * - * @author Brinda Santh - */ -object BluePrintTypes { - - @JvmStatic - fun validModelTypes(): List { - val validTypes: MutableList = arrayListOf() - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) - return validTypes - } - - @JvmStatic - fun validPropertyTypes(): List { - val validTypes: MutableList = arrayListOf() - validTypes.add(BluePrintConstants.DATA_TYPE_STRING) - validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) - validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) - validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) - validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) - validTypes.add(BluePrintConstants.DATA_TYPE_NULL) - validTypes.add(BluePrintConstants.DATA_TYPE_LIST) - return validTypes - } - - @JvmStatic - fun validPrimitiveTypes(): List { - val validTypes: MutableList = arrayListOf() - validTypes.add(BluePrintConstants.DATA_TYPE_STRING) - validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) - validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) - validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) - validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) - validTypes.add(BluePrintConstants.DATA_TYPE_NULL) - return validTypes - } - - @JvmStatic - fun validCollectionTypes(): List { - val validTypes: MutableList = arrayListOf() - validTypes.add(BluePrintConstants.DATA_TYPE_LIST) - validTypes.add(BluePrintConstants.DATA_TYPE_MAP) - return validTypes - } - - @JvmStatic - fun validCommands(): List { - return listOf(BluePrintConstants.EXPRESSION_GET_INPUT, - BluePrintConstants.EXPRESSION_GET_ATTRIBUTE, - BluePrintConstants.EXPRESSION_GET_PROPERTY, - BluePrintConstants.EXPRESSION_GET_ARTIFACT, - BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT, - BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE) - } - - @JvmStatic - fun rootNodeTypes(): List { - return listOf(BluePrintConstants.MODEL_TYPE_NODES_ROOT) - } - - @JvmStatic - fun rootDataTypes(): List { - return listOf(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT) - } - - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt deleted file mode 100644 index 845922040..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.core - -/** - * - * - * @author Brinda Santh - */ -object ConfigModelConstant { - - const val MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON" - const val MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE" - - const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic" - - const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact" - - const val MODEL_TYPE_CAPABILITY_NETCONF = "tosca.capability.Netconf" - const val MODEL_TYPE_CAPABILITY_SSH = "tosca.capability.Ssh" - const val MODEL_TYPE_CAPABILITY_SFTP = "tosca.capability.Sftp" - const val MODEL_TYPE_CAPABILITY_CHEF = "tosca.capability.Chef" - const val MODEL_TYPE_CAPABILITY_ANSIBLEF = "tosca.capability.Ansible" - - const val CAPABILITY_PROPERTY_MAPPING = "mapping" - - const val PROPERTY_RECIPE_NAMES = "action-names" - -} diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt deleted file mode 100644 index 7302f2b96..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt +++ /dev/null @@ -1,75 +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.core - -import org.slf4j.helpers.MessageFormatter -import java.io.File -import java.io.InputStream -import kotlin.reflect.KClass - -/** - * - * - * @author Brinda Santh - */ - -fun format(message: String, vararg args: Any?) : String{ - if(args != null && args.isNotEmpty()){ - return MessageFormatter.arrayFormat(message, args).message - } - return message -} - -fun MutableMap.getCastOptionalValue(key: String, valueType: KClass): T? { - if (containsKey(key)) { - return get(key) as? T - } else { - return null - } -} - -fun MutableMap.getCastValue(key: String, valueType: KClass): T { - if (containsKey(key)) { - return get(key) as T - } else { - throw BluePrintException("couldn't find the key " + key) - } -} - -fun checkNotEmpty(value : String?) : Boolean{ - return value != null && value.isNotEmpty() -} - -fun checkNotEmptyNThrow(value : String?, message : String? = value.plus(" is null/empty ")) : Boolean{ - val notEmpty = value != null && value.isNotEmpty() - if(!notEmpty){ - throw BluePrintException(message!!) - } - return notEmpty -} - -fun InputStream.toFile(path: String) : File { - val file = File(path) - file.outputStream().use { this.copyTo(it) } - return file -} - - - - - - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt deleted file mode 100644 index c0eb13f92..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt +++ /dev/null @@ -1,70 +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.core.data - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.ObjectNode -/** - * - * - * @author Brinda Santh - */ -data class ExpressionData( - var isExpression: Boolean = false, - var valueNode: JsonNode, - var expressionNode: ObjectNode? = null, - var inputExpression: InputExpression? = null, - var propertyExpression: PropertyExpression? = null, - var attributeExpression: AttributeExpression? = null, - var artifactExpression: ArtifactExpression? = null, - var operationOutputExpression: OperationOutputExpression? = null, - var command: String? = null -) - -data class InputExpression( - var propertyName: String -) - -data class PropertyExpression( - var modelableEntityName: String = "SELF", - var reqOrCapEntityName: String? = null, - var propertyName: String, - var subPropertyName: String? = null -) - -data class AttributeExpression( - var modelableEntityName: String = "SELF", - var reqOrCapEntityName: String? = null, - var attributeName: String, - var subAttributeName: String? = null -) - -data class ArtifactExpression( - val modelableEntityName: String = "SELF", - val artifactName: String, - val location: String? = "LOCAL_FILE", - val remove: Boolean? = false -) - -data class OperationOutputExpression( - val modelableEntityName: String = "SELF", - val interfaceName: String, - val operationName: String, - val propertyName: String -) - - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt deleted file mode 100644 index 1664f7920..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt +++ /dev/null @@ -1,612 +0,0 @@ -/* - * 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.core.data - -import com.fasterxml.jackson.annotation.JsonIgnore -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.JsonNode -import io.swagger.annotations.ApiModelProperty - -/** - * - * - * @author Brinda Santh - */ -open class EntityType { - @get:JsonIgnore - var id: String? = null - var description: String? = null - var version: String = "1.0.0" - var metadata: MutableMap? = null - @get:JsonProperty("derived_from") - lateinit var derivedFrom: String - var attributes: MutableMap? = null - var properties: MutableMap? = null -} - -/* - 5.3.2 tosca.datatypes.org.onap.ccsdk.apps.controllerblueprints.core.data.Credential - The org.onap.ccsdk.apps.controllerblueprints.core.data.Credential type is a complex TOSCA data Type used when describing - authorization credentials used to access network accessible resources. - */ -class Credential { - @get:JsonIgnore - var id: String? = null - var protocol: String? = null - @get:JsonProperty("token_type") - lateinit var tokenType: String - lateinit var token: String - var keys: MutableMap? = null - lateinit var user: String -} - -/* -3.5.2 Constraint clause -A constraint clause defines an operation along with one or more compatible values that can be used to define a constraint on a property or parameter’s allowed values when it is defined in a TOSCA Service Template or one of its entities. - */ -class ConstraintClause { - @get:JsonProperty("equal") - var equal: JsonNode? = null - @get:JsonProperty("greater_than") - var greaterThan: Any? = null - @get:JsonProperty("greater_or_equal") - var greaterOrEqual: Any? = null - @get:JsonProperty("less_than") - var lessThan: Any? = null - @get:JsonProperty("less_or_equal") - var lessOrEqual: Any? = null - @get:JsonProperty("in_range") - var inRange: Any? = null - @get:JsonProperty("valid_values") - var validValues: MutableList? = null - @get:JsonProperty("length") - var length: Any? = null - @get:JsonProperty("min_length") - var minLength: Any? = null - @get:JsonProperty("max_length") - var maxLength: Any? = null - var pattern: String? = null - var schema: String? = null -} - -/* -3.5.4 Node Filter definition -A node filter definition defines criteria for selection of a TOSCA Node Template based upon the template’s property values, capabilities and capability properties. - */ - -class NodeFilterDefinition { - var properties: MutableMap? = null - var capabilities : MutableList? = null -} - -/* -3.5.5 Repository definition - A repository definition defines a named external repository which contains deployment - and implementation artifacts that are referenced within the TOSCA Service Template. -*/ -class RepositoryDefinition { - @get:JsonIgnore - var id: String? = null - var description: String? = null - lateinit var url: String - var credential: Credential? = null -} - - -/* -3.5.6 Artifact definition -An artifact definition defines a named, typed file that can be associated with Node Type -or Node Template and used by orchestration engine to facilitate deployment and implementation of interface operations. - */ -class ArtifactDefinition { - @get:JsonIgnore - var id: String? = null - var type: String? = null - var file: String? = null - var repository: String? = null - var description: String? = null - @get:JsonProperty("deploy_Path") - var deployPath: String? = null - var properties: MutableMap? = null - var content: String? = null - @Deprecated("Mapping content is define by the Type") - var mappingContent: String? = null -} - - -/* -3.5.7 Import definition -An import definition is used within a TOSCA Service Template to locate and uniquely name -another TOSCA Service Template file which has type and template definitions to be imported (included) -and referenced within another Service Template. - */ -class ImportDefinition { - @get:JsonIgnore - var id: String? = null - lateinit var file: String - var repository: String? = null - @get:JsonProperty("namespace_uri") - var namespaceUri: String? = null - @get:JsonProperty("namespace_prefix") - var namespacePrefix: String? = null -} - -/* -3.5.8 Property definition A property definition defines a named, typed value and related data that can be associated with an -entity defined in this specification (e.g., Node Types, Relationship Types, Capability Types, etc.). -Properties are used by template authors to provide input values to TOSCA entities which indicate their “desired state” when they are -instantiated. The value of a property can be retrieved using the get_property function within TOSCA Service Templates. - */ -class PropertyDefinition { - @get:JsonIgnore - var id: String? = null - var description: String? = null - var required: Boolean? = null - lateinit var type: String - @get:JsonProperty("default") - var defaultValue: JsonNode? = null - var status: String? = null - var constraints: MutableList? = null - @get:JsonProperty("entry_schema") - var entrySchema: EntrySchema? = null - @get:ApiModelProperty(notes = "Property Value, It may be raw JSON or primitive data type values") - var value: JsonNode? = null -} - - -/* -3.5.10 Attribute definition - -An attribute definition defines a named, typed value that can be associated with an entity defined in this -specification (e.g., a Node, Relationship or Capability Type). Specifically, it is used to expose the -“actual state” of some property of a TOSCA entity after it has been deployed and instantiated -(as set by the TOSCA orchestrator). Attribute values can be retrieved via the get_attribute function -from the instance model and used as values to other entities within TOSCA Service Templates. - */ - -class AttributeDefinition { - @get:JsonIgnore - var id: String? = null - var description: String? = null - lateinit var type: String - @JsonProperty("default") - var defaultValue: JsonNode? = null - var status: String? = null - @JsonProperty("entry_schema") - var entrySchema: String? = null -} - -/* -3.5.13 Operation definition -An operation definition defines a named function or procedure that can be bound to an implementation artifact (e.g., a script). - */ -class OperationDefinition { - @get:JsonIgnore - var id: String? = null - var description: String? = null - var implementation: Implementation? = null - var inputs: MutableMap? = null - var outputs: MutableMap? = null -} - -class Implementation { - lateinit var primary: String - var dependencies: MutableList? = null -} - -/* -3.5.14 Interface definition -An interface definition defines a named interface that can be associated with a Node or Relationship Type - */ -class InterfaceDefinition { - @get:JsonIgnore - var id: String? = null - var type: String? = null - var operations: MutableMap? = null - var inputs: MutableMap? = null -} - -/* -3.5.15 Event Filter definition -An event filter definition defines criteria for selection of an attribute, for the purpose of monitoring it, within a TOSCA entity, or one its capabilities. - */ -class EventFilterDefinition { - @get:JsonIgnore - var id: String? = null - lateinit var node: String - var requirement: String? = null - var capability: String? = null -} - -/* -3.5.16 Trigger definition TODO -A trigger definition defines the event, condition and action that is used to “trigger” a policy it is associated with. - */ -class TriggerDefinition { - @get:JsonIgnore - var id: String? = null - var description: String? = null - @get:JsonProperty("event_type") - lateinit var eventType: String - @get:JsonProperty("target_filter") - var targetFilter: EventFilterDefinition? = null - var condition: ConditionClause? = null - var constraint: ConditionClause? = null - var method: String? = null - lateinit var action: String -} - -/* - 3.5.17 org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow activity definition - A workflow activity defines an operation to be performed in a TOSCA workflow. Activities allows to: - · Delegate the workflow for a node expected to be provided by the orchestrator - · Set the state of a node - · Call an operation defined on a TOSCA interface of a node, relationship or group - · Inline another workflow defined in the topology (to allow reusability) - */ -class Activity { - var delegate: String? = null - @get:JsonProperty("set_state") - var setState: String? = null - @get:JsonProperty("call_operation") - var callOperation: String? = null - var inlines: ArrayList? = null -} - -/* -3.5.20 org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow precondition definition -A workflow condition can be used as a filter or precondition to check if a workflow can be processed or not based on the state of the instances of a TOSCA topology deployment. When not met, the workflow will not be triggered. - */ -class PreConditionDefinition { - @get:JsonIgnore - var id: String? = null - lateinit var target: String - @get:JsonProperty("target_relationship") - lateinit var targetRelationship: String - lateinit var condition: ArrayList -} - -/* -3.5.21 org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow step definition -A workflow step allows to define one or multiple sequenced activities in a workflow and how they are connected to other steps in the workflow. They are the building blocks of a declarative workflow. - */ -class Step { - @get:JsonIgnore - var id: String? = null - var description: String? = null - var target: String? = null - @JsonProperty("target_relationship") - var targetRelationship: String? = null - @JsonProperty("operation_host") - var operationHost: String? = null - var activities: ArrayList? = null - @get:JsonProperty("on_success") - var onSuccess: ArrayList? = null - @get:JsonProperty("on_failure") - var onFailure: ArrayList? = null -} - -/* -3.6.2 Capability definition -A capability definition defines a named, typed set of data that can be associated with Node Type or Node Template to describe a transparent capability or feature of the software component the node describes. - */ - -class CapabilityDefinition { - @get:JsonIgnore - var id: String? = null - var type: String? = null - var description: String? = null - var properties: MutableMap? = null - @get:JsonProperty("valid_source_types") - var validSourceTypes: MutableList? = null - var occurrences: MutableList? = null -} - -/* -3.6.3 Requirement definition -The Requirement definition describes a named requirement (dependencies) of a TOSCA Node Type or Node template which needs to be fulfilled by a matching Capability definition declared by another TOSCA modelable entity. The requirement definition may itself include the specific name of the fulfilling entity (explicitly) or provide an abstract type, along with additional filtering characteristics, that a TOSCA orchestrator can use to fulfill the capability at runtime (implicitly). - */ -class RequirementDefinition { - @get:JsonIgnore - var id: String? = null - var description: String? = null - var capability: String? = null - var node: String? = null - var relationship: String? = null - var occurrences: MutableList? = null -} - -/* -3.6.4 Artifact Type -An Artifact Type is a reusable entity that defines the type of one or more files that are used to define implementation or deployment artifacts that are referenced by nodes or relationships on their operations. - */ -class ArtifactType : EntityType() { - @get:JsonProperty("mime_type") - var mimeType: String? = null - @get:JsonProperty("file_ext") - var fileExt: MutableList? = null - -} - -/* -3.6.6 Data Type -A Data Type definition defines the schema for new named datatypes in TOSCA. - */ - -class DataType : EntityType(){ - var constraints: MutableList? = null -} - -/* -3.6.9 Node Type -A Node Type is a reusable entity that defines the type of one or more Node Templates. As such, a Node Type defines the structure of observable properties via a Properties Definition, the Requirements and Capabilities of the node as well as its supported interfaces. - - */ - -class NodeType : EntityType() { - var capabilities: MutableMap? = null - var requirements: MutableMap? = null - var interfaces: MutableMap? = null - var artifacts: MutableMap? = null -} - -/* -3.6.8 Requirement Type -A Requirement Type is a reusable entity that describes a kind of requirement that a Node Type can declare to expose. The TOSCA Simple Profile seeks to simplify the need for declaring specific Requirement Types from nodes and instead rely upon nodes declaring their features sets using TOSCA Capability Types along with a named Feature notation. - */ - -class RequirementType : EntityType() { - var requirements: MutableMap? = null - var capabilities: MutableMap? = null - var interfaces: MutableMap? = null - var artifacts: MutableMap? = null -} - -/* -3.6.10 Relationship Type -A Relationship Type is a reusable entity that defines the type of one or more relationships between Node Types or Node Templates. -*/ - -class RelationshipType : EntityType() { - var interfaces: MutableMap? = null - @get:JsonProperty("valid_target_types") - var validTargetTypes: ArrayList? = null -} - -/* -3.6.11 Group Type -A Group Type defines logical grouping types for nodes, typically for different management purposes. -Groups can effectively be viewed as logical nodes that are not part of the physical deployment topology - of an application, yet can have capabilities and the ability to attach policies and interfaces - that can be applied (depending on the group type) to its member nodes. - */ - -class GroupType : EntityType() { - var members: MutableList? = null - var requirements: ArrayList? = null - var capabilities: MutableMap? = null - var interfaces: MutableMap? = null - -} - -/* - 3.6.12 Policy Type - A Policy Type defines a type of requirement that affects or governs an application or service’s - topology at some stage of its lifecycle, but is not explicitly part of the topology itself - (i.e., it does not prevent the application or service from being deployed or run if it did not exist). - */ -class PolicyType : EntityType(){ - lateinit var targets: MutableList -} - -/* -3.7.1 Capability assignment -A capability assignment allows node template authors to assign values to properties and attributes for a named capability definition that is part of a Node Template’s type definition. - */ -class CapabilityAssignment { - @get:JsonIgnore - var id: String? = null - var attributes: MutableMap? = null - var properties: MutableMap? = null -} - -/* -3.7.4 Relationship Template -A Relationship Template specifies the occurrence of a manageable relationship between node templates as part of an application’s topology model that is defined in a TOSCA Service Template. A Relationship template is an instance of a specified Relationship Type and can provide customized properties, constraints or operations which override the defaults provided by its Relationship Type and its implementations. - */ -class GroupDefinition { - @get:JsonIgnore - var id: String? = null - lateinit var type: String - var description: String? = null - var metadata : MutableMap? = null - var properties : MutableMap? = null - var members = ArrayList() - var interfaces : MutableMap?= null -} - -/* -3.7.6 Policy definition -A policy definition defines a policy that can be associated with a TOSCA topology or top-level entity definition (e.g., group definition, node template, etc.). - */ -class PolicyDefinition { - @get:JsonIgnore - var id: String? = null - lateinit var type: String - var description: String? = null - var metadata: MutableMap? = null - var properties: MutableMap? = null - var targets: MutableList? = null -} - - -/* -3.8 Topology Template definition -This section defines the topology template of a cloud application. The main ingredients of the topology template are node templates representing components of the application and relationship templates representing links between the components. These elements are defined in the nested node_templates section and the nested relationship_templates sections, respectively. Furthermore, a topology template allows for defining input parameters, output parameters as well as grouping of node templates. - */ -class TopologyTemplate { - @get:JsonIgnore - var id: String? = null - var description: String? = null - var inputs: MutableMap? = null - @get:JsonProperty("node_templates") - var nodeTemplates: MutableMap? = null - @get:JsonProperty("relationship_templates") - var relationshipTemplates: MutableMap? = null - var policies: MutableMap? = null - var outputs: MutableMap? = null - @get:JsonProperty("substitution_mappings") - var substitutionMappings: Any? = null - var workflows: MutableMap? = null -} - -class SubstitutionMapping { - @get:JsonProperty("node_type") - lateinit var nodeType: String - lateinit var capabilities: ArrayList - lateinit var requirements: ArrayList -} - -class EntrySchema { - lateinit var type: String - var constraints: MutableList? = null -} - -class InterfaceAssignment { - @get:JsonIgnore - var id: String? = null - var operations: MutableMap? = null - var inputs: MutableMap? = null -} - -/* -3.7.3 Node Template -A Node Template specifies the occurrence of a manageable software component as part of an application’s topology model which is defined in a TOSCA Service Template. A Node template is an instance of a specified Node Type and can provide customized properties, constraints or operations which override the defaults provided by its Node Type and its implementations. - */ - -class NodeTemplate { - @get:JsonIgnore - var id: String? = null - var description: String? = null - lateinit var type: String - var metadata: MutableMap? = null - var directives: MutableList? = null - //@get:JsonSerialize(using = PropertyDefinitionValueSerializer::class) - var properties: MutableMap? = null - var attributes: MutableMap? = null - var capabilities: MutableMap? = null - var requirements: MutableMap? = null - var interfaces: MutableMap? = null - var artifacts: MutableMap? = null - @get:JsonProperty("node_filter") - var nodeFilter: NodeFilterDefinition? = null - var copy: String? = null -} - -class OperationAssignment { - @get:JsonIgnore - var id: String? = null - var description: String? = null - var implementation: Implementation? = null - var inputs: MutableMap? = null - var outputs: MutableMap? = null -} - -/* -3.7.4 Relationship Template -A Relationship Template specifies the occurrence of a manageable relationship between node templates as part of an application’s topology model that is defined in a TOSCA Service Template. A Relationship template is an instance of a specified Relationship Type and can provide customized properties, constraints or operations which override the defaults provided by its Relationship Type and its implementations. - */ - -class RelationshipTemplate { - var type: String? = null - var description: String? = null - var metadata: MutableMap? = null - var properties: MutableMap? = null - var attributes: MutableMap? = null - var interfaces: MutableMap? = null - var copy: String? = null -} - -/* -3.7.2 Requirement assignment -A Requirement assignment allows template authors to provide either concrete names of TOSCA templates or provide abstract selection criteria for providers to use to find matching TOSCA templates that are used to fulfill a named requirement’s declared TOSCA Node Type. - */ - -class RequirementAssignment { - @get:JsonIgnore - var id: String? = null - var capability: String? = null - var node: String? = null - //Relationship Type or Relationship Template - var relationship: String? = null -} - - -class Workflow { - @get:JsonIgnore - var id: String? = null - var description: String? = null - var steps: MutableMap? = null - var preconditions: ArrayList? = null - var inputs: MutableMap? = null -} - - -class ConditionClause { - var and: ArrayList>? = null - var or: ArrayList>? = null - @get:JsonProperty("assert") - var assertConditions: ArrayList>? = null -} - -/* -3.9 Service Template definition -A TOSCA Service Template (YAML) document contains element definitions of building blocks for cloud application, or complete models of cloud applications. This section describes the top-level structural elements (TOSCA keynames) along with their grammars, which are allowed to appear in a TOSCA Service Template document. - */ - -class ServiceTemplate { - @get:JsonIgnore - var id: String? = null - @get:JsonProperty("tosca_definitions_version") - var toscaDefinitionsVersion: String = "controller_blueprint_1_0_0" - var metadata: MutableMap? = null - var description: String? = null - @get:JsonProperty("dsl_definitions") - var dslDefinitions: MutableMap? = null - var repositories: MutableMap? = null - var imports: MutableList? = null - @get:JsonProperty("artifact_types") - var artifactTypes: MutableMap? = null - @get:JsonProperty("data_types") - var dataTypes: MutableMap? = null - @get:JsonProperty("node_types") - var nodeTypes: MutableMap? = null - @get:JsonProperty("policy_types") - var policyTypes: PolicyType? = null - @get:JsonProperty("topology_template") - var topologyTemplate: TopologyTemplate? = null -} - -class ToscaMetaData { - lateinit var toscaMetaFileVersion: String - lateinit var csarVersion: String - lateinit var createdBy: String - lateinit var entityDefinitions: String - var templateTags: String? = null -} - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt deleted file mode 100644 index d796597be..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt +++ /dev/null @@ -1,45 +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.core.factory - -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager - - -/** - * BluePrintEnhancerFactory - * @author Brinda Santh - * - */ - -object BluePrintEnhancerFactory { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - var bluePrintEnhancerServices: MutableMap = HashMap() - - fun register(key: String, bluePrintEnhancerService: BluePrintEnhancerService) { - bluePrintEnhancerServices[key] = bluePrintEnhancerService - } - - /** - * Called by clients to get a Blueprint Parser for the Blueprint parser type - */ - fun instance(key: String): BluePrintEnhancerService? { - return bluePrintEnhancerServices.get(key) - } -} diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintParserFactory.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintParserFactory.kt deleted file mode 100644 index 83233abc1..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintParserFactory.kt +++ /dev/null @@ -1,51 +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.core.factory - -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintParserDefaultService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintParserService -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager - -/** - * - * BluePrintParserFactory - * @author Brinda Santh - */ - -object BluePrintParserFactory { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - var bluePrintParserServices: MutableMap = HashMap() - - init { - log.info("Initialised default BluePrintParser Service ") - bluePrintParserServices.put(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.TYPE_DEFAULT, BluePrintParserDefaultService()) - } - - fun register(key:String, bluePrintParserService: BluePrintParserService){ - bluePrintParserServices.put(key, bluePrintParserService) - } - - /** - * Called by clients to get a Blueprint Parser for the Blueprint parser type - */ - fun instance(key : String) : BluePrintParserService? { - return bluePrintParserServices.get(key) - } -} - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt deleted file mode 100644 index 63f788a2f..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt +++ /dev/null @@ -1,45 +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.core.factory - - -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorService - -/** - * - * - * @author Brinda Santh - */ - -object BluePrintValidatorFactory { - - var bluePrintValidatorServices: MutableMap = HashMap() - - init { - bluePrintValidatorServices[org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.TYPE_DEFAULT] = BluePrintValidatorDefaultService() - } - - fun register(key:String, bluePrintValidatorService: BluePrintValidatorService){ - bluePrintValidatorServices[key] = bluePrintValidatorService - } - - fun instance(key : String) : BluePrintValidatorService?{ - return bluePrintValidatorServices[key] - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt deleted file mode 100644 index 065176342..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt +++ /dev/null @@ -1,117 +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.core.service - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -/** - * - * - * @author Brinda Santh - */ -class BluePrintChainedService { - var bpc : BluePrintContext - - constructor(bpc : BluePrintContext){ - this.bpc = bpc - } - - fun nodeTypeChained(nodeTypeName: String): NodeType { - - val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName) - val attributes = hashMapOf() - val properties = hashMapOf() - val requirements = hashMapOf() - val capabilities = hashMapOf() - val interfaces = hashMapOf() - val artifacts = hashMapOf() - - recNodeTypesChained(nodeTypeName).forEach { nodeType -> - - val subAttributes = bpc.nodeTypeByName(nodeType.id!!).attributes - if (subAttributes != null) { - attributes.putAll(subAttributes) - } - - val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties - if (subProperties != null) { - properties.putAll(subProperties) - } - - val subRequirements = bpc.nodeTypeByName(nodeType.id!!).requirements - if (subRequirements != null) { - requirements.putAll(subRequirements) - } - val subCapabilities = bpc.nodeTypeByName(nodeType.id!!).capabilities - if (subCapabilities != null) { - capabilities.putAll(subCapabilities) - } - val subInterfaces = bpc.nodeTypeByName(nodeType.id!!).interfaces - if (subInterfaces != null) { - interfaces.putAll(subInterfaces) - } - - val subArtifacts = bpc.nodeTypeByName(nodeType.id!!).artifacts - if (subArtifacts != null) { - artifacts.putAll(subArtifacts) - } - } - nodeType.attributes = attributes - nodeType.properties = properties - nodeType.requirements = requirements - nodeType.capabilities = capabilities - nodeType.interfaces = interfaces - nodeType.artifacts = artifacts - return nodeType - } - - fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap? { - val nodeType = bpc.nodeTypeByName(nodeTypeName) - val properties = hashMapOf() - - recNodeTypesChained(nodeTypeName).forEach { nodeType -> - val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties - if (subProperties != null) { - properties.putAll(subProperties) - } - } - return properties - } - - private fun recNodeTypesChained(nodeTypeName: String, nodeTypes: MutableList? = arrayListOf()): MutableList { - val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName) - nodeType.id = nodeTypeName - val derivedFrom: String = nodeType.derivedFrom - if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { - recNodeTypesChained(derivedFrom, nodeTypes) - } - nodeTypes!!.add(nodeType) - return nodeTypes - } - - private fun recDataTypesChained(dataTypeName: String, dataTypes: MutableList? = arrayListOf()): MutableList { - val dataType: DataType = bpc.dataTypeByName(dataTypeName)!! - dataType.id = dataTypeName - val derivedFrom: String = dataType.derivedFrom - if (!BluePrintTypes.rootDataTypes().contains(derivedFrom)) { - recDataTypesChained(derivedFrom, dataTypes) - } - dataTypes!!.add(dataType) - return dataTypes - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt deleted file mode 100644 index 875cbea61..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt +++ /dev/null @@ -1,177 +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.core.service - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -/** - * - * - * @author Brinda Santh - */ -class BluePrintContext(serviceTemplate: ServiceTemplate) { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - val serviceTemplate: ServiceTemplate = serviceTemplate - - val imports: List? = serviceTemplate.imports - - val metadata: MutableMap? = serviceTemplate.metadata - - val dataTypes: MutableMap? = serviceTemplate.dataTypes - - val inputs: MutableMap? = serviceTemplate.topologyTemplate?.inputs - - val workflows: MutableMap? = serviceTemplate.topologyTemplate?.workflows - - fun blueprintJson(pretty: Boolean = false): String = print("json", pretty) - - fun blueprintYaml(pretty: Boolean = false): String = print("yaml", pretty) - - private fun print(type: String? = "json", pretty: Boolean = false): String { - return JacksonUtils.getJson(serviceTemplate, pretty) - } - - // Workflow - fun workflowByName(name: String): Workflow? = workflows?.get(name) - - // Data Type - fun dataTypeByName(name: String): DataType? = dataTypes?.get(name) - - // Artifact Type - val artifactTypes: MutableMap? = serviceTemplate.artifactTypes - - // Node Type Methods - val nodeTypes: MutableMap? = serviceTemplate.nodeTypes - - fun nodeTypeByName(name: String): NodeType = - nodeTypes?.get(name) ?: throw BluePrintException(String.format("Failed to get node type for the name : %s", name)) - - fun nodeTypeDerivedFrom(name: String): MutableMap? { - return nodeTypes?.filterValues { nodeType -> nodeType.derivedFrom == name }?.toMutableMap() - } - - fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition? { - return nodeTypeByName(nodeTypeName).interfaces?.values?.first() - } - - fun nodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, operationName: String): OperationDefinition? { - return nodeTypeInterface(nodeTypeName, interfaceName)?.operations?.get(operationName) - } - - fun interfaceNameForNodeType(nodeTypeName: String): String? { - return nodeTypeByName(nodeTypeName).interfaces?.keys?.first() - } - - fun nodeTypeInterfaceOperationInputs(nodeTypeName: String, interfaceName: String, operationName: String): MutableMap? { - return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName)?.inputs - } - - fun nodeTypeInterfaceOperationOutputs(nodeTypeName: String, interfaceName: String, operationName: String): MutableMap? { - return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName)?.outputs - } - - // Node Template Methods - val nodeTemplates: MutableMap? = serviceTemplate.topologyTemplate?.nodeTemplates - - fun nodeTemplateByName(name: String): NodeTemplate = - nodeTemplates?.get(name) ?: throw BluePrintException("Failed to get node template for the name " + name) - - fun nodeTemplateForNodeType(name: String): MutableMap? { - return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap() - } - - fun nodeTemplateNodeType(nodeTemplateName: String): NodeType { - val nodeTemplateType: String = nodeTemplateByName(nodeTemplateName).type - return nodeTypeByName(nodeTemplateType) - } - - fun nodeTemplateProperty(nodeTemplateName: String, propertyName: String): Any? { - return nodeTemplateByName(nodeTemplateName).properties?.get(propertyName) - } - - fun nodeTemplateArtifacts(nodeTemplateName: String): MutableMap? { - return nodeTemplateByName(nodeTemplateName).artifacts - } - - fun nodeTemplateArtifact(nodeTemplateName: String, artifactName: String): ArtifactDefinition? { - return nodeTemplateArtifacts(nodeTemplateName)?.get(artifactName) - } - - fun nodeTemplateFirstInterface(nodeTemplateName: String): InterfaceAssignment? { - return nodeTemplateByName(nodeTemplateName).interfaces?.values?.first() - } - - fun nodeTemplateFirstInterfaceName(nodeTemplateName: String): String? { - return nodeTemplateByName(nodeTemplateName).interfaces?.keys?.first() - } - - fun nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName: String): String? { - return nodeTemplateFirstInterface(nodeTemplateName)?.operations?.keys?.first() - } - - fun nodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap? { - return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName)?.operations?.get(operationName)?.inputs - } - - fun nodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap? { - return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName)?.operations?.get(operationName)?.outputs - } - - fun nodeTemplateInterface(nodeTemplateName: String, interfaceName: String): InterfaceAssignment? { - return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName) - } - - - fun nodeTemplateInterfaceOperation(nodeTemplateName: String, interfaceName: String, operationName: String): OperationAssignment? { - return nodeTemplateInterface(nodeTemplateName, interfaceName)?.operations?.get(operationName) - } - - fun nodeTemplateCapability(nodeTemplateName: String, capabilityName: String): CapabilityAssignment? { - return nodeTemplateByName(nodeTemplateName).capabilities?.get(capabilityName) - } - - fun nodeTemplateRequirement(nodeTemplateName: String, requirementName: String): RequirementAssignment? { - return nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName) - } - - fun nodeTemplateRequirementNode(nodeTemplateName: String, requirementName: String): NodeTemplate { - val nodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node - ?: throw BluePrintException(String.format("failed to get node name for node template's (%s) requirement's (%s) " + nodeTemplateName, requirementName)) - return nodeTemplateByName(nodeTemplateName) - } - - fun nodeTemplateCapabilityProperty(nodeTemplateName: String, capabilityName: String, propertyName: String): Any? { - return nodeTemplateCapability(nodeTemplateName, capabilityName)?.properties?.get(propertyName) - } - - // Chained Functions - - fun nodeTypeChained(nodeTypeName: String): NodeType { - return BluePrintChainedService(this).nodeTypeChained(nodeTypeName) - } - - fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap? { - return BluePrintChainedService(this).nodeTypeChainedProperties(nodeTypeName) - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt deleted file mode 100644 index f38c317e7..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt +++ /dev/null @@ -1,259 +0,0 @@ -/* - * 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.core.service - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.format -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils -import java.io.Serializable - -/** - * BluePrintEnhancerService - * @author Brinda Santh - * - */ -interface BluePrintEnhancerService : Serializable { - - @Throws(BluePrintException::class) - fun enhance(content: String): ServiceTemplate - - /** - * Read Blueprint from CSAR structure Directory - */ - @Throws(BluePrintException::class) - fun enhance(fileName: String, basePath: String): ServiceTemplate - - @Throws(BluePrintException::class) - fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate - - @Throws(BluePrintException::class) - fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) - - @Throws(BluePrintException::class) - fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) - - @Throws(BluePrintException::class) - fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) -} - -open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRepoService) : BluePrintEnhancerService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerDefaultService::class.toString()) - - lateinit var serviceTemplate: ServiceTemplate - - @Throws(BluePrintException::class) - override fun enhance(content: String): ServiceTemplate { - return JacksonReactorUtils.readValueFromFile(content, ServiceTemplate::class.java).map { serviceTemplate -> - enhance(serviceTemplate!!) - }.block()!! - } - - @Throws(BluePrintException::class) - override fun enhance(fileName: String, basePath: String): ServiceTemplate { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - @Throws(BluePrintException::class) - override fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate { - this.serviceTemplate = serviceTemplate - initialCleanUp() - enrichTopologyTemplate(serviceTemplate) - - // log.info("Enriched Blueprint :\n {}", JacksonUtils.getJson(serviceTemplate, true)) - return this.serviceTemplate - } - - open fun initialCleanUp() { - serviceTemplate.artifactTypes?.clear() - serviceTemplate.nodeTypes?.clear() - serviceTemplate.dataTypes?.clear() - - serviceTemplate.artifactTypes = HashMap() - serviceTemplate.nodeTypes = HashMap() - serviceTemplate.dataTypes = HashMap() - - } - - @Throws(BluePrintException::class) - open fun enrichTopologyTemplate(serviceTemplate: ServiceTemplate) { - serviceTemplate.topologyTemplate?.let { topologyTemplate -> - enrichTopologyTemplateInputs(topologyTemplate) - enrichTopologyTemplateNodeTemplates(topologyTemplate) - } - } - - @Throws(BluePrintException::class) - open fun enrichTopologyTemplateInputs(topologyTemplate: TopologyTemplate) { - topologyTemplate.inputs?.let { inputs -> - enrichPropertyDefinitions(inputs) - } - } - - open fun enrichTopologyTemplateNodeTemplates(topologyTemplate: TopologyTemplate) { - topologyTemplate.nodeTemplates?.forEach { nodeTemplateName, nodeTemplate -> - enrichNodeTemplate(nodeTemplateName, nodeTemplate) - } - } - - @Throws(BluePrintException::class) - override fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) { - val nodeTypeName = nodeTemplate.type - // Get NodeType from Repo and Update Service Template - val nodeType = populateNodeType(nodeTypeName) - - // Enrich NodeType - enrichNodeType(nodeTypeName, nodeType) - - //Enrich Node Template Artifacts - enrichNodeTemplateArtifactDefinition(nodeTemplateName, nodeTemplate) - } - - @Throws(BluePrintException::class) - override fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) { - - // NodeType Property Definitions - enrichNodeTypeProperties(nodeTypeName, nodeType) - - //NodeType Requirement - enrichNodeTypeRequirements(nodeTypeName, nodeType) - - //NodeType Capability - enrichNodeTypeCapabilityProperties(nodeTypeName, nodeType) - - //NodeType Interface - enrichNodeTypeInterfaces(nodeTypeName, nodeType) - } - - open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) { - nodeType.properties?.let { enrichPropertyDefinitions(nodeType.properties!!) } - } - - open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) { - - nodeType.requirements?.forEach { _, requirementDefinition -> - // Populate Requirement Node - requirementDefinition.node?.let { requirementNodeTypeName -> - // Get Requirement NodeType from Repo and Update Service Template - val requirementNodeType = populateNodeType(requirementNodeTypeName) - - enrichNodeType(requirementNodeTypeName, requirementNodeType) - } - } - } - - open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) { - nodeType.capabilities?.forEach { capabilityDefinitionName, capabilityDefinition -> - capabilityDefinition.properties?.let { properties -> - enrichPropertyDefinitions(properties) - } - } - } - - open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) { - nodeType.interfaces?.forEach { interfaceName, interfaceObj -> - // Populate Node type Interface Operation - log.info("*** ** Enriching NodeType: {} Interface {}", nodeTypeName, interfaceName) - populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj) - - } - } - - open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) { - - interfaceObj.operations?.forEach { operationName, operation -> - enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation) - enrichNodeTypeInterfaceOperationOputputs(nodeTypeName, operationName, operation) - } - } - - open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { - operation.inputs?.let { inputs -> - enrichPropertyDefinitions(inputs) - } - } - - open fun enrichNodeTypeInterfaceOperationOputputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { - operation.outputs?.let { inputs -> - enrichPropertyDefinitions(inputs) - } - } - - open fun enrichPropertyDefinitions(properties: MutableMap) { - - properties.forEach { propertyName, propertyDefinition -> - enrichPropertyDefinition(propertyName, propertyDefinition) - } - } - - @Throws(BluePrintException::class) - override fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) { - val propertyType = propertyDefinition.type - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - val entrySchema = propertyDefinition.entrySchema - ?: throw BluePrintException(format("Entry Schema is missing for collection property : {}", propertyName)) - - if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { - populateDataTypes(entrySchema.type) - } - } else { - populateDataTypes(propertyType) - } - - } - - open fun enrichNodeTemplateArtifactDefinition(nodeTemplateName: String, nodeTemplate: NodeTemplate) { - - nodeTemplate.artifacts?.forEach { artifactDefinitionName, artifactDefinition -> - val artifactTypeName = artifactDefinition.type - ?: throw BluePrintException(format("Artifact type is missing for NodeTemplate({}) artifact({})", nodeTemplateName, artifactDefinitionName)) - - // Populate Artifact Type - populateArtifactType(artifactTypeName) - } - } - - open fun populateNodeType(nodeTypeName: String): NodeType { - val nodeType = bluePrintRepoService.getNodeType(nodeTypeName)?.block() - ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName)) - serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) - return nodeType - } - - open fun populateArtifactType(artifactTypeName: String): ArtifactType { - val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName)?.block() - ?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName)) - serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) - return artifactType - } - - open fun populateDataTypes(dataTypeName: String): DataType { - val dataType = bluePrintRepoService.getDataType(dataTypeName)?.block() - ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName)) - serviceTemplate.dataTypes?.put(dataTypeName, dataType) - return dataType - } - -} - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt deleted file mode 100644 index 19d515e0e..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt +++ /dev/null @@ -1,176 +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.core.service - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.ArrayNode -import com.fasterxml.jackson.databind.node.ObjectNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -/** - * - * - * @author Brinda Santh - */ -object BluePrintExpressionService { - val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - @JvmStatic - fun getExpressionData(propertyAssignment: Any): ExpressionData { - val propertyAssignmentNode: JsonNode = JacksonUtils.jsonNodeFromObject(propertyAssignment) - return getExpressionData(propertyAssignmentNode) - } - - @JvmStatic - fun getExpressionData(propertyAssignmentNode: JsonNode): ExpressionData { - log.trace("Assignment Data/Expression : {}", propertyAssignmentNode) - val expressionData = ExpressionData(valueNode = propertyAssignmentNode) - if (propertyAssignmentNode is ObjectNode) { - - val commands: Set = propertyAssignmentNode.fieldNames().asSequence().toList().intersect(BluePrintTypes.validCommands()) - if (commands.isNotEmpty()) { - expressionData.isExpression = true - expressionData.command = commands.first() - expressionData.expressionNode = propertyAssignmentNode - - when (expressionData.command) { - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_INPUT -> { - expressionData.inputExpression = populateInputExpression(propertyAssignmentNode) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ATTRIBUTE -> { - expressionData.attributeExpression = populateAttributeExpression(propertyAssignmentNode) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_PROPERTY -> { - expressionData.propertyExpression = populatePropertyExpression(propertyAssignmentNode) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT -> { - expressionData.operationOutputExpression = populateOperationOutputExpression(propertyAssignmentNode) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ARTIFACT -> { - expressionData.artifactExpression = populateArtifactExpression(propertyAssignmentNode) - } - } - } - } - return expressionData - } - - @JvmStatic - fun populateInputExpression(jsonNode: JsonNode): InputExpression { - return InputExpression(propertyName = jsonNode.first().textValue()) - } - - @JvmStatic - fun populatePropertyExpression(jsonNode: JsonNode): PropertyExpression { - val arrayNode: ArrayNode = jsonNode.first() as ArrayNode - check(arrayNode.size() >= 2) { - throw BluePrintException(String.format("missing property expression, " + - "it should be [ , , , " + - ", ..., ] , but present {}", jsonNode)) - } - var reqOrCapEntityName: String? = null - var propertyName = "" - var subProperty: String? = null - when { - arrayNode.size() == 2 -> propertyName = arrayNode[1].textValue() - arrayNode.size() == 3 -> { - reqOrCapEntityName = arrayNode[1].textValue() - propertyName = arrayNode[2].textValue() - } - arrayNode.size() > 3 -> { - reqOrCapEntityName = arrayNode[1].textValue() - propertyName = arrayNode[2].textValue() - val propertyPaths: List = arrayNode.filterIndexed { index, obj -> - index >= 3 - }.map { it.textValue() } - subProperty = propertyPaths.joinToString("/") - } - } - - return PropertyExpression(modelableEntityName = arrayNode[0].asText(), - reqOrCapEntityName = reqOrCapEntityName, - propertyName = propertyName, - subPropertyName = subProperty - ) - } - - @JvmStatic - fun populateAttributeExpression(jsonNode: JsonNode): AttributeExpression { - val arrayNode: ArrayNode = jsonNode.first() as ArrayNode - check(arrayNode.size() >= 3) { - throw BluePrintException(String.format("missing attribute expression, " + - "it should be [ , , ," + - " , ..., ] , but present {}", jsonNode)) - } - - var reqOrCapEntityName: String? = null - var propertyName = "" - var subProperty: String? = null - if (arrayNode.size() == 2) { - propertyName = arrayNode[1].textValue() - } else if (arrayNode.size() == 3) { - reqOrCapEntityName = arrayNode[1].textValue() - propertyName = arrayNode[2].textValue() - } else if (arrayNode.size() > 3) { - reqOrCapEntityName = arrayNode[1].textValue() - propertyName = arrayNode[2].textValue() - val propertyPaths: List = arrayNode.filterIndexed { index, obj -> - index >= 3 - }.map { it.textValue() } - subProperty = propertyPaths.joinToString("/") - } - return AttributeExpression(modelableEntityName = arrayNode[0].asText(), - reqOrCapEntityName = reqOrCapEntityName, - attributeName = propertyName, - subAttributeName = subProperty - ) - } - - @JvmStatic - fun populateOperationOutputExpression(jsonNode: JsonNode): OperationOutputExpression { - val arrayNode: ArrayNode = jsonNode.first() as ArrayNode - - check(arrayNode.size() >= 4) { - throw BluePrintException(String.format("missing operation output expression, " + - "it should be (, , , ) , but present {}", jsonNode)) - } - return OperationOutputExpression(modelableEntityName = arrayNode[0].asText(), - interfaceName = arrayNode[1].asText(), - operationName = arrayNode[2].asText(), - propertyName = arrayNode[3].asText() - ) - } - - @JvmStatic - fun populateArtifactExpression(jsonNode: JsonNode): ArtifactExpression { - val arrayNode: ArrayNode = jsonNode.first() as ArrayNode - - check(arrayNode.size() >= 2) { - throw BluePrintException(String.format("missing artifact expression, " + - "it should be [ , , , ] , but present {}", jsonNode)) - } - return ArtifactExpression(modelableEntityName = arrayNode[0].asText(), - artifactName = arrayNode[1].asText(), - location = arrayNode[2]?.asText() ?: "LOCAL_FILE", - remove = arrayNode[3]?.asBoolean() ?: false - ) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt deleted file mode 100644 index 43267ff1b..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt +++ /dev/null @@ -1,62 +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.core.service - -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import java.io.File -import java.io.Serializable - -/** - * - * - * @author Brinda Santh - */ -interface BluePrintParserService : Serializable { - fun readBlueprint(content: String) : BluePrintContext - fun readBlueprintFile(fileName: String) : BluePrintContext - /** - * Read Blueprint from CSAR structure Directory - */ - fun readBlueprintFile(fileName: String, basePath : String) : BluePrintContext -} - -class BluePrintParserDefaultService : BluePrintParserService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - var basePath : String = javaClass.classLoader.getResource(".").path - - override fun readBlueprint(content: String): BluePrintContext { - return BluePrintContext(ServiceTemplateUtils.getServiceTemplateFromContent(content)) - } - - override fun readBlueprintFile(fileName: String): BluePrintContext { - return readBlueprintFile(fileName, basePath ) - } - - override fun readBlueprintFile(fileName: String, basePath : String): BluePrintContext { - val rootFilePath: String = StringBuilder().append(basePath).append(File.separator).append(fileName).toString() - val rootServiceTemplate : ServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath) - // TODO("Nested Lookup Implementation based on Import files") - return BluePrintContext(rootServiceTemplate) - } - - -} diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt deleted file mode 100644 index e1d1eac71..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.core.service - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils -import reactor.core.publisher.Mono -import java.io.File -import java.io.Serializable -import java.nio.charset.Charset - -/** - * BluePrintRepoFileService - * @author Brinda Santh - * - */ - -interface BluePrintRepoService : Serializable { - - @Throws(BluePrintException::class) - fun getNodeType(nodeTypeName: String): Mono? - - @Throws(BluePrintException::class) - fun getDataType(dataTypeName: String): Mono? - - @Throws(BluePrintException::class) - fun getArtifactType(artifactTypeName: String): Mono? - - @Throws(BluePrintException::class) - fun getRelationshipType(relationshipTypeName: String): Mono? - - @Throws(BluePrintException::class) - fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? - -} - - -open class BluePrintRepoFileService(modelTypePath: String) : BluePrintRepoService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRepoFileService::class.toString()) - - private val dataTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) - private val nodeTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) - private val artifactTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) - private val capabilityTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) - private val relationshipTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) - private val extension = ".json" - - override fun getDataType(dataTypeName: String): Mono? { - val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(dataTypeName).plus(extension) - return getModelType(fileName, DataType::class.java) - } - - override fun getNodeType(nodeTypeName: String): Mono? { - val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension) - return getModelType(fileName, NodeType::class.java) - } - - override fun getArtifactType(artifactTypeName: String): Mono? { - val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(artifactTypeName).plus(extension) - return getModelType(fileName, ArtifactType::class.java) - } - - override fun getRelationshipType(relationshipTypeName: String): Mono? { - val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(relationshipTypeName).plus(extension) - return getModelType(fileName, RelationshipType::class.java) - } - - override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? { - val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(capabilityDefinitionName).plus(extension) - return getModelType(fileName, CapabilityDefinition::class.java) - } - - private fun getModelType(fileName: String, valueType: Class): Mono { - return JacksonReactorUtils.readValueFromFile(fileName, valueType) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt deleted file mode 100644 index ce0bceeea..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ /dev/null @@ -1,278 +0,0 @@ -/* - * 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.core.service - - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -/** - * - * - * @author Brinda Santh - */ -open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var context: MutableMap = hashMapOf()) { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRuntimeService::class.toString()) - - /* - Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing - */ - open fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { - log.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName) - val propertyAssignmentValue: MutableMap = hashMapOf() - - val nodeTemplate: NodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) - - val propertyAssignments: MutableMap = - nodeTemplate.properties as MutableMap - - // Get the Node Type Definitions - val nodeTypeProperties: MutableMap = - bluePrintContext.nodeTypeChainedProperties(nodeTemplate.type)!! - - // Iterate Node Type Properties - nodeTypeProperties.forEach { nodeTypePropertyName, nodeTypeProperty -> - // Get the Express or Value for the Node Template - val propertyAssignment: Any? = propertyAssignments[nodeTypePropertyName] - - var resolvedValue: JsonNode = NullNode.getInstance() - if (propertyAssignment != null) { - // Resolve the Expressing - val propertyAssignmentExpression = PropertyAssignmentService(context, this) - resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment) - } else { - // Assign default value to the Operation - nodeTypeProperty.defaultValue?.let { defaultValue -> - resolvedValue = defaultValue - } - } - // Set for Return of method - propertyAssignmentValue[nodeTypePropertyName] = resolvedValue - } - log.info("resolved property definition for node template ({}), values ({})", nodeTemplateName, propertyAssignmentValue) - return propertyAssignmentValue - } - - open fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, - interfaceName: String, operationName: String): MutableMap { - log.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " + - "operationName({})", nodeTemplateName, interfaceName, operationName) - - val propertyAssignmentValue: MutableMap = hashMapOf() - - val propertyAssignments: MutableMap = - bluePrintContext.nodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) as? MutableMap - ?: throw BluePrintException(String.format("failed to get input definitions for node template (%s), " + - "interface name (%s), operationName(%s)", nodeTemplateName, interfaceName, operationName)) - - val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type - - val nodeTypeInterfaceOperationInputs: MutableMap = - bluePrintContext.nodeTypeInterfaceOperationInputs(nodeTypeName, interfaceName, operationName) - ?: throw BluePrintException(String.format("failed to get input definitions for node type (%s), " + - "interface name (%s), operationName(%s)", nodeTypeName, interfaceName, operationName)) - - log.info("input definition for node template ({}), values ({})", nodeTemplateName, propertyAssignments) - - // Iterate Node Type Properties - nodeTypeInterfaceOperationInputs.forEach { nodeTypePropertyName, nodeTypeProperty -> - // Get the Express or Value for the Node Template - val propertyAssignment: Any? = propertyAssignments[nodeTypePropertyName] - - var resolvedValue: JsonNode = NullNode.getInstance() - if (propertyAssignment != null) { - // Resolve the Expressing - val propertyAssignmentExpression = PropertyAssignmentService(context, this) - resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment) - } else { - // Assign default value to the Operation - nodeTypeProperty.defaultValue?.let { - resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!) - } - } - // Set for Return of method - propertyAssignmentValue[nodeTypePropertyName] = resolvedValue - } - log.info("resolved input assignments for node template ({}), values ({})", nodeTemplateName, propertyAssignmentValue) - - return propertyAssignmentValue - } - - - open fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, - interfaceName: String, operationName: String, componentContext: MutableMap) { - log.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " + - "operationName({})", nodeTemplateName, interfaceName, operationName) - - val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type - - val nodeTypeInterfaceOperationOutputs: MutableMap = - bluePrintContext.nodeTypeInterfaceOperationOutputs(nodeTypeName, interfaceName, operationName) - ?: throw BluePrintException(String.format("failed to get input definitions for node type (%s), " + - "interface name (%s), operationName(%s)", nodeTypeName, interfaceName, operationName)) - - // Iterate Node Type Properties - nodeTypeInterfaceOperationOutputs.forEach { nodeTypePropertyName, nodeTypeProperty -> - - val operationOutputPropertyName: String = StringBuilder().append(nodeTemplateName) - .append(".").append(interfaceName) - .append(".").append(operationName) - .append(".").append(nodeTypePropertyName).toString() - // Get the Value from component context - val resolvedValue: JsonNode = componentContext[operationOutputPropertyName] as? JsonNode - ?: NullNode.getInstance() - // Store operation output values into context - setNodeTemplateOperationPropertyValue(nodeTemplateName, interfaceName, operationName, nodeTypePropertyName, resolvedValue) - log.debug("resolved output assignments for node template ({}), property name ({}), value ({})", nodeTemplateName, nodeTypePropertyName, resolvedValue) - } - } - - open fun resolveNodeTemplateArtifact(nodeTemplateName: String, - artifactName: String): String { - val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) - - val artifactDefinition: ArtifactDefinition = nodeTemplate.artifacts?.get(artifactName) - ?: throw BluePrintProcessorException(String.format("failed to get artifat definition {} from the node template" - , artifactName)) - val propertyAssignmentExpression = PropertyAssignmentService(context, this) - return propertyAssignmentExpression.artifactContent(artifactDefinition) - } - - - open fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) { - val path = StringBuilder(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - log.trace("setting input path ({}), values ({})", path, value) - context[path] = value - } - - open fun setWorkflowInputValue(workflowName: String, propertyName: String, value: JsonNode) { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_WORKFLOWS).append(BluePrintConstants.PATH_DIVIDER).append(workflowName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - context[path] = value - } - - open fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) { - - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - context[path] = value - } - - open fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode) { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - log.trace("setting operation property path ({}), values ({})", path, value) - context[path] = value - } - - open fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode) { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - context[path] = value - } - - open fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode) { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - context[path] = value - } - - - open fun getInputValue(propertyName: String): JsonNode { - val path = StringBuilder(BluePrintConstants.PATH_INPUTS) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - return context[path] as? JsonNode ?: NullNode.instance - } - - open fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - return context[path] as JsonNode - } - - open fun getPropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - return context[path] as JsonNode - } - - open fun getRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_REQUIREMENTS).append(requirementName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - return context[path] as JsonNode - } - - open fun getCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_CAPABILITIES).append(capabilityName) - .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) - .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() - return context[path] as JsonNode - } - - open fun assignInputs(jsonNode: JsonNode) { - log.info("assignInputs from input JSON ({})", jsonNode.toString()) - bluePrintContext.inputs?.forEach { propertyName, property -> - val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) - ?: NullNode.getInstance() - setInputValue(propertyName, property, valueNode) - } - } - - open fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) { - log.info("assign workflow {} input value ({})", workflowName, jsonNode.toString()) - bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, property -> - val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) - ?: NullNode.getInstance() - setWorkflowInputValue(workflowName, propertyName, valueNode) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt deleted file mode 100644 index 34399fdd2..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt +++ /dev/null @@ -1,360 +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.core.service - -import com.fasterxml.jackson.databind.JsonNode -import com.google.common.base.Preconditions -import org.apache.commons.lang3.StringUtils -import org.onap.ccsdk.apps.controllerblueprints.core.* -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import java.io.Serializable - -/** - * - * - * @author Brinda Santh - */ -interface BluePrintValidatorService : Serializable { - - @Throws(BluePrintException::class) - fun validateBlueprint(bluePrintContext: BluePrintContext, properties: MutableMap) - - @Throws(BluePrintException::class) - fun validateBlueprint(serviceTemplate: ServiceTemplate, properties: MutableMap) -} - -open class BluePrintValidatorDefaultService : BluePrintValidatorService { - - val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorDefaultService::class.toString()) - - lateinit var bluePrintContext: BluePrintContext - lateinit var serviceTemplate: ServiceTemplate - lateinit var properties: MutableMap - var message: StringBuilder = StringBuilder() - private val separator: String = BluePrintConstants.PATH_DIVIDER - var paths: MutableList = arrayListOf() - - @Throws(BluePrintException::class) - override fun validateBlueprint(bluePrintContext: BluePrintContext, properties: MutableMap) { - validateBlueprint(bluePrintContext.serviceTemplate,properties) - } - - @Throws(BluePrintException::class) - override fun validateBlueprint(serviceTemplate: ServiceTemplate, properties: MutableMap) { - this.bluePrintContext = BluePrintContext(serviceTemplate) - this.serviceTemplate = serviceTemplate - this.properties = properties - try { - message.appendln("-> Config Blueprint") - serviceTemplate.metadata?.let { validateMetadata(serviceTemplate.metadata!!) } - serviceTemplate.artifactTypes?.let { validateArtifactTypes(serviceTemplate.artifactTypes!!) } - serviceTemplate.dataTypes?.let { validateDataTypes(serviceTemplate.dataTypes!!) } - serviceTemplate.nodeTypes?.let { validateNodeTypes(serviceTemplate.nodeTypes!!) } - serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) } - } catch (e: Exception) { - log.error("validation failed in the path : {}", paths.joinToString(separator), e) - log.error("validation trace message :{} ", message) - throw BluePrintException(e, - format("failed to validate blueprint on path ({}) with message {}" - , paths.joinToString(separator), e.message)) - } - } - - @Throws(BluePrintException::class) - open fun validateMetadata(metaDataMap: MutableMap) { - paths.add("metadata") - - val templateName = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME] - val templateVersion = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION] - val templateTags = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS] - val templateAuthor = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] - - Preconditions.checkArgument(StringUtils.isNotBlank(templateName), "failed to get template name metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(templateVersion), "failed to get template version metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(templateTags), "failed to get template tags metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(templateAuthor), "failed to get template author metadata") - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateArtifactTypes(artifactTypes: MutableMap) { - paths.add("artifact_types") - artifactTypes.forEach { artifactName, artifactType -> - paths.add(artifactName) - message.appendln("--> Artifact Type :" + paths.joinToString(separator)) - artifactType.properties?.let { validatePropertyDefinitions(artifactType.properties!!) } - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateDataTypes(dataTypes: MutableMap) { - paths.add("dataTypes") - dataTypes.forEach { dataTypeName, dataType -> - paths.add(dataTypeName) - message.appendln("--> Data Type :" + paths.joinToString(separator)) - dataType.properties?.let { validatePropertyDefinitions(dataType.properties!!) } - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateNodeTypes(nodeTypes: MutableMap) { - paths.add("nodeTypes") - nodeTypes.forEach { nodeTypeName, nodeType -> - // Validate Single Node Type - validateNodeType(nodeTypeName,nodeType) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateNodeType(nodeTypeName: String, nodeType: NodeType) { - paths.add(nodeTypeName) - message.appendln("--> Node Type :" + paths.joinToString(separator)) - val derivedFrom: String = nodeType.derivedFrom - //Check Derived From - checkValidNodeTypesDerivedFrom(derivedFrom) - - nodeType.properties?.let { validatePropertyDefinitions(nodeType.properties!!) } - nodeType.interfaces?.let { validateInterfaceDefinitions(nodeType.interfaces!!) } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateTopologyTemplate(topologyTemplate: TopologyTemplate) { - paths.add("topology") - message.appendln("--> Topology Template") - topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) } - topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) } - topologyTemplate.workflows?.let { validateWorkFlows(topologyTemplate.workflows!!) } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateInputs(inputs: MutableMap) { - paths.add("inputs") - message.appendln("---> Input :" + paths.joinToString(separator)) - validatePropertyDefinitions(inputs) - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateNodeTemplates(nodeTemplates: MutableMap) { - paths.add("nodeTemplates") - nodeTemplates.forEach { nodeTemplateName, nodeTemplate -> - validateNodeTemplate(nodeTemplateName, nodeTemplate) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateNodeTemplate(nodeTemplateName : String, nodeTemplate: NodeTemplate) { - paths.add(nodeTemplateName) - message.appendln("---> Node Template :" + paths.joinToString(separator)) - val type: String = nodeTemplate.type - - val nodeType: NodeType = serviceTemplate.nodeTypes?.get(type) - ?: throw BluePrintException(format("Failed to get node type definition for node template : {}", nodeTemplateName)) - - nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) } - nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } - nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeTemplate.capabilities!!) } - nodeTemplate.requirements?.let { validateRequirementAssignments(nodeTemplate.requirements!!) } - nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeTemplate.interfaces!!) } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateWorkFlows(workflows: MutableMap) { - paths.add("workflows") - workflows.forEach { workflowName, workflow -> - - // Validate Single workflow - validateWorkFlow(workflowName, workflow) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateWorkFlow(workflowName:String, workflow: Workflow) { - paths.add(workflowName) - message.appendln("---> Workflow :" + paths.joinToString(separator)) - // Step Validation Start - paths.add("steps") - workflow.steps?.forEach { stepName, step -> - paths.add(stepName) - message.appendln("----> Steps :" + paths.joinToString(separator)) - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - // Step Validation Ends - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validatePropertyDefinitions(properties: MutableMap) { - paths.add("properties") - properties.forEach { propertyName, propertyDefinition -> - paths.add(propertyName) - val dataType: String = propertyDefinition.type - when { - BluePrintTypes.validPrimitiveTypes().contains(dataType) -> { - // Do Nothing - } - BluePrintTypes.validCollectionTypes().contains(dataType) -> { - val entrySchemaType: String = propertyDefinition.entrySchema?.type - ?: throw BluePrintException(format("Entry schema for data type ({}) for the property ({}) not found", dataType, propertyName)) - checkPrimitiveOrComplex(entrySchemaType, propertyName) - } - else -> checkPropertyDataType(dataType, propertyName) - } - message.appendln("property " + paths.joinToString(separator) + " of type " + dataType) - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, - properties: MutableMap) { - properties.forEach { propertyName, propertyAssignment -> - val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] - ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) - // Check and Validate if Expression Node - val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) - if (!expressionData.isExpression) { - checkPropertyValue(propertyDefinition, propertyAssignment) - } - } - } - - @Throws(BluePrintException::class) - open fun validateArtifactDefinitions(artifacts: MutableMap) { - paths.add("artifacts") - artifacts.forEach { artifactName, artifactDefinition -> - paths.add(artifactName) - message.appendln("Validating artifact " + paths.joinToString(separator)) - val type: String = artifactDefinition.type - ?: throw BluePrintException("type is missing for artifact definition :" + artifactName) - // Check Artifact Type - checkValidArtifactType(type) - - val file: String = artifactDefinition.file - ?: throw BluePrintException(format("file is missing for artifact definition : {}", artifactName)) - - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateCapabilityAssignments(capabilities: MutableMap) { - - } - - @Throws(BluePrintException::class) - open fun validateRequirementAssignments(requirements: MutableMap) { - - } - - @Throws(BluePrintException::class) - open fun validateInterfaceAssignments(interfaces: MutableMap) { - - } - - @Throws(BluePrintException::class) - open fun validateInterfaceDefinitions(interfaces: MutableMap) { - paths.add("interfaces") - interfaces.forEach { interfaceName, interfaceDefinition -> - paths.add(interfaceName) - message.appendln("Validating : " + paths.joinToString(separator)) - interfaceDefinition.operations?.let { validateOperationDefinitions(interfaceDefinition.operations!!) } - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateOperationDefinitions(operations: MutableMap) { - paths.add("operations") - operations.forEach { opertaionName, operationDefinition -> - paths.add(opertaionName) - message.appendln("Validating : " + paths.joinToString(separator)) - operationDefinition.implementation?.let { validateImplementation(operationDefinition.implementation!!) } - operationDefinition.inputs?.let { validatePropertyDefinitions(operationDefinition.inputs!!) } - operationDefinition.outputs?.let { validatePropertyDefinitions(operationDefinition.outputs!!) } - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateImplementation(implementation: Implementation) { - checkNotEmptyNThrow(implementation.primary) - } - - @Throws(BluePrintException::class) - open fun checkValidNodeType(nodeType : String) { - - } - - @Throws(BluePrintException::class) - open fun checkValidArtifactType(artifactType: String) { - - serviceTemplate.artifactTypes?.containsKey(artifactType) - ?: throw BluePrintException(format("Failed to node type definition for artifact definition : {}", artifactType)) - } - - @Throws(BluePrintException::class) - open fun checkValidNodeTypesDerivedFrom(derivedFrom: String) { - - } - - private fun checkPropertyValue(propertyDefinition: PropertyDefinition, jsonNode: JsonNode) { - //log.info("validating path ({}), Property {}, value ({})", paths, propertyDefinition, jsonNode) - } - - private fun checkPropertyDataType(dataType: String, propertyName: String): Boolean { - if (checkDataType(dataType)) { - return true - } else { - throw BluePrintException(format("Data type ({}) for the property ({}) not found", dataType, propertyName)) - } - } - - private fun checkPrimitiveOrComplex(dataType: String, propertyName: String): Boolean { - if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) { - return true - } else { - throw BluePrintException(format("Data type ({}) for the property ({}) is not valid", dataType)) - } - } - - private fun checkDataType(key: String): Boolean { - return serviceTemplate.dataTypes?.containsKey(key) ?: false - } - - private fun checkNodeType(key: String): Boolean { - return serviceTemplate.nodeTypes?.containsKey(key) ?: false - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt deleted file mode 100644 index ece09d6e2..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt +++ /dev/null @@ -1,200 +0,0 @@ -/* - * 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.core.service - - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.format -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.ResourceResolverUtils -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -/** - * - * - * @author Brinda Santh - */ -class PropertyAssignmentService(var context: MutableMap, - var bluePrintRuntimeService: BluePrintRuntimeService) { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - private var bluePrintContext: BluePrintContext = bluePrintRuntimeService.bluePrintContext - -/* - -If Property Assignment is Expression. - Get the Expression - Recurssely resolve the expression - */ - - fun resolveAssignmentExpression(nodeTemplateName: String, assignmentName: String, - assignment: Any): JsonNode { - val valueNode: JsonNode - log.trace("Assignment ({})", assignment) - val expressionData = BluePrintExpressionService.getExpressionData(assignment) - - if (expressionData.isExpression) { - valueNode = resolveExpression(nodeTemplateName, assignmentName, expressionData) - } else { - valueNode = expressionData.valueNode - } - return valueNode - } - - fun resolveExpression(nodeTemplateName: String, propName: String, expressionData: ExpressionData): JsonNode { - - var valueNode: JsonNode = NullNode.getInstance() - - if(expressionData.isExpression) { - val command = expressionData.command!! - - when(command){ - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_INPUT ->{ - valueNode = bluePrintRuntimeService.getInputValue(expressionData.inputExpression?.propertyName!!) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ATTRIBUTE ->{ - valueNode = resolveAttributeExpression(nodeTemplateName, expressionData.attributeExpression!!) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_PROPERTY ->{ - valueNode = resolvePropertyExpression(nodeTemplateName, expressionData.propertyExpression!!) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT ->{ - valueNode = resolveOperationOutputExpression(nodeTemplateName, expressionData.operationOutputExpression!!) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ARTIFACT ->{ - valueNode = resolveArtifactExpression(nodeTemplateName, expressionData.artifactExpression!!) - } - org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE ->{ - - } - else ->{ - throw BluePrintException(String.format("for property ({}), command ({}) is not supported ", propName, command)) - } - } - } - return valueNode - } - - /* - get_property: [ , , , - , ..., ] - */ - fun resolveAttributeExpression(nodeTemplateName: String, attributeExpression: AttributeExpression): JsonNode { - val valueNode: JsonNode - - val attributeName = attributeExpression.attributeName - val subAttributeName: String? = attributeExpression.subAttributeName - - var attributeNodeTemplateName = nodeTemplateName - if (!attributeExpression.modelableEntityName.equals("SELF", true)) { - attributeNodeTemplateName = attributeExpression.modelableEntityName - } - - val nodeTemplateAttributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName) - ?: throw BluePrintException(String.format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, attributeName)) - - var propertyDefinition: AttributeDefinition = bluePrintContext.nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)!! - - log.info("node template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression) - - // Check it it is a nested expression - valueNode = resolveAssignmentExpression(attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression) - -// subPropertyName?.let { -// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName)) -// } - return valueNode - } - - /* - get_property: [ , , , - , ..., ] - */ - fun resolvePropertyExpression(nodeTemplateName: String, propertyExpression: PropertyExpression): JsonNode { - val valueNode: JsonNode - - val propertyName = propertyExpression.propertyName - val subPropertyName: String? = propertyExpression.subPropertyName - - var propertyNodeTemplateName = nodeTemplateName - if (!propertyExpression.modelableEntityName.equals("SELF", true)) { - propertyNodeTemplateName = propertyExpression.modelableEntityName - } - - val nodeTemplatePropertyExpression = bluePrintContext.nodeTemplateByName(propertyNodeTemplateName).properties?.get(propertyName) - ?: throw BluePrintException(format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, propertyName)) - - var propertyDefinition: PropertyDefinition = bluePrintContext.nodeTemplateNodeType(propertyNodeTemplateName).properties?.get(propertyName)!! - - log.info("node template name ({}), property Name ({}) resolved value ({})", propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression) - - // Check it it is a nested expression - valueNode = resolveAssignmentExpression(propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression) - -// subPropertyName?.let { -// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName)) -// } - return valueNode - } - - /* - get_operation_output: , , , - */ - fun resolveOperationOutputExpression(nodeTemplateName: String, operationOutputExpression: OperationOutputExpression): JsonNode { - var outputNodeTemplateName = nodeTemplateName - if (!operationOutputExpression.modelableEntityName.equals("SELF", true)) { - outputNodeTemplateName = operationOutputExpression.modelableEntityName - } - return bluePrintRuntimeService.getNodeTemplateOperationOutputValue(outputNodeTemplateName, - operationOutputExpression.interfaceName, operationOutputExpression.operationName, - operationOutputExpression.propertyName) - } - - /* - get_artifact: [ , , , ] - */ - fun resolveArtifactExpression(nodeTemplateName: String, artifactExpression: ArtifactExpression): JsonNode { - - var artifactNodeTemplateName = nodeTemplateName - if (!artifactExpression.modelableEntityName.equals("SELF", true)) { - artifactNodeTemplateName = artifactExpression.modelableEntityName - } - val artifactDefinition: ArtifactDefinition = bluePrintContext.nodeTemplateByName(artifactNodeTemplateName) - .artifacts?.get(artifactExpression.artifactName) - ?: throw BluePrintException(String.format("failed to get artifact definitions for node template ({})'s " + - "artifact name ({}) ", nodeTemplateName, artifactExpression.artifactName)) - - return JacksonUtils.jsonNodeFromObject(artifactContent(artifactDefinition)) - } - - fun artifactContent(artifactDefinition: ArtifactDefinition): String { - val bluePrintBasePath: String = context[org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] as? String - ?: throw BluePrintException(String.format("failed to get property (%s) from context", org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)) - - if (artifactDefinition.repository != null) { - TODO() - } else if (artifactDefinition.file != null) { - return ResourceResolverUtils.getFileContent(artifactDefinition.file!!, bluePrintBasePath) - } - return "" - } -} - diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt deleted file mode 100644 index b7f9fc7e6..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt +++ /dev/null @@ -1,95 +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.core.utils - - -import org.apache.commons.io.FileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import java.io.File -import java.nio.charset.Charset - -object BluePrintMetadataUtils { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - @JvmStatic - fun toscaMetaData(basePath: String): ToscaMetaData { - val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus("TOSCA-Metadata/TOSCA.meta") - return toscaMetaDataFromMetaFile(toscaMetaPath) - } - - @JvmStatic - fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData { - val toscaMetaData = ToscaMetaData() - val lines: MutableList = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset()) - lines.forEach { line -> - if (line.contains(":")) { - val keyValue = line.split(":") - if (keyValue.size == 2) { - val value: String = keyValue[1].trim() - when (keyValue[0]) { - "TOSCA-Meta-File-Version" -> toscaMetaData.toscaMetaFileVersion = value - "CSAR-Version" -> toscaMetaData.csarVersion = value - "Created-By" -> toscaMetaData.createdBy = value - "Entry-Definitions" -> toscaMetaData.entityDefinitions = value - "Template-Tags" -> toscaMetaData.templateTags = value - } - } - } - - } - return toscaMetaData - } - - /* - fun getBluePrintContext(blueprintBasePath: String): BluePrintContext { - - val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator) - .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString() - - val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile) - - log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions) - - return BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath) - } - - fun getBluePrintRuntime(requestId: String, blueprintBasePath: String): BluePrintRuntimeService { - - val metaDataFile = StringBuilder().append(blueprintBasePath).append(File.separator) - .append(BluePrintConstants.DEFAULT_TOSCA_METADATA_ENTRY_DEFINITION_FILE).toString() - - val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(metaDataFile) - - log.info("Processing blueprint base path ({}) and entry definition file ({})", blueprintBasePath, toscaMetaData.entityDefinitions) - - val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprintFile(toscaMetaData.entityDefinitions!!, blueprintBasePath) - - val context: MutableMap = hashMapOf() - context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath - context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = requestId - - val bluePrintRuntimeService: BluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context) - - return bluePrintRuntimeService - } - */ -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt deleted file mode 100644 index 07b819ffe..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt +++ /dev/null @@ -1,55 +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.core.utils - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager - -/** - * - * - * @author Brinda Santh - */ -object BluePrintRuntimeUtils { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - fun assignInputsFromFile(bluePrintContext: BluePrintContext, fileName: String, context: MutableMap) { - val jsonNode: JsonNode = JacksonUtils.jsonNodeFromFile(fileName) - return assignInputs(bluePrintContext, jsonNode, context) - } - - fun assignInputsFromContent(bluePrintContext: BluePrintContext, content: String, context: MutableMap) { - val jsonNode: JsonNode = JacksonUtils.jsonNode(content) - return assignInputs(bluePrintContext, jsonNode, context) - } - - fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap) { - log.info("assignInputs from input JSON ({})", jsonNode.toString()) - bluePrintContext.inputs?.forEach { propertyName, property -> - val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance() - - val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(propertyName) - log.trace("setting input path ({}), values ({})", path, valueNode) - context[path] = valueNode - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt deleted file mode 100644 index 0ed901702..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt +++ /dev/null @@ -1,108 +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.core.utils - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import reactor.core.publisher.Mono -import reactor.core.publisher.toMono - -object JacksonReactorUtils { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - @JvmStatic - fun getContent(fileName: String): Mono { - return JacksonUtils.getContent(fileName).toMono() - } - - @JvmStatic - fun getClassPathFileContent(fileName: String): Mono { - return JacksonUtils.getClassPathFileContent(fileName).toMono() - } - - @JvmStatic - fun readValue(content: String, valueType: Class): Mono { - return Mono.just(jacksonObjectMapper().readValue(content, valueType)) - } - - @JvmStatic - fun jsonNode(content: String): Mono { - return Mono.just(jacksonObjectMapper().readTree(content)) - } - - @JvmStatic - fun getJson(any: kotlin.Any, pretty: Boolean = false): Mono { - return Mono.just(JacksonUtils.getJson(any, pretty)) - } - - @JvmStatic - fun getListFromJson(content: String, valueType: Class): Mono> { - val objectMapper = jacksonObjectMapper() - val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType) - return objectMapper.readValue>(content, javaType).toMono() - } - - @JvmStatic - fun readValueFromFile(fileName: String, valueType: Class): Mono { - return getContent(fileName) - .flatMap { content -> - readValue(content, valueType) - } - } - - @JvmStatic - fun readValueFromClassPathFile(fileName: String, valueType: Class): Mono { - return getClassPathFileContent(fileName) - .flatMap { content -> - readValue(content, valueType) - } - } - - @JvmStatic - fun jsonNodeFromFile(fileName: String): Mono { - return getContent(fileName) - .flatMap { content -> - jsonNode(content) - } - } - - @JvmStatic - fun jsonNodeFromClassPathFile(fileName: String): Mono { - return getClassPathFileContent(fileName) - .flatMap { content -> - jsonNode(content) - } - } - - @JvmStatic - fun getListFromFile(fileName: String, valueType: Class): Mono> { - return getContent(fileName) - .flatMap { content -> - getListFromJson(content, valueType) - } - } - - @JvmStatic - fun getListFromClassPathFile(fileName: String, valueType: Class): Mono> { - return getClassPathFileContent(fileName) - .flatMap { content -> - getListFromJson(content, valueType) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt deleted file mode 100644 index 5075e7261..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ /dev/null @@ -1,248 +0,0 @@ -/* - * 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.core.utils - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.core.type.TypeReference -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.SerializationFeature -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import org.apache.commons.io.FileUtils -import org.apache.commons.io.IOUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.format -import java.io.File -import java.nio.charset.Charset - -/** - * - * - * @author Brinda Santh - */ -object JacksonUtils { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - inline fun readValue(content: String): T = - jacksonObjectMapper().readValue(content, T::class.java) - - @JvmStatic - fun readValue(content: String, valueType: Class): T? { - return jacksonObjectMapper().readValue(content, valueType) - } - - @JvmStatic - fun getContent(fileName: String): String { - return File(fileName).readText(Charsets.UTF_8) - } - - @JvmStatic - fun getClassPathFileContent(fileName: String): String { - return IOUtils.toString(JacksonUtils::class.java.classLoader - .getResourceAsStream(fileName), Charset.defaultCharset()) - } - - @JvmStatic - fun readValueFromFile(fileName: String, valueType: Class): T? { - val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) - ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) - return readValue(content, valueType) - } - - @JvmStatic - fun readValueFromClassPathFile(fileName: String, valueType: Class): T? { - val content: String = getClassPathFileContent(fileName) - return readValue(content, valueType) - } - - @JvmStatic - fun jsonNodeFromObject(from: kotlin.Any): JsonNode = jacksonObjectMapper().convertValue(from, JsonNode::class.java) - - @JvmStatic - fun jsonNodeFromClassPathFile(fileName: String): JsonNode { - val content: String = getClassPathFileContent(fileName) - return jsonNode(content) - } - - @JvmStatic - fun jsonNodeFromFile(fileName: String): JsonNode { - val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) - ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) - return jsonNode(content) - } - - @JvmStatic - fun jsonNode(content: String): JsonNode { - return jacksonObjectMapper().readTree(content) - } - - @JvmStatic - fun getJson(any: kotlin.Any): String { - return getJson(any, false) - } - - @JvmStatic - fun getJson(any: kotlin.Any, pretty: Boolean = false): String { - val objectMapper = jacksonObjectMapper() - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) - if (pretty) { - objectMapper.enable(SerializationFeature.INDENT_OUTPUT) - } - return objectMapper.writeValueAsString(any) - } - - @JvmStatic - fun getListFromJson(content: String, valueType: Class): List? { - val objectMapper = jacksonObjectMapper() - val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType) - return objectMapper.readValue>(content, javaType) - } - - @JvmStatic - fun getListFromFile(fileName: String, valueType: Class): List? { - val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) - ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) - return getListFromJson(content, valueType) - } - - @JvmStatic - fun getListFromClassPathFile(fileName: String, valueType: Class): List? { - val content: String = getClassPathFileContent(fileName) - return getListFromJson(content, valueType) - } - - @JvmStatic - fun getMapFromJson(content: String, valueType: Class): MutableMap? { - val objectMapper = jacksonObjectMapper() - val typeRef = object : TypeReference>() {} - return objectMapper.readValue(content, typeRef) - } - - @JvmStatic - fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean { - if (BluePrintTypes.validPrimitiveTypes().contains(type)) { - return checkJsonNodeValueOfPrimitiveType(type, jsonNode) - } else if (BluePrintTypes.validCollectionTypes().contains(type)) { - return checkJsonNodeValueOfCollectionType(type, jsonNode) - } - return false - } - - @JvmStatic - fun checkJsonNodeValueOfPrimitiveType(primitiveType: String, jsonNode: JsonNode): Boolean { - when (primitiveType) { - BluePrintConstants.DATA_TYPE_STRING -> return jsonNode.isTextual - BluePrintConstants.DATA_TYPE_BOOLEAN -> return jsonNode.isBoolean - BluePrintConstants.DATA_TYPE_INTEGER -> return jsonNode.isInt - BluePrintConstants.DATA_TYPE_FLOAT -> return jsonNode.isDouble - BluePrintConstants.DATA_TYPE_TIMESTAMP -> return jsonNode.isTextual - else -> return false - } - } - - @JvmStatic - fun checkJsonNodeValueOfCollectionType(type: String, jsonNode: JsonNode): Boolean { - when (type) { - BluePrintConstants.DATA_TYPE_LIST -> return jsonNode.isArray - BluePrintConstants.DATA_TYPE_MAP -> return jsonNode.isContainerNode - else -> return false - } - - } -/* - @JvmStatic - fun populatePrimitiveValues(key: String, value: Any, primitiveType: String, objectNode: ObjectNode) { - if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { - objectNode.put(key, value as Boolean) - } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) { - objectNode.put(key, value as Int) - } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) { - objectNode.put(key, value as Float) - } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == primitiveType) { - objectNode.put(key, value as String) - } else { - objectNode.put(key, value as String) - } - } - - @JvmStatic - fun populatePrimitiveValues(value: Any, primitiveType: String, objectNode: ArrayNode) { - if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { - objectNode.add(value as Boolean) - } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) { - objectNode.add(value as Int) - } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) { - objectNode.add(value as Float) - } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == primitiveType) { - objectNode.add(value as String) - } else { - objectNode.add(value as String) - } - } - - @JvmStatic - fun populatePrimitiveDefaultValues(key: String, primitiveType: String, objectNode: ObjectNode) { - if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { - objectNode.put(key, false) - } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) { - objectNode.put(key, 0) - } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) { - objectNode.put(key, 0.0) - } else { - objectNode.put(key, "") - } - } - - @JvmStatic - fun populatePrimitiveDefaultValuesForArrayNode(primitiveType: String, arrayNode: ArrayNode) { - if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) { - arrayNode.add(false) - } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) { - arrayNode.add(0) - } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) { - arrayNode.add(0.0) - } else { - arrayNode.add("") - } - } - - @JvmStatic - fun populateJsonNodeValues(key: String, nodeValue: JsonNode?, type: String, objectNode: ObjectNode) { - if (nodeValue == null || nodeValue is NullNode) { - objectNode.set(key, nodeValue) - } else if (BluePrintTypes.validPrimitiveTypes().contains(type)) { - if (BluePrintConstants.DATA_TYPE_BOOLEAN == type) { - objectNode.put(key, nodeValue.asBoolean()) - } else if (BluePrintConstants.DATA_TYPE_INTEGER == type) { - objectNode.put(key, nodeValue.asInt()) - } else if (BluePrintConstants.DATA_TYPE_FLOAT == type) { - objectNode.put(key, nodeValue.floatValue()) - } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == type) { - objectNode.put(key, nodeValue.asText()) - } else { - objectNode.put(key, nodeValue.asText()) - } - } else { - objectNode.set(key, nodeValue) - } - } - */ -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt deleted file mode 100644 index bc0d9b4c6..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt +++ /dev/null @@ -1,62 +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.core.utils - -import org.apache.commons.io.FileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import java.io.File -import java.net.URL -import java.nio.charset.Charset -/** - * - * - * @author Brinda Santh - */ -object ResourceResolverUtils { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - @JvmStatic - fun getFileContent(filename : String, basePath : String?): String { - log.trace("file ({}), basePath ({}) ", filename, basePath) - try{ - var resolvedFileName : String = filename - if(filename.startsWith("http", true) - || filename.startsWith("https", true)){ - val givenUrl : String = URL(filename).toString() - val systemUrl : String = File(".").toURI().toURL().toString() - log.trace("givenUrl ({}), systemUrl ({}) ", givenUrl, systemUrl) - if(givenUrl.startsWith(systemUrl)){ - - } - }else{ - if(!filename.startsWith("/")){ - if (checkNotEmpty(basePath)) { - resolvedFileName = basePath.plus(File.separator).plus(filename) - }else{ - resolvedFileName = javaClass.classLoader.getResource(".").path.plus(filename) - } - } - } - return FileUtils.readFileToString(File(resolvedFileName), Charset.defaultCharset()) - }catch (e : Exception){ - throw BluePrintException(e, "failed to file (%s), basePath (%s) ", filename, basePath) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt deleted file mode 100644 index 0d739357c..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt +++ /dev/null @@ -1,44 +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.core.utils - -import org.apache.commons.io.FileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate -import java.io.File -import java.nio.charset.Charset - -/** - * - * - * @author Brinda Santh - */ -object ServiceTemplateUtils { - - @JvmStatic - fun getServiceTemplate(fileName: String): ServiceTemplate { - val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) - return getServiceTemplateFromContent(content) - } - - - @JvmStatic - fun getServiceTemplateFromContent(content: String): ServiceTemplate { - return JacksonUtils.readValue(content) - } - - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt deleted file mode 100644 index dcafa974c..000000000 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt +++ /dev/null @@ -1,131 +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.core.utils - -import java.util.* - -/** - * - * - * @author Brinda Santh - */ -class TopologicalSortingUtils { - - private val neighbors: MutableMap> = hashMapOf() - - val isDag: Boolean - get() = topSort() != null - - override fun toString(): String { - val s = StringBuffer() - for (v in neighbors.keys) - s.append("\n " + v + " -> " + neighbors[v]) - return s.toString() - } - - fun getNeighbors(): Map> { - return neighbors - } - - fun add(vertex: V) { - if (neighbors.containsKey(vertex)) - return - neighbors[vertex] = arrayListOf() - } - - operator fun contains(vertex: V): Boolean { - return neighbors.containsKey(vertex) - } - - fun add(from: V, to: V) { - this.add(from) - this.add(to) - neighbors[from]?.add(to) - } - - fun remove(from: V, to: V) { - if (!(this.contains(from) && this.contains(to))) - throw IllegalArgumentException("Nonexistent vertex") - neighbors[from]?.remove(to) - } - - fun outDegree(): Map { - var result: MutableMap = hashMapOf() - for (v in neighbors.keys) - result[v] = neighbors[v]!!.size - return result - } - - - fun inDegree(): MutableMap { - val result = HashMap() - for (v in neighbors.keys) - result[v] = 0 // All in-degrees are 0 - for (from in neighbors.keys) { - for (to in neighbors[from]!!) { - result[to] = result[to]!! + 1 // Increment in-degree - } - } - return result - } - - fun topSort(): List? { - val degree = inDegree() - // Determine all vertices with zero in-degree - val zeroVerts = Stack() // Stack as good as any here - for (v in degree.keys) { - if (degree[v] == 0) zeroVerts.push(v) - } - // Determine the topological order - val result = ArrayList() - while (!zeroVerts.isEmpty()) { - val v = zeroVerts.pop() // Choose a vertex with zero in-degree - result.add(v) // Vertex v is next in topol order - // "Remove" vertex v by updating its neighbors - for (neighbor in neighbors[v]!!) { - degree[neighbor] = degree[neighbor]!! - 1 - // Remember any vertices that now have zero in-degree - if (degree[neighbor] == 0) zeroVerts.push(neighbor) - } - } - // Check that we have used the entire graph (if not, there was a cycle) - return if (result.size != neighbors.size) null else result - } - - - fun bfsDistance(start: V): Map<*, *> { - var distance: MutableMap = hashMapOf() - // Initially, all distance are infinity, except start node - for (v in neighbors.keys) - distance[v] = -1 - distance[start] = 0 - // Process nodes in queue order - val queue = LinkedList() - queue.offer(start) // Place start node in queue - while (!queue.isEmpty()) { - val v = queue.remove() - val vDist = distance[v]!! - // Update neighbors - for (neighbor in neighbors[v]!!) { - if (distance[neighbor] != null) continue // Ignore if already done - distance[neighbor] = vDist + 1 - queue.offer(neighbor) - } - } - return distance - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt deleted file mode 100644 index 128b7f576..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt +++ /dev/null @@ -1,35 +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.core - -import org.junit.Test -import kotlin.test.assertEquals -/** - * - * - * @author Brinda Santh - */ -class CustomFunctionsTest { - @Test - fun testFormat(): Unit { - val returnValue : String = format("This is {} for times {}", "test", 2) - assertEquals("This is test for times 2", returnValue, "Failed to format String") - - val returnValue1 : String = format("This is test for times 2") - assertEquals("This is test for times 2", returnValue1, "Failed to format empty args") - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt deleted file mode 100644 index 7a74ca476..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt +++ /dev/null @@ -1,70 +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.core.service - - -import org.apache.commons.io.FileUtils -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import java.io.File -import java.nio.charset.Charset -import kotlin.test.assertNotNull -/** - * - * - * @author Brinda Santh - */ -class BluePrintContextTest { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - lateinit var bluePrintContext: BluePrintContext - - @Before - fun setUp() { - - val basepath = "load/blueprints" - - bluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) - assertNotNull(bluePrintContext, "Failed to populate Blueprint context") - } - - @Test - fun testBluePrintContextFromContent() { - val fileName = "load/blueprints/baseconfiguration/Definitions/activation-blueprint.json" - val content : String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) - val bpContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprint(content) - assertNotNull(bpContext, "Failed to get blueprint content") - assertNotNull(bpContext.serviceTemplate, "Failed to get blueprint content's service template") - } - - @Test - fun testChainedProperty() { - val nodeType = bluePrintContext.nodeTypeChained("component-resource-assignment") - assertNotNull(nodeType, "Failed to get chained node type") - log.trace("Properties {}", JacksonUtils.getJson(nodeType, true)) - } - - -} diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt deleted file mode 100644 index 8e6d5efdf..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.core.service - -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils - -/** - * BluePrintEnhancerServiceTest - * @author Brinda Santh - * - */ - -class BluePrintEnhancerServiceTest { - val basePath = "load/model_type" - - @Test - fun testEnrichBlueprint() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) - val bluePrintEnhancerService: BluePrintEnhancerService = BluePrintEnhancerDefaultService(bluePrintEnhancerRepoFileService) - - val serviceTemplate = ServiceTemplateUtils.getServiceTemplate("load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json") - bluePrintEnhancerService.enhance(serviceTemplate) - - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt deleted file mode 100644 index 911a891a8..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt +++ /dev/null @@ -1,109 +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.core.service - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.data.ExpressionData -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -/** - * - * - * @author Brinda Santh - */ -class BluePrintExpressionServiceTest { - @Test - fun testInputExpression() { - val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_input\" : \"input-name\" }") - val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.inputExpression, " Failed to populate input expression data") - assertEquals("input-name", expressionData.inputExpression?.propertyName, "Failed to get propertyName from expression data") - } - - @Test - fun testPropertyExpression() { - val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"property-name\"] }") - val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.propertyExpression, " Failed to populate property expression data") - assertEquals("SELF", expressionData.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("property-name", expressionData.propertyExpression?.propertyName, " Failed to get expected propertyName") - - val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"\",\"property-name\", \"resource\", \"name\"] }") - val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1) - assertNotNull(expressionData1, " Failed to populate expression data") - assertEquals(expressionData1.isExpression, true, "Failed to identify as nested property expression") - assertNotNull(expressionData1.propertyExpression, " Failed to populate nested property expression data") - assertEquals("SELF", expressionData1.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("property-name", expressionData1.propertyExpression?.propertyName, " Failed to get expected propertyName") - assertEquals("resource/name",expressionData1.propertyExpression?.subPropertyName, " Failed to populate nested subPropertyName expression data") - } - - @Test - fun testAttributeExpression() { - val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"\",\"attribute-name\", \"resource\", \"name\"] }") - val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.attributeExpression, " Failed to populate attribute expression data") - assertEquals("SELF", expressionData.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("attribute-name", expressionData.attributeExpression?.attributeName, " Failed to get expected attributeName") - assertEquals("resource/name",expressionData.attributeExpression?.subAttributeName, " Failed to populate nested subAttributeName expression data") - } - - - @Test - fun testOutputOperationExpression() { - val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_operation_output\": [\"SELF\", \"interface-name\", \"operation-name\", \"output-property-name\"] }") - val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.operationOutputExpression, " Failed to populate output expression data") - assertEquals("SELF", expressionData.operationOutputExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("interface-name", expressionData.operationOutputExpression?.interfaceName, " Failed to get expected interfaceName") - assertEquals("operation-name", expressionData.operationOutputExpression?.operationName, " Failed to get expected operationName") - assertEquals("output-property-name", expressionData.operationOutputExpression?.propertyName, " Failed to get expected propertyName") - } - - - @Test - fun testArtifactExpression() { - val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\"] }") - val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.artifactExpression, " Failed to populate Artifact expression data") - assertEquals("SELF", expressionData.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("artifact-template", expressionData.artifactExpression?.artifactName, " Failed to get expected artifactName") - - - val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\", \"location\", true] }") - val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1) - assertNotNull(expressionData1, " Failed to populate expression data") - assertEquals(expressionData1.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData1.artifactExpression, " Failed to populate Artifact expression data") - assertEquals("SELF", expressionData1.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("artifact-template", expressionData1.artifactExpression?.artifactName, " Failed to get expected artifactName") - assertEquals("location", expressionData1.artifactExpression?.location, " Failed to get expected location") - assertEquals(true, expressionData1.artifactExpression?.remove, " Failed to get expected remove") - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserFactoryTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserFactoryTest.kt deleted file mode 100644 index 5a5557d75..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserFactoryTest.kt +++ /dev/null @@ -1,42 +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.core.service - -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import kotlin.test.assertNotNull - -/** - * - * - * @author Brinda Santh - */ -class BluePrintParserFactoryTest { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - @Test - fun testBluePrintJson() { - val basepath = "load/blueprints" - - val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) - assertNotNull(bluePrintContext, "Failed to populate Blueprint context") - log.trace("Blue Print {}",bluePrintContext.blueprintJson(true)) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt deleted file mode 100644 index 88aea919e..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.core.service - -import org.junit.Test -import java.io.FileNotFoundException -import kotlin.test.assertNotNull - -/** - * BluePrintRepoFileServiceTest - * @author Brinda Santh - * - */ -class BluePrintRepoFileServiceTest { - - private val basePath = "load/model_type" - private val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) - - @Test - fun testGetDataType() { - val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate")?.block() - assertNotNull(dataType, "Failed to get DataType from repo") - } - - @Test - fun testGetNodeType() { - val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment")?.block() - assertNotNull(nodeType, "Failed to get NodeType from repo") - } - - @Test - fun testGetArtifactType() { - val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")?.block() - assertNotNull(nodeType, "Failed to get ArtifactType from repo") - } - - @Test(expected = FileNotFoundException::class) - fun testModelNotFound() { - val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found")?.block() - assertNotNull(dataType, "Failed to get DataType from repo") - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt deleted file mode 100644 index 5d24b072f..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt +++ /dev/null @@ -1,131 +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.core.service - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.NullNode -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromFile -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromObject -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -/** - * - * - * @author Brinda Santh - */ -class BluePrintRuntimeServiceTest { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - val basepath = "load/blueprints" - - - @Before - fun setUp(): Unit { - - } - - @Test - fun testResolveNodeTemplateProperties() { - log.info("************************ testResolveNodeTemplateProperties **********************") - val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) - - val context: MutableMap = hashMapOf() - context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig") - val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context) - - val inputDataPath = "src/test/resources/data/default-context.json" - - val inputNode: JsonNode = jsonNodeFromFile(inputDataPath) - bluePrintRuntimeService.assignInputs(inputNode) - - val propContext: MutableMap = bluePrintRuntimeService.resolveNodeTemplateProperties("activate-process") - log.info("Context {}" ,bluePrintRuntimeService.context) - - assertNotNull(propContext, "Failed to populate interface property values") - assertEquals(propContext.get("process-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter process-name") - assertEquals(propContext.get("version"), jsonNodeFromObject("sample-action"), "Failed to populate parameter version") - } - - @Test - fun testResolveNodeTemplateInterfaceOperationInputs() { - log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************") - val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) - assertNotNull(bluePrintContext, "Failed to populate Blueprint context") - - val context: MutableMap = hashMapOf() - context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig") - - val inputDataPath = "src/test/resources/data/default-context.json" - BluePrintRuntimeUtils.assignInputsFromFile(bluePrintContext, inputDataPath, context) - - - val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context) - - log.info("Prepared Context {}" ,context) - - val inContext: MutableMap = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment", - "DefaultComponentNode", "process") - - log.trace("In Context {}" ,inContext) - - assertNotNull(inContext, "Failed to populate interface input property values") - assertEquals(inContext.get("action-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name") - assertEquals(inContext.get("request-id"), jsonNodeFromObject("12345"), "Failed to populate parameter action-name") - assertEquals(inContext.get("template-content"), jsonNodeFromObject("This is Sample Velocity Template"), "Failed to populate parameter action-name") - - } - - @Test - fun testResolveNodeTemplateInterfaceOperationOutputs() { - log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************") - val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) - assertNotNull(bluePrintContext, "Failed to populate Blueprint context") - - val context: MutableMap = hashMapOf() - context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig") - - val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context) - - val componentContext: MutableMap = hashMapOf() - val successValue : JsonNode= jsonNodeFromObject("Success") - componentContext["resource-assignment.DefaultComponentNode.process.status"] = successValue - componentContext["resource-assignment.DefaultComponentNode.process.resource-assignment-params"] = null - - bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment", - "DefaultComponentNode", "process", componentContext) - - assertEquals(NullNode.instance, - context.get("node_templates/resource-assignment/interfaces/DefaultComponentNode/operations/process/properties/resource-assignment-params"), - "Failed to get operation property resource-assignment-params") - - assertEquals(successValue, - context.get("node_templates/resource-assignment/interfaces/DefaultComponentNode/operations/process/properties/status"), - "Failed to get operation property status") - - - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt deleted file mode 100644 index b05fcb61b..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt +++ /dev/null @@ -1,49 +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.core.service - -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager - -/** - * - * - * @author Brinda Santh - */ -class BluePrintValidatorDefaultServiceTest { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - val basepath = "load/blueprints" - - @Before - fun setUp(): Unit { - - } - - @Test - fun testValidateBluePrint() { - val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!! - .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath) - val properties : MutableMap = hashMapOf() - val validatorService = BluePrintValidatorDefaultService() - validatorService.validateBlueprint(bluePrintContext.serviceTemplate,properties) - log.info("Validation Message {}", properties) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt deleted file mode 100644 index ddb39a2d6..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt +++ /dev/null @@ -1,40 +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.core.utils - - -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData -import kotlin.test.assertNotNull - -class BluePrintMetadataUtilsTest { - - @Test - fun testToscaMetaData(){ - - val basePath : String = "load/blueprints/baseconfiguration" - - val toscaMetaData : ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath) - assertNotNull(toscaMetaData, "Missing Tosca Definition Object") - assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version") - assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version") - assertNotNull(toscaMetaData.createdBy, "Missing Created by") - assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition") - assertNotNull(toscaMetaData.templateTags, "Missing Template Tags") - - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt deleted file mode 100644 index d13caa52c..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt +++ /dev/null @@ -1,51 +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.core.utils - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate -import java.io.FileNotFoundException -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -class JacksonReactorUtilsTest { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - @Test - fun testReadValues() { - - val serviceTemplate = JacksonReactorUtils.readValueFromFile("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json", - ServiceTemplate::class.java).block() - - assertNotNull(serviceTemplate, "Failed to simple transform Service Template") - assertEquals(true, serviceTemplate is ServiceTemplate, "failed to get Service Template instance") - - val jsonContent = JacksonReactorUtils.getJson(serviceTemplate!!, true).block() - assertNotNull(jsonContent, "Failed to get json content") - - val jsonNode = JacksonReactorUtils.jsonNodeFromFile("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json") - .block() - assertNotNull(jsonContent, "Failed to get json Node") - } - - @Test(expected = FileNotFoundException::class) - fun testReadValuesFailure() { - JacksonReactorUtils.jsonNodeFromFile("load/blueprints/not-found.json") - .block() - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt deleted file mode 100644 index a5a630e3c..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.core.utils - -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -import kotlin.test.assertTrue - -/** - * JacksonUtilsTest - * @author Brinda Santh - * ${DATA} - */ -class JacksonUtilsTest { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - val basePath = "load/blueprints" - - @Test - fun testReadValues() { - val content = ResourceResolverUtils.getFileContent("baseconfiguration/Definitions/activation-blueprint.json", basePath) - val serviceTemplate = JacksonUtils.readValue(content, ServiceTemplate::class.java) - assertNotNull(serviceTemplate, "Failed to simple transform Service Template") - assertEquals(true, serviceTemplate is ServiceTemplate, "failed to get Service Template instance") - - val jsonContent = JacksonUtils.getJson(serviceTemplate!!, true) - assertNotNull(jsonContent, "Failed to get json content") - } - - @Test - fun testJsonNodeFromClassPathFile() { - val filePath = "data/default-context.json" - JacksonUtils.jsonNodeFromClassPathFile(filePath) - } - - @Test - fun testJsonNodeFromFile() { - val filePath = basePath + "/baseconfiguration/Definitions/activation-blueprint.json" - JacksonUtils.jsonNodeFromFile(filePath) - } - - @Test - fun testGetListFromJson() { - val content = "[\"good\",\"boy\" ]" - val nodeType = JacksonUtils.getListFromJson(content, String::class.java) - assertNotNull(nodeType, "Failed to get String array from content") - } - - - @Test - fun testJsonValue() { - val filePath = "data/alltype-data.json" - val rootJson = JacksonUtils.jsonNodeFromClassPathFile(filePath) - assertNotNull(rootJson, "Failed to get all type data json node") - val intValue = rootJson.get("intValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value") - val floatValue = rootJson.get("floatValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value") - val stringValue = rootJson.get("stringValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value") - val booleanValue = rootJson.get("booleanValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value") - val arrayStringValue = rootJson.get("arrayStringValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value") - val mapValue = rootJson.get("mapValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value") - - assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed") - - - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt deleted file mode 100644 index 3fa4f75d9..000000000 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt +++ /dev/null @@ -1,36 +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.core.utils - -import org.junit.Test - -class TopologicalSortingUtilsTest { - - @Test - fun testSorting(): Unit { - val graph: TopologicalSortingUtils = TopologicalSortingUtils() - graph.add("bundle-id", "bundle-mac") - graph.add("bundle-id", "bundle-ip") - graph.add("bundle-mac", "bundle-ip") - graph.add("bundle-ip", "bundle-mac") - - println("The current graph: " + graph) - println("In-degrees: " + graph.inDegree()) - println("Out-degrees: " + graph.outDegree()) - println("A topological sort of the vertices: " + graph.topSort()) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/resources/componentnode/default.json b/ms/controllerblueprints/modules/core/src/test/resources/componentnode/default.json deleted file mode 100644 index b7265fcd1..000000000 --- a/ms/controllerblueprints/modules/core/src/test/resources/componentnode/default.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "metadata": { - "template_author": "bs2796", - "vendor": "Juniper", - "os": "XXX", - "service-type": "AVPN", - "vnf-type": "VRR", - "action": "Base Configuration", - "sub-action": "Generate Configuration", - "template_name": "VRR-baseconfiguration", - "template_version": "1.0.0" - }, - "topology_template": { - "inputs": { - "service-instance-id": { - "required": true, - "type": "string" - }, - "vnf-id": { - "required": true, - "type": "string" - }, - "service": { - "required": true, - "type": "string" - }, - "region": { - "required": true, - "type": "string" - }, - "bundle-id": { - "required": true, - "type": "string" - }, - "bundle-mac": { - "required": true, - "type": "string" - } - }, - "node_templates": { - "generate-configuration": { - "type": "mock-component-generateConfig", - "interfaces": { - "org-openecomp-sdnc-config-params-service-MockComponentNode": { - "operations": { - "process": { - "inputs": { - "entity-type": "vnf-type", - "template-content": "sample-template", - "entity-id": "{ \"get_input\" : \"vnf-id\" }" - }, - "outputs": { - "mergedData": "merged Data", - "status": "status" - } - } - } - } - } - } - } - }, - "node_types": { - "mock-component-generateConfig": { - "interfaces": { - "org-openecomp-sdnc-config-params-service-MockComponentNode": { - "operations": { - "process": { - "inputs": { - "entity-type": { - "required": false, - "type": "string" - }, - "template-content": { - "required": false, - "type": "string" - }, - "entity-id": { - "required": true, - "type": "string" - } - }, - "outputs": { - "generated-config": { - "required": true, - "type": "string" - }, - "status": { - "required": true, - "type": "string" - } - } - } - } - } - }, - "derived_from": "tosca.nodes.Component" - } - } -} diff --git a/ms/controllerblueprints/modules/core/src/test/resources/data/alltype-data.json b/ms/controllerblueprints/modules/core/src/test/resources/data/alltype-data.json deleted file mode 100644 index 055b09658..000000000 --- a/ms/controllerblueprints/modules/core/src/test/resources/data/alltype-data.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "intValue" : 1, - "floatValue" : 1.34, - "booleanValue" : true, - "stringValue" : "sample-String", - "timeValue" : "2018-09-29", - "arrayStringValue" : ["one", "two"], - "mapValue" : {"profile_name1":"profile_name1", - "profile_name2":"profile_name2"} -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/resources/data/default-context.json b/ms/controllerblueprints/modules/core/src/test/resources/data/default-context.json deleted file mode 100644 index fcd4cbe26..000000000 --- a/ms/controllerblueprints/modules/core/src/test/resources/data/default-context.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "request-id" : "12345", - "hostname" : "localhost", - "action-name" : "sample-action" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/resources/dictionary/dictionary_schema.json b/ms/controllerblueprints/modules/core/src/test/resources/dictionary/dictionary_schema.json deleted file mode 100644 index d03170050..000000000 --- a/ms/controllerblueprints/modules/core/src/test/resources/dictionary/dictionary_schema.json +++ /dev/null @@ -1,261 +0,0 @@ -{ - "type": "object", - "properties": { - "resource-path": { - "type": "string", - "required": true - }, - "description": { - "type": "string" - }, - "updated-by": { - "type": "string" - }, - "data-type": { - "type": "string", - "required": true - }, - "source": { - "type": "object", - "required": true, - "properties": { - "input": { - "type": "object", - "properties": { - "key": { - "type": "string" - } - } - }, - "component": { - "type": "object", - "properties": { - "name": { - "type": "string", - "required": true - }, - "input-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "output-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, - "default": { - "type": "any" - }, - "aai": { - "type": "any" - }, - "mdsal": { - "type": "object", - "properties": { - "path": { - "type": "string", - "required": true - }, - "url-path": { - "type": "string", - "required": true - }, - "input-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "type": { - "type": "string", - "required": true - }, - "output-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "base": { - "type": "string", - "required": true - } - } - }, - "network-resource-discovery": { - "type": "object", - "properties": { - "input-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "output-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, - "db": { - "type": "object", - "properties": { - "query": { - "type": "string", - "required": true - }, - "input-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "type": { - "type": "string", - "required": true - }, - "output-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "base": { - "type": "string", - "required": true - } - } - }, - "policy": { - "type": "object", - "properties": { - "input-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "output-key-mapping": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, - "candidate-dependency": { - "type": "object", - "properties": { - "input": { - "type": "object", - "properties": { - "names": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "component": { - "type": "object", - "properties": { - "names": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "aai": { - "type": "object", - "properties": { - "names": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "mdsal": { - "type": "object", - "properties": { - "names": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "network-resource-discovery": { - "type": "object", - "properties": { - "names": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "db": { - "type": "object", - "properties": { - "names": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "policy": { - "type": "object", - "properties": { - "names": { - "type": "array", - "items": { - "type": "string" - } - } - } - } - } - }, - "tags": { - "type": "string" - }, - "default": { - "type": "any" - }, - "name": { - "type": "string", - "required": true - }, - "valid-values": { - "type": "string" - }, - "resource-type": { - "type": "string", - "required": true - }, - "sample-value": { - "type": "string" - }, - "entry-schema": { - "type": "string" - } - } -} diff --git a/ms/controllerblueprints/modules/core/src/test/resources/properties/convert.json b/ms/controllerblueprints/modules/core/src/test/resources/properties/convert.json deleted file mode 100644 index cb7d08e44..000000000 --- a/ms/controllerblueprints/modules/core/src/test/resources/properties/convert.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "type": "sdnc-component-getResourceAssignment", - "interfaces": { - "ResourceAssignmentService": { - "operations": { - "getResourceAssignment": { - "inputs": { - "assignment-mappings": [ - { - "name": "service-name", - "mapping-field": "service", - "mapping-category": "SDN", - "required": true - }, - { - "name": "region-name", - "mapping-field": "region", - "mapping-category": "SDN", - "required": true - } - ], - "pre-data": "{ \"get_attribute\" : \"get-resource-assignment.config-params\" }", - "prifix": "get-resource-assignment" - }, - "outputs": { - "resource-assignment-status": "success", - "resource-assignment-params": "{ \"set_value\" : \"get-resource-assignment.config-params\" }" - } - } - } - } - } -} diff --git a/ms/controllerblueprints/modules/core/src/test/resources/properties/default.json b/ms/controllerblueprints/modules/core/src/test/resources/properties/default.json deleted file mode 100644 index 0ac97f907..000000000 --- a/ms/controllerblueprints/modules/core/src/test/resources/properties/default.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "default": "{ \"get_input\" : \"loopback-default\" }", - "domain": "ethernet", - "criteria": [ - { - "value": "attga301me1", - "type": "complex", - "nodeString": "layer3-service-list[].service-data.l3sdn-vnf-fields.vnf-name" - }, - { - "value": "{ \"get_input\" : \"host-ip-address\" }", - "type": "simple", - "nodeString": "layer3-service-list[].service-data.l3sdn-vnf-fields.vnf-name" - } - ] -} diff --git a/ms/controllerblueprints/modules/pom.xml b/ms/controllerblueprints/modules/pom.xml index 5ab4e4477..887d02331 100644 --- a/ms/controllerblueprints/modules/pom.xml +++ b/ms/controllerblueprints/modules/pom.xml @@ -31,8 +31,6 @@ pom - core - resource-dict service diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json deleted file mode 100644 index 95a9801dc..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "description": "This is Custom Java Component Resource Source Node Type", - "version": "1.0.0", - "properties": { - "type": { - "required": false, - "type": "string", - "default" : "DYNAMIC", - "constraints": [ - { - "validValues": [ - "DYNAMIC" - ] - } - ] - }, - "class-name": { - "required": true, - "type": "string", - "description" : "Fully Qualified Class Name ( + . + )" - }, - "key-dependencies": { - "required": false, - "type": "list", - "entry_schema": { - "type": "string" - } - } - }, - "derived_from": "tosca.nodes.ResourceSource" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json deleted file mode 100644 index 661a9503b..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "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/resource-dict/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json deleted file mode 100644 index 13e234e1b..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "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/resource-dict/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json deleted file mode 100644 index 126ea30bd..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "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/resource-dict/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json deleted file mode 100644 index f8dd8b6fc..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "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/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json deleted file mode 100644 index 2ef553e24..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "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/resource-dict/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json deleted file mode 100644 index 92b16a212..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "db-source", - "property" :{ - "description": "name of the ", - "type": "string" - }, - "resource-type": "ONAP", - "resource-path": "vnf/bundle-id", - "updated-by": "brindasanth@onap.com", - "tags": "bundle-id, brindasanth@onap.com", - "sources": { - "db": { - "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" - } - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json deleted file mode 100644 index 1c47f37b2..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", - "name": "default-source", - "property" :{ - "description": "name of the ", - "type": "string" - }, - "updated-by": "brindasanth@onap.com", - "resource-type": "ONAP", - "resource-path": "vnf/v4-ip-type", - "sources": { - "default": { - "type": "source-default", - "properties": { - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json deleted file mode 100644 index 676d92f86..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "input-source", - "property" :{ - "description": "name of the ", - "type": "string" - }, - "resource-path": "action-name", - "resource-type": "ONAP", - "updated-by": "brindasanth@onap.com", - "tags": null, - "sources": { - "input": { - "type": "source-input", - "properties": { - "key": "action-name" - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json deleted file mode 100644 index b49146a0e..000000000 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "tags": "oam-local-ipv4-address", - "name": "mdsal-source", - "property" :{ - "description": "based on service-instance-id,network-role,v4-ip-type and vm-type get the ipv4-gateway-prefix from the SDN-GC mdsal", - "type": "string" - }, - "updated-by": "brindasanth@onap.com", - "resource-type": "ATT", - "resource-path": "vnf/oam-local-ipv4-address", - "sources": { - "mdsal": { - "type": "source-rest", - "properties": { - "type": "JSON", - "url-path": "config/L3VNF-API:services/service-list/$service-instance-id/service-data/vnf-topology-information/vnf-assignments/vnf-vms/$vm-type/vm-networks/$network-role/v4-assigned-ip-list/$v4-ip-type", - "path": "/v4-assigned-ip-list/0/v4-ip-prefix", - "input-key-mapping": { - "service-instance-id": "service-instance-id", - "network-role": "network-role", - "v4-ip-type": "v4-ip-type", - "vm-type": "vm-type" - }, - "output-key-mapping": { - "oam-local-ipv4-address": "v4-ip-prefix" - }, - "key-dependencies": [ - "service-instance-id", - "network-role", - "v4-ip-type", - "vm-type" - ] - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/pom.xml b/ms/controllerblueprints/modules/resource-dict/pom.xml deleted file mode 100644 index dbc920fdf..000000000 --- a/ms/controllerblueprints/modules/resource-dict/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - 4.0.0 - - org.onap.ccsdk.apps.controllerblueprints - modules - 0.3.0-SNAPSHOT - - resource-dict - Controller Blueprints Resource Dictionary - - - - org.onap.ccsdk.apps.controllerblueprints - core - - - org.jetbrains.kotlin - kotlin-test - test - - - - - - diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt deleted file mode 100644 index a6802f677..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignmentProcessor.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.resource.dict - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException - -interface ResourceAssignmentProcessor { - - @Throws(BluePrintProcessorException::class) - fun validate(resourceAssignment: ResourceAssignment, context : MutableMap) - - @Throws(BluePrintProcessorException::class) - fun process(resourceAssignment: ResourceAssignment, context : MutableMap) - - @Throws(BluePrintProcessorException::class) - fun errorHandle(resourceAssignment: ResourceAssignment, context : MutableMap) - - @Throws(BluePrintProcessorException::class) - fun reTrigger(resourceAssignment: ResourceAssignment, context : MutableMap) -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt deleted file mode 100644 index 0808073f8..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.resource.dict - -import com.fasterxml.jackson.annotation.JsonFormat -import com.fasterxml.jackson.annotation.JsonProperty -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import java.io.Serializable -import java.util.* - -open class ResourceDefinition { - - @JsonProperty(value = "name", required = true) - lateinit var name: String - - @JsonProperty(value = "property", required = true) - lateinit var property: PropertyDefinition - - var tags: String? = null - - @JsonProperty(value = "updated-by") - lateinit var updatedBy: String - - @JsonProperty(value = "resource-type", required = true) - lateinit var resourceType: String - - @JsonProperty(value = "resource-path", required = true) - lateinit var resourcePath: String - - @JsonProperty(value = "sources", required = true) - lateinit var sources: MutableMap -} - -open class ResourceAssignment { - - @JsonProperty(value = "name", required = true) - lateinit var name: String - - @JsonProperty(value = "property") - var property: PropertyDefinition? = null - - @JsonProperty("input-param") - var inputParameter: Boolean = false - - @JsonProperty("dictionary-name") - var dictionaryName: String? = null - - @JsonProperty("dictionary-source") - var dictionarySource: String? = null - - @JsonProperty("dependencies") - var dependencies: MutableList? = null - - @JsonProperty("version") - var version: Int = 0 - - @JsonProperty("status") - var status: String? = null - - @JsonProperty("message") - var message: String? = null - - @JsonProperty("updated-date") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - var updatedDate: Date? = null - - @JsonProperty("updated-by") - var updatedBy: String? = null - - override fun toString(): String { - return StringBuilder() - .append("[") - .append("name=", name) - .append(", dictionaryName=", dictionaryName) - .append(", dictionarySource=", dictionarySource) - .append("]") - .toString() - } -} - -/** - * Interface for Source Definitions (ex Input Source, - * Default Source, Database Source, Rest Sources, etc) - */ -interface ResourceSource : Serializable diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt deleted file mode 100644 index aa6a9fb65..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.resource.dict -/** - * ResourceDictionaryConstants - * - * @author Brinda Santh - */ -object ResourceDictionaryConstants { - const val SOURCE_INPUT = "input" - const val SOURCE_DEFAULT = "default" - const val SOURCE_DB = "db" - - const val MODEL_DIR_RESOURCE_DEFINITION: String = "resource_dictionary" - - const val PROPERTY_TYPE = "type" - const val PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping" - const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping" - const val PROPERTY_KEY_DEPENDENCIES = "key-dependencies" -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt deleted file mode 100644 index c5a78a9c9..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt +++ /dev/null @@ -1,86 +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.resource.dict.service - -import com.att.eelf.configuration.EELFLogger -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import com.att.eelf.configuration.EELFManager - -/** - * ResourceAssignmentEnhancerService. - * - * @author Brinda Santh - */ -interface ResourceAssignmentEnhancerService { - - @Throws(BluePrintException::class) - fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, - resourceAssignments: List) - - @Throws(BluePrintException::class) - fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate -} - -/** - * ResourceAssignmentEnhancerDefaultService. - * - * @author Brinda Santh - */ -open class ResourceAssignmentEnhancerDefaultService(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) - : ResourceAssignmentEnhancerService { - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java) - - /** - * Get the defined source instance from the ResourceAssignment, - * then get the NodeType of the Sources assigned - */ - override fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, - resourceAssignments: List) { - - // Iterate the Resource Assignment and - resourceAssignments.map { resourceAssignment -> - val dictionaryName = resourceAssignment.dictionaryName!! - val dictionarySource = resourceAssignment.dictionarySource!! - log.info("Enriching Assignment name({}), dictionary name({}), source({})", resourceAssignment.name, - dictionaryName, dictionarySource) - // Get the Resource Definition from Repo - val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) - - val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource) - - // Enrich as NodeTemplate - bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate!!) - } - } - - override fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate { - val bluePrintEnhancerService = BluePrintEnhancerDefaultService(resourceDefinitionRepoService) - bluePrintEnhancerService.serviceTemplate = ServiceTemplate() - bluePrintEnhancerService.initialCleanUp() - enhanceBluePrint(bluePrintEnhancerService, resourceAssignments) - return bluePrintEnhancerService.serviceTemplate - } - - private fun getResourceDefinition(name: String): ResourceDefinition { - return resourceDefinitionRepoService.getResourceDefinition(name)!!.block()!! - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt deleted file mode 100644 index 228b39e29..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt +++ /dev/null @@ -1,151 +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.resource.dict.service - -import com.att.eelf.configuration.EELFLogger -import org.apache.commons.collections.CollectionUtils -import org.apache.commons.lang3.StringUtils -import org.apache.commons.lang3.text.StrBuilder -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import com.att.eelf.configuration.EELFManager -import java.io.Serializable - -/** - * ResourceAssignmentValidationService. - * - * @author Brinda Santh - */ -interface ResourceAssignmentValidationService : Serializable { - - @Throws(BluePrintException::class) - fun validate(resourceAssignments: List): Boolean -} - -/** - * ResourceAssignmentValidationDefaultService. - * - * @author Brinda Santh - */ -open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValidationService { - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java) - - open var resourceAssignmentMap: Map = hashMapOf() - open val validationMessage = StrBuilder() - - override fun validate(resourceAssignments: List): Boolean { - try { - validateSources(resourceAssignments) - validateTemplateNDictionaryKeys(resourceAssignments) - validateCyclicDependency(resourceAssignments) - if (StringUtils.isNotBlank(validationMessage)) { - throw BluePrintException("Resource Assignment Validation Failure") - } - } catch (e: Exception) { - throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString(), e) - } - return true - } - - open fun validateSources(resourceAssignments: List) { - log.info("validating resource assignment sources") - } - - open fun validateTemplateNDictionaryKeys(resourceAssignments: List) { - - resourceAssignmentMap = resourceAssignments.map { it.name to it }.toMap() - - val duplicateKeyNames = resourceAssignments.groupBy { it.name } - .filter { it.value.size > 1 } - .map { it.key } - - if (duplicateKeyNames.isNotEmpty()) { - validationMessage.appendln(String.format("Duplicate Assignment Template Keys (%s) is Present", duplicateKeyNames)) - } - - val duplicateDictionaryKeyNames = resourceAssignments.groupBy { it.dictionaryName } - .filter { it.value.size > 1 } - .map { it.key } - if (duplicateDictionaryKeyNames.isNotEmpty()) { - validationMessage.appendln(String.format("Duplicate Assignment Dictionary Keys (%s) is Present", duplicateDictionaryKeyNames)) - } - - val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten() - - log.info("Resource assignment definitions : {}", resourceAssignmentMap.keys) - log.info("Resource assignment Dictionary dependencies : {}", dependenciesNames) - - val notPresentDictionaries = dependenciesNames.filter { !resourceAssignmentMap.containsKey(it) }.distinct() - if (notPresentDictionaries.isNotEmpty()) { - validationMessage.appendln(String.format("No assignments for Dictionary Keys (%s)", notPresentDictionaries)) - } - - if (StringUtils.isNotBlank(validationMessage)) { - throw BluePrintException("Resource Assignment Validation Failure") - } - } - - open fun validateCyclicDependency(resourceAssignments: List) { - val startResourceAssignment = ResourceAssignment() - startResourceAssignment.name = "*" - - val topologySorting = TopologicalSortingUtils() - - resourceAssignmentMap.map { it.value }.map { resourceAssignment -> - if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { - resourceAssignment.dependencies!!.map { - log.info("Topological Graph link from {} to {}", it, resourceAssignment.name) - topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment) - } - } else { - topologySorting.add(startResourceAssignment, resourceAssignment) - } - } - - if (!topologySorting.isDag) { - val graph = getTopologicalGraph(topologySorting) - validationMessage.appendln("Cyclic Dependency :$graph") - } - } - - open fun getTopologicalGraph(topologySorting: TopologicalSortingUtils): String { - val s = StringBuilder() - val neighbors = topologySorting.getNeighbors() - - neighbors.forEach { v, vs -> - if (v.name == "*") { - s.append("\n * -> [") - for (resourceAssignment in vs) { - s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name - + "),") - } - s.append("]") - } else { - s.append("\n (" + v.dictionaryName + ":" + v.name + ") -> [") - for (resourceAssignment in vs) { - s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name - + "),") - } - s.append("]") - } - } - return s.toString() - } - - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt deleted file mode 100644 index d51338caf..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoService.kt +++ /dev/null @@ -1,61 +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.resource.dict.service - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import reactor.core.publisher.Mono -/** - * ResourceDefinitionRepoService. - * - * @author Brinda Santh - */ -interface ResourceDefinitionRepoService : BluePrintRepoService { - - fun getResourceDefinition(resourceDefinitionName: String): Mono? -} - -/** - * ResourceDefinitionFileRepoService. - * - * @author Brinda Santh - */ -open class ResourceDefinitionFileRepoService : BluePrintRepoFileService, - ResourceDefinitionRepoService { - - private var resourceDefinitionPath: String - private val extension = ".json" - - constructor(basePath: String) : this(basePath, - basePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(BluePrintConstants.MODEL_DIR_MODEL_TYPE)) - - constructor(basePath: String, modelTypePath: String) : super(modelTypePath) { - resourceDefinitionPath = basePath.plus("/resource_dictionary") - } - - override fun getResourceDefinition(resourceDefinitionName: String): Mono? { - - val fileName = resourceDefinitionPath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(resourceDefinitionName).plus(extension) - - return JacksonReactorUtils.readValueFromFile(fileName, ResourceDefinition::class.java) - } -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt deleted file mode 100644 index 14855d4b6..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications 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.resource.dict.service - -import com.att.eelf.configuration.EELFLogger -import com.fasterxml.jackson.databind.JsonNode -import com.google.common.base.Preconditions -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.format -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService -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.ResourceDefinition -import com.att.eelf.configuration.EELFManager -import java.io.Serializable -/** - * ResourceDefinitionValidationService. - * - * @author Brinda Santh - */ -interface ResourceDefinitionValidationService : Serializable { - - @Throws(BluePrintException::class) - fun validate(resourceDefinition: ResourceDefinition) - -} -/** - * ResourceDefinitionValidationService. - * - * @author Brinda Santh - */ -open class ResourceDefinitionDefaultValidationService(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidationService::class.java) - - override fun validate(resourceDefinition: ResourceDefinition) { - Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") - log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name) - - resourceDefinition.sources.forEach { (name, nodeTemplate) -> - val sourceType = nodeTemplate.type - - val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block() - ?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, sourceType)) - - // Validate Property Name, expression, values and Data Type - validateNodeTemplateProperties(nodeTemplate, sourceNodeType) - } - } - - - open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) { - nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } - } - - - open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, - properties: MutableMap) { - properties.forEach { propertyName, propertyAssignment -> - val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] - ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) - // Check and Validate if Expression Node - val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) - if (!expressionData.isExpression) { - checkPropertyValue(propertyDefinition, propertyName, propertyAssignment) - } else { - throw BluePrintException(format("property({}) of expression ({}) is not supported", - propertyName, propertyAssignment)) - } - } - } - - open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) { - val propertyType = propertyDefinition.type - val isValid : Boolean - - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) - - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - - isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) - } else { - bluePrintRepoService.getDataType(propertyType) - ?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository", - propertyName, propertyType)) - isValid = true - } - - check(isValid) { - throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})", - propertyName, propertyType, propertyAssignment)) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt deleted file mode 100644 index 747639c89..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt +++ /dev/null @@ -1,109 +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.resource.dict.utils - -import com.att.eelf.configuration.EELFLogger -import org.apache.commons.collections.CollectionUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import com.att.eelf.configuration.EELFManager -import java.util.ArrayList -/** - * BulkResourceSequencingUtils. - * - * @author Brinda Santh - */ -object BulkResourceSequencingUtils { - private val log: EELFLogger = EELFManager.getInstance().getLogger(BulkResourceSequencingUtils::class.java) - - @JvmStatic - fun process(resourceAssignments: MutableList): List> { - val resourceAssignmentMap: MutableMap = hashMapOf() - val sequenceBatchResourceAssignment = ArrayList>() - log.info("Assignments ({})", resourceAssignments) - // Prepare Map - resourceAssignments.forEach { resourceAssignment -> - log.trace("Processing Key ({})", resourceAssignment.name) - resourceAssignmentMap.put(resourceAssignment.name, resourceAssignment) - } - - val startResourceAssignment = ResourceAssignment() - startResourceAssignment.name = "*" - - // Preepare Sorting Map - val topologySorting = TopologicalSortingUtils() - resourceAssignmentMap.forEach { _, resourceAssignment -> - if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { - for (dependency in resourceAssignment.dependencies!!) { - topologySorting.add(resourceAssignmentMap[dependency]!!, resourceAssignment) - } - } else { - topologySorting.add(startResourceAssignment, resourceAssignment) - } - } - - val sequencedResourceAssignments: MutableList = topologySorting.topSort()!! as MutableList - log.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments) - - var batchResourceAssignment: MutableList? = null - var batchAssignmentName: MutableList? = null - - // Prepare Sorting - sequencedResourceAssignments.forEachIndexed { index, resourceAssignment -> - - var previousResourceAssignment: ResourceAssignment? = null - - if (index > 0) { - previousResourceAssignment = sequencedResourceAssignments[index - 1] - } - - var dependencyPresence = false - if (batchAssignmentName != null && resourceAssignment.dependencies != null) { - dependencyPresence = CollectionUtils.containsAny(batchAssignmentName, resourceAssignment.dependencies) - } - - log.trace("({}) -> Checking ({}), with ({}), result ({})", resourceAssignment.name, - batchAssignmentName, resourceAssignment.dependencies, dependencyPresence) - - if (previousResourceAssignment != null && resourceAssignment.dictionarySource != null - && resourceAssignment.dictionarySource!!.equals(previousResourceAssignment.dictionarySource, true) - && !dependencyPresence) { - batchResourceAssignment!!.add(resourceAssignment) - batchAssignmentName!!.add(resourceAssignment.name) - } else { - if (batchResourceAssignment != null) { - sequenceBatchResourceAssignment.add(batchResourceAssignment!!) - log.trace("Created old Set ({})", batchAssignmentName) - } - batchResourceAssignment = arrayListOf() - batchResourceAssignment!!.add(resourceAssignment) - - batchAssignmentName = arrayListOf() - batchAssignmentName!!.add(resourceAssignment.name) - } - - if (index == sequencedResourceAssignments.size - 1) { - log.trace("Created old Set ({})", batchAssignmentName) - sequenceBatchResourceAssignment.add(batchResourceAssignment!!) - } - } - log.info("Batched Sequence : ({})", sequenceBatchResourceAssignment) - - return sequenceBatchResourceAssignment - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt deleted file mode 100644 index a3456cd43..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.resource.dict.utils - -import com.att.eelf.configuration.EELFLogger -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.NullNode -import org.apache.commons.collections.MapUtils -import org.apache.commons.lang3.StringUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants -import com.att.eelf.configuration.EELFManager - - -object ResourceDictionaryUtils { - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDictionaryUtils::class.java) - - @JvmStatic - fun populateSourceMapping(resourceAssignment: ResourceAssignment, - resourceDefinition: ResourceDefinition) { - - if (StringUtils.isBlank(resourceAssignment.dictionarySource)) { - - if (MapUtils.isNotEmpty(resourceDefinition.sources)) { - val source = findFirstSource(resourceDefinition.sources) - - // Populate and Assign First Source - if (StringUtils.isNotBlank(source)) { - // Set Dictionary Source - resourceAssignment.dictionarySource = source - } else { - resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT - } - log.info("auto map resourceAssignment : {}", resourceAssignment) - }else { - resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT - } - } - } - - @JvmStatic - fun findFirstSource(sources: Map): String? { - var source: String? = null - if (MapUtils.isNotEmpty(sources)) { - source = sources.keys.stream().findFirst().get() - } - return source - } - - @JvmStatic - fun assignInputs(data: JsonNode, context: MutableMap) { - log.trace("assignInputs from input JSON ({})", data.toString()) - data.fields().forEach { field -> - val valueNode: JsonNode = data.at("/".plus(field.key)) ?: NullNode.getInstance() - - val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(field.key) - log.trace("setting path ({}), values ({})", path, valueNode) - context[path] = valueNode - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java deleted file mode 100644 index fde800057..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.resource.dict; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ResourceDefinitionTest { - private EELFLogger log = EELFManager.getInstance().getLogger(ResourceDefinitionTest.class); - private String basePath = "load/resource_dictionary"; - - @Test - public void testDictionaryDefinitionInputSource(){ - - String fileName = basePath + "/input-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionDefaultSource(){ - - String fileName = basePath + "/default-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionDBSource(){ - - String fileName = basePath + "/db-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionMDSALSource(){ - String fileName = basePath + "/mdsal-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", resourceDefinition); - } -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java deleted file mode 100644 index 57c8509d1..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java +++ /dev/null @@ -1,48 +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.resource.dict.service; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; - -import java.util.List; - -/** - * ResourceAssignmentEnhancerService. - * - * @author Brinda Santh - */ -public class ResourceAssignmentEnhancerServiceTest { - - @Test - public void testEnhanceBluePrint() throws BluePrintException { - - List resourceAssignments = JacksonReactorUtils - .getListFromClassPathFile("enrich/simple-enrich.json", ResourceAssignment.class).block(); - Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments); - ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load"); - ResourceAssignmentEnhancerService resourceAssignmentEnhancerService = - new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService); - ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments); - Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate); - } -} - diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt deleted file mode 100644 index 6216d5bf0..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt +++ /dev/null @@ -1,57 +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.resource.dict.service - -import com.att.eelf.configuration.EELFLogger -import org.junit.Assert -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import com.att.eelf.configuration.EELFManager -/** - * ResourceAssignmentValidationServiceTest. - * - * @author Brinda Santh - */ -class ResourceAssignmentValidationServiceTest { - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java) - @Test - fun testValidateSuccess() { - log.info("**************** testValidateSuccess *****************") - val assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment::class.java) - val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() - val result = resourceAssignmentValidator.validate(assignments!!) - Assert.assertTrue("Failed to Validate", result) - } - - @Test(expected = BluePrintException::class) - fun testValidateDuplicate() { - log.info(" **************** testValidateDuplicate *****************") - val assignments = JacksonUtils.getListFromClassPathFile("validation/duplicate.json", ResourceAssignment::class.java) - val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() - resourceAssignmentValidator.validate(assignments!!) - } - - @Test(expected = BluePrintException::class) - fun testValidateCyclic() { - log.info(" **************** testValidateCyclic *****************") - val assignments = JacksonUtils.getListFromClassPathFile("validation/cyclic.json", ResourceAssignment::class.java) - val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() - resourceAssignmentValidator.validate(assignments!!) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java deleted file mode 100644 index 1772277df..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionRepoServiceTest.java +++ /dev/null @@ -1,36 +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.resource.dict.service; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; - -public class ResourceDefinitionRepoServiceTest { - - @Test - public void testGetResourceDefinition() throws Exception{ - ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load"); - ResourceDefinition resourceDefinition = resourceDefinitionRepoService - .getResourceDefinition("db-source").block(); - Assert.assertNotNull("Failed to get Resource Definition db-source", resourceDefinition); - - NodeType nodeType = resourceDefinitionRepoService.getNodeType("source-db").block(); - Assert.assertNotNull("Failed to get Node Type source-db", resourceDefinition); - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java deleted file mode 100644 index ef305627f..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.resource.dict.service; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; - -public class ResourceDefinitionValidationServiceTest { - private String basePath = "load/model_type"; - private String dictionaryPath = "load/resource_dictionary"; - private BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); - - @Test - public void testValidateSource() throws Exception { - - String inputFileName = dictionaryPath + "/db-source.json"; - testValidate(inputFileName); - - String dbFileName = dictionaryPath + "/db-source.json"; - testValidate(dbFileName); - - String defaultFileName = dictionaryPath + "/default-source.json"; - testValidate(defaultFileName); - - String restFileName = dictionaryPath + "/mdsal-source.json"; - testValidate(restFileName); - } - - private void testValidate(String fileName) throws Exception { - - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); - - ResourceDefinitionValidationService resourceDictionaryValidationService = - new ResourceDefinitionDefaultValidationService(bluePrintRepoFileService); - resourceDictionaryValidationService.validate(resourceDefinition); - Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); - } -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java deleted file mode 100644 index c7444dbae..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java +++ /dev/null @@ -1,37 +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.resource.dict.utils; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import java.util.List; -/** - * BulkResourceSequencingUtils. - * - * @author Brinda Santh - */ -public class BulkResourceSequencingUtilsTest { - - @Test - public void testProcess(){ - List assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment.class); - Assert.assertNotNull("failed to get ResourceAssignment from validation/success.json ", assignments); - BulkResourceSequencingUtils.process(assignments); - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java deleted file mode 100644 index 13bf8195e..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.resource.dict.utils; - - -import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; -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.ResourceDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.util.HashMap; -import java.util.Map; -/** - * ResourceDictionaryUtilsTest. - * - * @author Brinda Santh - */ -public class ResourceDictionaryUtilsTest { - private static final EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); - - @Test - public void testPopulateSourceMapping() { - - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("sample-assignment"); - ResourceDefinition resourceDefinition = new ResourceDefinition(); - Map sources = new HashMap<>(); - resourceDefinition.setSources(sources); - // To Check Empty Source - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource()); - - // To Check First Source - resourceAssignment.setDictionarySource(null); - sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate()); - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource()); - - // To Check Assigned Source - resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_DB); - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_DB, resourceAssignment.getDictionarySource()); - - } - - @Test - public void testFindFirstSource() { - //To check if Empty Source - Map sources = new HashMap<>(); - String firstSource = ResourceDictionaryUtils.findFirstSource(sources); - Assert.assertNull("Source populated, which is not expected.", firstSource); - - // TO check the first Source - sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate()); - String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources); - Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource); - - // TO check the multiple Source - sources.put(ResourceDictionaryConstants.SOURCE_DB, new NodeTemplate()); - String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources); - Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource); - - } - - @Test - public void testAssignInputs() { - JsonNode data = JacksonUtils.jsonNodeFromClassPathFile("data/resource-assignment-input.json"); - Map context = new HashMap<>(); - ResourceDictionaryUtils.assignInputs(data, context); - String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue"); - log.info("populated context {}", context); - Assert.assertTrue(String.format("failed to get variable : %s",path),context.containsKey(path)); - - } - - -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json deleted file mode 100644 index d79c90682..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "intValue" : 1, - "floatValue" : 1.34, - "booleanValue" : true, - "stringValue" : "sample-String", - "timeValue" : "2018-09-29", - "arrayStringValue" : ["one", "two"], - "mapValue" : {"profile_name1":"profile_name1", - "profile_name2":"profile_name2"} -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/enrich/simple-enrich.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/enrich/simple-enrich.json deleted file mode 100644 index 641da80a2..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/resources/enrich/simple-enrich.json +++ /dev/null @@ -1,37 +0,0 @@ -[ - { - "name": "rs-db-source", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "db-source", - "dictionary-source": "db", - "dependencies": [ - "input-source" - ] - }, - { - "name": "ra-default-source", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "default-source", - "dictionary-source": "default", - "dependencies": [] - }, - { - "name": "ra-input-source", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "input-source", - "dictionary-source": "input", - "dependencies": [] - } -] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json deleted file mode 100644 index d837dc5d8..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json +++ /dev/null @@ -1,111 +0,0 @@ -[ - { - "name": "vnf-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "vnf-id", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "service-instance-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "service-instance-id", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "bundle-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "bundle-id", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id" - ] - }, - { - "name": "bundle-ip", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "bundle-ip", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id" - ] - }, - { - "name": "bundle-mac", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "bundle-mac", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id", - "bundle-id" - ] - }, - { - "name": "managed-ip", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "managed-ip", - "dictionary-source": "mdsal", - "dependencies": [ - "loopback-ip" - ] - }, - { - "name": "vnf-name", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "vnf-name", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "managed-ip1", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "managed-ip1", - "dictionary-source": "mdsal", - "dependencies": [ - "loopback-ip" - ] - }, - { - "name": "loopback-ip", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "loopback-ip", - "dictionary-source": "db", - "dependencies": [ - "bundle-mac", - "managed-ip1" - ] - } -] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json deleted file mode 100644 index 330324cda..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json +++ /dev/null @@ -1,110 +0,0 @@ -[ - { - "name": "vnf-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "vnf-id", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "service-instance-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "service-instance-id", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "bundle-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "bundle-id", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id" - ] - }, - { - "name": "bundle-ip", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "bundle-ip", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id" - ] - }, - { - "name": "bundle-mac", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "bundle-mac", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id", - "bundle-id" - ] - }, - { - "name": "bundle-mac", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "bundle-mac", - "dictionary-source": "mdsal", - "dependencies": [ - "loopback-ip" - ] - }, - { - "name": "vnf-name", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "vnf-name", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "managed-ip1", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "managed-ip1", - "dictionary-source": "mdsal", - "dependencies": [ - "loopback-ip" - ] - }, - { - "name": "loopback-ip", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "loopback-ip", - "dictionary-source": "db", - "dependencies": [ - "bundle-mac" - ] - } -] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json deleted file mode 100644 index 3215d06d7..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json +++ /dev/null @@ -1,110 +0,0 @@ -[ - { - "name": "vnf-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "vnf-id", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "service-instance-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "service-instance-id", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "bundle-id", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "bundle-id", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id" - ] - }, - { - "name": "bundle-ip", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "bundle-ip", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id" - ] - }, - { - "name": "bundle-mac", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "bundle-mac", - "dictionary-source": "mdsal", - "dependencies": [ - "vnf-id", - "bundle-id" - ] - }, - { - "name": "managed-ip", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "managed-ip", - "dictionary-source": "mdsal", - "dependencies": [ - "loopback-ip" - ] - }, - { - "name": "vnf-name", - "input-param": true, - "property": { - "type": "string", - "required": true - }, - "dictionary-name": "vnf-name", - "dictionary-source": "input", - "dependencies": [] - }, - { - "name": "managed-ip1", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "managed-ip1", - "dictionary-source": "mdsal", - "dependencies": [ - "loopback-ip" - ] - }, - { - "name": "loopback-ip", - "input-param": true, - "property": { - "type": "string" - }, - "dictionary-name": "loopback-ip", - "dictionary-source": "db", - "dependencies": [ - "bundle-mac" - ] - } -] -- cgit 1.2.3-korg From 03fde837e1eb307cc0a17dda5161f1215c6159ad Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Thu, 7 Feb 2019 14:51:50 -0500 Subject: Refactor components core and resource dict modules Change-Id: I04e9e723d68a38ecefe48206e67fddbe43c55854 Issue-ID: CCSDK-1047 Signed-off-by: Muthuramalingam, Brinda Santh --- .../artifact_type/artifact-bpmn-camunda.json | 8 + .../artifact_type/artifact-directed-graph.json | 9 + .../artifact_type/artifact-mapping-resource.json | 8 + .../artifact_type/artifact-script-python.json | 8 + .../artifact_type/artifact-template-velocity.json | 8 + .../tosca.artifacts.Implementation.json | 5 + .../model_type/data_type/datatype-property.json | 27 + .../data_type/datatype-resource-assignment.json | 46 ++ .../load/model_type/data_type/dt-license-key.json | 11 + .../load/model_type/data_type/dt-v4-aggregate.json | 15 + .../data_type/tosca.datatypes.Credential.json | 31 + .../node_type/artifact-config-template.json | 37 ++ .../node_type/component-config-generator.json | 72 +++ .../node_type/component-netconf-executor.json | 79 +++ .../node_type/component-resource-assignment.json | 68 +++ .../model_type/node_type/dg-activate-netconf.json | 52 ++ .../model_type/node_type/dg-config-generator.json | 51 ++ .../node_type/dg-resource-assign-activate.json | 56 ++ .../node_type/dg-resource-assignment.json | 51 ++ .../model_type/node_type/tosca.nodes.Artifact.json | 5 + .../node_type/tosca.nodes.Component.json | 5 + .../load/model_type/node_type/tosca.nodes.DG.json | 5 + .../load/model_type/node_type/tosca.nodes.Vnf.json | 5 + .../node_type/tosca.nodes.component.Python.json | 5 + .../model_type/node_type/vnf-netconf-device.json | 42 ++ .../modules/blueprint-core/pom.xml | 76 +++ .../core/BluePrintConstants.kt | 176 ++++++ .../controllerblueprints/core/BluePrintError.kt | 29 + .../core/BluePrintException.kt | 49 ++ .../core/BluePrintProcessorException.kt | 50 ++ .../controllerblueprints/core/BluePrintTypes.kt | 164 ++++++ .../core/ConfigModelConstant.kt | 30 + .../controllerblueprints/core/CustomFunctions.kt | 151 +++++ .../core/common/ApplicationConstants.kt | 23 + .../core/config/BluePrintLoadConfiguration.kt | 34 ++ .../core/data/BluePrintExpressionData.kt | 70 +++ .../core/data/BluePrintModel.kt | 622 +++++++++++++++++++++ .../core/data/BlueprintErrorCode.kt | 97 ++++ .../core/factory/BluePrintValidatorFactory.kt | 45 ++ .../core/interfaces/BluePrintCatalogService.kt | 59 ++ .../core/interfaces/BluePrintEnhancer.kt | 141 +++++ .../core/interfaces/BluePrintRepoService.kt | 47 ++ .../core/interfaces/BluePrintScriptsService.kt | 25 + .../core/interfaces/BlueprintFunctionNode.kt | 39 ++ .../core/interfaces/BlueprintValidator.kt | 132 +++++ .../core/service/BluePrintChainedService.kt | 117 ++++ .../core/service/BluePrintContext.kt | 254 +++++++++ .../core/service/BluePrintExpressionService.kt | 173 ++++++ .../core/service/BluePrintImportService.kt | 96 ++++ .../core/service/BluePrintParserService.kt | 62 ++ .../core/service/BluePrintRepoFileService.kt | 71 +++ .../core/service/BluePrintRuntimeService.kt | 501 +++++++++++++++++ .../core/service/BluePrintTemplateService.kt | 94 ++++ .../core/service/BluePrintValidatorService.kt | 607 ++++++++++++++++++++ .../core/service/PropertyAssignmentService.kt | 210 +++++++ .../core/utils/BluePrintArchiveUtils.kt | 147 +++++ .../core/utils/BluePrintFileUtils.kt | 253 +++++++++ .../core/utils/BluePrintMetadataUtils.kt | 144 +++++ .../core/utils/BluePrintRuntimeUtils.kt | 61 ++ .../core/utils/JacksonReactorUtils.kt | 109 ++++ .../core/utils/JacksonUtils.kt | 287 ++++++++++ .../core/utils/ResourceResolverUtils.kt | 62 ++ .../core/utils/ServiceTemplateUtils.kt | 110 ++++ .../core/utils/TopologicalSortingUtils.kt | 131 +++++ .../BluePrintArtifactTypeValidatorImpl.kt | 33 ++ .../BluePrintAttributeDefinitionValidatorImpl.kt | 29 + .../validation/BluePrintDataTypeValidatorImpl.kt | 37 ++ .../BluePrintNodeTemplateValidatorImpl.kt | 298 ++++++++++ .../validation/BluePrintNodeTypeValidatorImpl.kt | 155 +++++ .../BluePrintPropertyDefinitionValidatorImpl.kt | 83 +++ .../BluePrintServiceTemplateValidatorImpl.kt | 107 ++++ .../BluePrintTopologyTemplateValidatorImpl.kt | 72 +++ .../validation/BluePrintValidatorServiceImpl.kt | 48 ++ .../validation/BluePrintWorkflowValidatorImpl.kt | 76 +++ .../services/javax.script.ScriptEngineFactory | 17 + .../core/CustomFunctionsTest.kt | 35 ++ .../core/mock/MockBluePrintTypeValidatorService.kt | 59 ++ .../core/service/BluePrintContextTest.kt | 54 ++ .../core/service/BluePrintExpressionServiceTest.kt | 117 ++++ .../core/service/BluePrintRepoFileServiceTest.kt | 57 ++ .../core/service/BluePrintRuntimeServiceTest.kt | 144 +++++ .../core/service/BluePrintTemplateServiceTest.kt | 35 ++ .../BluePrintValidatorDefaultServiceTest.kt | 50 ++ .../core/utils/BluePrintFileUtilsTest.kt | 60 ++ .../core/utils/BluePrintMetadataUtilsTest.kt | 41 ++ .../core/utils/JacksonUtilsTest.kt | 78 +++ .../core/utils/TopologicalSortingUtilsTest.kt | 36 ++ .../BluePrintValidatorServiceImplTest.kt | 100 ++++ .../src/test/resources/componentnode/default.json | 100 ++++ .../src/test/resources/data/alltype-data.json | 10 + .../src/test/resources/data/default-context.json | 7 + .../resources/dictionary/dictionary_schema.json | 261 +++++++++ .../src/test/resources/properties/convert.json | 36 ++ .../src/test/resources/properties/default.json | 16 + .../scripts/SampleBlueprintFunctionNode.kts | 44 ++ .../test/resources/templates/base-config-data.json | 36 ++ .../resources/templates/base-config-template.vtl | 61 ++ .../modules/blueprint-validation/pom.xml | 2 +- .../modules/db-resources/pom.xml | 2 +- ms/controllerblueprints/modules/pom.xml | 7 +- .../node_type/source-component-java.json | 31 + .../load/model_type/node_type/source-default.json | 18 + .../load/model_type/node_type/source-input.json | 18 + .../model_type/node_type/source-primary-db.json | 44 ++ .../load/model_type/node_type/source-rest.json | 61 ++ .../node_type/tosca.nodes.ResourceSource.json | 5 + .../load/resource_dictionary/address.json | 17 + .../load/resource_dictionary/aic-cloud-region.json | 17 + .../load/resource_dictionary/aic_clli.json | 17 + .../resource_dictionary/availability_zone_0.json | 17 + .../load/resource_dictionary/default-source.json | 16 + .../load/resource_dictionary/input-source.json | 17 + .../load/resource_dictionary/mdsal-source.json | 34 ++ .../load/resource_dictionary/name_0.json | 17 + .../load/resource_dictionary/nf-role.json | 25 + .../load/resource_dictionary/nfc-naming-code.json | 25 + .../resource_dictionary/onap_private_net_cidr.json | 21 + .../resource_dictionary/onap_private_net_id.json | 17 + .../resource_dictionary/primary-db-source.json | 24 + .../resource_dictionary/private-prefix-id.json | 21 + .../resource_dictionary/protected-prefix-id.json | 21 + .../protected_private_net_cidr.json | 21 + .../load/resource_dictionary/public_net_id.json | 17 + .../resource_dictionary/service-instance-id.json | 17 + .../resource_dictionary/unprotected-prefix-id.json | 21 + .../unprotected_private_net_cidr.json | 21 + .../load/resource_dictionary/vf-module-id.json | 17 + .../load/resource_dictionary/vf-module-label.json | 25 + .../vf-module-model-customization-uuid.json | 17 + .../load/resource_dictionary/vf-module-type.json | 25 + .../load/resource_dictionary/vf-naming-policy.json | 25 + .../load/resource_dictionary/vf-nf-code.json | 25 + .../load/resource_dictionary/vf_module_name.json | 17 + .../resource_dictionary/vfccustomizationuuid.json | 25 + .../load/resource_dictionary/vfw_private_ip_0.json | 35 ++ .../load/resource_dictionary/vfw_private_ip_1.json | 35 ++ .../load/resource_dictionary/vfw_private_ip_2.json | 17 + .../load/resource_dictionary/vm-type.json | 25 + .../load/resource_dictionary/vnf-id.json | 17 + .../vnf-model-customization-uuid.json | 17 + .../load/resource_dictionary/vnf-name.json | 28 + .../load/resource_dictionary/vnf_name.json | 28 + .../vnfc-model-invariant-uuid.json | 25 + .../resource_dictionary/vnfc-model-version.json | 25 + .../load/resource_dictionary/vpg_private_ip_0.json | 35 ++ .../load/resource_dictionary/vpg_private_ip_1.json | 17 + .../load/resource_dictionary/vsn_private_ip_0.json | 35 ++ .../load/resource_dictionary/vsn_private_ip_1.json | 17 + .../modules/resource-dict/pom.xml | 42 ++ .../resource/dict/ResourceDefinition.kt | 100 ++++ .../resource/dict/ResourceDictionaryConstants.kt | 38 ++ .../dict/factory/ResourceSourceMappingFactory.kt | 47 ++ .../service/ResourceAssignmentValidationService.kt | 163 ++++++ .../service/ResourceDefinitionValidationService.kt | 113 ++++ .../dict/utils/BulkResourceSequencingUtils.kt | 109 ++++ .../resource/dict/utils/ResourceDictionaryUtils.kt | 94 ++++ .../resource/dict/ResourceDefinitionTest.java | 60 ++ .../factory/ResourceSourceMappingFactoryTest.java | 42 ++ .../ResourceAssignmentValidationServiceTest.kt | 66 +++ .../ResourceDefinitionValidationServiceTest.java | 56 ++ .../utils/BulkResourceSequencingUtilsTest.java | 37 ++ .../dict/utils/ResourceDictionaryUtilsTest.java | 99 ++++ .../dict/utils/ResourceDictionaryTestUtils.kt | 30 + .../resources/data/resource-assignment-input.json | 10 + .../src/test/resources/validation/cyclic.json | 111 ++++ .../src/test/resources/validation/duplicate.json | 110 ++++ .../src/test/resources/validation/success.json | 110 ++++ ms/controllerblueprints/parent/pom.xml | 64 ++- 168 files changed, 11263 insertions(+), 10 deletions(-) create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-bpmn-camunda.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-directed-graph.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-mapping-resource.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-script-python.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-template-velocity.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/tosca.artifacts.Implementation.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/datatype-property.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/datatype-resource-assignment.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/dt-license-key.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/dt-v4-aggregate.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/tosca.datatypes.Credential.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/artifact-config-template.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-config-generator.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-netconf-executor.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-resource-assignment.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-activate-netconf.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-config-generator.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-resource-assign-activate.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-resource-assignment.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Artifact.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Component.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.DG.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Vnf.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.component.Python.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/vnf-netconf-device.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/pom.xml create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintError.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/common/ApplicationConstants.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/config/BluePrintLoadConfiguration.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BlueprintErrorCode.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt create mode 100755 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintRepoService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintTemplateService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt create mode 100755 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt create mode 100755 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintArtifactTypeValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintAttributeDefinitionValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintDataTypeValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintPropertyDefinitionValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintServiceTemplateValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintTopologyTemplateValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/mock/MockBluePrintTypeValidatorService.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtilsTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImplTest.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/resources/componentnode/default.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/alltype-data.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/resources/dictionary/dictionary_schema.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/resources/properties/convert.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/resources/properties/default.json create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts/SampleBlueprintFunctionNode.kts create mode 100755 ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data.json create mode 100755 ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-template.vtl create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-component-java.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-primary-db.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/tosca.nodes.ResourceSource.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/address.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/aic-cloud-region.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/aic_clli.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/availability_zone_0.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/name_0.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/nf-role.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/nfc-naming-code.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/onap_private_net_cidr.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/onap_private_net_id.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/primary-db-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/private-prefix-id.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/protected-prefix-id.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/protected_private_net_cidr.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/public_net_id.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/service-instance-id.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/unprotected-prefix-id.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/unprotected_private_net_cidr.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vf-module-id.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vf-module-label.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vf-module-model-customization-uuid.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vf-module-type.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vf-naming-policy.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vf-nf-code.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vf_module_name.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vfccustomizationuuid.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vfw_private_ip_0.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vfw_private_ip_1.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vfw_private_ip_2.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vm-type.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnf-id.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnf-model-customization-uuid.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnf-name.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnf_name.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnfc-model-invariant-uuid.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnfc-model-version.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vpg_private_ip_0.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vpg_private_ip_1.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vsn_private_ip_0.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vsn_private_ip_1.json create mode 100644 ms/controllerblueprints/modules/resource-dict/pom.xml create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-bpmn-camunda.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-bpmn-camunda.json new file mode 100644 index 000000000..cae06c18f --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-bpmn-camunda.json @@ -0,0 +1,8 @@ +{ + "description": " Camunda BPM File", + "version": "1.0.0", + "file_ext": [ + "bpmn" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-directed-graph.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-directed-graph.json new file mode 100644 index 000000000..10bf7d2c4 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-directed-graph.json @@ -0,0 +1,9 @@ +{ + "description": "Directed Graph File", + "version": "1.0.0", + "file_ext": [ + "json", + "xml" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-mapping-resource.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-mapping-resource.json new file mode 100644 index 000000000..9123efd1d --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-mapping-resource.json @@ -0,0 +1,8 @@ +{ + "description": " Velocity Template Resource Mapping File used along with Configuration template", + "version": "1.0.0", + "file_ext": [ + "json" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-script-python.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-script-python.json new file mode 100644 index 000000000..22af3b0a9 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-script-python.json @@ -0,0 +1,8 @@ +{ + "description": " Kotlin Script Template used for Configuration", + "version": "1.0.0", + "file_ext": [ + "py" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-template-velocity.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-template-velocity.json new file mode 100644 index 000000000..20f94c946 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/artifact-template-velocity.json @@ -0,0 +1,8 @@ +{ + "description": " Velocity Template used for Configuration", + "version": "1.0.0", + "file_ext": [ + "vtl" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/tosca.artifacts.Implementation.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/tosca.artifacts.Implementation.json new file mode 100644 index 000000000..d75f33760 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/artifact_type/tosca.artifacts.Implementation.json @@ -0,0 +1,5 @@ +{ + "description": "TOSCA base type for implementation artifacts", + "version": "1.0.0", + "derived_from": "tosca.artifacts.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/datatype-property.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/datatype-property.json new file mode 100644 index 000000000..d3ecffd17 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/datatype-property.json @@ -0,0 +1,27 @@ +{ + "version": "1.0.0", + "description": "This is Entry point Input Data Type, which is dynamic datatype, The parameter names will be populated during the Design time for each inputs", + "properties": { + "type": { + "required": true, + "type": "string" + }, + "description": { + "required": false, + "type": "string" + }, + "required": { + "required": false, + "type": "boolean" + }, + "default": { + "required": false, + "type": "string" + }, + "entry_schema": { + "required": false, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/datatype-resource-assignment.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/datatype-resource-assignment.json new file mode 100644 index 000000000..8fa595a15 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/datatype-resource-assignment.json @@ -0,0 +1,46 @@ +{ + "version": "1.0.0", + "description": "This is Resource Assignment Data Type", + "properties": { + "property": { + "required": true, + "type": "datatype-property" + }, + "input-param": { + "required": true, + "type": "boolean" + }, + "dictionary-name": { + "required": false, + "type": "string" + }, + "dictionary-source": { + "required": false, + "type": "string" + }, + "dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + }, + "status": { + "required": false, + "type": "string" + }, + "message": { + "required": false, + "type": "string" + }, + "updated-date": { + "required": false, + "type": "string" + }, + "updated-by": { + "required": false, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/dt-license-key.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/dt-license-key.json new file mode 100644 index 000000000..27e25fe17 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/dt-license-key.json @@ -0,0 +1,11 @@ +{ + "version": "1.0.0", + "description": "This is dt-plicense-key Data Type", + "properties": { + "license-key": { + "required": true, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/dt-v4-aggregate.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/dt-v4-aggregate.json new file mode 100644 index 000000000..4f7be2dba --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/dt-v4-aggregate.json @@ -0,0 +1,15 @@ +{ + "version": "1.0.0", + "description": "This is dt-v4-aggregate Data Type", + "properties": { + "ipv4-address": { + "required": true, + "type": "string" + }, + "ipv4-plen": { + "required": false, + "type": "integer" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/tosca.datatypes.Credential.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/tosca.datatypes.Credential.json new file mode 100644 index 000000000..68d91652f --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/data_type/tosca.datatypes.Credential.json @@ -0,0 +1,31 @@ +{ + "version": "1.0.0", + "description": "Credential", + "properties": { + "protocol": { + "required": false, + "type": "string" + }, + "token_type": { + "required": true, + "type": "string", + "default" : "password" + }, + "token": { + "required": false, + "type": "string" + }, + "keys": { + "required": false, + "type": "list", + "entry_schema": { + "type": "string" + } + }, + "user": { + "required": false, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/artifact-config-template.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/artifact-config-template.json new file mode 100644 index 000000000..057038fd2 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/artifact-config-template.json @@ -0,0 +1,37 @@ +{ + "description": "This is Configuration Velocity Template", + "version": "1.0.0", + "properties": { + "action-names": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "capabilities": { + "content": { + "type": "tosca.capabilities.Content", + "properties": { + "content": { + "required": true, + "type": "string" + } + } + }, + "mapping": { + "type": "tosca.capabilities.Mapping", + "properties": { + "mapping": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-resource-assignment" + } + } + } + } + }, + "derived_from": "tosca.nodes.Artifact" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-config-generator.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-config-generator.json new file mode 100644 index 000000000..05bf7fe24 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-config-generator.json @@ -0,0 +1,72 @@ +{ + "description": "This is Generate Configuration Component API", + "version": "1.0.0", + "capabilities": { + "component-node": { + "type": "tosca.capabilities.Node" + } + }, + "interfaces": { + "org-onap-ccsdk-config-generator-service-ConfigGeneratorNode": { + "operations": { + "process": { + "inputs": { + "template-data": { + "description": "Conditional : JSON string which is used to mash with template. Either template-data or ( resource-id and resource-type ) should be present", + "required": false, + "type": "string" + }, + "template-content": { + "description": "Conditional : Dynamic Template used to generate Configuration.", + "required": false, + "type": "string" + }, + "resource-type": { + "description": "Conditional : resource-type used to pull the data content from the data base. Either template-data or ( resource-id and resource-type ) should be present", + "required": false, + "type": "string" + }, + "request-id": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": true, + "type": "string" + }, + "resource-id": { + "description": "Conditional : Id used to pull the data content from the data base. Either template-data or ( resource-id and resource-type ) should be present", + "required": false, + "type": "string" + }, + "action-name": { + "description": "Conditional : Action Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "template-name": { + "description": "Conditional : Name of the Artifact Node Template, to get the template Content. If template-content is present, then content wont be reterived from the Artifact Node Template.", + "required": true, + "type": "string" + } + }, + "outputs": { + "generated-config": { + "description": "Generated Configuration for the Template adn Resource Data", + "required": true, + "type": "string" + }, + "mask-info": { + "description": "If template contains mask encription keys, then this mask-info field will be generated, This JSON Content alligns to the bean org.onap.ccsdk.apps.controllerblueprints.core.data.custom.MaskInfo ", + "required": false, + "type": "string" + }, + "status": { + "description": "Status of the Component Execution ( success or failure )", + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.Component" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-netconf-executor.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-netconf-executor.json new file mode 100644 index 000000000..22f5c9b3c --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-netconf-executor.json @@ -0,0 +1,79 @@ +{ + "description": "This is Netconf Transaction Configuration Component API", + "version": "1.0.0", + "capabilities": { + "component-node": { + "type": "tosca.capabilities.Node" + } + }, + "requirements": { + "netconf-connection": { + "capability": "netconf", + "node": "vnf-netconf-device", + "relationship": "tosca.relationships.ConnectsTo" + } + }, + "interfaces": { + "org-onap-ccsdk-netconf-adaptor-service-NetconfExecutorNode": { + "operations": { + "process": { + "inputs": { + "request-id": { + "description": "Request Id used to store the generated configuration, in the database along with the template-name", + "required": true, + "type": "string" + }, + "service-template-name": { + "description": "Service Template Name", + "required": true, + "type": "string" + }, + "service-template-version": { + "description": "Service Template Version", + "required": true, + "type": "string" + }, + "action-name": { + "description": "Action Name to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "resource-type": { + "description": "Resource Type to get from Database, Either (message & mask-info ) or( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "resource-id": { + "description": "Resource Id to get from Database, Either (message & mask-info ) or ( resource-id & resource-type & action-name & template-name ) should be present. Message will be given higest priority", + "required": false, + "type": "string" + }, + "reservation-id": { + "description": "Reservation Id used to send to NPM", + "required": false, + "type": "string" + }, + "execution-script": { + "description": "Python Script to Execute for this Component action, It should refer any one of Prython Artifact Definition for this Node Template.", + "required": true, + "type": "string" + } + }, + "outputs": { + "response-data": { + "description": "Execution Response Data in JSON format.", + "required": false, + "type": "string" + }, + "status": { + "description": "Status of the Component Execution ( success or failure )", + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.Component" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-resource-assignment.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-resource-assignment.json new file mode 100644 index 000000000..e009f8583 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/component-resource-assignment.json @@ -0,0 +1,68 @@ +{ + "description": "This is Resource Assignment Component API", + "version": "1.0.0", + "capabilities": { + "component-node": { + "type": "tosca.capabilities.Node" + } + }, + "interfaces": { + "ResourceAssignmentComponent": { + "operations": { + "process": { + "inputs": { + "service-template-name": { + "description": "Service Template Name.", + "required": true, + "type": "string" + }, + "service-template-version": { + "description": "Service Template Version.", + "required": true, + "type": "string" + }, + "resource-type": { + "description": "Request type.", + "required": true, + "type": "string" + }, + "template-names": { + "description": "Name of the artifact Node Templates, to get the template Content.", + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + }, + "request-id": { + "description": "Request Id, Unique Id for the request.", + "required": true, + "type": "string" + }, + "resource-id": { + "description": "Resource Id.", + "required": true, + "type": "string" + }, + "action-name": { + "description": "Action Name of the process", + "required": true, + "type": "string" + } + }, + "outputs": { + "resource-assignment-params": { + "required": true, + "type": "string" + }, + "status": { + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.Component" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-activate-netconf.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-activate-netconf.json new file mode 100644 index 000000000..57667de98 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-activate-netconf.json @@ -0,0 +1,52 @@ +{ + "description": "This is Download Netconf Directed Graph", + "version": "1.0.0", + "properties": { + "mode": { + "required": false, + "type": "string", + "default": "sync" + }, + "version": { + "required": false, + "type": "string", + "default": "LATEST" + }, + "is-start-flow": { + "required": false, + "type": "boolean", + "default": false + } + }, + "capabilities": { + "dg-node": { + "type": "tosca.capabilities.Node" + } + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "component-netconf-executor", + "relationship": "tosca.relationships.DependsOn" + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "ActivateNetconf": { + "inputs": { + "params": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-property" + } + } + } + } + } + } + }, + + "derived_from": "tosca.nodes.DG" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-config-generator.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-config-generator.json new file mode 100644 index 000000000..679c4641c --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-config-generator.json @@ -0,0 +1,51 @@ +{ + "description": "This is Activate DG for Config Generator Directed Graph", + "version": "1.0.0", + "properties": { + "mode": { + "required": false, + "type": "string", + "default": "sync" + }, + "version": { + "required": false, + "type": "string", + "default": "LATEST" + }, + "is-start-flow": { + "required": false, + "type": "boolean", + "default": false + } + }, + "capabilities": { + "dg-node": { + "type": "tosca.capabilities.Node" + } + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "component-config-generator", + "relationship": "tosca.relationships.DependsOn" + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "GenerateConfiguration": { + "inputs": { + "params": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-property" + } + } + } + } + } + } + }, + "derived_from": "tosca.nodes.DG" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-resource-assign-activate.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-resource-assign-activate.json new file mode 100644 index 000000000..87b052b61 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-resource-assign-activate.json @@ -0,0 +1,56 @@ +{ + "description": "This is Resource Assign and Activate Netconf Directed Graph", + "version": "1.0.0", + "properties": { + "mode": { + "required": false, + "type": "string", + "default": "sync" + }, + "version": { + "required": false, + "type": "string", + "default": "LATEST" + }, + "is-start-flow": { + "required": false, + "type": "boolean", + "default": false + } + }, + "capabilities": { + "dg-node": { + "type": "tosca.capabilities.Node" + } + }, + "requirements": { + "ra-component": { + "capability": "component-node", + "node": "component-resource-assignment", + "relationship": "tosca.relationships.DependsOn" + }, + "netconf-component": { + "capability": "component-node", + "node": "component-netconf-executor", + "relationship": "tosca.relationships.DependsOn" + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "ResourceAssignAndActivate": { + "inputs": { + "params": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-property" + } + } + } + } + } + } + }, + "derived_from": "tosca.nodes.DG" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-resource-assignment.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-resource-assignment.json new file mode 100644 index 000000000..9de599b01 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/dg-resource-assignment.json @@ -0,0 +1,51 @@ +{ + "description": "This is Resource Assignment Directed Graph", + "version": "1.0.0", + "properties": { + "mode": { + "required": false, + "type": "string", + "default": "sync" + }, + "version": { + "required": false, + "type": "string", + "default": "LATEST" + }, + "is-start-flow": { + "required": false, + "type": "boolean", + "default": false + } + }, + "capabilities": { + "dg-node": { + "type": "tosca.capabilities.Node" + } + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "component-resource-assignment", + "relationship": "tosca.relationships.DependsOn" + } + }, + "interfaces": { + "CONFIG": { + "operations": { + "ResourceAssignment": { + "inputs": { + "params": { + "required": false, + "type": "list", + "entry_schema": { + "type": "datatype-property" + } + } + } + } + } + } + }, + "derived_from": "tosca.nodes.DG" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Artifact.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Artifact.json new file mode 100644 index 000000000..4db3f73c8 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Artifact.json @@ -0,0 +1,5 @@ +{ + "description": "This is Deprecated Artifact Node Type.", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Component.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Component.json new file mode 100644 index 000000000..d559216af --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Component.json @@ -0,0 +1,5 @@ +{ + "description": "This is default Component Node", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.DG.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.DG.json new file mode 100644 index 000000000..eb8cac0ae --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.DG.json @@ -0,0 +1,5 @@ +{ + "description": "This is Directed Graph Node Type", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Vnf.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Vnf.json new file mode 100644 index 000000000..c2f5b8687 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.Vnf.json @@ -0,0 +1,5 @@ +{ + "description": "This is VNF Node Type", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.component.Python.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.component.Python.json new file mode 100644 index 000000000..908e5682e --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/tosca.nodes.component.Python.json @@ -0,0 +1,5 @@ +{ + "description": "This is Python Component", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/vnf-netconf-device.json b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/vnf-netconf-device.json new file mode 100644 index 000000000..b226a0cf8 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/load/model_type/node_type/vnf-netconf-device.json @@ -0,0 +1,42 @@ +{ + "description": "This is VNF Device with Netconf Capability", + "version": "1.0.0", + "capabilities": { + "netconf": { + "type": "tosca.capability.Netconf", + "properties": { + "login-key": { + "required": true, + "type": "string", + "default": "sdnc" + }, + "login-account": { + "required": true, + "type": "string", + "default": "sdnc-tacacs" + }, + "source": { + "required": true, + "type": "string", + "default": "npm" + }, + "target-ip-address": { + "required": true, + "type": "string" + }, + "port-number": { + "required": true, + "type": "integer", + "default": 830 + }, + "connection-time-out": { + "required": false, + "type": "integer", + "default": 30 + } + } + } + }, + "derived_from": "tosca.nodes.Vnf" + +} diff --git a/ms/controllerblueprints/modules/blueprint-core/pom.xml b/ms/controllerblueprints/modules/blueprint-core/pom.xml new file mode 100644 index 000000000..9461b2ca5 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/pom.xml @@ -0,0 +1,76 @@ + + + + + 4.0.0 + + org.onap.ccsdk.apps.controllerblueprints + modules + 0.4.1-SNAPSHOT + + blueprint-core + Controller Blueprints Core + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.module + jackson-module-jsonSchema + + + io.projectreactor + reactor-core + + + org.yaml + snakeyaml + + + org.apache.velocity + velocity + + + + org.jetbrains.kotlin + kotlin-test-junit + test + + + io.mockk + mockk + test + + + org.jetbrains.kotlinx + kotlinx-coroutines-test + test + + + + + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt new file mode 100644 index 000000000..c50218bfb --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt @@ -0,0 +1,176 @@ +/* + * 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.core + +/** + * BluePrintConstants + * + * @author Brinda Santh + */ +object BluePrintConstants { + + const val RESPONSE_HEADER_TRANSACTION_ID: String = "X-ONAP-RequestID" + const val RESPONSE_HEADER_MINOR_VERSION: String = "X-MinorVersion" + const val RESPONSE_HEADER_PATCH_VERSION: String = "X-PatchVersion" + const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion" + + const val STATUS_SUCCESS: String = "success" + const val STATUS_PROCESSING: String = "processing" + const val STATUS_FAILURE: String = "failure" + + const val TYPE_DEFAULT: String = "default" + + const val DATA_TYPE_STRING: String = "string" + const val DATA_TYPE_INTEGER: String = "integer" + const val DATA_TYPE_FLOAT: String = "float" + const val DATA_TYPE_DOUBLE: String = "double" + const val DATA_TYPE_BOOLEAN: String = "boolean" + const val DATA_TYPE_TIMESTAMP: String = "timestamp" + const val DATA_TYPE_NULL: String = "null" + const val DATA_TYPE_LIST: String = "list" + const val DATA_TYPE_MAP: String = "map" + + const val USER_SYSTEM: String = "System" + + const val PATH_DIVIDER: String = "/" + const val PATH_SERVICE_TEMPLATE: String = "service_template" + const val PATH_TOPOLOGY_TEMPLATE: String = "topology_template" + const val PATH_METADATA: String = "metadata" + const val PATH_NODE_TYPES: String = "node_types" + const val PATH_POLICY_TYPES: String = "policy_types" + const val PATH_RELATIONSHIP_TYPES: String = "relationship_types" + const val PATH_ARTIFACT_TYPES: String = "artifact_types" + const val PATH_DATA_TYPES: String = "data_types" + const val PATH_INPUTS: String = "inputs" + const val PATH_NODE_WORKFLOWS: String = "workflows" + const val PATH_NODE_TEMPLATES: String = "node_templates" + const val PATH_CAPABILITIES: String = "capabilities" + const val PATH_REQUIREMENTS: String = "requirements" + const val PATH_INTERFACES: String = "interfaces" + const val PATH_OPERATIONS: String = "operations" + const val PATH_OUTPUTS: String = "outputs" + const val PATH_PROPERTIES: String = "properties" + const val PATH_ATTRIBUTES: String = "attributes" + const val PATH_ARTIFACTS: String = "artifacts" + + const val MODEL_DIR_MODEL_TYPE: String = "definition-type" + + const val MODEL_DEFINITION_TYPE_NODE_TYPE: String = "node_type" + const val MODEL_DEFINITION_TYPE_ARTIFACT_TYPE: String = "artifact_type" + const val MODEL_DEFINITION_TYPE_CAPABILITY_TYPE: String = "capability_type" + const val MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE: String = "relationship_type" + const val MODEL_DEFINITION_TYPE_DATA_TYPE: String = "data_type" + + const val MODEL_TYPE_DATATYPES_ROOT: String = "tosca.datatypes.Root" + const val MODEL_TYPE_NODES_ROOT: String = "tosca.nodes.Root" + const val MODEL_TYPE_GROUPS_ROOT: String = "tosca.groups.Root" + const val MODEL_TYPE_RELATIONSHIPS_ROOT: String = "tosca.relationships.Root" + const val MODEL_TYPE_ARTIFACTS_ROOT: String = "tosca.artifacts.Root" + const val MODEL_TYPE_CAPABILITIES_ROOT: String = "tosca.capabilities.Root" + const val MODEL_TYPE_INTERFACES_ROOT: String = "tosca.interfaces.Root" + + const val MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON = "tosca.relationships.DependsOn" + const val MODEL_TYPE_RELATIONSHIPS_HOSTED_ON = "tosca.relationships.HostedOn" + const val MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO = "tosca.relationships.ConnectsTo" + const val MODEL_TYPE_RELATIONSHIPS_ATTACH_TO = "tosca.relationships.AttachesTo" + const val MODEL_TYPE_RELATIONSHIPS_ROUTES_TO = "tosca.relationships.RoutesTo" + + const val MODEL_TYPE_NODE_DG = "tosca.nodes.DG" + const val MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component" + const val MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf" + @Deprecated("Artifacts will be attached to Node Template") + const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact" + const val MODEL_TYPE_NODE_RESOURCE_SOURCE = "tosca.nodes.ResourceSource" + + const val MODEL_TYPE_NODES_COMPONENT_JAVA: String = "tosca.nodes.component.Java" + const val MODEL_TYPE_NODES_COMPONENT_BUNDLE: String = "tosca.nodes.component.Bundle" + const val MODEL_TYPE_NODES_COMPONENT_SCRIPT: String = "tosca.nodes.component.Script" + const val MODEL_TYPE_NODES_COMPONENT_PYTHON: String = "tosca.nodes.component.Python" + const val MODEL_TYPE_NODES_COMPONENT_JYTHON: String = "tosca.nodes.component.Jython" + const val MODEL_TYPE_NODES_COMPONENT_KOTLIN: String = "tosca.nodes.component.Kotlin" + const val MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT: String = "tosca.nodes.component.JavaScript" + + const val MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION = "tosca.artifacts.Implementation" + + const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic" + + const val MODEL_TYPE_CAPABILITY_TYPE_NODE = "tosca.capabilities.Node" + const val MODEL_TYPE_CAPABILITY_TYPE_COMPUTE = "tosca.capabilities.Compute" + const val MODEL_TYPE_CAPABILITY_TYPE_NETWORK = "tosca.capabilities.Network" + const val MODEL_TYPE_CAPABILITY_TYPE_STORAGE = "tosca.capabilities.Storage" + const val MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT = "tosca.capabilities.Endpoint" + const val MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT_PUBLIC = "tosca.capabilities.Endpoint.Public" + const val MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT_ADMIN = "tosca.capabilities.Endpoint.Admin" + const val MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT_DATABASE = "tosca.capabilities.Endpoint.Database" + const val MODEL_TYPE_CAPABILITY_TYPE_ATTACHMENT = "tosca.capabilities.Attachment" + const val MODEL_TYPE_CAPABILITY_TYPE_OPERATION_SYSTEM = "tosca.capabilities.OperatingSystem" + const val MODEL_TYPE_CAPABILITY_TYPE_BINDABLE = "tosca.capabilities.network.Bindable" + // Custom capabilities + const val MODEL_TYPE_CAPABILITY_TYPE_CONTENT = "tosca.capabilities.Content" + const val MODEL_TYPE_CAPABILITY_TYPE_MAPPING = "tosca.capabilities.Mapping" + const val MODEL_TYPE_CAPABILITY_TYPE_NETCONF = "tosca.capabilities.Netconf" + const val MODEL_TYPE_CAPABILITY_TYPE_SSH = "tosca.capabilities.Ssh" + const val MODEL_TYPE_CAPABILITY_TYPE_SFTP = "tosca.capabilities.Sftp" + + const val EXPRESSION_GET_INPUT: String = "get_input" + const val EXPRESSION_GET_ATTRIBUTE: String = "get_attribute" + const val EXPRESSION_GET_ARTIFACT: String = "get_artifact" + const val EXPRESSION_GET_PROPERTY: String = "get_property" + const val EXPRESSION_GET_OPERATION_OUTPUT: String = "get_operation_output" + const val EXPRESSION_GET_NODE_OF_TYPE: String = "get_nodes_of_type" + + const val PROPERTY_BLUEPRINT_PROCESS_ID: String = "blueprint-process-id" + const val PROPERTY_BLUEPRINT_BASE_PATH: String = "blueprint-basePath" + const val PROPERTY_BLUEPRINT_RUNTIME: String = "blueprint-runtime" + const val PROPERTY_BLUEPRINT_INPUTS_DATA: String = "blueprint-inputs-data" + const val PROPERTY_BLUEPRINT_CONTEXT: String = "blueprint-context" + const val PROPERTY_BLUEPRINT_NAME: String = "template_name" + const val PROPERTY_BLUEPRINT_VERSION: String = "template_version" + + const val TOSCA_METADATA_DIR: String = "TOSCA-Metadata" + const val TOSCA_METADATA_ENTRY_DEFINITION_FILE: String = "TOSCA-Metadata/TOSCA.meta" + const val TOSCA_DEFINITIONS_DIR: String = "Definitions" + const val TOSCA_PLANS_DIR: String = "Plans" + const val TOSCA_SCRIPTS_DIR: String = "Scripts" + const val TOSCA_MAPPINGS_DIR: String = "Mappings" + const val TOSCA_TEMPLATES_DIR: String = "Templates" + const val TOSCA_SCRIPTS_KOTLIN_DIR: String = "$TOSCA_SCRIPTS_DIR/kotlin" + + const val METADATA_USER_GROUPS = "user-groups" + const val METADATA_TEMPLATE_NAME = "template_name" + const val METADATA_TEMPLATE_VERSION = "template_version" + const val METADATA_TEMPLATE_AUTHOR = "template_author" + const val METADATA_TEMPLATE_TAGS = "template_tags" + const val METADATA_WORKFLOW_NAME = "workflow_name" + + const val PAYLOAD_DATA = "payload-data" + const val PROPERTY_CURRENT_STEP = "current-step" + const val PROPERTY_CURRENT_NODE_TEMPLATE = "current-node-template" + const val PROPERTY_CURRENT_INTERFACE = "current-interface" + const val PROPERTY_CURRENT_OPERATION = "current-operation" + const val PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation" + const val PROPERTY_EXECUTION_REQUEST = "execution-request" + + const val OPERATION_PROCESS = "process" + const val OPERATION_PREPARE = "prepare" + + const val BLUEPRINT_RETRIEVE_TYPE_DB = "db" + const val BLUEPRINT_RETRIEVE_TYPE_FILE = "file" + const val BLUEPRINT_RETRIEVE_TYPE_REPO = "repo" + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintError.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintError.kt new file mode 100644 index 000000000..ea5bda42e --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintError.kt @@ -0,0 +1,29 @@ +/* + * 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.core + +class BluePrintError { + var errors: MutableList = arrayListOf() + + fun addError(type: String, name: String, error: String) { + this.errors.add("$type : $name : $error") + } + + fun addError(error: String) { + this.errors.add(error) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt new file mode 100644 index 000000000..5acdf8e43 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintException.kt @@ -0,0 +1,49 @@ +/* + * 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.core +/** + * + * + * @author Brinda Santh + */ +class BluePrintException : Exception { + + var code: Int = 100 + + constructor(cause: Throwable) : super(cause) + constructor(message: String) : super(message) + constructor(message: String, cause: Throwable) : super(message, cause) + constructor(cause: Throwable, message: String, vararg args: Any?) : super(String.format(message, *args), cause) + + constructor(code: Int, cause: Throwable) : super(cause) { + this.code = code + } + + constructor(code: Int, message: String) : super(message) { + this.code = code + } + + constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { + this.code = code + } + + constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) + : super(String.format(message, *args), cause) { + this.code = code + } +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt new file mode 100644 index 000000000..6ebabb7a9 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintProcessorException.kt @@ -0,0 +1,50 @@ +/* + * 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.core + +/** + * + * + * @author Brinda Santh + */ +class BluePrintProcessorException : RuntimeException { + var code: Int = 100 + + constructor(message: String, cause: Throwable) : super(message, cause) + constructor(message: String) : super(message) + constructor(cause: Throwable) : super(cause) + constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) + + constructor(code: Int, cause: Throwable) : super(cause) { + this.code = code + } + + constructor(code: Int, message: String) : super(message) { + this.code = code + } + + constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { + this.code = code + } + + constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) + : super(String.format(message, *args), cause) { + this.code = code + } +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt new file mode 100644 index 000000000..4509cccf3 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt @@ -0,0 +1,164 @@ +/* + * 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.core + +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition + +/** + * + * + * @author Brinda Santh + */ +object BluePrintTypes { + + @JvmStatic + val validNodeTypeDerivedFroms: MutableList = arrayListOf( + BluePrintConstants.MODEL_TYPE_NODES_ROOT, + BluePrintConstants.MODEL_TYPE_NODE_DG, + BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, + BluePrintConstants.MODEL_TYPE_NODE_VNF, + BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT, + BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, + BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_JAVA, + BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_BUNDLE, + BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_SCRIPT, + BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_PYTHON, + BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_JYTHON, + BluePrintConstants.MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT + ) + + @JvmStatic + val validArtifactTypeDerivedFroms: MutableList = arrayListOf( + BluePrintConstants.MODEL_TYPE_ARTIFACTS_ROOT, + BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION + ) + + @JvmStatic + val validDataTypeDerivedFroms: MutableList = arrayListOf( + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT, + BluePrintConstants.MODEL_TYPE_DATA_TYPE_DYNAMIC + ) + + @Deprecated("This has to move to Relationship Types Model Drive") + @JvmStatic + val validRelationShipDerivedFroms: MutableList = arrayListOf( + BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT, + BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON, + BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_HOSTED_ON, + BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ATTACH_TO, + BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROUTES_TO + ) + + @Deprecated("This has to move to Capability Types Model Drive") + @JvmStatic + val validCapabilityTypes: MutableList = arrayListOf( + BluePrintConstants.MODEL_TYPE_CAPABILITIES_ROOT, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_NODE, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_COMPUTE, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_NETWORK, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_STORAGE, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT_PUBLIC, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT_ADMIN, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT_DATABASE, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ATTACHMENT, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_OPERATION_SYSTEM, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_BINDABLE, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_CONTENT, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_MAPPING, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_NETCONF, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_SSH, + BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_SFTP + ) + + @JvmStatic + fun validModelTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + return validTypes + } + + @JvmStatic + fun validPropertyTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_STRING) + validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) + validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) + validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE) + validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) + validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) + validTypes.add(BluePrintConstants.DATA_TYPE_NULL) + validTypes.add(BluePrintConstants.DATA_TYPE_LIST) + validTypes.add(BluePrintConstants.DATA_TYPE_MAP) + return validTypes + } + + @JvmStatic + fun validPrimitiveTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_STRING) + validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) + validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) + validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE) + validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) + validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) + validTypes.add(BluePrintConstants.DATA_TYPE_NULL) + return validTypes + } + + @JvmStatic + fun validCollectionTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_LIST) + validTypes.add(BluePrintConstants.DATA_TYPE_MAP) + return validTypes + } + + @JvmStatic + fun validPrimitiveOrCollectionPrimitive(propertyDefinition: PropertyDefinition): Boolean { + val entrySchema = propertyDefinition.entrySchema?.type ?: BluePrintConstants.DATA_TYPE_NULL + return BluePrintTypes.validPropertyTypes().contains(propertyDefinition.type) + && BluePrintTypes.validPrimitiveTypes().contains(entrySchema) + } + + @JvmStatic + fun validCommands(): List { + return listOf(BluePrintConstants.EXPRESSION_GET_INPUT, + BluePrintConstants.EXPRESSION_GET_ATTRIBUTE, + BluePrintConstants.EXPRESSION_GET_PROPERTY, + BluePrintConstants.EXPRESSION_GET_ARTIFACT, + BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT, + BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE) + } + + @JvmStatic + fun rootNodeTypes(): List { + return listOf(BluePrintConstants.MODEL_TYPE_NODES_ROOT) + } + + @JvmStatic + fun rootDataTypes(): List { + return listOf(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT) + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt new file mode 100644 index 000000000..68858dc58 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt @@ -0,0 +1,30 @@ +/* + * 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.core + +/** + * + * + * @author Brinda Santh + */ +object ConfigModelConstant { + + const val MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON" + const val MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE" + const val CAPABILITY_PROPERTY_MAPPING = "mapping" +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt new file mode 100644 index 000000000..0b9c142b8 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt @@ -0,0 +1,151 @@ +/* + * 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.core + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.BooleanNode +import com.fasterxml.jackson.databind.node.DoubleNode +import com.fasterxml.jackson.databind.node.IntNode +import com.fasterxml.jackson.databind.node.TextNode +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.helpers.MessageFormatter +import java.io.File +import java.io.InputStream +import kotlin.reflect.KClass + +/** + * + * + * @author Brinda Santh + */ + +fun String.asJsonPrimitive(): TextNode { + return TextNode(this) +} + +fun Boolean.asJsonPrimitive(): BooleanNode { + return BooleanNode.valueOf(this) +} + +fun Int.asJsonPrimitive(): IntNode { + return IntNode.valueOf(this) +} + +fun Double.asJsonPrimitive(): DoubleNode { + return DoubleNode.valueOf(this) +} + +fun MutableMap.asJsonNode(): JsonNode { + return JacksonUtils.jsonNodeFromObject(this) +} + +fun format(message: String, vararg args: Any?): String { + if (args != null && args.isNotEmpty()) { + return MessageFormatter.arrayFormat(message, args).message + } + return message +} + +fun MutableMap.castOptionalValue(key: String, valueType: KClass): T? { + if (containsKey(key)) { + return get(key) as? T + } else { + return null + } +} + +fun MutableMap.castValue(key: String, valueType: KClass): T { + if (containsKey(key)) { + return get(key) as T + } else { + throw BluePrintException("couldn't find the key $key") + } +} + +fun MutableMap.putJsonElement(key: String, value: Any) { + when (value) { + is JsonNode -> + this[key] = value + is String -> + this[key] = TextNode(value) + is Boolean -> + this[key] = BooleanNode.valueOf(value) + is Int -> + this[key] = IntNode.valueOf(value.toInt()) + is Double -> + this[key] = DoubleNode.valueOf(value.toDouble()) + else -> + this[key] = JacksonUtils.jsonNodeFromObject(value) + } +} + +fun MutableMap.getAsString(key: String): String { + return this[key]?.asText() ?: throw BluePrintException("couldn't find value for key($key)") +} + +fun MutableMap.getAsBoolean(key: String): Boolean { + return this[key]?.asBoolean() ?: throw BluePrintException("couldn't find value for key($key)") +} + +fun MutableMap.getAsInt(key: String): Int { + return this[key]?.asInt() ?: throw BluePrintException("couldn't find value for key($key)") +} + +fun MutableMap.getAsDouble(key: String): Double { + return this[key]?.asDouble() ?: throw BluePrintException("couldn't find value for key($key)") +} + +// Checks + +fun checkNotEmpty(value: String?): Boolean { + return value != null && value.isNotBlank() +} + +fun checkNotEmptyOrThrow(value: String?, message: String? = value.plus(" is null/empty ")): Boolean { + val notEmpty = checkNotEmpty(value) + if (!notEmpty) { + throw BluePrintException(message!!) + } + return notEmpty +} + +fun checkEqualsOrThrow(value1: String?, value2: String?, lazyMessage: () -> Any): Boolean { + if (value1.equals(value2, ignoreCase = true)) { + return true + } else { + throw BluePrintException(lazyMessage().toString()) + } +} + +fun nullToEmpty(value: String?): String { + return if (checkNotEmpty(value)) value!! else "" +} + +fun returnNotEmptyOrThrow(value: String?, lazyMessage: () -> Any): String { + if (checkNotEmpty(value)) { + return value!! + } else { + throw IllegalStateException(lazyMessage().toString()) + } +} + +fun InputStream.toFile(path: String): File { + val file = File(path) + file.outputStream().use { this.copyTo(it) } + return file +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/common/ApplicationConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/common/ApplicationConstants.kt new file mode 100644 index 000000000..994ea5b7b --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/common/ApplicationConstants.kt @@ -0,0 +1,23 @@ +/* + * Copyright © 2019 Bell Canada + * + * 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.core.common + +object ApplicationConstants { + const val ACTIVE_Y = "Y" + const val ACTIVE_N = "N" + const val ASDC_ARTIFACT_TYPE_SDNC_MODEL = "SDNC_MODEL" +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/config/BluePrintLoadConfiguration.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/config/BluePrintLoadConfiguration.kt new file mode 100644 index 000000000..235cfd56b --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/config/BluePrintLoadConfiguration.kt @@ -0,0 +1,34 @@ +/* + * 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.core.config + +open class BluePrintLoadConfiguration { + + lateinit var blueprintDeployPath: String + lateinit var blueprintArchivePath: String + lateinit var blueprintEnrichmentPath: String + + var loadInitialData: Boolean = false + var loadBluePrint: Boolean = false + var loadBluePrintPaths: String? = null + + var loadModelType: Boolean = false + var loadModeTypePaths: String? = null + + var loadResourceDictionary: Boolean = false + var loadResourceDictionaryPaths: String? = null +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt new file mode 100644 index 000000000..96f549db8 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintExpressionData.kt @@ -0,0 +1,70 @@ +/* + * 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.core.data + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.ObjectNode +/** + * + * + * @author Brinda Santh + */ +data class ExpressionData( + var isExpression: Boolean = false, + var valueNode: JsonNode, + var expressionNode: ObjectNode? = null, + var inputExpression: InputExpression? = null, + var propertyExpression: PropertyExpression? = null, + var attributeExpression: AttributeExpression? = null, + var artifactExpression: ArtifactExpression? = null, + var operationOutputExpression: OperationOutputExpression? = null, + var command: String? = null +) + +data class InputExpression( + var propertyName: String +) + +data class PropertyExpression( + var modelableEntityName: String = "SELF", + var reqOrCapEntityName: String? = null, + var propertyName: String, + var subPropertyName: String? = null +) + +data class AttributeExpression( + var modelableEntityName: String = "SELF", + var reqOrCapEntityName: String? = null, + var attributeName: String, + var subAttributeName: String? = null +) + +data class ArtifactExpression( + val modelableEntityName: String = "SELF", + val artifactName: String, + val location: String? = "LOCAL_FILE", + val remove: Boolean? = false +) + +data class OperationOutputExpression( + val modelableEntityName: String = "SELF", + val interfaceName: String, + val operationName: String, + val propertyName: String +) + + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt new file mode 100644 index 000000000..c4376d5e4 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -0,0 +1,622 @@ +/* + * 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.core.data + +import com.fasterxml.jackson.annotation.JsonIgnore +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonPropertyOrder +import com.fasterxml.jackson.databind.JsonNode +import io.swagger.annotations.ApiModelProperty + +/** + * + * + * @author Brinda Santh + */ +open class EntityType { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var version: String = "1.0.0" + var metadata: MutableMap? = null + @get:JsonProperty("derived_from") + lateinit var derivedFrom: String + var attributes: MutableMap? = null + var properties: MutableMap? = null +} + +/* + 5.3.2 tosca.datatypes.Credential + The Credential type is a complex TOSCA data Type used when describing + authorization credentials used to access network accessible resources. + */ +class Credential { + @get:JsonIgnore + var id: String? = null + var protocol: String? = null + @get:JsonProperty("token_type") + lateinit var tokenType: String + lateinit var token: String + var keys: MutableMap? = null + lateinit var user: String +} + +/* +3.5.2 Constraint clause +A constraint clause defines an operation along with one or more compatible values that can be used to define a constraint on a property or parameter’s allowed values when it is defined in a TOSCA Service Template or one of its entities. + */ +class ConstraintClause { + @get:JsonProperty("equal") + var equal: JsonNode? = null + @get:JsonProperty("greater_than") + var greaterThan: Any? = null + @get:JsonProperty("greater_or_equal") + var greaterOrEqual: Any? = null + @get:JsonProperty("less_than") + var lessThan: Any? = null + @get:JsonProperty("less_or_equal") + var lessOrEqual: Any? = null + @get:JsonProperty("in_range") + var inRange: Any? = null + @get:JsonProperty("valid_values") + var validValues: MutableList? = null + @get:JsonProperty("length") + var length: Any? = null + @get:JsonProperty("min_length") + var minLength: Any? = null + @get:JsonProperty("max_length") + var maxLength: Any? = null + var pattern: String? = null + var schema: String? = null +} + +/* +3.5.4 Node Filter definition +A node filter definition defines criteria for selection of a TOSCA Node Template based upon the template’s property values, capabilities and capability properties. + */ + +class NodeFilterDefinition { + var properties: MutableMap? = null + var capabilities: MutableList? = null +} + +/* +3.5.5 Repository definition + A repository definition defines a named external repository which contains deployment + and implementation artifacts that are referenced within the TOSCA Service Template. +*/ +class RepositoryDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + lateinit var url: String + var credential: Credential? = null +} + + +/* +3.5.6 Artifact definition +An artifact definition defines a named, typed file that can be associated with Node Type +or Node Template and used by orchestration engine to facilitate deployment and implementation of interface operations. + */ +class ArtifactDefinition { + @get:JsonIgnore + var id: String? = null + var type: String? = null + var file: String? = null + var repository: String? = null + var description: String? = null + @get:JsonProperty("deploy_Path") + var deployPath: String? = null + var properties: MutableMap? = null + var content: String? = null + @Deprecated("Mapping content is define by the Type") + var mappingContent: String? = null +} + + +/* +3.5.7 Import definition +An import definition is used within a TOSCA Service Template to locate and uniquely name +another TOSCA Service Template file which has type and template definitions to be imported (included) +and referenced within another Service Template. + */ +class ImportDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var file: String + var repository: String? = null + @get:JsonProperty("namespace_uri") + var namespaceUri: String? = null + @get:JsonProperty("namespace_prefix") + var namespacePrefix: String? = null +} + +/* +3.5.8 Property definition A property definition defines a named, typed value and related data that can be associated with an +entity defined in this specification (e.g., Node Types, Relationship Types, Capability Types, etc.). +Properties are used by template authors to provide input values to TOSCA entities which indicate their “desired state” when they are +instantiated. The value of a property can be retrieved using the get_property function within TOSCA Service Templates. + */ +class PropertyDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var required: Boolean? = null + lateinit var type: String + @get:JsonProperty("default") + var defaultValue: JsonNode? = null + var status: String? = null + var constraints: MutableList? = null + @get:JsonProperty("entry_schema") + var entrySchema: EntrySchema? = null + @get:ApiModelProperty(notes = "Property Value, It may be raw JSON or primitive data type values") + var value: JsonNode? = null +} + + +/* +3.5.10 Attribute definition + +An attribute definition defines a named, typed value that can be associated with an entity defined in this +specification (e.g., a Node, Relationship or Capability Type). Specifically, it is used to expose the +“actual state” of some property of a TOSCA entity after it has been deployed and instantiated +(as set by the TOSCA orchestrator). Attribute values can be retrieved via the get_attribute function +from the instance model and used as values to other entities within TOSCA Service Templates. + */ + +class AttributeDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var required: Boolean? = null + lateinit var type: String + @JsonProperty("default") + var defaultValue: JsonNode? = null + var status: String? = null + var constraints: MutableList? = null + @JsonProperty("entry_schema") + var entrySchema: EntrySchema? = null +} + +/* +3.5.13 Operation definition +An operation definition defines a named function or procedure that can be bound to an implementation artifact (e.g., a script). + */ +class OperationDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var implementation: Implementation? = null + var inputs: MutableMap? = null + var outputs: MutableMap? = null +} + +class Implementation { + lateinit var primary: String + var dependencies: MutableList? = null +} + +/* +3.5.14 Interface definition +An interface definition defines a named interface that can be associated with a Node or Relationship Type + */ +class InterfaceDefinition { + @get:JsonIgnore + var id: String? = null + var type: String? = null + var operations: MutableMap? = null + var inputs: MutableMap? = null +} + +/* +3.5.15 Event Filter definition +An event filter definition defines criteria for selection of an attribute, for the purpose of monitoring it, within a TOSCA entity, or one its capabilities. + */ +class EventFilterDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var node: String + var requirement: String? = null + var capability: String? = null +} + +/* +3.5.16 Trigger definition TODO +A trigger definition defines the event, condition and action that is used to “trigger” a policy it is associated with. + */ +class TriggerDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + @get:JsonProperty("event_type") + lateinit var eventType: String + @get:JsonProperty("target_filter") + var targetFilter: EventFilterDefinition? = null + var condition: ConditionClause? = null + var constraint: ConditionClause? = null + var method: String? = null + lateinit var action: String +} + +/* + 3.5.17 Workflow activity definition + A workflow activity defines an operation to be performed in a TOSCA workflow. Activities allows to: + · Delegate the workflow for a node expected to be provided by the orchestrator + · Set the state of a node + · Call an operation defined on a TOSCA interface of a node, relationship or group + · Inline another workflow defined in the topology (to allow reusability) + */ +class Activity { + var delegate: String? = null + @get:JsonProperty("set_state") + var setState: String? = null + @get:JsonProperty("call_operation") + var callOperation: String? = null + var inlines: ArrayList? = null +} + +/* +3.5.20 Workflow precondition definition +A workflow condition can be used as a filter or precondition to check if a workflow can be processed or not based on the state of the instances of a TOSCA topology deployment. When not met, the workflow will not be triggered. + */ +class PreConditionDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var target: String + @get:JsonProperty("target_relationship") + lateinit var targetRelationship: String + lateinit var condition: ArrayList +} + +/* +3.5.21 Workflow step definition +A workflow step allows to define one or multiple sequenced activities in a workflow and how they are connected to other steps in the workflow. They are the building blocks of a declarative workflow. + */ +class Step { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var target: String? = null + @JsonProperty("target_relationship") + var targetRelationship: String? = null + @JsonProperty("operation_host") + var operationHost: String? = null + var activities: ArrayList? = null + @get:JsonProperty("on_success") + var onSuccess: ArrayList? = null + @get:JsonProperty("on_failure") + var onFailure: ArrayList? = null +} + +/* +3.6.2 Capability definition +A capability definition defines a named, typed set of data that can be associated with Node Type or Node Template to describe a transparent capability or feature of the software component the node describes. + */ + +class CapabilityDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var type: String + var description: String? = null + var properties: MutableMap? = null + @get:JsonProperty("valid_source_types") + var validSourceTypes: MutableList? = null + var occurrences: MutableList? = null +} + +/* +3.6.3 Requirement definition +The Requirement definition describes a named requirement (dependencies) of a TOSCA Node Type or Node template which needs to be fulfilled by a matching Capability definition declared by another TOSCA modelable entity. The requirement definition may itself include the specific name of the fulfilling entity (explicitly) or provide an abstract type, along with additional filtering characteristics, that a TOSCA orchestrator can use to fulfill the capability at runtime (implicitly). + */ +class RequirementDefinition { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var capability: String? = null + var node: String? = null + var relationship: String? = null + var occurrences: MutableList? = null +} + +/* +3.6.4 Artifact Type +An Artifact Type is a reusable entity that defines the type of one or more files that are used to define implementation or deployment artifacts that are referenced by nodes or relationships on their operations. + */ +class ArtifactType : EntityType() { + @get:JsonProperty("mime_type") + var mimeType: String? = null + @get:JsonProperty("file_ext") + var fileExt: MutableList? = null + +} + +/* +3.6.6 Data Type +A Data Type definition defines the schema for new named datatypes in TOSCA. + */ + +class DataType : EntityType() { + var constraints: MutableList? = null +} + +/* +3.6.9 Node Type +A Node Type is a reusable entity that defines the type of one or more Node Templates. As such, a Node Type defines the structure of observable properties via a Properties Definition, the Requirements and Capabilities of the node as well as its supported interfaces. + + */ + +class NodeType : EntityType() { + var capabilities: MutableMap? = null + var requirements: MutableMap? = null + var interfaces: MutableMap? = null + var artifacts: MutableMap? = null +} + +/* +3.6.8 Requirement Type +A Requirement Type is a reusable entity that describes a kind of requirement that a Node Type can declare to expose. The TOSCA Simple Profile seeks to simplify the need for declaring specific Requirement Types from nodes and instead rely upon nodes declaring their features sets using TOSCA Capability Types along with a named Feature notation. + */ + +class RequirementType : EntityType() { + var requirements: MutableMap? = null + var capabilities: MutableMap? = null + var interfaces: MutableMap? = null + var artifacts: MutableMap? = null +} + +/* +3.6.10 Relationship Type +A Relationship Type is a reusable entity that defines the type of one or more relationships between Node Types or Node Templates. +*/ + +class RelationshipType : EntityType() { + var interfaces: MutableMap? = null + @get:JsonProperty("valid_target_types") + var validTargetTypes: ArrayList? = null +} + +/* +3.6.11 Group Type +A Group Type defines logical grouping types for nodes, typically for different management purposes. +Groups can effectively be viewed as logical nodes that are not part of the physical deployment topology + of an application, yet can have capabilities and the ability to attach policies and interfaces + that can be applied (depending on the group type) to its member nodes. + */ + +class GroupType : EntityType() { + var members: MutableList? = null + var requirements: ArrayList? = null + var capabilities: MutableMap? = null + var interfaces: MutableMap? = null + +} + +/* + 3.6.12 Policy Type + A Policy Type defines a type of requirement that affects or governs an application or service’s + topology at some stage of its lifecycle, but is not explicitly part of the topology itself + (i.e., it does not prevent the application or service from being deployed or run if it did not exist). + */ +class PolicyType : EntityType() { + lateinit var targets: MutableList +} + +/* +3.7.1 Capability assignment +A capability assignment allows node template authors to assign values to properties and attributes for a named capability definition that is part of a Node Template’s type definition. + */ +class CapabilityAssignment { + @get:JsonIgnore + var id: String? = null + var attributes: MutableMap? = null + var properties: MutableMap? = null +} + +/* +3.7.4 Relationship Template +A Relationship Template specifies the occurrence of a manageable relationship between node templates as part of an application’s topology model that is defined in a TOSCA Service Template. A Relationship template is an instance of a specified Relationship Type and can provide customized properties, constraints or operations which override the defaults provided by its Relationship Type and its implementations. + */ +class GroupDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var type: String + var description: String? = null + var metadata: MutableMap? = null + var properties: MutableMap? = null + var members = ArrayList() + var interfaces: MutableMap? = null +} + +/* +3.7.6 Policy definition +A policy definition defines a policy that can be associated with a TOSCA topology or top-level entity definition (e.g., group definition, node template, etc.). + */ +class PolicyDefinition { + @get:JsonIgnore + var id: String? = null + lateinit var type: String + var description: String? = null + var metadata: MutableMap? = null + var properties: MutableMap? = null + var targets: MutableList? = null +} + + +/* +3.8 Topology Template definition +This section defines the topology template of a cloud application. The main ingredients of the topology template are node templates representing components of the application and relationship templates representing links between the components. These elements are defined in the nested node_templates section and the nested relationship_templates sections, respectively. Furthermore, a topology template allows for defining input parameters, output parameters as well as grouping of node templates. + */ +class TopologyTemplate { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var inputs: MutableMap? = null + @get:JsonProperty("node_templates") + var nodeTemplates: MutableMap? = null + @get:JsonProperty("relationship_templates") + var relationshipTemplates: MutableMap? = null + var policies: MutableMap? = null + var outputs: MutableMap? = null + @get:JsonProperty("substitution_mappings") + var substitutionMappings: Any? = null + var workflows: MutableMap? = null +} + +class SubstitutionMapping { + @get:JsonProperty("node_type") + lateinit var nodeType: String + lateinit var capabilities: ArrayList + lateinit var requirements: ArrayList +} + +class EntrySchema { + lateinit var type: String + var constraints: MutableList? = null +} + +class InterfaceAssignment { + @get:JsonIgnore + var id: String? = null + var operations: MutableMap? = null + var inputs: MutableMap? = null +} + +/* +3.7.3 Node Template +A Node Template specifies the occurrence of a manageable software component as part of an application’s topology model which is defined in a TOSCA Service Template. A Node template is an instance of a specified Node Type and can provide customized properties, constraints or operations which override the defaults provided by its Node Type and its implementations. + */ + +open class NodeTemplate { + @get:JsonIgnore + var id: String? = null + var description: String? = null + lateinit var type: String + var metadata: MutableMap? = null + var directives: MutableList? = null + //@get:JsonSerialize(using = PropertyDefinitionValueSerializer::class) + var properties: MutableMap? = null + var attributes: MutableMap? = null + var capabilities: MutableMap? = null + var requirements: MutableMap? = null + var interfaces: MutableMap? = null + var artifacts: MutableMap? = null + @get:JsonProperty("node_filter") + var nodeFilter: NodeFilterDefinition? = null + var copy: String? = null +} + +class OperationAssignment { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var implementation: Implementation? = null + var inputs: MutableMap? = null + var outputs: MutableMap? = null +} + +/* +3.7.4 Relationship Template +A Relationship Template specifies the occurrence of a manageable relationship between node templates as part of an application’s topology model that is defined in a TOSCA Service Template. A Relationship template is an instance of a specified Relationship Type and can provide customized properties, constraints or operations which override the defaults provided by its Relationship Type and its implementations. + */ + +class RelationshipTemplate { + var type: String? = null + var description: String? = null + var metadata: MutableMap? = null + var properties: MutableMap? = null + var attributes: MutableMap? = null + var interfaces: MutableMap? = null + var copy: String? = null +} + +/* +3.7.2 Requirement assignment +A Requirement assignment allows template authors to provide either concrete names of TOSCA templates or provide abstract selection criteria for providers to use to find matching TOSCA templates that are used to fulfill a named requirement’s declared TOSCA Node Type. + */ + +class RequirementAssignment { + @get:JsonIgnore + var id: String? = null + var capability: String? = null + var node: String? = null + //Relationship Type or Relationship Template + var relationship: String? = null +} + + +class Workflow { + @get:JsonIgnore + var id: String? = null + var description: String? = null + var steps: MutableMap? = null + var preconditions: ArrayList? = null + var inputs: MutableMap? = null +} + + +class ConditionClause { + var and: ArrayList>? = null + var or: ArrayList>? = null + @get:JsonProperty("assert") + var assertConditions: ArrayList>? = null +} + +/* +3.9 Service Template definition +A TOSCA Service Template (YAML) document contains element definitions of building blocks for cloud application, or complete models of cloud applications. This section describes the top-level structural elements (TOSCA keynames) along with their grammars, which are allowed to appear in a TOSCA Service Template document. + */ + +@JsonPropertyOrder(value = ["toscaDefinitionsVersion", "description", "metadata", "imports", "topologyTemplate"]) +class ServiceTemplate : Cloneable { + @get:JsonIgnore + var id: String? = null + @get:JsonProperty("tosca_definitions_version") + var toscaDefinitionsVersion: String = "controller_blueprint_1_0_0" + var metadata: MutableMap? = null + var description: String? = null + @get:JsonProperty("dsl_definitions") + var dslDefinitions: MutableMap? = null + var repositories: MutableMap? = null + var imports: MutableList? = null + @get:JsonProperty("artifact_types") + var artifactTypes: MutableMap? = null + @get:JsonProperty("data_types") + var dataTypes: MutableMap? = null + @get:JsonProperty("relationship_types") + var relationshipTypes: MutableMap? = null + @get:JsonProperty("node_types") + var nodeTypes: MutableMap? = null + @get:JsonProperty("policy_types") + var policyTypes: MutableMap? = null + @get:JsonProperty("topology_template") + var topologyTemplate: TopologyTemplate? = null + + override public fun clone(): ServiceTemplate { + return super.clone() as ServiceTemplate + } +} + +class ToscaMetaData { + lateinit var toscaMetaFileVersion: String + lateinit var csarVersion: String + lateinit var createdBy: String + lateinit var entityDefinitions: String + var templateTags: String? = null +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BlueprintErrorCode.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BlueprintErrorCode.kt new file mode 100644 index 000000000..bef174b9d --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BlueprintErrorCode.kt @@ -0,0 +1,97 @@ +/* + * Copyright © 2018-2019 Bell Canada 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.core.data + +import java.util.HashMap + +/** + * ErrorCode.java Purpose: Maintain a list of HTTP status codes + * + * @author Steve Siani + * @version 1.0 + */ +enum class ErrorCode (val value: Int, val httpCode: Int) { + + /// TODO: Add more attribute for each needed application protocol + // TODO: Example: INVALID_FILE_EXTENSION(2, 415, 25) + GENERIC_FAILURE(1, 500) { + override fun message(detailMsg: String): String { + return "Generic failure. Details : {$detailMsg}" + } + }, + INVALID_FILE_EXTENSION(2, 415) { + override fun message(detailMsg: String): String { + return "Unexpected file extension. Details : {$detailMsg}" + } + }, + BLUEPRINT_PATH_MISSING(3, 503) { + override fun message(detailMsg: String): String { + return "Blueprint path missing or wrong. Details : {$detailMsg}" + } + }, + BLUEPRINT_WRITING_FAIL(4, 503) { + override fun message(detailMsg: String): String { + return "Fail to write blueprint files. Details : {$detailMsg}" + } + }, + IO_FILE_INTERRUPT(5, 503) { + override fun message(detailMsg: String): String { + return "IO file system interruption. Details : {$detailMsg}" + } + }, + INVALID_REQUEST_FORMAT(6, 400) { + override fun message(detailMsg: String): String { + return "Bad request. Details : {$detailMsg}" + } + }, + UNAUTHORIZED_REQUEST(7, 401) { + override fun message(detailMsg: String): String { + return "The request requires user authentication. Details : {$detailMsg}" + } + }, + REQUEST_NOT_FOUND(8, 404) { + override fun message(detailMsg: String): String { + return "Request mapping doesn't exist. Details : {$detailMsg}" + } + }, + RESOURCE_NOT_FOUND(9, 404) { + override fun message(detailMsg: String): String { + return "No response was found for this request in the server. Details : {$detailMsg}" + } + }, + CONFLICT_ADDING_RESOURCE(10, 409) { + override fun message(detailMsg: String): String { + return "Duplicated entry while saving Blueprint. Details : {$detailMsg}" + } + }; + + abstract fun message(detailMsg: String): String + + companion object { + + private val map = HashMap() + + init { + for (errorCode in ErrorCode.values()) { + map[errorCode.value] = errorCode + } + } + + fun valueOf(value: Int): ErrorCode? { + return if (map.containsKey(value)) map[value] else map[1] + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt new file mode 100644 index 000000000..687b86cde --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt @@ -0,0 +1,45 @@ +/* + * 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.core.factory + + +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorService + +/** + * + * + * @author Brinda Santh + */ + +object BluePrintValidatorFactory { + + var bluePrintValidatorServices: MutableMap = HashMap() + + init { + bluePrintValidatorServices[org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.TYPE_DEFAULT] = BluePrintValidatorDefaultService() + } + + fun register(key:String, bluePrintValidatorService: BluePrintValidatorService){ + bluePrintValidatorServices[key] = bluePrintValidatorService + } + + fun instance(key : String) : BluePrintValidatorService?{ + return bluePrintValidatorServices[key] + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt new file mode 100755 index 000000000..c99cdf749 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt @@ -0,0 +1,59 @@ +/* + * 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.core.interfaces + +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import java.io.File +import java.nio.file.Path + +interface BluePrintCatalogService { + + /** + * Save the CBA to database. + * @param blueprintFile Either a directory, or an archive + * @param validate whether to validate blueprint content. Default true. + * @return The unique blueprint identifier + * @throws BluePrintException if process failed + */ + @NotNull + @Throws(BluePrintException::class) + fun saveToDatabase(@NotNull blueprintFile: File, @Nullable validate: Boolean = true): String + + /** + * Retrieve the CBA from database either archived or extracted. + * @param name Name of the blueprint + * @param version Version of the blueprint + * @param extract true to extract the content, false for archived content. Default to true + * @return Path where CBA is located + * @throws BluePrintException if process failed + */ + @NotNull + @Throws(BluePrintException::class) + fun getFromDatabase(@NotNull name: String, @NotNull version: String, @Nullable extract: Boolean = true): Path + + /** + * Delete the CBA from database. + * @param name Name of the blueprint + * @param version Version of the blueprint + * @throws BluePrintException if process failed + */ + @NotNull + @Throws(BluePrintException::class) + fun deleteFromDatabase(@NotNull name: String, @NotNull version: String) +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt new file mode 100644 index 000000000..f01f12620 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt @@ -0,0 +1,141 @@ +/* + * 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.core.interfaces + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + +interface BluePrintEnhancer { + fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T) +} + +interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer + +interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer + +interface BluePrintWorkflowEnhancer : BluePrintEnhancer + +interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer + +interface BluePrintNodeTypeEnhancer : BluePrintEnhancer + +interface BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer + +interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer + +interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer + +interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer + + +interface BluePrintEnhancerService { + + @Throws(BluePrintException::class) + fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext + + @Throws(BluePrintException::class) + fun enhance(basePath: String): BluePrintContext +} + +interface BluePrintTypeEnhancerService { + + fun getServiceTemplateEnhancers(): List + + fun getTopologyTemplateEnhancers(): List + + fun getWorkflowEnhancers(): List + + fun getNodeTemplateEnhancers(): List + + fun getNodeTypeEnhancers(): List + + fun getArtifactDefinitionEnhancers(): List + + fun getPolicyTypeEnhancers(): List + + fun getPropertyDefinitionEnhancers(): List + + fun getAttributeDefinitionEnhancers(): List + + fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) { + val enhancers = getServiceTemplateEnhancers() + doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers) + } + + fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) { + val enhancers = getTopologyTemplateEnhancers() + doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers) + } + + fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) { + val enhancers = getWorkflowEnhancers() + doEnhancement(bluePrintRuntimeService, name, workflow, enhancers) + } + + fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { + val enhancers = getNodeTemplateEnhancers() + doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers) + } + + fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) { + val enhancers = getNodeTypeEnhancers() + doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers) + } + + fun enhanceArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) { + val enhancers = getArtifactDefinitionEnhancers() + doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers) + } + + fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) { + val enhancers = getPolicyTypeEnhancers() + doEnhancement(bluePrintRuntimeService, name, policyType, enhancers) + } + + fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap) { + properties.forEach { propertyName, propertyDefinition -> + enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition) + } + } + + fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) { + val enhancers = getPropertyDefinitionEnhancers() + doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers) + } + + fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap) { + attributes.forEach { attributeName, attributeDefinition -> + enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition) + } + } + + fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) { + val enhancers = getAttributeDefinitionEnhancers() + doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers) + } + + @Suppress("UNCHECKED_CAST") + private fun doEnhancement(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, enhancers: List>) { + if (enhancers.isNotEmpty()) { + enhancers.forEach { + it.enhance(bluePrintRuntimeService, name, definition as T) + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintRepoService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintRepoService.kt new file mode 100644 index 000000000..e5ba6f4c4 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintRepoService.kt @@ -0,0 +1,47 @@ +/* + * 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.core.interfaces + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import java.io.Serializable + +/** + * BluePrintRepoFileService + * @author Brinda Santh + * + */ + +interface BluePrintRepoService : Serializable { + + @Throws(BluePrintException::class) + fun getNodeType(nodeTypeName: String): NodeType + + @Throws(BluePrintException::class) + fun getDataType(dataTypeName: String): DataType + + @Throws(BluePrintException::class) + fun getArtifactType(artifactTypeName: String): ArtifactType + + @Throws(BluePrintException::class) + fun getRelationshipType(relationshipTypeName: String): RelationshipType + + @Throws(BluePrintException::class) + fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt new file mode 100644 index 000000000..124c167a8 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt @@ -0,0 +1,25 @@ +/* + * 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.core.interfaces + +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext + +interface BluePrintScriptsService{ + + fun scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String, + reCompile: Boolean): T +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt new file mode 100644 index 000000000..0b9f1f182 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintFunctionNode.kt @@ -0,0 +1,39 @@ +/* + * 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.core.interfaces + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import java.util.function.Function + + +interface BlueprintFunctionNode : Function { + + fun getName(): String + + @Throws(BluePrintProcessorException::class) + fun prepareRequest(executionRequest: T): T + + @Throws(BluePrintProcessorException::class) + fun process(executionRequest: T) + + @Throws(BluePrintProcessorException::class) + fun recover(runtimeException: RuntimeException, executionRequest: T) + + @Throws(BluePrintProcessorException::class) + fun prepareResponse(): R + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt new file mode 100644 index 000000000..bea790fd3 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt @@ -0,0 +1,132 @@ +package org.onap.ccsdk.apps.controllerblueprints.core.interfaces + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + + +interface BluePrintValidator { + + fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T) + +} + + +interface BluePrintServiceTemplateValidator : BluePrintValidator + +interface BluePrintTopologyTemplateValidator : BluePrintValidator + +interface BluePrintArtifactTypeValidator : BluePrintValidator + +interface BluePrintDataTypeValidator : BluePrintValidator + +interface BluePrintNodeTypeValidator : BluePrintValidator + +interface BluePrintNodeTemplateValidator : BluePrintValidator + +interface BluePrintWorkflowValidator : BluePrintValidator + +interface BluePrintPropertyDefinitionValidator : BluePrintValidator + +interface BluePrintAttributeDefinitionValidator : BluePrintValidator + +/** + * Blueprint Validation Interface. + */ +interface BluePrintValidatorService { + + @Throws(BluePrintException::class) + fun validateBluePrints(basePath: String): Boolean + + @Throws(BluePrintException::class) + fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean +} + + +interface BluePrintTypeValidatorService { + + fun getServiceTemplateValidators(): List + + fun getDataTypeValidators(): List + + fun getArtifactTypeValidators(): List + + fun getNodeTypeValidators(): List + + fun getTopologyTemplateValidators(): List + + fun getNodeTemplateValidators(): List + + fun getWorkflowValidators(): List + + fun getPropertyDefinitionValidators(): List + + fun getAttributeDefinitionValidators(): List + + fun validateServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) { + val validators = getServiceTemplateValidators() + doValidation(bluePrintRuntimeService, name, serviceTemplate, validators) + } + + fun validateArtifactType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactType: ArtifactType) { + val validators = getArtifactTypeValidators() + doValidation(bluePrintRuntimeService, name, artifactType, validators) + } + + fun validateDataType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, dataType: DataType) { + val validators = getDataTypeValidators() + doValidation(bluePrintRuntimeService, name, dataType, validators) + } + + fun validateNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) { + val validators = getNodeTypeValidators() + doValidation(bluePrintRuntimeService, name, nodeType, validators) + } + + fun validateTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) { + val validators = getTopologyTemplateValidators() + doValidation(bluePrintRuntimeService, name, topologyTemplate, validators) + } + + fun validateNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { + val validators = getNodeTemplateValidators() + doValidation(bluePrintRuntimeService, name, nodeTemplate, validators) + } + + fun validateWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) { + val validators = getWorkflowValidators() + doValidation(bluePrintRuntimeService, name, workflow, validators) + } + + fun validatePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap) { + properties.forEach { propertyName, propertyDefinition -> + validatePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition) + } + } + + fun validatePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) { + val validators = getPropertyDefinitionValidators() + doValidation(bluePrintRuntimeService, name, propertyDefinition, validators) + } + + fun validateAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap) { + attributes.forEach { attributeName, attributeDefinition -> + validateAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition) + } + } + + fun validateAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) { + val validators = getAttributeDefinitionValidators() + doValidation(bluePrintRuntimeService, name, attributeDefinition, validators) + } + + @Suppress("UNCHECKED_CAST") + private fun doValidation(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, validators: List>) { + validators.forEach { + it.validate(bluePrintRuntimeService, name, definition as T) + } + } +} + + + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt new file mode 100644 index 000000000..3c637bde5 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintChainedService.kt @@ -0,0 +1,117 @@ +/* + * 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.core.service + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +/** + * + * + * @author Brinda Santh + */ +class BluePrintChainedService { + var bpc : BluePrintContext + + constructor(bpc : BluePrintContext){ + this.bpc = bpc + } + + fun nodeTypeChained(nodeTypeName: String): NodeType { + + val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName) + val attributes = hashMapOf() + val properties = hashMapOf() + val requirements = hashMapOf() + val capabilities = hashMapOf() + val interfaces = hashMapOf() + val artifacts = hashMapOf() + + recNodeTypesChained(nodeTypeName).forEach { nodeType -> + + val subAttributes = bpc.nodeTypeByName(nodeType.id!!).attributes + if (subAttributes != null) { + attributes.putAll(subAttributes) + } + + val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties + if (subProperties != null) { + properties.putAll(subProperties) + } + + val subRequirements = bpc.nodeTypeByName(nodeType.id!!).requirements + if (subRequirements != null) { + requirements.putAll(subRequirements) + } + val subCapabilities = bpc.nodeTypeByName(nodeType.id!!).capabilities + if (subCapabilities != null) { + capabilities.putAll(subCapabilities) + } + val subInterfaces = bpc.nodeTypeByName(nodeType.id!!).interfaces + if (subInterfaces != null) { + interfaces.putAll(subInterfaces) + } + + val subArtifacts = bpc.nodeTypeByName(nodeType.id!!).artifacts + if (subArtifacts != null) { + artifacts.putAll(subArtifacts) + } + } + nodeType.attributes = attributes + nodeType.properties = properties + nodeType.requirements = requirements + nodeType.capabilities = capabilities + nodeType.interfaces = interfaces + nodeType.artifacts = artifacts + return nodeType + } + + fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap? { + val nodeType = bpc.nodeTypeByName(nodeTypeName) + val properties = hashMapOf() + + recNodeTypesChained(nodeTypeName).forEach { nodeType -> + val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties + if (subProperties != null) { + properties.putAll(subProperties) + } + } + return properties + } + + private fun recNodeTypesChained(nodeTypeName: String, nodeTypes: MutableList? = arrayListOf()): MutableList { + val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName) + nodeType.id = nodeTypeName + val derivedFrom: String = nodeType.derivedFrom + if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { + recNodeTypesChained(derivedFrom, nodeTypes) + } + nodeTypes!!.add(nodeType) + return nodeTypes + } + + private fun recDataTypesChained(dataTypeName: String, dataTypes: MutableList? = arrayListOf()): MutableList { + val dataType: DataType = bpc.dataTypeByName(dataTypeName)!! + dataType.id = dataTypeName + val derivedFrom: String = dataType.derivedFrom + if (!BluePrintTypes.rootDataTypes().contains(derivedFrom)) { + recDataTypesChained(derivedFrom, dataTypes) + } + dataTypes!!.add(dataType) + return dataTypes + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt new file mode 100644 index 000000000..a0bf054b9 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt @@ -0,0 +1,254 @@ +/* + * 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. + */ +@file:Suppress("unused") + +package org.onap.ccsdk.apps.controllerblueprints.core.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils + +/** + * + * + * @author Brinda Santh + */ +class BluePrintContext(val serviceTemplate: ServiceTemplate) { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + /** + * Blueprint CBA extracted file location + */ + var rootPath = "." + /** + * Root Definition file path + */ + var entryDefinition = "" + + val imports: List? = serviceTemplate.imports + + val metadata: MutableMap? = serviceTemplate.metadata + + val dataTypes: MutableMap? = serviceTemplate.dataTypes + + val inputs: MutableMap? = serviceTemplate.topologyTemplate?.inputs + + fun blueprintJson(pretty: Boolean = false): String = print("json", pretty) + + private fun print(type: String? = "json", pretty: Boolean = false): String { + return JacksonUtils.getJson(serviceTemplate, pretty) + } + + fun name(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_NAME) + ?: throw BluePrintException("could't get template name from meta data") + + fun version(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_VERSION) + ?: throw BluePrintException("could't get template version from meta data") + + fun author(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR) + ?: throw BluePrintException("could't get template author from meta data") + + // Workflow + val workflows: MutableMap? = serviceTemplate.topologyTemplate?.workflows + + fun workflowByName(workFlowName: String): Workflow = workflows?.get(workFlowName) + ?: throw BluePrintException("could't get workflow($workFlowName)") + + fun workflowInputs(workFlowName: String) = workflowByName(workFlowName).inputs + + fun workflowStepByName(workFlowName: String, stepName: String): Step { + return workflowByName(workFlowName).steps?.get(stepName) + ?: throw BluePrintException("could't get step($stepName) for workflow($workFlowName)") + } + + fun workflowStepNodeTemplate(workFlowName: String, stepName: String): String { + return workflowStepByName(workFlowName, stepName).target + ?: throw BluePrintException("could't get node template name for workflow($workFlowName)'s step($stepName)") + } + + fun workflowFirstStepNodeTemplate(workFlowName: String): String { + val firstStepName = workflowByName(workFlowName).steps?.keys?.first() + ?: throw BluePrintException("could't get first step for workflow($workFlowName)") + return workflowStepNodeTemplate(workFlowName, firstStepName) + } + + fun workflowStepFirstCallOperation(workFlowName: String, stepName: String): String { + return workflowStepByName(workFlowName, stepName).activities?.filter { it.callOperation != null }?.single()?.callOperation + ?: throw BluePrintException("could't get first callOperation for WorkFlow($workFlowName) ") + } + + // Data Type + fun dataTypeByName(name: String): DataType? = dataTypes?.get(name) + + // Artifact Type + val artifactTypes: MutableMap? = serviceTemplate.artifactTypes + + // Policy Types + val policyTypes: MutableMap? = serviceTemplate.policyTypes + + fun policyTypeByName(policyName: String) = policyTypes?.get(policyName) + ?: throw BluePrintException("could't get policy type for the name($policyName)") + + fun policyTypesDerivedFrom(name: String): MutableMap? { + return policyTypes?.filterValues { policyType -> policyType.derivedFrom == name }?.toMutableMap() + } + + fun policyTypesTarget(target: String): MutableMap? { + return policyTypes?.filterValues { it.targets.contains(target) }?.toMutableMap() + } + + fun policyTypesTargetNDerivedFrom(target: String, derivedFrom: String): MutableMap? { + return policyTypesDerivedFrom(derivedFrom)?.filterValues { + it.targets.contains(target) + }?.toMutableMap() + } + + // Node Type Methods + val nodeTypes: MutableMap? = serviceTemplate.nodeTypes + + fun nodeTypeByName(name: String): NodeType = + nodeTypes?.get(name) + ?: throw BluePrintException("could't get node type for the name($name)") + + fun nodeTypeDerivedFrom(name: String): MutableMap? { + return nodeTypes?.filterValues { nodeType -> nodeType.derivedFrom == name }?.toMutableMap() + } + + fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition { + return nodeTypeByName(nodeTypeName).interfaces?.get(interfaceName) + ?: throw BluePrintException("could't get node type($nodeTypeName)'s interface definition($interfaceName)") + } + + fun nodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, operationName: String): OperationDefinition { + return nodeTypeInterface(nodeTypeName, interfaceName).operations?.get(operationName) + ?: throw BluePrintException("could't get node type($nodeTypeName)'s interface definition($interfaceName) operation definition($operationName)") + } + + fun interfaceNameForNodeType(nodeTypeName: String): String { + return nodeTypeByName(nodeTypeName).interfaces?.keys?.first() + ?: throw BluePrintException("could't get NodeType($nodeTypeName)'s first InterfaceDefinition name") + } + + fun nodeTypeInterfaceOperationInputs(nodeTypeName: String, interfaceName: String, operationName: String): MutableMap? { + return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName).inputs + } + + fun nodeTypeInterfaceOperationOutputs(nodeTypeName: String, interfaceName: String, operationName: String): MutableMap? { + return nodeTypeInterfaceOperation(nodeTypeName, interfaceName, operationName).outputs + } + + // Node Template Methods + val nodeTemplates: MutableMap? = serviceTemplate.topologyTemplate?.nodeTemplates + + fun nodeTemplateByName(name: String): NodeTemplate = + nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name)") + + fun nodeTemplateForNodeType(name: String): MutableMap? { + return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap() + } + + fun nodeTemplateNodeType(nodeTemplateName: String): NodeType { + val nodeTemplateType: String = nodeTemplateByName(nodeTemplateName).type + return nodeTypeByName(nodeTemplateType) + } + + fun nodeTemplateProperty(nodeTemplateName: String, propertyName: String): Any? { + return nodeTemplateByName(nodeTemplateName).properties?.get(propertyName) + } + + fun nodeTemplateArtifacts(nodeTemplateName: String): MutableMap? { + return nodeTemplateByName(nodeTemplateName).artifacts + } + + fun nodeTemplateArtifact(nodeTemplateName: String, artifactName: String): ArtifactDefinition { + return nodeTemplateArtifacts(nodeTemplateName)?.get(artifactName) + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s ArtifactDefinition($artifactName)") + } + + fun nodeTemplateArtifactForArtifactType(nodeTemplateName: String, artifactType: String): ArtifactDefinition { + return nodeTemplateArtifacts(nodeTemplateName)?.filter { it.value.type == artifactType }?.map { it.value }?.get(0) + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s Artifact Type($artifactType)") + } + + fun nodeTemplateFirstInterface(nodeTemplateName: String): InterfaceAssignment { + return nodeTemplateByName(nodeTemplateName).interfaces?.values?.first() + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s first InterfaceAssignment") + } + + fun nodeTemplateFirstInterfaceName(nodeTemplateName: String): String { + return nodeTemplateByName(nodeTemplateName).interfaces?.keys?.first() + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s first InterfaceAssignment name") + } + + fun nodeTemplateFirstInterfaceFirstOperationName(nodeTemplateName: String): String { + return nodeTemplateFirstInterface(nodeTemplateName).operations?.keys?.first() + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s first InterfaceAssignment's first OperationAssignment name") + } + + fun nodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap? { + return nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName).inputs + } + + fun nodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap? { + return nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName).outputs + } + + fun nodeTemplateInterface(nodeTemplateName: String, interfaceName: String): InterfaceAssignment { + return nodeTemplateByName(nodeTemplateName).interfaces?.get(interfaceName) + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s InterfaceAssignment($interfaceName)") + } + + fun nodeTemplateInterfaceOperation(nodeTemplateName: String, interfaceName: String, operationName: String): OperationAssignment { + return nodeTemplateInterface(nodeTemplateName, interfaceName).operations?.get(operationName) + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s InterfaceAssignment($interfaceName) OperationAssignment($operationName)") + } + + fun nodeTemplateCapability(nodeTemplateName: String, capabilityName: String): CapabilityAssignment { + return nodeTemplateByName(nodeTemplateName).capabilities?.get(capabilityName) + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s CapabilityAssignment($capabilityName)") + } + + fun nodeTemplateRequirement(nodeTemplateName: String, requirementName: String): RequirementAssignment { + return nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName) + ?: throw BluePrintException("could't get NodeTemplate($nodeTemplateName)'s first RequirementAssignment($requirementName)") + } + + fun nodeTemplateRequirementNode(nodeTemplateName: String, requirementName: String): NodeTemplate { + val filteredNodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node + ?: throw BluePrintException("could't NodeTemplate for NodeTemplate's($nodeTemplateName) requirement's ($requirementName) ") + return nodeTemplateByName(filteredNodeTemplateName) + } + + fun nodeTemplateCapabilityProperty(nodeTemplateName: String, capabilityName: String, propertyName: String): Any? { + return nodeTemplateCapability(nodeTemplateName, capabilityName).properties?.get(propertyName) + } + + // Chained Functions + + fun nodeTypeChained(nodeTypeName: String): NodeType { + return BluePrintChainedService(this).nodeTypeChained(nodeTypeName) + } + + fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap? { + return BluePrintChainedService(this).nodeTypeChainedProperties(nodeTypeName) + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt new file mode 100644 index 000000000..caa02dbce --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt @@ -0,0 +1,173 @@ +/* + * 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.core.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.ArrayNode +import com.fasterxml.jackson.databind.node.ObjectNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.* + +/** + * + * + * @author Brinda Santh + */ +object BluePrintExpressionService { + val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @JvmStatic + fun getExpressionData(propertyAssignmentNode: JsonNode): ExpressionData { + log.trace("Assignment Data/Expression : {}", propertyAssignmentNode) + val expressionData = ExpressionData(valueNode = propertyAssignmentNode) + if (propertyAssignmentNode is ObjectNode) { + + val commands: Set = propertyAssignmentNode.fieldNames().asSequence().toList().intersect(BluePrintTypes.validCommands()) + if (commands.isNotEmpty()) { + expressionData.isExpression = true + expressionData.command = commands.first() + expressionData.expressionNode = propertyAssignmentNode + + when (expressionData.command) { + BluePrintConstants.EXPRESSION_GET_INPUT -> { + expressionData.inputExpression = populateInputExpression(propertyAssignmentNode) + } + BluePrintConstants.EXPRESSION_GET_ATTRIBUTE -> { + expressionData.attributeExpression = populateAttributeExpression(propertyAssignmentNode) + } + BluePrintConstants.EXPRESSION_GET_PROPERTY -> { + expressionData.propertyExpression = populatePropertyExpression(propertyAssignmentNode) + } + BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT -> { + expressionData.operationOutputExpression = populateOperationOutputExpression(propertyAssignmentNode) + } + BluePrintConstants.EXPRESSION_GET_ARTIFACT -> { + expressionData.artifactExpression = populateArtifactExpression(propertyAssignmentNode) + } + } + } + } + return expressionData + } + + @JvmStatic + fun populateInputExpression(jsonNode: JsonNode): InputExpression { + return InputExpression(propertyName = jsonNode.first().textValue()) + } + + @JvmStatic + fun populatePropertyExpression(jsonNode: JsonNode): PropertyExpression { + val arrayNode: ArrayNode = jsonNode.first() as ArrayNode + check(arrayNode.size() >= 2) { + throw BluePrintException(String.format("missing property expression, " + + "it should be [ , , , " + + ", ..., ] , but present {}", jsonNode)) + } + var reqOrCapEntityName: String? = null + var propertyName = "" + var subProperty: String? = null + when { + arrayNode.size() == 2 -> propertyName = arrayNode[1].textValue() + arrayNode.size() == 3 -> { + reqOrCapEntityName = arrayNode[1].textValue() + propertyName = arrayNode[2].textValue() + } + arrayNode.size() > 3 -> { + reqOrCapEntityName = arrayNode[1].textValue() + propertyName = arrayNode[2].textValue() + val propertyPaths: List = arrayNode.filterIndexed { index, _ -> + index >= 3 + }.map { it.textValue() } + subProperty = propertyPaths.joinToString("/") + } + } + + return PropertyExpression(modelableEntityName = arrayNode[0].asText(), + reqOrCapEntityName = reqOrCapEntityName, + propertyName = propertyName, + subPropertyName = subProperty + ) + } + + @JvmStatic + fun populateAttributeExpression(jsonNode: JsonNode): AttributeExpression { + val arrayNode: ArrayNode = jsonNode.first() as ArrayNode + check(arrayNode.size() >= 2) { + throw BluePrintException(String.format("missing attribute expression, " + + "it should be [ , , ," + + " , ..., ] , but present {}", jsonNode)) + } + + var reqOrCapEntityName: String? = null + var attributeName = "" + var subAttributeName: String? = null + when { + arrayNode.size() == 2 -> attributeName = arrayNode[1].textValue() + arrayNode.size() == 3 -> { + reqOrCapEntityName = arrayNode[1].textValue() + attributeName = arrayNode[2].textValue() + } + arrayNode.size() > 3 -> { + reqOrCapEntityName = arrayNode[1].textValue() + attributeName = arrayNode[2].textValue() + val propertyPaths: List = arrayNode.filterIndexed { index, _ -> + index >= 3 + }.map { it.textValue() } + subAttributeName = propertyPaths.joinToString("/") + } + } + return AttributeExpression(modelableEntityName = arrayNode[0].asText(), + reqOrCapEntityName = reqOrCapEntityName, + attributeName = attributeName, + subAttributeName = subAttributeName + ) + } + + @JvmStatic + fun populateOperationOutputExpression(jsonNode: JsonNode): OperationOutputExpression { + val arrayNode: ArrayNode = jsonNode.first() as ArrayNode + + check(arrayNode.size() >= 4) { + throw BluePrintException(String.format("missing operation output expression, " + + "it should be (, , , ) , but present {}", jsonNode)) + } + return OperationOutputExpression(modelableEntityName = arrayNode[0].asText(), + interfaceName = arrayNode[1].asText(), + operationName = arrayNode[2].asText(), + propertyName = arrayNode[3].asText() + ) + } + + @JvmStatic + fun populateArtifactExpression(jsonNode: JsonNode): ArtifactExpression { + val arrayNode: ArrayNode = jsonNode.first() as ArrayNode + + check(arrayNode.size() >= 2) { + throw BluePrintException(String.format("missing artifact expression, " + + "it should be [ , , , ] , but present {}", jsonNode)) + } + return ArtifactExpression(modelableEntityName = arrayNode[0].asText(), + artifactName = arrayNode[1].asText(), + location = arrayNode[2]?.asText() ?: "LOCAL_FILE", + remove = arrayNode[3]?.asBoolean() ?: false + ) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt new file mode 100644 index 000000000..26eb19de1 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt @@ -0,0 +1,96 @@ +/* + * 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.core.service + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.ImportDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import java.io.File +import java.net.URL +import java.net.URLDecoder +import java.nio.charset.Charset + +class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate, private val blueprintBasePath: String) { + companion object { + private const val PARENT_SERVICE_TEMPLATE: String = "parent" + } + + private val log: Logger = LoggerFactory.getLogger(this::class.toString()) + + private var importServiceTemplateMap: MutableMap = hashMapOf() + + + fun getImportResolvedServiceTemplate(): ServiceTemplate { + // Populate Imported Service Templates + traverseSchema(PARENT_SERVICE_TEMPLATE, parentServiceTemplate) + + importServiceTemplateMap.forEach { key, serviceTemplate -> + ServiceTemplateUtils.merge(parentServiceTemplate, serviceTemplate) + log.debug("merged service template $key") + } + return parentServiceTemplate + } + + private fun traverseSchema(key: String, serviceTemplate: ServiceTemplate) { + if (key != PARENT_SERVICE_TEMPLATE) { + importServiceTemplateMap[key] = serviceTemplate + } + val imports: List? = serviceTemplate.imports + + imports?.let { + serviceTemplate.imports?.forEach { importDefinition -> + val childServiceTemplate = resolveImportDefinition(importDefinition) + val keyName: String = importDefinition.file + traverseSchema(keyName, childServiceTemplate) + } + } + } + + private fun resolveImportDefinition(importDefinition: ImportDefinition): ServiceTemplate { + var serviceTemplate: ServiceTemplate? = null + val file: String = importDefinition.file + val decodedSystemId: String = URLDecoder.decode(file, Charset.defaultCharset().toString()) + log.trace("file ({}), decodedSystemId ({}) ", file, decodedSystemId) + try { + if (decodedSystemId.startsWith("http", true) + || decodedSystemId.startsWith("https", true)) { + val givenUrl: String = URL(decodedSystemId).toString() + val systemUrl: String = File(".").toURI().toURL().toString() + log.trace("givenUrl ({}), systemUrl ({}) ", givenUrl, systemUrl) + if (givenUrl.startsWith(systemUrl)) { + + } + } else { + if (!decodedSystemId.startsWith("/")) { + importDefinition.file = StringBuilder().append(blueprintBasePath).append(File.separator).append(file).toString() + } + serviceTemplate = ServiceTemplateUtils.getServiceTemplate(importDefinition.file) + } + } catch (e: Exception) { + throw BluePrintException("failed to populate service template for ${importDefinition.file}", e) + } + if (serviceTemplate == null) { + throw BluePrintException("failed to populate service template for : ${importDefinition.file}") + } + return serviceTemplate + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt new file mode 100644 index 000000000..b1d67ece9 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt @@ -0,0 +1,62 @@ +/* + * 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.core.service + +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import java.io.File +import java.io.Serializable + +/** + * + * + * @author Brinda Santh + */ +interface BluePrintParserService : Serializable { + fun readBlueprint(content: String) : BluePrintContext + fun readBlueprintFile(fileName: String) : BluePrintContext + /** + * Read Blueprint from CSAR structure Directory + */ + fun readBlueprintFile(fileName: String, basePath : String) : BluePrintContext +} + +class BluePrintParserDefaultService : BluePrintParserService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + var basePath : String = javaClass.classLoader.getResource(".").path + + override fun readBlueprint(content: String): BluePrintContext { + return BluePrintContext(ServiceTemplateUtils.getServiceTemplateFromContent(content)) + } + + override fun readBlueprintFile(fileName: String): BluePrintContext { + return readBlueprintFile(fileName, basePath ) + } + + override fun readBlueprintFile(fileName: String, basePath : String): BluePrintContext { + val rootFilePath: String = StringBuilder().append(basePath).append(File.separator).append(fileName).toString() + val rootServiceTemplate : ServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath) + // TODO("Nested Lookup Implementation based on Import files") + return BluePrintContext(rootServiceTemplate) + } + + +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileService.kt new file mode 100644 index 000000000..5d6ca7573 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileService.kt @@ -0,0 +1,71 @@ +/* + * 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.core.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils + +open class BluePrintRepoFileService(modelTypePath: String) : BluePrintRepoService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRepoFileService::class.toString()) + + private val dataTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + private val nodeTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + private val artifactTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + private val capabilityTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + private val relationshipTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + private val extension = ".json" + + override fun getDataType(dataTypeName: String): DataType { + val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(dataTypeName).plus(extension) + return getModelType(fileName, DataType::class.java) + } + + override fun getNodeType(nodeTypeName: String): NodeType { + val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension) + return getModelType(fileName, NodeType::class.java) + } + + override fun getArtifactType(artifactTypeName: String): ArtifactType { + val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(artifactTypeName).plus(extension) + return getModelType(fileName, ArtifactType::class.java) + } + + override fun getRelationshipType(relationshipTypeName: String): RelationshipType { + val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(relationshipTypeName).plus(extension) + return getModelType(fileName, RelationshipType::class.java) + } + + override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition { + val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(capabilityDefinitionName).plus(extension) + return getModelType(fileName, CapabilityDefinition::class.java) + } + + private fun getModelType(fileName: String, valueType: Class): T { + return JacksonUtils.readValueFromFile(fileName, valueType) + ?: throw BluePrintException("couldn't get file($fileName) for type(${valueType.name}") + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt new file mode 100644 index 000000000..5c10f80c9 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -0,0 +1,501 @@ +/* + * 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.core.service + + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import com.fasterxml.jackson.databind.node.ObjectNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils + +interface BluePrintRuntimeService { + + fun id(): String + + fun bluePrintContext(): BluePrintContext + + fun getExecutionContext(): T + + fun setExecutionContext(executionContext: T) + + fun put(key: String, value: JsonNode) + + fun get(key: String): JsonNode? + + fun check(key: String): Boolean + + fun cleanRuntime() + + fun getAsString(key: String): String? + + fun getAsBoolean(key: String): Boolean? + + fun getAsInt(key: String): Int? + + fun getAsDouble(key: String): Double? + + fun getBluePrintError(): BluePrintError + + fun setBluePrintError(bluePrintError: BluePrintError) + + fun resolveNodeTemplatePropertyAssignments(nodeTemplateName: String, + propertyDefinitions: MutableMap, + propertyAssignments: MutableMap): MutableMap + + fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap + + fun resolveNodeTemplateCapabilityProperties(nodeTemplateName: String, capabilityName: String): MutableMap + + fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, + operationName: String): MutableMap + + fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, interfaceName: String, + operationName: String): MutableMap + + fun resolveNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): String + + fun resolveNodeTemplateArtifactDefinition(nodeTemplateName: String, artifactName: String): ArtifactDefinition + + fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) + + fun setWorkflowInputValue(workflowName: String, propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) + + fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) + + fun setNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String, value: JsonNode) + + fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, value: JsonNode) + + fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, value: JsonNode) + + fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, value: JsonNode) + + fun getInputValue(propertyName: String): JsonNode + + fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String): JsonNode + + fun getNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? + + fun getNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String): JsonNode? + + fun assignInputs(jsonNode: JsonNode) + + fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) + + fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List): JsonNode +} + +/** + * + * + * @author Brinda Santh + */ +open class DefaultBluePrintRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext) + : BluePrintRuntimeService> { + + @Transient + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRuntimeService::class.toString()) + + private var store: MutableMap = hashMapOf() + + private var bluePrintError = BluePrintError() + + override fun id(): String { + return id + } + + override fun bluePrintContext(): BluePrintContext { + return bluePrintContext + } + + override fun getExecutionContext(): MutableMap { + return store + } + + @Suppress("UNCHECKED_CAST") + override fun setExecutionContext(executionContext: MutableMap) { + this.store = executionContext + } + + override fun put(key: String, value: JsonNode) { + store[key] = value + } + + override fun get(key: String): JsonNode { + return store[key] ?: throw BluePrintProcessorException("failed to get execution property($key)") + } + + override fun check(key: String): Boolean { + return store.containsKey(key) + } + + override fun cleanRuntime() { + store.clear() + } + + private fun getJsonNode(key: String): JsonNode { + return get(key) + } + + override fun getAsString(key: String): String? { + return get(key).asText() + } + + override fun getAsBoolean(key: String): Boolean? { + return get(key).asBoolean() + } + + override fun getAsInt(key: String): Int? { + return get(key).asInt() + } + + override fun getAsDouble(key: String): Double? { + return get(key).asDouble() + } + + override fun getBluePrintError(): BluePrintError { + return this.bluePrintError + } + + override fun setBluePrintError(bluePrintError: BluePrintError) { + this.bluePrintError = bluePrintError + } + + /** + * Resolve any property assignments for the node + */ + override fun resolveNodeTemplatePropertyAssignments(nodeTemplateName: String, + propertyDefinitions: MutableMap, + propertyAssignments: MutableMap) + : MutableMap { + + val propertyAssignmentValue: MutableMap = hashMapOf() + + propertyDefinitions.forEach { nodeTypePropertyName, nodeTypeProperty -> + // Get the Express or Value for the Node Template + val propertyAssignment: JsonNode? = propertyAssignments[nodeTypePropertyName] + + var resolvedValue: JsonNode = NullNode.getInstance() + if (propertyAssignment != null) { + // Resolve the Expressing + val propertyAssignmentExpression = PropertyAssignmentService(this) + resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, + nodeTypePropertyName, propertyAssignment) + } else { + // Assign default value to the Operation + nodeTypeProperty.defaultValue?.let { + resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!) + } + } + // Set for Return of method + propertyAssignmentValue[nodeTypePropertyName] = resolvedValue + } + return propertyAssignmentValue + } + + override fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { + log.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName) + + val nodeTemplate: NodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) + + val propertyAssignments: MutableMap = nodeTemplate.properties!! + + // Get the Node Type Definitions + val nodeTypePropertieDefinitions: MutableMap = bluePrintContext + .nodeTypeChainedProperties(nodeTemplate.type)!! + + /** + * Resolve the NodeTemplate Property Assignment Values. + */ + return resolveNodeTemplatePropertyAssignments(nodeTemplateName, nodeTypePropertieDefinitions, + propertyAssignments) + } + + override fun resolveNodeTemplateCapabilityProperties(nodeTemplateName: String, capabilityName: String): + MutableMap { + log.info("resolveNodeTemplateCapabilityProperties for node template($nodeTemplateName) capability " + + "($capabilityName)") + val nodeTemplate: NodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) + + val propertyAssignments = nodeTemplate.capabilities?.get(capabilityName)?.properties ?: hashMapOf() + + val propertyDefinitions = bluePrintContext.nodeTemplateNodeType(nodeTemplateName) + .capabilities?.get(capabilityName)?.properties ?: hashMapOf() + + /** + * Resolve the Capability Property Assignment Values. + */ + return resolveNodeTemplatePropertyAssignments(nodeTemplateName, propertyDefinitions, + propertyAssignments) + } + + override fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, + interfaceName: String, + operationName: String): MutableMap { + log.info("resolveNodeTemplateInterfaceOperationInputs for node template ($nodeTemplateName),interface name " + + "($interfaceName), operationName($operationName)") + + val propertyAssignments: MutableMap = + bluePrintContext.nodeTemplateInterfaceOperationInputs(nodeTemplateName, interfaceName, operationName) + ?: hashMapOf() + + val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type + + val nodeTypeInterfaceOperationInputs: MutableMap = + bluePrintContext.nodeTypeInterfaceOperationInputs(nodeTypeName, interfaceName, operationName) + ?: hashMapOf() + + log.info("input definition for node template ($nodeTemplateName), values ($propertyAssignments)") + + /** + * Resolve the Property Input Assignment Values. + */ + return resolveNodeTemplatePropertyAssignments(nodeTemplateName, nodeTypeInterfaceOperationInputs, + propertyAssignments) + + } + + + override fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, + interfaceName: String, + operationName: String): MutableMap { + log.info("resolveNodeTemplateInterfaceOperationOutputs for node template ($nodeTemplateName),interface name " + + "($interfaceName), operationName($operationName)") + + val propertyAssignments: MutableMap = + bluePrintContext.nodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName) + ?: hashMapOf() + + val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type + + val nodeTypeInterfaceOperationOutputs: MutableMap = + bluePrintContext.nodeTypeInterfaceOperationOutputs(nodeTypeName, interfaceName, operationName) + ?: hashMapOf() + /** + * Resolve the Property Output Assignment Values. + */ + val propertyAssignmentValue = resolveNodeTemplatePropertyAssignments(nodeTemplateName, + nodeTypeInterfaceOperationOutputs, propertyAssignments) + + // Store operation output values into context + propertyAssignmentValue.forEach { key, value -> + setNodeTemplateOperationOutputValue(nodeTemplateName, interfaceName, operationName, key, value) + } + return propertyAssignmentValue + } + + override fun resolveNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): String { + val artifactDefinition: ArtifactDefinition = resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) + val propertyAssignmentExpression = PropertyAssignmentService(this) + return propertyAssignmentExpression.artifactContent(artifactDefinition) + } + + override fun resolveNodeTemplateArtifactDefinition(nodeTemplateName: String, artifactName: String): ArtifactDefinition { + val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) + + return nodeTemplate.artifacts?.get(artifactName) + ?: throw BluePrintProcessorException("failed to get artifat definition($artifactName) from the node " + + "template") + + } + + override fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) { + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + log.trace("setting input path ({}), values ({})", path, value) + put(path, value) + } + + override fun setWorkflowInputValue(workflowName: String, propertyName: String, + propertyDefinition: PropertyDefinition, value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_WORKFLOWS) + .append(BluePrintConstants.PATH_DIVIDER).append(workflowName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + put(path, value) + } + + override fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) { + + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + put(path, value) + } + + override fun setNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String, value: JsonNode) { + + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) + .append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString() + put(path, value) + } + + override fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) + .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) + .append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + log.trace("setting operation property path ({}), values ({})", path, value) + put(path, value) + } + + override fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) + .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) + .append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + put(path, value) + } + + override fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) + .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) + .append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + put(path, value) + } + + + override fun getInputValue(propertyName: String): JsonNode { + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + return getJsonNode(path) + } + + override fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, + operationName: String, propertyName: String): JsonNode { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES) + .append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS) + .append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + return getJsonNode(path) + } + + override fun getNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String): JsonNode { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + return getJsonNode(path) + } + + override fun getNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String): JsonNode { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) + .append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString() + return getJsonNode(path) + } + + override fun assignInputs(jsonNode: JsonNode) { + log.info("assignInputs from input JSON ({})", jsonNode.toString()) + bluePrintContext.inputs?.forEach { propertyName, property -> + val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() + setInputValue(propertyName, property, valueNode) + } + } + + override fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) { + log.info("assign workflow {} input value ({})", workflowName, jsonNode.toString()) + + val dynamicInputPropertiesName = "$workflowName-properties" + + bluePrintContext.workflowByName(workflowName).inputs?.forEach { propertyName, property -> + if (propertyName != dynamicInputPropertiesName) { + val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() + setInputValue(propertyName, property, valueNode) + } + } + // Load Dynamic data Types + val workflowDynamicInputs: JsonNode? = jsonNode.get(dynamicInputPropertiesName) + + workflowDynamicInputs?.let { + bluePrintContext.dataTypeByName("dt-$dynamicInputPropertiesName")?.properties?.forEach { propertyName, property -> + val valueNode: JsonNode = workflowDynamicInputs.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() + setInputValue(propertyName, property, valueNode) + + } + } + } + + override fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List): JsonNode { + + val jsonNode: ObjectNode = jacksonObjectMapper().createObjectNode() + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES) + .append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES) + .append(BluePrintConstants.PATH_DIVIDER).toString() + store.keys.filter { + it.startsWith(path) + }.map { + val key = it.replace(path, "") + if (keys.contains(key)) { + val value = store[it] as JsonNode + jsonNode.set(key, value) + } + } + return jsonNode + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintTemplateService.kt new file mode 100644 index 000000000..d175fddea --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintTemplateService.kt @@ -0,0 +1,94 @@ +/* + * 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.core.service + +import com.fasterxml.jackson.core.io.CharTypes +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.JsonNodeFactory +import com.fasterxml.jackson.databind.node.TextNode +import org.apache.commons.lang3.BooleanUtils +import org.apache.commons.lang3.StringUtils +import org.apache.velocity.VelocityContext +import org.apache.velocity.app.Velocity +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import java.io.StringWriter + +open class BluePrintTemplateService { + + companion object { + + /** + * Generate Content from Velocity Template and JSON Content. + */ + fun generateContent(template: String, json: String, + ignoreJsonNull: Boolean = false, + additionalContext: MutableMap = hashMapOf()): String { + Velocity.init() + val mapper = ObjectMapper() + val nodeFactory = BluePrintJsonNodeFactory() + mapper.setNodeFactory(nodeFactory) + + val jsonNode = mapper.readValue(json, JsonNode::class.java) + ?: throw BluePrintProcessorException("couldn't get json node from json") + + if (ignoreJsonNull) + JacksonUtils.removeJsonNullNode(jsonNode) + + val velocityContext = VelocityContext() + velocityContext.put("StringUtils", StringUtils::class.java) + velocityContext.put("BooleanUtils", BooleanUtils::class.java) + /** + * Add the Custom Velocity Context API + */ + additionalContext.forEach { name, value -> velocityContext.put(name, value) } + /** + * Add the JSON Data to the context + */ + jsonNode.fields().forEach { entry -> + velocityContext.put(entry.key, entry.value) + } + + val stringWriter = StringWriter() + Velocity.evaluate(velocityContext, stringWriter, "TemplateData", template) + stringWriter.flush() + return stringWriter.toString() + } + } +} + +/** + * Customise JsonNodeFactory adn TextNode, Since it introduces quotes for string data. + */ +open class BluePrintJsonNodeFactory : JsonNodeFactory() { + override fun textNode(text: String): TextNode { + return BluePrintTextNode(text) + } +} + +open class BluePrintTextNode(v: String) : TextNode(v) { + override fun toString(): String { + var len = this._value.length + len = len + 2 + (len shr 4) + val sb = StringBuilder(len) + CharTypes.appendQuoted(sb, this._value) + return sb.toString() + } + +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt new file mode 100644 index 000000000..9ee53146b --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt @@ -0,0 +1,607 @@ +/* + * 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.core.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.google.common.base.Preconditions +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.* +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import java.io.Serializable + +/** + * + * + * @author Brinda Santh + */ +interface BluePrintValidatorService : Serializable { + + @Throws(BluePrintException::class) + fun validateBlueprint(bluePrintContext: BluePrintContext, properties: MutableMap) + + @Throws(BluePrintException::class) + fun validateBlueprint(serviceTemplate: ServiceTemplate, properties: MutableMap) +} + +open class BluePrintValidatorDefaultService : BluePrintValidatorService { + + val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorDefaultService::class.toString()) + + lateinit var bluePrintContext: BluePrintContext + lateinit var serviceTemplate: ServiceTemplate + lateinit var properties: MutableMap + var message: StringBuilder = StringBuilder() + private val separator: String = BluePrintConstants.PATH_DIVIDER + var paths: MutableList = arrayListOf() + + @Throws(BluePrintException::class) + override fun validateBlueprint(bluePrintContext: BluePrintContext, properties: MutableMap) { + validateBlueprint(bluePrintContext.serviceTemplate, properties) + } + + @Throws(BluePrintException::class) + override fun validateBlueprint(serviceTemplate: ServiceTemplate, properties: MutableMap) { + this.bluePrintContext = BluePrintContext(serviceTemplate) + this.serviceTemplate = serviceTemplate + this.properties = properties + try { + message.appendln("-> Config Blueprint") + serviceTemplate.metadata?.let { validateMetadata(serviceTemplate.metadata!!) } + serviceTemplate.artifactTypes?.let { validateArtifactTypes(serviceTemplate.artifactTypes!!) } + serviceTemplate.dataTypes?.let { validateDataTypes(serviceTemplate.dataTypes!!) } + serviceTemplate.nodeTypes?.let { validateNodeTypes(serviceTemplate.nodeTypes!!) } + serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) } + } catch (e: Exception) { + log.error("validation failed in the path : {}", paths.joinToString(separator), e) + log.error("validation trace message :{} ", message) + throw BluePrintException(e, + format("failed to validate blueprint on path ({}) with message {}" + , paths.joinToString(separator), e.message)) + } + } + + @Throws(BluePrintException::class) + open fun validateMetadata(metaDataMap: MutableMap) { + paths.add("metadata") + + val templateName = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME] + val templateVersion = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION] + val templateTags = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS] + val templateAuthor = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] + + Preconditions.checkArgument(StringUtils.isNotBlank(templateName), "failed to get template name metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateVersion), "failed to get template version metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateTags), "failed to get template tags metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateAuthor), "failed to get template author metadata") + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateArtifactTypes(artifactTypes: MutableMap) { + paths.add("artifact_types") + artifactTypes.forEach { artifactName, artifactType -> + paths.add(artifactName) + message.appendln("--> Artifact Type :" + paths.joinToString(separator)) + artifactType.properties?.let { validatePropertyDefinitions(artifactType.properties!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateDataTypes(dataTypes: MutableMap) { + paths.add("dataTypes") + dataTypes.forEach { dataTypeName, dataType -> + paths.add(dataTypeName) + message.appendln("--> DataType :" + paths.joinToString(separator)) + dataType.properties?.let { validatePropertyDefinitions(dataType.properties!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateNodeTypes(nodeTypes: MutableMap) { + paths.add("nodeTypes") + nodeTypes.forEach { nodeTypeName, nodeType -> + // Validate Single Node Type + validateNodeType(nodeTypeName, nodeType) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateNodeType(nodeTypeName: String, nodeType: NodeType) { + paths.add(nodeTypeName) + message.appendln("--> Node Type :" + paths.joinToString(separator)) + val derivedFrom: String = nodeType.derivedFrom + //Check Derived From + checkValidNodeTypesDerivedFrom(nodeTypeName, derivedFrom) + + if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { + serviceTemplate.nodeTypes?.get(derivedFrom) + ?: throw BluePrintException(format("Failed to get derivedFrom NodeType({})'s for NodeType({}) ", + derivedFrom, nodeTypeName)) + } + + nodeType.properties?.let { validatePropertyDefinitions(nodeType.properties!!) } + nodeType.capabilities?.let { validateCapabilityDefinitions(nodeTypeName, nodeType) } + nodeType.requirements?.let { validateRequirementDefinitions(nodeTypeName, nodeType) } + nodeType.interfaces?.let { validateInterfaceDefinitions(nodeType.interfaces!!) } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun checkValidNodeTypesDerivedFrom(nodeTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validNodeTypeDerivedFroms.contains(derivedFrom)) { + throw BluePrintException(format("Failed to get node type ({})'s derivedFrom({}) definition ", nodeTypeName, derivedFrom)) + } + } + + @Throws(BluePrintException::class) + open fun validateTopologyTemplate(topologyTemplate: TopologyTemplate) { + paths.add("topology") + message.appendln("--> Topology Template") + topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) } + topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) } + topologyTemplate.workflows?.let { validateWorkFlows(topologyTemplate.workflows!!) } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateInputs(inputs: MutableMap) { + paths.add("inputs") + message.appendln("---> Input :" + paths.joinToString(separator)) + validatePropertyDefinitions(inputs) + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateNodeTemplates(nodeTemplates: MutableMap) { + paths.add("nodeTemplates") + nodeTemplates.forEach { nodeTemplateName, nodeTemplate -> + validateNodeTemplate(nodeTemplateName, nodeTemplate) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) { + paths.add(nodeTemplateName) + message.appendln("---> NodeTemplate :" + paths.joinToString(separator)) + val type: String = nodeTemplate.type + + val nodeType: NodeType = serviceTemplate.nodeTypes?.get(type) + ?: throw BluePrintException(format("Failed to get NodeType({}) definition for NodeTemplate({})", type, nodeTemplateName)) + + nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) } + nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } + nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeType, nodeTemplateName, nodeTemplate) } + nodeTemplate.requirements?.let { validateRequirementAssignments(nodeType, nodeTemplateName, nodeTemplate) } + nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeType, nodeTemplateName, nodeTemplate) } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateArtifactDefinitions(artifacts: MutableMap) { + paths.add("artifacts") + artifacts.forEach { artifactDefinitionName, artifactDefinition -> + paths.add(artifactDefinitionName) + message.appendln("Validating artifact " + paths.joinToString(separator)) + val type: String = artifactDefinition.type + ?: throw BluePrintException(format("type is missing for ArtifactDefinition({})", artifactDefinitionName)) + // Check Artifact Type + checkValidArtifactType(artifactDefinitionName, type) + + val file: String = artifactDefinition.file + ?: throw BluePrintException(format("file is missing for ArtifactDefinition({})", artifactDefinitionName)) + + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateWorkFlows(workflows: MutableMap) { + paths.add("workflows") + workflows.forEach { workflowName, workflow -> + + // Validate Single workflow + validateWorkFlow(workflowName, workflow) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateWorkFlow(workflowName: String, workflow: Workflow) { + paths.add(workflowName) + message.appendln("---> Workflow :" + paths.joinToString(separator)) + // Step Validation Start + paths.add("steps") + workflow.steps?.forEach { stepName, _ -> + paths.add(stepName) + message.appendln("----> Steps :" + paths.joinToString(separator)) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + // Step Validation Ends + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validatePropertyDefinitions(properties: MutableMap) { + paths.add("properties") + properties.forEach { propertyName, propertyDefinition -> + paths.add(propertyName) + val dataType: String = propertyDefinition.type + when { + BluePrintTypes.validPrimitiveTypes().contains(dataType) -> { + // Do Nothing + } + BluePrintTypes.validCollectionTypes().contains(dataType) -> { + val entrySchemaType: String = propertyDefinition.entrySchema?.type + ?: throw BluePrintException(format("Entry schema for DataType ({}) for the property ({}) not found", dataType, propertyName)) + checkPrimitiveOrComplex(entrySchemaType, propertyName) + } + else -> checkPropertyDataType(dataType, propertyName) + } + message.appendln("property " + paths.joinToString(separator) + " of type " + dataType) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, + properties: MutableMap) { + properties.forEach { propertyName, propertyAssignment -> + val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] + ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) + + validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + + } + } + + @Throws(BluePrintException::class) + open fun validatePropertyAssignment(propertyName: String, propertyDefinition: PropertyDefinition, + propertyAssignment: JsonNode) { + // Check and Validate if Expression Node + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyName, propertyDefinition, propertyAssignment) + } + } + + @Throws(BluePrintException::class) + open fun validateCapabilityAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { + val capabilities = nodeTemplate.capabilities + paths.add("capabilities") + capabilities?.forEach { capabilityName, capabilityAssignment -> + paths.add(capabilityName) + + val capabilityDefinition = nodeType.capabilities?.get(capabilityName) + ?: throw BluePrintException(format("Failed to get NodeTemplate({}) capability definition ({}) " + + "from NodeType({}) ", nodeTemplateName, capabilityName, nodeTemplate.type)) + + validateCapabilityAssignment(nodeTemplateName, capabilityName, capabilityDefinition, capabilityAssignment) + + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateCapabilityAssignment(nodeTemplateName: String, capabilityName: String, + capabilityDefinition: CapabilityDefinition, capabilityAssignment: CapabilityAssignment) { + + capabilityAssignment.properties?.let { validatePropertyAssignments(capabilityDefinition.properties!!, capabilityAssignment.properties!!) } + + } + + @Throws(BluePrintException::class) + open fun validateRequirementAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { + val requirements = nodeTemplate.requirements + paths.add("requirements") + requirements?.forEach { requirementName, requirementAssignment -> + paths.add(requirementName) + val requirementDefinition = nodeType.requirements?.get(requirementName) + ?: throw BluePrintException(format("Failed to get NodeTemplate({}) requirement definition ({}) from" + + " NodeType({}) ", nodeTemplateName, requirementName, nodeTemplate.type)) + // Validate Requirement Assignment + validateRequirementAssignment(nodeTemplateName, requirementName, requirementDefinition, requirementAssignment) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + + } + + @Throws(BluePrintException::class) + open fun validateRequirementAssignment(nodeTemplateName: String, requirementAssignmentName: String, + requirementDefinition: RequirementDefinition, requirementAssignment: RequirementAssignment) { + log.info("Validating NodeTemplate({}) requirement assignment ({}) ", nodeTemplateName, requirementAssignmentName) + val requirementNodeTemplateName = requirementAssignment.node!! + val capabilityName = requirementAssignment.capability + val relationship = requirementAssignment.relationship!! + + check(BluePrintTypes.validRelationShipDerivedFroms.contains(relationship)) { + throw BluePrintException(format("Failed to get relationship type ({}) for NodeTemplate({})'s requirement({}) ", + relationship, nodeTemplateName, requirementAssignmentName)) + } + + val relationShipNodeTemplate = serviceTemplate.topologyTemplate?.nodeTemplates?.get(requirementNodeTemplateName) + ?: throw BluePrintException(format("Failed to get requirement NodeTemplate({})'s for NodeTemplate({}) requirement({}) ", + requirementNodeTemplateName, nodeTemplateName, requirementAssignmentName)) + + relationShipNodeTemplate.capabilities?.get(capabilityName) + ?: throw BluePrintException(format("Failed to get requirement NodeTemplate({})'s capability({}) for NodeTemplate ({})'s requirement({}) ", + requirementNodeTemplateName, capabilityName, nodeTemplateName, requirementAssignmentName)) + + + } + + @Throws(BluePrintException::class) + open fun validateInterfaceAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { + + val interfaces = nodeTemplate.interfaces + paths.add("interfaces") + interfaces?.forEach { interfaceAssignmentName, interfaceAssignment -> + paths.add(interfaceAssignmentName) + val interfaceDefinition = nodeType.interfaces?.get(interfaceAssignmentName) + ?: throw BluePrintException(format("Failed to get NodeTemplate({}) interface definition ({}) from" + + " NodeType({}) ", nodeTemplateName, interfaceAssignmentName, nodeTemplate.type)) + + validateInterfaceAssignment(nodeTemplateName, interfaceAssignmentName, interfaceDefinition, + interfaceAssignment) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + + + } + + @Throws(BluePrintException::class) + open fun validateInterfaceAssignment(nodeTemplateName: String, interfaceAssignmentName: String, + interfaceDefinition: InterfaceDefinition, + interfaceAssignment: InterfaceAssignment) { + + val operations = interfaceAssignment.operations + operations?.let { + validateInterfaceOperationsAssignment(nodeTemplateName, interfaceAssignmentName, interfaceDefinition, + interfaceAssignment) + } + + } + + @Throws(BluePrintException::class) + open fun validateInterfaceOperationsAssignment(nodeTemplateName: String, interfaceAssignmentName: String, + interfaceDefinition: InterfaceDefinition, + interfaceAssignment: InterfaceAssignment) { + + val operations = interfaceAssignment.operations + operations?.let { + it.forEach { operationAssignmentName, operationAssignments -> + + val operationDefinition = interfaceDefinition.operations?.get(operationAssignmentName) + ?: throw BluePrintException(format("Failed to get NodeTemplate({}) operation definition ({}) ", + nodeTemplateName, operationAssignmentName)) + + log.info("Validation NodeTemplate({}) Interface({}) Operation ({})", nodeTemplateName, + interfaceAssignmentName, operationAssignmentName) + + val inputs = operationAssignments.inputs + val outputs = operationAssignments.outputs + + inputs?.forEach { propertyName, propertyAssignment -> + val propertyDefinition = operationDefinition.inputs?.get(propertyName) + ?: throw BluePrintException(format("Failed to get NodeTemplate({}) operation definition ({}) " + + "property definition({})", nodeTemplateName, operationAssignmentName, propertyName)) + // Check the property values with property definition + validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + } + + outputs?.forEach { propertyName, propertyAssignment -> + val propertyDefinition = operationDefinition.outputs?.get(propertyName) + ?: throw BluePrintException(format("Failed to get NodeTemplate({}) operation definition ({}) " + + "output property definition({})", nodeTemplateName, operationAssignmentName, + propertyName)) + // Check the property values with property definition + validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + } + + } + } + + } + + @Throws(BluePrintException::class) + open fun validateCapabilityDefinitions(nodeTypeName: String, nodeType: NodeType) { + val capabilities = nodeType.capabilities + paths.add("capabilities") + capabilities?.forEach { capabilityName, capabilityDefinition -> + paths.add(capabilityName) + + validateCapabilityDefinition(nodeTypeName, nodeType, capabilityName, capabilityDefinition) + + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateCapabilityDefinition(nodeTypeName: String, nodeType: NodeType, capabilityName: String, + capabilityDefinition: CapabilityDefinition) { + val capabilityType = capabilityDefinition.type + check(BluePrintTypes.validCapabilityTypes.contains(capabilityType)) { + throw BluePrintException(format("Failed to get CapabilityType({}) for NodeType({})", + capabilityType, nodeTypeName)) + } + } + + @Throws(BluePrintException::class) + open fun validateRequirementDefinitions(nodeName: String, nodeType: NodeType) { + paths.add("requirements") + val requirements = nodeType.requirements + + requirements?.forEach { requirementDefinitionName, requirementDefinition -> + paths.add(requirementDefinitionName) + message.appendln("Validating : " + paths.joinToString(separator)) + validateRequirementDefinition(nodeName, nodeType, requirementDefinitionName, requirementDefinition) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateRequirementDefinition(nodeTypeName: String, nodeType: NodeType, requirementDefinitionName: String, + requirementDefinition: RequirementDefinition) { + + log.info("Validating NodeType({}) RequirementDefinition ({}) ", nodeTypeName, requirementDefinitionName) + val requirementNodeTypeName = requirementDefinition.node!! + val capabilityName = requirementDefinition.capability + val relationship = requirementDefinition.relationship!! + + check(BluePrintTypes.validRelationShipDerivedFroms.contains(relationship)) { + throw BluePrintException(format("Failed to get relationship({}) for NodeType({})'s requirement({}) ", + relationship, nodeTypeName, requirementDefinitionName)) + } + + val relationShipNodeType = serviceTemplate.nodeTypes?.get(requirementNodeTypeName) + ?: throw BluePrintException(format("Failed to get requirement NodeType({})'s for requirement({}) ", + requirementNodeTypeName, requirementDefinitionName)) + + relationShipNodeType.capabilities?.get(capabilityName) + ?: throw BluePrintException(format("Failed to get requirement NodeType({})'s capability({}) for NodeType ({})'s requirement({}) ", + requirementNodeTypeName, capabilityName, nodeTypeName, requirementDefinitionName)) + + } + + + @Throws(BluePrintException::class) + open fun validateInterfaceDefinitions(interfaces: MutableMap) { + paths.add("interfaces") + interfaces.forEach { interfaceName, interfaceDefinition -> + paths.add(interfaceName) + message.appendln("Validating : " + paths.joinToString(separator)) + interfaceDefinition.operations?.let { validateOperationDefinitions(interfaceDefinition.operations!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateOperationDefinitions(operations: MutableMap) { + paths.add("operations") + operations.forEach { opertaionName, operationDefinition -> + paths.add(opertaionName) + message.appendln("Validating : " + paths.joinToString(separator)) + operationDefinition.implementation?.let { validateImplementation(operationDefinition.implementation!!) } + operationDefinition.inputs?.let { validatePropertyDefinitions(operationDefinition.inputs!!) } + operationDefinition.outputs?.let { validatePropertyDefinitions(operationDefinition.outputs!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateImplementation(implementation: Implementation) { + checkNotEmptyOrThrow(implementation.primary) + } + + @Throws(BluePrintException::class) + open fun checkValidArtifactType(artifactDefinitionName: String, artifactTypeName: String) { + + val artifactType = serviceTemplate.artifactTypes?.get(artifactTypeName) + ?: throw BluePrintException("failed to artifactType($artifactTypeName) for ArtifactDefinition($artifactDefinitionName)") + + checkValidArtifactTypeDerivedFrom(artifactTypeName, artifactType.derivedFrom) + } + + @Throws(BluePrintException::class) + open fun checkValidArtifactTypeDerivedFrom(artifactTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validArtifactTypeDerivedFroms.contains(derivedFrom)) { + throw BluePrintException("failed to get artifactType($artifactTypeName)'s derivedFrom($derivedFrom) definition") + } + } + + @Throws(BluePrintException::class) + open fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) { + throw BluePrintException(format("Failed to get DataType({})'s derivedFrom({}) definition ", dataTypeName, derivedFrom)) + } + } + + @Throws(BluePrintException::class) + open fun checkValidRelationshipTypeDerivedFrom(relationshipTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validRelationShipDerivedFroms.contains(derivedFrom)) { + throw BluePrintException(format("Failed to get relationship type ({})'s derivedFrom({}) definition ", relationshipTypeName, derivedFrom)) + } + } + + open fun checkPropertyValue(propertyName: String, propertyDefinition: PropertyDefinition, propertyAssignment: JsonNode) { + val propertyType = propertyDefinition.type + val isValid: Boolean + + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { + isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) + + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + + val entrySchemaType = propertyDefinition.entrySchema?.type + ?: throw BluePrintException(format("Failed to get EntrySchema type for the collection property ({})", propertyName)) + + if (!BluePrintTypes.validPropertyTypes().contains(entrySchemaType)) { + checkPropertyDataType(entrySchemaType, propertyName) + } + isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) + } else { + checkPropertyDataType(propertyType, propertyName) + isValid = true + } + + check(isValid) { + throw BluePrintException(format("property({}) defined of type({}) is not comptable with the value ({})", + propertyName, propertyType, propertyAssignment)) + } + } + + private fun checkPropertyDataType(dataTypeName: String, propertyName: String) { + + val dataType = serviceTemplate.dataTypes?.get(dataTypeName) + ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataTypeName, propertyName)) + + checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom) + + } + + private fun checkPrimitiveOrComplex(dataType: String, propertyName: String): Boolean { + if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) { + return true + } else { + throw BluePrintException(format("DataType({}) for the property({}) is not valid", dataType, propertyName)) + } + } + + private fun checkDataType(key: String): Boolean { + return serviceTemplate.dataTypes?.containsKey(key) ?: false + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt new file mode 100644 index 000000000..81b7acb56 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt @@ -0,0 +1,210 @@ +/* + * 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.core.service + + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.ResourceResolverUtils + +/** + * + * + * @author Brinda Santh + */ +class PropertyAssignmentService(var bluePrintRuntimeService: BluePrintRuntimeService>) { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + private var bluePrintContext: BluePrintContext = bluePrintRuntimeService.bluePrintContext() + +/* + +If Property Assignment is Expression. + Get the Expression + Recursively resolve the expression + */ + + fun resolveAssignmentExpression(nodeTemplateName: String, assignmentName: String, + assignment: JsonNode): JsonNode { + val valueNode: JsonNode + log.trace("Assignment ({})", assignment) + val expressionData = BluePrintExpressionService.getExpressionData(assignment) + + if (expressionData.isExpression) { + valueNode = resolveExpression(nodeTemplateName, assignmentName, expressionData) + } else { + valueNode = expressionData.valueNode + } + return valueNode + } + + fun resolveExpression(nodeTemplateName: String, propName: String, expressionData: ExpressionData): JsonNode { + + var valueNode: JsonNode = NullNode.getInstance() + + if (expressionData.isExpression) { + val command = expressionData.command!! + + when (command) { + BluePrintConstants.EXPRESSION_GET_INPUT -> { + valueNode = bluePrintRuntimeService.getInputValue(expressionData.inputExpression?.propertyName!!) + } + BluePrintConstants.EXPRESSION_GET_ATTRIBUTE -> { + valueNode = resolveAttributeExpression(nodeTemplateName, expressionData.attributeExpression!!) + } + BluePrintConstants.EXPRESSION_GET_PROPERTY -> { + valueNode = resolvePropertyExpression(nodeTemplateName, expressionData.propertyExpression!!) + } + BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT -> { + valueNode = resolveOperationOutputExpression(nodeTemplateName, expressionData.operationOutputExpression!!) + } + BluePrintConstants.EXPRESSION_GET_ARTIFACT -> { + valueNode = resolveArtifactExpression(nodeTemplateName, expressionData.artifactExpression!!) + } + BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE -> { + + } + else -> { + throw BluePrintException(format("for property ({}), command ({}) is not supported ", propName, command)) + } + } + } + return valueNode + } + + /* + get_property: [ , , , + , ..., ] + */ + fun resolveAttributeExpression(nodeTemplateName: String, attributeExpression: AttributeExpression): JsonNode { + val valueNode: JsonNode + + val attributeName = attributeExpression.attributeName + val subAttributeName: String? = attributeExpression.subAttributeName + + var attributeNodeTemplateName = nodeTemplateName + when (attributeExpression.modelableEntityName) { + "ENV" -> { + val environmentValue = System.getProperty(attributeName) + valueNode = JacksonUtils.jsonNode(environmentValue) + } + else -> { + if (!attributeExpression.modelableEntityName.equals("SELF", true)) { + attributeNodeTemplateName = attributeExpression.modelableEntityName + } + /* Enable in ONAP Dublin Release + val nodeTemplateAttributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName) + ?: throw BluePrintException(format("failed to get attribute definitions for node template " + + "({})'s property name ({}) ", nodeTemplateName, attributeName)) + + var attributeDefinition: AttributeDefinition = bluePrintContext.nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)!! + + log.info("node template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression) + */ + + valueNode = bluePrintRuntimeService.getNodeTemplateAttributeValue(attributeNodeTemplateName, attributeName) + ?: throw BluePrintException(format("failed to get node template ({})'s attribute ({}) ", nodeTemplateName, attributeName)) + } + + } +// subPropertyName?.let { +// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName)) +// } + return valueNode + } + + /* + get_property: [ , , , + , ..., ] + */ + fun resolvePropertyExpression(nodeTemplateName: String, propertyExpression: PropertyExpression): JsonNode { + val valueNode: JsonNode + + val propertyName = propertyExpression.propertyName + val subPropertyName: String? = propertyExpression.subPropertyName + + var propertyNodeTemplateName = nodeTemplateName + if (!propertyExpression.modelableEntityName.equals("SELF", true)) { + propertyNodeTemplateName = propertyExpression.modelableEntityName + } + + val nodeTemplatePropertyExpression = bluePrintContext.nodeTemplateByName(propertyNodeTemplateName).properties?.get(propertyName) + ?: throw BluePrintException(format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, propertyName)) + + var propertyDefinition: PropertyDefinition = bluePrintContext.nodeTemplateNodeType(propertyNodeTemplateName).properties?.get(propertyName)!! + + log.info("node template name ({}), property Name ({}) resolved value ({})", propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression) + + // Check it it is a nested expression + valueNode = resolveAssignmentExpression(propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression) + +// subPropertyName?.let { +// valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName)) +// } + return valueNode + } + + /* + get_operation_output: , , , + */ + fun resolveOperationOutputExpression(nodeTemplateName: String, operationOutputExpression: OperationOutputExpression): JsonNode { + var outputNodeTemplateName = nodeTemplateName + if (!operationOutputExpression.modelableEntityName.equals("SELF", true)) { + outputNodeTemplateName = operationOutputExpression.modelableEntityName + } + return bluePrintRuntimeService.getNodeTemplateOperationOutputValue(outputNodeTemplateName, + operationOutputExpression.interfaceName, operationOutputExpression.operationName, + operationOutputExpression.propertyName) + } + + /* + get_artifact: [ , , , ] + */ + fun resolveArtifactExpression(nodeTemplateName: String, artifactExpression: ArtifactExpression): JsonNode { + + var artifactNodeTemplateName = nodeTemplateName + if (!artifactExpression.modelableEntityName.equals("SELF", true)) { + artifactNodeTemplateName = artifactExpression.modelableEntityName + } + val artifactDefinition: ArtifactDefinition = bluePrintContext.nodeTemplateByName(artifactNodeTemplateName) + .artifacts?.get(artifactExpression.artifactName) + ?: throw BluePrintException(format("failed to get artifact definitions for node template ({})'s " + + "artifact name ({}) ", nodeTemplateName, artifactExpression.artifactName)) + + return JacksonUtils.jsonNodeFromObject(artifactContent(artifactDefinition)) + } + + fun artifactContent(artifactDefinition: ArtifactDefinition): String { + val bluePrintBasePath: String = bluePrintContext.rootPath + + if (artifactDefinition.repository != null) { + TODO() + } else if (artifactDefinition.file != null) { + return ResourceResolverUtils.getFileContent(artifactDefinition.file!!, bluePrintBasePath) + } + return "" + } +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt new file mode 100755 index 000000000..fe7929e85 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt @@ -0,0 +1,147 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.core.utils + +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream +import org.apache.commons.io.IOUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.slf4j.LoggerFactory +import java.io.BufferedInputStream +import java.io.File +import java.io.FileInputStream +import java.io.IOException +import java.nio.charset.Charset +import java.util.zip.ZipFile + +class BluePrintArchiveUtils { + + companion object { + private val log = LoggerFactory.getLogger(BluePrintArchiveUtils::class.java) + + fun getFileContent(fileName: String): String = runBlocking { + async { + try { + File(fileName).readText(Charsets.UTF_8) + } catch (e: Exception) { + throw BluePrintException("couldn't find file($fileName)") + } + }.await() + } + + fun compress(source: String, destination: String, absolute: Boolean): Boolean { + val rootDir = File(source) + val saveFile = File(destination) + return compress(rootDir, saveFile, absolute) + } + + /** + * Create a new Zip from a root directory + * + * @param source the base directory + * @param destination the output filename + * @param absolute store absolute filepath (from directory) or only filename + * @return True if OK + */ + fun compress(source: File, destination: File, absolute: Boolean): Boolean { + try { + ZipArchiveOutputStream(destination).use { + recurseFiles(source, source, it, absolute) + } + } catch (e: Exception) { + log.error("Fail to compress folder(:$source) to path(${destination.path}", e) + return false + } + return true + } + + /** + * Recursive traversal to add files + * + * @param root + * @param file + * @param zaos + * @param absolute + * @throws IOException + */ + @Throws(IOException::class) + private fun recurseFiles(root: File, file: File, zaos: ZipArchiveOutputStream, + absolute: Boolean) { + if (file.isDirectory) { + // recursive call + val files = file.listFiles() + for (fileChild in files!!) { + recurseFiles(root, fileChild, zaos, absolute) + } + } else if (!file.name.endsWith(".zip") && !file.name.endsWith(".ZIP")) { + val filename = if (absolute) { + file.absolutePath.substring(root.absolutePath.length) + } else { + file.name + } + val zae = ZipArchiveEntry(filename) + zae.size = file.length() + zaos.putArchiveEntry(zae) + FileInputStream(file).use { IOUtils.copy(it, zaos) } + zaos.closeArchiveEntry() + } + } + + + fun deCompress(zipFile: File, targetPath: String): File { + val zip = ZipFile(zipFile, Charset.defaultCharset()) + val enumeration = zip.entries() + while (enumeration.hasMoreElements()) { + val entry = enumeration.nextElement() + val destFilePath = File(targetPath, entry.name) + destFilePath.parentFile.mkdirs() + + if (entry.isDirectory) + continue + + val bufferedIs = BufferedInputStream(zip.getInputStream(entry)) + bufferedIs.use { + destFilePath.outputStream().buffered(1024).use { bos -> + bufferedIs.copyTo(bos) + } + } + } + + val destinationDir = File(targetPath) + check(destinationDir.isDirectory && destinationDir.exists()) { + throw BluePrintProcessorException("failed to decompress blueprint(${zipFile.absolutePath}) to ($targetPath) ") + } + + return destinationDir + } + + /** + * Get the first item in directory + * + * @param zipFile + * @return string + */ + fun getFirstItemInDirectory(dir: File): String { + return dir.walk().map { it.name }.elementAt(1) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt new file mode 100755 index 000000000..9746bf579 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt @@ -0,0 +1,253 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import kotlinx.coroutines.runBlocking +import org.apache.commons.io.FileUtils +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.data.ErrorCode +import org.onap.ccsdk.apps.controllerblueprints.core.data.ImportDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import java.io.File +import java.io.FileFilter +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths +import java.nio.file.StandardOpenOption + + +class BluePrintFileUtils { + companion object { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + fun createEmptyBluePrint(basePath: String) { + + val blueprintDir = File(basePath) + FileUtils.deleteDirectory(blueprintDir) + + Files.createDirectories(blueprintDir.toPath()) + + val metaDataDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_METADATA_DIR)) + Files.createDirectories(metaDataDir.toPath()) + + val metaFile = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants + .TOSCA_METADATA_ENTRY_DEFINITION_FILE)) + Files.write(metaFile.toPath(), getMetaDataContent().toByteArray(), StandardOpenOption.CREATE_NEW) + + val definitionsDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR)) + Files.createDirectories(definitionsDir.toPath()) + + val scriptsDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_SCRIPTS_DIR)) + Files.createDirectories(scriptsDir.toPath()) + + val plansDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_PLANS_DIR)) + Files.createDirectories(plansDir.toPath()) + + val templatesDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_TEMPLATES_DIR)) + Files.createDirectories(templatesDir.toPath()) + + } + + fun copyBluePrint(sourcePath: String, targetPath: String) { + val sourceFile = File(sourcePath) + val targetFile = File(targetPath) + sourceFile.copyRecursively(targetFile, true) + } + + fun deleteBluePrintTypes(basePath: String) { + val definitionPath = basePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR) + log.info("deleting definition types under : $definitionPath") + + val definitionDir = File(definitionPath) + // Find the Type Definitions + val fileFilter = FileFilter { pathname -> pathname.absolutePath.endsWith("_types.json") } + // Delete the Type Files + definitionDir.listFiles(fileFilter).forEach { + Files.deleteIfExists(it.toPath()) + } + } + + fun writeEnhancedBluePrint(blueprintContext: BluePrintContext) { + + // Write Blueprint Types + writeBluePrintTypes(blueprintContext) + // Re Populate the Imports + populateDefaultImports(blueprintContext) + // Rewrite the Entry Definition Files + writeEntryDefinitionFile(blueprintContext) + + } + + fun writeBluePrintTypes(blueprintContext: BluePrintContext) { + + val basePath = blueprintContext.rootPath + val definitionPath = basePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR) + val definitionDir = File(definitionPath) + + check(definitionDir.exists()) { + throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get definition file under " + + "path(${definitionDir.absolutePath})") + } + + blueprintContext.serviceTemplate.dataTypes?.let { + val dataTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_DATA_TYPES, it.toSortedMap(), true) + writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_DATA_TYPES, dataTypesContent) + } + + blueprintContext.serviceTemplate.relationshipTypes?.let { + val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_RELATIONSHIP_TYPES, it.toSortedMap(), true) + writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_RELATIONSHIP_TYPES, nodeTypesContent) + } + + blueprintContext.serviceTemplate.artifactTypes?.let { + val artifactTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_ARTIFACT_TYPES, it.toSortedMap(), true) + writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_ARTIFACT_TYPES, artifactTypesContent) + } + + blueprintContext.serviceTemplate.nodeTypes?.let { + val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_NODE_TYPES, it.toSortedMap(), true) + writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_NODE_TYPES, nodeTypesContent) + } + + blueprintContext.serviceTemplate.policyTypes?.let { + val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_POLICY_TYPES, it.toSortedMap(), true) + writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_POLICY_TYPES, nodeTypesContent) + } + } + + private fun populateDefaultImports(blueprintContext: BluePrintContext) { + // Get the Default Types + val types = arrayListOf(BluePrintConstants.PATH_DATA_TYPES, BluePrintConstants.PATH_RELATIONSHIP_TYPES, + BluePrintConstants.PATH_ARTIFACT_TYPES, BluePrintConstants.PATH_NODE_TYPES, + BluePrintConstants.PATH_POLICY_TYPES) + + // Clean Type Imports + cleanImportTypes(blueprintContext.serviceTemplate) + + val imports = mutableListOf() + types.forEach { typeName -> + val import = ImportDefinition() + import.file = BluePrintConstants.TOSCA_DEFINITIONS_DIR.plus("/$typeName.json") + imports.add(import) + } + + blueprintContext.serviceTemplate.imports = imports + } + + fun cleanImportTypes(serviceTemplate: ServiceTemplate) { + // Clean the Type imports + val toDeleteTypes = serviceTemplate.imports?.filter { + it.file.endsWith("_types.json") + } + + if (toDeleteTypes != null && toDeleteTypes.isNotEmpty()) { + serviceTemplate.imports?.removeAll(toDeleteTypes) + } + } + + /** + * Re Generate the Blueprint Service Template Definition file based on BluePrint Context. + */ + private fun writeEntryDefinitionFile(blueprintContext: BluePrintContext) { + + val absoluteEntryDefinitionFile = blueprintContext.rootPath.plus(File.separator).plus(blueprintContext.entryDefinition) + + val serviceTemplate = blueprintContext.serviceTemplate + + // Clone the Service Template + val writeServiceTemplate = serviceTemplate.clone() + writeServiceTemplate.dataTypes = null + writeServiceTemplate.artifactTypes = null + writeServiceTemplate.policyTypes = null + writeServiceTemplate.relationshipTypes = null + writeServiceTemplate.nodeTypes = null + + // Write the Service Template + writeDefinitionFile(absoluteEntryDefinitionFile, JacksonUtils.getJson(writeServiceTemplate, true)) + } + + fun writeDefinitionFile(definitionFileName: String, content: String) = runBlocking { + val definitionFile = File(definitionFileName) + // Delete the File If exists + Files.deleteIfExists(definitionFile.toPath()) + + Files.write(definitionFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW) + check(definitionFile.exists()) { + throw BluePrintException(ErrorCode.BLUEPRINT_WRITING_FAIL.value, "couldn't write definition file under " + + "path(${definitionFile.absolutePath})") + } + } + + private fun writeTypeFile(definitionPath: String, type: String, content: String) = runBlocking { + val typeFile = File(definitionPath.plus(File.separator).plus("$type.json")) + + Files.write(typeFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW) + check(typeFile.exists()) { + throw BluePrintException(ErrorCode.BLUEPRINT_WRITING_FAIL.value, "couldn't write $type.json file under " + + "path(${typeFile.absolutePath})") + } + } + + private fun getMetaDataContent(): String { + return "TOSCA-Meta-File-Version: 1.0.0" + + "\nCSAR-Version: " + + "\nCreated-By: " + + "\nEntry-Definitions: Definitions/.json" + + "\nTemplate-Tags: " + } + + + fun getBluePrintFile(fileName: String, targetPath: Path) : File { + val filePath = targetPath.resolve(fileName).toString() + val file = File(filePath) + check(file.exists()) { + throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get definition file under " + + "path(${file.absolutePath})") + } + return file + } + + fun getCbaStorageDirectory(path: String): Path { + check(StringUtils.isNotBlank(path)) { + throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get " + + "Blueprint folder under path($path)") + } + + val fileStorageLocation = Paths.get(path).toAbsolutePath().normalize() + + if (!Files.exists(fileStorageLocation)) + Files.createDirectories(fileStorageLocation) + + return fileStorageLocation + } + + fun stripFileExtension(fileName: String): String { + val dotIndexe = fileName.lastIndexOf('.') + + // In case dot is in first position, we are dealing with a hidden file rather than an extension + return if (dotIndexe > 0) fileName.substring(0, dotIndexe) else fileName + } + + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt new file mode 100644 index 000000000..7764bc192 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt @@ -0,0 +1,144 @@ +/* + * 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.core.utils + + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import org.apache.commons.io.FileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintImportService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService +import java.io.File +import java.nio.charset.Charset + +class BluePrintMetadataUtils { + companion object { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + + fun toscaMetaData(basePath: String): ToscaMetaData { + val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE) + return toscaMetaDataFromMetaFile(toscaMetaPath) + } + + fun entryDefinitionFile(basePath: String): String { + val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE) + return toscaMetaDataFromMetaFile(toscaMetaPath).entityDefinitions + } + + fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData { + val toscaMetaData = ToscaMetaData() + val lines: MutableList = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset()) + lines.forEach { line -> + if (line.contains(":")) { + val keyValue = line.split(":") + if (keyValue.size == 2) { + val value: String = keyValue[1].trim() + when (keyValue[0]) { + "TOSCA-Meta-File-Version" -> toscaMetaData.toscaMetaFileVersion = value + "CSAR-Version" -> toscaMetaData.csarVersion = value + "Created-By" -> toscaMetaData.createdBy = value + "Entry-Definitions" -> toscaMetaData.entityDefinitions = value + "Template-Tags" -> toscaMetaData.templateTags = value + } + } + } + + } + return toscaMetaData + } + + fun getBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService> { + + val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath) + + val context: MutableMap = hashMapOf() + context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive() + context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive() + + val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) + bluePrintRuntimeService.setExecutionContext(context) + + return bluePrintRuntimeService + } + + fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService> { + + val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath) + val context: MutableMap = hashMapOf() + context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive() + context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive() + + val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) + bluePrintRuntimeService.setExecutionContext(context) + + return bluePrintRuntimeService + } + + fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap): BluePrintRuntimeService> { + val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath) + val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) + bluePrintRuntimeService.setExecutionContext(executionContext) + return bluePrintRuntimeService + } + + fun getBluePrintContext(blueprintBasePath: String): BluePrintContext { + + val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath) + + log.info("Reading blueprint path($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})") + + return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath) + } + + private fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext { + val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath) + // Clean Type files + BluePrintFileUtils.deleteBluePrintTypes(blueprintBasePath) + val rootFilePath: String = blueprintBasePath.plus(File.separator).plus(toscaMetaData.entityDefinitions) + val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath) + + // Clean the Import Definitions + BluePrintFileUtils.cleanImportTypes(rootServiceTemplate) + + val blueprintContext = BluePrintContext(rootServiceTemplate) + blueprintContext.rootPath = blueprintBasePath + blueprintContext.entryDefinition = toscaMetaData.entityDefinitions + return blueprintContext + } + + private fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext { + val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions) + val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath) + // Recursively Import Template files + val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, basePath) + val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate() + val blueprintContext = BluePrintContext(completeServiceTemplate) + blueprintContext.rootPath = basePath + blueprintContext.entryDefinition = entityDefinitions + return blueprintContext + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt new file mode 100644 index 000000000..c37d8eeaa --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt @@ -0,0 +1,61 @@ +/* + * 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.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext + +/** + * + * + * @author Brinda Santh + */ +object BluePrintRuntimeUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + fun assignInputsFromFile(bluePrintContext: BluePrintContext, fileName: String, context: MutableMap) { + val jsonNode: JsonNode = JacksonUtils.jsonNodeFromFile(fileName) + return assignInputs(bluePrintContext, jsonNode, context) + } + + fun assignInputsFromClassPathFile(bluePrintContext: BluePrintContext, fileName: String, context: MutableMap) { + val jsonNode = JacksonUtils.jsonNodeFromClassPathFile(fileName) + return assignInputs(bluePrintContext, jsonNode, context) + } + + fun assignInputsFromContent(bluePrintContext: BluePrintContext, content: String, context: MutableMap) { + val jsonNode: JsonNode = JacksonUtils.jsonNode(content) + return assignInputs(bluePrintContext, jsonNode, context) + } + + fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap) { + log.info("assignInputs from input JSON ({})", jsonNode.toString()) + bluePrintContext.inputs?.forEach { propertyName, _ -> + val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance() + + val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(propertyName) + log.trace("setting input path ({}), values ({})", path, valueNode) + context[path] = valueNode + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt new file mode 100644 index 000000000..0522e1f5e --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt @@ -0,0 +1,109 @@ +/* + * 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.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import reactor.core.publisher.Mono +import reactor.core.publisher.toMono + +@Deprecated("Reactor will be replaced by coroutines by default") +object JacksonReactorUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @JvmStatic + fun getContent(fileName: String): Mono { + return JacksonUtils.getContent(fileName).toMono() + } + + @JvmStatic + fun getClassPathFileContent(fileName: String): Mono { + return JacksonUtils.getClassPathFileContent(fileName).toMono() + } + + @JvmStatic + fun readValue(content: String, valueType: Class): Mono { + return Mono.just(jacksonObjectMapper().readValue(content, valueType)) + } + + @JvmStatic + fun jsonNode(content: String): Mono { + return Mono.just(jacksonObjectMapper().readTree(content)) + } + + @JvmStatic + fun getJson(any: kotlin.Any, pretty: Boolean = false): Mono { + return Mono.just(JacksonUtils.getJson(any, pretty)) + } + + @JvmStatic + fun getListFromJson(content: String, valueType: Class): Mono> { + val objectMapper = jacksonObjectMapper() + val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType) + return objectMapper.readValue>(content, javaType).toMono() + } + + @JvmStatic + fun readValueFromFile(fileName: String, valueType: Class): Mono { + return getContent(fileName) + .flatMap { content -> + readValue(content, valueType) + } + } + + @JvmStatic + fun readValueFromClassPathFile(fileName: String, valueType: Class): Mono { + return getClassPathFileContent(fileName) + .flatMap { content -> + readValue(content, valueType) + } + } + + @JvmStatic + fun jsonNodeFromFile(fileName: String): Mono { + return getContent(fileName) + .flatMap { content -> + jsonNode(content) + } + } + + @JvmStatic + fun jsonNodeFromClassPathFile(fileName: String): Mono { + return getClassPathFileContent(fileName) + .flatMap { content -> + jsonNode(content) + } + } + + @JvmStatic + fun getListFromFile(fileName: String, valueType: Class): Mono> { + return getContent(fileName) + .flatMap { content -> + getListFromJson(content, valueType) + } + } + + @JvmStatic + fun getListFromClassPathFile(fileName: String, valueType: Class): Mono> { + return getClassPathFileContent(fileName) + .flatMap { content -> + getListFromJson(content, valueType) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt new file mode 100644 index 000000000..75310ee89 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -0,0 +1,287 @@ +/* + * 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.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.databind.node.ArrayNode +import com.fasterxml.jackson.databind.node.NullNode +import com.fasterxml.jackson.databind.node.ObjectNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext +import org.apache.commons.io.IOUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import java.io.File +import java.nio.charset.Charset + +/** + * + * + * @author Brinda Santh + */ +class JacksonUtils { + companion object { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + inline fun readValue(content: String): T = + jacksonObjectMapper().readValue(content, T::class.java) + + fun readValue(content: String, valueType: Class): T? { + return jacksonObjectMapper().readValue(content, valueType) + } + + fun readValue(node: JsonNode, valueType: Class): T? { + return jacksonObjectMapper().treeToValue(node, valueType) + } + + fun removeJsonNullNode(node: JsonNode) { + val it = node.iterator() + while (it.hasNext()) { + val child = it.next() + if (child.isNull) { + it.remove() + } else { + removeJsonNullNode(child) + } + } + } + + fun getContent(fileName: String): String = runBlocking { + async { + try { + File(fileName).readText(Charsets.UTF_8) + } catch (e: Exception) { + throw BluePrintException("couldn't get file ($fileName) content : ${e.message}") + } + }.await() + } + + fun getClassPathFileContent(fileName: String): String { + return runBlocking { + withContext(Dispatchers.Default) { + IOUtils.toString(JacksonUtils::class.java.classLoader + .getResourceAsStream(fileName), Charset.defaultCharset()) + } + } + } + + fun readValueFromFile(fileName: String, valueType: Class): T? { + val content: String = getContent(fileName) + return readValue(content, valueType) + } + + fun readValueFromClassPathFile(fileName: String, valueType: Class): T? { + val content: String = getClassPathFileContent(fileName) + return readValue(content, valueType) + } + + fun jsonNodeFromObject(from: kotlin.Any): JsonNode { + return jacksonObjectMapper().convertValue(from, JsonNode::class.java) + } + + fun jsonNodeFromClassPathFile(fileName: String): JsonNode { + val content: String = getClassPathFileContent(fileName) + return jsonNode(content) + } + + fun jsonNodeFromFile(fileName: String): JsonNode { + val content: String = getContent(fileName) + return jsonNode(content) + } + + fun jsonNode(content: String): JsonNode { + return jacksonObjectMapper().readTree(content) + } + + fun getJson(any: kotlin.Any): String { + return getJson(any, false) + } + + fun getWrappedJson(wrapper: String, any: kotlin.Any, pretty: Boolean = false): String { + val wrapperMap = hashMapOf() + wrapperMap[wrapper] = any + return getJson(wrapperMap, pretty) + } + + fun getJson(any: kotlin.Any, pretty: Boolean = false): String { + val objectMapper = jacksonObjectMapper() + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) + if (pretty) { + objectMapper.enable(SerializationFeature.INDENT_OUTPUT) + } + return objectMapper.writeValueAsString(any) + } + + fun getJsonNode(any: kotlin.Any?, pretty: Boolean = false): JsonNode { + val objectMapper = jacksonObjectMapper() + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) + if (pretty) { + objectMapper.enable(SerializationFeature.INDENT_OUTPUT) + } + return objectMapper.valueToTree(any) + } + + fun getListFromJsonNode(node: JsonNode, valueType: Class): List? { + return getListFromJson(node.toString(), valueType) + } + + fun getListFromJson(content: String, valueType: Class): List? { + val objectMapper = jacksonObjectMapper() + val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType) + return objectMapper.readValue>(content, javaType) + } + + fun getListFromFile(fileName: String, valueType: Class): List? { + val content: String = getContent(fileName) + return getListFromJson(content, valueType) + } + + fun getListFromClassPathFile(fileName: String, valueType: Class): List? { + val content: String = getClassPathFileContent(fileName) + return getListFromJson(content, valueType) + } + + fun getMapFromJson(content: String, valueType: Class): MutableMap? { + val objectMapper = jacksonObjectMapper() + val typeRef = object : TypeReference>() {} + return objectMapper.readValue(content, typeRef) + } + + fun getMapFromFile(fileName: String, valueType: Class): MutableMap? { + val content: String = getContent(fileName) + return getMapFromJson(content, valueType) + } + + fun getInstanceFromMap(properties: MutableMap, classType: Class): T { + return readValue(getJson(properties), classType) + ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)") + } + + fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean { + if (BluePrintTypes.validPrimitiveTypes().contains(type.toLowerCase())) { + return checkJsonNodeValueOfPrimitiveType(type, jsonNode) + } else if (BluePrintTypes.validCollectionTypes().contains(type)) { + return checkJsonNodeValueOfCollectionType(type, jsonNode) + } + return false + } + + fun checkIfPrimitiveType(primitiveType: String): Boolean { + return when (primitiveType.toLowerCase()) { + BluePrintConstants.DATA_TYPE_STRING -> true + BluePrintConstants.DATA_TYPE_BOOLEAN -> true + BluePrintConstants.DATA_TYPE_INTEGER -> true + BluePrintConstants.DATA_TYPE_FLOAT -> true + BluePrintConstants.DATA_TYPE_DOUBLE -> true + BluePrintConstants.DATA_TYPE_TIMESTAMP -> true + else -> false + } + } + + fun checkJsonNodeValueOfPrimitiveType(primitiveType: String, jsonNode: JsonNode): Boolean { + return when (primitiveType.toLowerCase()) { + BluePrintConstants.DATA_TYPE_STRING -> jsonNode.isTextual + BluePrintConstants.DATA_TYPE_BOOLEAN -> jsonNode.isBoolean + BluePrintConstants.DATA_TYPE_INTEGER -> jsonNode.isInt + BluePrintConstants.DATA_TYPE_FLOAT -> jsonNode.isDouble + BluePrintConstants.DATA_TYPE_DOUBLE -> jsonNode.isDouble + BluePrintConstants.DATA_TYPE_TIMESTAMP -> jsonNode.isTextual + else -> false + } + } + + fun checkJsonNodeValueOfCollectionType(type: String, jsonNode: JsonNode): Boolean { + return when (type.toLowerCase()) { + BluePrintConstants.DATA_TYPE_LIST -> jsonNode.isArray + BluePrintConstants.DATA_TYPE_MAP -> jsonNode.isContainerNode + else -> false + } + } + + fun populatePrimitiveValues(key: String, value: Any, primitiveType: String, objectNode: ObjectNode) { + when (primitiveType.toLowerCase()) { + BluePrintConstants.DATA_TYPE_BOOLEAN -> objectNode.put(key, value as Boolean) + BluePrintConstants.DATA_TYPE_INTEGER -> objectNode.put(key, value as Int) + BluePrintConstants.DATA_TYPE_FLOAT -> objectNode.put(key, value as Float) + BluePrintConstants.DATA_TYPE_DOUBLE -> objectNode.put(key, value as Double) + BluePrintConstants.DATA_TYPE_TIMESTAMP -> objectNode.put(key, value as String) + else -> objectNode.put(key, value as String) + } + } + + fun populatePrimitiveValues(value: Any, primitiveType: String, arrayNode: ArrayNode) { + when (primitiveType.toLowerCase()) { + BluePrintConstants.DATA_TYPE_BOOLEAN -> arrayNode.add(value as Boolean) + BluePrintConstants.DATA_TYPE_INTEGER -> arrayNode.add(value as Int) + BluePrintConstants.DATA_TYPE_FLOAT -> arrayNode.add(value as Float) + BluePrintConstants.DATA_TYPE_DOUBLE -> arrayNode.add(value as Double) + BluePrintConstants.DATA_TYPE_TIMESTAMP -> arrayNode.add(value as String) + else -> arrayNode.add(value as String) + } + } + + fun populatePrimitiveDefaultValues(key: String, primitiveType: String, objectNode: ObjectNode) { + when (primitiveType.toLowerCase()) { + BluePrintConstants.DATA_TYPE_BOOLEAN -> objectNode.put(key, false) + BluePrintConstants.DATA_TYPE_INTEGER -> objectNode.put(key, 0) + BluePrintConstants.DATA_TYPE_FLOAT -> objectNode.put(key, 0.0) + BluePrintConstants.DATA_TYPE_DOUBLE -> objectNode.put(key, 0.0) + else -> objectNode.put(key, "") + } + } + + fun populatePrimitiveDefaultValuesForArrayNode(primitiveType: String, arrayNode: ArrayNode) { + when (primitiveType.toLowerCase()) { + BluePrintConstants.DATA_TYPE_BOOLEAN -> arrayNode.add(false) + BluePrintConstants.DATA_TYPE_INTEGER -> arrayNode.add(0) + BluePrintConstants.DATA_TYPE_FLOAT -> arrayNode.add(0.0) + BluePrintConstants.DATA_TYPE_DOUBLE -> arrayNode.add(0.0) + else -> arrayNode.add("") + } + } + + fun populateJsonNodeValues(key: String, nodeValue: JsonNode?, type: String, objectNode: ObjectNode) { + if (nodeValue == null || nodeValue is NullNode) { + objectNode.set(key, nodeValue) + } else if (BluePrintTypes.validPrimitiveTypes().contains(type)) { + populatePrimitiveValues(key, nodeValue, type, objectNode) + } else { + objectNode.set(key, nodeValue) + } + } + + fun convertPrimitiveResourceValue(type: String, value: String): JsonNode { + return when (type.toLowerCase()) { + BluePrintConstants.DATA_TYPE_BOOLEAN -> jsonNodeFromObject(java.lang.Boolean.valueOf(value)) + BluePrintConstants.DATA_TYPE_INTEGER -> jsonNodeFromObject(Integer.valueOf(value)) + BluePrintConstants.DATA_TYPE_FLOAT -> jsonNodeFromObject(java.lang.Float.valueOf(value)) + BluePrintConstants.DATA_TYPE_DOUBLE -> jsonNodeFromObject(java.lang.Double.valueOf(value)) + else -> getJsonNode(value) + } + } + + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt new file mode 100644 index 000000000..965e965c6 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt @@ -0,0 +1,62 @@ +/* + * 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.core.utils + +import org.apache.commons.io.FileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import java.io.File +import java.net.URL +import java.nio.charset.Charset +/** + * + * + * @author Brinda Santh + */ +object ResourceResolverUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @JvmStatic + fun getFileContent(filename : String, basePath : String?): String { + log.trace("file ({}), basePath ({}) ", filename, basePath) + try{ + var resolvedFileName : String = filename + if(filename.startsWith("http", true) + || filename.startsWith("https", true)){ + val givenUrl : String = URL(filename).toString() + val systemUrl : String = File(".").toURI().toURL().toString() + log.trace("givenUrl ({}), systemUrl ({}) ", givenUrl, systemUrl) + if(givenUrl.startsWith(systemUrl)){ + + } + }else{ + if(!filename.startsWith("/")){ + if (checkNotEmpty(basePath)) { + resolvedFileName = basePath.plus(File.separator).plus(filename) + }else{ + resolvedFileName = javaClass.classLoader.getResource(".").path.plus(filename) + } + } + } + return FileUtils.readFileToString(File(resolvedFileName), Charset.defaultCharset()) + }catch (e : Exception){ + throw BluePrintException(e, "failed to file (%s), basePath (%s) ", filename, basePath) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt new file mode 100644 index 000000000..933161323 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt @@ -0,0 +1,110 @@ +/* + * 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.core.utils + +import org.apache.commons.io.FileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate +import java.io.File +import java.nio.charset.Charset + +/** + * + * + * @author Brinda Santh + */ +object ServiceTemplateUtils { + + @JvmStatic + fun getServiceTemplate(fileName: String): ServiceTemplate { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + return getServiceTemplateFromContent(content) + } + + + @JvmStatic + fun getServiceTemplateFromContent(content: String): ServiceTemplate { + return JacksonUtils.readValue(content) + } + + fun merge(parentServiceTemplate: ServiceTemplate, toMerge: ServiceTemplate, removeImports: Boolean? = true): ServiceTemplate { + if (removeImports!!) { + parentServiceTemplate.imports = null + toMerge.imports = null + } + + toMerge.metadata?.let { + parentServiceTemplate.metadata = parentServiceTemplate.metadata ?: hashMapOf() + parentServiceTemplate.metadata?.putAll(toMerge.metadata as MutableMap) + } + + toMerge.dslDefinitions?.let { + parentServiceTemplate.dslDefinitions = parentServiceTemplate.dslDefinitions ?: hashMapOf() + parentServiceTemplate.dslDefinitions?.putAll(toMerge.dslDefinitions as MutableMap) + } + + toMerge.dataTypes?.let { + parentServiceTemplate.dataTypes = parentServiceTemplate.dataTypes ?: hashMapOf() + parentServiceTemplate.dataTypes?.putAll(toMerge.dataTypes as MutableMap) + } + + toMerge.nodeTypes?.let { + parentServiceTemplate.nodeTypes = parentServiceTemplate.nodeTypes ?: hashMapOf() + parentServiceTemplate.nodeTypes?.putAll(toMerge.nodeTypes as MutableMap) + } + + toMerge.artifactTypes?.let { + parentServiceTemplate.artifactTypes = parentServiceTemplate.artifactTypes ?: hashMapOf() + parentServiceTemplate.artifactTypes?.putAll(toMerge.artifactTypes as MutableMap) + } + + toMerge.repositories?.let { + parentServiceTemplate.repositories = parentServiceTemplate.repositories ?: hashMapOf() + parentServiceTemplate.repositories?.putAll(toMerge.repositories as MutableMap) + } + + parentServiceTemplate.topologyTemplate = parentServiceTemplate.topologyTemplate ?: TopologyTemplate() + + toMerge.topologyTemplate?.inputs?.let { + parentServiceTemplate.topologyTemplate?.inputs = parentServiceTemplate.topologyTemplate?.inputs ?: hashMapOf() + parentServiceTemplate.topologyTemplate?.inputs?.putAll(parentServiceTemplate.topologyTemplate?.inputs as MutableMap) + } + + toMerge.topologyTemplate?.nodeTemplates?.let { + parentServiceTemplate.topologyTemplate?.nodeTemplates = parentServiceTemplate.topologyTemplate?.nodeTemplates ?: hashMapOf() + parentServiceTemplate.topologyTemplate?.nodeTemplates?.putAll(parentServiceTemplate.topologyTemplate?.nodeTemplates as MutableMap) + } + + toMerge.topologyTemplate?.relationshipTemplates?.let { + parentServiceTemplate.topologyTemplate?.relationshipTemplates = parentServiceTemplate.topologyTemplate?.relationshipTemplates ?: hashMapOf() + parentServiceTemplate.topologyTemplate?.relationshipTemplates?.putAll(parentServiceTemplate.topologyTemplate?.relationshipTemplates as MutableMap) + } + + toMerge.topologyTemplate?.policies?.let { + parentServiceTemplate.topologyTemplate?.policies = parentServiceTemplate.topologyTemplate?.policies ?: hashMapOf() + parentServiceTemplate.topologyTemplate?.policies?.putAll(parentServiceTemplate.topologyTemplate?.policies as MutableMap) + } + + toMerge.topologyTemplate?.workflows?.let { + parentServiceTemplate.topologyTemplate?.workflows = parentServiceTemplate.topologyTemplate?.workflows ?: hashMapOf() + parentServiceTemplate.topologyTemplate?.workflows?.putAll(parentServiceTemplate.topologyTemplate?.workflows as MutableMap) + } + return parentServiceTemplate + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt new file mode 100644 index 000000000..b3adab085 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtils.kt @@ -0,0 +1,131 @@ +/* + * 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.core.utils + +import java.util.* + +/** + * + * + * @author Brinda Santh + */ +class TopologicalSortingUtils { + + private val neighbors: MutableMap> = hashMapOf() + + val isDag: Boolean + get() = topSort() != null + + override fun toString(): String { + val s = StringBuffer() + for (v in neighbors.keys) + s.append("\n " + v + " -> " + neighbors[v]) + return s.toString() + } + + fun getNeighbors(): Map> { + return neighbors + } + + fun add(vertex: V) { + if (neighbors.containsKey(vertex)) + return + neighbors[vertex] = arrayListOf() + } + + operator fun contains(vertex: V): Boolean { + return neighbors.containsKey(vertex) + } + + fun add(from: V, to: V) { + this.add(from) + this.add(to) + neighbors[from]?.add(to) + } + + fun remove(from: V, to: V) { + if (!(this.contains(from) && this.contains(to))) + throw IllegalArgumentException("Nonexistent vertex") + neighbors[from]?.remove(to) + } + + fun outDegree(): Map { + val result: MutableMap = hashMapOf() + for (v in neighbors.keys) + result[v] = neighbors[v]!!.size + return result + } + + + fun inDegree(): MutableMap { + val result = HashMap() + for (v in neighbors.keys) + result[v] = 0 // All in-degrees are 0 + for (from in neighbors.keys) { + for (to in neighbors[from]!!) { + result[to] = result[to]!! + 1 // Increment in-degree + } + } + return result + } + + fun topSort(): List? { + val degree = inDegree() + // Determine all vertices with zero in-degree + val zeroVerts = Stack() // Stack as good as any here + for (v in degree.keys) { + if (degree[v] == 0) zeroVerts.push(v) + } + // Determine the topological order + val result = ArrayList() + while (!zeroVerts.isEmpty()) { + val v = zeroVerts.pop() // Choose a vertex with zero in-degree + result.add(v) // Vertex v is next in topol order + // "Remove" vertex v by updating its neighbors + for (neighbor in neighbors[v]!!) { + degree[neighbor] = degree[neighbor]!! - 1 + // Remember any vertices that now have zero in-degree + if (degree[neighbor] == 0) zeroVerts.push(neighbor) + } + } + // Check that we have used the entire graph (if not, there was a cycle) + return if (result.size != neighbors.size) null else result + } + + + fun bfsDistance(start: V): Map<*, *> { + val distance: MutableMap = hashMapOf() + // Initially, all distance are infinity, except start node + for (v in neighbors.keys) + distance[v] = -1 + distance[start] = 0 + // Process nodes in queue order + val queue = LinkedList() + queue.offer(start) // Place start node in queue + while (!queue.isEmpty()) { + val v = queue.remove() + val vDist = distance[v]!! + // Update neighbors + for (neighbor in neighbors[v]!!) { + if (distance[neighbor] != null) continue // Ignore if already done + distance[neighbor] = vDist + 1 + queue.offer(neighbor) + } + } + return distance + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintArtifactTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintArtifactTypeValidatorImpl.kt new file mode 100644 index 000000000..e383588ee --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintArtifactTypeValidatorImpl.kt @@ -0,0 +1,33 @@ +/* + * 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.core.validation + +import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintArtifactTypeValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + +open class BluePrintArtifactTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintArtifactTypeValidator { + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactType: ArtifactType) { + + artifactType.properties?.let { + bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, artifactType.properties!!) + } + // TODO ("Files Present ") + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintAttributeDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintAttributeDefinitionValidatorImpl.kt new file mode 100644 index 000000000..53a27b53d --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintAttributeDefinitionValidatorImpl.kt @@ -0,0 +1,29 @@ +/* + * 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.core.validation + +import org.onap.ccsdk.apps.controllerblueprints.core.data.AttributeDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + +open class BluePrintAttributeDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintAttributeDefinitionValidator { + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: AttributeDefinition) { + //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintDataTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintDataTypeValidatorImpl.kt new file mode 100644 index 000000000..980302bf9 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintDataTypeValidatorImpl.kt @@ -0,0 +1,37 @@ +/* + * 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.core.validation + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintDataTypeValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + +open class BluePrintDataTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintDataTypeValidator { + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintDataTypeValidatorImpl::class.toString()) + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, dataType: DataType) { + log.trace("Validating DataType($name)") + + dataType.properties?.let { + + bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, dataType.properties!!) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt new file mode 100644 index 000000000..0ed87f813 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt @@ -0,0 +1,298 @@ +/* + * 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.core.validation + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTemplateValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils + + +open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintNodeTemplateValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateValidatorImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + var paths: MutableList = arrayListOf() + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, nodeTemplate: NodeTemplate) { + log.info("Validating NodeTemplate($nodeTemplateName)") + + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + paths.add(nodeTemplateName) + + val type: String = nodeTemplate.type + + val nodeType: NodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(type) + ?: throw BluePrintException("Failed to get NodeType($type) definition for NodeTemplate($nodeTemplateName)") + + nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } + nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeType, nodeTemplateName, nodeTemplate) } + nodeTemplate.requirements?.let { validateRequirementAssignments(nodeType, nodeTemplateName, nodeTemplate) } + nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeType, nodeTemplateName, nodeTemplate) } + nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) } + + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateArtifactDefinitions(artifacts: MutableMap) { + paths.add("artifacts") + artifacts.forEach { artifactDefinitionName, artifactDefinition -> + paths.add(artifactDefinitionName) + val type: String = artifactDefinition.type + ?: throw BluePrintException("type is missing for ArtifactDefinition$artifactDefinitionName)") + // Check Artifact Type + checkValidArtifactType(artifactDefinitionName, type) + + val file: String = artifactDefinition.file + ?: throw BluePrintException("file is missing for ArtifactDefinition($artifactDefinitionName)") + + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + + @Throws(BluePrintException::class) + open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, + properties: MutableMap) { + properties.forEach { propertyName, propertyAssignment -> + val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] + ?: throw BluePrintException("failed to get definition for the property ($propertyName)") + + validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + + } + } + + @Throws(BluePrintException::class) + open fun validatePropertyAssignment(propertyName: String, propertyDefinition: PropertyDefinition, + propertyAssignment: JsonNode) { + // Check and Validate if Expression Node + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyName, propertyDefinition, propertyAssignment) + } + } + + @Throws(BluePrintException::class) + open fun validateCapabilityAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { + val capabilities = nodeTemplate.capabilities + paths.add("capabilities") + capabilities?.forEach { capabilityName, capabilityAssignment -> + paths.add(capabilityName) + + val capabilityDefinition = nodeType.capabilities?.get(capabilityName) + ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) capability definition ($capabilityName) " + + "from NodeType(${nodeTemplate.type})") + + validateCapabilityAssignment(nodeTemplateName, capabilityName, capabilityDefinition, capabilityAssignment) + + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + @Throws(BluePrintException::class) + open fun validateCapabilityAssignment(nodeTemplateName: String, capabilityName: String, + capabilityDefinition: CapabilityDefinition, capabilityAssignment: CapabilityAssignment) { + + capabilityAssignment.properties?.let { validatePropertyAssignments(capabilityDefinition.properties!!, capabilityAssignment.properties!!) } + + } + + @Throws(BluePrintException::class) + open fun validateRequirementAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { + val requirements = nodeTemplate.requirements + paths.add("requirements") + requirements?.forEach { requirementName, requirementAssignment -> + paths.add(requirementName) + val requirementDefinition = nodeType.requirements?.get(requirementName) + ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) requirement definition ($requirementName) from" + + " NodeType(${nodeTemplate.type})") + // Validate Requirement Assignment + validateRequirementAssignment(nodeTemplateName, requirementName, requirementDefinition, requirementAssignment) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + + } + + @Throws(BluePrintException::class) + open fun validateRequirementAssignment(nodeTemplateName: String, requirementAssignmentName: String, + requirementDefinition: RequirementDefinition, requirementAssignment: RequirementAssignment) { + log.info("Validating NodeTemplate({}) requirement assignment ({}) ", nodeTemplateName, requirementAssignmentName) + val requirementNodeTemplateName = requirementAssignment.node!! + val capabilityName = requirementAssignment.capability + val relationship = requirementAssignment.relationship!! + + check(BluePrintTypes.validRelationShipDerivedFroms.contains(relationship)) { + throw BluePrintException("Failed to get relationship type ($relationship) for NodeTemplate($nodeTemplateName)'s requirement($requirementAssignmentName)") + } + + val relationShipNodeTemplate = bluePrintContext.serviceTemplate.topologyTemplate?.nodeTemplates?.get(requirementNodeTemplateName) + ?: throw BluePrintException("Failed to get requirement NodeTemplate($requirementNodeTemplateName)'s " + + "for NodeTemplate($nodeTemplateName) requirement($requirementAssignmentName)") + + relationShipNodeTemplate.capabilities?.get(capabilityName) + ?: throw BluePrintException("Failed to get requirement NodeTemplate($requirementNodeTemplateName)'s " + + "capability($capabilityName) for NodeTemplate ($nodeTemplateName)'s requirement($requirementAssignmentName)") + + + } + + @Throws(BluePrintException::class) + open fun validateInterfaceAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { + + val interfaces = nodeTemplate.interfaces + paths.add("interfaces") + interfaces?.forEach { interfaceAssignmentName, interfaceAssignment -> + paths.add(interfaceAssignmentName) + val interfaceDefinition = nodeType.interfaces?.get(interfaceAssignmentName) + ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) interface definition ($interfaceAssignmentName) from" + + " NodeType(${nodeTemplate.type})") + + validateInterfaceAssignment(nodeTemplateName, interfaceAssignmentName, interfaceDefinition, + interfaceAssignment) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + + + } + + @Throws(BluePrintException::class) + open fun validateInterfaceAssignment(nodeTemplateName: String, interfaceAssignmentName: String, + interfaceDefinition: InterfaceDefinition, + interfaceAssignment: InterfaceAssignment) { + + val operations = interfaceAssignment.operations + operations?.let { + validateInterfaceOperationsAssignment(nodeTemplateName, interfaceAssignmentName, interfaceDefinition, + interfaceAssignment) + } + + } + + @Throws(BluePrintException::class) + open fun validateInterfaceOperationsAssignment(nodeTemplateName: String, interfaceAssignmentName: String, + interfaceDefinition: InterfaceDefinition, + interfaceAssignment: InterfaceAssignment) { + + val operations = interfaceAssignment.operations + operations?.let { + it.forEach { operationAssignmentName, operationAssignments -> + + val operationDefinition = interfaceDefinition.operations?.get(operationAssignmentName) + ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation definition ($operationAssignmentName)") + + log.info("Validation NodeTemplate($nodeTemplateName) Interface($interfaceAssignmentName) Operation ($operationAssignmentName)") + + val inputs = operationAssignments.inputs + val outputs = operationAssignments.outputs + + inputs?.forEach { propertyName, propertyAssignment -> + val propertyDefinition = operationDefinition.inputs?.get(propertyName) + ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation " + + "definition ($operationAssignmentName) property definition($propertyName)") + // Check the property values with property definition + validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + } + + outputs?.forEach { propertyName, propertyAssignment -> + val propertyDefinition = operationDefinition.outputs?.get(propertyName) + ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation definition ($operationAssignmentName) " + + "output property definition($propertyName)") + // Check the property values with property definition + validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + } + + } + } + + } + + open fun checkValidArtifactType(artifactDefinitionName: String, artifactTypeName: String) { + + val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName) + ?: throw BluePrintException("failed to get artifactType($artifactTypeName) for ArtifactDefinition($artifactDefinitionName)") + + checkValidArtifactTypeDerivedFrom(artifactTypeName, artifactType.derivedFrom) + } + + @Throws(BluePrintException::class) + open fun checkValidArtifactTypeDerivedFrom(artifactTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validArtifactTypeDerivedFroms.contains(derivedFrom)) { + throw BluePrintException("failed to get artifactType($artifactTypeName)'s derivedFrom($derivedFrom) definition") + } + } + + open fun checkPropertyValue(propertyName: String, propertyDefinition: PropertyDefinition, propertyAssignment: JsonNode) { + val propertyType = propertyDefinition.type + val isValid: Boolean + + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { + isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) + + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + + val entrySchemaType = propertyDefinition.entrySchema?.type + ?: throw BluePrintException(format("Failed to get EntrySchema type for the collection property ({})", propertyName)) + + if (!BluePrintTypes.validPropertyTypes().contains(entrySchemaType)) { + checkPropertyDataType(entrySchemaType, propertyName) + } + isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) + } else { + checkPropertyDataType(propertyType, propertyName) + isValid = true + } + + check(isValid) { + throw BluePrintException("property(propertyName) defined of type(propertyType) is not comptable with the value (propertyAssignment)") + } + } + + private fun checkPropertyDataType(dataTypeName: String, propertyName: String) { + + val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) + ?: throw BluePrintException("DataType ($dataTypeName) for the property ($propertyName) not found") + + checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom) + + } + + private fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) { + throw BluePrintException("Failed to get DataType($dataTypeName)'s derivedFrom($derivedFrom) definition ") + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt new file mode 100644 index 000000000..1077f347e --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt @@ -0,0 +1,155 @@ +/* + * 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.core.validation + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + + +open class BluePrintNodeTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintNodeTypeValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + var paths: MutableList = arrayListOf() + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTypeName: String, nodeType: NodeType) { + log.trace("Validating NodeType($nodeTypeName)") + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + paths.add(nodeTypeName) + + val derivedFrom: String = nodeType.derivedFrom + //Check Derived From + checkValidNodeTypesDerivedFrom(nodeTypeName, derivedFrom) + + if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { + bluePrintContext.serviceTemplate.nodeTypes?.get(derivedFrom) + ?: throw BluePrintException("Failed to get derivedFrom NodeType($derivedFrom)'s for NodeType($nodeTypeName)") + } + + nodeType.properties?.let { bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!) } + nodeType.capabilities?.let { validateCapabilityDefinitions(nodeTypeName, nodeType) } + nodeType.requirements?.let { validateRequirementDefinitions(nodeTypeName, nodeType) } + nodeType.interfaces?.let { validateInterfaceDefinitions(nodeType.interfaces!!) } + + paths.removeAt(paths.lastIndex) + } + + fun checkValidNodeTypesDerivedFrom(nodeTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validNodeTypeDerivedFroms.contains(derivedFrom)) { + throw BluePrintException("Failed to get node type ($nodeTypeName)'s derivedFrom($derivedFrom) definition ") + } + } + + open fun validateCapabilityDefinitions(nodeTypeName: String, nodeType: NodeType) { + val capabilities = nodeType.capabilities + paths.add("capabilities") + capabilities?.forEach { capabilityName, capabilityDefinition -> + paths.add(capabilityName) + + validateCapabilityDefinition(nodeTypeName, nodeType, capabilityName, capabilityDefinition) + + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + open fun validateCapabilityDefinition(nodeTypeName: String, nodeType: NodeType, capabilityName: String, + capabilityDefinition: CapabilityDefinition) { + val capabilityType = capabilityDefinition.type + check(BluePrintTypes.validCapabilityTypes.contains(capabilityType)) { + throw BluePrintException("failed to get CapabilityType($capabilityType) for NodeType($nodeTypeName)") + } + } + + open fun validateRequirementDefinitions(nodeName: String, nodeType: NodeType) { + paths.add("requirements") + val requirements = nodeType.requirements + + requirements?.forEach { requirementDefinitionName, requirementDefinition -> + paths.add(requirementDefinitionName) + validateRequirementDefinition(nodeName, nodeType, requirementDefinitionName, requirementDefinition) + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + open fun validateRequirementDefinition(nodeTypeName: String, nodeType: NodeType, requirementDefinitionName: String, + requirementDefinition: RequirementDefinition) { + + log.info("validating NodeType({}) RequirementDefinition ({}) ", nodeTypeName, requirementDefinitionName) + val requirementNodeTypeName = requirementDefinition.node!! + val capabilityName = requirementDefinition.capability + val relationship = requirementDefinition.relationship!! + + check(BluePrintTypes.validRelationShipDerivedFroms.contains(relationship)) { + throw BluePrintException("failed to get relationship($relationship) for NodeType($nodeTypeName)'s requirement($requirementDefinitionName)") + } + + val relationShipNodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(requirementNodeTypeName) + ?: throw BluePrintException("failed to get requirement NodeType($requirementNodeTypeName)'s for requirement($requirementDefinitionName) ") + + relationShipNodeType.capabilities?.get(capabilityName) + ?: throw BluePrintException("failed to get requirement NodeType($requirementNodeTypeName)'s " + + "capability($nodeTypeName) for NodeType ($capabilityName)'s requirement($requirementDefinitionName) ") + + } + + open fun validateInterfaceDefinitions(interfaces: MutableMap) { + paths.add("interfaces") + interfaces.forEach { interfaceName, interfaceDefinition -> + paths.add(interfaceName) + interfaceDefinition.operations?.let { validateOperationDefinitions(interfaceDefinition.operations!!) } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + open fun validateOperationDefinitions(operations: MutableMap) { + paths.add("operations") + operations.forEach { opertaionName, operationDefinition -> + paths.add(opertaionName) + operationDefinition.implementation?.let { validateImplementation(operationDefinition.implementation!!) } + + operationDefinition.inputs?.let { + bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, operationDefinition.inputs!!) + } + + operationDefinition.outputs?.let { + bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, operationDefinition.outputs!!) + } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + } + + open fun validateImplementation(implementation: Implementation) { + checkNotEmptyOrThrow(implementation.primary) + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintPropertyDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintPropertyDefinitionValidatorImpl.kt new file mode 100644 index 000000000..ca156190c --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintPropertyDefinitionValidatorImpl.kt @@ -0,0 +1,83 @@ +/* + * 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.core.validation + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPropertyDefinitionValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + +open class BluePrintPropertyDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintPropertyDefinitionValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) { + this.bluePrintRuntimeService = bluePrintRuntimeService + + + log.trace("Validating PropertyDefinition($name)") + + val dataType: String = propertyDefinition.type + + when { + BluePrintTypes.validPrimitiveTypes().contains(dataType) -> { + // Do Nothing + } + BluePrintTypes.validCollectionTypes().contains(dataType) -> { + val entrySchemaType: String = propertyDefinition.entrySchema?.type + ?: throw BluePrintException(format("Entry schema for DataType ({}) for the property ({}) not found", dataType, name)) + checkPrimitiveOrComplex(entrySchemaType, name) + } + else -> checkPropertyDataType(dataType, name) + } + } + + + private fun checkPrimitiveOrComplex(dataType: String, propertyName: String): Boolean { + if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) { + return true + } else { + throw BluePrintException(format("DataType({}) for the property({}) is not valid", dataType, propertyName)) + } + } + + private fun checkPropertyDataType(dataTypeName: String, propertyName: String) { + + val dataType = bluePrintRuntimeService.bluePrintContext().serviceTemplate.dataTypes?.get(dataTypeName) + ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataTypeName, propertyName)) + + checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom) + } + + private fun checkDataType(key: String): Boolean { + return bluePrintRuntimeService.bluePrintContext().serviceTemplate.dataTypes?.containsKey(key) ?: false + } + + open fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) { + throw BluePrintException(format("Failed to get DataType({})'s derivedFrom({}) definition ", dataTypeName, derivedFrom)) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintServiceTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintServiceTemplateValidatorImpl.kt new file mode 100644 index 000000000..61159cf8b --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintServiceTemplateValidatorImpl.kt @@ -0,0 +1,107 @@ +/* + * 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.core.validation + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.google.common.base.Preconditions +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintServiceTemplateValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + +open class BluePrintServiceTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintServiceTemplateValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var error: BluePrintError + + var paths: MutableList = arrayListOf() + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) { + log.trace("Validating Service Template..") + try { + this.bluePrintRuntimeService = bluePrintRuntimeService + this.error = bluePrintRuntimeService.getBluePrintError() + + serviceTemplate.metadata?.let { validateMetadata(serviceTemplate.metadata!!) } + serviceTemplate.dataTypes?.let { validateDataTypes(serviceTemplate.dataTypes!!) } + serviceTemplate.artifactTypes?.let { validateArtifactTypes(serviceTemplate.artifactTypes!!) } + serviceTemplate.nodeTypes?.let { validateNodeTypes(serviceTemplate.nodeTypes!!) } + serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) } + } catch (e: Exception) { + log.error("failed in blueprint service template validation", e) + error.addError(BluePrintConstants.PATH_SERVICE_TEMPLATE, paths.joinToString(BluePrintConstants.PATH_DIVIDER), e.message!!) + } + } + + fun validateMetadata(metaDataMap: MutableMap) { + + paths.add(BluePrintConstants.PATH_METADATA) + + val templateName = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME] + val templateVersion = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION] + val templateTags = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS] + val templateAuthor = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] + + Preconditions.checkArgument(StringUtils.isNotBlank(templateName), "failed to get template name metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateVersion), "failed to get template version metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateTags), "failed to get template tags metadata") + Preconditions.checkArgument(StringUtils.isNotBlank(templateAuthor), "failed to get template author metadata") + + paths.removeAt(paths.lastIndex) + } + + + fun validateDataTypes(dataTypes: MutableMap) { + + paths.add(BluePrintConstants.PATH_DATA_TYPES) + dataTypes.forEach { dataTypeName, dataType -> + // Validate Single Data Type + bluePrintTypeValidatorService.validateDataType(bluePrintRuntimeService, dataTypeName, dataType) + } + paths.removeAt(paths.lastIndex) + } + + fun validateArtifactTypes(artifactTypes: MutableMap) { + paths.add(BluePrintConstants.PATH_ARTIFACT_TYPES) + artifactTypes.forEach { artifactName, artifactType -> + // Validate Single Artifact Type + bluePrintTypeValidatorService.validateArtifactType(bluePrintRuntimeService, artifactName, artifactType) + } + paths.removeAt(paths.lastIndex) + } + + fun validateNodeTypes(nodeTypes: MutableMap) { + paths.add(BluePrintConstants.PATH_NODE_TYPES) + nodeTypes.forEach { nodeTypeName, nodeType -> + // Validate Single Node Type + bluePrintTypeValidatorService.validateNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) + } + paths.removeAt(paths.lastIndex) + } + + fun validateTopologyTemplate(topologyTemplate: TopologyTemplate) { + paths.add(BluePrintConstants.PATH_TOPOLOGY_TEMPLATE) + bluePrintTypeValidatorService.validateTopologyTemplate(bluePrintRuntimeService, "topologyTemplate", topologyTemplate) + paths.removeAt(paths.lastIndex) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintTopologyTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintTopologyTemplateValidatorImpl.kt new file mode 100644 index 000000000..b87666d2d --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintTopologyTemplateValidatorImpl.kt @@ -0,0 +1,72 @@ +/* + * 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.core.validation + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTopologyTemplateValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + +open class BluePrintTopologyTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintTopologyTemplateValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) { + log.trace("Validating Topology Template..") + this.bluePrintRuntimeService = bluePrintRuntimeService + + // Validate Inputs + topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) } + // Validate Node Templates + topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) } + // Validate Workflow + topologyTemplate.workflows?.let { validateWorkflows(topologyTemplate.workflows!!) } + } + + @Throws(BluePrintException::class) + fun validateInputs(inputs: MutableMap) { + bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, inputs) + } + + + @Throws(BluePrintException::class) + fun validateNodeTemplates(nodeTemplates: MutableMap) { + + nodeTemplates.forEach { nodeTemplateName, nodeTemplate -> + // Validate Single Node Template + bluePrintTypeValidatorService.validateNodeTemplate(bluePrintRuntimeService, nodeTemplateName, nodeTemplate) + } + } + + @Throws(BluePrintException::class) + open fun validateWorkflows(workflows: MutableMap) { + + workflows.forEach { workflowName, workflow -> + // Validate Single workflow + bluePrintTypeValidatorService.validateWorkflow(bluePrintRuntimeService, workflowName, workflow) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImpl.kt new file mode 100644 index 000000000..4f68342eb --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImpl.kt @@ -0,0 +1,48 @@ +/* + * 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.core.validation + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import java.util.* + + +open class BluePrintValidatorServiceImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintValidatorService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorServiceImpl::class.toString()) + + override fun validateBluePrints(basePath: String): Boolean { + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(UUID.randomUUID().toString(), basePath) + return validateBluePrints(bluePrintRuntimeService) + } + + override fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean { + + bluePrintTypeValidatorService.validateServiceTemplate(bluePrintRuntimeService, "service_template", + bluePrintRuntimeService.bluePrintContext().serviceTemplate) + if (bluePrintRuntimeService.getBluePrintError().errors.size > 0) { + throw BluePrintException("failed in blueprint validation : ${bluePrintRuntimeService.getBluePrintError().errors.joinToString("\n")}") + } + return true + } +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt new file mode 100644 index 000000000..61918fbc9 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt @@ -0,0 +1,76 @@ +/* + * 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.core.validation + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowValidator +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService + +open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintWorkflowValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + + var paths: MutableList = arrayListOf() + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, workflowName: String, workflow: Workflow) { + log.info("Validating Workflow($workflowName)") + + this.bluePrintRuntimeService = bluePrintRuntimeService + + + paths.add(workflowName) + paths.joinToString(BluePrintConstants.PATH_DIVIDER) + + // Step Validation Start + paths.add("steps") + workflow.steps?.forEach { stepName, step -> + paths.add(stepName) + paths.joinToString(BluePrintConstants.PATH_DIVIDER) + + // Validate target + step.target?.let { + try { + val nodeTemplate = bluePrintRuntimeService.bluePrintContext().nodeTemplateByName(it) + + val nodeTypeDerivedFrom = bluePrintRuntimeService.bluePrintContext().nodeTemplateNodeType(it).derivedFrom + + check(nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_DG) { + "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected is " + + "'${BluePrintConstants.MODEL_TYPE_NODE_DG}'" + } + } catch (e: Exception) { + bluePrintRuntimeService.getBluePrintError() + .addError("Failed to validate Workflow($workflowName)'s step($stepName)'s " + + "definition", paths.joinToString(BluePrintConstants.PATH_DIVIDER), e.message!!) + } + } + paths.removeAt(paths.lastIndex) + } + paths.removeAt(paths.lastIndex) + // Step Validation Ends + paths.removeAt(paths.lastIndex) + + workflow.inputs?.let { + bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.inputs!!) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory b/ms/controllerblueprints/modules/blueprint-core/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory new file mode 100644 index 000000000..89838f44f --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory @@ -0,0 +1,17 @@ +# +# 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. +# + +org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt new file mode 100644 index 000000000..1b315a211 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctionsTest.kt @@ -0,0 +1,35 @@ +/* + * 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.core + +import org.junit.Test +import kotlin.test.assertEquals +/** + * + * + * @author Brinda Santh + */ +class CustomFunctionsTest { + @Test + fun testFormat(): Unit { + val returnValue : String = format("This is {} for times {}", "test", 2) + assertEquals("This is test for times 2", returnValue, "Failed to format String") + + val returnValue1 : String = format("This is test for times 2") + assertEquals("This is test for times 2", returnValue1, "Failed to format empty args") + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/mock/MockBluePrintTypeValidatorService.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/mock/MockBluePrintTypeValidatorService.kt new file mode 100644 index 000000000..4c174f92e --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/mock/MockBluePrintTypeValidatorService.kt @@ -0,0 +1,59 @@ +/* + * 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.core.mock + +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.* +import org.onap.ccsdk.apps.controllerblueprints.core.validation.* + +class MockBluePrintTypeValidatorService : BluePrintTypeValidatorService { + + override fun getServiceTemplateValidators(): List { + return listOf(BluePrintServiceTemplateValidatorImpl(this)) + } + + override fun getDataTypeValidators(): List { + return listOf(BluePrintDataTypeValidatorImpl(this)) + } + + override fun getArtifactTypeValidators(): List { + return listOf(BluePrintArtifactTypeValidatorImpl(this)) + } + + override fun getNodeTypeValidators(): List { + return listOf(BluePrintNodeTypeValidatorImpl(this)) + } + + override fun getTopologyTemplateValidators(): List { + return listOf(BluePrintTopologyTemplateValidatorImpl(this)) + } + + override fun getNodeTemplateValidators(): List { + return listOf(BluePrintNodeTemplateValidatorImpl(this)) + } + + override fun getWorkflowValidators(): List { + return listOf(BluePrintWorkflowValidatorImpl(this)) + } + + override fun getPropertyDefinitionValidators(): List { + return listOf(BluePrintPropertyDefinitionValidatorImpl(this)) + } + + override fun getAttributeDefinitionValidators(): List { + return listOf(BluePrintAttributeDefinitionValidatorImpl(this)) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt new file mode 100644 index 000000000..0c4d94f3c --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContextTest.kt @@ -0,0 +1,54 @@ +/* + * 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.core.service + + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import kotlin.test.assertNotNull + +/** + * + * + * @author Brinda Santh + */ +class BluePrintContextTest { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + + @Test + fun testBluePrintContextCreation() { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath) + assertNotNull(bluePrintContext, "Failed to populate Blueprint context") + } + + @Test + fun testChainedProperty() { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath) + val nodeType = bluePrintContext.nodeTypeChained("component-resource-assignment") + assertNotNull(nodeType, "Failed to get chained node type") + log.trace("Properties {}", JacksonUtils.getJson(nodeType, true)) + } + + +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt new file mode 100644 index 000000000..d68892fc1 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt @@ -0,0 +1,117 @@ +/* + * 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.core.service + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.data.ExpressionData +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +/** + * + * + * @author Brinda Santh + */ +class BluePrintExpressionServiceTest { + @Test + fun testInputExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_input\" : \"input-name\" }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.inputExpression, " Failed to populate input expression data") + assertEquals("input-name", expressionData.inputExpression?.propertyName, "Failed to get propertyName from expression data") + } + + @Test + fun testPropertyExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"property-name\"] }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.propertyExpression, " Failed to populate property expression data") + assertEquals("SELF", expressionData.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("property-name", expressionData.propertyExpression?.propertyName, " Failed to get expected propertyName") + + val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"\",\"property-name\", \"resource\", \"name\"] }") + val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1) + assertNotNull(expressionData1, " Failed to populate expression data") + assertEquals(expressionData1.isExpression, true, "Failed to identify as nested property expression") + assertNotNull(expressionData1.propertyExpression, " Failed to populate nested property expression data") + assertEquals("SELF", expressionData1.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("property-name", expressionData1.propertyExpression?.propertyName, " Failed to get expected propertyName") + assertEquals("resource/name",expressionData1.propertyExpression?.subPropertyName, " Failed to populate nested subPropertyName expression data") + } + + @Test + fun testAttributeExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"resource\"] }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.attributeExpression, " Failed to populate attribute expression data") + assertEquals("SELF", expressionData.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("resource", expressionData.attributeExpression?.attributeName, " Failed to get expected attributeName") + + val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"\",\"attribute-name\", \"resource\", \"name\"] }") + val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1) + assertNotNull(expressionData1, " Failed to populate expression data") + assertEquals(expressionData1.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData1.attributeExpression, " Failed to populate attribute expression data") + assertEquals("SELF", expressionData1.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("attribute-name", expressionData1.attributeExpression?.attributeName, " Failed to get expected attributeName") + assertEquals("resource/name",expressionData1.attributeExpression?.subAttributeName, " Failed to populate nested subAttributeName expression data") + } + + + @Test + fun testOutputOperationExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_operation_output\": [\"SELF\", \"interface-name\", \"operation-name\", \"output-property-name\"] }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.operationOutputExpression, " Failed to populate output expression data") + assertEquals("SELF", expressionData.operationOutputExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("interface-name", expressionData.operationOutputExpression?.interfaceName, " Failed to get expected interfaceName") + assertEquals("operation-name", expressionData.operationOutputExpression?.operationName, " Failed to get expected operationName") + assertEquals("output-property-name", expressionData.operationOutputExpression?.propertyName, " Failed to get expected propertyName") + } + + + @Test + fun testArtifactExpression() { + val node : JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\"] }") + val expressionData : ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.artifactExpression, " Failed to populate Artifact expression data") + assertEquals("SELF", expressionData.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("artifact-template", expressionData.artifactExpression?.artifactName, " Failed to get expected artifactName") + + + val node1 : JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\", \"location\", true] }") + val expressionData1 : ExpressionData = BluePrintExpressionService.getExpressionData(node1) + assertNotNull(expressionData1, " Failed to populate expression data") + assertEquals(expressionData1.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData1.artifactExpression, " Failed to populate Artifact expression data") + assertEquals("SELF", expressionData1.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("artifact-template", expressionData1.artifactExpression?.artifactName, " Failed to get expected artifactName") + assertEquals("location", expressionData1.artifactExpression?.location, " Failed to get expected location") + assertEquals(true, expressionData1.artifactExpression?.remove, " Failed to get expected remove") + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt new file mode 100644 index 000000000..6f942a365 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -0,0 +1,57 @@ +/* + * 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.core.service + +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import kotlin.test.assertNotNull + +/** + * BluePrintRepoFileServiceTest + * @author Brinda Santh + * + */ +class BluePrintRepoFileServiceTest { + + private val basePath = "load/model_type" + private val bluePrintRepoFileService = BluePrintRepoFileService(basePath) + + @Test + fun testGetDataType() { + val dataType = bluePrintRepoFileService.getDataType("dt-v4-aggregate") + assertNotNull(dataType, "Failed to get DataType from repo") + } + + @Test + fun testGetNodeType() { + val nodeType = bluePrintRepoFileService.getNodeType("component-resource-assignment") + assertNotNull(nodeType, "Failed to get NodeType from repo") + } + + @Test + fun testGetArtifactType() { + val nodeType = bluePrintRepoFileService.getArtifactType("artifact-template-velocity") + assertNotNull(nodeType, "Failed to get ArtifactType from repo") + } + + @Test(expected = BluePrintException::class) + fun testModelNotFound() { + val dataType = bluePrintRepoFileService.getDataType("dt-not-found") + assertNotNull(dataType, "Failed to get DataType from repo") + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt new file mode 100644 index 000000000..7a178758a --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt @@ -0,0 +1,144 @@ +/* + * 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.core.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +/** + * + * + * @author Brinda Santh + */ +class BluePrintRuntimeServiceTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @Test + fun `test Resolve NodeTemplate Properties`() { + log.info("************************ testResolveNodeTemplateProperties **********************") + + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val inputDataPath = "src/test/resources/data/default-context.json" + + val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath) + bluePrintRuntimeService.assignInputs(inputNode) + + val propContext: MutableMap = bluePrintRuntimeService + .resolveNodeTemplateProperties("activate-process") + + assertNotNull(propContext, "Failed to populate interface property values") + } + + @Test + fun `test resolve NodeTemplate Capability Properties`() { + log.info("************************ testResolveNodeTemplateRequirementProperties **********************") + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val executionContext = bluePrintRuntimeService.getExecutionContext() + + BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(), + "data/default-context.json", executionContext) + + val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device", + "netconf") + assertNotNull(capProperties, "Failed to populate capability property values") + assertEquals(capProperties["target-ip-address"], JacksonUtils.jsonNodeFromObject("localhost"), "Failed to populate parameter target-ip-address") + assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number") + } + + @Test + fun `test Resolve NodeTemplate Interface Operation Inputs`() { + log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************") + + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val executionContext = bluePrintRuntimeService.getExecutionContext() + + BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(), + "data/default-context.json", executionContext) + + val inContext: MutableMap = bluePrintRuntimeService + .resolveNodeTemplateInterfaceOperationInputs("resource-assignment", + "ResourceAssignmentComponent", "process") + + assertNotNull(inContext, "Failed to populate interface input property values") + assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name") + assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name") + } + + @Test + fun `test Resolve NodeTemplate Interface Operation Outputs`() { + log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************") + + val bluePrintRuntimeService = getBluePrintRuntimeService() + + bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance()) + + bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment", + "ResourceAssignmentComponent", "process") + + val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment", + "ResourceAssignmentComponent", "process", "status") + assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status") + + val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment", + "ResourceAssignmentComponent", "process", "resource-assignment-params") + assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params") + + } + + @Test + fun `test NodeTemplate Context Property`() { + log.info("************************ testNodeTemplateContextProperty **********************") + val bluePrintRuntimeService = getBluePrintRuntimeService() + + bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1", + JacksonUtils.jsonNodeFromObject("context1-value")) + bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2", + JacksonUtils.jsonNodeFromObject("context2-value")) + + val keys = listOf("context1", "context2") + + val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys) + assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties") + log.info("JSON Prepared Value Context {}", jsonValueNode) + + } + + private fun getBluePrintRuntimeService(): BluePrintRuntimeService> { + val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) + val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH) + + assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation") + + return blueprintRuntime + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt new file mode 100644 index 000000000..663a3751a --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt @@ -0,0 +1,35 @@ +/* + * 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.core.service + +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import kotlin.test.assertNotNull + +class BluePrintTemplateServiceTest { + + @Test + fun testGenerateContent() { + + val template = JacksonUtils.getClassPathFileContent("templates/base-config-template.vtl") + val json = JacksonUtils.getClassPathFileContent("templates/base-config-data.json") + + val content = BluePrintTemplateService.generateContent(template, json) + assertNotNull(content, "failed to generate content for velocity template") + + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt new file mode 100644 index 000000000..861f7d095 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt @@ -0,0 +1,50 @@ +/* + * 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.core.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils + +/** + * + * + * @author Brinda Santh + */ +class BluePrintValidatorDefaultServiceTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @Before + fun setUp(): Unit { + + } + + @Test + fun testValidateBluePrint() { + + val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath) + val properties: MutableMap = hashMapOf() + + val validatorService = BluePrintValidatorDefaultService() + validatorService.validateBlueprint(bluePrintContext.serviceTemplate, properties) + log.info("Validation Message {}", properties) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtilsTest.kt new file mode 100644 index 000000000..528f2c6f2 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtilsTest.kt @@ -0,0 +1,60 @@ +/* + * 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.core.utils + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import java.io.File +import java.nio.file.Paths +import kotlin.test.assertTrue + + +class BluePrintFileUtilsTest { + + @Test + fun testNewBlueprint() = runBlocking { + val targetPath: String = Paths.get("target").toUri().toURL().path.plus("/bp-new-test") + BluePrintFileUtils.createEmptyBluePrint(targetPath) + + } + + @Test + fun testBlueprintCopy() = runBlocking { + val sourcePath: String = "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration" + + val targetPath: String = Paths.get("target").toUri().toURL().path.plus("/bp-copy-test") + + val targetDir = File(targetPath) + targetDir.deleteOnExit() + // Copy the BP file + BluePrintFileUtils.copyBluePrint(sourcePath, targetDir.absolutePath) + + assertTrue(targetDir.exists(), "faield to copy blueprint to ${targetDir.absolutePath}") + + // Delete Type Files + BluePrintFileUtils.deleteBluePrintTypes(targetDir.absolutePath) + + // Generate the Type Files + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(sourcePath) + bluePrintContext.rootPath = targetDir.absolutePath + + BluePrintFileUtils.writeBluePrintTypes(bluePrintContext) + + + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt new file mode 100644 index 000000000..80daad5d8 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt @@ -0,0 +1,41 @@ +/* + * 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.core.utils + + +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData +import kotlin.test.assertNotNull + +class BluePrintMetadataUtilsTest { + + @Test + fun testToscaMetaData(){ + + val basePath : String = "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration" + + val toscaMetaData : ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath) + assertNotNull(toscaMetaData, "Missing Tosca Definition Object") + assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version") + assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version") + assertNotNull(toscaMetaData.createdBy, "Missing Created by") + assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition") + assertNotNull(toscaMetaData.templateTags, "Missing Template Tags") + + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt new file mode 100644 index 000000000..12156d659 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt @@ -0,0 +1,78 @@ +/* + * 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.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +/** + * JacksonUtilsTest + * @author Brinda Santh + * ${DATA} + */ +class JacksonUtilsTest { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @Test + fun testJsonNodeFromClassPathFile() { + val filePath = "data/default-context.json" + JacksonUtils.jsonNodeFromClassPathFile(filePath) + } + + @Test + fun testJsonNodeFromFile() { + val filePath = "src/test/resources/data/default-context.json" + JacksonUtils.jsonNodeFromFile(filePath) + } + + @Test + fun testGetListFromJson() { + val content = "[\"good\",\"boy\" ]" + val nodeType = JacksonUtils.getListFromJson(content, String::class.java) + assertNotNull(nodeType, "Failed to get String array from content") + } + + + @Test + fun testJsonValue() { + val filePath = "data/alltype-data.json" + val rootJson = JacksonUtils.jsonNodeFromClassPathFile(filePath) + assertNotNull(rootJson, "Failed to get all type data json node") + val intValue = rootJson.get("intValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value") + val floatValue = rootJson.get("floatValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value") + val stringValue = rootJson.get("stringValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value") + val booleanValue = rootJson.get("booleanValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value") + val arrayStringValue = rootJson.get("arrayStringValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value") + val mapValue = rootJson.get("mapValue") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value") + + assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed") + + + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt new file mode 100644 index 000000000..5999dbfa5 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/TopologicalSortingUtilsTest.kt @@ -0,0 +1,36 @@ +/* + * 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.core.utils + +import org.junit.Test + +class TopologicalSortingUtilsTest { + + @Test + fun testSorting(): Unit { + val graph: TopologicalSortingUtils = TopologicalSortingUtils() + graph.add("bundle-id", "bundle-mac") + graph.add("bundle-id", "bundle-ip") + graph.add("bundle-mac", "bundle-ip") + graph.add("bundle-ip", "bundle-mac") + + println("The current graph: " + graph) + println("In-degrees: " + graph.inDegree()) + println("Out-degrees: " + graph.outDegree()) + println("A topological sort of the vertices: " + graph.topSort()) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImplTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImplTest.kt new file mode 100644 index 000000000..cfcbd9b2f --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImplTest.kt @@ -0,0 +1,100 @@ +/* + * 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.core.validation + +import io.mockk.every +import io.mockk.mockk +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.apps.controllerblueprints.core.data.Step +import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.apps.controllerblueprints.core.mock.MockBluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class BluePrintValidatorServiceImplTest { + + private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) + private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService() + private val defaultBluePrintValidatorService = BluePrintValidatorServiceImpl(mockBluePrintTypeValidatorService) + private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService) + + @Test + fun testValidateOfType() { + val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime) + assertTrue(valid, "failed in blueprint Validation") + } + + @Test + fun testValidateWorkflowFailToFoundNodeTemplate() { + val workflowName = "resource-assignment" + + val step = Step() + step.target = "TestCaseFailNoNodeTemplate" + val workflow = Workflow() + workflow.steps = mutableMapOf("test" to step) + workflowValidator.validate(bluePrintRuntime, workflowName, workflow) + + assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size) + assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : could't get node template for the name(TestCaseFailNoNodeTemplate)", bluePrintRuntime.getBluePrintError().errors[0]) + } + + @Test + fun testValidateWorkflowFailNodeTemplateNotDgGeneric() { + val workflowName = "resource-assignment" + val nodeTemplateName = "resource-assignment-process" + + val nodeTemplate = mockk() + every { nodeTemplate.type } returns "TestNodeType" + + val nodeType = mockk() + every { nodeType.derivedFrom } returns "tosca.nodes.TEST" + + val blueprintContext = mockk() + every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate + every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType + + val bluePrintRuntime = mockk("1234") + + every { bluePrintRuntime.getBluePrintError() } returns BluePrintError() + every { bluePrintRuntime.bluePrintContext() } returns blueprintContext + + val step = Step() + step.target = nodeTemplateName + val workflow = Workflow() + workflow.steps = mutableMapOf("test" to step) + workflowValidator.validate(bluePrintRuntime, workflowName, workflow) + + assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size) + assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', Expected is 'tosca.nodes.DG'", bluePrintRuntime.getBluePrintError().errors[0]) + } + + @Test + fun testValidateWorkflowSuccess() { + val workflowName = "resource-assignment" + workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName)) + } + +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/componentnode/default.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/componentnode/default.json new file mode 100644 index 000000000..a1982631b --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/componentnode/default.json @@ -0,0 +1,100 @@ +{ + "metadata": { + "template_author": "bs2796", + "vendor": "Juniper", + "os": "XXX", + "service-type": "AVPN", + "vnf-type": "VRR", + "action": "Base Configuration", + "sub-action": "Generate Configuration", + "template_name": "VRR-baseconfiguration", + "template_version": "1.0.0" + }, + "topology_template": { + "inputs": { + "service-instance-id": { + "required": true, + "type": "string" + }, + "vnf-id": { + "required": true, + "type": "string" + }, + "service": { + "required": true, + "type": "string" + }, + "region": { + "required": true, + "type": "string" + }, + "bundle-id": { + "required": true, + "type": "string" + }, + "bundle-mac": { + "required": true, + "type": "string" + } + }, + "node_templates": { + "generate-configuration": { + "type": "mock-component-generateConfig", + "interfaces": { + "org-onap-ccsdk-config-params-service-MockComponentNode": { + "operations": { + "process": { + "inputs": { + "entity-type": "vnf-type", + "template-content": "sample-template", + "entity-id": { "get_input" : "vnf-id" } + }, + "outputs": { + "mergedData": "merged Data", + "status": "status" + } + } + } + } + } + } + } + }, + "node_types": { + "mock-component-generateConfig": { + "interfaces": { + "org-onap-ccsdk-config-params-service-MockComponentNode": { + "operations": { + "process": { + "inputs": { + "entity-type": { + "required": false, + "type": "string" + }, + "template-content": { + "required": false, + "type": "string" + }, + "entity-id": { + "required": true, + "type": "string" + } + }, + "outputs": { + "generated-config": { + "required": true, + "type": "string" + }, + "status": { + "required": true, + "type": "string" + } + } + } + } + } + }, + "derived_from": "tosca.nodes.Component" + } + } +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/alltype-data.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/alltype-data.json new file mode 100644 index 000000000..055b09658 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/alltype-data.json @@ -0,0 +1,10 @@ +{ + "intValue" : 1, + "floatValue" : 1.34, + "booleanValue" : true, + "stringValue" : "sample-String", + "timeValue" : "2018-09-29", + "arrayStringValue" : ["one", "two"], + "mapValue" : {"profile_name1":"profile_name1", + "profile_name2":"profile_name2"} +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json new file mode 100644 index 000000000..3968626b8 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/data/default-context.json @@ -0,0 +1,7 @@ +{ + "request-id" : "12345", + "hostname" : "localhost", + "template_name": "baseconfiguration", + "template_version": "1.0.0", + "action-name" : "sample-action" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/dictionary/dictionary_schema.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/dictionary/dictionary_schema.json new file mode 100644 index 000000000..cac8770af --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/dictionary/dictionary_schema.json @@ -0,0 +1,261 @@ +{ + "type": "object", + "properties": { + "resource-path": { + "type": "string", + "required": true + }, + "description": { + "type": "string" + }, + "updated-by": { + "type": "string" + }, + "data-type": { + "type": "string", + "required": true + }, + "source": { + "type": "object", + "required": true, + "properties": { + "input": { + "type": "object", + "properties": { + "key": { + "type": "string" + } + } + }, + "component": { + "type": "object", + "properties": { + "name": { + "type": "string", + "required": true + }, + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "default": { + "type": "any" + }, + "aai": { + "type": "any" + }, + "primary-config-data": { + "type": "object", + "properties": { + "path": { + "type": "string", + "required": true + }, + "url-path": { + "type": "string", + "required": true + }, + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "type": { + "type": "string", + "required": true + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "base": { + "type": "string", + "required": true + } + } + }, + "network-resource-discovery": { + "type": "object", + "properties": { + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "primary-db": { + "type": "object", + "properties": { + "query": { + "type": "string", + "required": true + }, + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "type": { + "type": "string", + "required": true + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "base": { + "type": "string", + "required": true + } + } + }, + "policy": { + "type": "object", + "properties": { + "input-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "output-key-mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "candidate-dependency": { + "type": "object", + "properties": { + "input": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "component": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "aai": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "primary-config-data": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "network-resource-discovery": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "primary-db": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "policy": { + "type": "object", + "properties": { + "names": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + }, + "tags": { + "type": "string" + }, + "default": { + "type": "any" + }, + "name": { + "type": "string", + "required": true + }, + "valid-values": { + "type": "string" + }, + "resource-type": { + "type": "string", + "required": true + }, + "sample-value": { + "type": "string" + }, + "entry-schema": { + "type": "string" + } + } +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/properties/convert.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/properties/convert.json new file mode 100644 index 000000000..f7893ce53 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/properties/convert.json @@ -0,0 +1,36 @@ +{ + "type": "sdnc-component-getResourceAssignment", + "interfaces": { + "ResourceAssignmentService": { + "operations": { + "getResourceAssignment": { + "inputs": { + "assignment-mappings": [ + { + "name": "service-name", + "mapping-field": "service", + "mapping-category": "SDN", + "required": true + }, + { + "name": "region-name", + "mapping-field": "region", + "mapping-category": "SDN", + "required": true + } + ], + "pre-data": { + "get_input": "get-resource-assignment.config-params" + }, + "prifix": "get-resource-assignment" + }, + "outputs": { + "resource-assignment-status": "success", + "resource-assignment-params": "{ \"set_value\" : \"get-resource-assignment.config-params" + } + } + } + } + } +} + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/properties/default.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/properties/default.json new file mode 100644 index 000000000..9f17574e7 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/properties/default.json @@ -0,0 +1,16 @@ +{ + "default": { "get_input" : "loopback-default" }, + "domain": "ethernet", + "criteria": [ + { + "value": "attga301me1", + "type": "complex", + "nodeString": "layer3-service-list[].service-data.l3sdn-vnf-fields.vnf-name" + }, + { + "value": { "get_input" : "host-ip-address" }, + "type": "simple", + "nodeString": "layer3-service-list[].service-data.l3sdn-vnf-fields.vnf-name" + } + ] +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts/SampleBlueprintFunctionNode.kts b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts/SampleBlueprintFunctionNode.kts new file mode 100644 index 000000000..44cc957d2 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts/SampleBlueprintFunctionNode.kts @@ -0,0 +1,44 @@ +/* + * 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. + */ + +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode + +open class SampleBlueprintFunctionNode : BlueprintFunctionNode{ + + override fun getName(): String { + return "Kotlin-Script-Function-Node" + } + + override fun prepareRequest(executionRequest: String): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun process(executionRequest: String) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun recover(runtimeException: RuntimeException, executionRequest: String) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun prepareResponse(): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun apply(t: String): String { + return "$t-status" + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data.json new file mode 100755 index 000000000..2acc6fcdd --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data.json @@ -0,0 +1,36 @@ +{ + "node0_hostname": "sdnc-host", + "node0_backup_router_address": "2001:1890:1253::192:168:100:1", + "servers": [ + "Server1", + "Server2", + "Server3" + ], + "tacplus-servers": [ + { + "tacplus-server-name": "tacplus-server-name1", + "tacplus-server-source-address": "enc-dsdsasa1" + }, + { + "tacplus-server-name": "tacplus-server-name2", + "tacplus-server-source-address": "enc-dsdsasa2" + } + ], + "classes": [ + { + "name": "superuser-class", + "idle-timeout": 5, + "permissions": "all" + }, + { + "name": "tacacs-adv-class", + "idle-timeout": 5 + }, + { + "name": "tacacs-base-class", + "idle-timeout": 5 + } + ], + "system-password": "teamops-system-password", + "root-password": "teamops-root-password" +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-template.vtl b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-template.vtl new file mode 100755 index 000000000..f7b1269b3 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-template.vtl @@ -0,0 +1,61 @@ + + 15.1X49-D50.3 + + node0 + + #foreach($server in ${servers}) + $StringUtils.upperCase("$server") + #end + + + ${node0_hostname} + +
${node0_backup_router_address}
+ $node0_backup_router_address +
+ #foreach($tacplus-server in ${tacplus-servers}) + + $tacplus-server.tacplus-server-name + $tacplus-server.tacplus-server-source-address + + #end + + ONAP information assets + #foreach($class in ${classes}) + + $class.name + $class.idle-timeout + #if ($class.permissions) + $class.permissions + #end + + #end + + readonly + Read Only Account Access + 1001 + tacacs-base-class + + + readwrite + Read - Write Account Access + 1002 + tacacs-adv-class + + ${system-password} + + + + readwrite + Emergency Access Only + 1000 + superuser-class + + ${root-password} + + + +
+
+
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/pom.xml b/ms/controllerblueprints/modules/blueprint-validation/pom.xml index d175eecf2..4ae2870e2 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/pom.xml +++ b/ms/controllerblueprints/modules/blueprint-validation/pom.xml @@ -37,7 +37,7 @@ org.onap.ccsdk.apps.controllerblueprints - core + blueprint-core org.onap.ccsdk.apps.controllerblueprints diff --git a/ms/controllerblueprints/modules/db-resources/pom.xml b/ms/controllerblueprints/modules/db-resources/pom.xml index c09d96c10..b2f4370be 100644 --- a/ms/controllerblueprints/modules/db-resources/pom.xml +++ b/ms/controllerblueprints/modules/db-resources/pom.xml @@ -32,7 +32,7 @@ org.onap.ccsdk.apps.controllerblueprints - core + blueprint-core org.springframework.boot diff --git a/ms/controllerblueprints/modules/pom.xml b/ms/controllerblueprints/modules/pom.xml index 834db24eb..1ef81ea4c 100644 --- a/ms/controllerblueprints/modules/pom.xml +++ b/ms/controllerblueprints/modules/pom.xml @@ -1,6 +1,7 @@ + + 4.0.0 + + org.onap.ccsdk.apps.controllerblueprints + modules + 0.4.1-SNAPSHOT + + resource-dict + Controller Blueprints Resource Dictionary + + + + org.onap.ccsdk.apps.controllerblueprints + blueprint-core + + + org.jetbrains.kotlin + kotlin-test-junit + test + + + + + diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt new file mode 100644 index 000000000..d141ed0cb --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt @@ -0,0 +1,100 @@ +/* + * Copyright © 2018 IBM. + * Modifications 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.resource.dict + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.annotation.JsonProperty +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import java.io.Serializable +import java.util.* + +open class ResourceDefinition { + + @JsonProperty(value = "name", required = true) + lateinit var name: String + + @JsonProperty(value = "property", required = true) + lateinit var property: PropertyDefinition + + var tags: String? = null + + @JsonProperty(value = "updated-by") + lateinit var updatedBy: String + + @JsonProperty(value = "sources", required = true) + lateinit var sources: MutableMap +} + +open class ResourceAssignment { + + @JsonProperty(value = "name", required = true) + lateinit var name: String + + @JsonProperty(value = "property") + var property: PropertyDefinition? = null + + @JsonProperty("input-param") + var inputParameter: Boolean = false + + @JsonProperty("dictionary-name") + var dictionaryName: String? = null + + @JsonProperty("dictionary-source") + var dictionarySource: String? = null + + @JsonProperty("dependencies") + var dependencies: MutableList? = null + + @JsonProperty("version") + var version: Int = 0 + + @JsonProperty("status") + var status: String? = null + + @JsonProperty("message") + var message: String? = null + + @JsonProperty("updated-date") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + var updatedDate: Date? = null + + @JsonProperty("updated-by") + var updatedBy: String? = null + + override fun toString(): String { + return StringBuilder() + .append("[") + .append("name=", name) + .append(", dictionaryName=", dictionaryName) + .append(", dictionarySource=", dictionarySource) + .append("]") + .toString() + } +} + +/** + * Interface for Source Definitions (ex Input Source, + * Default Source, Database Source, Rest Sources, etc) + */ +interface ResourceSource : Serializable + + +open class ResourceSourceMapping { + lateinit var resourceSourceMappings: MutableMap +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt new file mode 100644 index 000000000..aa06c9da0 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -0,0 +1,38 @@ +/* + * 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.resource.dict + +/** + * ResourceDictionaryConstants + * + * @author Brinda Santh + */ +object ResourceDictionaryConstants { + const val SOURCE_INPUT = "input" + const val SOURCE_DEFAULT = "default" + const val SOURCE_PRIMARY_CONFIG_DATA = "primary-config-data" + const val SOURCE_PRIMARY_DB = "primary-db" + + const val MODEL_DIR_RESOURCE_DEFINITION: String = "resource_dictionary" + + const val PROPERTY_TYPE = "type" + const val PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping" + const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping" + const val PROPERTY_KEY_DEPENDENCIES = "key-dependencies" + + const val PATH_RESOURCE_DEFINITION_TYPE = "resource_definition_types" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt new file mode 100644 index 000000000..876aca9f7 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt @@ -0,0 +1,47 @@ +/* + * 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.resource.dict.factory + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping + +/** + * ResourceSourceMappingFactory. + * + * @author Brinda Santh + */ +object ResourceSourceMappingFactory { + + private val resourceSourceMappings: MutableMap = hashMapOf() + + fun registerSourceMapping(sourceInstance: String, nodeTypeName: String) { + resourceSourceMappings[sourceInstance] = nodeTypeName + } + + fun getRegisterSourceMapping(sourceInstance: String): String { + return resourceSourceMappings[sourceInstance] + ?: throw BluePrintException(format("failed to get source({}) mapping", sourceInstance)) + } + + fun getRegisterSourceMapping(): ResourceSourceMapping { + val resourceSourceMapping = ResourceSourceMapping() + resourceSourceMapping.resourceSourceMappings = resourceSourceMappings + return resourceSourceMapping + } +} + diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt new file mode 100644 index 000000000..d71fbbf80 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -0,0 +1,163 @@ +/* + * 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.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang3.StringUtils +import org.apache.commons.lang3.text.StrBuilder +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory +import java.io.Serializable + +/** + * ResourceAssignmentValidationService. + * + * @author Brinda Santh + */ +interface ResourceAssignmentValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceAssignments: List): Boolean +} + +/** + * ResourceAssignmentValidationServiceImpl. + * + * @author Brinda Santh + */ +open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidationService { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceImpl::class.java) + + open var resourceAssignmentMap: Map = hashMapOf() + open val validationMessage = StrBuilder() + + override fun validate(resourceAssignments: List): Boolean { + try { + validateSources(resourceAssignments) + validateTemplateNDictionaryKeys(resourceAssignments) + validateCyclicDependency(resourceAssignments) + if (StringUtils.isNotBlank(validationMessage)) { + throw BluePrintException("Resource Assignment Validation Failure") + } + } catch (e: Exception) { + throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString(), e) + } + return true + } + + open fun validateSources(resourceAssignments: List) { + log.info("validating resource assignment sources") + // Check the Resource Assignment Source(Dynamic Instance) is valid. + resourceAssignments.forEach { resourceAssignment -> + try { + ResourceSourceMappingFactory.getRegisterSourceMapping(resourceAssignment.dictionarySource!!) + } catch (e: BluePrintException) { + validationMessage.appendln(e.message + format(" for resource assignment({})", resourceAssignment.name)) + } + } + } + + open fun validateTemplateNDictionaryKeys(resourceAssignments: List) { + + resourceAssignmentMap = resourceAssignments.map { it.name to it }.toMap() + + // Check the Resource Assignment has Duplicate Key Names + val duplicateKeyNames = resourceAssignments.groupBy { it.name } + .filter { it.value.size > 1 } + .map { it.key } + + if (duplicateKeyNames.isNotEmpty()) { + validationMessage.appendln(String.format("Duplicate Assignment Template Keys (%s) is Present", duplicateKeyNames)) + } + + // Check the Resource Assignment has Duplicate Dictionary Names + val duplicateDictionaryKeyNames = resourceAssignments.groupBy { it.dictionaryName } + .filter { it.value.size > 1 } + .map { it.key } + if (duplicateDictionaryKeyNames.isNotEmpty()) { + validationMessage.appendln(String.format("Duplicate Assignment Dictionary Keys (%s) is Present", duplicateDictionaryKeyNames)) + } + + // Collect all the dependencies as a single list + val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten() + + // Check all the dependencies keys have Resource Assignment mappings. + val notPresentDictionaries = dependenciesNames.filter { !resourceAssignmentMap.containsKey(it) }.distinct() + if (notPresentDictionaries.isNotEmpty()) { + validationMessage.appendln(String.format("No assignments for Dictionary Keys (%s)", notPresentDictionaries)) + } + + if (StringUtils.isNotBlank(validationMessage)) { + throw BluePrintException("Resource Assignment Validation Failure") + } + } + + open fun validateCyclicDependency(resourceAssignments: List) { + val startResourceAssignment = ResourceAssignment() + startResourceAssignment.name = "*" + + val topologySorting = TopologicalSortingUtils() + + resourceAssignmentMap.map { it.value }.map { resourceAssignment -> + if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { + resourceAssignment.dependencies!!.map { + log.info("Topological Graph link from {} to {}", it, resourceAssignment.name) + topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment) + } + } else { + topologySorting.add(startResourceAssignment, resourceAssignment) + } + } + + if (!topologySorting.isDag) { + val graph = getTopologicalGraph(topologySorting) + validationMessage.appendln("Cyclic Dependency :$graph") + } + } + + open fun getTopologicalGraph(topologySorting: TopologicalSortingUtils): String { + val s = StringBuilder() + val neighbors = topologySorting.getNeighbors() + + neighbors.forEach { v, vs -> + if (v.name == "*") { + s.append("\n * -> [") + for (resourceAssignment in vs) { + s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name + + "),") + } + s.append("]") + } else { + s.append("\n (" + v.dictionaryName + ":" + v.name + ") -> [") + for (resourceAssignment in vs) { + s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name + + "),") + } + s.append("]") + } + } + return s.toString() + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt new file mode 100644 index 000000000..9541a7b89 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt @@ -0,0 +1,113 @@ +/* + * Copyright © 2018 IBM. + * Modifications 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.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.google.common.base.Preconditions +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import java.io.Serializable + +/** + * ResourceDefinitionValidationService. + * + * @author Brinda Santh + */ +interface ResourceDefinitionValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceDefinition: ResourceDefinition) + +} + +/** + * ResourceDefinitionValidationService. + * + * @author Brinda Santh + */ +open class ResourceDefinitionValidationServiceImpl(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidationService::class.java) + + override fun validate(resourceDefinition: ResourceDefinition) { + Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") + log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name) + + resourceDefinition.sources.forEach { name, nodeTemplate -> + val sourceType = nodeTemplate.type + + val sourceNodeType = bluePrintRepoService.getNodeType(sourceType) + + // Validate Property Name, expression, values and Data Type + validateNodeTemplateProperties(nodeTemplate, sourceNodeType) + } + } + + + open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) { + nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } + } + + + open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, + properties: MutableMap) { + properties.forEach { propertyName, propertyAssignment -> + val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] + ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) + // Check and Validate if Expression Node + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyDefinition, propertyName, propertyAssignment) + } else { + throw BluePrintException(format("property({}) of expression ({}) is not supported", + propertyName, propertyAssignment)) + } + } + } + + open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) { + val propertyType = propertyDefinition.type + val isValid: Boolean + + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { + isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) + + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + + isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) + } else { + bluePrintRepoService.getDataType(propertyType) + isValid = true + } + + check(isValid) { + throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})", + propertyName, propertyType, propertyAssignment)) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt new file mode 100644 index 000000000..cd92f42c0 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt @@ -0,0 +1,109 @@ +/* + * 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.resource.dict.utils + +import com.att.eelf.configuration.EELFLogger +import org.apache.commons.collections.CollectionUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import com.att.eelf.configuration.EELFManager +import java.util.ArrayList +/** + * BulkResourceSequencingUtils. + * + * @author Brinda Santh + */ +object BulkResourceSequencingUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(BulkResourceSequencingUtils::class.java) + + @JvmStatic + fun process(resourceAssignments: MutableList): List> { + val resourceAssignmentMap: MutableMap = hashMapOf() + val sequenceBatchResourceAssignment = ArrayList>() + log.info("Assignments ({})", resourceAssignments) + // Prepare Map + resourceAssignments.forEach { resourceAssignment -> + log.trace("Processing Key ({})", resourceAssignment.name) + resourceAssignmentMap.put(resourceAssignment.name, resourceAssignment) + } + + val startResourceAssignment = ResourceAssignment() + startResourceAssignment.name = "*" + + // Preepare Sorting Map + val topologySorting = TopologicalSortingUtils() + resourceAssignmentMap.forEach { _, resourceAssignment -> + if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { + for (dependency in resourceAssignment.dependencies!!) { + topologySorting.add(resourceAssignmentMap[dependency]!!, resourceAssignment) + } + } else { + topologySorting.add(startResourceAssignment, resourceAssignment) + } + } + + val sequencedResourceAssignments: MutableList = topologySorting.topSort()!! as MutableList + log.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments) + + var batchResourceAssignment: MutableList? = null + var batchAssignmentName: MutableList? = null + + // Prepare Sorting + sequencedResourceAssignments.forEachIndexed { index, resourceAssignment -> + + var previousResourceAssignment: ResourceAssignment? = null + + if (index > 0) { + previousResourceAssignment = sequencedResourceAssignments[index - 1] + } + + var dependencyPresence = false + if (batchAssignmentName != null && resourceAssignment.dependencies != null) { + dependencyPresence = CollectionUtils.containsAny(batchAssignmentName, resourceAssignment.dependencies) + } + + log.trace("({}) -> Checking ({}), with ({}), result ({})", resourceAssignment.name, + batchAssignmentName, resourceAssignment.dependencies, dependencyPresence) + + if (previousResourceAssignment != null && resourceAssignment.dictionarySource != null + && resourceAssignment.dictionarySource!!.equals(previousResourceAssignment.dictionarySource, true) + && !dependencyPresence) { + batchResourceAssignment!!.add(resourceAssignment) + batchAssignmentName!!.add(resourceAssignment.name) + } else { + if (batchResourceAssignment != null) { + sequenceBatchResourceAssignment.add(batchResourceAssignment!!) + log.trace("Created old Set ({})", batchAssignmentName) + } + batchResourceAssignment = arrayListOf() + batchResourceAssignment!!.add(resourceAssignment) + + batchAssignmentName = arrayListOf() + batchAssignmentName!!.add(resourceAssignment.name) + } + + if (index == sequencedResourceAssignments.size - 1) { + log.trace("Created old Set ({})", batchAssignmentName) + sequenceBatchResourceAssignment.add(batchResourceAssignment!!) + } + } + log.info("Batched Sequence : ({})", sequenceBatchResourceAssignment) + + return sequenceBatchResourceAssignment + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt new file mode 100644 index 000000000..1aeda0ba1 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -0,0 +1,94 @@ +/* + * 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.resource.dict.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.apache.commons.collections.MapUtils +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils +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.ResourceDefinition +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import java.io.File + + +object ResourceDictionaryUtils { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDictionaryUtils::class.java) + + @JvmStatic + fun populateSourceMapping(resourceAssignment: ResourceAssignment, + resourceDefinition: ResourceDefinition) { + + if (StringUtils.isBlank(resourceAssignment.dictionarySource)) { + + if (MapUtils.isNotEmpty(resourceDefinition.sources)) { + val source = findFirstSource(resourceDefinition.sources) + + // Populate and Assign First Source + if (StringUtils.isNotBlank(source)) { + // Set Dictionary Source + resourceAssignment.dictionarySource = source + } else { + resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT + } + log.info("auto map resourceAssignment : {}", resourceAssignment) + } else { + resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT + } + } + } + + @JvmStatic + fun findFirstSource(sources: Map): String? { + var source: String? = null + if (MapUtils.isNotEmpty(sources)) { + source = sources.keys.stream().findFirst().get() + } + return source + } + + @JvmStatic + fun assignInputs(data: JsonNode, context: MutableMap) { + log.trace("assignInputs from input JSON ({})", data.toString()) + data.fields().forEach { field -> + val valueNode: JsonNode = data.at("/".plus(field.key)) ?: NullNode.getInstance() + + val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(field.key) + log.trace("setting path ({}), values ({})", path, valueNode) + context[path] = valueNode + } + } + + fun getResourceAssignmentFromFile(filePath: String): List { + return JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java) + ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") + } + + fun writeResourceDefinitionTypes(basePath: String, resourceDefinitionMap: Map) { + val typePath = basePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR) + .plus(File.separator).plus("${ResourceDictionaryConstants.PATH_RESOURCE_DEFINITION_TYPE}.json") + val resourceDefinitionContent = JacksonUtils.getJson(resourceDefinitionMap.toSortedMap(), true) + BluePrintFileUtils.writeDefinitionFile(typePath, resourceDefinitionContent) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java new file mode 100644 index 000000000..d059d1ba5 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java @@ -0,0 +1,60 @@ +/* + * 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.resource.dict; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceDefinitionTest { + private EELFLogger log = EELFManager.getInstance().getLogger(ResourceDefinitionTest.class); + private String basePath = "load/resource_dictionary"; + + @Test + public void testDictionaryDefinitionInputSource(){ + + String fileName = basePath + "/input-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDefaultSource(){ + + String fileName = basePath + "/default-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDBSource(){ + + String fileName = basePath + "/primary-db-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for primary-db type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionMDSALSource(){ + String fileName = basePath + "/mdsal-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", resourceDefinition); + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java new file mode 100644 index 000000000..3950ae367 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java @@ -0,0 +1,42 @@ +/* + * 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.resource.dict.factory; + +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping; +import org.springframework.util.Assert; + +public class ResourceSourceMappingFactoryTest { + + @Test + public void testRegisterResourceMapping() { + + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-db", "source-primary-db"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-config-data", "source-rest"); + + String nodeTypeName = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping("primary-db"); + Assert.notNull(nodeTypeName, "Failed to get primary-db mapping"); + + ResourceSourceMapping resourceSourceMapping = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); + Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping"); + Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings"); + + } + +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt new file mode 100644 index 000000000..8905dab60 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt @@ -0,0 +1,66 @@ +/* + * 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.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import org.junit.Assert +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import com.att.eelf.configuration.EELFManager +import org.junit.Before +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils + +/** + * ResourceAssignmentValidationServiceTest. + * + * @author Brinda Santh + */ +class ResourceAssignmentValidationServiceTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java) + @Before + fun setUp() { + // Setup dummy Source Instance Mapping + ResourceDictionaryTestUtils.setUpResourceSourceMapping() + } + + @Test + fun testValidateSuccess() { + log.info("**************** testValidateSuccess *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() + val result = resourceAssignmentValidator.validate(assignments!!) + Assert.assertTrue("Failed to Validate", result) + } + + @Test(expected = BluePrintException::class) + fun testValidateDuplicate() { + log.info(" **************** testValidateDuplicate *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/duplicate.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() + resourceAssignmentValidator.validate(assignments!!) + } + + @Test(expected = BluePrintException::class) + fun testValidateCyclic() { + log.info(" **************** testValidateCyclic *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/cyclic.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() + resourceAssignmentValidator.validate(assignments!!) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java new file mode 100644 index 000000000..7f040b2e2 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java @@ -0,0 +1,56 @@ +/* + * 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.resource.dict.service; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; + +public class ResourceDefinitionValidationServiceTest { + private String basePath = "load/model_type"; + private String dictionaryPath = "load/resource_dictionary"; + private BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); + + @Test + public void testValidateSource() throws Exception { + + String inputFileName = dictionaryPath + "/input-source.json"; + testValidate(inputFileName); + + String dbFileName = dictionaryPath + "/primary-db-source.json"; + testValidate(dbFileName); + + String defaultFileName = dictionaryPath + "/default-source.json"; + testValidate(defaultFileName); + + String restFileName = dictionaryPath + "/mdsal-source.json"; + testValidate(restFileName); + } + + private void testValidate(String fileName) throws Exception { + + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); + + ResourceDefinitionValidationService resourceDictionaryValidationService = + new ResourceDefinitionValidationServiceImpl(bluePrintRepoFileService); + resourceDictionaryValidationService.validate(resourceDefinition); + Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java new file mode 100644 index 000000000..c1b9f5007 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java @@ -0,0 +1,37 @@ +/* + * 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.resource.dict.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import java.util.List; +/** + * BulkResourceSequencingUtils. + * + * @author Brinda Santh + */ +public class BulkResourceSequencingUtilsTest { + + @Test + public void testProcess(){ + List assignments = JacksonUtils.Companion.getListFromClassPathFile("validation/success.json", ResourceAssignment.class); + Assert.assertNotNull("failed to get ResourceAssignment from validation/success.json ", assignments); + BulkResourceSequencingUtils.process(assignments); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java new file mode 100644 index 000000000..e4ddac131 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -0,0 +1,99 @@ +/* + * 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.resource.dict.utils; + + +import com.fasterxml.jackson.databind.JsonNode; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; +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.ResourceDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.HashMap; +import java.util.Map; +/** + * ResourceDictionaryUtilsTest. + * + * @author Brinda Santh + */ +public class ResourceDictionaryUtilsTest { + private static final EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); + + @Test + public void testPopulateSourceMapping() { + + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("sample-assignment"); + ResourceDefinition resourceDefinition = new ResourceDefinition(); + Map sources = new HashMap<>(); + resourceDefinition.setSources(sources); + // To Check Empty Source + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource()); + + // To Check First Source + resourceAssignment.setDictionarySource(null); + sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate()); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource()); + + // To Check Assigned Source + resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PRIMARY_DB); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.getDictionarySource()); + + } + + @Test + public void testFindFirstSource() { + //To check if Empty Source + Map sources = new HashMap<>(); + String firstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertNull("Source populated, which is not expected.", firstSource); + + // TO check the first Source + sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate()); + String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource); + + // TO check the multiple Source + sources.put(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, new NodeTemplate()); + String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource); + + } + + @Test + public void testAssignInputs() { + JsonNode data = JacksonUtils.Companion.jsonNodeFromClassPathFile("data/resource-assignment-input.json"); + Map context = new HashMap<>(); + ResourceDictionaryUtils.assignInputs(data, context); + String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue"); + log.info("populated context {}", context); + Assert.assertTrue(String.format("failed to get variable : %s",path),context.containsKey(path)); + + } + + +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt new file mode 100644 index 000000000..ed2bfc0a1 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt @@ -0,0 +1,30 @@ +/* + * 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.resource.dict.utils + +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory + +object ResourceDictionaryTestUtils { + + @JvmStatic + fun setUpResourceSourceMapping() { + ResourceSourceMappingFactory.registerSourceMapping("primary-db", "source-primary-db") + ResourceSourceMappingFactory.registerSourceMapping("input", "source-input") + ResourceSourceMappingFactory.registerSourceMapping("default", "source-default") + ResourceSourceMappingFactory.registerSourceMapping("primary-config-data", "source-rest") + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json new file mode 100644 index 000000000..d79c90682 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json @@ -0,0 +1,10 @@ +{ + "intValue" : 1, + "floatValue" : 1.34, + "booleanValue" : true, + "stringValue" : "sample-String", + "timeValue" : "2018-09-29", + "arrayStringValue" : ["one", "two"], + "mapValue" : {"profile_name1":"profile_name1", + "profile_name2":"profile_name2"} +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json new file mode 100644 index 000000000..3bfa4167d --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json @@ -0,0 +1,111 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "managed-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip", + "dictionary-source": "primary-config-data", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "primary-config-data", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "primary-db", + "dependencies": [ + "bundle-mac", + "managed-ip1" + ] + } +] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json new file mode 100644 index 000000000..473920d6d --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json @@ -0,0 +1,110 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "primary-config-data", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "primary-config-data", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "primary-db", + "dependencies": [ + "bundle-mac" + ] + } +] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json new file mode 100644 index 000000000..f8fe623fd --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json @@ -0,0 +1,110 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "primary-config-data", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "managed-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip", + "dictionary-source": "primary-config-data", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "primary-config-data", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "primary-db", + "dependencies": [ + "bundle-mac" + ] + } +] diff --git a/ms/controllerblueprints/parent/pom.xml b/ms/controllerblueprints/parent/pom.xml index 8cbc98e03..f29e50147 100644 --- a/ms/controllerblueprints/parent/pom.xml +++ b/ms/controllerblueprints/parent/pom.xml @@ -16,7 +16,8 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - + 4.0.0 org.onap.ccsdk.apps @@ -41,6 +42,7 @@ 1.4.197 1.2.2 1.7.4 + 1.9 @@ -91,12 +93,17 @@ commons-io 2.6 + + org.apache.commons + commons-compress + 1.15 + org.apache.velocity velocity 1.7 - + com.google.guava guava ${guava.version} @@ -142,8 +149,8 @@ ${kotlin.version} - org.jetbrains.kotlin - kotlinx-couroutines-core + org.jetbrains.kotlinx + kotlinx-coroutines-core ${kotlin.couroutines.version} @@ -205,7 +212,7 @@ org.onap.ccsdk.apps.controllerblueprints - core + blueprint-core ${project.version} @@ -240,6 +247,12 @@ + + io.mockk + mockk + ${mockk.version} + test + org.powermock powermock-api-mockito2 @@ -252,6 +265,12 @@ ${kotlin.version} test + + org.jetbrains.kotlinx + kotlinx-coroutines-test + ${kotlin.couroutines.version} + test + io.grpc grpc-testing @@ -273,7 +292,7 @@ org.apache.commons commons-lang3 - + commons-collections commons-collections @@ -282,6 +301,10 @@ commons-io commons-io + + org.apache.commons + commons-compress + com.jayway.jsonpath json-path @@ -302,14 +325,43 @@ org.jetbrains.kotlin kotlin-stdlib + + org.jetbrains.kotlin + kotlin-script-util + org.jetbrains.kotlin kotlin-stdlib-jdk8 + + org.jetbrains.kotlinx + kotlinx-coroutines-core + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + com.fasterxml.jackson.module jackson-module-kotlin + + + io.grpc + grpc-netty + + + io.grpc + grpc-protobuf + + + io.grpc + grpc-stub + + + com.google.protobuf + protobuf-java-util + -- cgit 1.2.3-korg From a5130dcf4e70f394c1432baefffc198882f04dc1 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Wed, 27 Feb 2019 20:16:47 -0500 Subject: Add blueprint runtime validator Change-Id: I9e2aa1aec392fc4191d547115fa90e8811f0f9e9 Issue-ID: CCSDK-1110 Signed-off-by: Muthuramalingam, Brinda Santh --- .../controllerblueprints/core/BluePrintTypes.kt | 20 +-- .../core/service/BluePrintRuntimeService.kt | 3 +- .../core/utils/JacksonUtils.kt | 16 ++- .../BluePrintArtifactDefinitionValidatorImpl.kt | 2 +- .../BluePrintDesignTimeValidatorService.kt | 33 ++++- .../validation/BluePrintValidationConfiguration.kt | 24 ++++ .../extension/ArtifactMappingResourceValidator.kt | 2 +- .../extension/ResourceDefinitionValidation.kt | 44 ++++++ .../BluePrintDesignTimeValidatorServiceTest.kt | 7 +- .../service/ResourceAssignmentValidationService.kt | 16 +-- .../service/ResourceDefinitionValidationService.kt | 113 ---------------- .../ResourceDefinitionValidationServiceTest.java | 56 -------- .../validator/ResourceDictionaryValidator.java | 60 --------- .../validator/ServiceTemplateValidator.java | 147 --------------------- .../service/BluePrintRepoServiceImpl.kt | 12 +- .../service/handler/ResourceDictionaryHandler.kt | 22 ++- 16 files changed, 147 insertions(+), 430 deletions(-) create mode 100644 ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt create mode 100644 ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt index b2f1b727c..cf400fa7a 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt @@ -98,16 +98,9 @@ object BluePrintTypes { @JvmStatic fun validPropertyTypes(): List { val validTypes: MutableList = arrayListOf() - validTypes.add(BluePrintConstants.DATA_TYPE_STRING) - validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) - validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) - validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE) - validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) - validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) - validTypes.add(BluePrintConstants.DATA_TYPE_NULL) - validTypes.add(BluePrintConstants.DATA_TYPE_LIST) - validTypes.add(BluePrintConstants.DATA_TYPE_MAP) - validTypes.add(BluePrintConstants.DATA_TYPE_JSON) + validTypes.addAll(validPrimitiveTypes()) + validTypes.addAll(validComplexTypes()) + validTypes.addAll(validCollectionTypes()) return validTypes } @@ -124,6 +117,13 @@ object BluePrintTypes { return validTypes } + @JvmStatic + fun validComplexTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_JSON) + return validTypes + } + @JvmStatic fun validCollectionTypes(): List { val validTypes: MutableList = arrayListOf() diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index 80ad3f2a8..c58280732 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -29,7 +29,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import java.io.File interface BluePrintRuntimeService { @@ -234,7 +233,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl } else { // Assign default value to the Operation nodeTypeProperty.defaultValue?.let { - resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!) + resolvedValue = nodeTypeProperty.defaultValue!! } } // Set for Return of method diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 1bc250053..932f0edce 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -68,12 +68,14 @@ class JacksonUtils { } } - fun getContent(fileName: String): String = runBlocking { + fun getContent(fileName: String): String = getContent(File(fileName)) + + fun getContent(file: File): String = runBlocking { async { try { - File(fileName).readText(Charsets.UTF_8) + file.readText(Charsets.UTF_8) } catch (e: Exception) { - throw BluePrintException("couldn't get file ($fileName) content : ${e.message}") + throw BluePrintException("couldn't get file (${file.absolutePath}) content : ${e.message}") } }.await() } @@ -167,17 +169,19 @@ class JacksonUtils { return getListFromJson(content, valueType) } - fun getMapFromJson(content: String, valueType: Class): MutableMap? { + fun getMapFromJson(content: String, valueType: Class): MutableMap { val objectMapper = jacksonObjectMapper() val mapType = objectMapper.typeFactory.constructMapType(Map::class.java, String::class.java, valueType) return objectMapper.readValue(content, mapType) } - fun getMapFromFile(fileName: String, valueType: Class): MutableMap? { - val content: String = getContent(fileName) + fun getMapFromFile(file: File, valueType: Class): MutableMap { + val content: String = getContent(file) return getMapFromJson(content, valueType) } + fun getMapFromFile(fileName: String, valueType: Class): MutableMap = getMapFromFile(File(fileName), valueType) + fun getInstanceFromMap(properties: MutableMap, classType: Class): T { return readValue(getJson(properties), classType) ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)") diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt index 4ea5ab5bc..a43bf4571 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt @@ -49,7 +49,7 @@ open class BluePrintArtifactDefinitionValidatorImpl( paths.add(name) val type: String = artifactDefinition.type - log.info("Validation ArtifactDefinition of type {$type}") + log.trace("Validation ArtifactDefinition of type {$type}") // Check Artifact Type checkValidArtifactType(name, type) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt index 84073ff2e..c89857742 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt @@ -19,17 +19,25 @@ package org.onap.ccsdk.apps.controllerblueprints.validation import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator import org.springframework.stereotype.Service +import java.io.File import java.util.* @Service -open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintValidatorService { +open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService, + private val resourceDefinitionValidator: ResourceDefinitionValidator) + : BluePrintValidatorService { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintDesignTimeValidatorService::class.toString()) @@ -43,9 +51,32 @@ open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidato bluePrintTypeValidatorService.validateServiceTemplate(bluePrintRuntimeService, "service_template", bluePrintRuntimeService.bluePrintContext().serviceTemplate) + + // Validate Resource Definitions + validateResourceDefinitions(bluePrintRuntimeService) + if (bluePrintRuntimeService.getBluePrintError().errors.size > 0) { throw BluePrintException("failed in blueprint validation : ${bluePrintRuntimeService.getBluePrintError().errors.joinToString("\n")}") } return true } + + private fun validateResourceDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>) { + // Validate Resource Dictionary + val blueprintBasePath = bluePrintRuntimeService.bluePrintContext().rootPath + + val resourceDefinitionsPath = blueprintBasePath.plus(File.separator) + .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator) + .plus("${ResourceDictionaryConstants.PATH_RESOURCE_DEFINITION_TYPE}.json") + + val resourceDefinitionFile = File(resourceDefinitionsPath) + + if (resourceDefinitionFile.exists()) { + val resourceDefinitionMap = JacksonUtils.getMapFromFile(resourceDefinitionFile, ResourceDefinition::class.java) + + resourceDefinitionMap?.forEach { resourceDefinitionName, resourceDefinition -> + resourceDefinitionValidator.validate(bluePrintRuntimeService, resourceDefinitionName, resourceDefinition) + } + } + } } diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt new file mode 100644 index 000000000..bad147915 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt @@ -0,0 +1,24 @@ +/* + * Copyright © 2019 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.validation + +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +open class BluePrintValidationConfiguration \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt index 6fe4fa36e..002dd9fbd 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt @@ -40,7 +40,7 @@ open class ArtifactMappingResourceValidator(private val bluePrintTypeValidatorSe val bluePrintContext = bluePrintRuntimeService.bluePrintContext() val file: String = artifactDefinition.file val completePath = bluePrintContext.rootPath.plus(File.separator).plus(file) - log.info("Validation artifact-mapping-resource($completePath)") + log.trace("Validation artifact-mapping-resource($completePath)") val resourceAssignment = JacksonUtils.getListFromFile(completePath, ResourceAssignment::class.java) val resourceAssignmentValidationService = ResourceAssignmentValidationServiceImpl() resourceAssignmentValidationService.validate(resourceAssignment) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt new file mode 100644 index 000000000..6975ec619 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt @@ -0,0 +1,44 @@ +/* + * Copyright © 2019 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.validation.extension + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidator +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +interface ResourceDefinitionValidator : BluePrintValidator + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class ResourceDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : ResourceDefinitionValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidatorImpl::class.java) + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, + resourceDefinition: ResourceDefinition) { + log.trace("validating resource definition($name)") + resourceDefinition.sources.forEach { name, nodeTemplate -> + bluePrintTypeValidatorService.validateNodeTemplate(bluePrintRuntimeService, name, nodeTemplate) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt index 43c3e0e3e..3fc918e60 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -35,11 +37,14 @@ class BluePrintDesignTimeValidatorServiceTest { private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService() - private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService) + private val resourceDefinitionValidator = mockk() + private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService, resourceDefinitionValidator) private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService) @Test fun testValidateOfType() { + every { resourceDefinitionValidator.validate(bluePrintRuntime, any(), any()) } returns Unit + val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime) assertTrue(valid, "failed in blueprint Validation") } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt index d71fbbf80..b35bca744 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -23,10 +23,8 @@ import org.apache.commons.collections.CollectionUtils import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.format import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory import java.io.Serializable /** @@ -53,7 +51,6 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio override fun validate(resourceAssignments: List): Boolean { try { - validateSources(resourceAssignments) validateTemplateNDictionaryKeys(resourceAssignments) validateCyclicDependency(resourceAssignments) if (StringUtils.isNotBlank(validationMessage)) { @@ -65,17 +62,6 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio return true } - open fun validateSources(resourceAssignments: List) { - log.info("validating resource assignment sources") - // Check the Resource Assignment Source(Dynamic Instance) is valid. - resourceAssignments.forEach { resourceAssignment -> - try { - ResourceSourceMappingFactory.getRegisterSourceMapping(resourceAssignment.dictionarySource!!) - } catch (e: BluePrintException) { - validationMessage.appendln(e.message + format(" for resource assignment({})", resourceAssignment.name)) - } - } - } open fun validateTemplateNDictionaryKeys(resourceAssignments: List) { @@ -121,7 +107,7 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio resourceAssignmentMap.map { it.value }.map { resourceAssignment -> if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { resourceAssignment.dependencies!!.map { - log.info("Topological Graph link from {} to {}", it, resourceAssignment.name) + log.trace("Topological Graph link from {} to {}", it, resourceAssignment.name) topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment) } } else { diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt deleted file mode 100644 index 9541a7b89..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications 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.resource.dict.service - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import com.fasterxml.jackson.databind.JsonNode -import com.google.common.base.Preconditions -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.format -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import java.io.Serializable - -/** - * ResourceDefinitionValidationService. - * - * @author Brinda Santh - */ -interface ResourceDefinitionValidationService : Serializable { - - @Throws(BluePrintException::class) - fun validate(resourceDefinition: ResourceDefinition) - -} - -/** - * ResourceDefinitionValidationService. - * - * @author Brinda Santh - */ -open class ResourceDefinitionValidationServiceImpl(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidationService::class.java) - - override fun validate(resourceDefinition: ResourceDefinition) { - Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") - log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name) - - resourceDefinition.sources.forEach { name, nodeTemplate -> - val sourceType = nodeTemplate.type - - val sourceNodeType = bluePrintRepoService.getNodeType(sourceType) - - // Validate Property Name, expression, values and Data Type - validateNodeTemplateProperties(nodeTemplate, sourceNodeType) - } - } - - - open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) { - nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } - } - - - open fun validatePropertyAssignments(nodeTypeProperties: MutableMap, - properties: MutableMap) { - properties.forEach { propertyName, propertyAssignment -> - val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] - ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) - // Check and Validate if Expression Node - val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) - if (!expressionData.isExpression) { - checkPropertyValue(propertyDefinition, propertyName, propertyAssignment) - } else { - throw BluePrintException(format("property({}) of expression ({}) is not supported", - propertyName, propertyAssignment)) - } - } - } - - open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) { - val propertyType = propertyDefinition.type - val isValid: Boolean - - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) - - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - - isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) - } else { - bluePrintRepoService.getDataType(propertyType) - isValid = true - } - - check(isValid) { - throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})", - propertyName, propertyType, propertyAssignment)) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java deleted file mode 100644 index 7f040b2e2..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.resource.dict.service; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; - -public class ResourceDefinitionValidationServiceTest { - private String basePath = "load/model_type"; - private String dictionaryPath = "load/resource_dictionary"; - private BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); - - @Test - public void testValidateSource() throws Exception { - - String inputFileName = dictionaryPath + "/input-source.json"; - testValidate(inputFileName); - - String dbFileName = dictionaryPath + "/primary-db-source.json"; - testValidate(dbFileName); - - String defaultFileName = dictionaryPath + "/default-source.json"; - testValidate(defaultFileName); - - String restFileName = dictionaryPath + "/mdsal-source.json"; - testValidate(restFileName); - } - - private void testValidate(String fileName) throws Exception { - - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); - - ResourceDefinitionValidationService resourceDictionaryValidationService = - new ResourceDefinitionValidationServiceImpl(bluePrintRepoFileService); - resourceDictionaryValidationService.validate(resourceDefinition); - Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java deleted file mode 100644 index 57330d90f..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.validator; - -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; - -/** - * ResourceDictionaryValidator.java Purpose: Provide Validation Service for Model Type Resource - * Dictionary Validator - * - * @author Brinda Santh - * @version 1.0 - */ -public class ResourceDictionaryValidator { - - private ResourceDictionaryValidator() {} - - /** - * This is a validateResourceDictionary method - * - * @param resourceDictionary - * @return boolean - * - */ - public static boolean validateResourceDictionary(ResourceDictionary resourceDictionary) { - - Preconditions.checkNotNull(resourceDictionary,"ResourceDictionary Information is missing." ); - - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getName()), - "DataDictionary Alias Name Information is missing."); - Preconditions.checkNotNull( resourceDictionary.getDefinition(), - "DataDictionary Definition Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()), - "DataDictionary Description Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getTags()), - "DataDictionary Tags Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getUpdatedBy()), - "DataDictionary Updated By Information is missing."); - return true; - - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java deleted file mode 100644 index 5d15e0876..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java +++ /dev/null @@ -1,147 +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.validator; - -import com.google.common.base.Preconditions; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.jetbrains.annotations.NotNull; -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.CapabilityAssignment; -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService; -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.service.ResourceAssignmentValidationService; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator - * - * @author Brinda Santh - * @version 1.0 - */ - -public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { - - StringBuilder message = new StringBuilder(); - private Map metaData = new HashMap<>(); - - /** - * This is a validateServiceTemplate - * - * @param serviceTemplateContent serviceTemplateContent - * @return boolean - * @throws BluePrintException BluePrintException - */ - public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { - if (StringUtils.isNotBlank(serviceTemplateContent)) { - ServiceTemplate serviceTemplate = - JacksonUtils.Companion.readValue(serviceTemplateContent, ServiceTemplate.class); - return validateServiceTemplate(serviceTemplate); - } else { - throw new BluePrintException( - "Service Template Content is (" + serviceTemplateContent + ") not Defined."); - } - } - - /** - * This is a validateServiceTemplate - * - * @param serviceTemplate serviceTemplate - * @return boolean - * @throws BluePrintException BluePrintException - */ - @SuppressWarnings("squid:S00112") - public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - Map properties = new HashMap<>(); - super.validateBlueprint(serviceTemplate, properties); - return true; - } - - /** - * This is a getMetaData to get the key information during the - * - * @return Map - */ - public Map getMetaData() { - return metaData; - } - - @Override - public void validateMetadata(@NotNull Map metaDataMap) throws BluePrintException { - - Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing."); - super.validateMetadata(metaDataMap); - - this.metaData.putAll(serviceTemplate.getMetadata()); - } - - - @Override - public void validateNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) - throws BluePrintException { - super.validateNodeTemplate(nodeTemplateName, nodeTemplate); - validateNodeTemplateCustom(nodeTemplateName, nodeTemplate); - - } - - @Deprecated() - private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) - throws BluePrintException { - String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom(); - - if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) { - List resourceAssignment = getResourceAssignments(nodeTemplate); - ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl(); - resourceAssignmentValidationService.validate(resourceAssignment); - } - } - - private List getResourceAssignments(@NotNull NodeTemplate nodeTemplate) { - - List resourceAssignment = null; - - if (MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) { - - CapabilityAssignment capabilityAssignment = - nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) { - Object mappingObject = - capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - if (mappingObject != null) { - String mappingContent = JacksonUtils.Companion.getJson(mappingObject); - Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent), - String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)); - - resourceAssignment = JacksonUtils.Companion.getListFromJson(mappingContent, ResourceAssignment.class); - - Preconditions.checkNotNull(resourceAssignment, - String.format("Failed to get resource assignment info from the content (%s) ", mappingContent)); - } - } - } - return resourceAssignment; - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt index f856b9efe..88589eb7d 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,21 +25,10 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.* import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationServiceImpl import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository import org.springframework.stereotype.Service -// Resource Dictionary Validation Services - -@Service -class DefaultResourceAssignmentValidationService : ResourceAssignmentValidationServiceImpl() - -@Service -class DefalutResourceDefinitionValidationService(bluePrintRepoService: BluePrintRepoService) - : ResourceDefinitionValidationServiceImpl(bluePrintRepoService) - interface ResourceDefinitionRepoService : BluePrintRepoService { @Throws(BluePrintException::class) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt index c24931484..ec7d8aebc 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,17 +21,15 @@ import com.google.common.base.Preconditions import org.apache.commons.collections.CollectionUtils import org.apache.commons.lang3.StringUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationService 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 import org.springframework.stereotype.Service @Service -class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository, - private val resourceDictionaryValidationService: ResourceDefinitionValidationService) { +class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) { /** @@ -86,7 +85,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour val resourceDefinition = resourceDictionary.definition Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content") // Validate the Resource Definitions - resourceDictionaryValidationService.validate(resourceDefinition) + //TODO( Save Validator) + //validate(resourceDefinition) resourceDictionary.tags = resourceDefinition.tags resourceDefinition.updatedBy = resourceDictionary.updatedBy @@ -98,7 +98,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour resourceDictionary.entrySchema = propertyDefinition.entrySchema!!.type } - ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary) + validateResourceDictionary(resourceDictionary) val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name) if (dbResourceDictionaryData.isPresent) { @@ -135,4 +135,14 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour fun getResourceSourceMapping(): ResourceSourceMapping { return ResourceSourceMappingFactory.getRegisterSourceMapping() } + + private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean { + checkNotEmptyOrThrow(resourceDictionary.name, "DataDictionary Definition name is missing.") + checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." } + checkNotEmptyOrThrow(resourceDictionary.description, "DataDictionary Definition Information is missing.") + checkNotEmptyOrThrow(resourceDictionary.tags, "DataDictionary Definition tags is missing.") + checkNotEmptyOrThrow(resourceDictionary.updatedBy, "DataDictionary Definition updatedBy is missing.") + return true + + } } \ No newline at end of file -- cgit 1.2.3-korg From 3476ae694de004c83600bb7a1a58ee94f9cf9f87 Mon Sep 17 00:00:00 2001 From: vinal patel Date: Wed, 20 Feb 2019 16:02:44 -0500 Subject: Ressource resolution using configurable database Change-Id: I40338a221884d6f4df4c8a7dc3dac1f58f142074 Issue-ID: CCSDK-1092 Signed-off-by: vinal patel --- .../application/src/main/resources/application-dev.properties | 2 +- .../application/src/main/resources/application.properties | 2 +- .../application/src/test/resources/application.properties | 2 +- .../resource/dict/ResourceDictionaryConstants.kt | 2 ++ .../resource/dict/utils/ResourceDictionaryUtilsTest.java | 6 +++--- .../modules/service/src/test/resources/application.properties | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) (limited to 'ms/controllerblueprints/modules/resource-dict/src/test/java') diff --git a/ms/controllerblueprints/application/src/main/resources/application-dev.properties b/ms/controllerblueprints/application/src/main/resources/application-dev.properties index 1c9029d5b..3401ece04 100755 --- a/ms/controllerblueprints/application/src/main/resources/application-dev.properties +++ b/ms/controllerblueprints/application/src/main/resources/application-dev.properties @@ -49,7 +49,7 @@ spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect # Load Resource Source Mappings -resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability +resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability # Controller Blueprints Core Configuration controllerblueprints.blueprintDeployPath=/etc/blueprints/deploy controllerblueprints.blueprintArchivePath=/etc/blueprints/archive diff --git a/ms/controllerblueprints/application/src/main/resources/application.properties b/ms/controllerblueprints/application/src/main/resources/application.properties index 034093888..8789c24ec 100755 --- a/ms/controllerblueprints/application/src/main/resources/application.properties +++ b/ms/controllerblueprints/application/src/main/resources/application.properties @@ -52,7 +52,7 @@ spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect # Load Resource Source Mappings -resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability +resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability # Controller Blueprints Core Configuration controllerblueprints.blueprintDeployPath=/etc/blueprints/deploy diff --git a/ms/controllerblueprints/application/src/test/resources/application.properties b/ms/controllerblueprints/application/src/test/resources/application.properties index e0369aea4..8ad9f2c09 100755 --- a/ms/controllerblueprints/application/src/test/resources/application.properties +++ b/ms/controllerblueprints/application/src/test/resources/application.properties @@ -33,7 +33,7 @@ swagger.contact.url=www.onap.com swagger.contact.email=brindasanth@onap.com # Load Resource Source Mappings -resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability +resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability # Controller Blueprints Core Configuration controllerblueprints.blueprintDeployPath=./target/blueprints/deploy diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt index d33a2f04b..75368684c 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -24,6 +24,8 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict object ResourceDictionaryConstants { const val SOURCE_INPUT = "input" const val SOURCE_DEFAULT = "default" + //const val SOURCE_PRIMARY_CONFIG_DATA = "rest" + const val SOURCE_PROCESSOR_DB = "processor-db" const val SOURCE_PRIMARY_CONFIG_DATA = "primary-config-data" const val SOURCE_PRIMARY_DB = "primary-db" diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java index e4ddac131..45fc739d7 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -59,9 +59,9 @@ public class ResourceDictionaryUtilsTest { Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource()); // To Check Assigned Source - resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PRIMARY_DB); + resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.getDictionarySource()); + Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.getDictionarySource()); } @@ -78,7 +78,7 @@ public class ResourceDictionaryUtilsTest { Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource); // TO check the multiple Source - sources.put(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, new NodeTemplate()); + sources.put(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, new NodeTemplate()); String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources); Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource); diff --git a/ms/controllerblueprints/modules/service/src/test/resources/application.properties b/ms/controllerblueprints/modules/service/src/test/resources/application.properties index 20450f445..011bad32c 100755 --- a/ms/controllerblueprints/modules/service/src/test/resources/application.properties +++ b/ms/controllerblueprints/modules/service/src/test/resources/application.properties @@ -20,7 +20,7 @@ logging.level.org.springframework.web=INFO logging.level.org.hibernate.SQL=warn logging.level.org.hibernate.type.descriptor.sql=debug # Load Resource Source Mappings -resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability +resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability # Controller Blueprints Core Configuration controllerblueprints.blueprintDeployPath=./target/blueprints/deploy controllerblueprints.blueprintArchivePath=./target/blueprints/archive -- cgit 1.2.3-korg