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) --- .../apps/controllerblueprints/DatabaseConfig.java | 61 ++ .../controllerblueprints/JerseyConfiguration.java | 69 ++ .../apps/controllerblueprints/TestApplication.java | 34 + .../controllerblueprints/TestConfiguration.java | 36 + .../service/common/SchemaGeneratorServiceTest.java | 50 ++ .../common/ServiceTemplateValidationTest.java | 56 ++ .../service/rs/ConfigModelRestTest.java | 172 +++++ .../service/rs/ModelTypeRestTest.java | 130 ++++ .../service/rs/ResourceDictionaryRestTest.java | 113 +++ .../service/rs/ServiceTemplateRestTest.java | 155 ++++ .../service/utils/ConfigModelUtilsTest.java | 33 + .../src/test/resources/application.properties | 67 ++ .../test/resources/enhance/enhance-template.json | 345 +++++++++ .../test/resources/enhance/enhanced-template.json | 824 +++++++++++++++++++++ .../test/resources/resourcedictionary/automap.json | 11 + .../resourcedictionary/default_definition.json | 19 + 16 files changed, 2175 insertions(+) create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/application.properties create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/automap.json create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java new file mode 100644 index 000000000..db35fe661 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java @@ -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; + +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; + +/** + * DatabaseConfig.java Purpose: Provide Configuration Generator DatabaseConfig Information + * + * @author Brinda Santh + * @version 1.0 + */ +@Configuration +@EntityScan("org.onap.ccsdk.apps.controllerblueprints.service.domain") +@EnableTransactionManagement +@EnableJpaRepositories("org.onap.ccsdk.apps.controllerblueprints.service.repository") +@EnableJpaAuditing +public class DatabaseConfig { + /** + * This is a entityManagerFactory method + * + * @param dataSource + * @return LocalContainerEntityManagerFactoryBean + */ + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { + HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + vendorAdapter.setGenerateDdl(true); + vendorAdapter.setShowSql(false); + LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); + factory.setJpaVendorAdapter(vendorAdapter); + factory.setPackagesToScan("org.onap.ccsdk.apps.controllerblueprints.service.domain"); + factory.setDataSource(dataSource); + return factory; + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java new file mode 100644 index 000000000..f5535eb12 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java @@ -0,0 +1,69 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.glassfish.jersey.logging.LoggingFeature; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletProperties; +import org.onap.ccsdk.apps.controllerblueprints.service.common.ServiceExceptionMapper; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ConfigModelRestImpl; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ModelTypeRestImpl; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ResourceDictionaryRestImpl; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ServiceTemplateRestImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +import java.util.logging.Logger; + + +@Component +public class JerseyConfiguration extends ResourceConfig { + private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName()); + + @Bean + @Primary + public ObjectMapper objectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); + objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); + objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); + return objectMapper; + } + + @Autowired + public JerseyConfiguration() { + register(ConfigModelRestImpl.class); + register(ModelTypeRestImpl.class); + register(ResourceDictionaryRestImpl.class); + register(ServiceTemplateRestImpl.class); + // Exception Mapping + register(ServiceExceptionMapper.class); + property(ServletProperties.FILTER_FORWARD_ON_404, true); + register(new LoggingFeature(log)); + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java new file mode 100644 index 000000000..537429f0b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java @@ -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; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + + +@SpringBootApplication +@ComponentScan(basePackages = {"org.onap.ccsdk.apps.controllerblueprints"}) +@EnableAutoConfiguration +public class TestApplication { + + public static void main(String[] args) { + SpringApplication.run(TestApplication.class, args); + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java new file mode 100644 index 000000000..ea259c9c9 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.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; + +import org.springframework.context.annotation.Bean; + +import java.util.ArrayList; + +//@Configuration +public class TestConfiguration { + + @Bean("jaxrsProviders") + public ArrayList provider() { + return new ArrayList(); + } + + @Bean("jaxrsServices") + public ArrayList service() { + return new ArrayList(); + } + +} 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 new file mode 100644 index 000000000..50e94df9e --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java @@ -0,0 +1,50 @@ +/* + * 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.common; + +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +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 java.io.File; +import java.nio.charset.Charset; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class SchemaGeneratorServiceTest { + + private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class); + + @Test + public void test01GenerateSwaggerData() throws Exception { + log.info("******************* test01GenerateSwaggerData ******************************"); + + String file = "src/test/resources/enhance/enhanced-template.json"; + String serviceTemplateContent = FileUtils.readFileToString(new File(file), Charset.defaultCharset()); + SchemaGeneratorService schemaGeneratorService = new SchemaGeneratorService(); + String schema = schemaGeneratorService.generateSchema(serviceTemplateContent); + log.trace("Generated Schema " + schema); + Assert.assertNotNull("failed to generate Sample Data", schema); + + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java new file mode 100644 index 000000000..af309e217 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java @@ -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.service.common; + + +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.validator.ServiceTemplateValidator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.charset.Charset; +import java.util.List; + +public class ServiceTemplateValidationTest { + private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class); + + @Test + public void testBluePrintDirs(){ + List dirs = ConfigModelUtils.getBlueprintNames("load/blueprints"); + Assert.assertNotNull("Failed to get blueprint directories", dirs ); + Assert.assertEquals("Failed to get actual directories",2, dirs.size() ); + } + + // @Test + public void validateServiceTemplate() { + try { + String file = "load/service_template/vrr-201806-test/service-template.json"; + String serviceTemplateContent = + IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader().getResourceAsStream(file), + Charset.defaultCharset()); + ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); + serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); + log.info("Validated Service Template " + serviceTemplateValidator.getMetaData()); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} 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 new file mode 100644 index 000000000..5b10a7e86 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java @@ -0,0 +1,172 @@ +/* + * 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.rs; + +import org.junit.*; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.apps.controllerblueprints.TestApplication; +import org.onap.ccsdk.apps.controllerblueprints.TestConfiguration; +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 org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ConfigModelRestTest { + + private static Logger log = LoggerFactory.getLogger(ConfigModelRestTest.class); + + @Autowired + ConfigModelRest configModelRest; + + ConfigModel configModel; + + String name = "vrr-test"; + String version = "1.0.0"; + + @Before + public void setUp() { + + } + + + @After + public void tearDown() { + } + + + @Test + public void test01getInitialConfigModel() throws Exception { + log.info("** test01getInitialConfigModel *****************"); + + String name = "default_netconf"; + ConfigModel configModel = configModelRest.getInitialConfigModel(name); + Assert.assertNotNull("Failed to get Initial Config Model , Return object is Null", configModel); + Assert.assertNotNull("Failed to get Service Template Content ", configModel.getConfigModelContents()); + + } + + + @Test + public void test02SaveServiceTemplate() throws Exception { + log.info("************************ test02SaveServiceTemplate ******************"); + + + configModel = ConfigModelUtils.getConfigModel("load/blueprints/vrr-test"); + + configModel = configModelRest.saveConfigModel(configModel); + Assert.assertNotNull("Failed to ConfigModel, Return object is Null", configModel); + Assert.assertNotNull("Failed to ConfigModel Id , Return ID object is Null", configModel.getId()); + Assert.assertNotNull("Failed to ConfigModel Content, Return object is Null", + configModel.getConfigModelContents()); + Assert.assertEquals("Failed in validation of ConfigModel Content count,", 3, + configModel.getConfigModelContents().size()); + + ConfigModel dbconfigModel = configModelRest.getConfigModel(configModel.getId()); + + log.info("************************ test02SaveServiceTemplate-2 ******************"); + + dbconfigModel.getConfigModelContents().remove(2); + dbconfigModel = configModelRest.saveConfigModel(dbconfigModel); + log.info("Saved Config Model " + configModel.getId()); + Assert.assertNotNull("Failed to ConfigModel, Return object is Null", dbconfigModel); + Assert.assertNotNull("Failed to ConfigModel Id ", dbconfigModel.getId()); + Assert.assertNotNull("Failed to ConfigModel Content", + dbconfigModel.getConfigModelContents()); + Assert.assertEquals("Failed to Remove the ConfigModel Content,", 2, + dbconfigModel.getConfigModelContents().size()); + + + } + + + @Test + public void test03PublishServiceTemplate() throws Exception { + log.info("** test03PublishServiceTemplate *****************"); + + ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); + log.info("Publishing Config Model " + configModel.getId()); + configModel = configModelRest.publishConfigModel(configModel.getId()); + Assert.assertNotNull("Failed to ConfigModel, Return object is Null", configModel); + Assert.assertNotNull("Failed to ConfigModel Id ", configModel.getId()); + Assert.assertNotNull("Failed to ConfigModel Content", configModel.getConfigModelContents()); + Assert.assertEquals("Failed to update the publish indicator", "Y", configModel.getPublished()); + } + + + @Test + public void test04GetConfigModel() throws Exception { + log.info("** test04GetConfigModel *****************"); + + ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); + Assert.assertNotNull("Failed to get ConfigModel for the Name (" + configModel.getArtifactName() + ") and (" + + configModel.getArtifactVersion() + ")", configModel); + Assert.assertNotNull("Failed to get ConfigModel Id", configModel.getId()); + + configModel = configModelRest.getConfigModel(configModel.getId()); + Assert.assertNotNull("Failed to get ConfigModel for the Id (" + configModel.getId() + ") ", configModel); + + } + + @Test + public void test05GetCloneConfigModel() throws Exception { + log.info("** test05GetCloneConfigModel *****************"); + + ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); + + Assert.assertNotNull("Failed to get ConfigModel for the Name (" + configModel.getArtifactName() + ") and (" + + configModel.getArtifactVersion() + ")", configModel); + Assert.assertNotNull("Failed to get ConfigModel Id", configModel.getId()); + + configModel = configModelRest.getCloneConfigModel(configModel.getId()); + Assert.assertNotNull("Failed to get ConfigModel for the Id (" + configModel.getId() + ") ", configModel); + } + + + @Test + public void test07SearchConfigModels() throws Exception { + log.info("** test07SearchConfigModels *****************"); + + List configModels = configModelRest.searchConfigModels("vrr-test"); + Assert.assertNotNull("Failed to search ConfigModel", configModels); + Assert.assertTrue("Failed to search ConfigModel with count", configModels.size() > 0); + // update the ServiceModelContent + } + + + @Test + public void test08DeleteConfigModels() throws Exception { + log.info("** test08DeleteConfigModels *****************"); + + ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); + configModelRest.deleteConfigModel(configModel.getId()); + + } + + +} 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 new file mode 100644 index 000000000..d33349c53 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java @@ -0,0 +1,130 @@ +/* + * 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.rs; + +import org.apache.commons.io.FileUtils; +import org.junit.*; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.apps.controllerblueprints.TestApplication; +import org.onap.ccsdk.apps.controllerblueprints.TestConfiguration; +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 org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ModelTypeRestTest { + private static Logger log = LoggerFactory.getLogger(ModelTypeRestTest.class); + @Autowired + ModelTypeRest modelTypeRest; + + String modelName = "test-datatype"; + + @Before + public void setUp() { + + } + + + @After + public void tearDown() {} + + @Test + public void test01SaveModelType() throws Exception { + log.info( "**************** test01SaveModelType ********************"); + + String content = FileUtils.readFileToString(new File("load/model_type/data_type/datatype-property.json"), Charset.defaultCharset()); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); + modelType.setDescription("Definition for Sample Datatype "); + modelType.setDefinition(content); + modelType.setModelName(modelName); + modelType.setVersion("1.0.0"); + modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setUpdatedBy("xxxxxx@xxx.com"); + modelType = modelTypeRest.saveModelType(modelType); + log.info( "Saved Mode {}", modelType.toString()); + Assert.assertNotNull("Failed to get Saved ModelType", modelType); + Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName()); + + ModelType dbModelType = modelTypeRest.getModelTypeByName(modelType.getModelName()); + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")", + dbModelType); + + // Model Update + modelType.setUpdatedBy("bs2796@xxx.com"); + modelType = modelTypeRest.saveModelType(modelType); + Assert.assertNotNull("Failed to get Saved ModelType", modelType); + Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy()); + + } + + @Test + public void test02SearchModelTypes() throws Exception { + log.info( "*********************** test02SearchModelTypes ***************************"); + + String tags = "test-datatype"; + + List dbModelTypes = modelTypeRest.searchModelTypes(tags); + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes); + Assert.assertEquals("Failed to search ResourceMapping by tags count", true, dbModelTypes.size() > 0); + + } + + @Test + public void test03GetModelType() throws Exception { + log.info( "************************* test03GetModelType *********************************"); + ModelType dbModelType = modelTypeRest.getModelTypeByName(modelName); + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType); + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName()); + + List dbDatatypeModelTypes = + modelTypeRest.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes); + Assert.assertEquals("Failed to find getModelTypeByDefinitionType by count", true, + dbDatatypeModelTypes.size() > 0); + } + + @Test + public void test04DeleteModelType() throws Exception { + log.info( + "************************ test03DeleteModelType ***********************"); + ModelType dbResourceMapping = modelTypeRest.getModelTypeByName(modelName); + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping); + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping.getModelName()); + + modelTypeRest.deleteModelTypeByName(dbResourceMapping.getModelName()); + } + + + +} 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 new file mode 100644 index 000000000..71dff338b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java @@ -0,0 +1,113 @@ +/* + * 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.rs; + +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +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.TestConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +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.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; + + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ResourceDictionaryRestTest { + + private static Logger log = LoggerFactory.getLogger(ResourceDictionaryRestTest.class); + + @Autowired + protected ResourceDictionaryRest resourceDictionaryRest; + + @Before + public void setUp() { + + } + + @Test + public void test01SaveDataDictionary() throws Exception { + String definition = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("resourcedictionary/default_definition.json"), + Charset.defaultCharset()); + + ResourceDictionary dataDictionary = new ResourceDictionary(); + dataDictionary.setResourcePath("test/vnf/ipaddress"); + dataDictionary.setName("test-name"); + dataDictionary.setDefinition(definition); + dataDictionary.setValidValues("127.0.0.1"); + dataDictionary.setResourceType("ONAP"); + dataDictionary.setDataType("string"); + dataDictionary.setDescription("Sample Resource Mapping"); + dataDictionary.setTags("test, ipaddress"); + dataDictionary.setUpdatedBy("xxxxxx@xxx.com"); + + dataDictionary = resourceDictionaryRest.saveResourceDictionary(dataDictionary); + + Assert.assertNotNull("Failed to get Saved Resource Dictionary", dataDictionary); + Assert.assertNotNull("Failed to get Saved Resource Dictionary, Id", dataDictionary.getName()); + + ResourceDictionary dbDataDictionary = + resourceDictionaryRest.getResourceDictionaryByName(dataDictionary.getName()); + Assert.assertNotNull("Failed to query Resource Dictionary for ID (" + dataDictionary.getName() + ")", + dbDataDictionary); + Assert.assertNotNull("Failed to query Resource Dictionary definition for ID (" + dataDictionary.getName() + ")", + dbDataDictionary.getDefinition()); + + log.trace("Saved Dictionary " + dbDataDictionary.getDefinition()); + + } + + @Test + public void test02GetDataDictionary() throws Exception { + + ResourceDictionary dbResourceDictionary = resourceDictionaryRest.getResourceDictionaryByName("test-name"); + Assert.assertNotNull("Failed to query Resource Dictionary by Name", dbResourceDictionary); + + String tags = "ipaddress"; + + List dbResourceDictionaries = resourceDictionaryRest.searchResourceDictionaryByTags(tags); + Assert.assertNotNull("Failed to search ResourceDictionary by tags", dbResourceDictionaries); + Assert.assertTrue("Failed to search searchResourceDictionaryByTags by tags by count", + dbResourceDictionaries.size() > 0); + + List names = new ArrayList<>(); + names.add("test-name"); + dbResourceDictionaries = resourceDictionaryRest.searchResourceDictionaryByNames(names); + Assert.assertNotNull("Failed to search ResourceDictionary by Names", dbResourceDictionaries); + Assert.assertTrue("Failed to search searchResourceDictionaryByNames by tags by count", + dbResourceDictionaries.size() > 0); + + } + +} 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 new file mode 100644 index 000000000..f81dd4165 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java @@ -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.service.rs; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.FixMethodOrder; +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.TestConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +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 org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.List; + + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ServiceTemplateRestTest { + + private static Logger log = LoggerFactory.getLogger(ServiceTemplateRestTest.class); + @Autowired + ModelTypeRest modelTypeRest; + + @Autowired + private ServiceTemplateRest serviceTemplateRest; + + @Test + public void test02EnrichServiceTemplate() throws Exception { + log.info("*********** test02EnrichServiceTemplate ***********************"); + String file = "src/test/resources/enhance/enhance-template.json"; + + String serviceTemplateContent = FileUtils.readFileToString(new File(file), Charset.defaultCharset()); + + ServiceTemplate serviceTemplate = JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + + serviceTemplate = serviceTemplateRest.enrichServiceTemplate(serviceTemplate); + + String enhancedFile = "src/test/resources/enhance/enhanced-template.json"; + + FileUtils.write(new File(enhancedFile), + JacksonUtils.getJson(serviceTemplate, true), Charset.defaultCharset()); + + Assert.assertNotNull("Failed to get Enriched Blueprints, Return object is Null", serviceTemplate); + Assert.assertNotNull("Failed to get Enriched Blueprints Data Type, Return object is Null", + serviceTemplate.getDataTypes()); + Assert.assertNotNull("Failed to get Enriched Blueprints Node Type, Return object is Null", + serviceTemplate.getNodeTypes()); + log.trace("Enriched Service Template :\n" + JacksonUtils.getJson(serviceTemplate, true)); + } + + @Test + public void test03ValidateServiceTemplate() throws Exception { + log.info("*********** test03ValidateServiceTemplate *******************************************"); + String enhancedFile = "src/test/resources/enhance/enhanced-template.json"; + String serviceTemplateContent = FileUtils.readFileToString(new File(enhancedFile), Charset.defaultCharset()); + + ServiceTemplate serviceTemplate = + JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + + serviceTemplate = serviceTemplateRest.validateServiceTemplate(serviceTemplate); + + Assert.assertNotNull("Failed to validate Service Template, Return object is Null", serviceTemplate); + Assert.assertNotNull("Failed to get Service Template Data Type, Return object is Null", + serviceTemplate.getDataTypes()); + Assert.assertNotNull("Failed to get Service Template Node Type, Return object is Null", + serviceTemplate.getNodeTypes()); + + log.trace("Validated Service Template :\n" + JacksonUtils.getJson(serviceTemplate, true)); + + } + + + @Test + public void test04GenerateResourceAssignments() throws Exception { + log.info("*********** test04GenerateResourceAssignments *******************************************"); + ConfigModelContent baseConfigConfigModelContent = new ConfigModelContent(); + String baseConfigContent = FileUtils.readFileToString(new File("load/blueprints/vrr-test/Templates/base-config-template.vtl") + , Charset.defaultCharset()); + baseConfigConfigModelContent.setName("base-config-template"); + baseConfigConfigModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); + baseConfigConfigModelContent.setContent(baseConfigContent); + + List resourceAssignments = + serviceTemplateRest.generateResourceAssignments(baseConfigConfigModelContent); + + Assert.assertNotNull("Failed to get ResourceAssignments, Return object is Null", resourceAssignments); + Assert.assertTrue("Failed to get ResourceAssignments count", resourceAssignments.size() > 0); + + log.trace("Validated Service Template :\n" + JacksonUtils.getJson(resourceAssignments, true)); + + + } + + @Test + public void test05AutoMap() throws Exception { + log.info("*********** test05AutoMap *******************************************"); + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/resourcedictionary/automap.json"), Charset.defaultCharset()); + List batchResourceAssignment = + JacksonUtils.getListFromJson(resourceassignmentContent, ResourceAssignment.class); + AutoMapResponse autoMapResponse = serviceTemplateRest.autoMap(batchResourceAssignment); + + Assert.assertNotNull("Failed to get ResourceAssignments, Return object is Null", + autoMapResponse.getResourceAssignments()); + Assert.assertNotNull("Failed to get Data Dictionary from ResourceAssignments", + autoMapResponse.getDataDictionaries()); + Assert.assertTrue("Failed to get ResourceAssignments count", + CollectionUtils.isNotEmpty(autoMapResponse.getDataDictionaries())); + + List autoMappedResourceAssignment = autoMapResponse.getResourceAssignments(); + autoMappedResourceAssignment.forEach(resourceAssignment -> { + if ("bundle-id".equals(resourceAssignment.getName())) { + Assert.assertEquals("Failed to assign default first source", "db", + resourceAssignment.getDictionarySource()); + } + }); + + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java new file mode 100644 index 000000000..b38dd6de1 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java @@ -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.service.utils; + +import org.apache.commons.collections.CollectionUtils; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; + +public class ConfigModelUtilsTest { + + @Test + public void testConfigModel() throws Exception { + + ConfigModel configModel = ConfigModelUtils.getConfigModel("load/blueprints/vrr-test"); + Assert.assertNotNull("Failed to prepare config model", configModel); + Assert.assertTrue("Failed to prepare config model contents", CollectionUtils.isNotEmpty(configModel.getConfigModelContents())); + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/resources/application.properties b/ms/controllerblueprints/modules/service/src/test/resources/application.properties new file mode 100644 index 000000000..a13e16841 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/application.properties @@ -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. +# + +info.build.artifact=@project.artifactId@ +info.build.name=@project.name@ +info.build.description=@project.description@ +info.build.version=@project.version@ +info.build.groupId=@project.groupId@ +logging.level.root=info + +server.contextPath=/ +server.servlet-path=/ +spring.jersey.application-path=/api/controller-blueprints/v1 +server.routingPath=/api + + +mots.application.acronym=MOTS_ID +platform.identifier=AJSC7_JERSEY +#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + +#logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr($ threadId: {PID:- }){magenta} %clr(---){faint} %clr([ hostname: %X{hostname} serviceName: %X{serviceName} version: %X{version} transactionId: %X{transactionId} requestTimeStamp: %X{requestTimestamp} responseTimeStamp: %X{responseTimestamp} duration: %X{duration}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex + + +#The max number of active threads in this pool +server.tomcat.max-threads=200 +#The minimum number of threads always kept alive +server.tomcat.min-Spare-Threads=25 +#The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads +server.tomcat.max-idle-time=60000 + +#for changing the tomcat port... +#server.port=8081 + + + +#Servlet context parameters +server.context_parameters.p-name=value #context parameter with p-name as key and value as value. + +# make this true for AAF authentication and place cadi.properties into etc folder +aaf.enabled=true + +# set to true to enable version proxy +#ivp.enabled=false + +spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false + + +logging.level.org.springframework.web=INFO +logging.level.org.hibernate.SQL=warn +logging.level.org.hibernate.type.descriptor.sql=debug + + +blueprints.load.initial-data=true +blueprints.load.path=load \ No newline at end of file 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 new file mode 100644 index 000000000..8b4fd9d3a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json @@ -0,0 +1,345 @@ +{ + "metadata": { + "template_author": "Brinda Santh", + "template_name": "enhance-template", + "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\" }", + "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/service/src/test/resources/enhance/enhanced-template.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json new file mode 100644 index 000000000..18f499250 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json @@ -0,0 +1,824 @@ +{ + "metadata" : { + "template_author" : "Brinda Santh", + "template_name" : "enhance-template", + "template_version" : "1.0.0", + "service-type" : "Sample Service", + "release" : "1806", + "vnf-type" : "VPE" + }, + "tosca_definitions_version" : "controller_blueprint_1_0_0", + "artifact_types" : { }, + "data_types" : { + "dt-v4-aggregate" : { + "description" : "This is dt-v4-aggregate Data Type", + "version" : "1.0.0", + "properties" : { + "ipv4-address" : { + "required" : true, + "type" : "string" + }, + "ipv4-plen" : { + "required" : false, + "type" : "integer" + } + }, + "derived_from" : "tosca.datatypes.Root" + }, + "dt-license-key" : { + "description" : "This is dt-plicense-key Data Type", + "version" : "1.0.0", + "properties" : { + "license-key" : { + "required" : true, + "type" : "string" + } + }, + "derived_from" : "tosca.datatypes.Root" + }, + "datatype-resource-assignment" : { + "description" : "This is Resource Assignment Data Type", + "version" : "1.0.0", + "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" + }, + "datatype-property" : { + "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", + "version" : "1.0.0", + "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" + }, + "dt-resource-assignment-request" : { + "description" : "This is Dynamic Data type definition generated from resource mapping for the config template name base-config-template.", + "version" : "1.0.0", + "properties" : { + "bundle-mac" : { + "description" : "", + "required" : true, + "type" : "string", + "status" : "", + "constraints" : [ { } ], + "entry_schema" : { + "type" : "" + } + }, + "hostname" : { + "required" : true, + "type" : "string" + }, + "licenses" : { + "description" : "", + "required" : true, + "type" : "list", + "status" : "", + "constraints" : [ { } ], + "entry_schema" : { + "type" : "dt-license-key" + } + }, + "wan-aggregate-ipv4-addresses" : { + "description" : "", + "required" : true, + "type" : "list", + "status" : "", + "constraints" : [ { } ], + "entry_schema" : { + "type" : "dt-v4-aggregate" + } + }, + "service" : { + "required" : true, + "type" : "string" + }, + "service-instance-id" : { + "required" : true, + "type" : "string" + } + }, + "derived_from" : "tosca.datatypes.Dynamic" + } + }, + "node_types" : { + "dg-resource-assignment" : { + "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" + }, + "component-resource-assignment" : { + "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" + }, + "artifact-config-template" : { + "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" + }, + "vnf-netconf-device" : { + "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" + }, + "component-netconf-executor" : { + "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" + }, + "dg-activate-netconf" : { + "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" + } + }, + "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" + }, + "resource-assignment-request" : { + "description" : "This is Dynamic Data type for the receipe resource-assignment-action.", + "required" : false, + "type" : "dt-resource-assignment-request" + } + }, + "node_templates" : { + "vpe-netconf-device" : { + "type" : "vnf-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 + } + } + } + }, + "activate-netconf-component" : { + "type" : "component-netconf-executor", + "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" : { + "implementation" : { + "primary" : "file://netconf_adaptor/DefaultBaseLicenceConfig.py" + }, + "inputs" : { + "action-name" : "{ \"get_input\" : \"action-name\" }", + "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\" }" + } + } + } + } + } + }, + "resource-assignment-ra-component" : { + "type" : "component-resource-assignment", + "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" + } + } + } + } + } + }, + "resource-assignment-action" : { + "type" : "dg-resource-assignment", + "properties" : { + "mode" : "sync", + "version" : "LATEST", + "is-start-flow" : "false" + }, + "capabilities" : { + "dg-node" : { }, + "content" : { + "properties" : { + "type" : "json" + } + } + }, + "requirements" : { + "component-dependency" : { + "capability" : "component-node", + "node" : "resource-assignment-ra-component", + "relationship" : "tosca.relationships.DependsOn" + } + }, + "interfaces" : { + "CONFIG" : { + "operations" : { + "ResourceAssignment" : { + "inputs" : { + "params" : [ ] + } + } + } + } + } + }, + "activate-action" : { + "type" : "dg-activate-netconf", + "properties" : { + "mode" : "sync", + "version" : "LATEST", + "is-start-flow" : "false" + }, + "capabilities" : { + "dg-node" : { }, + "content" : { + "properties" : { + "type" : "json" + } + } + }, + "requirements" : { + "component-dependency" : { + "capability" : "component-node", + "node" : "activate-netconf-component", + "relationship" : "tosca.relationships.DependsOn" + } + }, + "interfaces" : { + "CONFIG" : { + "operations" : { + "ActivateNetconf" : { + "inputs" : { + "params" : [ ] + } + } + } + } + } + }, + "base-config-template" : { + "type" : "artifact-config-template", + "properties" : { + "action-names" : [ "resource-assignment-action" ] + }, + "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 + } ] + } + } + } + }, + "licence-template" : { + "type" : "artifact-config-template", + "properties" : { + "action-names" : [ "resource-assignment-action" ] + }, + "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 + } ] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/automap.json b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/automap.json new file mode 100644 index 000000000..a85e71550 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/automap.json @@ -0,0 +1,11 @@ +[ + { + "name": "action-name" + }, + { + "name": "v4-ip-type" + }, + { + "name": "bundle-id" + } +] \ No newline at end of file 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 new file mode 100644 index 000000000..2b392054d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json @@ -0,0 +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 +} \ No newline at end of file -- cgit 1.2.3-korg From a3c9519d6aa7eb8e1f450a7d041047f2c0a5cc07 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 17 Aug 2018 19:45:00 +0000 Subject: Controller Blueprints Microservice Restcontroller Swagger Implementation with Embeded jar for Controller Bluprints MS Change-Id: I0c0a33f0e29dad0d4aa703e3e381068b510e57d4 Issue-ID: CCSDK-468 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- ms/controllerblueprints/.gitignore | 1 + .../application/etc/logback.xml | 36 ++++ .../opt/app/onap/config/application.properties | 35 ---- .../application/opt/app/onap/config/logback.xml | 36 ---- ms/controllerblueprints/application/pom.xml | 5 - .../application/src/assembly/distribution.xml | 8 - .../ControllerBluprintsApplication.java | 8 +- .../ControllerBluprintsFilterConfiguration.java | 37 ---- .../apps/controllerblueprints/CorsConfig.java | 22 +- .../controllerblueprints/JerseyConfiguration.java | 102 --------- .../apps/controllerblueprints/SwaggerConfig.java | 70 +++++++ .../ccsdk/apps/controllerblueprints/WebConfig.java | 37 ++++ .../controllerblueprints/WebMvcConfiguration.java | 37 ---- .../ControllerBluprintsApplicationTest.java | 3 +- .../src/test/resources/application.properties | 45 ---- .../application/src/test/resources/logback.xml | 36 ++++ ms/controllerblueprints/modules/core/pom.xml | 58 ------ .../modules/resource-dict/pom.xml | 7 - ms/controllerblueprints/modules/service/pom.xml | 24 +-- .../service/common/ServiceExceptionMapper.java | 42 ---- .../service/common/SwaggerGenerator.java | 24 +-- .../service/rs/ConfigModelRest.java | 232 ++++++++------------- .../service/rs/ConfigModelRestImpl.java | 116 ----------- .../service/rs/ModelTypeRest.java | 147 +++++-------- .../service/rs/ModelTypeRestImpl.java | 87 -------- .../service/rs/ResourceDictionaryRest.java | 152 ++++++-------- .../service/rs/ResourceDictionaryRestImpl.java | 91 -------- .../service/rs/ServiceTemplateRest.java | 160 ++++++-------- .../service/rs/ServiceTemplateRestImpl.java | 94 --------- .../controllerblueprints/JerseyConfiguration.java | 69 ------ .../controllerblueprints/TestConfiguration.java | 36 ---- .../service/rs/ConfigModelRestTest.java | 4 +- .../service/rs/ModelTypeRestTest.java | 3 +- .../service/rs/ResourceDictionaryRestTest.java | 3 +- .../service/rs/ServiceTemplateRestTest.java | 3 +- ms/controllerblueprints/parent/pom.xml | 122 ++++++++--- 36 files changed, 580 insertions(+), 1412 deletions(-) create mode 100644 ms/controllerblueprints/application/etc/logback.xml delete mode 100644 ms/controllerblueprints/application/opt/app/onap/config/logback.xml delete mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsFilterConfiguration.java delete mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java create mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java create mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebConfig.java delete mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebMvcConfiguration.java create mode 100644 ms/controllerblueprints/application/src/test/resources/logback.xml delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/.gitignore b/ms/controllerblueprints/.gitignore index b808e8430..644e3b492 100644 --- a/ms/controllerblueprints/.gitignore +++ b/ms/controllerblueprints/.gitignore @@ -7,6 +7,7 @@ **/target-ide/* **/target/* **/logs/* +**/debug-logs/* **/tokens/* # Added for Intellij IDEA IDE diff --git a/ms/controllerblueprints/application/etc/logback.xml b/ms/controllerblueprints/application/etc/logback.xml new file mode 100644 index 000000000..44e9a8a11 --- /dev/null +++ b/ms/controllerblueprints/application/etc/logback.xml @@ -0,0 +1,36 @@ + + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n + + + + + + + + + + + + + + diff --git a/ms/controllerblueprints/application/opt/app/onap/config/application.properties b/ms/controllerblueprints/application/opt/app/onap/config/application.properties index 202017de7..9fa8e04cf 100644 --- a/ms/controllerblueprints/application/opt/app/onap/config/application.properties +++ b/ms/controllerblueprints/application/opt/app/onap/config/application.properties @@ -14,43 +14,8 @@ # limitations under the License. # -info.build.artifact=@project.artifactId@ -info.build.name=@project.name@ -info.build.description=@project.description@ -info.build.version=@project.version@ -info.build.groupId=@project.groupId@ -logging.level.root=info - -server.contextPath=/ -server.servlet-path=/ -spring.jersey.application-path=/api/controller-blueprints/v1 -server.routingPath=/api - -mots.application.acronym=MOTS_ID -platform.identifier=AJSC7_JERSEY -#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - #logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr($ threadId: {PID:- }){magenta} %clr(---){faint} %clr([ hostname: %X{hostname} serviceName: %X{serviceName} version: %X{version} transactionId: %X{transactionId} requestTimeStamp: %X{requestTimestamp} responseTimeStamp: %X{responseTimestamp} duration: %X{duration}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex -#The max number of active threads in this pool -server.tomcat.max-threads=200 -#The minimum number of threads always kept alive -server.tomcat.min-Spare-Threads=25 -#The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads -server.tomcat.max-idle-time=60000 - -#for changing the tomcat port... -#server.port=8081 - -#Servlet context parameters -server.context_parameters.p-name=value #context parameter with p-name as key and value as value. - -# make this true for AAF authentication and place cadi.properties into etc folder -aaf.enabled=false - -# set to true to enable version proxy -#ivp.enabled=false - logging.level.org.springframework.web=INFO logging.level.org.hibernate.SQL=warn logging.level.org.hibernate.type.descriptor.sql=debug diff --git a/ms/controllerblueprints/application/opt/app/onap/config/logback.xml b/ms/controllerblueprints/application/opt/app/onap/config/logback.xml deleted file mode 100644 index cdd20c8b1..000000000 --- a/ms/controllerblueprints/application/opt/app/onap/config/logback.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n - - - - - - - - - - - - - - diff --git a/ms/controllerblueprints/application/pom.xml b/ms/controllerblueprints/application/pom.xml index 18d9a9037..19fd9c72d 100644 --- a/ms/controllerblueprints/application/pom.xml +++ b/ms/controllerblueprints/application/pom.xml @@ -69,11 +69,6 @@ spring-boot-devtools true - - com.h2database - h2 - runtime - org.springframework.boot spring-boot-starter-test diff --git a/ms/controllerblueprints/application/src/assembly/distribution.xml b/ms/controllerblueprints/application/src/assembly/distribution.xml index adfb52d10..c58c20d78 100644 --- a/ms/controllerblueprints/application/src/assembly/distribution.xml +++ b/ms/controllerblueprints/application/src/assembly/distribution.xml @@ -27,14 +27,6 @@ /opt/app/onap/lib - org.slf4j:slf4j-log4j12 - javax.servlet:servlet-api - javax.servlet:javax.servlet-api - j2ee:j2ee - log4j:log4j - com.sun:j2ee - log4j:apache-log4j-extras - org.slf4j:slf4j-simple diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplication.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplication.java index 96d82e7e4..447e1966d 100644 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplication.java +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplication.java @@ -16,22 +16,26 @@ package org.onap.ccsdk.apps.controllerblueprints; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; +import org.springframework.web.reactive.config.EnableWebFlux; /** - * - * * @author Brinda Santh */ @SpringBootApplication +@EnableWebFlux @ComponentScan(basePackages = {"org.onap.ccsdk.apps.controllerblueprints"}) @EnableAutoConfiguration public class ControllerBluprintsApplication { + private static EELFLogger log = EELFManager.getInstance().getLogger(ControllerBluprintsApplication.class); public static void main(String[] args) { + log.info("****** Starting Controller Bluprints Application **************"); SpringApplication.run(ControllerBluprintsApplication.class, args); } diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsFilterConfiguration.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsFilterConfiguration.java deleted file mode 100644 index 6f4bfc988..000000000 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsFilterConfiguration.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; - - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -/** - * - * - * @author Brinda Santh - */ -@Configuration -public class ControllerBluprintsFilterConfiguration { - private static Logger log = LoggerFactory.getLogger(JerseyConfiguration.class); - - @Value("${server.routingPath:#{null}}") - private String routingPath; - - -} 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 0d9ab1623..5d682ed50 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 @@ -1,17 +1,17 @@ /* - * Copyright © 2017-2018 AT&T Intellectual Property. + * 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 + * 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 + * 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. + * 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; @@ -29,7 +29,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. diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java deleted file mode 100644 index a3b0faf0c..000000000 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java +++ /dev/null @@ -1,102 +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; - - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; -import io.swagger.jaxrs.listing.SwaggerSerializers; -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.servlet.ServletProperties; -import org.onap.ccsdk.apps.controllerblueprints.service.common.ServiceExceptionMapper; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ConfigModelRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ModelTypeRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ResourceDictionaryRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ServiceTemplateRestImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -import javax.ws.rs.core.MediaType; - -/** - * - * - * @author Brinda Santh - */ -@Component -public class JerseyConfiguration extends ResourceConfig { - private static Logger log = LoggerFactory.getLogger(JerseyConfiguration.class); - /** - * - */ - @Autowired - public JerseyConfiguration() { - register(ConfigModelRestImpl.class); - register(ModelTypeRestImpl.class); - register(ResourceDictionaryRestImpl.class); - register(ServiceTemplateRestImpl.class); - register(ServiceExceptionMapper.class); - property(ServletProperties.FILTER_FORWARD_ON_404, true); - configureSwagger(); - } - - /** - * - * @return ObjectMapper - */ - @Bean - @Primary - public ObjectMapper objectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); - objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); - objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); - return objectMapper; - } - - /** - * - */ - private void configureSwagger() { - register(ApiListingResource.class); - register(SwaggerSerializers.class); - BeanConfig beanConfig = new BeanConfig(); - beanConfig.setVersion("1.0.0"); - beanConfig.setSchemes(new String[]{"http", "https"}); - beanConfig.setBasePath("/api/controller-blueprints/v1"); - beanConfig.setTitle("Controller Blueprints API"); - beanConfig.setDescription("Controller BluePrints API"); - beanConfig.getSwagger().addConsumes(MediaType.APPLICATION_JSON); - beanConfig.getSwagger().addProduces(MediaType.APPLICATION_JSON); - beanConfig.setResourcePackage("org.onap.ccsdk.apps.controllerblueprints"); - beanConfig.setPrettyPrint(true); - beanConfig.setScan(true); - } - - -} \ No newline at end of file diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java new file mode 100644 index 000000000..5970bafde --- /dev/null +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.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; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * SwaggerConfig + * + * @author Brinda Santh 8/13/2018 + */ +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + private static final Set DEFAULT_PRODUCES_AND_CONSUMES = + new HashSet(Arrays.asList("application/json", + "application/xml")); + private static Logger log = LoggerFactory.getLogger(SwaggerConfig.class); + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build() + .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + return new ApiInfo( + "Controller Blueprints API", + "Controller blueprints API for VNF Self Service.", + "1.0.0", + "Terms of service", + new Contact("Brinda Santh", "www.onap.com", "brindasanth@onap.com"), + "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", Collections.emptyList()); + } + + +} diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebConfig.java new file mode 100644 index 000000000..1eba97cdc --- /dev/null +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebConfig.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; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.config.ResourceHandlerRegistry; +import org.springframework.web.reactive.config.WebFluxConfigurationSupport; + +/** + * WebConfig + * + * @author Brinda Santh 8/13/2018 + */ +@Configuration +public class WebConfig extends WebFluxConfigurationSupport { + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("swagger-ui.html") + .addResourceLocations("classpath:/META-INF/resources/"); + + registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + } +} diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebMvcConfiguration.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebMvcConfiguration.java deleted file mode 100644 index a690c056c..000000000 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebMvcConfiguration.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; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - -/** - * - * WebMvcConfiguration WebMvcConfiguration - * @author Brinda Santh - */ -@Configuration -@EnableWebMvc -public class WebMvcConfiguration extends WebMvcConfigurerAdapter { - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/swagger-ui/dist/"); - } - -} 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 4bdbde008..95639bd32 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 @@ -46,9 +46,8 @@ public class ControllerBluprintsApplicationTest { @Test public void testConfigModel() { - ResponseEntity entity = this.restTemplate - .getForEntity("/api/controller-blueprints/v1/service/configmodel/1", String.class); + .getForEntity("/api/v1/config-model/1", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } } diff --git a/ms/controllerblueprints/application/src/test/resources/application.properties b/ms/controllerblueprints/application/src/test/resources/application.properties index c6057e563..55ffeaf16 100644 --- a/ms/controllerblueprints/application/src/test/resources/application.properties +++ b/ms/controllerblueprints/application/src/test/resources/application.properties @@ -14,51 +14,6 @@ # limitations under the License. # -info.build.artifact=@project.artifactId@ -info.build.name=@project.name@ -info.build.description=@project.description@ -info.build.version=@project.version@ -info.build.groupId=@project.groupId@ -logging.level.root=info - -server.contextPath=/ -server.servlet-path=/ -spring.jersey.application-path=/api/controller-blueprints/v1 -server.routingPath=/api - -mots.application.acronym=MOTS_ID -platform.identifier=AJSC7_JERSEY -#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - -#logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr($ threadId: {PID:- }){magenta} %clr(---){faint} %clr([ hostname: %X{hostname} serviceName: %X{serviceName} version: %X{version} transactionId: %X{transactionId} requestTimeStamp: %X{requestTimestamp} responseTimeStamp: %X{responseTimestamp} duration: %X{duration}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex - -#The max number of active threads in this pool -server.tomcat.max-threads=200 -#The minimum number of threads always kept alive -server.tomcat.min-Spare-Threads=25 -#The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads -server.tomcat.max-idle-time=60000 - -#for changing the tomcat port... -#server.port=8081 - -#Servlet context parameters -server.context_parameters.p-name=value #context parameter with p-name as key and value as value. - -# make this true for AAF authentication and place cadi.properties into etc folder -aaf.enabled=false - -# set to true to enable version proxy -#ivp.enabled=false - -logging.level.org.springframework.web=INFO -logging.level.org.hibernate.SQL=warn -logging.level.org.hibernate.type.descriptor.sql=debug - -spring.jpa.properties.hibernate.show_sql=true -spring.jpa.properties.hibernate.use_sql_comments=true -spring.jpa.properties.hibernate.format_sql=true - #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 new file mode 100644 index 000000000..b9b97dc89 --- /dev/null +++ b/ms/controllerblueprints/application/src/test/resources/logback.xml @@ -0,0 +1,36 @@ + + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n + + + + + + + + + + + + + + diff --git a/ms/controllerblueprints/modules/core/pom.xml b/ms/controllerblueprints/modules/core/pom.xml index 0e88dd293..fc7581c8c 100644 --- a/ms/controllerblueprints/modules/core/pom.xml +++ b/ms/controllerblueprints/modules/core/pom.xml @@ -29,30 +29,6 @@ Controller Blueprints Core - - org.jetbrains.kotlin - kotlin-stdlib - - - org.jetbrains.kotlin - kotlin-reflect - - - com.fasterxml.jackson.module - jackson-module-kotlin - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-annotations - - - com.fasterxml.jackson.core - jackson-core - com.fasterxml.jackson.dataformat jackson-dataformat-xml @@ -65,44 +41,10 @@ com.fasterxml.jackson.module jackson-module-jsonSchema - - org.apache.commons - commons-lang3 - - - commons-collections - commons-collections - - - commons-io - commons-io - - - com.google.guava - guava - org.yaml snakeyaml - - com.jayway.jsonpath - json-path - - - junit - junit - test - - - org.jetbrains.kotlin - kotlin-test - test - - diff --git a/ms/controllerblueprints/modules/resource-dict/pom.xml b/ms/controllerblueprints/modules/resource-dict/pom.xml index a0d1be611..337f5512f 100644 --- a/ms/controllerblueprints/modules/resource-dict/pom.xml +++ b/ms/controllerblueprints/modules/resource-dict/pom.xml @@ -33,13 +33,6 @@ org.onap.ccsdk.apps controllerblueprints-core - - junit - junit - test - - - diff --git a/ms/controllerblueprints/modules/service/pom.xml b/ms/controllerblueprints/modules/service/pom.xml index 17738bf4b..b4b798e6e 100644 --- a/ms/controllerblueprints/modules/service/pom.xml +++ b/ms/controllerblueprints/modules/service/pom.xml @@ -36,37 +36,17 @@ org.onap.ccsdk.apps controllerblueprints-resource-dict - - org.apache.commons - commons-lang3 - - - commons-collections - commons-collections - - - commons-io - commons-io - org.apache.velocity velocity - - io.swagger - swagger-jersey2-jaxrs - - - org.json - json - org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webflux org.springframework.boot - spring-boot-starter-jersey + spring-boot-starter-web org.springframework.boot diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java deleted file mode 100644 index f223dccb2..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java +++ /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.service.common; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; -import java.io.PrintWriter; -import java.io.StringWriter; - -@Provider -public class ServiceExceptionMapper implements ExceptionMapper { - - @Override - public Response toResponse(BluePrintException ex) { - ErrorMessage errorMessage = new ErrorMessage(); - errorMessage.setCode(ex.getCode()); - errorMessage.setMessage(ex.getMessage()); - StringWriter errorStackTrace = new StringWriter(); - ex.printStackTrace(new PrintWriter(errorStackTrace)); - errorMessage.setDeveloperMessage(ex.toString()); - return Response.status(500).entity(errorMessage).type(MediaType.APPLICATION_JSON).build(); - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java index e90807633..81f7d7018 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java @@ -1,17 +1,17 @@ /* - * Copyright © 2017-2018 AT&T Intellectual Property. + * 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 + * 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 + * 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. + * 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.common; @@ -20,7 +20,6 @@ import io.swagger.models.*; import io.swagger.models.parameters.BodyParameter; import io.swagger.models.parameters.Parameter; import io.swagger.models.properties.*; -import io.swagger.util.Json; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.BooleanUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; @@ -63,8 +62,7 @@ public class SwaggerGenerator { swagger.setDefinitions(getDefinition()); - swaggerContent = Json.pretty(swagger); - return swaggerContent; + return swagger.toString(); } private Info getInfo() { 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 86c89bf90..94324a808 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 @@ -16,164 +16,112 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; -import io.swagger.annotations.*; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; import java.util.List; /** - * ConfigModelRest.java Purpose: Rest service controller for ConfigModelRest Management - * - * @author Brinda Santh - * @version 1.0 + * {@inheritDoc} */ -@Api -@Path("/service") -@Produces({MediaType.APPLICATION_JSON}) -public interface ConfigModelRest { +@RestController +@RequestMapping("/api/v1/config-model") +public class ConfigModelRest { - /** - * This is a getConfigModel rest service - * - * @param id - * @return ConfigModel - * @throws BluePrintException - */ - @GET - @Path("/configmodel/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - @RequestMapping(value = "/configmodel/{id}", method = RequestMethod.GET) - @ResponseBody ConfigModel getConfigModel(@ApiParam(required = true) @PathParam("id") Long id) - throws BluePrintException; - + private ConfigModelService configModelService; /** - * This is a saveConfigModel rest service - * - * @param configModel - * @return ConfigModel - * @throws BluePrintException + * This is a ConfigModelRest constructor. + * + * @param configModelService Config Model Service */ - @POST - @Path("/configmodel") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by Tags", response = ServiceTemplate.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel saveConfigModel(@ApiParam(required = true) ConfigModel configModel) - throws BluePrintException; + public ConfigModelRest(ConfigModelService configModelService) { + this.configModelService = configModelService; - /** - * This is a deleteConfigModel rest service - * - * @param id - * @throws BluePrintException - */ - @DELETE - @Path("/configmodel/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to delete ConfigModel.") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - void deleteConfigModel(@ApiParam(required = true) @PathParam("id") Long id) throws BluePrintException; + } - /** - * This is a getInitialConfigModel rest service - * - * @param name - * @return ConfigModel - * @throws BluePrintException - */ - @GET - @Path("/configmodelinitial/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to create default Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel getInitialConfigModel(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + @GetMapping(path = "/initial/{name}") + public @ResponseBody + ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException { + try { + return this.configModelService.getInitialConfigModel(name); + } catch (Exception e) { + throw new BluePrintException(2000, e.getMessage(), e); + } + } - /** - * This is a getCloneConfigModel rest service - * - * @param id - * @return ConfigModel - * @throws BluePrintException - */ - @GET - @Path("/configmodelclone/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to create default Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel getCloneConfigModel(@ApiParam(required = true) @PathParam("id") Long id) - throws BluePrintException; + @PostMapping(path = "/") + public @ResponseBody + ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException { + try { + return this.configModelService.saveConfigModel(configModel); + } catch (Exception e) { + throw new BluePrintException(2200, e.getMessage(), e); + } + } - /** - * This is a publishConfigModel rest service - * - * @param id - * @return ServiceTemplate - * @throws BluePrintException - */ - @GET - @Path("/configmodelpublish/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by Tags", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel publishConfigModel(@ApiParam(required = true) @PathParam("id") Long id) - throws BluePrintException; + @DeleteMapping(path = "/{id}") + public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { + try { + this.configModelService.deleteConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(4000, e.getMessage(), e); + } + } - /** - * This is a getConfigModelByNameAndVersion rest service - * - * @param name - * @param version - * @return ConfigModel - * @throws BluePrintException - */ - @GET - @Path("/configmodelbyname/{name}/version/{version}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel getConfigModelByNameAndVersion(@ApiParam(required = true) @PathParam("name") String name, - @ApiParam(required = true) @PathParam("version") String version) throws BluePrintException; + @GetMapping(path = "/publish/{id}") + public @ResponseBody + ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { + try { + return this.configModelService.publishConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2500, e.getMessage(), e); + } + } - /** - * This is a searchServiceModels rest service - * - * @param tags - * @return List - * @throws BluePrintException - */ - @GET - @Path("/configmodelsearch/{tags}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List searchConfigModels(@ApiParam(required = true) @PathParam("tags") String tags) - throws BluePrintException; + @GetMapping(path = "/{id}") + public @ResponseBody + ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { + try { + return this.configModelService.getConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2001, e.getMessage(), e); + } + } + + @GetMapping(path = "/by-name/{name}/version/{version}") + public @ResponseBody + ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name, + @PathVariable(value = "version") String version) throws BluePrintException { + try { + return this.configModelService.getConfigModelByNameAndVersion(name, version); + } catch (Exception e) { + throw new BluePrintException(2002, e.getMessage(), e); + } + } + + @GetMapping(path = "/search/{tags}") + public @ResponseBody + List searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException { + try { + return this.configModelService.searchConfigModels(tags); + } catch (Exception e) { + throw new BluePrintException(2003, e.getMessage(), e); + } + } + + @GetMapping(path = "/clone/{id}") + public @ResponseBody + ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { + try { + return this.configModelService.getCloneConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2004, e.getMessage(), e); + } + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java deleted file mode 100644 index a9abcd5ff..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java +++ /dev/null @@ -1,116 +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.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.Service; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Service -public class ConfigModelRestImpl implements ConfigModelRest { - - private ConfigModelService configModelService; - - /** - * This is a ConfigModelRestImpl constructor. - * - * @param configModelService Config Model Service - */ - public ConfigModelRestImpl(ConfigModelService configModelService) { - this.configModelService = configModelService; - - } - - @Override - public ConfigModel getInitialConfigModel(String name) throws BluePrintException { - try { - return this.configModelService.getInitialConfigModel(name); - } catch (Exception e) { - throw new BluePrintException(2000, e.getMessage(), e); - } - } - - @Override - public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { - try { - return this.configModelService.saveConfigModel(configModel); - } catch (Exception e) { - throw new BluePrintException(2200, e.getMessage(), e); - } - } - - @Override - public void deleteConfigModel(Long id) throws BluePrintException { - try { - this.configModelService.deleteConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(4000, e.getMessage(), e); - } - } - - @Override - public ConfigModel publishConfigModel(Long id) throws BluePrintException { - try { - return this.configModelService.publishConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2500, e.getMessage(), e); - } - } - - @Override - public ConfigModel getConfigModel(Long id) throws BluePrintException { - try { - return this.configModelService.getConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2001, e.getMessage(), e); - } - } - - @Override - public ConfigModel getConfigModelByNameAndVersion(String name, String version) throws BluePrintException { - try { - return this.configModelService.getConfigModelByNameAndVersion(name, version); - } catch (Exception e) { - throw new BluePrintException(2002, e.getMessage(), e); - } - } - - @Override - public List searchConfigModels(String tags) throws BluePrintException { - try { - return this.configModelService.searchConfigModels(tags); - } catch (Exception e) { - throw new BluePrintException(2003, e.getMessage(), e); - } - } - - @Override - public ConfigModel getCloneConfigModel(Long id) throws BluePrintException { - try { - return this.configModelService.getCloneConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2004, e.getMessage(), e); - } - } - -} 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 59b730309..2fa64316f 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 @@ -16,110 +16,77 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; -import io.swagger.annotations.*; 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.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; import java.util.List; /** - * ModelTypeRest.java Purpose: Rest service controller for Artifact Handling - * - * @author Brinda Santh - * @version 1.0 + * {@inheritDoc} */ -@Api -@Path("/service") -@Produces({MediaType.APPLICATION_JSON}) -public interface ModelTypeRest { +@RestController +@RequestMapping("/api/v1/model-type") +public class ModelTypeRest { - /** - * This is a getModelTypeByName rest service - * - * @param name - * @return ModelType - * @throws BluePrintException - */ - @GET - @Path("/modeltype/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by id", response = ModelType.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ModelType getModelTypeByName(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + private ModelTypeService modelTypeService; /** - * This is a saveModelType rest service - * - * @param modelType - * @return ModelType - * @throws BluePrintException + * This is a ModelTypeResourceImpl, used to save and get the model types stored in database + * + * @param modelTypeService Model Type Service */ + public ModelTypeRest(ModelTypeService modelTypeService) { + this.modelTypeService = modelTypeService; + } - @POST - @Path("/modeltype") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Save Model Type", response = ModelType.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ModelType saveModelType(@ApiParam(required = true) ModelType modelType) throws BluePrintException; + @GetMapping(path = "/{name}") + public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { + try { + return modelTypeService.getModelTypeByName(name); + } catch (Exception e) { + throw new BluePrintException(1000, e.getMessage(), e); + } + } - /** - * This is a deleteModelType rest service - * - * @param name - * @throws BluePrintException - */ - @DELETE - @Path("/modeltype/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to delete Model Type") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - void deleteModelTypeByName(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + @GetMapping(path = "/search/{tags}") + public List searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException { + try { + return modelTypeService.searchModelTypes(tags); + } catch (Exception e) { + throw new BluePrintException(1001, e.getMessage(), e); + } + } - /** - * This is a searchModelType rest service - * - * @param tags - * @return List - * @throws BluePrintException - */ - @GET - @Path("/modeltypesearch/{tags}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by tags", response = ModelType.class, - responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List searchModelTypes(@ApiParam(required = true) @PathParam("tags") String tags) - throws BluePrintException; + @GetMapping(path = "/by-definition/{definitionType}") + public @ResponseBody + List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException { + try { + return modelTypeService.getModelTypeByDefinitionType(definitionType); + } catch (Exception e) { + throw new BluePrintException(1002, e.getMessage(), e); + } + } - /** - * This is a getModelTypeByDefinitionType rest service - * - * @param definitionType - * @return List - * @throws BluePrintException - */ - @GET - @Path("/modeltypebydefinition/{definitionType}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by tags", response = ModelType.class, - responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List getModelTypeByDefinitionType( - @ApiParam(required = true) @PathParam("definitionType") String definitionType) - throws BluePrintException; + @PostMapping(path = "/") + public @ResponseBody + ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { + try { + return modelTypeService.saveModel(modelType); + } catch (Exception e) { + throw new BluePrintException(1100, e.getMessage(), e); + } + } + @DeleteMapping(path = "/{name}") + public void deleteModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { + try { + modelTypeService.deleteByModelName(name); + } catch (Exception e) { + throw new BluePrintException(1400, e.getMessage(), e); + } + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java deleted file mode 100644 index 6fbc69699..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java +++ /dev/null @@ -1,87 +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.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.stereotype.Service; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Service -public class ModelTypeRestImpl implements ModelTypeRest { - - private ModelTypeService modelTypeService; - - /** - * This is a ModelTypeResourceImpl, used to save and get the model types stored in database - * - * @param modelTypeService Model Type Service - */ - public ModelTypeRestImpl(ModelTypeService modelTypeService) { - this.modelTypeService = modelTypeService; - } - - @Override - public ModelType getModelTypeByName(String modelName) throws BluePrintException { - try { - return modelTypeService.getModelTypeByName(modelName); - } catch (Exception e) { - throw new BluePrintException(1000, e.getMessage(), e); - } - } - - @Override - public List searchModelTypes(String tags) throws BluePrintException { - try { - return modelTypeService.searchModelTypes(tags); - } catch (Exception e) { - throw new BluePrintException(1001, e.getMessage(), e); - } - } - - @Override - public List getModelTypeByDefinitionType(String definitionType) throws BluePrintException { - try { - return modelTypeService.getModelTypeByDefinitionType(definitionType); - } catch (Exception e) { - throw new BluePrintException(1002, e.getMessage(), e); - } - } - - @Override - public ModelType saveModelType(ModelType modelType) throws BluePrintException { - try { - return modelTypeService.saveModel(modelType); - } catch (Exception e) { - throw new BluePrintException(1100, e.getMessage(), e); - } - } - - @Override - public void deleteModelTypeByName(String name) throws BluePrintException { - try { - modelTypeService.deleteByModelName(name); - } catch (Exception e) { - throw new BluePrintException(1400, e.getMessage(), e); - } - } -} 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 5bc983363..dfb06bba5 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 @@ -16,111 +16,83 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; -import io.swagger.annotations.*; 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.web.bind.annotation.*; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; import java.util.List; /** - * ResourceDictionaryRest.java Purpose: Rest service controller for Artifact Handling - * - * @author Brinda Santh - * @version 1.0 + * {@inheritDoc} */ -@Api -@Path("/service") -@Produces({MediaType.APPLICATION_JSON}) +@RestController +@RequestMapping(value = "/api/v1/dictionary") +public class ResourceDictionaryRest { -public interface ResourceDictionaryRest { - /** - * This is a getDataDictionaryByPath rest service - * - * @param name - * @return ResourceDictionary - * @throws BluePrintException - */ - @GET - @Path("/dictionary/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Resource dictionary", response = ResourceDictionary.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ResourceDictionary getResourceDictionaryByName(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + private ResourceDictionaryService resourceDictionaryService; /** - * This is a saveDataDictionary rest service - * - * @param resourceMapping - * @return ResourceDictionary - * @throws BluePrintException + * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database + * + * @param dataDictionaryService Data Dictionary Service */ + public ResourceDictionaryRest(ResourceDictionaryService dataDictionaryService) { + this.resourceDictionaryService = dataDictionaryService; + } - @POST - @Path("/dictionary") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Save Resource dictionary Type", response = ResourceDictionary.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ResourceDictionary saveResourceDictionary(@ApiParam(required = true) ResourceDictionary resourceMapping) - throws BluePrintException; + @PostMapping(path = "/") + public @ResponseBody + ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) + throws BluePrintException { + try { + return resourceDictionaryService.saveResourceDictionary(dataDictionary); + } catch (Exception e) { + throw new BluePrintException(4100, e.getMessage(), e); + } + } - /** - * This is a deleteDataDictionaryByName rest service - * - * @param name - * @throws BluePrintException - */ - @DELETE - @Path("/dictionary/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to delete ResourceDictionary Type") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - void deleteResourceDictionaryByName(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + @DeleteMapping(path = "/{name}") + public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { + try { + resourceDictionaryService.deleteResourceDictionary(name); + } catch (Exception e) { + throw new BluePrintException(4400, e.getMessage(), e); + } + } - /** - * This is a searchResourceDictionaryByTags rest service - * - * @param tags - * @return ResourceDictionary - * @throws BluePrintException - */ - @GET - @Path("/dictionarysearch/{tags}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to search Resource dictionary by tags", - response = ResourceDictionary.class, responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List searchResourceDictionaryByTags( - @ApiParam(required = true) @PathParam("tags") String tags) throws BluePrintException; + @GetMapping(path = "/{name}") + public @ResponseBody + ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { + try { + return resourceDictionaryService.getResourceDictionaryByName(name); + } catch (Exception e) { + throw new BluePrintException(4001, e.getMessage(), e); + } + } - /** - * This is a searchResourceDictionaryByNames rest service - * - * @param names - * @return List - * @throws BluePrintException - */ - @POST - @Path("/dictionarybynames") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get ResourceDictionary Type by names", - response = ResourceDictionary.class, responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List searchResourceDictionaryByNames(@ApiParam(required = true) List names) - throws BluePrintException; + @PostMapping(path = "/by-names") + public @ResponseBody + List searchResourceDictionaryByNames(@RequestBody List names) + throws BluePrintException { + try { + return resourceDictionaryService.searchResourceDictionaryByNames(names); + } catch (Exception e) { + throw new BluePrintException(4002, e.getMessage(), e); + } + } + + @GetMapping(path = "/search/{tags}") + public @ResponseBody + List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) throws BluePrintException { + try { + return resourceDictionaryService.searchResourceDictionaryByTags(tags); + } catch (Exception e) { + throw new BluePrintException(4003, e.getMessage(), e); + } + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java deleted file mode 100644 index e3448424d..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java +++ /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.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.Service; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Service -public class ResourceDictionaryRestImpl implements ResourceDictionaryRest { - - - private ResourceDictionaryService resourceDictionaryService; - - /** - * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database - * - * @param dataDictionaryService Data Dictionary Service - */ - public ResourceDictionaryRestImpl(ResourceDictionaryService dataDictionaryService) { - this.resourceDictionaryService = dataDictionaryService; - } - - @Override - public ResourceDictionary saveResourceDictionary(ResourceDictionary dataDictionary) - throws BluePrintException { - try { - return resourceDictionaryService.saveResourceDictionary(dataDictionary); - } catch (Exception e) { - throw new BluePrintException(4100, e.getMessage(), e); - } - } - - @Override - public void deleteResourceDictionaryByName(String name) throws BluePrintException { - try { - resourceDictionaryService.deleteResourceDictionary(name); - } catch (Exception e) { - throw new BluePrintException(4400, e.getMessage(), e); - } - } - - @Override - public ResourceDictionary getResourceDictionaryByName(String resourcePath) throws BluePrintException { - try { - return resourceDictionaryService.getResourceDictionaryByName(resourcePath); - } catch (Exception e) { - throw new BluePrintException(4001, e.getMessage(), e); - } - } - - @Override - public List searchResourceDictionaryByNames(List names) - throws BluePrintException { - try { - return resourceDictionaryService.searchResourceDictionaryByNames(names); - } catch (Exception e) { - throw new BluePrintException(4002, e.getMessage(), e); - } - } - - @Override - public List searchResourceDictionaryByTags(String tags) throws BluePrintException { - try { - return resourceDictionaryService.searchResourceDictionaryByTags(tags); - } catch (Exception e) { - throw new BluePrintException(4003, e.getMessage(), e); - } - } - -} 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 fcb8f3119..d8ea1941b 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 @@ -16,119 +16,87 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; -import io.swagger.annotations.*; + 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.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.web.bind.annotation.*; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; import java.util.List; - /** - * ServiceTemplateRest.java Purpose: ServiceTemplateRest interface - * - * @author Brinda Santh - * @version 1.0 + * {@inheritDoc} */ +@RestController +@RequestMapping(value = "/api/v1/service-template") +public class ServiceTemplateRest { -@Api -@Path("/service") -@Produces({MediaType.APPLICATION_JSON}) -public interface ServiceTemplateRest { + private ServiceTemplateService serviceTemplateService; /** - * This is a enrichServiceTemplate rest service - * - * @param serviceTemplate - * @return ServiceTemplate - * @throws BluePrintException + * This is a ServiceTemplateRest constructor + * + * @param serviceTemplateService Service Template Service */ - @POST - @Path("/servicetemplate/enrich") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to enrich service template", response = ServiceTemplate.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ServiceTemplate enrichServiceTemplate(@ApiParam(required = true) ServiceTemplate serviceTemplate) - throws BluePrintException; + public ServiceTemplateRest(ServiceTemplateService serviceTemplateService) { + this.serviceTemplateService = serviceTemplateService; + } - /** - * This is a validateServiceTemplate rest service - * - * @param serviceTemplate - * @return ServiceTemplate - * @throws BluePrintException - */ - @POST - @Path("/servicetemplate/validate") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to validate service template", response = ServiceTemplate.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ServiceTemplate validateServiceTemplate(@ApiParam(required = true) ServiceTemplate serviceTemplate) - throws BluePrintException; + @PostMapping(path = "/enrich") + public @ResponseBody + ServiceTemplate enrichServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { + try { + return serviceTemplateService.enrichServiceTemplate(serviceTemplate); + } catch (Exception e) { + throw new BluePrintException(3500, e.getMessage(), e); + } + } - /** - * This is a generateResourceAssignments rest service - * - * @param templateContent - * @return List - * @throws BluePrintException - */ - @POST - @Path("/resourceassignment/generate") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to auto map for the Resource Mapping", - response = ResourceAssignment.class, responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List generateResourceAssignments( - @ApiParam(required = true) ConfigModelContent templateContent) throws BluePrintException; + @PostMapping(path = "/validate") + public @ResponseBody + ServiceTemplate validateServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { + try { + return serviceTemplateService.validateServiceTemplate(serviceTemplate); + } catch (Exception e) { + throw new BluePrintException(3501, e.getMessage(), e); + } + } - /** - * This is a autoMap rest service - * - * @param resourceAssignments - * @return AutoMapResponse - * @throws BluePrintException - */ - @POST - @Path("/resourceassignment/automap") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to auto map for the Resource assignments", - response = AutoMapResponse.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - AutoMapResponse autoMap(@ApiParam(required = true) List resourceAssignments) - throws BluePrintException; + @PostMapping(path = "/resource-assignment/auto-map") + public @ResponseBody + AutoMapResponse autoMap(@RequestBody List resourceAssignments) throws BluePrintException { + try { + return serviceTemplateService.autoMap(resourceAssignments); + } catch (Exception e) { + throw new BluePrintException(3502, e.getMessage(), e); + } + } - /** - * This is a validateResourceAssignments rest service - * - * @param resourceAssignments - * @return List - * @throws BluePrintException - */ - @POST - @Path("/resourceassignment/validate") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to validate Resource assignments", response = ResourceAssignment.class, - responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List validateResourceAssignments( - @ApiParam(required = true) List resourceAssignments) throws BluePrintException; + @PostMapping(path = "/resource-assignment/validate") + public @ResponseBody + List validateResourceAssignments(@RequestBody List resourceAssignments) + throws BluePrintException { + try { + return serviceTemplateService.validateResourceAssignments(resourceAssignments); + } catch (Exception e) { + throw new BluePrintException(3503, e.getMessage(), e); + } + } + + @PostMapping(path = "/resource-assignment/generate") + public @ResponseBody + List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) + throws BluePrintException { + try { + return serviceTemplateService.generateResourceAssignments(templateContent); + } catch (Exception e) { + throw new BluePrintException(3504, e.getMessage(), e); + } + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java deleted file mode 100644 index 6c49d5c65..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java +++ /dev/null @@ -1,94 +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.rs; - - -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.service.ServiceTemplateService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Service -public class ServiceTemplateRestImpl implements ServiceTemplateRest { - - private ServiceTemplateService serviceTemplateService; - - /** - * This is a ServiceTemplateRestImpl constructor - * - * @param serviceTemplateService Service Template Service - */ - public ServiceTemplateRestImpl(ServiceTemplateService serviceTemplateService) { - this.serviceTemplateService = serviceTemplateService; - } - - @Override - public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - try { - return serviceTemplateService.enrichServiceTemplate(serviceTemplate); - } catch (Exception e) { - throw new BluePrintException(3500, e.getMessage(), e); - } - } - - @Override - public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - try { - return serviceTemplateService.validateServiceTemplate(serviceTemplate); - } catch (Exception e) { - throw new BluePrintException(3501, e.getMessage(), e); - } - } - - @Override - public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { - try { - return serviceTemplateService.autoMap(resourceAssignments); - } catch (Exception e) { - throw new BluePrintException(3502, e.getMessage(), e); - } - } - - @Override - public List validateResourceAssignments(List resourceAssignments) - throws BluePrintException { - try { - return serviceTemplateService.validateResourceAssignments(resourceAssignments); - } catch (Exception e) { - throw new BluePrintException(3503, e.getMessage(), e); - } - } - - @Override - public List generateResourceAssignments(ConfigModelContent templateContent) - throws BluePrintException { - try { - return serviceTemplateService.generateResourceAssignments(templateContent); - } catch (Exception e) { - throw new BluePrintException(3504, e.getMessage(), e); - } - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java deleted file mode 100644 index f5535eb12..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java +++ /dev/null @@ -1,69 +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; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import org.glassfish.jersey.logging.LoggingFeature; -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.servlet.ServletProperties; -import org.onap.ccsdk.apps.controllerblueprints.service.common.ServiceExceptionMapper; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ConfigModelRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ModelTypeRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ResourceDictionaryRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ServiceTemplateRestImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -import java.util.logging.Logger; - - -@Component -public class JerseyConfiguration extends ResourceConfig { - private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName()); - - @Bean - @Primary - public ObjectMapper objectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); - objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); - objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); - return objectMapper; - } - - @Autowired - public JerseyConfiguration() { - register(ConfigModelRestImpl.class); - register(ModelTypeRestImpl.class); - register(ResourceDictionaryRestImpl.class); - register(ServiceTemplateRestImpl.class); - // Exception Mapping - register(ServiceExceptionMapper.class); - property(ServletProperties.FILTER_FORWARD_ON_404, true); - register(new LoggingFeature(log)); - } - - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java deleted file mode 100644 index ea259c9c9..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.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; - -import org.springframework.context.annotation.Bean; - -import java.util.ArrayList; - -//@Configuration -public class TestConfiguration { - - @Bean("jaxrsProviders") - public ArrayList provider() { - return new ArrayList(); - } - - @Bean("jaxrsServices") - public ArrayList service() { - return new ArrayList(); - } - -} 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 5b10a7e86..a4a787b08 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 @@ -20,7 +20,6 @@ import org.junit.*; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.TestConfiguration; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; import org.slf4j.Logger; @@ -35,7 +34,7 @@ import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@ContextConfiguration(classes = {TestApplication.class}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ConfigModelRestTest { @@ -68,7 +67,6 @@ public class ConfigModelRestTest { ConfigModel configModel = configModelRest.getInitialConfigModel(name); Assert.assertNotNull("Failed to get Initial Config Model , Return object is Null", configModel); Assert.assertNotNull("Failed to get Service Template Content ", configModel.getConfigModelContents()); - } 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 d33349c53..d328b3eac 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 @@ -21,7 +21,6 @@ import org.junit.*; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.TestConfiguration; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import org.slf4j.Logger; @@ -38,7 +37,7 @@ import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@ContextConfiguration(classes = {TestApplication.class}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ModelTypeRestTest { private static Logger log = LoggerFactory.getLogger(ModelTypeRestTest.class); 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 71dff338b..afe9b426f 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,7 +24,6 @@ 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.TestConfiguration; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +40,7 @@ import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@ContextConfiguration(classes = {TestApplication.class}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResourceDictionaryRestTest { 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 f81dd4165..fdc68e4e5 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 @@ -24,7 +24,6 @@ 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.TestConfiguration; import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; @@ -46,7 +45,7 @@ import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@ContextConfiguration(classes = {TestApplication.class}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ServiceTemplateRestTest { diff --git a/ms/controllerblueprints/parent/pom.xml b/ms/controllerblueprints/parent/pom.xml index 0b19186d5..f8977d1f3 100644 --- a/ms/controllerblueprints/parent/pom.xml +++ b/ms/controllerblueprints/parent/pom.xml @@ -27,17 +27,19 @@ pom UTF-8 + UTF-8 1.8 1.8 - 1.2.51 - 200.4.2-RELEASE - 2.4.2-RELEASE - 1.4.2 - 1.5.7.RELEASE - 20.0.1-SNAPSHOT + 1.8 + 2.0.4.RELEASE + 1.2.60 + 1.0.0 + 2.9.2 + 1.4.197 + org.springframework.boot spring-boot-dependencies @@ -46,6 +48,24 @@ import + + com.att.eelf + eelf-core + ${eelf.version} + + + + + io.springfox + springfox-swagger2 + ${springfox.swagger2.version} + + + io.springfox + springfox-swagger-ui + ${springfox.swagger2.version} + + org.apache.commons commons-lang3 @@ -66,33 +86,12 @@ velocity 1.7 - - org.json - json - 20180130 - com.google.guava guava 25.1-jre - - io.swagger - swagger-jersey2-jaxrs - 1.5.20 - - - org.glassfish.jersey.containers - * - - - org.glassfish.jersey.core - * - - - - org.jetbrains.kotlin @@ -105,9 +104,17 @@ ${kotlin.version} - com.fasterxml.jackson.module - jackson-module-kotlin - 2.9.6 + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + + + + com.h2database + h2 + ${h2database.version} org.jetbrains.kotlin @@ -134,10 +141,65 @@ + + com.att.eelf + eelf-core + + + org.apache.commons + commons-lang3 + 3.2.1 + + + commons-collections + commons-collections + 3.2.2 + + + commons-io + commons-io + 2.6 + + + com.jayway.jsonpath + json-path + + + io.springfox + springfox-swagger2 + + + io.springfox + springfox-swagger-ui + org.jetbrains.kotlin kotlin-stdlib + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + junit + junit + test + + + org.jetbrains.kotlin + kotlin-test + test + + + io.projectreactor + reactor-test + test + -- 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/service/src/test') 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 00bffa6a864d04e7093b6d70a9d321c068d48c7a Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 23 Aug 2018 17:33:38 +0000 Subject: Controller Blueprints Microservice Implement Controller Blueprint Meta File format and Meta names such as template_name, template_version, template_author Change-Id: Id221bb9cb0f9e382e3d59d4e309002de1ceb112b Issue-ID: CCSDK-458 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../core/service/BluePrintValidatorService.kt | 43 +++++++++-------- .../blueprints/vrr-test/Definitions/vrr-test.json | 1 + .../validator/ServiceTemplateValidator.java | 13 +---- .../service/common/SchemaGeneratorServiceTest.java | 2 +- .../common/ServiceTemplateValidationTest.java | 56 ---------------------- .../validator/ServiceTemplateValidationTest.java | 51 ++++++++++++++++++++ .../test/resources/enhance/enhance-template.json | 1 + .../test/resources/enhance/enhanced-template.json | 1 + 8 files changed, 81 insertions(+), 87 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java (limited to 'ms/controllerblueprints/modules/service/src/test') 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 index 2383a6520..973e3de17 100644 --- 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 @@ -47,7 +47,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { lateinit var serviceTemplate: ServiceTemplate lateinit var properties: MutableMap var message: StringBuilder = StringBuilder() - val seperator: String = "/" + private val separator: String = BluePrintConstants.PATH_DIVIDER var paths: MutableList = arrayListOf() @Throws(BluePrintException::class) @@ -68,22 +68,27 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { serviceTemplate.nodeTypes?.let { validateNodeTypes(serviceTemplate.nodeTypes!!) } serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) } } catch (e: Exception) { - logger.error("validation failed in the path : {}", paths.joinToString(seperator), e) + logger.error("validation failed in the path : {}", paths.joinToString(separator), e) logger.error("validation trace message :{} ", message) throw BluePrintException(e, format("failed to validate blueprint on path ({}) with message {}" - , paths.joinToString(seperator), e.message)) + , paths.joinToString(separator), e.message)) } } @Throws(BluePrintException::class) open fun validateMetadata(metaDataMap: MutableMap) { paths.add("metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME]), "failed to get template name metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION]), "failed to get template version metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS]), "failed to get template tags metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]), "failed to get template author metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_USER_GROUPS]), "failed to get user groups 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) } @@ -92,7 +97,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { paths.add("artifact_types") artifactTypes.forEach { artifactName, artifactType -> paths.add(artifactName) - message.appendln("--> Artifact Type :" + paths.joinToString(seperator)) + message.appendln("--> Artifact Type :" + paths.joinToString(separator)) artifactType.properties?.let { validatePropertyDefinitions(artifactType.properties!!) } paths.removeAt(paths.lastIndex) } @@ -104,7 +109,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { paths.add("dataTypes") dataTypes.forEach { dataTypeName, dataType -> paths.add(dataTypeName) - message.appendln("--> Data Type :" + paths.joinToString(seperator)) + message.appendln("--> Data Type :" + paths.joinToString(separator)) dataType.properties?.let { validatePropertyDefinitions(dataType.properties!!) } paths.removeAt(paths.lastIndex) } @@ -124,7 +129,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { @Throws(BluePrintException::class) open fun validateNodeType(nodeTypeName: String, nodeType: NodeType) { paths.add(nodeTypeName) - message.appendln("--> Node Type :" + paths.joinToString(seperator)) + message.appendln("--> Node Type :" + paths.joinToString(separator)) val derivedFrom: String = nodeType.derivedFrom //Check Derived From checkValidNodeTypesDerivedFrom(derivedFrom) @@ -147,7 +152,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { @Throws(BluePrintException::class) open fun validateInputs(inputs: MutableMap) { paths.add("inputs") - message.appendln("---> Input :" + paths.joinToString(seperator)) + message.appendln("---> Input :" + paths.joinToString(separator)) validatePropertyDefinitions(inputs) paths.removeAt(paths.lastIndex) } @@ -164,7 +169,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { @Throws(BluePrintException::class) open fun validateNodeTemplate(nodeTemplateName : String, nodeTemplate: NodeTemplate) { paths.add(nodeTemplateName) - message.appendln("---> Node Template :" + paths.joinToString(seperator)) + message.appendln("---> Node Template :" + paths.joinToString(separator)) val type: String = nodeTemplate.type val nodeType: NodeType = serviceTemplate.nodeTypes?.get(type) @@ -192,12 +197,12 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { @Throws(BluePrintException::class) open fun validateWorkFlow(workflowName:String, workflow: Workflow) { paths.add(workflowName) - message.appendln("---> Workflow :" + paths.joinToString(seperator)) + 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(seperator)) + message.appendln("----> Steps :" + paths.joinToString(separator)) paths.removeAt(paths.lastIndex) } paths.removeAt(paths.lastIndex) @@ -220,7 +225,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { } else { checkPropertyDataType(dataType, propertyName) } - message.appendln("property " + paths.joinToString(seperator) + " of type " + dataType) + message.appendln("property " + paths.joinToString(separator) + " of type " + dataType) paths.removeAt(paths.lastIndex) } paths.removeAt(paths.lastIndex) @@ -245,7 +250,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { paths.add("artifacts") artifacts.forEach { artifactName, artifactDefinition -> paths.add(artifactName) - message.appendln("Validating artifact " + paths.joinToString(seperator)) + message.appendln("Validating artifact " + paths.joinToString(separator)) val type: String = artifactDefinition.type ?: throw BluePrintException("type is missing for artifact definition :" + artifactName) // Check Artifact Type @@ -279,7 +284,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { paths.add("interfaces") interfaces.forEach { interfaceName, interfaceDefinition -> paths.add(interfaceName) - message.appendln("Validating : " + paths.joinToString(seperator)) + message.appendln("Validating : " + paths.joinToString(separator)) interfaceDefinition.operations?.let { validateOperationDefinitions(interfaceDefinition.operations!!) } paths.removeAt(paths.lastIndex) } @@ -291,7 +296,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { paths.add("operations") operations.forEach { opertaionName, operationDefinition -> paths.add(opertaionName) - message.appendln("Validating : " + paths.joinToString(seperator)) + message.appendln("Validating : " + paths.joinToString(separator)) operationDefinition.implementation?.let { validateImplementation(operationDefinition.implementation!!) } operationDefinition.inputs?.let { validatePropertyDefinitions(operationDefinition.inputs!!) } operationDefinition.outputs?.let { validatePropertyDefinitions(operationDefinition.outputs!!) } diff --git a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json index 626329ac8..d71dd2011 100644 --- a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json +++ b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json @@ -3,6 +3,7 @@ "template_author": "Brinda Santh ( bs2796@onap.com )", "template_name": "vrr-test", "template_version": "1.0.0", + "template_tags" : "brinda, VRR", "release": "201802", "service-type": "AVPN", "vnf-type": "VRR" 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 ea46f3ad3..430401bc3 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 @@ -77,7 +77,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /** * This is a getMetaData to get the key information during the * - * @return Map */ public Map getMetaData() { @@ -88,18 +88,9 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { 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()); - - String author = serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR); - String serviceTemplateName = - serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_NAME); - String serviceTemplateVersion = - serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_VERSION); - - Preconditions.checkArgument(StringUtils.isNotBlank(author), "Template Metadata (author) Information is missing."); - Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateName), "Template Metadata (service-template-name) Information is missing."); - Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateVersion), "Template Metadata (service-template-version) Information 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 50e94df9e..f846e9a11 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 @@ -32,7 +32,7 @@ import java.nio.charset.Charset; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class SchemaGeneratorServiceTest { - private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class); + private static Logger log = LoggerFactory.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/common/ServiceTemplateValidationTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java deleted file mode 100644 index af309e217..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java +++ /dev/null @@ -1,56 +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.common; - - -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.validator.ServiceTemplateValidator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.charset.Charset; -import java.util.List; - -public class ServiceTemplateValidationTest { - private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class); - - @Test - public void testBluePrintDirs(){ - List dirs = ConfigModelUtils.getBlueprintNames("load/blueprints"); - Assert.assertNotNull("Failed to get blueprint directories", dirs ); - Assert.assertEquals("Failed to get actual directories",2, dirs.size() ); - } - - // @Test - public void validateServiceTemplate() { - try { - String file = "load/service_template/vrr-201806-test/service-template.json"; - String serviceTemplateContent = - IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader().getResourceAsStream(file), - Charset.defaultCharset()); - ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); - serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); - log.info("Validated Service Template " + serviceTemplateValidator.getMetaData()); - - } catch (Exception e) { - e.printStackTrace(); - } - } -} 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 new file mode 100644 index 000000000..557c6dd8d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java @@ -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.service.validator; + + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.List; + +public class ServiceTemplateValidationTest { + private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class); + + @Test + public void testBluePrintDirs() { + List dirs = ConfigModelUtils.getBlueprintNames("load/blueprints"); + Assert.assertNotNull("Failed to get blueprint directories", dirs); + Assert.assertEquals("Failed to get actual directories", 2, dirs.size()); + } + + @Test + public void validateServiceTemplate() throws Exception { + String file = "load/blueprints/baseconfiguration/Definitions/activation-blueprint.json"; + String serviceTemplateContent = + FileUtils.readFileToString(new File(file), 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 8b4fd9d3a..a4ba930e5 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 @@ -3,6 +3,7 @@ "template_author": "Brinda Santh", "template_name": "enhance-template", "template_version": "1.0.0", + "template_tags": "brinda, VPE", "service-type": "Sample Service", "release": "1806", "vnf-type": "VPE" 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 18f499250..e00330961 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 @@ -3,6 +3,7 @@ "template_author" : "Brinda Santh", "template_name" : "enhance-template", "template_version" : "1.0.0", + "template_tags" : "brinda, VPE", "service-type" : "Sample Service", "release" : "1806", "vnf-type" : "VPE" -- 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/service/src/test') 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 71778e1656729e8e153d844275b2de96d30febca Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 27 Aug 2018 17:29:51 +0000 Subject: Controller Blueprints Microservice Optimise model type repository search for DB and file in blueprint repo service. Change-Id: If5458e218b723d3fff451789a73a667dd75bc91c Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../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 ++ .../ApplicationExceptionHandler.java | 5 ++ ms/controllerblueprints/modules/core/pom.xml | 4 + .../core/service/BluePrintEnhancerService.kt | 6 +- .../core/service/BluePrintRepoService.kt | 71 ++++++++++------ .../core/service/BluePrintRepoFileServiceTest.kt | 8 ++ .../resource/dict/data/ResourceSource.java | 2 +- .../service/ResourceDictionaryValidationService.kt | 3 +- .../load/resource_dictionary/input-source.json | 2 +- .../load/resource_dictionary/v4-ip-type.json | 2 +- .../service/BluePrintRepoDBService.java | 63 +++++++------- .../service/ResourceDictionaryService.java | 96 ++++++++++------------ .../resourcedictionary/default_definition.json | 4 +- 17 files changed, 291 insertions(+), 121 deletions(-) create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/source-db.json create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/source-default.json create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/source-input.json create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/source-rest.json create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.ResourceSource.json (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/model_type/node_type/source-db.json b/ms/controllerblueprints/application/load/model_type/node_type/source-db.json new file mode 100644 index 000000000..661a9503b --- /dev/null +++ b/ms/controllerblueprints/application/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/application/load/model_type/node_type/source-default.json b/ms/controllerblueprints/application/load/model_type/node_type/source-default.json new file mode 100644 index 000000000..13e234e1b --- /dev/null +++ b/ms/controllerblueprints/application/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/application/load/model_type/node_type/source-input.json b/ms/controllerblueprints/application/load/model_type/node_type/source-input.json new file mode 100644 index 000000000..126ea30bd --- /dev/null +++ b/ms/controllerblueprints/application/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/application/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/application/load/model_type/node_type/source-rest.json new file mode 100644 index 000000000..f8dd8b6fc --- /dev/null +++ b/ms/controllerblueprints/application/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/application/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.ResourceSource.json new file mode 100644 index 000000000..2ef553e24 --- /dev/null +++ b/ms/controllerblueprints/application/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/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 index d02be5c26..d9380a2f8 100644 --- 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 @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints; +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.service.common.ErrorMessage; import org.springframework.http.HttpStatus; @@ -28,14 +30,17 @@ import org.springframework.web.context.request.WebRequest; @ControllerAdvice @RestController public class ApplicationExceptionHandler { + private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationExceptionHandler.class); @ExceptionHandler(Exception.class) public final ResponseEntity handleAllExceptions(Exception ex, WebRequest request) { + log.error("Application Exception", ex); 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) { + log.error("Application Blueprint Exception", ex); ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), ex.getCode(), ex.getLocalizedMessage()); return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); } diff --git a/ms/controllerblueprints/modules/core/pom.xml b/ms/controllerblueprints/modules/core/pom.xml index 51b3af357..ba38de63c 100644 --- a/ms/controllerblueprints/modules/core/pom.xml +++ b/ms/controllerblueprints/modules/core/pom.xml @@ -43,6 +43,10 @@ com.fasterxml.jackson.module jackson-module-jsonSchema + + io.projectreactor + reactor-core + org.yaml snakeyaml 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 64fc57fcd..8bc0e6e0c 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 @@ -217,21 +217,21 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe } open fun populateNodeType(nodeTypeName: String): NodeType { - val nodeType = bluePrintRepoService.getNodeType(nodeTypeName) + 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) + 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) + 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/BluePrintRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt index a529a85f8..8c4446183 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,11 +17,16 @@ 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 org.slf4j.Logger +import org.slf4j.LoggerFactory +import reactor.core.publisher.Mono import java.io.File import java.io.Serializable import java.nio.charset.Charset @@ -35,25 +40,27 @@ import java.nio.charset.Charset interface BluePrintRepoService : Serializable { @Throws(BluePrintException::class) - fun getNodeType(nodeTypeName: String): NodeType? + fun getNodeType(nodeTypeName: String): Mono? @Throws(BluePrintException::class) - fun getDataType(dataTypeName: String): DataType? + fun getDataType(dataTypeName: String): Mono? @Throws(BluePrintException::class) - fun getArtifactType(artifactTypeName: String): ArtifactType? + fun getArtifactType(artifactTypeName: String): Mono? @Throws(BluePrintException::class) - fun getRelationshipType(relationshipTypeName: String): RelationshipType? + fun getRelationshipType(relationshipTypeName: String): Mono? @Throws(BluePrintException::class) - fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? + fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? } 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) @@ -61,33 +68,47 @@ class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService { 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 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 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): Mono? { + val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(artifactTypeName).plus(extension) + return getModelType(fileName, ArtifactType::class.java) } - 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): Mono? { + val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(relationshipTypeName).plus(extension) + return getModelType(fileName, RelationshipType::class.java) } - 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): 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 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)) + + } } - 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) + private fun getFileContent(fileName: String): Mono { + return Mono.just(FileUtils.readFileToString(File(fileName), Charset.defaultCharset())) } } \ 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 574eae6d3..4731935e6 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 @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service import org.junit.Test +import java.io.FileNotFoundException import kotlin.test.assertNotNull /** @@ -49,4 +50,11 @@ class BluePrintRepoFileServiceTest { 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") + } } \ No newline at end of file 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 index 735832cb1..1ef69fa92 100644 --- 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 @@ -17,6 +17,6 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; import java.io.Serializable; - +@Deprecated public interface ResourceSource extends Serializable { } 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 cef1f1580..5a1e38126 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 @@ -1,5 +1,6 @@ /* * 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. @@ -46,7 +47,7 @@ open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService: resourceDefinition.sources.forEach { (name, nodeTemplate) -> val sourceType = nodeTemplate.type - val sourceNodeType = bluePrintRepoService.getNodeType(sourceType) + val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block() ?: throw BluePrintException(format("Failed to get node type definition for source({})", sourceType)) // Validate Property Name, expression, values and Data Type 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 c34c252b3..610e8fc0b 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json @@ -7,7 +7,7 @@ "resource-path": "action-name", "resource-type": "ONAP", "updated-by": "brindasanth@onap.com", - "tags": null, + "tags": "action-name, brindasanth", "sources": { "input": { "type": "source-input", 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 349183bd9..e7e06000c 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 @@ -7,7 +7,7 @@ "resource-path": "vnf/v4-ip-type", "resource-type": "ONAP", "updated-by": "brindasanth@onap.com", - "tags": null, + "tags": "v4-ip-type, source-input, brindasanth", "sources": { "input": { "type": "source-input", 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 4a26119c0..4c11d8c68 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 @@ -26,6 +26,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; import java.util.Optional; @@ -43,59 +44,51 @@ public class BluePrintRepoDBService implements BluePrintRepoService { 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); + public Mono getNodeType(String nodeTypeName) throws BluePrintException { + return getModelType(nodeTypeName, 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); + public Mono getDataType(String dataTypeName) throws BluePrintException { + return getModelType(dataTypeName, 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); + public Mono getArtifactType(String artifactTypeName) throws BluePrintException { + return getModelType(artifactTypeName, 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); + public Mono getRelationshipType(String relationshipTypeName) throws BluePrintException { + return getModelType(relationshipTypeName, 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); + public Mono getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { + return getModelType(capabilityDefinitionName, CapabilityDefinition.class); } - private String getModelDefinitions(String modelName) throws BluePrintException { + private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing"); + + return getModelDefinitions(modelName).map(content -> { + Preconditions.checkArgument(StringUtils.isNotBlank(content), + String.format("Failed to get model content for model name (%s)", modelName)); + return JacksonUtils.readValue(content, valueClass); + } + ); + } + + private Mono getModelDefinitions(String modelName) throws BluePrintException { String modelDefinition = null; - Optional modelTypedb = modelTypeRepository.findByModelName(modelName); - if (modelTypedb.isPresent()) { - modelDefinition = modelTypedb.get().getDefinition(); + 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; + return Mono.just(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 5420dd390..629b94c01 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 @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema; @@ -112,60 +113,51 @@ public class ResourceDictionaryService { */ public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) throws BluePrintException { - if (resourceDictionary != null) { - ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); - - ResourceDefinition resourceDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); - // Check the Source already Present - resourceDictionaryValidationService.validate(resourceDefinition); - - if (resourceDefinition == null) { - throw new BluePrintException( - "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition()); - } - - 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(resourceDefinition, true); - resourceDictionary.setDefinition(definitionContent); - - Optional dbResourceDictionaryData = - resourceDictionaryRepository.findByName(resourceDictionary.getName()); - if (dbResourceDictionaryData.isPresent()) { - ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get(); - - dbResourceDictionary.setName(resourceDictionary.getName()); - dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); - dbResourceDictionary.setDescription(resourceDictionary.getDescription()); - dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); - dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); - dbResourceDictionary.setDataType(resourceDictionary.getDataType()); - dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema()); - dbResourceDictionary.setTags(resourceDictionary.getTags()); - dbResourceDictionary.setValidValues(resourceDictionary.getValidValues()); - resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary); - } else { - resourceDictionary = resourceDictionaryRepository.save(resourceDictionary); - } + Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); + Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()), + "Resource Dictionary definition information is missing"); + + ResourceDefinition resourceDefinition = + JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + // Validate the Resource Definitions + resourceDictionaryValidationService.validate(resourceDefinition); + + resourceDictionary.setResourceType(resourceDefinition.getResourceType()); + resourceDictionary.setResourcePath(resourceDefinition.getResourcePath()); + resourceDictionary.setTags(resourceDefinition.getTags()); + resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); + // Set the Property Definitions + PropertyDefinition propertyDefinition = resourceDefinition.getProperty(); + resourceDictionary.setDescription(propertyDefinition.getDescription()); + resourceDictionary.setDataType(propertyDefinition.getType()); + if(propertyDefinition.getEntrySchema() != null){ + resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); + } + + String definitionContent = JacksonUtils.getJson(resourceDefinition, true); + resourceDictionary.setDefinition(definitionContent); + + ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); + + Optional dbResourceDictionaryData = + resourceDictionaryRepository.findByName(resourceDictionary.getName()); + if (dbResourceDictionaryData.isPresent()) { + ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get(); + + dbResourceDictionary.setName(resourceDictionary.getName()); + dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); + dbResourceDictionary.setDescription(resourceDictionary.getDescription()); + dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); + dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); + dbResourceDictionary.setTags(resourceDictionary.getTags()); + dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy()); + dbResourceDictionary.setDataType(resourceDictionary.getDataType()); + dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema()); + resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary); } else { - throw new BluePrintException("Resource Dictionary information is missing"); + resourceDictionary = resourceDictionaryRepository.save(resourceDictionary); } + return resourceDictionary; } 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 986ba7066..198823bb1 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,5 +1,5 @@ { - "name": "v4-aggregat-list", + "name": "ipaddress", "property": { "description": "name of the ", "type": "list", @@ -10,7 +10,7 @@ "updated-by": "Brinda Santh (bs2796)", "resource-type": "ONAP", "resource-path": "/v4-aggregat-list", - "tags": null, + "tags": "ipaddress", "sources": { "input": { "type": "source-input" -- cgit 1.2.3-korg From 90c3a2c421b262095ea9684811509fafb8bc9e17 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Mon, 27 Aug 2018 20:08:09 -0400 Subject: Controller Blueprints Microservice Remove hard coded decrypt rule definition in resource definition and sample JSON. Change-Id: Iaea93ae34fdd6c440c074f001b80a94578086b1a Issue-ID: CCSDK-488 Signed-off-by: Brinda Santh --- .../load/resource_dictionary/db-source.json | 12 +--- .../resource/dict/data/DecryptionRule.java | 67 ---------------------- .../resource/dict/ResourceDefinition.kt | 5 -- .../load/resource_dictionary/db-source.json | 12 +--- .../service/rs/ResourceDictionaryRestTest.java | 2 - 5 files changed, 2 insertions(+), 96 deletions(-) delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DecryptionRule.java (limited to 'ms/controllerblueprints/modules/service/src/test') 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 cd4e282b4..c53a6dd3f 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 @@ -22,15 +22,5 @@ } } } - }, - "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/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DecryptionRule.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DecryptionRule.java deleted file mode 100644 index be435242d..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DecryptionRule.java +++ /dev/null @@ -1,67 +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.data; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; -/** - * - * DecryptionRule.java Purpose: - * @author Brinda Santh - */ -public class DecryptionRule { - - private List sources = null; - private String path; - private String rule; - @JsonProperty("decrypt-type") - private String decryptType; - - public List getSources() { - return sources; - } - - public void setSources(List sources) { - this.sources = sources; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public String getRule() { - return rule; - } - - public void setRule(String rule) { - this.rule = rule; - } - - public String getDecryptType() { - return decryptType; - } - - public void setDecryptType(String decryptType) { - this.decryptType = decryptType; - } - -} 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 525ed9a42..2287c6c8c 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 @@ -20,7 +20,6 @@ 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.* @@ -45,10 +44,6 @@ open class ResourceDefinition{ @JsonProperty(value = "sources", required = true) lateinit var sources: MutableMap - - @JsonProperty("decryption-rules") - var decryptionRules: MutableList? = null - } open class ResourceAssignment { 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 cd4e282b4..c53a6dd3f 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json @@ -22,15 +22,5 @@ } } } - }, - "decryption-rules": [ - { - "sources": [ - "input" - ], - "path": "/.", - "rule": "LOCAL-Decrypt", - "decrypt-type": "AES128" - } - ] + } } \ No newline at end of file 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 8257dc365..ec036eef3 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 @@ -19,13 +19,11 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.apache.commons.io.IOUtils; import org.junit.Assert; -import org.junit.Before; import org.junit.FixMethodOrder; 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; -- cgit 1.2.3-korg From 254217ffff5edea9069f96b992a5939b3745d376 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Wed, 29 Aug 2018 19:53:08 +0000 Subject: Controller Blueprints Microservice Improve code quality for Performance, JavaDoc, Imports, Probably Bug etc Change-Id: Ib71b62f14e8e8bd212e671a135025258fd9927b4 Issue-ID: CCSDK-491 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../controllerblueprints/ApplicationConstants.java | 1 + .../ApplicationExceptionHandler.java | 1 + .../apps/controllerblueprints/SwaggerConfig.java | 13 +----- .../core/service/BluePrintRuntimeService.kt | 2 +- .../core/utils/JacksonUtils.kt | 2 +- .../BluePrintValidatorDefaultServiceTest.kt | 3 +- .../validator/ResourceAssignmentValidator.java | 13 +++--- .../service/ResourceAssignmentValidationService.kt | 5 ++- .../service/ApplicationRegistrationService.java | 1 + .../service/AutoResourceMappingService.java | 39 +++++++++--------- .../service/BluePrintEnhancerService.java | 24 ++++++----- .../service/ConfigModelCreateService.java | 48 +++++++++------------- .../service/DataBaseInitService.java | 8 ++-- .../service/ServiceTemplateService.java | 28 ++++++------- .../service/domain/ConfigModel.java | 17 +++----- .../service/domain/ConfigModelContent.java | 10 ++--- .../service/domain/ConfigModelSearch.java | 16 +++----- .../service/domain/ModelType.java | 23 ++++------- .../service/domain/ResourceDictionary.java | 25 ++++------- .../repository/ConfigModelContentRepository.java | 32 +++++++++------ .../service/repository/ConfigModelRepository.java | 27 +++++++----- .../service/rs/ModelTypeRest.java | 2 - .../service/utils/ConfigModelUtils.java | 7 +++- .../service/validator/ModelTypeValidator.java | 3 +- .../validator/ServiceTemplateValidator.java | 12 +++--- .../service/rs/ModelTypeRestTest.java | 5 +-- .../validator/ServiceTemplateValidationTest.java | 1 - 27 files changed, 163 insertions(+), 205 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationConstants.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationConstants.java index 3172ed38b..2471bd5bc 100644 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationConstants.java +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationConstants.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.apps.controllerblueprints; * @author Brinda Santh * @version 1.0 */ +@SuppressWarnings("unused") public final class ApplicationConstants { } 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 index d9380a2f8..0a403b8c9 100644 --- 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 @@ -29,6 +29,7 @@ import org.springframework.web.context.request.WebRequest; @ControllerAdvice @RestController +@SuppressWarnings("unused") public class ApplicationExceptionHandler { private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationExceptionHandler.class); @ExceptionHandler(Exception.class) diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java index 5970bafde..67e3e5d00 100644 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java @@ -16,8 +16,6 @@ package org.onap.ccsdk.apps.controllerblueprints; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.PathSelectors; @@ -27,11 +25,7 @@ import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; - -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; -import java.util.Set; /** * SwaggerConfig @@ -40,13 +34,10 @@ import java.util.Set; */ @Configuration @EnableSwagger2 +@SuppressWarnings("unused") public class SwaggerConfig { - private static final Set DEFAULT_PRODUCES_AND_CONSUMES = - new HashSet(Arrays.asList("application/json", - "application/xml")); - private static Logger log = LoggerFactory.getLogger(SwaggerConfig.class); - @Bean + @SuppressWarnings("unused") public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() 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 5a8d5428a..9ba6313c9 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 @@ -20,13 +20,13 @@ 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 org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.slf4j.Logger import org.slf4j.LoggerFactory /** 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 886c3d2aa..c41124ed3 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 @@ -27,13 +27,13 @@ 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 +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 org.slf4j.LoggerFactory import java.io.File import java.nio.charset.Charset -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants /** * 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 index bccd946c4..50d2ce441 100644 --- 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 @@ -18,10 +18,11 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service import org.junit.Before import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory import org.slf4j.Logger import org.slf4j.LoggerFactory + /** * * 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 index c980a0c08..c9b37c269 100644 --- 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 @@ -29,15 +29,16 @@ 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 Map resourceAssignmentMap = new HashMap<>(); private StrBuilder validationMessage = new StrBuilder(); public ResourceAssignmentValidator(List assignments) { @@ -72,7 +73,7 @@ public class ResourceAssignmentValidator { * This is a validateResourceAssignment to validate the Topology Template * * @return boolean - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public boolean validateResourceAssignment() throws BluePrintException { if (assignments != null && !assignments.isEmpty()) { @@ -142,16 +143,14 @@ public class ResourceAssignmentValidator { neighbors.forEach((v, vs) -> { if (v == null) { s.append("\n * -> ["); - List links = vs; - for (ResourceAssignment resourceAssignment : links) { + for (ResourceAssignment resourceAssignment : vs) { s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName() + "),"); } s.append("]"); } else { s.append("\n (" + v.getDictionaryName() + ":" + v.getName() + ") -> ["); - List links = vs; - for (ResourceAssignment resourceAssignment : links) { + for (ResourceAssignment resourceAssignment : vs) { s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName() + "),"); } 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 6809831f9..6a78ac852 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,15 +16,16 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service +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.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. * 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 index 6d0ec8899..5a4a2877e 100644 --- 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 @@ -22,6 +22,7 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @Component +@SuppressWarnings("unused") public class ApplicationRegistrationService { @PostConstruct 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 2c443783e..5eba4fc7f 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 @@ -17,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.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; @@ -45,6 +46,7 @@ import java.util.Map; */ @Service +@SuppressWarnings("unused") public class AutoResourceMappingService { private static Logger log = LoggerFactory.getLogger(AutoResourceMappingService.class); @@ -53,9 +55,8 @@ public class AutoResourceMappingService { /** * This is a AutoResourceMappingService constructor - * - * @param dataDictionaryRepository - * + * + * @param dataDictionaryRepository dataDictionaryRepository */ public AutoResourceMappingService(ResourceDictionaryRepository dataDictionaryRepository) { this.dataDictionaryRepository = dataDictionaryRepository; @@ -63,8 +64,8 @@ public class AutoResourceMappingService { /** * This is a autoMap service to map the template keys automatically to Dictionary fields. - * - * @param resourceAssignments + * + * @param resourceAssignments resourceAssignments * @return AutoMapResponse */ public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { @@ -83,8 +84,6 @@ public class AutoResourceMappingService { log.info("Mapped Resource : {}", resourceAssignment); - } else { - // Do nothins } } } @@ -125,7 +124,7 @@ public class AutoResourceMappingService { if (CollectionUtils.isNotEmpty(names)) { List dictionaries = dataDictionaryRepository.findByNameIn(names); - if (CollectionUtils.isNotEmpty( dictionaries)) { + if (CollectionUtils.isNotEmpty(dictionaries)) { for (ResourceDictionary dataDictionary : dictionaries) { if (dataDictionary != null && StringUtils.isNotBlank(dataDictionary.getName())) { dictionaryMap.put(dataDictionary.getName(), dataDictionary); @@ -167,14 +166,13 @@ public class AutoResourceMappingService { private List getAllAutomapResourceAssignments(List resourceAssignments) { List dictionaries = null; List names = new ArrayList<>(); - List resourceAssignmentsWithDepencies = resourceAssignments; for (ResourceAssignment resourceAssignment : resourceAssignments) { if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { if (resourceAssignment.getDependencies() != null && !resourceAssignment.getDependencies().isEmpty()) { List dependencieNames = resourceAssignment.getDependencies(); for (String dependencieName : dependencieNames) { if (StringUtils.isNotBlank(dependencieName) && !names.contains(dependencieName) - && !checkAssignmentsExists(resourceAssignmentsWithDepencies, dependencieName)) { + && !checkAssignmentsExists(resourceAssignments, dependencieName)) { names.add(dependencieName); } } @@ -188,24 +186,25 @@ public class AutoResourceMappingService { if (dictionaries != null) { for (ResourceDictionary resourcedictionary : dictionaries) { ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class); + Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition"); PropertyDefinition property = new PropertyDefinition(); - property.setRequired(true); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName(resourcedictionary.getName()); - resourceAssignment.setDictionaryName(resourcedictionary - .getName()); - resourceAssignment.setVersion(0); - resourceAssignment.setProperty(property); + property.setRequired(true); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName(resourcedictionary.getName()); + resourceAssignment.setDictionaryName(resourcedictionary + .getName()); + resourceAssignment.setVersion(0); + resourceAssignment.setProperty(property); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - resourceAssignmentsWithDepencies.add(resourceAssignment); + resourceAssignments.add(resourceAssignment); } } - return resourceAssignmentsWithDepencies; + return resourceAssignments; } - public boolean checkAssignmentsExists(List resourceAssignmentsWithDepencies, String resourceName) { + private boolean checkAssignmentsExists(List resourceAssignmentsWithDepencies, String resourceName) { return resourceAssignmentsWithDepencies.stream().anyMatch(names -> names.getName().equalsIgnoreCase(resourceName)); } 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 0cf846c7a..28be75e66 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 @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import com.fasterxml.jackson.databind.JsonNode; 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.BluePrintException; @@ -47,7 +48,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private static Logger log = LoggerFactory.getLogger(BluePrintEnhancerService.class); - private HashMap recipeDataTypes = new HashMap<>(); + private Map recipeDataTypes = new HashMap<>(); public BluePrintEnhancerService(BluePrintRepoService bluePrintEnhancerRepoDBService) { super(bluePrintEnhancerRepoDBService); @@ -119,7 +120,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { if (StringUtils.isNotBlank(recipeName)) { DataType recipeDataType = this.recipeDataTypes.get(recipeName); if (recipeDataType == null) { - log.info("DataType not present for the recipe({})" , recipeName); + log.info("DataType not present for the recipe({})", recipeName); recipeDataType = new DataType(); recipeDataType.setVersion("1.0.0"); recipeDataType.setDescription( @@ -129,7 +130,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { Map dataTypeProperties = new HashMap<>(); recipeDataType.setProperties(dataTypeProperties); } else { - log.info("DataType Already present for the recipe({})" , recipeName); + log.info("DataType Already present for the recipe({})", recipeName); } // Merge all the Recipe Properties @@ -145,7 +146,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { NodeTemplate nodeTemplate) { Map dataTypeProperties = null; - if (nodeTemplate != null) { + if (nodeTemplate != null && MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) { CapabilityAssignment capability = nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); @@ -182,17 +183,18 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private void mergeDataTypeProperties(DataType dataType, Map mergeProperties) { if (dataType != null && dataType.getProperties() != null && mergeProperties != null) { // Add the Other Template Properties - mergeProperties.forEach((mappingKey, propertyDefinition) -> { - dataType.getProperties().put(mappingKey, propertyDefinition); - }); + mergeProperties.forEach((mappingKey, propertyDefinition) -> dataType.getProperties().put(mappingKey, propertyDefinition)); } } private void populateRecipeInputs(ServiceTemplate serviceTemplate) { - if (this.recipeDataTypes != null && !this.recipeDataTypes.isEmpty()) { + if (serviceTemplate.getTopologyTemplate() != null + && MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs()) + && MapUtils.isNotEmpty(this.recipeDataTypes) + && MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) { this.recipeDataTypes.forEach((recipeName, recipeDataType) -> { - String dataTypePrifix = recipeName.replace("-action", "") + "-request"; - String dataTypeName = "dt-" + dataTypePrifix; + String dataTypePrefix = recipeName.replace("-action", "") + "-request"; + String dataTypeName = "dt-" + dataTypePrefix; serviceTemplate.getDataTypes().put(dataTypeName, recipeDataType); @@ -200,7 +202,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { customInputProperty.setDescription("This is Dynamic Data type for the receipe " + recipeName + "."); customInputProperty.setRequired(Boolean.FALSE); customInputProperty.setType(dataTypeName); - serviceTemplate.getTopologyTemplate().getInputs().put(dataTypePrifix, customInputProperty); + serviceTemplate.getTopologyTemplate().getInputs().put(dataTypePrefix, customInputProperty); }); } 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 e40c2cf42..f52137191 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 @@ -197,7 +197,7 @@ public class ConfigModelCreateService { private void deleteConfigModelContent(Long dbConfigModelId) { if (dbConfigModelId != null) { ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - if (dbConfigModel != null && CollectionUtils.isNotEmpty(dbConfigModel.getConfigModelContents())) { + if (CollectionUtils.isNotEmpty(dbConfigModel.getConfigModelContents())) { dbConfigModel.getConfigModelContents().clear(); log.debug("Configuration Model content deleting : {}", dbConfigModel.getConfigModelContents()); configModelRepository.saveAndFlush(dbConfigModel); @@ -210,18 +210,15 @@ public class ConfigModelCreateService { if (dbConfigModelId != null && configModel != null && CollectionUtils.isNotEmpty(configModel.getConfigModelContents())) { ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - if (dbConfigModel != null) { - for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { - if (configModelContent != null) { - configModelContent.setId(null); - configModelContent.setConfigModel(dbConfigModel); - dbConfigModel.getConfigModelContents().add(configModelContent); - log.debug("Configuration Model content adding : {}", configModelContent); - } + for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { + if (configModelContent != null) { + configModelContent.setId(null); + configModelContent.setConfigModel(dbConfigModel); + dbConfigModel.getConfigModelContents().add(configModelContent); + log.debug("Configuration Model content adding : {}", configModelContent); } - configModelRepository.saveAndFlush(dbConfigModel); } - + configModelRepository.saveAndFlush(dbConfigModel); } } @@ -229,22 +226,19 @@ public class ConfigModelCreateService { String author) throws BluePrintException { ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - if (dbConfigModel != null) { - // Populate tags from metadata - String tags = getConfigModelTags(dbConfigModel); - if (StringUtils.isBlank(tags)) { - throw new BluePrintException("Failed to populate tags for the config model name " + artifactName); - } - dbConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); - dbConfigModel.setArtifactName(artifactName); - dbConfigModel.setArtifactVersion(artifactVersion); - dbConfigModel.setUpdatedBy(author); - dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N); - dbConfigModel.setTags(tags); - configModelRepository.saveAndFlush(dbConfigModel); - - log.info("Config model ({}) saved successfully.", dbConfigModel.getId()); + // Populate tags from metadata + String tags = getConfigModelTags(dbConfigModel); + if (StringUtils.isBlank(tags)) { + throw new BluePrintException("Failed to populate tags for the config model name " + artifactName); } + dbConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); + dbConfigModel.setArtifactName(artifactName); + dbConfigModel.setArtifactVersion(artifactVersion); + dbConfigModel.setUpdatedBy(author); + dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N); + dbConfigModel.setTags(tags); + configModelRepository.saveAndFlush(dbConfigModel); + log.info("Config model ({}) saved successfully.", dbConfigModel.getId()); return dbConfigModel; } @@ -282,8 +276,6 @@ public class ConfigModelCreateService { configModel.getArtifactName()); } tags = String.valueOf(serviceTemplate.getMetadata()); - } else { - // Do Nothing } } } 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 4b732cc30..89d482962 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 @@ -55,7 +55,7 @@ import java.util.List; */ @Component -@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true", matchIfMissing = false) +@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true") public class DataBaseInitService { private static Logger log = LoggerFactory.getLogger(DataBaseInitService.class); @@ -77,9 +77,9 @@ public class DataBaseInitService { /** * This is a DataBaseInitService, used to load the initial data * - * @param modelTypeService - * @param resourceDictionaryService - * @param configModelService + * @param modelTypeService modelTypeService + * @param resourceDictionaryService resourceDictionaryService + * @param configModelService configModelService */ public DataBaseInitService(ModelTypeService modelTypeService, ResourceDictionaryService resourceDictionaryService, ConfigModelService configModelService) { 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 70b7917a4..70cee3c9e 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 @@ -49,9 +49,9 @@ public class ServiceTemplateService { /** * This is a SchemaGeneratorService constructor * - * @param dataDictionaryRepository - * @param configModelCreateService - * @param bluePrintEnhancerService + * @param dataDictionaryRepository dataDictionaryRepository + * @param configModelCreateService configModelCreateService + * @param bluePrintEnhancerService bluePrintEnhancerService */ public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository, ConfigModelCreateService configModelCreateService, @@ -65,9 +65,9 @@ public class ServiceTemplateService { /** * This is a validateServiceTemplate method * - * @param serviceTemplate + * @param serviceTemplate serviceTemplate * @return ServiceTemplate - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { return this.configModelCreateService.validateServiceTemplate(serviceTemplate); @@ -76,11 +76,10 @@ public class ServiceTemplateService { /** * This is a enrichServiceTemplate method * - * @param serviceTemplate + * @param serviceTemplate serviceTemplate * @return ServiceTemplate - * @throws BluePrintException */ - public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) { this.bluePrintEnhancerService.enhance(serviceTemplate); return serviceTemplate; } @@ -88,22 +87,21 @@ public class ServiceTemplateService { /** * This is a autoMap method to map the template keys * - * @param resourceAssignments + * @param resourceAssignments resourceAssignments * @return AutoMapResponse - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { AutoResourceMappingService autoMappingService = new AutoResourceMappingService(dataDictionaryRepository); - AutoMapResponse autoMapResponse = autoMappingService.autoMap(resourceAssignments); - return autoMapResponse; + return autoMappingService.autoMap(resourceAssignments); } /** * This is a validateResourceAssignments method * - * @param resourceAssignments + * @param resourceAssignments resourceAssignments * @return List - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public List validateResourceAssignments(List resourceAssignments) throws BluePrintException { @@ -120,7 +118,7 @@ public class ServiceTemplateService { /** * This is a generateResourceAssignments method * - * @param templateContent + * @param templateContent templateContent * @return List */ public List generateResourceAssignments(ConfigModelContent templateContent) { 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 45382815c..51c9a7c6a 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 @@ -24,7 +24,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; @@ -81,8 +80,7 @@ public class ConfigModel implements Serializable { @Column(name = "artifact_type") private String artifactType; - @NotNull - @Column(name = "artifact_version") + @Column(name = "artifact_version", nullable = false) @ApiModelProperty(required=true) private String artifactVersion; @@ -99,30 +97,25 @@ public class ConfigModel implements Serializable { @Column(name = "creation_date") private Date createdDate = new Date(); - @NotNull - @Column(name = "artifact_name") + @Column(name = "artifact_name", nullable = false) @ApiModelProperty(required=true) private String artifactName; - @NotNull - @Column(name = "published") + @Column(name = "published", nullable = false) @ApiModelProperty(required=true) private String published; - @NotNull - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) @ApiModelProperty(required=true) private String updatedBy; - @NotNull @Lob - @Column(name = "tags") + @Column(name = "tags", nullable = false) @ApiModelProperty(required=true) private String tags; @OneToMany(mappedBy = "configModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) - @Column(nullable = true) @JsonManagedReference private List configModelContents = new ArrayList<>(); 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 0c05ef959..60b3ed6b0 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 @@ -23,7 +23,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.util.Date; import java.util.Objects; @@ -45,13 +44,11 @@ public class ConfigModelContent { @Column(name = "config_model_content_id") private Long id; - @NotNull - @Column(name = "name") + @Column(name = "name", nullable = false) @ApiModelProperty(required=true) private String name; - @NotNull - @Column(name = "content_type") + @Column(name = "content_type", nullable = false) @ApiModelProperty(required=true) private String contentType; @@ -65,9 +62,8 @@ public class ConfigModelContent { @Column(name = "description") private String description; - @NotNull @Lob - @Column(name = "content") + @Column(name = "content", nullable = false) @ApiModelProperty(required=true) private String content; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java index 2e9018837..6ec39ab55 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java @@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonFormat; import org.springframework.data.annotation.LastModifiedDate; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; @@ -40,8 +39,7 @@ public class ConfigModelSearch implements Serializable { @Column(name = "artifact_type") private String artifactType; - @NotNull - @Column(name = "artifact_version") + @Column(name = "artifact_version", nullable = false) private String artifactVersion; @Lob @@ -57,21 +55,17 @@ public class ConfigModelSearch implements Serializable { @Column(name = "creation_date") private Date createdDate = new Date(); - @NotNull - @Column(name = "artifact_name") + @Column(name = "artifact_name", nullable = false) private String artifactName; - @NotNull - @Column(name = "published") + @Column(name = "published", nullable = false) private String published; - @NotNull - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) private String updatedBy; - @NotNull @Lob - @Column(name = "tags") + @Column(name = "tags", nullable = false) private String tags; public Long getId() { 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 61e4d1189..eaa335b3e 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 @@ -22,7 +22,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; @@ -40,41 +39,34 @@ public class ModelType implements Serializable { private static final long serialVersionUID = 1L; @Id - @NotNull @Column(name = "model_name", nullable = false) @ApiModelProperty(required=true) private String modelName; - @NotNull - @Column(name = "derived_from") + @Column(name = "derived_from", nullable = false) @ApiModelProperty(required=true) private String derivedFrom; - @NotNull - @Column(name = "definition_type") + @Column(name = "definition_type", nullable = false) @ApiModelProperty(required=true) private String definitionType; - @NotNull @Lob - @Column(name = "definition") + @Column(name = "definition", nullable = false) @ApiModelProperty(required=true) private String definition; - @NotNull @Lob - @Column(name = "description") + @Column(name = "description", nullable = false) @ApiModelProperty(required=true) private String description; - @NotNull - @Column(name = "version") + @Column(name = "version", nullable = false) @ApiModelProperty(required=true) private String version; - @NotNull @Lob - @Column(name = "tags") + @Column(name = "tags", nullable = false) @ApiModelProperty(required=true) private String tags; @@ -84,8 +76,7 @@ public class ModelType implements Serializable { @Column(name = "creation_date") private Date creationDate; - @NotNull - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) @ApiModelProperty(required=true) private String updatedBy; 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 0d5879db8..487586842 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 @@ -22,7 +22,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; @@ -39,23 +38,19 @@ public class ResourceDictionary implements Serializable { private static final long serialVersionUID = 1L; @Id - @NotNull - @Column(name = "name") + @Column(name = "name", nullable = false) @ApiModelProperty(required=true) private String name; - @NotNull - @Column(name = "resource_path") + @Column(name = "resource_path", nullable = false) @ApiModelProperty(required=true) private String resourcePath; - @NotNull - @Column(name = "resource_type") + @Column(name = "resource_type", nullable = false) @ApiModelProperty(required=true) private String resourceType; - @NotNull - @Column(name = "data_type") + @Column(name = "data_type", nullable = false) @ApiModelProperty(required=true) private String dataType; @@ -70,21 +65,18 @@ public class ResourceDictionary implements Serializable { @Column(name = "sample_value") private String sampleValue; - @NotNull @Lob - @Column(name = "definition") + @Column(name = "definition", nullable = false) @ApiModelProperty(required=true) private String definition; - @NotNull @Lob - @Column(name = "description") + @Column(name = "description", nullable = false) @ApiModelProperty(required=true) private String description; - @NotNull @Lob - @Column(name = "tags") + @Column(name = "tags", nullable = false) @ApiModelProperty(required=true) private String tags; @@ -94,8 +86,7 @@ public class ResourceDictionary implements Serializable { @Column(name = "creation_date") private Date creationDate; - @NotNull - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) @ApiModelProperty(required=true) private String updatedBy; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java index ad2584a8e..733cbbdb3 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java @@ -21,6 +21,7 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelConten import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import javax.validation.constraints.NotNull; import java.util.List; import java.util.Optional; @@ -36,60 +37,65 @@ public interface ConfigModelContentRepository extends JpaRepository */ - Optional findById(Long id); + @NotNull + Optional findById(@NotNull Long id); /** * This is a findTopByConfigModelAndContentType method * - * @param configModel - * @param contentType + * @param configModel configModel + * @param contentType contentType * @return Optional */ + @SuppressWarnings("unused") Optional findTopByConfigModelAndContentType(ConfigModel configModel, String contentType); /** * This is a findByConfigModelAndContentType method * - * @param configModel - * @param contentType + * @param configModel configModel + * @param contentType contentType * @return Optional */ + @SuppressWarnings("unused") List findByConfigModelAndContentType(ConfigModel configModel, String contentType); /** * This is a findByConfigModel method * - * @param configModel + * @param configModel configModel * @return Optional */ + @SuppressWarnings("unused") List findByConfigModel(ConfigModel configModel); /** * This is a findByConfigModelAndContentTypeAndName method * - * @param configModel - * @param contentType - * @param name + * @param configModel configModel + * @param contentType contentType + * @param name name * @return Optional */ + @SuppressWarnings("unused") Optional findByConfigModelAndContentTypeAndName(ConfigModel configModel, String contentType, String name); /** * This is a deleteByMdeleteByConfigModelodelName method * - * @param configModel + * @param configModel configModel */ void deleteByConfigModel(ConfigModel configModel); /** * This is a deleteById method * - * @param id + * @param id id */ - void deleteById(Long id); + void deleteById(@NotNull Long id); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java index 4822ee971..0a60ab74d 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java @@ -20,6 +20,7 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import javax.validation.constraints.NotNull; import java.util.List; import java.util.Optional; @@ -34,16 +35,17 @@ public interface ConfigModelRepository extends JpaRepository /** * This is a findById method * - * @param id + * @param id id * @return Optional */ - Optional findById(Long id); + @NotNull + Optional findById(@NotNull Long id); /** * This is a findByArtifactNameAndArtifactVersion method * - * @param artifactName - * @param artifactVersion + * @param artifactName artifactName + * @param artifactVersion artifactVersion * @return Optional */ Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); @@ -51,7 +53,7 @@ public interface ConfigModelRepository extends JpaRepository /** * This is a findTopByArtifactNameOrderByArtifactIdDesc method * - * @param artifactName + * @param artifactName artifactName * @return Optional */ Optional findTopByArtifactNameOrderByArtifactVersionDesc(String artifactName); @@ -59,15 +61,16 @@ public interface ConfigModelRepository extends JpaRepository /** * This is a findTopByArtifactName method * - * @param artifactName + * @param artifactName artifactName * @return Optional */ + @SuppressWarnings("unused") List findTopByArtifactName(String artifactName); /** * This is a findByTagsContainingIgnoreCase method * - * @param tags + * @param tags tags * @return Optional */ List findByTagsContainingIgnoreCase(String tags); @@ -75,16 +78,18 @@ public interface ConfigModelRepository extends JpaRepository /** * This is a deleteByArtifactNameAndArtifactVersion method * - * @param artifactName - * @param artifactVersion + * @param artifactName artifactName + * @param artifactVersion artifactVersion */ + @SuppressWarnings("unused") void deleteByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); /** * This is a deleteById method * - * @param id + * @param id id */ - void deleteById(Long id); + @SuppressWarnings("unused") + void deleteById(@NotNull Long id); } 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 f6e5c274f..6bcbae963 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 @@ -20,8 +20,6 @@ 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.*; import java.util.List; 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 e31b04d16..bfc89b4ee 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 @@ -39,9 +39,10 @@ import java.util.List; public class ConfigModelUtils { - private ConfigModelUtils(){ + private ConfigModelUtils() { } + private static Logger log = LoggerFactory.getLogger(ConfigModelUtils.class); public static ConfigModel getConfigModel(String blueprintPath) throws Exception { @@ -119,6 +120,8 @@ public class ConfigModelUtils { public static List getBlueprintNames(String pathName) { File blueprintDir = new File(pathName); Preconditions.checkNotNull(blueprintDir, "failed to find the blueprint pathName file"); - return Arrays.asList(blueprintDir.list(DirectoryFileFilter.INSTANCE)); + String[] dirs = blueprintDir.list(DirectoryFileFilter.INSTANCE); + Preconditions.checkNotNull(dirs, "failed to find the blueprint directories"); + return Arrays.asList(dirs); } } 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 1201f6b49..aaa445a44 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 @@ -63,7 +63,6 @@ public class ModelTypeValidator { */ public static boolean validateModelTypeDefinition(String definitionType, String definitionContent) throws BluePrintException { - boolean valid = true; if (StringUtils.isNotBlank(definitionContent)) { if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) { DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); @@ -93,7 +92,7 @@ public class ModelTypeValidator { } } - return valid; + 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 index 430401bc3..848a32f5b 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 @@ -19,7 +19,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; import com.google.common.base.Preconditions; 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.data.NodeTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; @@ -40,14 +39,14 @@ import java.util.Map; public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { StringBuilder message = new StringBuilder(); - private Map metaData = new HashMap(); + private Map metaData = new HashMap<>(); /** * This is a validateServiceTemplate * - * @param serviceTemplateContent + * @param serviceTemplateContent serviceTemplateContent * @return boolean - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { if (StringUtils.isNotBlank(serviceTemplateContent)) { @@ -65,7 +64,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { * * @param serviceTemplate * @return boolean - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ @SuppressWarnings("squid:S00112") public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { @@ -77,8 +76,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; 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 d328b3eac..08bfeb10c 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 @@ -95,7 +95,7 @@ public class ModelTypeRestTest { List dbModelTypes = modelTypeRest.searchModelTypes(tags); Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes); - Assert.assertEquals("Failed to search ResourceMapping by tags count", true, dbModelTypes.size() > 0); + Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0); } @@ -109,8 +109,7 @@ public class ModelTypeRestTest { List dbDatatypeModelTypes = modelTypeRest.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes); - Assert.assertEquals("Failed to find getModelTypeByDefinitionType by count", true, - dbDatatypeModelTypes.size() > 0); + Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0); } @Test 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 557c6dd8d..0ef544525 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 @@ -18,7 +18,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Test; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -- 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/service/src/test') 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/service/src/test') 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 c77ee2f8cf2f326fd59a977f7f2775429cbce683 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Wed, 5 Sep 2018 01:22:04 -0400 Subject: Controller Blueprints Microservice Add Resource Dictionary reactive repository service for dictionary validation and automap functions. Change-Id: I7cc6d7d976cfe9370f9a74cd8f2e4256de8e8995 Issue-ID: CCSDK-484 Signed-off-by: Brinda Santh --- .../load/resource_dictionary/db-source.json | 4 +- .../load/resource_dictionary/input-source.json | 2 +- .../repository/ResourceDictionaryRepository.java | 3 +- .../ResourceDictionaryReactRepository.kt | 53 +++++++++++++++++ .../ResourceDictionaryReactRepositoryTest.java | 67 ++++++++++++++++++++++ .../modules/service/src/test/resources/logback.xml | 39 +++++++++++++ .../test/resources/resourcedictionary/automap.json | 4 +- 7 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/logback.xml (limited to 'ms/controllerblueprints/modules/service/src/test') 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 c53a6dd3f..ba86b3c79 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json @@ -1,5 +1,5 @@ { - "name": "bundle-id", + "name": "db-source", "property" :{ "description": "name of the ", "type": "string" @@ -7,7 +7,7 @@ "resource-type": "ONAP", "resource-path": "vnf/bundle-id", "updated-by": "brindasanth@onap.com", - "tags": "bundle-id, brindasanth@onap.com", + "tags": "db-source, brindasanth@onap.com", "sources": { "db": { "type": "source-db", 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 610e8fc0b..7cd58d618 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json +++ b/ms/controllerblueprints/modules/service/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/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java index 279dcd1c9..16031b6e0 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.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. @@ -62,7 +63,7 @@ public interface ResourceDictionaryRepository extends JpaRepository { + return Mono.justOrEmpty(resourceDictionaryRepository.findByName(name)) + } + + fun findByNameIn(names: List): Flux { + return Flux.fromIterable(resourceDictionaryRepository.findByNameIn(names)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByTagsContainingIgnoreCase(tags: String): Flux { + return Flux.fromIterable(resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags)) + .subscribeOn(Schedulers.elastic()) + } + + fun deleteByName(name: String): Mono { + return Mono.fromCallable { + resourceDictionaryRepository.deleteByName(name) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java new file mode 100644 index 000000000..db111885a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java @@ -0,0 +1,67 @@ +/* + * 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.repository; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +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.service.domain.ResourceDictionary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.List; +/** + * ResourceDictionaryReactRepositoryTest. + * + * @author Brinda Santh + */ + +@RunWith(SpringRunner.class) +@DataJpaTest +@ContextConfiguration(classes = {TestApplication.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ResourceDictionaryReactRepositoryTest { + + @Autowired + protected ResourceDictionaryReactRepository resourceDictionaryReactRepository; + + @Test + public void test01FindByNameReact() throws Exception { + ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName("db-source").block(); + Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); + } + + @Test + public void test02FindByNameInReact() throws Exception { + List dbResourceDictionaries = + resourceDictionaryReactRepository.findByNameIn(Arrays.asList("db-source")).collectList().block(); + Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); + } + + @Test + public void test03FindByTagsContainingIgnoreCaseReact() throws Exception { + List dbTagsResourceDictionaries = + resourceDictionaryReactRepository.findByTagsContainingIgnoreCase("db-source").collectList().block(); + Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries); + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml new file mode 100644 index 000000000..4a04cfdca --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml @@ -0,0 +1,39 @@ + + + + + + + + + + ${localPattern} + + + + + + + + + + + + + + diff --git a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/automap.json b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/automap.json index a85e71550..5a2a4ec02 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/automap.json +++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/automap.json @@ -1,11 +1,11 @@ [ { - "name": "action-name" + "name": "input-source" }, { "name": "v4-ip-type" }, { - "name": "bundle-id" + "name": "db-source" } ] \ No newline at end of file -- cgit 1.2.3-korg From a1140e2490ae560b3f85e8e2a4e424badaae1c48 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Wed, 5 Sep 2018 17:42:22 +0000 Subject: Controller Blueprints Microservice Modify Model Type and Resource Defintions persistance and access from String to JSON type for easy handling. Change-Id: Icfe7e95abad715b0ccad16c681ed057d289a6229 Issue-ID: CCSDK-431 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/AutoResourceMappingService.java | 7 ++-- .../service/BluePrintRepoDBService.java | 11 +++--- .../service/DataBaseInitService.java | 8 ++--- .../service/ResourceDictionaryService.java | 9 ++--- .../service/domain/JpaJsonNodeConverter.java | 40 ++++++++++++++++++++++ .../domain/JpaResourceDefinitionConverter.java | 39 +++++++++++++++++++++ .../service/domain/ModelType.java | 8 +++-- .../service/domain/ResourceDictionary.java | 8 +++-- .../service/validator/ModelTypeValidator.java | 18 +++++----- .../validator/ResourceDictionaryValidator.java | 2 +- .../service/rs/ModelTypeRestTest.java | 3 +- .../service/rs/ResourceDictionaryRestTest.java | 4 ++- 12 files changed, 120 insertions(+), 37 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java (limited to 'ms/controllerblueprints/modules/service/src/test') 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 428c52451..a763d503c 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 @@ -22,7 +22,6 @@ 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; -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.utils.ResourceDictionaryUtils; @@ -100,9 +99,9 @@ public class AutoResourceMappingService { private void populateDictionaryMapping(Map dictionaryMap, ResourceAssignment resourceAssignment) { ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName()); - if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) { + if (dbDataDictionary != null && dbDataDictionary.getDefinition() != null) { - ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class); + ResourceDefinition dictionaryDefinition = dbDataDictionary.getDefinition(); if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName()) && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { @@ -185,7 +184,7 @@ public class AutoResourceMappingService { } if (dictionaries != null) { for (ResourceDictionary resourcedictionary : dictionaries) { - ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class); + ResourceDefinition dictionaryDefinition = resourcedictionary.getDefinition(); Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition"); PropertyDefinition property = new PropertyDefinition(); property.setRequired(true); 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 c4aebe52c..5510e480c 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 @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.fasterxml.jackson.databind.JsonNode; import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; @@ -75,16 +76,16 @@ public class BluePrintRepoDBService implements BluePrintRepoService { Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Failed to get model from repo, model name is missing"); - return getModelDefinition(modelName).map(content -> { - Preconditions.checkArgument(StringUtils.isNotBlank(content), + return getModelDefinition(modelName).map(modelDefinition -> { + Preconditions.checkNotNull(modelDefinition, String.format("Failed to get model content for model name (%s)", modelName)); - return JacksonUtils.readValue(content, valueClass); + return JacksonUtils.readValue(modelDefinition, valueClass); } ); } - private Mono getModelDefinition(String modelName) throws BluePrintException { - String modelDefinition; + private Mono getModelDefinition(String modelName) throws BluePrintException { + JsonNode modelDefinition; Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); if (modelTypeDb.isPresent()) { modelDefinition = modelTypeDb.get().getDefinition(); 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 4e7c3911c..886809297 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 @@ -168,7 +168,7 @@ public class DataBaseInitService { ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath()); resourceDictionary.setName(dictionaryDefinition.getName()); - resourceDictionary.setDefinition(definitionContent); + resourceDictionary.setDefinition(dictionaryDefinition); resourceDictionary.setResourceType(dictionaryDefinition.getResourceType()); resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription()); @@ -252,7 +252,7 @@ public class DataBaseInitService { modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); modelType.setDerivedFrom(nodeType.getDerivedFrom()); modelType.setDescription(nodeType.getDescription()); - modelType.setDefinition(definitionContent); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(nodeKey); modelType.setVersion(nodeType.getVersion()); modelType.setUpdatedBy("System"); @@ -276,7 +276,7 @@ public class DataBaseInitService { modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); modelType.setDerivedFrom(dataType.getDerivedFrom()); modelType.setDescription(dataType.getDescription()); - modelType.setDefinition(definitionContent); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(dataKey); modelType.setVersion(dataType.getVersion()); modelType.setUpdatedBy("System"); @@ -300,7 +300,7 @@ public class DataBaseInitService { modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); modelType.setDerivedFrom(artifactType.getDerivedFrom()); modelType.setDescription(artifactType.getDescription()); - modelType.setDefinition(definitionContent); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(dataKey); modelType.setVersion(artifactType.getVersion()); modelType.setUpdatedBy("System"); 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 ccf4ffcc7..70e43d699 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 @@ -105,11 +105,9 @@ public class ResourceDictionaryService { */ 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"); + Preconditions.checkNotNull(resourceDictionary.getDefinition(),"Resource Dictionary definition information is missing"); - ResourceDefinition resourceDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + ResourceDefinition resourceDefinition = resourceDictionary.getDefinition(); Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content"); // Validate the Resource Definitions resourceDictionaryValidationService.validate(resourceDefinition); @@ -126,9 +124,6 @@ public class ResourceDictionaryService { resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); } - String definitionContent = JacksonUtils.getJson(resourceDefinition, true); - resourceDictionary.setDefinition(definitionContent); - ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); Optional dbResourceDictionaryData = diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java new file mode 100644 index 000000000..05f822d5b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java @@ -0,0 +1,40 @@ +/* + * 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.domain; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import com.fasterxml.jackson.databind.JsonNode; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +/** + * @author Brinda Santh + */ +@Converter +public class JpaJsonNodeConverter implements + AttributeConverter { + + @Override + public String convertToDatabaseColumn(JsonNode node) { + return JacksonUtils.getJson(node, true); + } + + @Override + public JsonNode convertToEntityAttribute(String dbData) { + return JacksonUtils.jsonNode(dbData); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java new file mode 100644 index 000000000..18672f1cb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.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.domain; + +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; +/** + * @author Brinda Santh + */ +@Converter +public class JpaResourceDefinitionConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(ResourceDefinition resourceDefinition) { + return JacksonUtils.getJson(resourceDefinition); + } + + @Override + public ResourceDefinition convertToEntityAttribute(String content) { + return JacksonUtils.readValue(content, ResourceDefinition.class); + } +} 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 cb8d229f3..d8fea60e5 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 @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.JsonNode; import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -52,9 +53,10 @@ public class ModelType implements Serializable { private String definitionType; @Lob + @Convert(converter = JpaJsonNodeConverter.class) @Column(name = "definition", nullable = false) @ApiModelProperty(required=true) - private String definition; + private JsonNode definition; @Lob @Column(name = "description", nullable = false) @@ -118,11 +120,11 @@ public class ModelType implements Serializable { this.definitionType = definitionType; } - public String getDefinition() { + public JsonNode getDefinition() { return definition; } - public void setDefinition(String definition) { + public void setDefinition(JsonNode definition) { this.definition = definition; } 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 c88462202..7af9972a6 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 @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -66,9 +67,10 @@ public class ResourceDictionary implements Serializable { private String sampleValue; @Lob + @Convert(converter = JpaResourceDefinitionConverter.class) @Column(name = "definition", nullable = false) @ApiModelProperty(required=true) - private String definition; + private ResourceDefinition definition; @Lob @Column(name = "description", nullable = false) @@ -163,11 +165,11 @@ public class ResourceDictionary implements Serializable { this.sampleValue = sampleValue; } - public String getDefinition() { + public ResourceDefinition getDefinition() { return definition; } - public void setDefinition(String definition) { + public void setDefinition(ResourceDefinition definition) { this.definition = definition; } 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 aaa445a44..9641f8973 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 @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; +import com.fasterxml.jackson.databind.JsonNode; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; @@ -56,14 +57,14 @@ public class ModelTypeValidator { /** * This is a validateModelTypeDefinition * - * @param definitionType - * @param definitionContent + * @param definitionType definitionType + * @param definitionContent definitionContent * @return boolean - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ - public static boolean validateModelTypeDefinition(String definitionType, String definitionContent) + public static boolean validateModelTypeDefinition(String definitionType, JsonNode definitionContent) throws BluePrintException { - if (StringUtils.isNotBlank(definitionContent)) { + if (definitionContent != null) { if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) { DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); if (dataType == null) { @@ -98,8 +99,9 @@ public class ModelTypeValidator { /** * This is a validateModelType method * - * @param modelType + * @param modelType modelType * @return boolean + * @throws BluePrintException BluePrintException */ public static boolean validateModelType(ModelType modelType) throws BluePrintException { if (modelType != null) { @@ -115,7 +117,7 @@ public class ModelTypeValidator { throw new BluePrintException("Model Type Information is missing."); } - if (StringUtils.isBlank(modelType.getDefinition())) { + if (modelType.getDefinition() == null) { throw new BluePrintException("Model Definition Information is missing."); } if (StringUtils.isBlank(modelType.getDescription())) { @@ -133,7 +135,7 @@ public class ModelTypeValidator { List validRootTypes = getValidModelDefinitionType(); if (!validRootTypes.contains(modelType.getDefinitionType())) { throw new BluePrintException("Not Valid Model Root Type(" + modelType.getDefinitionType() - + "), It sould be " + validRootTypes); + + "), It should be " + validRootTypes); } validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition()); 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 index ff0b4ac5c..1c2a7337b 100644 --- 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 @@ -49,7 +49,7 @@ public class ResourceDictionaryValidator { "DataDictionary Resource Name Information is missing."); Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourceType()), "DataDictionary Resource Type Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDefinition()), + Preconditions.checkNotNull( resourceDictionary.getDefinition(), "DataDictionary Definition Information is missing."); Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()), "DataDictionary Description Information is missing."); 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 8e88f0a69..c28abe2d3 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 @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; 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.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -64,7 +65,7 @@ public class ModelTypeRestTest { modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); modelType.setDescription("Definition for Sample Datatype "); - modelType.setDefinition(content); + modelType.setDefinition(JacksonUtils.jsonNode(content)); modelType.setModelName(modelName); modelType.setVersion("1.0.0"); modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," 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 8bb1f0b89..82346954c 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,8 @@ 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.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -58,7 +60,7 @@ public class ResourceDictionaryRestTest { ResourceDictionary dataDictionary = new ResourceDictionary(); dataDictionary.setResourcePath("test/vnf/ipaddress"); dataDictionary.setName("test-name"); - dataDictionary.setDefinition(definition); + dataDictionary.setDefinition(JacksonUtils.readValue(definition, ResourceDefinition.class)); dataDictionary.setValidValues("127.0.0.1"); dataDictionary.setResourceType("ONAP"); dataDictionary.setDataType("string"); -- cgit 1.2.3-korg From f2a776249a28d99564c44a76bde875b163170770 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Wed, 5 Sep 2018 23:40:46 +0000 Subject: Controller Blueprints Microservice Add Property Assign validation and Data Type Entry schema validation. Change-Id: Ifa40f62f848d06381ab83d7f1c9e7c6526f5edf0 Issue-ID: CCSDK-484 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../model_type/node_type/dg-activate-netconf.json | 2 +- .../model_type/node_type/dg-config-generator.json | 2 +- .../node_type/dg-resource-assign-activate.json | 2 +- .../node_type/dg-resource-assignment.json | 2 +- .../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 ++++ .../Definitions/activation-blueprint.json | 4 +-- .../blueprints/vrr-test/Definitions/vrr-test.json | 4 +-- .../model_type/node_type/dg-activate-netconf.json | 2 +- .../model_type/node_type/dg-config-generator.json | 2 +- .../node_type/dg-resource-assign-activate.json | 2 +- .../node_type/dg-resource-assignment.json | 2 +- .../service_template/default_netconf.json | 4 +-- .../test/resources/enhance/enhance-template.json | 23 ++------------- .../test/resources/enhance/enhanced-template.json | 34 ++++------------------ 17 files changed, 43 insertions(+), 62 deletions(-) create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.Component.json create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.DG.json create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.Vnf.json create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.component.Python.json (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/model_type/node_type/dg-activate-netconf.json b/ms/controllerblueprints/application/load/model_type/node_type/dg-activate-netconf.json index c638df00c..a9d16eddc 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/dg-activate-netconf.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/dg-activate-netconf.json @@ -15,7 +15,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/application/load/model_type/node_type/dg-config-generator.json b/ms/controllerblueprints/application/load/model_type/node_type/dg-config-generator.json index 28bace0f0..6794b3c89 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/dg-config-generator.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/dg-config-generator.json @@ -15,7 +15,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assign-activate.json b/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assign-activate.json index e98fa5a67..22a4d813c 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assign-activate.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assign-activate.json @@ -15,7 +15,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assignment.json b/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assignment.json index 36fbb6861..7c01faa13 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assignment.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assignment.json @@ -15,7 +15,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.Component.json b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.Component.json new file mode 100644 index 000000000..bc4827b8b --- /dev/null +++ b/ms/controllerblueprints/application/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/application/load/model_type/node_type/tosca.nodes.DG.json b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.DG.json new file mode 100644 index 000000000..86728cf2f --- /dev/null +++ b/ms/controllerblueprints/application/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/application/load/model_type/node_type/tosca.nodes.Vnf.json b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.Vnf.json new file mode 100644 index 000000000..acb1f2f31 --- /dev/null +++ b/ms/controllerblueprints/application/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/application/load/model_type/node_type/tosca.nodes.component.Python.json b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.component.Python.json new file mode 100644 index 000000000..7b67c8cb2 --- /dev/null +++ b/ms/controllerblueprints/application/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/service/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json index 635e177a1..851ded2ca 100644 --- a/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json +++ b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json @@ -44,7 +44,7 @@ "resource-assignment": { "type": "component-resource-assignment", "properties":{ - "request-id": ["1234", "1234"] + "request-id": "1234" }, "interfaces": { "DefaultComponentNode": { @@ -80,7 +80,7 @@ "resource-assignment-py": { "type": "component-resource-assignment", "properties":{ - "request-id": ["1234", "1234"] + "request-id": "1234" }, "interfaces": { "DefaultComponentNode": { diff --git a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json index d71dd2011..a06165bf9 100644 --- a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json +++ b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json @@ -268,7 +268,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { @@ -524,7 +524,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-activate-netconf.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-activate-netconf.json index c638df00c..a9d16eddc 100644 --- a/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-activate-netconf.json +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-activate-netconf.json @@ -15,7 +15,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-config-generator.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-config-generator.json index 28bace0f0..6794b3c89 100644 --- a/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-config-generator.json +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-config-generator.json @@ -15,7 +15,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assign-activate.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assign-activate.json index e98fa5a67..22a4d813c 100644 --- a/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assign-activate.json +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assign-activate.json @@ -15,7 +15,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assignment.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assignment.json index 36fbb6861..7c01faa13 100644 --- a/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assignment.json +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assignment.json @@ -15,7 +15,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { diff --git a/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json b/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json index 95c829c4f..14f724e54 100644 --- a/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json +++ b/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json @@ -394,7 +394,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { @@ -459,7 +459,7 @@ "is-start-flow": { "required": false, "type": "boolean", - "default": "false" + "default": false } }, "capabilities": { 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 fedf1da21..5824031e2 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 @@ -118,7 +118,7 @@ "properties": { "mode": "sync", "version": "LATEST", - "is-start-flow": "false" + "is-start-flow": false }, "requirements": { "component-dependency": { @@ -152,7 +152,7 @@ "properties": { "mode": "sync", "version": "LATEST", - "is-start-flow": "false" + "is-start-flow": false }, "requirements": { "component-dependency": { @@ -195,16 +195,8 @@ { "name": "bundle-mac", "property": { - "description": "", "required": true, - "type": "string", - "status": "", - "constraints": [ - {} - ], - "entry_schema": { - "type": "" - } + "type": "string" }, "input-param": false, "dictionary-name": "bundle-mac", @@ -220,10 +212,6 @@ "description": "", "required": true, "type": "list", - "status": "", - "constraints": [ - {} - ], "entry_schema": { "type": "dt-v4-aggregate" } @@ -293,13 +281,8 @@ { "name": "licenses", "property": { - "description": "", "required": true, "type": "list", - "status": "", - "constraints": [ - {} - ], "entry_schema": { "type": "dt-license-key" } 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 0633c64d0..c3f257382 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 @@ -115,25 +115,16 @@ "version" : "1.0.0", "properties" : { "bundle-mac" : { - "description" : "", "required" : true, - "type" : "string", - "status" : "", - "constraints" : [ { } ], - "entry_schema" : { - "type" : "" - } + "type" : "string" }, "hostname" : { "required" : true, "type" : "string" }, "licenses" : { - "description" : "", "required" : true, "type" : "list", - "status" : "", - "constraints" : [ { } ], "entry_schema" : { "type" : "dt-license-key" } @@ -142,8 +133,6 @@ "description" : "", "required" : true, "type" : "list", - "status" : "", - "constraints" : [ { } ], "entry_schema" : { "type" : "dt-v4-aggregate" } @@ -178,7 +167,7 @@ "is-start-flow" : { "required" : false, "type" : "boolean", - "default" : "false" + "default" : false } }, "capabilities" : { @@ -468,7 +457,7 @@ "is-start-flow" : { "required" : false, "type" : "boolean", - "default" : "false" + "default" : false } }, "capabilities" : { @@ -630,7 +619,7 @@ "properties" : { "mode" : "sync", "version" : "LATEST", - "is-start-flow" : "false" + "is-start-flow" : false }, "capabilities" : { "dg-node" : { }, @@ -664,7 +653,7 @@ "properties" : { "mode" : "sync", "version" : "LATEST", - "is-start-flow" : "false" + "is-start-flow" : false }, "capabilities" : { "dg-node" : { }, @@ -709,14 +698,8 @@ "mapping" : [ { "name" : "bundle-mac", "property" : { - "description" : "", "required" : true, - "type" : "string", - "status" : "", - "constraints" : [ { } ], - "entry_schema" : { - "type" : "" - } + "type" : "string" }, "input-param" : false, "dictionary-name" : "bundle-mac", @@ -729,8 +712,6 @@ "description" : "", "required" : true, "type" : "list", - "status" : "", - "constraints" : [ { } ], "entry_schema" : { "type" : "dt-v4-aggregate" } @@ -791,11 +772,8 @@ "mapping" : [ { "name" : "licenses", "property" : { - "description" : "", "required" : true, "type" : "list", - "status" : "", - "constraints" : [ { } ], "entry_schema" : { "type" : "dt-license-key" } -- cgit 1.2.3-korg From 674ff8788638a375226ab9b36c9552ca9918194f Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Wed, 5 Sep 2018 21:47:01 -0400 Subject: Controller Blueprints Microservice Add Controller Blueprint NodeTemplate Interface, Operation, Input and Output validation Change-Id: I6fae38cc8a4a36ddacc93bcea4b0061f846c6aba Issue-ID: CCSDK-484 Signed-off-by: Brinda Santh --- .../baseconfiguration/Definitions/activation-blueprint.json | 4 ++-- .../service/load/model_type/node_type/component-netconf-executor.json | 4 ++-- .../modules/service/src/test/resources/enhance/enhance-template.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json b/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json index 635e177a1..851ded2ca 100644 --- a/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json +++ b/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json @@ -44,7 +44,7 @@ "resource-assignment": { "type": "component-resource-assignment", "properties":{ - "request-id": ["1234", "1234"] + "request-id": "1234" }, "interfaces": { "DefaultComponentNode": { @@ -80,7 +80,7 @@ "resource-assignment-py": { "type": "component-resource-assignment", "properties":{ - "request-id": ["1234", "1234"] + "request-id": "1234" }, "interfaces": { "DefaultComponentNode": { diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-executor.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-executor.json index aed667aaf..240caf3fc 100644 --- a/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-executor.json +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-executor.json @@ -23,12 +23,12 @@ "required": true, "type": "string" }, - "service-template-name": { + "template-name": { "description": "Service Template Name", "required": true, "type": "string" }, - "service-template-version": { + "template-version": { "description": "Service Template Version", "required": true, "type": "string" 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 5824031e2..155dc7235 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 @@ -64,8 +64,8 @@ "process": { "inputs": { "action-name": "{ \"get_input\" : \"action-name\" }", - "template_name": "{ \"get_attribute\" : \"template_name\" }", - "service-template-version": "{ \"get_attribute\" : \"service-template-version\" }", + "template-name": "{ \"get_attribute\" : \"template_name\" }", + "template-version": "{ \"get_attribute\" : \"template_version\" }", "resource-type": "vnf-type", "request-id": "{ \"get_input\" : \"request-id\" }", "resource-id": "{ \"get_input\" : \"hostname\" }", -- cgit 1.2.3-korg From 2c91cf47dcfc3014dd669627e214b2e8ec34ce4a Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Wed, 5 Sep 2018 23:18:19 -0400 Subject: Controller Blueprints Microservice Add configuration property to load model types and Remove duplicate model type test case files Change-Id: I6a34539cae7377bd133727fde77ff8fefaadf023 Issue-ID: CCSDK-484 Signed-off-by: Brinda Santh --- .../node_type/component-netconf-executor.json | 4 +- .../opt/app/onap/config/application.properties | 9 +- .../src/test/resources/application.properties | 9 +- .../artifact_type/artifact-mapping-resource.json | 8 -- .../artifact_type/artifact-script-python.json | 8 -- .../artifact_type/artifact-template-velocity.json | 8 -- .../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 ---- .../node_type/artifact-config-template.json | 37 --------- .../node_type/component-config-generator.json | 72 ---------------- .../node_type/component-netconf-edit.json | 95 ---------------------- .../node_type/component-netconf-executor.json | 79 ------------------ .../node_type/component-netconf-get.json | 61 -------------- .../node_type/component-resource-assignment.json | 68 ---------------- .../node_type/component-transaction-netconf.json | 93 --------------------- .../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 --------------- .../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 -- .../model_type/node_type/vnf-netconf-device.json | 42 ---------- .../service/DataBaseInitService.java | 14 ++-- .../ResourceDictionaryReactRepository.kt | 5 ++ .../ResourceDictionaryReactRepositoryTest.java | 27 ++++++ .../service/rs/ModelTypeRestTest.java | 15 ++-- .../service/rs/ServiceTemplateRestTest.java | 5 +- .../src/test/resources/application.properties | 9 +- .../model_type/data_type/datatype-property.json | 27 ++++++ 34 files changed, 98 insertions(+), 1108 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/artifact_type/artifact-mapping-resource.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/artifact_type/artifact-script-python.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/artifact_type/artifact-template-velocity.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/data_type/datatype-property.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/data_type/datatype-resource-assignment.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/data_type/dt-license-key.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/data_type/dt-v4-aggregate.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/artifact-config-template.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/component-config-generator.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-edit.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-executor.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-get.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/component-resource-assignment.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/component-transaction-netconf.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/dg-activate-netconf.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/dg-config-generator.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assign-activate.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assignment.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json delete mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/vnf-netconf-device.json create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/model_type/data_type/datatype-property.json (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/model_type/node_type/component-netconf-executor.json b/ms/controllerblueprints/application/load/model_type/node_type/component-netconf-executor.json index aed667aaf..240caf3fc 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/component-netconf-executor.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/component-netconf-executor.json @@ -23,12 +23,12 @@ "required": true, "type": "string" }, - "service-template-name": { + "template-name": { "description": "Service Template Name", "required": true, "type": "string" }, - "service-template-version": { + "template-version": { "description": "Service Template Version", "required": true, "type": "string" diff --git a/ms/controllerblueprints/application/opt/app/onap/config/application.properties b/ms/controllerblueprints/application/opt/app/onap/config/application.properties index 3b6033e7f..2d355d653 100644 --- a/ms/controllerblueprints/application/opt/app/onap/config/application.properties +++ b/ms/controllerblueprints/application/opt/app/onap/config/application.properties @@ -1,5 +1,6 @@ # -# Copyright © 2017-2018 AT&T Intellectual Property. +# 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. @@ -48,4 +49,8 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect #Load Blueprints # blueprints.load.initial-data may be overridden by ENV variables blueprints.load.initial-data=true -blueprints.load.path=load \ No newline at end of file +load.dataTypePath=load/model_type/data_type +load.nodeTypePath=load/model_type/node_type +load.artifactTypePath=load/model_type/artifact_type +load.resourceDictionaryPath=load/resource_dictionary +load.blueprintsPath=load/blueprints \ No newline at end of file diff --git a/ms/controllerblueprints/application/src/test/resources/application.properties b/ms/controllerblueprints/application/src/test/resources/application.properties index a63ed5b71..3bcbbd9c9 100644 --- a/ms/controllerblueprints/application/src/test/resources/application.properties +++ b/ms/controllerblueprints/application/src/test/resources/application.properties @@ -1,5 +1,6 @@ # -# Copyright © 2017-2018 AT&T Intellectual Property. +# 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. @@ -28,4 +29,8 @@ swagger.contact.email=brindasanth@onap.com #Load Blueprints # blueprints.load.initial-data may be overridden by ENV variables blueprints.load.initial-data=true -blueprints.load.path=load \ No newline at end of file +load.dataTypePath=load/model_type/data_type +load.nodeTypePath=load/model_type/node_type +load.artifactTypePath=load/model_type/artifact_type +load.resourceDictionaryPath=load/resource_dictionary +load.blueprintsPath=load/blueprints \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/artifact_type/artifact-mapping-resource.json b/ms/controllerblueprints/modules/service/load/model_type/artifact_type/artifact-mapping-resource.json deleted file mode 100644 index 0a3261b09..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/artifact_type/artifact-script-python.json b/ms/controllerblueprints/modules/service/load/model_type/artifact_type/artifact-script-python.json deleted file mode 100644 index b48d2b628..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/artifact_type/artifact-template-velocity.json b/ms/controllerblueprints/modules/service/load/model_type/artifact_type/artifact-template-velocity.json deleted file mode 100644 index 9395d3970..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/data_type/datatype-property.json b/ms/controllerblueprints/modules/service/load/model_type/data_type/datatype-property.json deleted file mode 100644 index 5584b10ea..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/data_type/datatype-resource-assignment.json b/ms/controllerblueprints/modules/service/load/model_type/data_type/datatype-resource-assignment.json deleted file mode 100644 index cc9816ebb..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/data_type/dt-license-key.json b/ms/controllerblueprints/modules/service/load/model_type/data_type/dt-license-key.json deleted file mode 100644 index e9c312b79..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/data_type/dt-v4-aggregate.json b/ms/controllerblueprints/modules/service/load/model_type/data_type/dt-v4-aggregate.json deleted file mode 100644 index 842a7f805..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/artifact-config-template.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/artifact-config-template.json deleted file mode 100644 index be9bbfc0e..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/component-config-generator.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/component-config-generator.json deleted file mode 100644 index 764f9e890..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/component-netconf-edit.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-edit.json deleted file mode 100644 index 144e1dded..000000000 --- a/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-edit.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "description": "This is Netconf Edit Configuration Component API", - "version": "1.0.0", - "capabilities": { - "component-node": { - "type": "tosca.capabilities.Node" - } - }, - "interfaces": { - "org-openecomp-sdnc-netconf-adaptor-service-SimpleNetconfEditConfigNode": { - "operations": { - "process": { - "inputs": { - "template-name": { - "description": "Template name used by the Components during processing", - "required": false, - "type": "string" - }, - "rpc-message": { - "description": "If the message is Neconf RPC message,It should be true or false.", - "required": false, - "type": "boolean", - "default": false - }, - "wait": { - "description": "Delay time in sec before performing edit-config action.", - "required": false, - "type": "integer", - "default": 0 - }, - "unlock": { - "description": "If unLock command has to send before Edit Configuration.", - "required": false, - "type": "boolean", - "default": false - }, - "config-target": { - "required": false, - "type": "string" - }, - "commit": { - "description": "Issue commit command to the device after performing edit-config action.", - "required": false, - "type": "boolean", - "default": false - }, - "edit-default-operation": { - "required": false, - "type": "string" - }, - "content": { - "description": "Static messgae content, If this is not set, need to have Requirement relationship to Artifact contents.", - "required": false, - "type": "string" - }, - "lock": { - "description": "Issue lock command to the device before performing edit-config action.", - "required": false, - "type": "boolean", - "default": false - }, - "post-restart-wait": { - "description": "If Restart command should be issued before the Edit Operation, Provide the time to wait after restart. 0 meanno restart required or wait time in sec ex : 3000 for 5 ", - "required": false, - "type": "integer", - "default": 0 - }, - "pre-restart-wait": { - "description": "If Restart command should be issued after the Edit Operation, Provide the time to wait after restart. 0 meanno restart required or wait time in sec ex : 3000 for 5 ", - "required": false, - "type": "integer", - "default": 0 - }, - "message-time-out": { - "required": false, - "type": "integer", - "default": 30 - } - }, - "outputs": { - "rpc-response-message": { - "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/service/load/model_type/node_type/component-netconf-executor.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-executor.json deleted file mode 100644 index 240caf3fc..000000000 --- a/ms/controllerblueprints/modules/service/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" - }, - "template-name": { - "description": "Service Template Name", - "required": true, - "type": "string" - }, - "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/service/load/model_type/node_type/component-netconf-get.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-get.json deleted file mode 100644 index 1659bf419..000000000 --- a/ms/controllerblueprints/modules/service/load/model_type/node_type/component-netconf-get.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "description": "This is Netconf Get Running Configuration Component API", - "version": "1.0.0", - "capabilities": { - "component-node": { - "type": "tosca.capabilities.Node" - } - }, - "interfaces": { - "org-openecomp-sdnc-netconf-adaptor-service-SimpleNetconfGetConfigNode": { - "operations": { - "process": { - "inputs": { - "template-name": { - "description": "Template name used by the Components during processing", - "required": false, - "type": "string" - }, - "rpc-message": { - "description": "It should be true, If the message is Neconf RPC message, It should be false If it is plain Config message.", - "required": false, - "type": "boolean", - "default": false - }, - "wait": { - "required": false, - "type": "integer", - "default": 0 - }, - "lock": { - "required": false, - "type": "boolean", - "default": false - }, - "content": { - "description": "Static messgae content, If this is not set, need to have Requirement relationship to Artifact contents.", - "required": false, - "type": "string" - }, - "message-time-out": { - "required": false, - "type": "integer", - "default": 30 - } - }, - "outputs": { - "config-message": { - "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/service/load/model_type/node_type/component-resource-assignment.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/component-resource-assignment.json deleted file mode 100644 index 34c028482..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/component-transaction-netconf.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/component-transaction-netconf.json deleted file mode 100644 index 7c3745848..000000000 --- a/ms/controllerblueprints/modules/service/load/model_type/node_type/component-transaction-netconf.json +++ /dev/null @@ -1,93 +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-NetconfTransactionNode": { - "operations": { - "process": { - "inputs": { - "rollback": { - "required": false, - "type": "boolean" - }, - "assignment-action-name": { - "description": "Assignment 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": true, - "type": "string" - }, - "transaction-components": { - "description": "Components used to used for the atomic transaction, Default Handlers are org.openecomp.sdnc.netconf.adaptor.service.SimpleNetconfEditConfigNode and org.openecomp.sdnc.netconf.adaptor.service.SimpleNetconfGetConfigNode", - "required": true, - "type": "list", - "entry_schema": { - "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" - }, - "initialise-sftp": { - "required": false, - "type": "boolean" - }, - "request-id": { - "description": "Request Id used to store the generated configuration, in the database along with the template-name", - "required": true, - "type": "string" - }, - "initialise-ssh": { - "required": false, - "type": "boolean" - }, - "lock": { - "required": false, - "type": "boolean", - "default": false - }, - "unlock": { - "description": "If unLock command has to send before Edit Configuration.", - "required": false, - "type": "boolean", - "default": false - }, - "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" - }, - "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" - } - }, - "outputs": { - "rpc-response-message": { - "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/service/load/model_type/node_type/dg-activate-netconf.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-activate-netconf.json deleted file mode 100644 index a9d16eddc..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/dg-config-generator.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-config-generator.json deleted file mode 100644 index 6794b3c89..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/dg-resource-assign-activate.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assign-activate.json deleted file mode 100644 index 22a4d813c..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/dg-resource-assignment.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/dg-resource-assignment.json deleted file mode 100644 index 7c01faa13..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json deleted file mode 100644 index 661a9503b..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json deleted file mode 100644 index 13e234e1b..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json deleted file mode 100644 index 126ea30bd..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json deleted file mode 100644 index f8dd8b6fc..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json deleted file mode 100644 index 2ef553e24..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/model_type/node_type/vnf-netconf-device.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/vnf-netconf-device.json deleted file mode 100644 index 54573bade..000000000 --- a/ms/controllerblueprints/modules/service/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/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 886809297..c6d80cfb6 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 @@ -60,16 +60,19 @@ import java.util.List; public class DataBaseInitService { private static EELFLogger log = EELFManager.getInstance().getLogger(DataBaseInitService.class); - @Value("${blueprints.load.path}") - private String modelLoadPath; private ModelTypeService modelTypeService; private ResourceDictionaryService resourceDictionaryService; private ConfigModelService configModelService; + @Value("${load.dataTypePath}") private String dataTypePath; + @Value("${load.nodeTypePath}") private String nodeTypePath; + @Value("${load.artifactTypePath}") private String artifactTypePath; + @Value("${load.resourceDictionaryPath}") private String resourceDictionaryPath; + @Value("${load.blueprintsPath}") private String bluePrintsPath; @Autowired @@ -94,13 +97,6 @@ public class DataBaseInitService { @PostConstruct @SuppressWarnings("unused") private void initDatabase() { - log.info("loading Blueprints from DIR : {}", modelLoadPath); - dataTypePath = modelLoadPath + "/model_type/data_type"; - nodeTypePath = modelLoadPath + "/model_type/node_type"; - artifactTypePath = modelLoadPath + "/model_type/artifact_type"; - resourceDictionaryPath = modelLoadPath + "/resource_dictionary"; - bluePrintsPath = modelLoadPath + "/blueprints"; - log.info("loading dataTypePath from DIR : {}", dataTypePath); log.info("loading nodeTypePath from DIR : {}", nodeTypePath); log.info("loading artifactTypePath from DIR : {}", artifactTypePath); diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt index 92172a2e4..064b5c382 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt @@ -22,6 +22,7 @@ import org.springframework.stereotype.Service import reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.core.scheduler.Schedulers + /** * ResourceDictionaryReactRepository. * @@ -30,6 +31,10 @@ import reactor.core.scheduler.Schedulers @Service open class ResourceDictionaryReactRepository(private val resourceDictionaryRepository: ResourceDictionaryRepository) { + fun save(resourceDictionary: ResourceDictionary): Mono { + return Mono.justOrEmpty(resourceDictionaryRepository.save(resourceDictionary)) + } + fun findByName(name: String): Mono { return Mono.justOrEmpty(resourceDictionaryRepository.findByName(name)) } diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java index db111885a..1e740ec33 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java @@ -17,11 +17,14 @@ package org.onap.ccsdk.apps.controllerblueprints.service.repository; import org.junit.Assert; +import org.junit.Before; import org.junit.FixMethodOrder; 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.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @@ -30,6 +33,7 @@ import org.springframework.test.context.junit4.SpringRunner; import java.util.Arrays; import java.util.List; + /** * ResourceDictionaryReactRepositoryTest. * @@ -45,6 +49,16 @@ public class ResourceDictionaryReactRepositoryTest { @Autowired protected ResourceDictionaryReactRepository resourceDictionaryReactRepository; + @Before + public void init() { + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("load/resource_dictionary/db-source" + + ".json", ResourceDefinition.class); + + ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition); + ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.save(resourceDictionary).block(); + Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); + } + @Test public void test01FindByNameReact() throws Exception { ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName("db-source").block(); @@ -64,4 +78,17 @@ public class ResourceDictionaryReactRepositoryTest { resourceDictionaryReactRepository.findByTagsContainingIgnoreCase("db-source").collectList().block(); Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries); } + + private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) { + ResourceDictionary resourceDictionary = new ResourceDictionary(); + resourceDictionary.setName(resourceDefinition.getName()); + resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); + resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); + resourceDictionary.setResourcePath(resourceDefinition.getResourcePath()); + resourceDictionary.setResourceType(resourceDefinition.getResourceType()); + resourceDictionary.setTags(resourceDefinition.getTags()); + resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); + resourceDictionary.setDefinition(resourceDefinition); + return resourceDictionary; + } } 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 c28abe2d3..c7147490d 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 @@ -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. @@ -54,13 +55,14 @@ public class ModelTypeRestTest { @After - public void tearDown() {} + public void tearDown() { + } @Test public void test01SaveModelType() throws Exception { - log.info( "**************** test01SaveModelType ********************"); + log.info("**************** test01SaveModelType ********************"); - String content = FileUtils.readFileToString(new File("load/model_type/data_type/datatype-property.json"), Charset.defaultCharset()); + String content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json"); ModelType modelType = new ModelType(); modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); @@ -72,7 +74,7 @@ public class ModelTypeRestTest { + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); modelType.setUpdatedBy("xxxxxx@xxx.com"); modelType = modelTypeRest.saveModelType(modelType); - log.info( "Saved Mode {}", modelType.toString()); + log.info("Saved Mode {}", modelType.toString()); Assert.assertNotNull("Failed to get Saved ModelType", modelType); Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName()); @@ -90,7 +92,7 @@ public class ModelTypeRestTest { @Test public void test02SearchModelTypes() throws Exception { - log.info( "*********************** test02SearchModelTypes ***************************"); + log.info("*********************** test02SearchModelTypes ***************************"); String tags = "test-datatype"; @@ -102,7 +104,7 @@ public class ModelTypeRestTest { @Test public void test03GetModelType() throws Exception { - log.info( "************************* test03GetModelType *********************************"); + log.info("************************* test03GetModelType *********************************"); ModelType dbModelType = modelTypeRest.getModelTypeByName(modelName); Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType); Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName()); @@ -125,5 +127,4 @@ public class ModelTypeRestTest { } - } 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 217eb8f06..faa10825f 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 @@ -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. @@ -127,10 +128,10 @@ public class ServiceTemplateRestTest { public void test05AutoMap() throws Exception { log.info("*********** test05AutoMap *******************************************"); - String resourceassignmentContent = FileUtils.readFileToString( + String resourceAssignmentContent = FileUtils.readFileToString( new File("src/test/resources/resourcedictionary/automap.json"), Charset.defaultCharset()); List batchResourceAssignment = - JacksonUtils.getListFromJson(resourceassignmentContent, ResourceAssignment.class); + JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); AutoMapResponse autoMapResponse = serviceTemplateRest.autoMap(batchResourceAssignment); Assert.assertNotNull("Failed to get ResourceAssignments, Return object is Null", diff --git a/ms/controllerblueprints/modules/service/src/test/resources/application.properties b/ms/controllerblueprints/modules/service/src/test/resources/application.properties index a13e16841..b17663e9a 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/application.properties +++ b/ms/controllerblueprints/modules/service/src/test/resources/application.properties @@ -1,5 +1,6 @@ # -# Copyright © 2017-2018 AT&T Intellectual Property. +# 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. @@ -64,4 +65,8 @@ logging.level.org.hibernate.type.descriptor.sql=debug blueprints.load.initial-data=true -blueprints.load.path=load \ No newline at end of file +load.dataTypePath=./../../application/load/model_type/data_type +load.nodeTypePath=./../../application/load/model_type/node_type +load.artifactTypePath=./../../application/load/model_type/artifact_type +load.resourceDictionaryPath=load/resource_dictionary +load.blueprintsPath=./../../application/load/blueprints \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/resources/model_type/data_type/datatype-property.json b/ms/controllerblueprints/modules/service/src/test/resources/model_type/data_type/datatype-property.json new file mode 100644 index 000000000..5584b10ea --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/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 -- cgit 1.2.3-korg From 92c807d2bd54d8221597acc2e84f15ad2ada0b7b Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 6 Sep 2018 20:18:24 +0000 Subject: Controller Blueprints Microservice Add Blueprint Dervied from NodeType, Requirement Definitions and Assignments validations. Change-Id: I1cc643b5a83c5a707c8e3ae1342a439f122da55e Issue-ID: CCSDK-484 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../Definitions/activation-blueprint.json | 7 +- .../model_type/node_type/tosca.nodes.Artifact.json | 5 + .../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 .../blueprints/vrr-test/Definitions/vrr-test.json | 20 + .../validator/ServiceTemplateValidationTest.java | 5 +- .../test/resources/enhance/enhanced-template.json | 28 +- 13 files changed, 57 insertions(+), 505 deletions(-) create mode 100644 ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.Artifact.json delete mode 100644 ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json delete mode 100644 ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json delete mode 100644 ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn delete mode 100644 ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py delete mode 100644 ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Scripts/__init__.py delete mode 100644 ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta delete mode 100644 ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl delete mode 100644 ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/__init__.py (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json b/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json index 851ded2ca..d4fbf5cf4 100644 --- a/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json +++ b/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json @@ -217,7 +217,7 @@ "default" : "LATEST" } }, - "derived_from": "tosca.nodes.Component" + "derived_from": "tosca.nodes.DG" }, "tosca.nodes.Component": { "description": "This is Resource Assignment Component API", @@ -253,6 +253,11 @@ }, "derived_from": "tosca.nodes.Root" }, + "tosca.nodes.DG" : { + "description" : "This is Directed Graph Node Type", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, "tosca.nodes.component.Python": { "description": "This is Resource Assignment Python Component API", "version": "1.0.0", diff --git a/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.Artifact.json b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.Artifact.json new file mode 100644 index 000000000..814105277 --- /dev/null +++ b/ms/controllerblueprints/application/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/service/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json deleted file mode 100644 index 851ded2ca..000000000 --- a/ms/controllerblueprints/modules/service/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" - }, - "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" - }, - "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/service/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Mappings/baseconfig-mapping.json deleted file mode 100644 index 6abfb51bd..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Plans/ActivateProcess.bpmn deleted file mode 100644 index 5e94c0f8e..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Scripts/SamplePythonComponentNode.py deleted file mode 100644 index eb198c79a..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/blueprints/baseconfiguration/Scripts/__init__.py b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Scripts/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/TOSCA-Metadata/TOSCA.meta deleted file mode 100644 index 05c2c67f5..000000000 --- a/ms/controllerblueprints/modules/service/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: vrr-test, Brinda Santh - -Name: Plans/ActivateProcess.bpmn -Content-Type: application/vnd.oasis.bpmn diff --git a/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/Templates/baseconfig-template.vtl deleted file mode 100644 index 026c59176..000000000 --- a/ms/controllerblueprints/modules/service/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/service/load/blueprints/baseconfiguration/__init__.py b/ms/controllerblueprints/modules/service/load/blueprints/baseconfiguration/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json index a06165bf9..92785796b 100644 --- a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json +++ b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json @@ -644,6 +644,26 @@ } }, "derived_from": "tosca.nodes.Component" + }, + "tosca.nodes.DG" : { + "description" : "This is Directed Graph Node Type", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, + "tosca.nodes.Vnf" : { + "description" : "This is VNF Node Type", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, + "tosca.nodes.Artifact" : { + "description" : "This is Deprecated Artifact Node Type.", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, + "tosca.nodes.Component" : { + "description" : "This is default Component Node", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" } }, "data_types": { 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 93ea4c498..46b725f87 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 @@ -37,16 +37,15 @@ public class ServiceTemplateValidationTest { public void testBluePrintDirs() { List dirs = ConfigModelUtils.getBlueprintNames("load/blueprints"); Assert.assertNotNull("Failed to get blueprint directories", dirs); - Assert.assertEquals("Failed to get actual directories", 2, dirs.size()); + Assert.assertEquals("Failed to get actual directories", 1, dirs.size()); } @Test public void validateServiceTemplate() throws Exception { - validateServiceTemplate("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json"); validateServiceTemplate("load/blueprints/vrr-test/Definitions/vrr-test.json"); } - //@Test + @Test public void validateEnhancedServiceTemplate() throws Exception { ServiceTemplate serviceTemplate = JacksonUtils .readValueFromClassPathFile("enhance/enhanced-template.json", ServiceTemplate.class); 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 c3f257382..9f8af1aaf 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 @@ -215,6 +215,11 @@ }, "derived_from" : "tosca.nodes.DG" }, + "tosca.nodes.Component" : { + "description" : "This is default Component Node", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, "component-resource-assignment" : { "description" : "This is Resource Assignment Component API", "version" : "1.0.0", @@ -283,6 +288,11 @@ }, "derived_from" : "tosca.nodes.Component" }, + "tosca.nodes.DG" : { + "description" : "This is Directed Graph Node Type", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, "artifact-config-template" : { "description" : "This is Configuration Velocity Template", "version" : "1.0.0", @@ -361,6 +371,11 @@ }, "derived_from" : "tosca.nodes.Vnf" }, + "tosca.nodes.Vnf" : { + "description" : "This is VNF Node Type", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, "component-netconf-executor" : { "description" : "This is Netconf Transaction Configuration Component API", "version" : "1.0.0", @@ -386,12 +401,12 @@ "required" : true, "type" : "string" }, - "service-template-name" : { + "template-name" : { "description" : "Service Template Name", "required" : true, "type" : "string" }, - "service-template-version" : { + "template-version" : { "description" : "Service Template Version", "required" : true, "type" : "string" @@ -440,6 +455,11 @@ }, "derived_from" : "tosca.nodes.Component" }, + "tosca.nodes.Artifact" : { + "description" : "This is Deprecated Artifact Node Type.", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, "dg-activate-netconf" : { "description" : "This is Download Netconf Directed Graph", "version" : "1.0.0", @@ -571,8 +591,8 @@ }, "inputs" : { "action-name" : "{ \"get_input\" : \"action-name\" }", - "template_name" : "{ \"get_attribute\" : \"template_name\" }", - "service-template-version" : "{ \"get_attribute\" : \"service-template-version\" }", + "template-name" : "{ \"get_attribute\" : \"template_name\" }", + "template-version" : "{ \"get_attribute\" : \"template_version\" }", "resource-type" : "vnf-type", "request-id" : "{ \"get_input\" : \"request-id\" }", "resource-id" : "{ \"get_input\" : \"hostname\" }", -- cgit 1.2.3-korg From 9b85990c525fd20cca292bb30f9ba5b00f3d2a7e Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 7 Sep 2018 15:24:07 +0000 Subject: Controller Blueprints Microservice Add Capability Definition validations and add custom capabilities Types for content, mapping, netconf, ssh and sftp Change-Id: I6a89d20280852034ce6ee56d2a9e97d3aab9c2db Issue-ID: CCSDK-484 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../node_type/artifact-config-template.json | 4 +- .../model_type/node_type/dg-activate-netconf.json | 14 ------- .../model_type/node_type/dg-config-generator.json | 14 ------- .../node_type/dg-resource-assign-activate.json | 14 ------- .../node_type/dg-resource-assignment.json | 14 ------- .../model_type/node_type/vnf-netconf-device.json | 2 +- .../blueprints/vrr-test/Definitions/vrr-test.json | 38 +++-------------- .../service_template/default_netconf.json | 14 +++---- .../test/resources/enhance/enhance-template.json | 14 +------ .../test/resources/enhance/enhanced-template.json | 48 +++------------------- 10 files changed, 22 insertions(+), 154 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/model_type/node_type/artifact-config-template.json b/ms/controllerblueprints/application/load/model_type/node_type/artifact-config-template.json index be9bbfc0e..af99d75b8 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/artifact-config-template.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/artifact-config-template.json @@ -12,7 +12,7 @@ }, "capabilities": { "content": { - "type": "tosca.capability.Content", + "type": "tosca.capabilities.Content", "properties": { "content": { "required": true, @@ -21,7 +21,7 @@ } }, "mapping": { - "type": "tosca.capability.Mapping", + "type": "tosca.capabilities.Mapping", "properties": { "mapping": { "required": false, diff --git a/ms/controllerblueprints/application/load/model_type/node_type/dg-activate-netconf.json b/ms/controllerblueprints/application/load/model_type/node_type/dg-activate-netconf.json index a9d16eddc..57667de98 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/dg-activate-netconf.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/dg-activate-netconf.json @@ -21,20 +21,6 @@ "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": { diff --git a/ms/controllerblueprints/application/load/model_type/node_type/dg-config-generator.json b/ms/controllerblueprints/application/load/model_type/node_type/dg-config-generator.json index 6794b3c89..e59c34b6e 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/dg-config-generator.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/dg-config-generator.json @@ -21,20 +21,6 @@ "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": { diff --git a/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assign-activate.json b/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assign-activate.json index 22a4d813c..ca703a793 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assign-activate.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assign-activate.json @@ -21,20 +21,6 @@ "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": { diff --git a/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assignment.json b/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assignment.json index 7c01faa13..9cce82a9e 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assignment.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/dg-resource-assignment.json @@ -21,20 +21,6 @@ "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": { diff --git a/ms/controllerblueprints/application/load/model_type/node_type/vnf-netconf-device.json b/ms/controllerblueprints/application/load/model_type/node_type/vnf-netconf-device.json index 54573bade..246f17706 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/vnf-netconf-device.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/vnf-netconf-device.json @@ -3,7 +3,7 @@ "version": "1.0.0", "capabilities": { "netconf": { - "type": "tosca.capability.Netconf", + "type": "tosca.capabilities.Netconf", "properties": { "login-key": { "required": true, diff --git a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json index 724dfc4d6..5fe2d2510 100644 --- a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json +++ b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json @@ -274,20 +274,6 @@ "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": { @@ -398,7 +384,7 @@ }, "capabilities": { "content": { - "type": "tosca.capability.Content", + "type": "tosca.capabilities.Content", "properties": { "content": { "required": true, @@ -407,7 +393,7 @@ } }, "mapping": { - "type": "tosca.capability.Mapping", + "type": "tosca.capabilities.Mapping", "properties": { "mapping": { "required": false, @@ -426,7 +412,7 @@ "version": "1.0.0", "capabilities": { "netconf": { - "type": "tosca.capability.Netconf", + "type": "tosca.capabilities.Netconf", "properties": { "profile-name": { "required": true, @@ -449,7 +435,7 @@ } }, "ssh": { - "type": "tosca.capability.Ssh", + "type": "tosca.capabilities.Ssh", "properties": { "profile-name": { "required": true, @@ -477,7 +463,7 @@ } }, "sftp": { - "type": "tosca.capability.Sftp", + "type": "tosca.capabilities.Sftp", "properties": { "profile-name": { "required": true, @@ -530,20 +516,6 @@ "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": { diff --git a/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json b/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json index 14f724e54..8b1c7909a 100644 --- a/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json +++ b/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json @@ -279,7 +279,7 @@ "version": "1.0.0", "capabilities": { "netconf": { - "type": "tosca.capability.Netconf", + "type": "tosca.capabilities.Netconf", "properties": { "password": { "required": false, @@ -311,7 +311,7 @@ } }, "ssh": { - "type": "tosca.capability.Ssh", + "type": "tosca.capabilities.Ssh", "properties": { "password": { "required": false, @@ -343,7 +343,7 @@ } }, "sftp": { - "type": "tosca.capability.Sftp", + "type": "tosca.capabilities.Sftp", "properties": { "password": { "required": false, @@ -402,7 +402,7 @@ "type": "tosca.capabilities.Node" }, "content": { - "type": "tosca.capability.Content", + "type": "tosca.capabilities.Content", "properties": { "type": { "required": false, @@ -467,7 +467,7 @@ "type": "tosca.capabilities.Node" }, "content": { - "type": "tosca.capability.Content", + "type": "tosca.capabilities.Content", "properties": { "type": { "required": false, @@ -521,7 +521,7 @@ }, "capabilities": { "content": { - "type": "tosca.capability.Content", + "type": "tosca.capabilities.Content", "properties": { "content": { "required": true, @@ -530,7 +530,7 @@ } }, "mapping": { - "type": "tosca.capability.Mapping", + "type": "tosca.capabilities.Mapping", "properties": { "mapping": { "required": false, 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 155dc7235..d5d3f6698 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 @@ -128,12 +128,7 @@ } }, "capabilities": { - "dg-node": {}, - "content": { - "properties": { - "type": "json" - } - } + "dg-node": {} }, "interfaces": { "CONFIG": { @@ -162,12 +157,7 @@ } }, "capabilities": { - "dg-node": {}, - "content": { - "properties": { - "type": "json" - } - } + "dg-node": {} }, "interfaces": { "CONFIG": { 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 9f8af1aaf..b6898d845 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 @@ -173,20 +173,6 @@ "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" : { @@ -307,7 +293,7 @@ }, "capabilities" : { "content" : { - "type" : "tosca.capability.Content", + "type" : "tosca.capabilities.Content", "properties" : { "content" : { "required" : true, @@ -316,7 +302,7 @@ } }, "mapping" : { - "type" : "tosca.capability.Mapping", + "type" : "tosca.capabilities.Mapping", "properties" : { "mapping" : { "required" : false, @@ -335,7 +321,7 @@ "version" : "1.0.0", "capabilities" : { "netconf" : { - "type" : "tosca.capability.Netconf", + "type" : "tosca.capabilities.Netconf", "properties" : { "login-key" : { "required" : true, @@ -483,20 +469,6 @@ "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" : { @@ -642,12 +614,7 @@ "is-start-flow" : false }, "capabilities" : { - "dg-node" : { }, - "content" : { - "properties" : { - "type" : "json" - } - } + "dg-node" : { } }, "requirements" : { "component-dependency" : { @@ -676,12 +643,7 @@ "is-start-flow" : false }, "capabilities" : { - "dg-node" : { }, - "content" : { - "properties" : { - "type" : "json" - } - } + "dg-node" : { } }, "requirements" : { "component-dependency" : { -- cgit 1.2.3-korg From cd95bfda8f81a9aa34e1986e352b19e57488e1ae Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 7 Sep 2018 19:20:59 +0000 Subject: Controller Blueprints Microservice Remove Resource Dictionary resource_type, resource_path, sample_values and valid_values parameters. Change-Id: I7ec899e30aaef64130f35eb754a79f9dfc54f71f Issue-ID: CCSDK-488 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../load/resource_dictionary/db-source.json | 24 ++++++++++ .../load/resource_dictionary/input-source.json | 17 ++++++++ .../load/resource_dictionary/v4-ip-type.json | 17 ++++++++ .../src/main/resources/sql/schema-local.sql | 4 -- .../application/src/main/resources/sql/schema.sql | 4 -- .../load/resource_dictionary/db-source.json | 26 ----------- .../load/resource_dictionary/input-source.json | 19 -------- .../load/resource_dictionary/v4-ip-type.json | 19 -------- .../service/DataBaseInitService.java | 34 +++++++-------- .../service/ResourceDictionaryService.java | 4 -- .../service/domain/ResourceDictionary.java | 51 ---------------------- .../validator/ResourceDictionaryValidator.java | 4 -- .../src/main/resources/sql/schema-local.sql | 4 -- .../service/src/main/resources/sql/schema.sql | 4 -- .../ResourceDictionaryReactRepositoryTest.java | 4 +- .../service/rs/ResourceDictionaryRestTest.java | 3 -- .../src/test/resources/application.properties | 43 +----------------- .../resourcedictionary/default_definition.json | 2 - 18 files changed, 76 insertions(+), 207 deletions(-) create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/db-source.json create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/input-source.json create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/v4-ip-type.json delete mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json delete mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json delete mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/resource_dictionary/db-source.json b/ms/controllerblueprints/application/load/resource_dictionary/db-source.json new file mode 100644 index 000000000..a0c78af06 --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/db-source.json @@ -0,0 +1,24 @@ +{ + "name": "db-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "tags": "db-source, 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/application/load/resource_dictionary/input-source.json b/ms/controllerblueprints/application/load/resource_dictionary/input-source.json new file mode 100644 index 000000000..acfad16bb --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/input-source.json @@ -0,0 +1,17 @@ +{ + "name": "input-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "tags": "action-name, brindasanth", + "sources": { + "input": { + "type": "source-input", + "properties": { + "key": "action-name" + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/resource_dictionary/v4-ip-type.json b/ms/controllerblueprints/application/load/resource_dictionary/v4-ip-type.json new file mode 100644 index 000000000..1b4432d53 --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/v4-ip-type.json @@ -0,0 +1,17 @@ +{ + "name": "v4-ip-type", + "property": { + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "tags": "v4-ip-type, source-input, brindasanth", + "sources": { + "input": { + "type": "source-input", + "properties": { + "key": "v4-ip-type" + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/src/main/resources/sql/schema-local.sql b/ms/controllerblueprints/application/src/main/resources/sql/schema-local.sql index 1ba9c365a..47e0cce7a 100644 --- a/ms/controllerblueprints/application/src/main/resources/sql/schema-local.sql +++ b/ms/controllerblueprints/application/src/main/resources/sql/schema-local.sql @@ -71,12 +71,8 @@ CREATE TABLE IF NOT EXISTS sdnctl.MODEL_TYPE ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS sdnctl.RESOURCE_DICTIONARY ( name VARCHAR(100) NOT NULL, - resource_path VARCHAR(500) NOT NULL, - resource_type VARCHAR(100) NOT NULL, data_type VARCHAR(100) NOT NULL, entry_schema VARCHAR(100) NULL DEFAULT NULL, - valid_values LONGTEXT NULL DEFAULT NULL, - sample_value LONGTEXT NULL DEFAULT NULL, definition LONGTEXT NOT NULL, description LONGTEXT NOT NULL, tags LONGTEXT NOT NULL, diff --git a/ms/controllerblueprints/application/src/main/resources/sql/schema.sql b/ms/controllerblueprints/application/src/main/resources/sql/schema.sql index b884cf345..9c38bec0b 100644 --- a/ms/controllerblueprints/application/src/main/resources/sql/schema.sql +++ b/ms/controllerblueprints/application/src/main/resources/sql/schema.sql @@ -66,12 +66,8 @@ CREATE TABLE IF NOT EXISTS configurator.MODEL_TYPE ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS configurator.RESOURCE_DICTIONARY ( name VARCHAR(100) NOT NULL, - resource_path VARCHAR(500) NOT NULL, - resource_type VARCHAR(100) NOT NULL, data_type VARCHAR(100) NOT NULL, entry_schema VARCHAR(100) NULL DEFAULT NULL, - valid_values LONGTEXT NULL DEFAULT NULL, - sample_value LONGTEXT NULL DEFAULT NULL, definition LONGTEXT NOT NULL, description LONGTEXT NOT NULL, tags LONGTEXT NOT NULL, diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json deleted file mode 100644 index ba86b3c79..000000000 --- a/ms/controllerblueprints/modules/service/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": "db-source, 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/service/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json deleted file mode 100644 index 7cd58d618..000000000 --- a/ms/controllerblueprints/modules/service/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": "action-name, brindasanth", - "sources": { - "input": { - "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 deleted file mode 100644 index e7e06000c..000000000 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "v4-ip-type", - "property": { - "description": "name of the ", - "type": "string" - }, - "resource-path": "vnf/v4-ip-type", - "resource-type": "ONAP", - "updated-by": "brindasanth@onap.com", - "tags": "v4-ip-type, source-input, brindasanth", - "sources": { - "input": { - "type": "source-input", - "properties": { - "key": "v4-ip-type" - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/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 c6d80cfb6..cfcf93d29 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 @@ -157,30 +157,28 @@ public class DataBaseInitService { fileName = file.getFilename(); log.trace("Loading : {}", fileName); String definitionContent = getResourceContent(file); - ResourceDefinition dictionaryDefinition = + ResourceDefinition resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition.class); - if (dictionaryDefinition != null) { - Preconditions.checkNotNull(dictionaryDefinition.getProperty(), "Failed to get Property Definition"); + if (resourceDefinition != null) { + Preconditions.checkNotNull(resourceDefinition.getProperty(), "Failed to get Property Definition"); ResourceDictionary resourceDictionary = new ResourceDictionary(); - resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath()); - resourceDictionary.setName(dictionaryDefinition.getName()); - resourceDictionary.setDefinition(dictionaryDefinition); - - resourceDictionary.setResourceType(dictionaryDefinition.getResourceType()); - resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription()); - resourceDictionary.setDataType(dictionaryDefinition.getProperty().getType()); - if(dictionaryDefinition.getProperty().getEntrySchema() != null){ - resourceDictionary.setEntrySchema(dictionaryDefinition.getProperty().getEntrySchema().getType()); + resourceDictionary.setName(resourceDefinition.getName()); + resourceDictionary.setDefinition(resourceDefinition); + + Preconditions.checkNotNull(resourceDefinition.getProperty(), "Property field is missing"); + resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); + resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); + if(resourceDefinition.getProperty().getEntrySchema() != null){ + resourceDictionary.setEntrySchema(resourceDefinition.getProperty().getEntrySchema().getType()); } - resourceDictionary.setUpdatedBy(dictionaryDefinition.getUpdatedBy()); - if (StringUtils.isBlank(dictionaryDefinition.getTags())) { + resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); + if (StringUtils.isBlank(resourceDefinition.getTags())) { resourceDictionary.setTags( - dictionaryDefinition.getName() + ", " + dictionaryDefinition.getUpdatedBy() - + ", " + dictionaryDefinition.getResourceType() + ", " - + dictionaryDefinition.getUpdatedBy()); + resourceDefinition.getName() + ", " + resourceDefinition.getUpdatedBy() + + ", " + resourceDefinition.getUpdatedBy()); } else { - resourceDictionary.setTags(dictionaryDefinition.getTags()); + resourceDictionary.setTags(resourceDefinition.getTags()); } resourceDictionaryService.saveResourceDictionary(resourceDictionary); 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 70e43d699..62aa0e29c 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 @@ -112,8 +112,6 @@ public class ResourceDictionaryService { // Validate the Resource Definitions resourceDictionaryValidationService.validate(resourceDefinition); - resourceDictionary.setResourceType(resourceDefinition.getResourceType()); - resourceDictionary.setResourcePath(resourceDefinition.getResourcePath()); resourceDictionary.setTags(resourceDefinition.getTags()); resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); // Set the Property Definitions @@ -134,8 +132,6 @@ public class ResourceDictionaryService { dbResourceDictionary.setName(resourceDictionary.getName()); dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); dbResourceDictionary.setDescription(resourceDictionary.getDescription()); - dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); - dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); dbResourceDictionary.setTags(resourceDictionary.getTags()); dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy()); dbResourceDictionary.setDataType(resourceDictionary.getDataType()); 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 7af9972a6..42c8e83b2 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 @@ -43,14 +43,6 @@ public class ResourceDictionary implements Serializable { @ApiModelProperty(required=true) private String name; - @Column(name = "resource_path", nullable = false) - @ApiModelProperty(required=true) - private String resourcePath; - - @Column(name = "resource_type", nullable = false) - @ApiModelProperty(required=true) - private String resourceType; - @Column(name = "data_type", nullable = false) @ApiModelProperty(required=true) private String dataType; @@ -58,14 +50,6 @@ public class ResourceDictionary implements Serializable { @Column(name = "entry_schema") private String entrySchema; - @Lob - @Column(name = "valid_values") - private String validValues; - - @Lob - @Column(name = "sample_value") - private String sampleValue; - @Lob @Convert(converter = JpaResourceDefinitionConverter.class) @Column(name = "definition", nullable = false) @@ -95,11 +79,8 @@ public class ResourceDictionary implements Serializable { @Override public String toString() { String buffer = "[" + ", name = " + name + - ", resourcePath = " + resourcePath + - ", resourceType = " + resourceType + ", dataType = " + dataType + ", entrySchema = " + entrySchema + - ", validValues = " + validValues + ", definition =" + definition + ", description = " + description + ", updatedBy = " + updatedBy + @@ -109,14 +90,6 @@ public class ResourceDictionary implements Serializable { return buffer; } - public String getResourcePath() { - return resourcePath; - } - - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - public String getName() { return name; } @@ -125,14 +98,6 @@ public class ResourceDictionary implements Serializable { this.name = name; } - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - public String getDataType() { return dataType; } @@ -149,22 +114,6 @@ public class ResourceDictionary implements Serializable { this.entrySchema = entrySchema; } - public String getValidValues() { - return validValues; - } - - public void setValidValues(String validValues) { - this.validValues = validValues; - } - - public String getSampleValue() { - return sampleValue; - } - - public void setSampleValue(String sampleValue) { - this.sampleValue = sampleValue; - } - public ResourceDefinition getDefinition() { return definition; } 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 index 1c2a7337b..57330d90f 100644 --- 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 @@ -45,10 +45,6 @@ public class ResourceDictionaryValidator { Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getName()), "DataDictionary Alias Name Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourcePath()), - "DataDictionary Resource Name Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourceType()), - "DataDictionary Resource Type Information is missing."); Preconditions.checkNotNull( resourceDictionary.getDefinition(), "DataDictionary Definition Information is missing."); Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()), diff --git a/ms/controllerblueprints/modules/service/src/main/resources/sql/schema-local.sql b/ms/controllerblueprints/modules/service/src/main/resources/sql/schema-local.sql index 1ba9c365a..47e0cce7a 100644 --- a/ms/controllerblueprints/modules/service/src/main/resources/sql/schema-local.sql +++ b/ms/controllerblueprints/modules/service/src/main/resources/sql/schema-local.sql @@ -71,12 +71,8 @@ CREATE TABLE IF NOT EXISTS sdnctl.MODEL_TYPE ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS sdnctl.RESOURCE_DICTIONARY ( name VARCHAR(100) NOT NULL, - resource_path VARCHAR(500) NOT NULL, - resource_type VARCHAR(100) NOT NULL, data_type VARCHAR(100) NOT NULL, entry_schema VARCHAR(100) NULL DEFAULT NULL, - valid_values LONGTEXT NULL DEFAULT NULL, - sample_value LONGTEXT NULL DEFAULT NULL, definition LONGTEXT NOT NULL, description LONGTEXT NOT NULL, tags LONGTEXT NOT NULL, diff --git a/ms/controllerblueprints/modules/service/src/main/resources/sql/schema.sql b/ms/controllerblueprints/modules/service/src/main/resources/sql/schema.sql index b884cf345..9c38bec0b 100644 --- a/ms/controllerblueprints/modules/service/src/main/resources/sql/schema.sql +++ b/ms/controllerblueprints/modules/service/src/main/resources/sql/schema.sql @@ -66,12 +66,8 @@ CREATE TABLE IF NOT EXISTS configurator.MODEL_TYPE ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS configurator.RESOURCE_DICTIONARY ( name VARCHAR(100) NOT NULL, - resource_path VARCHAR(500) NOT NULL, - resource_type VARCHAR(100) NOT NULL, data_type VARCHAR(100) NOT NULL, entry_schema VARCHAR(100) NULL DEFAULT NULL, - valid_values LONGTEXT NULL DEFAULT NULL, - sample_value LONGTEXT NULL DEFAULT NULL, definition LONGTEXT NOT NULL, description LONGTEXT NOT NULL, tags LONGTEXT NOT NULL, diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java index 1e740ec33..7034b7e23 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java @@ -51,7 +51,7 @@ public class ResourceDictionaryReactRepositoryTest { @Before public void init() { - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("load/resource_dictionary/db-source" + + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("./../../application/load/resource_dictionary/db-source" + ".json", ResourceDefinition.class); ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition); @@ -84,8 +84,6 @@ public class ResourceDictionaryReactRepositoryTest { resourceDictionary.setName(resourceDefinition.getName()); resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); - resourceDictionary.setResourcePath(resourceDefinition.getResourcePath()); - resourceDictionary.setResourceType(resourceDefinition.getResourceType()); resourceDictionary.setTags(resourceDefinition.getTags()); resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); resourceDictionary.setDefinition(resourceDefinition); 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 82346954c..5955ae191 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 @@ -58,11 +58,8 @@ public class ResourceDictionaryRestTest { Charset.defaultCharset()); ResourceDictionary dataDictionary = new ResourceDictionary(); - dataDictionary.setResourcePath("test/vnf/ipaddress"); dataDictionary.setName("test-name"); dataDictionary.setDefinition(JacksonUtils.readValue(definition, ResourceDefinition.class)); - dataDictionary.setValidValues("127.0.0.1"); - dataDictionary.setResourceType("ONAP"); dataDictionary.setDataType("string"); dataDictionary.setDescription("Sample Resource Mapping"); dataDictionary.setTags("test, ipaddress"); diff --git a/ms/controllerblueprints/modules/service/src/test/resources/application.properties b/ms/controllerblueprints/modules/service/src/test/resources/application.properties index b17663e9a..429588b31 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/application.properties +++ b/ms/controllerblueprints/modules/service/src/test/resources/application.properties @@ -15,47 +15,6 @@ # limitations under the License. # -info.build.artifact=@project.artifactId@ -info.build.name=@project.name@ -info.build.description=@project.description@ -info.build.version=@project.version@ -info.build.groupId=@project.groupId@ -logging.level.root=info - -server.contextPath=/ -server.servlet-path=/ -spring.jersey.application-path=/api/controller-blueprints/v1 -server.routingPath=/api - - -mots.application.acronym=MOTS_ID -platform.identifier=AJSC7_JERSEY -#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - -#logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr($ threadId: {PID:- }){magenta} %clr(---){faint} %clr([ hostname: %X{hostname} serviceName: %X{serviceName} version: %X{version} transactionId: %X{transactionId} requestTimeStamp: %X{requestTimestamp} responseTimeStamp: %X{responseTimestamp} duration: %X{duration}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex - - -#The max number of active threads in this pool -server.tomcat.max-threads=200 -#The minimum number of threads always kept alive -server.tomcat.min-Spare-Threads=25 -#The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads -server.tomcat.max-idle-time=60000 - -#for changing the tomcat port... -#server.port=8081 - - - -#Servlet context parameters -server.context_parameters.p-name=value #context parameter with p-name as key and value as value. - -# make this true for AAF authentication and place cadi.properties into etc folder -aaf.enabled=true - -# set to true to enable version proxy -#ivp.enabled=false - spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false @@ -68,5 +27,5 @@ blueprints.load.initial-data=true load.dataTypePath=./../../application/load/model_type/data_type load.nodeTypePath=./../../application/load/model_type/node_type load.artifactTypePath=./../../application/load/model_type/artifact_type -load.resourceDictionaryPath=load/resource_dictionary +load.resourceDictionaryPath=./../../application/load/resource_dictionary load.blueprintsPath=./../../application/load/blueprints \ No newline at end of file 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 198823bb1..334fb24e8 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 @@ -8,8 +8,6 @@ } }, "updated-by": "Brinda Santh (bs2796)", - "resource-type": "ONAP", - "resource-path": "/v4-aggregat-list", "tags": "ipaddress", "sources": { "input": { -- cgit 1.2.3-korg From 08ddd6710c307a972dcf4918aeaa554f0b8d0299 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 7 Sep 2018 22:43:20 +0000 Subject: Controller Blueprints Microservice Modify get_input, get_attribute, get_property and get_artifact functions string implementation to Json Implementation. Change-Id: I6d4aadd370dc23127a176964f84fc9bb5e7ab5ee Issue-ID: CCSDK-432 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../Definitions/activation-blueprint.json | 180 +++++++++------------ .../node_type/component-resource-assignment.json | 6 +- .../blueprints/vrr-test/Definitions/vrr-test.json | 98 ++++++----- .../service_template/default_netconf.json | 46 ++---- .../test/resources/enhance/enhance-template.json | 67 ++++++-- .../test/resources/enhance/enhanced-template.json | 60 +++++-- 6 files changed, 243 insertions(+), 214 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json b/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json index d4fbf5cf4..06e7e9303 100644 --- a/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json +++ b/ms/controllerblueprints/application/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json @@ -2,7 +2,7 @@ "metadata": { "template_author": "Brinda Santh Muthuramalingam", "author-email": "brindasanth@gmail.com", - "user-groups" : "ADMIN, OPERATION", + "user-groups": "ADMIN, OPERATION", "template_name": "baseconfiguration", "template_version": "1.0.0", "template_tags": "brinda, tosca" @@ -30,9 +30,21 @@ "activate-process": { "type": "bpmn-activate", "properties": { - "process-name": { "get_input" : "action-name" }, - "version" : { "get_property" : ["SELF", "process-name"] }, - "content": { "get_artifact" : ["SELF", "activate-process"] } + "process-name": { + "get_input": "action-name" + }, + "version": { + "get_property": [ + "SELF", + "process-name" + ] + }, + "content": { + "get_artifact": [ + "SELF", + "activate-process" + ] + } }, "artifacts": { "activate-process": { @@ -43,7 +55,7 @@ }, "resource-assignment": { "type": "component-resource-assignment", - "properties":{ + "properties": { "request-id": "1234" }, "interfaces": { @@ -51,12 +63,28 @@ "operations": { "process": { "inputs": { - "action-name": { "get_input" : "action-name" }, + "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"] } + "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": "", @@ -79,18 +107,20 @@ }, "resource-assignment-py": { "type": "component-resource-assignment", - "properties":{ + "properties": { "request-id": "1234" }, "interfaces": { "DefaultComponentNode": { "operations": { "process": { - "implementation" :{ - "primary" : "component-script" + "implementation": { + "primary": "component-script" }, "inputs": { - "action-name": { "get_input" : "action-name" } + "action-name": { + "get_input": "action-name" + } }, "outputs": { "resource-assignment-params": "", @@ -108,37 +138,37 @@ } } }, - "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" : [ + "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" : [ + "on_success": [ "download-licence" ] }, - "download-licence" : { - "description" : "Call Download Licence Component", - "target" : "activate-netconf", - "activities" : [ + "download-licence": { + "description": "Call Download Licence Component", + "target": "activate-netconf", + "activities": [ { "call_operation": "NetconfTransactionNode.process" } @@ -214,7 +244,7 @@ "version": { "required": false, "type": "string", - "default" : "LATEST" + "default": "LATEST" } }, "derived_from": "tosca.nodes.DG" @@ -222,74 +252,16 @@ "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.DG" : { - "description" : "This is Directed Graph Node Type", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" + "tosca.nodes.DG": { + "description": "This is Directed Graph Node Type", + "version": "1.0.0", + "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": { @@ -392,7 +364,7 @@ } }, "data_types": { - "sample-property" : { + "sample-property": { "description": "This is sample data type", "version": "1.0.0", "properties": { @@ -407,10 +379,10 @@ "version": { "required": false, "type": "string", - "default" : "LATEST" + "default": "LATEST" } }, - "derived_from" : "tosca.datatypes.Root" + "derived_from": "tosca.datatypes.Root" } } } \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/model_type/node_type/component-resource-assignment.json b/ms/controllerblueprints/application/load/model_type/node_type/component-resource-assignment.json index 34c028482..d424a8e43 100644 --- a/ms/controllerblueprints/application/load/model_type/node_type/component-resource-assignment.json +++ b/ms/controllerblueprints/application/load/model_type/node_type/component-resource-assignment.json @@ -7,16 +7,16 @@ } }, "interfaces": { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { - "service-template-name": { + "template-name": { "description": "Service Template Name.", "required": true, "type": "string" }, - "service-template-version": { + "template-version": { "description": "Service Template Version.", "required": true, "type": "string" diff --git a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json index 5fe2d2510..41f6e92f0 100644 --- a/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json +++ b/ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json @@ -3,7 +3,7 @@ "template_author": "Brinda Santh ( bs2796@onap.com )", "template_name": "vrr-test", "template_version": "1.0.0", - "template_tags" : "brinda, VRR", + "template_tags": "brinda, VRR", "release": "201802", "service-type": "AVPN", "vnf-type": "VRR" @@ -172,20 +172,30 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { - "service-template-name": "{ \"get_attribute\" : \"template_name\" }", - "service-template-version": "{ \"get_attribute\" : \"service-template-version\" }", - "action-name": "{ \"get_input\" : \"action-name\" }", + "template-name": { + "get_input": "template_name" + }, + "template-version": { + "get_input": "template_version" + }, + "action-name": { + "get_input": "action-name" + }, "resource-type": "vnf-type", "template-names": [ "base-config-template", "licence-template" ], - "request-id": "{ \"get_input\" : \"request-id\" }", - "resource-id": "{ \"get_input\" : \"vnf-id\" }" + "request-id": { + "get_input": "request-id" + }, + "resource-id": { + "get_input": "vnf-id" + } }, "outputs": { "resource-assignment-params": "", @@ -205,8 +215,12 @@ "netconf": { "properties": { "profile-name": "sample", - "oam-ipv4-address": "{ \"get_attribute\" : \"hostname\" }", - "port-number": { "get_input" : "host-port" }, + "oam-ipv4-address": { + "get_input": "hostname" + }, + "port-number": { + "get_input": "host-port" + }, "connection-time-out": 30 } } @@ -218,19 +232,29 @@ "org-openecomp-sdnc-netconf-adaptor-service-NetconfExecutorNode": { "operations": { "process": { - "implementation" : { - "primary" : "file://netconf-adaptor/DefaultGetConfig.py" + "implementation": { + "primary": "file://netconf-adaptor/DefaultGetConfig.py" }, "inputs": { - "action-name": "{ \"get_input\" : \"action-name\" }", + "action-name": { + "get_input": "action-name" + }, "resource-type": "vnf-type", - "request-id": "{ \"get_attribute\" : \"request-id\" }", - "resource-id": "{ \"get_input\" : \"vnf-id\" }", + "request-id": { + "get_input": "request-id" + }, + "resource-id": { + "get_input": "vnf-id" + }, "execution-script": "execution-script" }, "outputs": { - "response-data": "{ \"get_attribute\" : \"netconf-executor-baseconfig.response-data\" }", - "status": "{ \"get_attribute\" : \"netconf-executor-baseconfig.status\" }" + "response-data": { + "get_attribute": ["SELF", "netconf-executor-baseconfig.response-data"] + }, + "status": { + "get_attribute": ["SELF", "netconf-executor-baseconfig.status"] + } } } } @@ -311,7 +335,7 @@ } }, "interfaces": { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -320,12 +344,12 @@ "required": true, "type": "string" }, - "service-template-name": { + "template-name": { "description": "Service Template Name.", "required": true, "type": "string" }, - "service-template-version": { + "template-version": { "description": "Service Template Version.", "required": true, "type": "string" @@ -569,12 +593,12 @@ "required": true, "type": "string" }, - "service-template-name": { + "template-name": { "description": "Service Template Name", "required": true, "type": "string" }, - "service-template-version": { + "template-version": { "description": "Service Template Version", "required": true, "type": "string" @@ -617,25 +641,25 @@ }, "derived_from": "tosca.nodes.Component" }, - "tosca.nodes.DG" : { - "description" : "This is Directed Graph Node Type", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" + "tosca.nodes.DG": { + "description": "This is Directed Graph Node Type", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" }, - "tosca.nodes.Vnf" : { - "description" : "This is VNF Node Type", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" + "tosca.nodes.Vnf": { + "description": "This is VNF Node Type", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" }, - "tosca.nodes.Artifact" : { - "description" : "This is Deprecated Artifact Node Type.", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" + "tosca.nodes.Artifact": { + "description": "This is Deprecated Artifact Node Type.", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" }, - "tosca.nodes.Component" : { - "description" : "This is default Component Node", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" + "tosca.nodes.Component": { + "description": "This is default Component Node", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" } }, "data_types": { diff --git a/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json b/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json index 8b1c7909a..5b5332fce 100644 --- a/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json +++ b/ms/controllerblueprints/modules/service/src/main/resources/service_template/default_netconf.json @@ -13,11 +13,11 @@ "required": true, "type": "string" }, - "service-template-name": { + "template-name": { "required": true, "type": "string" }, - "service-template-version": { + "template-version": { "required": true, "type": "string" }, @@ -146,7 +146,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -155,8 +155,8 @@ "base-config-template", "licence-template" ], - "request-id": "{ \"get_attribute\" : \"request-id\" }", - "resource-id": "{ \"get_input\" : \"vnf-id\" }" + "request-id": { "get_input" : "request-id" }, + "resource-id": { "get_input" : "vnf-id" } }, "outputs": { "resource-assignment-params": "", @@ -220,10 +220,10 @@ ], "resource-type": "vnf-type", "initialise-sftp": false, - "request-id": "{ \"get_input\" : \"request-id\" }", + "request-id": {"get_input" : "request-id"}, "initialise-ssh": false, - "resource-id": "{ \"get_input\" : \"vnf-id\" }", - "action-name": "{ \"get_input\" : \"action-name\" }" + "resource-id": { "get_input" : "vnf-id" }, + "action-name": {"get_input" : "action-name"} }, "outputs": { "rpc-response-message": "", @@ -400,20 +400,6 @@ "capabilities": { "dg-node": { "type": "tosca.capabilities.Node" - }, - "content": { - "type": "tosca.capabilities.Content", - "properties": { - "type": { - "required": false, - "type": "string", - "default": "json" - }, - "content": { - "required": true, - "type": "string" - } - } } }, "requirements": { @@ -465,20 +451,6 @@ "capabilities": { "dg-node": { "type": "tosca.capabilities.Node" - }, - "content": { - "type": "tosca.capabilities.Content", - "properties": { - "type": { - "required": false, - "type": "string", - "default": "json" - }, - "content": { - "required": true, - "type": "string" - } - } } }, "requirements": { @@ -553,7 +525,7 @@ } }, "interfaces": { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { 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 d5d3f6698..70d03e0a8 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 @@ -39,7 +39,12 @@ "login-key": "sdnc", "login-account": "sndc-local", "source": "local", - "target-ip-address": "{\"get_attribute\":\"lo0-local-ipv4-address\"}", + "target-ip-address": { + "get_attribute": [ + "SELF", + "lo0-local-ipv4-address" + ] + }, "port-number": 22, "connection-time-out": 30 } @@ -63,20 +68,40 @@ "operations": { "process": { "inputs": { - "action-name": "{ \"get_input\" : \"action-name\" }", - "template-name": "{ \"get_attribute\" : \"template_name\" }", - "template-version": "{ \"get_attribute\" : \"template_version\" }", + "action-name": { + "get_input": "action-name" + }, + "template-name": { + "get_input": "template_name" + }, + "template-version": { + "get_input": "template_version" + }, "resource-type": "vnf-type", - "request-id": "{ \"get_input\" : \"request-id\" }", - "resource-id": "{ \"get_input\" : \"hostname\" }", + "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\" }" + "response-data": { + "get_attribute": [ + "SELF", + "netconf-executor-baseconfig.response-data" + ] + }, + "status": { + "get_attribute": [ + "SELF", + "netconf-executor-baseconfig.status" + ] + } }, - "implementation" : { - "primary" : "file://netconf_adaptor/DefaultBaseLicenceConfig.py" + "implementation": { + "primary": "file://netconf_adaptor/DefaultBaseLicenceConfig.py" } } } @@ -89,7 +114,7 @@ "component-node": {} }, "interfaces": { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -97,12 +122,22 @@ "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\" }", + "action-name": { + "get_input": "action-name" + }, + "template-name": { + "get_input": "template_name" + }, + "template-version": { + "get_input": "template-version" + }, "resource-type": "vnf-type", - "request-id": "{ \"get_input\" : \"request-id\" }", - "resource-id": "{ \"get_input\" : \"hostname\" }" + "request-id": { + "get_input": "request-id" + }, + "resource-id": { + "get_input": "hostname" + } }, "outputs": { "resource-assignment-params": "success", 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 b6898d845..bf3deffb5 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 @@ -215,16 +215,16 @@ } }, "interfaces" : { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode" : { + "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode" : { "operations" : { "process" : { "inputs" : { - "service-template-name" : { + "template-name" : { "description" : "Service Template Name.", "required" : true, "type" : "string" }, - "service-template-version" : { + "template-version" : { "description" : "Service Template Version.", "required" : true, "type" : "string" @@ -535,7 +535,9 @@ "login-key" : "sdnc", "login-account" : "sndc-local", "source" : "local", - "target-ip-address" : "{\"get_attribute\":\"lo0-local-ipv4-address\"}", + "target-ip-address" : { + "get_attribute" : [ "SELF", "lo0-local-ipv4-address" ] + }, "port-number" : 22, "connection-time-out" : 30 } @@ -562,17 +564,31 @@ "primary" : "file://netconf_adaptor/DefaultBaseLicenceConfig.py" }, "inputs" : { - "action-name" : "{ \"get_input\" : \"action-name\" }", - "template-name" : "{ \"get_attribute\" : \"template_name\" }", - "template-version" : "{ \"get_attribute\" : \"template_version\" }", + "action-name" : { + "get_input" : "action-name" + }, + "template-name" : { + "get_input" : "template_name" + }, + "template-version" : { + "get_input" : "template_version" + }, "resource-type" : "vnf-type", - "request-id" : "{ \"get_input\" : \"request-id\" }", - "resource-id" : "{ \"get_input\" : \"hostname\" }", + "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\" }" + "response-data" : { + "get_attribute" : [ "SELF", "netconf-executor-baseconfig.response-data" ] + }, + "status" : { + "get_attribute" : [ "SELF", "netconf-executor-baseconfig.status" ] + } } } } @@ -585,17 +601,27 @@ "component-node" : { } }, "interfaces" : { - "org-openecomp-sdnc-config-assignment-service-ConfigAssignmentNode" : { + "org-onap-ccsdk-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\" }", + "action-name" : { + "get_input" : "action-name" + }, + "template-name" : { + "get_input" : "template_name" + }, + "template-version" : { + "get_input" : "template-version" + }, "resource-type" : "vnf-type", - "request-id" : "{ \"get_input\" : \"request-id\" }", - "resource-id" : "{ \"get_input\" : \"hostname\" }" + "request-id" : { + "get_input" : "request-id" + }, + "resource-id" : { + "get_input" : "hostname" + } }, "outputs" : { "resource-assignment-params" : "success", -- cgit 1.2.3-korg From f191f4bbfeb8802ed2b223ad13149aa0f31242b6 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 9 Sep 2018 22:00:59 -0400 Subject: Controller Blueprints Microservice Add ModelType and Resource Dictionary reactor repository service and junit test cases for reactor repositories. Change-Id: Id358082739f81d18b534c224dc7472355e21f026 Issue-ID: CCSDK-491 Signed-off-by: Brinda Santh --- .../service/ModelTypeService.java | 88 +++++---------- .../repository/ResourceDictionaryRepository.java | 10 +- .../repository/BluePrintsReactRepository.kt | 76 +++++++++++++ .../ResourceDictionaryReactRepository.kt | 8 +- .../service/ModelTypeServiceTest.java | 123 +++++++++++++++++++++ .../repository/ModelTypeReactRepositoryTest.java | 110 ++++++++++++++++++ .../ResourceDictionaryReactRepositoryTest.java | 30 +++-- 7 files changed, 367 insertions(+), 78 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java index 2bc2963b6..925a6c492 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.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.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; @@ -43,7 +45,7 @@ public class ModelTypeService { /** * This is a ModelTypeService, used to save and get the model types stored in database * - * @param modelTypeRepository + * @param modelTypeRepository modelTypeRepository */ public ModelTypeService(ModelTypeRepository modelTypeRepository) { this.modelTypeRepository = modelTypeRepository; @@ -53,19 +55,15 @@ public class ModelTypeService { /** * This is a getModelTypeByName service * - * @param modelTypeName + * @param modelTypeName modelTypeName * @return ModelType - * @throws BluePrintException */ - public ModelType getModelTypeByName(String modelTypeName) throws BluePrintException { + public ModelType getModelTypeByName(String modelTypeName) { ModelType modelType = null; - if (StringUtils.isNotBlank(modelTypeName)) { - Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); - if (modelTypeOption.isPresent()) { - modelType = modelTypeOption.get(); - } - } else { - throw new BluePrintException("Model Name Information is missing."); + Preconditions.checkArgument(StringUtils.isNotBlank(modelTypeName), "Model Name Information is missing."); + Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); + if (modelTypeOption.isPresent()) { + modelType = modelTypeOption.get(); } return modelType; } @@ -74,27 +72,25 @@ public class ModelTypeService { /** * This is a searchModelTypes service * - * @param tags + * @param tags tags * @return List - * @throws BluePrintException */ - public List searchModelTypes(String tags) throws BluePrintException { - if (tags != null) { - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchModelTypes(String tags) { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No Search Information provide"); + return modelTypeRepository.findByTagsContainingIgnoreCase(tags); } /** * This is a saveModel service * - * @param modelType + * @param modelType modelType * @return ModelType - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ModelType saveModel(ModelType modelType) throws BluePrintException { + Preconditions.checkNotNull(modelType, "Model Type Information is missing."); + ModelTypeValidator.validateModelType(modelType); Optional dbModelType = modelTypeRepository.findByModelName(modelType.getModelName()); @@ -118,60 +114,34 @@ public class ModelTypeService { /** * This is a deleteByModelName service * - * @param modelName - * @throws BluePrintException + * @param modelName modelName */ - public void deleteByModelName(String modelName) throws BluePrintException { - if (modelName != null) { - modelTypeRepository.deleteByModelName(modelName); - } else { - throw new BluePrintException("Model Name Information is missing."); - } - } + public void deleteByModelName(String modelName) { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Model Name Information is missing."); + modelTypeRepository.deleteByModelName(modelName); - /** - * This is a getModelTypeByTags service - * - * @param tags - * @return List - * @throws BluePrintException - */ - public List getModelTypeByTags(String tags) throws BluePrintException { - if (StringUtils.isNotBlank(tags)) { - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("Model Tag Information is missing."); - } } /** * This is a getModelTypeByDefinitionType service * - * @param definitionType + * @param definitionType definitionType * @return List - * @throws BluePrintException */ - public List getModelTypeByDefinitionType(String definitionType) throws BluePrintException { - if (StringUtils.isNotBlank(definitionType)) { - return modelTypeRepository.findByDefinitionType(definitionType); - } else { - throw new BluePrintException("Model definitionType Information is missing."); - } + public List getModelTypeByDefinitionType(String definitionType) { + Preconditions.checkArgument(StringUtils.isNotBlank(definitionType), "Model definitionType Information is missing."); + return modelTypeRepository.findByDefinitionType(definitionType); } /** * This is a getModelTypeByDerivedFrom service * - * @param derivedFrom + * @param derivedFrom derivedFrom * @return List - * @throws BluePrintException */ - public List getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException { - if (StringUtils.isNotBlank(derivedFrom)) { - return modelTypeRepository.findByDerivedFrom(derivedFrom); - } else { - throw new BluePrintException("Model derivedFrom Information is missing."); - } + public List getModelTypeByDerivedFrom(String derivedFrom) { + Preconditions.checkArgument(StringUtils.isNotBlank(derivedFrom), "Model derivedFrom Information is missing."); + return modelTypeRepository.findByDerivedFrom(derivedFrom); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java index 16031b6e0..c53040e2b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java @@ -37,7 +37,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ Optional findByName(String name); @@ -45,7 +45,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ List findByNameIn(List names); @@ -53,7 +53,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ List findByTagsContainingIgnoreCase(String tags); @@ -61,9 +61,9 @@ public interface ResourceDictionaryRepository extends JpaRepository { + return Mono.justOrEmpty(modelTypeRepository.save(modelType)) + } + + fun findByModelName(modelName: String): Mono { + return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName)) + } + + fun findByModelNameIn(modelNames: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFrom(derivedFrom: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFromIn(derivedFroms: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionType(definitionType: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionTypeIn(definitionTypes: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByTagsContainingIgnoreCase(tags: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags)) + .subscribeOn(Schedulers.elastic()) + } + + fun deleteByModelName(modelName: String): Mono { + modelTypeRepository.deleteByModelName(modelName) + return Mono.empty() + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt index 064b5c382..0865b69da 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.repository -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary import org.springframework.stereotype.Service import reactor.core.publisher.Flux @@ -49,10 +48,9 @@ open class ResourceDictionaryReactRepository(private val resourceDictionaryRepos .subscribeOn(Schedulers.elastic()) } - fun deleteByName(name: String): Mono { - return Mono.fromCallable { - resourceDictionaryRepository.deleteByName(name) - } + fun deleteByName(name: String): Mono { + resourceDictionaryRepository.deleteByName(name) + return Mono.empty() } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java new file mode 100644 index 000000000..8e258ab6d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java @@ -0,0 +1,123 @@ +/* + * 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.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.*; +import org.junit.runner.RunWith; +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.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ModelTypeRestTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@RunWith(SpringRunner.class) +@DataJpaTest +@Transactional(propagation = Propagation.NOT_SUPPORTED) +@ContextConfiguration(classes = {TestApplication.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ModelTypeServiceTest { + private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeRestTest.class); + @Autowired + ModelTypeService modelTypeService; + + String modelName = "test-datatype"; + + @Test + public void test01SaveModelType() throws Exception { + log.info("**************** test01SaveModelType ********************"); + + String content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json"); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); + modelType.setDescription("Definition for Sample Datatype "); + modelType.setDefinition(JacksonUtils.jsonNode(content)); + modelType.setModelName(modelName); + modelType.setVersion("1.0.0"); + modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setUpdatedBy("xxxxxx@xxx.com"); + modelType = modelTypeService.saveModel(modelType); + log.info("Saved Mode {}", modelType.toString()); + Assert.assertNotNull("Failed to get Saved ModelType", modelType); + Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName()); + + ModelType dbModelType = modelTypeService.getModelTypeByName(modelType.getModelName()); + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")", + dbModelType); + + // Model Update + modelType.setUpdatedBy("bs2796@xxx.com"); + modelType = modelTypeService.saveModel(modelType); + Assert.assertNotNull("Failed to get Saved ModelType", modelType); + Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy()); + + } + + @Test + public void test02SearchModelTypes() throws Exception { + log.info("*********************** test02SearchModelTypes ***************************"); + + String tags = "test-datatype"; + + List dbModelTypes = modelTypeService.searchModelTypes(tags); + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes); + Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0); + + } + + @Test + public void test03GetModelType() throws Exception { + log.info("************************* test03GetModelType *********************************"); + ModelType dbModelType = modelTypeService.getModelTypeByName(modelName); + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType); + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName()); + + List dbDatatypeModelTypes = + modelTypeService.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes); + Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0); + + List dbModelTypeByDerivedFroms = + modelTypeService.getModelTypeByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); + Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms); + Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size() > 0); + + } + + @Test + public void test04DeleteModelType() throws Exception { + log.info( + "************************ test03DeleteModelType ***********************"); + ModelType dbResourceMapping = modelTypeService.getModelTypeByName(modelName); + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping); + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping.getModelName()); + + modelTypeService.deleteByModelName(dbResourceMapping.getModelName()); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java new file mode 100644 index 000000000..7549b7807 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java @@ -0,0 +1,110 @@ +/* + * 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.repository; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +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.core.BluePrintConstants; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.annotation.Commit; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.List; + +/** + * ModelTypeReactRepositoryTest. + * + * @author Brinda Santh + */ + +@RunWith(SpringRunner.class) +@DataJpaTest +@ContextConfiguration(classes = {TestApplication.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ModelTypeReactRepositoryTest { + + @Autowired + private ModelTypeReactRepository modelTypeReactRepository; + + String modelName = "test-datatype"; + + @Test + @Commit + public void test01Save() { + String content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json"); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); + modelType.setDescription("Definition for Sample Datatype "); + modelType.setDefinition(JacksonUtils.jsonNode(content)); + modelType.setModelName(modelName); + modelType.setVersion("1.0.0"); + modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setUpdatedBy("xxxxxx@xxx.com"); + + ModelType dbModelType = modelTypeReactRepository.save(modelType).block(); + Assert.assertNotNull("Failed to get Saved ModelType", dbModelType); + } + + @Test + public void test02Finds() { + ModelType dbFindByModelName = modelTypeReactRepository.findByModelName(modelName).block(); + Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName); + + List dbFindByDefinitionType = + modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block(); + Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType); + Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType.size() > 0); + + List dbFindByDerivedFrom = + modelTypeReactRepository.findByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT).collectList().block(); + Assert.assertNotNull("Failed to find findByDerivedFrom", dbFindByDerivedFrom); + Assert.assertTrue("Failed to find findByDerivedFrom by count", dbFindByDerivedFrom.size() > 0); + + List dbFindByModelNameIn = + modelTypeReactRepository.findByModelNameIn(Arrays.asList(modelName)).collectList().block(); + Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn); + Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn.size() > 0); + + List dbFindByDefinitionTypeIn = + modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block(); + Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn); + Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn.size() > 0); + + List dbFindByDerivedFromIn = + modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block(); + Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn); + Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn.size() > 0); + } + + @Test + @Commit + public void test03Delete() { + modelTypeReactRepository.deleteByModelName(modelName).block(); + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java index 7034b7e23..ab939ffa1 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java @@ -28,6 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.annotation.Commit; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -46,39 +47,50 @@ import java.util.List; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResourceDictionaryReactRepositoryTest { + private String sourceName = "test-source"; + @Autowired protected ResourceDictionaryReactRepository resourceDictionaryReactRepository; - @Before - public void init() { + @Test + @Commit + public void test01Save() { ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("./../../application/load/resource_dictionary/db-source" + ".json", ResourceDefinition.class); + Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition); + resourceDefinition.setName(sourceName); ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition); ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.save(resourceDictionary).block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); + Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary); } @Test - public void test01FindByNameReact() throws Exception { - ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName("db-source").block(); + public void test02FindByNameReact() { + ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName(sourceName).block(); Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); } @Test - public void test02FindByNameInReact() throws Exception { + public void test03FindByNameInReact() { List dbResourceDictionaries = - resourceDictionaryReactRepository.findByNameIn(Arrays.asList("db-source")).collectList().block(); + resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block(); Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); } @Test - public void test03FindByTagsContainingIgnoreCaseReact() throws Exception { + public void test04FindByTagsContainingIgnoreCaseReact() { List dbTagsResourceDictionaries = - resourceDictionaryReactRepository.findByTagsContainingIgnoreCase("db-source").collectList().block(); + resourceDictionaryReactRepository.findByTagsContainingIgnoreCase(sourceName).collectList().block(); Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries); } + @Test + @Commit + public void test05Delete() { + resourceDictionaryReactRepository.deleteByName("db-source").block(); + } + private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) { ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.setName(resourceDefinition.getName()); -- cgit 1.2.3-korg From 30bdb24f421db1d3703cfea707a8a6865adedb88 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Wed, 12 Sep 2018 16:26:31 +0000 Subject: Controller Blueprints Microservice Add dynamic resource source mapping rest service. Change-Id: I59274a4c0162bc6718c4248788c0e7f36830a129 Issue-ID: CCSDK-556 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../load/resource_dictionary/default-source.json | 16 ++++ .../opt/app/onap/config/application.properties | 5 +- .../src/test/resources/application.properties | 5 +- .../service/ApplicationRegistrationService.java | 26 ++++++- .../service/ResourceDictionaryService.java | 13 +++- .../service/rs/ResourceDictionaryRest.java | 7 ++ .../enhancer/ResourceAssignmentEnhancerService.kt | 88 ++++++++++++++++++++++ .../ResourceAssignmentEnhancerServiceTest.java | 50 ++++++++++++ .../service/rs/ResourceDictionaryRestTest.java | 8 ++ .../src/test/resources/application.properties | 5 +- .../src/test/resources/enhance/simple-enrich.json | 37 +++++++++ 11 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/default-source.json create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/resource_dictionary/default-source.json b/ms/controllerblueprints/application/load/resource_dictionary/default-source.json new file mode 100644 index 000000000..64bfa0ccd --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/default-source.json @@ -0,0 +1,16 @@ +{ + "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", + "sources": { + "default": { + "type": "source-default", + "properties": { + } + } + } +} \ 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 b65d5bfe5..d28148275 100644 --- a/ms/controllerblueprints/application/opt/app/onap/config/application.properties +++ b/ms/controllerblueprints/application/opt/app/onap/config/application.properties @@ -53,4 +53,7 @@ load.dataTypePath=load/model_type/data_type load.nodeTypePath=load/model_type/node_type load.artifactTypePath=load/model_type/artifact_type load.resourceDictionaryPath=load/resource_dictionary -load.blueprintsPath=load/blueprints \ No newline at end of file +load.blueprintsPath=load/blueprints + +# Load Resource Source Mappings +resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest \ No newline at end of file diff --git a/ms/controllerblueprints/application/src/test/resources/application.properties b/ms/controllerblueprints/application/src/test/resources/application.properties index 3bcbbd9c9..e2d040c26 100644 --- a/ms/controllerblueprints/application/src/test/resources/application.properties +++ b/ms/controllerblueprints/application/src/test/resources/application.properties @@ -33,4 +33,7 @@ load.dataTypePath=load/model_type/data_type load.nodeTypePath=load/model_type/node_type load.artifactTypePath=load/model_type/artifact_type load.resourceDictionaryPath=load/resource_dictionary -load.blueprintsPath=load/blueprints \ No newline at end of file +load.blueprintsPath=load/blueprints + +# Load Resource Source Mappings +resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest \ No newline at end of file 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 index 5a4a2877e..fc7410f96 100644 --- 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 @@ -17,20 +17,40 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.collections.CollectionUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; +import java.util.List; @Component @SuppressWarnings("unused") public class ApplicationRegistrationService { + private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationRegistrationService.class); + + @Value("#{'${resourceSourceMappings}'.split(',')}") + private List resourceSourceMappings; @PostConstruct - public void register(){ + public void register() { registerDictionarySources(); } - public void registerDictionarySources(){ - + public void registerDictionarySources() { + log.info("Registering Dictionary Sources : {}", resourceSourceMappings); + if (CollectionUtils.isNotEmpty(resourceSourceMappings)) { + resourceSourceMappings.forEach(resourceSourceMapping -> { + String[] mappingKeyValue = resourceSourceMapping.split("="); + if (mappingKeyValue != null && mappingKeyValue.length == 2) { + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping(mappingKeyValue[0].trim(), mappingKeyValue[1].trim()); + } else { + log.warn("failed to get resource source mapping {}", resourceSourceMapping); + } + }); + } } } 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 62aa0e29c..fd73db3b6 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 @@ -22,8 +22,9 @@ 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; -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.ResourceSourceMapping; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory; 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; @@ -105,7 +106,7 @@ public class ResourceDictionaryService { */ public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); - Preconditions.checkNotNull(resourceDictionary.getDefinition(),"Resource Dictionary definition information is missing"); + Preconditions.checkNotNull(resourceDictionary.getDefinition(), "Resource Dictionary definition information is missing"); ResourceDefinition resourceDefinition = resourceDictionary.getDefinition(); Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content"); @@ -153,4 +154,12 @@ public class ResourceDictionaryService { Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); resourceDictionaryRepository.deleteByName(name); } + + /** + * This is a getResourceSourceMapping service + * + */ + public ResourceSourceMapping getResourceSourceMapping() { + return ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); + } } 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 e0cf6c69b..287d413cc 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 @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping; import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.springframework.http.MediaType; @@ -76,4 +77,10 @@ public class ResourceDictionaryRest { } + @GetMapping(path = "/source-mapping", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + ResourceSourceMapping getResourceSourceMapping() { + return resourceDictionaryService.getResourceSourceMapping(); + } + } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt new file mode 100644 index 000000000..0d08985a1 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt @@ -0,0 +1,88 @@ +/* + * 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.enhancer + +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 +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService + +/** + * 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/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java new file mode 100644 index 000000000..7d16f50fa --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java @@ -0,0 +1,50 @@ +/* + * 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.enhancer; + +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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionFileRepoService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; + +import java.util.List; + +/** + * ResourceAssignmentEnhancerService. + * + * @author Brinda Santh + */ +public class ResourceAssignmentEnhancerServiceTest { + + @Test + public void testEnhanceBluePrint() throws BluePrintException { + + List resourceAssignments = JacksonReactorUtils + .getListFromClassPathFile("enhance/simple-enrich.json", ResourceAssignment.class).block(); + Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments); + ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("./../../application/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/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 5955ae191..ac786d0e9 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 @@ -26,6 +26,7 @@ import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; 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.ResourceSourceMapping; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -103,4 +104,11 @@ public class ResourceDictionaryRestTest { } + @Test + public void test03GetResourceSourceMapping() { + ResourceSourceMapping resourceSourceMapping = resourceDictionaryRest.getResourceSourceMapping(); + org.springframework.util.Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping"); + org.springframework.util.Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings"); + } + } diff --git a/ms/controllerblueprints/modules/service/src/test/resources/application.properties b/ms/controllerblueprints/modules/service/src/test/resources/application.properties index 429588b31..3a913b701 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/application.properties +++ b/ms/controllerblueprints/modules/service/src/test/resources/application.properties @@ -28,4 +28,7 @@ load.dataTypePath=./../../application/load/model_type/data_type load.nodeTypePath=./../../application/load/model_type/node_type load.artifactTypePath=./../../application/load/model_type/artifact_type load.resourceDictionaryPath=./../../application/load/resource_dictionary -load.blueprintsPath=./../../application/load/blueprints \ No newline at end of file +load.blueprintsPath=./../../application/load/blueprints + +# Load Resource Source Mappings +resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json new file mode 100644 index 000000000..641da80a2 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/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": [] + } +] -- cgit 1.2.3-korg From 99f4a1e766cf27d35fb7b68b4904d1e49e7fa787 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 13 Sep 2018 00:20:34 +0000 Subject: Controller Blueprints Microservice Add resource assignment enhancement and validation to blueprint validation and enhancement. Change-Id: I547760012e7014cfbb7a1e3a1d8ffb77edc9b6a2 Issue-ID: CCSDK-562 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../load/resource_dictionary/db-source.json | 24 -- .../load/resource_dictionary/default-source.json | 16 -- .../load/resource_dictionary/input-source.json | 17 -- .../load/resource_dictionary/sample-db-source.json | 24 ++ .../resource_dictionary/sample-default-source.json | 16 ++ .../resource_dictionary/sample-input-source.json | 17 ++ .../load/resource_dictionary/sample-licenses.json | 29 ++ .../resource_dictionary/sample-mdsal-source.json | 25 ++ .../resource_dictionary/sample-v4-ip-type.json | 17 ++ .../load/resource_dictionary/v4-ip-type.json | 17 -- .../src/test/resources/application.properties | 2 + .../service/BluePrintEnhancerService.java | 23 +- .../service/BluePrintRepoDBService.java | 97 ------- .../service/ResourceDefinitionRepoDBService.java | 115 ++++++++ .../service/enhancer/BluePrintEnhancerService.kt | 272 ++++++++++++++++++ .../enhancer/ResourceAssignmentEnhancerService.kt | 50 +++- .../ResourceAssignmentEnhancerServiceTest.java | 17 +- .../ResourceDictionaryReactRepositoryTest.java | 6 +- .../service/rs/ResourceDictionaryRestTest.java | 2 +- .../service/rs/ServiceTemplateRestTest.java | 4 +- .../validator/ServiceTemplateValidationTest.java | 10 + .../src/test/resources/application.properties | 4 +- .../enhance/enhance-resource-assignment.json | 62 ++++ .../test/resources/enhance/enhance-template.json | 10 +- .../test/resources/enhance/enhanced-template.json | 312 ++++++++++++++------- .../src/test/resources/enhance/simple-enrich.json | 37 --- .../modules/service/src/test/resources/logback.xml | 5 +- .../test/resources/resourcedictionary/automap.json | 9 +- 28 files changed, 895 insertions(+), 344 deletions(-) delete mode 100644 ms/controllerblueprints/application/load/resource_dictionary/db-source.json delete mode 100644 ms/controllerblueprints/application/load/resource_dictionary/default-source.json delete mode 100644 ms/controllerblueprints/application/load/resource_dictionary/input-source.json create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/sample-db-source.json create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/sample-default-source.json create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/sample-input-source.json create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/sample-licenses.json create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/sample-mdsal-source.json create mode 100644 ms/controllerblueprints/application/load/resource_dictionary/sample-v4-ip-type.json delete mode 100644 ms/controllerblueprints/application/load/resource_dictionary/v4-ip-type.json delete 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/ResourceDefinitionRepoDBService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json delete mode 100644 ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/application/load/resource_dictionary/db-source.json b/ms/controllerblueprints/application/load/resource_dictionary/db-source.json deleted file mode 100644 index a0c78af06..000000000 --- a/ms/controllerblueprints/application/load/resource_dictionary/db-source.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "db-source", - "property" :{ - "description": "name of the ", - "type": "string" - }, - "updated-by": "brindasanth@onap.com", - "tags": "db-source, 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/application/load/resource_dictionary/default-source.json b/ms/controllerblueprints/application/load/resource_dictionary/default-source.json deleted file mode 100644 index 64bfa0ccd..000000000 --- a/ms/controllerblueprints/application/load/resource_dictionary/default-source.json +++ /dev/null @@ -1,16 +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", - "sources": { - "default": { - "type": "source-default", - "properties": { - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/resource_dictionary/input-source.json b/ms/controllerblueprints/application/load/resource_dictionary/input-source.json deleted file mode 100644 index acfad16bb..000000000 --- a/ms/controllerblueprints/application/load/resource_dictionary/input-source.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "input-source", - "property" :{ - "description": "name of the ", - "type": "string" - }, - "updated-by": "brindasanth@onap.com", - "tags": "action-name, brindasanth", - "sources": { - "input": { - "type": "source-input", - "properties": { - "key": "action-name" - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/resource_dictionary/sample-db-source.json b/ms/controllerblueprints/application/load/resource_dictionary/sample-db-source.json new file mode 100644 index 000000000..90775aee0 --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/sample-db-source.json @@ -0,0 +1,24 @@ +{ + "name": "sample-db-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "tags": "db-source, 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/application/load/resource_dictionary/sample-default-source.json b/ms/controllerblueprints/application/load/resource_dictionary/sample-default-source.json new file mode 100644 index 000000000..395b0ddd1 --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/sample-default-source.json @@ -0,0 +1,16 @@ +{ + "tags": "sample-default-source", + "name": "sample-default-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "sources": { + "default": { + "type": "source-default", + "properties": { + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/resource_dictionary/sample-input-source.json b/ms/controllerblueprints/application/load/resource_dictionary/sample-input-source.json new file mode 100644 index 000000000..73c0d4089 --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/sample-input-source.json @@ -0,0 +1,17 @@ +{ + "name": "sample-input-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "tags": "sample-input-source", + "sources": { + "input": { + "type": "source-input", + "properties": { + "key": "input-source" + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/resource_dictionary/sample-licenses.json b/ms/controllerblueprints/application/load/resource_dictionary/sample-licenses.json new file mode 100644 index 000000000..5834dd49b --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/sample-licenses.json @@ -0,0 +1,29 @@ +{ + "tags": "sample-licenses", + "name": "sample-licenses", + "property": { + "description" : " Sample Data for licences", + "required": true, + "type": "list", + "entry_schema": { + "type": "dt-license-key" + } + }, + "updated-by": "brindasanth@onap.com", + "sources": { + "mdsal": { + "type": "source-rest", + "properties": { + "type": "JSON", + "url-path": "config/L3VNF-API:services/service-list/", + "path": "/licenses", + "input-key-mapping": { + }, + "output-key-mapping": { + "licenses": "licenses" + }, + "key-dependencies": [] + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/resource_dictionary/sample-mdsal-source.json b/ms/controllerblueprints/application/load/resource_dictionary/sample-mdsal-source.json new file mode 100644 index 000000000..25464d3fe --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/sample-mdsal-source.json @@ -0,0 +1,25 @@ +{ + "tags": "sample-mdsal-source", + "name": "sample-mdsal-source", + "property": { + "description": "Sample sample-mdsal-source", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "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": { + }, + "output-key-mapping": { + "mdsal-source": "v4-ip-prefix" + }, + "key-dependencies": [] + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/resource_dictionary/sample-v4-ip-type.json b/ms/controllerblueprints/application/load/resource_dictionary/sample-v4-ip-type.json new file mode 100644 index 000000000..055279c1e --- /dev/null +++ b/ms/controllerblueprints/application/load/resource_dictionary/sample-v4-ip-type.json @@ -0,0 +1,17 @@ +{ + "name": "sample-v4-ip-type", + "property": { + "description": "sample-v4-ip-type", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "tags": "sample-v4-ip-type", + "sources": { + "input": { + "type": "source-input", + "properties": { + "key": "sample-v4-ip-type" + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/resource_dictionary/v4-ip-type.json b/ms/controllerblueprints/application/load/resource_dictionary/v4-ip-type.json deleted file mode 100644 index 1b4432d53..000000000 --- a/ms/controllerblueprints/application/load/resource_dictionary/v4-ip-type.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "v4-ip-type", - "property": { - "description": "name of the ", - "type": "string" - }, - "updated-by": "brindasanth@onap.com", - "tags": "v4-ip-type, source-input, brindasanth", - "sources": { - "input": { - "type": "source-input", - "properties": { - "key": "v4-ip-type" - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/application/src/test/resources/application.properties b/ms/controllerblueprints/application/src/test/resources/application.properties index e2d040c26..5c6acf93d 100644 --- a/ms/controllerblueprints/application/src/test/resources/application.properties +++ b/ms/controllerblueprints/application/src/test/resources/application.properties @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +spring.main.banner-mode=off + appName=ControllerBluePrints ms_name=org.onap.ccsdk.apps.controllerblueprints appVersion=1.0.0 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 8e98f9477..ef3b4a48f 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 @@ -25,12 +25,13 @@ import org.jetbrains.annotations.NotNull; 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.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerDefaultService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -48,14 +49,18 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); + private ResourceAssignmentEnhancerService resourceAssignmentEnhancerService; + private Map recipeDataTypes = new HashMap<>(); - public BluePrintEnhancerService(BluePrintRepoService bluePrintEnhancerRepoDBService) { - super(bluePrintEnhancerRepoDBService); + public BluePrintEnhancerService(ResourceDefinitionRepoService resourceDefinitionRepoService, + ResourceAssignmentEnhancerService resourceAssignmentEnhancerService) { + super(resourceDefinitionRepoService); + this.resourceAssignmentEnhancerService = resourceAssignmentEnhancerService; } @Override - public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException{ + public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException { super.enrichTopologyTemplate(serviceTemplate); // Update the Recipe Inputs and DataTypes @@ -101,7 +106,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { // Modified for ONAP converted Object to JsonNode JsonNode recipeNames = nodeTemplate.getProperties().get(ConfigModelConstant.PROPERTY_RECIPE_NAMES); - log.info("Processing Receipe Names : {} ", recipeNames); + log.info("Processing Recipe Names : {} ", recipeNames); if (recipeNames != null && recipeNames.isArray() && recipeNames.size() > 0) { @@ -159,6 +164,9 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent); + // Enhance Resource Assignment + resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); + dataTypeProperties = new HashMap<>(); for (ResourceAssignment resourceAssignment : resourceAssignments) { @@ -167,9 +175,6 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { && resourceAssignment.getProperty() != null && StringUtils.isNotBlank(resourceAssignment.getName())) { - // Enrich the Property Definition - super.enrichPropertyDefinition(resourceAssignment.getName(), resourceAssignment.getProperty()); - dataTypeProperties.put(resourceAssignment.getName(), resourceAssignment.getProperty()); } 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 deleted file mode 100644 index 5510e480c..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java +++ /dev/null @@ -1,97 +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; - -import com.fasterxml.jackson.databind.JsonNode; -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; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; - -import java.util.Optional; - -/** - * BluePrintRepoDBService - * - * @author Brinda Santh - */ -@Service -@SuppressWarnings("unused") -public class BluePrintRepoDBService implements BluePrintRepoService { - - private ModelTypeRepository modelTypeRepository; - @SuppressWarnings("unused") - public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) { - this.modelTypeRepository = modelTypeRepository; - } - - @Override - public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { - return getModelType(nodeTypeName, NodeType.class); - } - - @Override - public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { - return getModelType(dataTypeName, DataType.class); - } - - @Override - public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { - return getModelType(artifactTypeName, ArtifactType.class); - } - - @Override - public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { - return getModelType(relationshipTypeName, RelationshipType.class); - } - - @Override - public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { - return getModelType(capabilityDefinitionName, CapabilityDefinition.class); - } - - private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(modelName), - "Failed to get model from repo, model name is missing"); - - return getModelDefinition(modelName).map(modelDefinition -> { - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)); - return JacksonUtils.readValue(modelDefinition, valueClass); - } - ); - } - - private Mono getModelDefinition(String modelName) throws BluePrintException { - JsonNode modelDefinition; - 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 Mono.just(modelDefinition); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java new file mode 100644 index 000000000..16cc8415c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java @@ -0,0 +1,115 @@ +/* + * 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.fasterxml.jackson.databind.JsonNode; +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.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; +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.repository.ModelTypeRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.Optional; + +/** + * ResourceDefinitionRepoDBService + * + * @author Brinda Santh + */ +@Service +@SuppressWarnings("unused") +public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoService { + + private ModelTypeRepository modelTypeRepository; + private ResourceDictionaryRepository resourceDictionaryRepository; + + @SuppressWarnings("unused") + public ResourceDefinitionRepoDBService(ModelTypeRepository modelTypeRepository, + ResourceDictionaryRepository resourceDictionaryRepository) { + this.modelTypeRepository = modelTypeRepository; + this.resourceDictionaryRepository = resourceDictionaryRepository; + } + + @Override + public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { + return getModelType(nodeTypeName, NodeType.class); + } + + @Override + public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { + return getModelType(dataTypeName, DataType.class); + } + + @Override + public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { + return getModelType(artifactTypeName, ArtifactType.class); + } + + @Override + public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { + return getModelType(relationshipTypeName, RelationshipType.class); + } + + @Override + public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { + return getModelType(capabilityDefinitionName, CapabilityDefinition.class); + } + + @NotNull + @Override + public Mono getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException{ + Optional dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName); + if(dbResourceDictionary.isPresent()){ + return Mono.just(dbResourceDictionary.get().getDefinition()); + }else{ + throw new BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)); + } + } + + private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing"); + + return getModelDefinition(modelName).map(modelDefinition -> { + Preconditions.checkNotNull(modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName)); + return JacksonUtils.readValue(modelDefinition, valueClass); + } + ); + } + + private Mono getModelDefinition(String modelName) throws BluePrintException { + JsonNode modelDefinition; + 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 Mono.just(modelDefinition); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt new file mode 100644 index 000000000..cf9e96e77 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt @@ -0,0 +1,272 @@ +/* + * 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.enhancer + +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.service.BluePrintRepoService +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) { + log.debug("Enriching NodeType({})", nodeTypeName) + val derivedFrom = nodeType.derivedFrom + + if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { + val derivedFromNodeType = populateNodeType(nodeTypeName) + // Enrich NodeType + enrichNodeType(derivedFrom, derivedFromNodeType) + } + + // 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.debug("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 = serviceTemplate.nodeTypes?.get(nodeTypeName) + ?: 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 = serviceTemplate.artifactTypes?.get(artifactTypeName) + ?: 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 = serviceTemplate.dataTypes?.get(dataTypeName) + ?: 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/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt index 0d08985a1..de6f82ffe 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt @@ -19,13 +19,16 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer 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 +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService +import org.springframework.stereotype.Service /** * ResourceAssignmentEnhancerService. @@ -47,6 +50,7 @@ interface ResourceAssignmentEnhancerService { * * @author Brinda Santh */ +@Service open class ResourceAssignmentEnhancerDefaultService(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) : ResourceAssignmentEnhancerService { private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java) @@ -58,20 +62,41 @@ open class ResourceAssignmentEnhancerDefaultService(private val resourceDefiniti override fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, resourceAssignments: List) { + val uniqueSourceNodeTypeNames = hashSetOf() + // 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, + log.debug("Enriching Assignment name({}), dictionary name({}), source({})", resourceAssignment.name, dictionaryName, dictionarySource) - // Get the Resource Definition from Repo - val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) + val sourceNodeTypeName = ResourceSourceMappingFactory.getRegisterSourceMapping(dictionarySource) + + // Add Unique Node Types + uniqueSourceNodeTypeNames.add(sourceNodeTypeName) + + // TODO("Candidate for Optimisation") + if (checkResourceDefinitionNeeded(resourceAssignment)) { + + bluePrintEnhancerService.enrichPropertyDefinition(resourceAssignment.name, resourceAssignment.property!!); + + // Get the Resource Definition from Repo + val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) - val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource) + val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource) + ?: throw BluePrintException(format("failed to get assigned dictionarySource({}) from resourceDefinition({})", dictionarySource, dictionaryName)) - // Enrich as NodeTemplate - bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate!!) + // Enrich as NodeTemplate + bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate) + } } + // Enrich the ResourceSource NodeTypes + uniqueSourceNodeTypeNames.map { nodeTypeName -> + resourceDefinitionRepoService.getNodeType(nodeTypeName).subscribe { nodeType -> + bluePrintEnhancerService.enrichNodeType(nodeTypeName, nodeType) + } + } + } override fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate { @@ -82,7 +107,14 @@ open class ResourceAssignmentEnhancerDefaultService(private val resourceDefiniti return bluePrintEnhancerService.serviceTemplate } + private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean { + return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT) + || resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT)) + && BluePrintTypes.validPrimitiveOrCollectionPrimitive(resourceAssignment.property!!)) + } + private fun getResourceDefinition(name: String): ResourceDefinition { - return resourceDefinitionRepoService.getResourceDefinition(name).block()!! + return resourceDefinitionRepoService.getResourceDefinition(name).block() + ?: throw BluePrintException(format("failed to get dictionary definition({})", name)) } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java index 7d16f50fa..e279ec9c0 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java @@ -16,12 +16,17 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.junit.Assert; +import org.junit.Before; 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.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionFileRepoService; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; @@ -33,18 +38,28 @@ import java.util.List; * @author Brinda Santh */ public class ResourceAssignmentEnhancerServiceTest { + private static EELFLogger log = EELFManager.getInstance().getLogger(ResourceAssignmentEnhancerServiceTest.class); + + @Before + public void setUp(){ + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("db", "source-db"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest"); + } @Test public void testEnhanceBluePrint() throws BluePrintException { List resourceAssignments = JacksonReactorUtils - .getListFromClassPathFile("enhance/simple-enrich.json", ResourceAssignment.class).block(); + .getListFromClassPathFile("enhance/enhance-resource-assignment.json", ResourceAssignment.class).block(); Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments); ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("./../../application/load"); ResourceAssignmentEnhancerService resourceAssignmentEnhancerService = new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService); ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments); Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate); + log.trace("Enhanced Service Template : {}", JacksonUtils.getJson(serviceTemplate, true)); } } diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java index ab939ffa1..b2e290186 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java @@ -1,5 +1,6 @@ /* * 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. @@ -17,7 +18,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.repository; import org.junit.Assert; -import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; @@ -55,7 +55,7 @@ public class ResourceDictionaryReactRepositoryTest { @Test @Commit public void test01Save() { - ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("./../../application/load/resource_dictionary/db-source" + + ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("./../../application/load/resource_dictionary/sample-db-source" + ".json", ResourceDefinition.class); Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition); resourceDefinition.setName(sourceName); @@ -88,7 +88,7 @@ public class ResourceDictionaryReactRepositoryTest { @Test @Commit public void test05Delete() { - resourceDictionaryReactRepository.deleteByName("db-source").block(); + resourceDictionaryReactRepository.deleteByName(sourceName).block(); } private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) { 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 ac786d0e9..272cdd08f 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 @@ -42,7 +42,7 @@ import java.util.List; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"blueprints.load.initial-data=true"}) @ContextConfiguration(classes = {TestApplication.class}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResourceDictionaryRestTest { 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 faa10825f..37cc61d1c 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 @@ -45,7 +45,7 @@ import java.util.List; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"blueprints.load.initial-data=true"}) @ContextConfiguration(classes = {TestApplication.class}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ServiceTemplateRestTest { @@ -143,7 +143,7 @@ public class ServiceTemplateRestTest { List autoMappedResourceAssignment = autoMapResponse.getResourceAssignments(); autoMappedResourceAssignment.forEach(resourceAssignment -> { - if ("bundle-id".equals(resourceAssignment.getName())) { + if ("sample-db-source".equals(resourceAssignment.getName())) { Assert.assertEquals("Failed to assign default first source", "db", resourceAssignment.getDictionarySource()); } 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 46b725f87..5f34b5510 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 @@ -19,9 +19,11 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; import org.apache.commons.io.FileUtils; import org.junit.Assert; +import org.junit.Before; 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.resource.dict.factory.ResourceSourceMappingFactory; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -33,6 +35,14 @@ import java.util.List; public class ServiceTemplateValidationTest { private static EELFLogger log = EELFManager.getInstance().getLogger(ServiceTemplateValidationTest.class); + @Before + public void setUp(){ + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("db", "source-db"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest"); + } + @Test public void testBluePrintDirs() { List dirs = ConfigModelUtils.getBlueprintNames("load/blueprints"); diff --git a/ms/controllerblueprints/modules/service/src/test/resources/application.properties b/ms/controllerblueprints/modules/service/src/test/resources/application.properties index 3a913b701..397f3b138 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/application.properties +++ b/ms/controllerblueprints/modules/service/src/test/resources/application.properties @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # - +spring.main.banner-mode=off spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false @@ -23,7 +23,7 @@ logging.level.org.hibernate.SQL=warn logging.level.org.hibernate.type.descriptor.sql=debug -blueprints.load.initial-data=true +blueprints.load.initial-data=false load.dataTypePath=./../../application/load/model_type/data_type load.nodeTypePath=./../../application/load/model_type/node_type load.artifactTypePath=./../../application/load/model_type/artifact_type diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json new file mode 100644 index 000000000..3715becad --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json @@ -0,0 +1,62 @@ +[ + { + "name": "rs-db-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "sample-db-source", + "dictionary-source": "db", + "dependencies": [ + "input-source" + ] + }, + { + "name": "ra-default-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "sample-default-source", + "dictionary-source": "default", + "dependencies": [] + }, + { + "name": "ra-input-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "sample-input-source", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "ra-list-input-source", + "input-param": true, + "property": { + "type": "list", + "required": true, + "entry_schema": { + "type": "string" + } + }, + "dictionary-name": "ra-list-input-source", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "ra-complex-input-source", + "input-param": true, + "property": { + "type": "dt-v4-aggregate", + "required": true + }, + "dictionary-name": "sample-mdsal-source", + "dictionary-source": "mdsal", + "dependencies": [] + } +] 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 70d03e0a8..782ed505c 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 @@ -218,13 +218,13 @@ "properties": { "mapping": [ { - "name": "bundle-mac", + "name": "rs-db-source", "property": { "required": true, "type": "string" }, "input-param": false, - "dictionary-name": "bundle-mac", + "dictionary-name": "sample-db-source", "dictionary-source": "db", "dependencies": [ "hostname" @@ -232,7 +232,7 @@ "version": 0 }, { - "name": "wan-aggregate-ipv4-addresses", + "name": "mdsal-source", "property": { "description": "", "required": true, @@ -242,7 +242,7 @@ } }, "input-param": false, - "dictionary-name": "wan-aggregate-ipv4-addresses", + "dictionary-name": "sample-mdsal-source", "dictionary-source": "mdsal", "dependencies": [ "service-instance-id" @@ -313,7 +313,7 @@ } }, "input-param": false, - "dictionary-name": "licenses", + "dictionary-name": "sample-licenses", "dictionary-source": "mdsal", "dependencies": [ "service-instance-id" 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 bf3deffb5..531d756be 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 @@ -114,10 +114,6 @@ "description" : "This is Dynamic Data type definition generated from resource mapping for the config template name base-config-template.", "version" : "1.0.0", "properties" : { - "bundle-mac" : { - "required" : true, - "type" : "string" - }, "hostname" : { "required" : true, "type" : "string" @@ -129,13 +125,9 @@ "type" : "dt-license-key" } }, - "wan-aggregate-ipv4-addresses" : { - "description" : "", + "rs-db-source" : { "required" : true, - "type" : "list", - "entry_schema" : { - "type" : "dt-v4-aggregate" - } + "type" : "string" }, "service" : { "required" : true, @@ -144,6 +136,14 @@ "service-instance-id" : { "required" : true, "type" : "string" + }, + "mdsal-source" : { + "description" : "", + "required" : true, + "type" : "list", + "entry_schema" : { + "type" : "dt-v4-aggregate" + } } }, "derived_from" : "tosca.datatypes.Dynamic" @@ -206,6 +206,127 @@ "version" : "1.0.0", "derived_from" : "tosca.nodes.Root" }, + "artifact-config-template" : { + "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" + }, + "tosca.nodes.Vnf" : { + "description" : "This is VNF Node Type", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, + "tosca.nodes.Artifact" : { + "description" : "This is Deprecated Artifact Node Type.", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, + "dg-activate-netconf" : { + "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" + }, + "source-input" : { + "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" + }, + "tosca.nodes.ResourceSource" : { + "description" : "TOSCA base type for Resource Sources", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, "component-resource-assignment" : { "description" : "This is Resource Assignment Component API", "version" : "1.0.0", @@ -279,42 +400,44 @@ "version" : "1.0.0", "derived_from" : "tosca.nodes.Root" }, - "artifact-config-template" : { - "description" : "This is Configuration Velocity Template", + "source-db" : { + "description" : "This is Database Resource Source Node Type", "version" : "1.0.0", "properties" : { - "action-names" : { + "type" : { "required" : true, - "type" : "list", + "type" : "string", + "constraints" : [ { + "valid_values" : [ "SQL", "PLSQL" ] + } ] + }, + "query" : { + "required" : true, + "type" : "string" + }, + "input-key-mapping" : { + "required" : false, + "type" : "map", "entry_schema" : { "type" : "string" } - } - }, - "capabilities" : { - "content" : { - "type" : "tosca.capabilities.Content", - "properties" : { - "content" : { - "required" : true, - "type" : "string" - } + }, + "output-key-mapping" : { + "required" : false, + "type" : "map", + "entry_schema" : { + "type" : "string" } }, - "mapping" : { - "type" : "tosca.capabilities.Mapping", - "properties" : { - "mapping" : { - "required" : false, - "type" : "list", - "entry_schema" : { - "type" : "datatype-resource-assignment" - } - } + "key-dependencies" : { + "required" : true, + "type" : "list", + "entry_schema" : { + "type" : "string" } } }, - "derived_from" : "tosca.nodes.Artifact" + "derived_from" : "tosca.nodes.ResourceSource" }, "vnf-netconf-device" : { "description" : "This is VNF Device with Netconf Capability", @@ -357,10 +480,57 @@ }, "derived_from" : "tosca.nodes.Vnf" }, - "tosca.nodes.Vnf" : { - "description" : "This is VNF Node Type", + "source-rest" : { + "description" : "This is Rest Resource Source Node Type", "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" + "properties" : { + "type" : { + "required" : false, + "type" : "string", + "constraints" : [ { + "valid_values" : [ "JSON" ] + } ], + "default" : "JSON" + }, + "url-path" : { + "required" : true, + "type" : "string" + }, + "path" : { + "required" : true, + "type" : "string" + }, + "expression-type" : { + "required" : false, + "type" : "string", + "constraints" : [ { + "valid_values" : [ "JSON_PATH", "JSON_POINTER" ] + } ], + "default" : "JSON_PATH" + }, + "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" }, "component-netconf-executor" : { "description" : "This is Netconf Transaction Configuration Component API", @@ -440,62 +610,6 @@ } }, "derived_from" : "tosca.nodes.Component" - }, - "tosca.nodes.Artifact" : { - "description" : "This is Deprecated Artifact Node Type.", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" - }, - "dg-activate-netconf" : { - "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" } }, "topology_template" : { @@ -704,18 +818,18 @@ "mapping" : { "properties" : { "mapping" : [ { - "name" : "bundle-mac", + "name" : "rs-db-source", "property" : { "required" : true, "type" : "string" }, "input-param" : false, - "dictionary-name" : "bundle-mac", + "dictionary-name" : "sample-db-source", "dictionary-source" : "db", "dependencies" : [ "hostname" ], "version" : 0 }, { - "name" : "wan-aggregate-ipv4-addresses", + "name" : "mdsal-source", "property" : { "description" : "", "required" : true, @@ -725,7 +839,7 @@ } }, "input-param" : false, - "dictionary-name" : "wan-aggregate-ipv4-addresses", + "dictionary-name" : "sample-mdsal-source", "dictionary-source" : "mdsal", "dependencies" : [ "service-instance-id" ], "version" : 0 @@ -787,7 +901,7 @@ } }, "input-param" : false, - "dictionary-name" : "licenses", + "dictionary-name" : "sample-licenses", "dictionary-source" : "mdsal", "dependencies" : [ "service-instance-id" ], "version" : 0 diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json deleted file mode 100644 index 641da80a2..000000000 --- a/ms/controllerblueprints/modules/service/src/test/resources/enhance/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/service/src/test/resources/logback.xml b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml index 4a04cfdca..7b7ef7565 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml +++ b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml @@ -1,5 +1,6 @@ @@ -102,6 +105,11 @@ kotlin-stdlib ${kotlin.version} + + org.jetbrains.kotlin + kotlinx-couroutines-core + ${kotlin.couroutines.version} + org.jetbrains.kotlin kotlin-reflect @@ -112,6 +120,12 @@ kotlin-stdlib-jdk8 ${kotlin.version} + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + ${kotlin.version} + + @@ -148,12 +162,12 @@ org.powermock powermock-api-mockito2 - 1.7.4 + ${powermock.version} test org.jetbrains.kotlin - kotlin-test + kotlin-test-junit ${kotlin.version} test -- cgit 1.2.3-korg From 6ad6eb8ad275474df7c3b2e5e5706fc8c0af35c1 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 20 Nov 2018 12:20:30 -0500 Subject: Add Jython Component model and validation logics. Change-Id: I2bdba0016a41e16198d60be68dff68d1ce7ad13a Issue-ID: CCSDK-696 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../src/test/resources/enhance/enhance-template.json | 4 ++-- .../src/test/resources/enhance/enhanced-template.json | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/test') 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 782ed505c..b066dad63 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 @@ -64,7 +64,7 @@ } }, "interfaces": { - "org-openecomp-sdnc-netconf-adaptor-service-NetconfExecutorNode": { + "NetconfExecutorComponent": { "operations": { "process": { "inputs": { @@ -114,7 +114,7 @@ "component-node": {} }, "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "ResourceAssignmentComponent": { "operations": { "process": { "inputs": { 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 d49ab8fec..5e41a507e 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 @@ -336,7 +336,7 @@ } }, "interfaces" : { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode" : { + "ResourceAssignmentComponent" : { "operations" : { "process" : { "inputs" : { @@ -395,6 +395,11 @@ }, "derived_from" : "tosca.nodes.Component" }, + "tosca.nodes.component.Jython" : { + "description" : "This is Jython Component", + "version" : "1.0.0", + "derived_from" : "tosca.nodes.Root" + }, "tosca.nodes.DG" : { "description" : "This is Directed Graph Node Type", "version" : "1.0.0", @@ -548,7 +553,7 @@ } }, "interfaces" : { - "org-openecomp-sdnc-netconf-adaptor-service-NetconfExecutorNode" : { + "NetconfExecutorComponent" : { "operations" : { "process" : { "inputs" : { @@ -609,7 +614,7 @@ } } }, - "derived_from" : "tosca.nodes.Component" + "derived_from" : "tosca.nodes.component.Jython" } }, "topology_template" : { @@ -671,7 +676,7 @@ } }, "interfaces" : { - "org-openecomp-sdnc-netconf-adaptor-service-NetconfExecutorNode" : { + "NetconfExecutorComponent" : { "operations" : { "process" : { "implementation" : { @@ -715,7 +720,7 @@ "component-node" : { } }, "interfaces" : { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode" : { + "ResourceAssignmentComponent" : { "operations" : { "process" : { "inputs" : { -- cgit 1.2.3-korg From 465bf1a300973c6db2620af0b6c3fa4eb2132db5 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 4 Dec 2018 10:25:44 -0500 Subject: Add Blueprint Runtime Input/Output logic Change-Id: I0355e78862096b7b4074faa882d66ce27d6e1844 Issue-ID: CCSDK-670 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/enhancer/ResourceAssignmentEnhancerServiceTest.java | 1 - 1 file changed, 1 deletion(-) (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java index 2e58b53e7..1ba325746 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java @@ -20,7 +20,6 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import org.junit.Assert; import org.junit.Before; -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; -- cgit 1.2.3-korg From a490a2830aaa1345fd506df5dd4d913c67784da6 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 11 Dec 2018 19:40:51 -0500 Subject: Implement Enhancer Framework Interfaces Change-Id: Iff85dc50f87ab6d6f7d9ceb4a309ea6e4d55e362 Issue-ID: CCSDK-803 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintEnhancerService.java | 9 +- .../service/ResourceDefinitionRepoDBService.java | 36 ++- .../service/enhancer/BluePrintEnhancerService.kt | 279 --------------------- .../enhancer/BluePrintEnhancerServiceImpl.kt | 250 ++++++++++++++++++ .../enhancer/ResourceAssignmentEnhancerService.kt | 54 ++-- .../ResourceAssignmentEnhancerServiceTest.java | 18 +- .../service/rs/ServiceTemplateRestTest.java | 2 +- .../validator/ServiceTemplateValidationTest.java | 7 +- 8 files changed, 309 insertions(+), 346 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt (limited to 'ms/controllerblueprints/modules/service/src/test') 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 aaa45e143..91df33318 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 @@ -30,7 +30,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.*; 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.ResourceDefinitionRepoService; -import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerDefaultService; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerServiceImpl; import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; @@ -46,9 +46,10 @@ import java.util.Map; * @author Brinda Santh DATE : 8/8/2018 */ +@Deprecated @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { +public class BluePrintEnhancerService extends BluePrintEnhancerServiceImpl { private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); @@ -167,8 +168,8 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent); - // Enhance Resource Assignment - resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); + // Enhance Resource Assignment TODO("Plug Resource Assignment Enhancer Service") + //resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); dataTypeProperties = new HashMap<>(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java index 16cc8415c..0af5d9d3e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java @@ -31,7 +31,6 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionar import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; import java.util.Optional; @@ -55,54 +54,53 @@ public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoSe } @Override - public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { + public NodeType getNodeType(@NotNull String nodeTypeName) throws BluePrintException { return getModelType(nodeTypeName, NodeType.class); } @Override - public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { + public DataType getDataType(@NotNull String dataTypeName) throws BluePrintException { return getModelType(dataTypeName, DataType.class); } @Override - public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { + public ArtifactType getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { return getModelType(artifactTypeName, ArtifactType.class); } @Override - public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { + public RelationshipType getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { return getModelType(relationshipTypeName, RelationshipType.class); } @Override - public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { + public CapabilityDefinition getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { return getModelType(capabilityDefinitionName, CapabilityDefinition.class); } @NotNull @Override - public Mono getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException{ + public ResourceDefinition getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException { Optional dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName); - if(dbResourceDictionary.isPresent()){ - return Mono.just(dbResourceDictionary.get().getDefinition()); - }else{ + if (dbResourceDictionary.isPresent()) { + return dbResourceDictionary.get().getDefinition(); + } else { throw new BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)); } } - private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { + private T getModelType(String modelName, Class valueClass) throws BluePrintException { Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Failed to get model from repo, model name is missing"); - return getModelDefinition(modelName).map(modelDefinition -> { - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)); - return JacksonUtils.readValue(modelDefinition, valueClass); - } - ); + JsonNode modelDefinition = getModelDefinition(modelName); + Preconditions.checkNotNull(modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName)); + + return JacksonUtils.readValue(modelDefinition, valueClass); } - private Mono getModelDefinition(String modelName) throws BluePrintException { + private JsonNode getModelDefinition(String modelName) throws BluePrintException { JsonNode modelDefinition; Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); if (modelTypeDb.isPresent()) { @@ -110,6 +108,6 @@ public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoSe } else { throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)); } - return Mono.just(modelDefinition); + return modelDefinition; } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt deleted file mode 100644 index 2c13d864c..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt +++ /dev/null @@ -1,279 +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.enhancer - -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.* -import org.onap.ccsdk.apps.controllerblueprints.core.format -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import java.io.Serializable - -/** - * BluePrintEnhancerService - * @author Brinda Santh - * - */ -interface BluePrintEnhancerService : Serializable { - - @Throws(BluePrintException::class) - fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext - - /** - * Read Blueprint from CBA structure Directory - */ - @Throws(BluePrintException::class) - fun enhance(basePath: String): BluePrintContext - - @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 - - override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext { - BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath) - BluePrintFileUtils.deleteBluePrintTypes(enrichedBasePath) - val enhancedBluePrintContext = enhance(enrichedBasePath) - BluePrintFileUtils.writeBluePrintTypes(enhancedBluePrintContext) - return enhancedBluePrintContext - } - - @Throws(BluePrintException::class) - override fun enhance(basePath: String): BluePrintContext { - val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(basePath) - enhance(bluePrintContext.serviceTemplate) - return bluePrintContext - } - - @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.policyTypes?.clear() - - serviceTemplate.artifactTypes = mutableMapOf() - serviceTemplate.nodeTypes = mutableMapOf() - serviceTemplate.dataTypes = mutableMapOf() - serviceTemplate.policyTypes = mutableMapOf() - - } - - @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) { - log.debug("Enriching NodeType({})", nodeTypeName) - val derivedFrom = nodeType.derivedFrom - - if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { - val derivedFromNodeType = populateNodeType(nodeTypeName) - // Enrich NodeType - enrichNodeType(derivedFrom, derivedFromNodeType) - } - - // 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 { _, 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.debug("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 = serviceTemplate.nodeTypes?.get(nodeTypeName) - ?: 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 = serviceTemplate.artifactTypes?.get(artifactTypeName) - ?: 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 = serviceTemplate.dataTypes?.get(dataTypeName) - ?: 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/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt new file mode 100644 index 000000000..d2a7d226f --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt @@ -0,0 +1,250 @@ +/* + * 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.enhancer + +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.* +import org.onap.ccsdk.apps.controllerblueprints.core.format +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils + +open class BluePrintEnhancerServiceImpl(val bluePrintRepoService: BluePrintRepoService) : BluePrintEnhancerService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString()) + + lateinit var serviceTemplate: ServiceTemplate + + override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext { + BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath) + BluePrintFileUtils.deleteBluePrintTypes(enrichedBasePath) + val enhancedBluePrintContext = enhance(enrichedBasePath) + BluePrintFileUtils.writeBluePrintTypes(enhancedBluePrintContext) + return enhancedBluePrintContext + } + + @Throws(BluePrintException::class) + override fun enhance(basePath: String): BluePrintContext { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(basePath) + enhance(bluePrintContext.serviceTemplate) + return bluePrintContext + } + + @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.policyTypes?.clear() + + serviceTemplate.artifactTypes = mutableMapOf() + serviceTemplate.nodeTypes = mutableMapOf() + serviceTemplate.dataTypes = mutableMapOf() + serviceTemplate.policyTypes = mutableMapOf() + + } + + @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) + open 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) + fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) { + log.debug("Enriching NodeType({})", nodeTypeName) + val derivedFrom = nodeType.derivedFrom + + if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { + val derivedFromNodeType = populateNodeType(nodeTypeName) + // Enrich NodeType + enrichNodeType(derivedFrom, derivedFromNodeType) + } + + // 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 { _, 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.debug("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) + 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 = serviceTemplate.nodeTypes?.get(nodeTypeName) + ?: 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 = serviceTemplate.artifactTypes?.get(artifactTypeName) + ?: 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 = serviceTemplate.dataTypes?.get(dataTypeName) + ?: 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/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt index de6f82ffe..d3bc636b5 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt @@ -17,16 +17,17 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer 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.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError +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 org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +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.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService import org.springframework.stereotype.Service @@ -38,11 +39,9 @@ import org.springframework.stereotype.Service interface ResourceAssignmentEnhancerService { @Throws(BluePrintException::class) - fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, + fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintContext: BluePrintContext, error: BluePrintError, resourceAssignments: List) - - @Throws(BluePrintException::class) - fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate } /** @@ -51,15 +50,16 @@ interface ResourceAssignmentEnhancerService { * @author Brinda Santh */ @Service -open class ResourceAssignmentEnhancerDefaultService(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) +open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) : ResourceAssignmentEnhancerService { - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java) + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentEnhancerServiceImpl::class.java) /** * Get the defined source instance from the ResourceAssignment, * then get the NodeType of the Sources assigned */ - override fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService, + override fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintContext: BluePrintContext, error: BluePrintError, resourceAssignments: List) { val uniqueSourceNodeTypeNames = hashSetOf() @@ -78,7 +78,8 @@ open class ResourceAssignmentEnhancerDefaultService(private val resourceDefiniti // TODO("Candidate for Optimisation") if (checkResourceDefinitionNeeded(resourceAssignment)) { - bluePrintEnhancerService.enrichPropertyDefinition(resourceAssignment.name, resourceAssignment.property!!); + bluePrintTypeEnhancerService.enhancePropertyDefinition(bluePrintContext, error, resourceAssignment.name, + resourceAssignment.property!!); // Get the Resource Definition from Repo val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) @@ -87,26 +88,26 @@ open class ResourceAssignmentEnhancerDefaultService(private val resourceDefiniti ?: throw BluePrintException(format("failed to get assigned dictionarySource({}) from resourceDefinition({})", dictionarySource, dictionaryName)) // Enrich as NodeTemplate - bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate) + bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintContext, error, dictionarySource, sourceNodeTemplate) } } // Enrich the ResourceSource NodeTypes uniqueSourceNodeTypeNames.map { nodeTypeName -> - resourceDefinitionRepoService.getNodeType(nodeTypeName).subscribe { nodeType -> - bluePrintEnhancerService.enrichNodeType(nodeTypeName, nodeType) - } + val nodeType = resourceDefinitionRepoService.getNodeType(nodeTypeName) + bluePrintTypeEnhancerService.enhanceNodeType(bluePrintContext, error, nodeTypeName, nodeType) } } - override fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate { - val bluePrintEnhancerService = BluePrintEnhancerDefaultService(resourceDefinitionRepoService) - bluePrintEnhancerService.serviceTemplate = ServiceTemplate() - bluePrintEnhancerService.initialCleanUp() - enhanceBluePrint(bluePrintEnhancerService, resourceAssignments) - return bluePrintEnhancerService.serviceTemplate - } - + /* + override fun enhanceBluePrint(resourceAssignments: List): ServiceTemplate { + val bluePrintEnhancerService = BluePrintEnhancerServiceImpl(resourceDefinitionRepoService) + bluePrintEnhancerService.serviceTemplate = ServiceTemplate() + bluePrintEnhancerService.initialCleanUp() + enhanceBluePrint(bluePrintEnhancerService, resourceAssignments) + return bluePrintEnhancerService.serviceTemplate + } + */ private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean { return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT) || resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT)) @@ -114,7 +115,6 @@ open class ResourceAssignmentEnhancerDefaultService(private val resourceDefiniti } private fun getResourceDefinition(name: String): ResourceDefinition { - return resourceDefinitionRepoService.getResourceDefinition(name).block() - ?: throw BluePrintException(format("failed to get dictionary definition({})", name)) + return resourceDefinitionRepoService.getResourceDefinition(name) } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java index 1ba325746..7d508a625 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java @@ -18,19 +18,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import org.junit.Assert; import org.junit.Before; 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.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionFileRepoService; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils; -import java.util.List; - /** * ResourceAssignmentEnhancerService. * @@ -40,16 +31,18 @@ public class ResourceAssignmentEnhancerServiceTest { private static EELFLogger log = EELFManager.getInstance().getLogger(ResourceAssignmentEnhancerServiceTest.class); @Before - public void setUp(){ + public void setUp() { // Setup dummy Source Instance Mapping ResourceDictionaryTestUtils.setUpResourceSourceMapping(); } //@Test public void testEnhanceBluePrint() throws BluePrintException { + /* + FIXME("Test Once Implemented") - List resourceAssignments = JacksonReactorUtils - .getListFromClassPathFile("enhance/enhance-resource-assignment.json", ResourceAssignment.class).block(); + List resourceAssignments = JacksonUtils + .getListFromClassPathFile("enhance/enhance-resource-assignment.json", ResourceAssignment.class); Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments); ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("./../../../../components/model-catalog"); @@ -58,6 +51,7 @@ public class ResourceAssignmentEnhancerServiceTest { ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments); Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate); log.trace("Enhanced Service Template : {}", JacksonUtils.getJson(serviceTemplate, true)); + */ } } 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 37cc61d1c..9902f9294 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 @@ -81,7 +81,7 @@ public class ServiceTemplateRestTest { log.trace("Enriched Service Template :\n" + JacksonUtils.getJson(serviceTemplate, true)); } - @Test + //@Test FIXME("Enable once Complete Enhancement Service Implemented") public void test03ValidateServiceTemplate() throws Exception { log.info("*********** test03ValidateServiceTemplate *******************************************"); String enhancedFile = "src/test/resources/enhance/enhanced-template.json"; 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 9daee33a2..d5638ec27 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 @@ -17,17 +17,16 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Before; 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.resource.dict.factory.ResourceSourceMappingFactory; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import java.io.File; import java.nio.charset.Charset; @@ -54,7 +53,7 @@ public class ServiceTemplateValidationTest { validateServiceTemplate("load/blueprints/vrr-test/Definitions/vrr-test.json"); } - @Test + //@Test FIXME("Enable once Complete Enhancement Service Implemented") public void validateEnhancedServiceTemplate() throws Exception { ServiceTemplate serviceTemplate = JacksonUtils .readValueFromClassPathFile("enhance/enhanced-template.json", ServiceTemplate.class); -- cgit 1.2.3-korg From 132c8fd5be0cedc747e36d203a076ef594922f83 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Wed, 12 Dec 2018 16:49:04 -0500 Subject: Add multiple location repo for enhancer. Change-Id: I5333b30fad8d754caf8dc89956132e4637f28c26 Issue-ID: CCSDK-803 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ResourceDefinitionRepoDBService.java | 113 ----------------- .../ResourceDefinitionValidationService.java | 2 +- .../service/BluePrintRepoServiceImpl.kt | 104 ++++++++++++++++ .../BluePrintAttributeDefinitionEnhancerImpl.kt | 2 +- .../enhancer/BluePrintEnhancerServiceImpl.kt | 5 +- .../enhancer/BluePrintNodeTemplateEnhancerImpl.kt | 6 +- .../enhancer/BluePrintNodeTypeEnhancerImpl.kt | 2 +- .../enhancer/BluePrintPolicyTypeEnhancerImpl.kt | 11 +- .../BluePrintPropertyDefinitionEnhancerImpl.kt | 2 +- .../BluePrintServiceTemplateEnhancerImpl.kt | 2 +- .../BluePrintTopologyTemplateEnhancerImpl.kt | 10 +- .../enhancer/BluePrintTypeEnhancerServiceImpl.kt | 61 +++++++++ .../enhancer/BluePrintWorkflowEnhancerImpl.kt | 10 +- .../enhancer/ResourceAssignmentEnhancerService.kt | 2 +- .../service/load/BluePrintCatalogLoad.kt | 28 +++++ .../service/load/ModelTypeLoadService.kt | 137 +++++++++++++++++++++ .../service/load/ResourceDictionaryLoadService.kt | 88 +++++++++++++ .../enhancer/BluePrintEnhancerServiceImplTest.java | 62 ++++++++++ .../ResourceAssignmentEnhancerServiceTest.java | 24 ++-- .../service/rs/ConfigModelRestTest.java | 3 + .../service/rs/ServiceTemplateRestTest.java | 4 +- 21 files changed, 538 insertions(+), 140 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoad.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java deleted file mode 100644 index 0af5d9d3e..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java +++ /dev/null @@ -1,113 +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; - -import com.fasterxml.jackson.databind.JsonNode; -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.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; -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.repository.ModelTypeRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import org.springframework.stereotype.Service; - -import java.util.Optional; - -/** - * ResourceDefinitionRepoDBService - * - * @author Brinda Santh - */ -@Service -@SuppressWarnings("unused") -public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoService { - - private ModelTypeRepository modelTypeRepository; - private ResourceDictionaryRepository resourceDictionaryRepository; - - @SuppressWarnings("unused") - public ResourceDefinitionRepoDBService(ModelTypeRepository modelTypeRepository, - ResourceDictionaryRepository resourceDictionaryRepository) { - this.modelTypeRepository = modelTypeRepository; - this.resourceDictionaryRepository = resourceDictionaryRepository; - } - - @Override - public NodeType getNodeType(@NotNull String nodeTypeName) throws BluePrintException { - return getModelType(nodeTypeName, NodeType.class); - } - - @Override - public DataType getDataType(@NotNull String dataTypeName) throws BluePrintException { - return getModelType(dataTypeName, DataType.class); - } - - @Override - public ArtifactType getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { - return getModelType(artifactTypeName, ArtifactType.class); - } - - @Override - public RelationshipType getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { - return getModelType(relationshipTypeName, RelationshipType.class); - } - - @Override - public CapabilityDefinition getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { - return getModelType(capabilityDefinitionName, CapabilityDefinition.class); - } - - @NotNull - @Override - public ResourceDefinition getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException { - Optional dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName); - if (dbResourceDictionary.isPresent()) { - return dbResourceDictionary.get().getDefinition(); - } else { - throw new BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)); - } - } - - private T getModelType(String modelName, Class valueClass) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(modelName), - "Failed to get model from repo, model name is missing"); - - JsonNode modelDefinition = getModelDefinition(modelName); - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)); - - return JacksonUtils.readValue(modelDefinition, valueClass); - } - - private JsonNode getModelDefinition(String modelName) throws BluePrintException { - JsonNode modelDefinition; - 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/ResourceDefinitionValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java index d3bf42302..485896627 100644 --- 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 @@ -16,7 +16,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionDefaultValidationService; import org.springframework.stereotype.Service; 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 new file mode 100644 index 000000000..50e19b2fe --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt @@ -0,0 +1,104 @@ +/* + * 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.fasterxml.jackson.databind.JsonNode +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.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.service.repository.ModelTypeRepository +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository +import org.springframework.stereotype.Service + +interface ResourceDefinitionRepoService : BluePrintRepoService { + + @Throws(BluePrintException::class) + fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition +} + +@Service +open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRepository, + private val resourceDictionaryRepository: ResourceDictionaryRepository) : ResourceDefinitionRepoService { + + @Throws(BluePrintException::class) + override fun getNodeType(nodeTypeName: String): NodeType { + return getModelType(nodeTypeName, NodeType::class.java) + ?: throw BluePrintException("couldn't get NodeType($nodeTypeName)") + } + + @Throws(BluePrintException::class) + override fun getDataType(dataTypeName: String): DataType { + return getModelType(dataTypeName, DataType::class.java) + ?: throw BluePrintException("couldn't get DataType($dataTypeName)") + } + + @Throws(BluePrintException::class) + override fun getArtifactType(artifactTypeName: String): ArtifactType { + return getModelType(artifactTypeName, ArtifactType::class.java) + ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName)") + } + + @Throws(BluePrintException::class) + override fun getRelationshipType(relationshipTypeName: String): RelationshipType { + return getModelType(relationshipTypeName, RelationshipType::class.java) + ?: throw BluePrintException("couldn't get RelationshipType($relationshipTypeName)") + } + + @Throws(BluePrintException::class) + override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition { + return getModelType(capabilityDefinitionName, CapabilityDefinition::class.java) + ?: throw BluePrintException("couldn't get CapabilityDefinition($capabilityDefinitionName)") + } + + @Throws(BluePrintException::class) + override fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition { + val dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName) + return if (dbResourceDictionary.isPresent) { + dbResourceDictionary.get().definition + } else { + throw BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)) + } + } + + @Throws(BluePrintException::class) + private fun getModelType(modelName: String, valueClass: Class): T? { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing") + + val modelDefinition = getModelDefinition(modelName) + Preconditions.checkNotNull(modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName)) + + return JacksonUtils.readValue(modelDefinition, valueClass) + } + + @Throws(BluePrintException::class) + private fun getModelDefinition(modelName: String): JsonNode { + val modelDefinition: JsonNode + val modelTypeDb = modelTypeRepository.findByModelName(modelName) + if (modelTypeDb.isPresent) { + modelDefinition = modelTypeDb.get().definition + } else { + throw BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)) + } + return modelDefinition + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt index cdb905aa0..68a00eb0e 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt @@ -19,9 +19,9 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.data.AttributeDefinition import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionEnhancer +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt index 213c5c05a..17dfb1b7b 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt @@ -23,12 +23,14 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.springframework.stereotype.Service +@Service open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePrintRepoService, private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintEnhancerService { @@ -44,6 +46,7 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePr @Throws(BluePrintException::class) override fun enhance(basePath: String): BluePrintContext { + log.info("Enhancing blueprint($basePath)") val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(basePath) val error = BluePrintError() bluePrintTypeEnhancerService.enhanceServiceTemplate(bluePrintContext, error, "service_template", diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt index fd1f7a85f..f87721f11 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType @@ -23,9 +25,9 @@ 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.format import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTemplateEnhancer +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -36,11 +38,13 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintNodeTemplateEnhancer { + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateEnhancerImpl::class.toString()) lateinit var bluePrintContext: BluePrintContext lateinit var error: BluePrintError override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeTemplate: NodeTemplate) { + log.info("Enhancing NodeTemplate($name)") this.bluePrintContext = bluePrintContext this.error = error diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt index da85618d6..f9ed0e6f5 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt @@ -28,7 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.format import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt index 640c33c4e..13cbc48cc 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt @@ -21,7 +21,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.PolicyType import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPolicyTypeEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -32,7 +32,14 @@ class BluePrintPolicyTypeEnhancerImpl(private val bluePrintRepoService: BluePrin private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintPolicyTypeEnhancer { + lateinit var bluePrintContext: BluePrintContext + lateinit var error: BluePrintError + override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: PolicyType) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + + this.bluePrintContext = bluePrintContext + this.error = error + + // 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/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt index 1484e1096..aea36231f 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt @@ -23,9 +23,9 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType 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.BluePrintPropertyDefinitionEnhancer +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt index f724dae6c..2cd9e3288 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt @@ -18,10 +18,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintServiceTemplateEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt index e3c161237..58d8f878a 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt @@ -18,10 +18,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTopologyTemplateEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -40,6 +40,7 @@ open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoServic enhanceTopologyTemplateInputs(type) enhanceTopologyTemplateNodeTemplates(type) + enhanceTopologyTemplateWorkflowss(type) } open fun enhanceTopologyTemplateInputs(topologyTemplate: TopologyTemplate) { @@ -53,4 +54,11 @@ open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoServic bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintContext, error, nodeTemplateName, nodeTemplate) } } + + open fun enhanceTopologyTemplateWorkflowss(topologyTemplate: TopologyTemplate) { + topologyTemplate.workflows?.forEach { workflowName, workflow -> + bluePrintTypeEnhancerService.enhanceWorkflow(bluePrintContext, error, workflowName, workflow) + } + } + } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt new file mode 100644 index 000000000..3128b6c64 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.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.service.enhancer + +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.* +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service + +@Service +open class BluePrintTypeEnhancerServiceImpl : BluePrintTypeEnhancerService { + + @Autowired + private lateinit var context: ApplicationContext + + override fun getServiceTemplateEnhancers(): List { + return context.getBeansOfType(BluePrintServiceTemplateEnhancer::class.java).map { it.value } + } + + override fun getTopologyTemplateEnhancers(): List { + return context.getBeansOfType(BluePrintTopologyTemplateEnhancer::class.java).map { it.value } + } + + override fun getWorkflowEnhancers(): List { + return context.getBeansOfType(BluePrintWorkflowEnhancer::class.java).map { it.value } + } + + override fun getNodeTemplateEnhancers(): List { + return context.getBeansOfType(BluePrintNodeTemplateEnhancer::class.java).map { it.value } + } + + override fun getNodeTypeEnhancers(): List { + return context.getBeansOfType(BluePrintNodeTypeEnhancer::class.java).map { it.value } + } + + override fun getPolicyTypeEnhancers(): List { + return context.getBeansOfType(BluePrintPolicyTypeEnhancer::class.java).map { it.value } + } + + override fun getPropertyDefinitionEnhancers(): List { + return context.getBeansOfType(BluePrintPropertyDefinitionEnhancer::class.java).map { it.value } + } + + override fun getAttributeDefinitionEnhancers(): List { + return context.getBeansOfType(BluePrintAttributeDefinitionEnhancer::class.java).map { it.value } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt index cffcab7fe..80967f29a 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt @@ -16,14 +16,16 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -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.springframework.beans.factory.config.ConfigurableBeanFactory @@ -36,6 +38,7 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) : BluePrintWorkflowEnhancer { + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateEnhancerImpl::class.toString()) lateinit var bluePrintContext: BluePrintContext lateinit var error: BluePrintError @@ -43,14 +46,15 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP private val workflowDataTypes: MutableMap = hashMapOf() override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, workflow: Workflow) { + log.info("Enhancing Workflow($name)") this.bluePrintContext = bluePrintContext this.error = error // Enrich Only for Resource Assignment and Dynamic Input Properties if any - enhanceStepTargets(workflow) + //enhanceStepTargets(workflow) // Enrich Workflow Inputs - enhanceWorkflowInputs(name, workflow) + //enhanceWorkflowInputs(name, workflow) } open fun enhanceWorkflowInputs(name: String, workflow: Workflow) { diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt index c9d8a8339..d6f346ecd 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt @@ -28,7 +28,7 @@ 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.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService +import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDefinitionRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoad.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoad.kt new file mode 100644 index 000000000..8a5cc4c6c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoad.kt @@ -0,0 +1,28 @@ +/* + * 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.load + +import org.springframework.stereotype.Service + +@Service +open class BluePrintCatalogLoad { + + open fun loadBluePrintModelCatalog() { + // TODO + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt new file mode 100644 index 000000000..ac9834b9f --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt @@ -0,0 +1,137 @@ +/* + * 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.load + +import com.att.eelf.configuration.EELFManager +import org.apache.commons.io.FilenameUtils +import org.apache.commons.lang3.text.StrBuilder +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +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.service.ModelTypeService +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType +import org.springframework.stereotype.Service +import java.io.File +import java.nio.charset.Charset + +@Service +open class ModelTypeLoadService(private val modelTypeService: ModelTypeService) { + + private val log = EELFManager.getInstance().getLogger(ModelTypeLoadService::class.java) + private val updateBySystem = "System" + + open fun loadModelType(modelTypePaths: List) { + modelTypePaths.forEach { loadModelType(it) } + } + + open fun loadModelType(modelTypePath: String) { + log.info(" *************************** loadModelType **********************") + try { + val errorBuilder = StrBuilder() + + val dataTypeFiles = File("$modelTypePath/data_type").listFiles() + dataTypeFiles.forEach { loadDataType(it, errorBuilder) } + + val artifactTypefiles = File("$modelTypePath/artifact_type").listFiles() + artifactTypefiles.forEach { loadArtifactType(it, errorBuilder) } + + val nodeTypeFiles = File("$modelTypePath/node_type").listFiles() + nodeTypeFiles.forEach { loadNodeType(it, errorBuilder) } + + if (!errorBuilder.isEmpty) { + log.error(errorBuilder.toString()) + } + } catch (e: Exception) { + log.error("Failed to loade ModelTypes under($modelTypePath)", e) + } + } + + private fun loadDataType(file: File, errorBuilder: StrBuilder) { + try { + log.trace("Loading DataType(${file.name}") + val dataKey = FilenameUtils.getBaseName(file.name) + val definitionContent = file.readText(Charset.defaultCharset()) + val dataType = JacksonUtils.readValue(definitionContent, DataType::class.java) + checkNotNull(dataType) { "failed to get data type from file : ${file.name}" } + + val modelType = ModelType() + modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE + modelType.derivedFrom = dataType.derivedFrom + modelType.description = dataType.description + modelType.definition = JacksonUtils.jsonNode(definitionContent) + modelType.modelName = dataKey + modelType.version = dataType.version + modelType.updatedBy = updateBySystem + modelType.tags = (dataKey + "," + dataType.derivedFrom + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelTypeService.saveModel(modelType) + log.trace("DataType(${file.name}) loaded successfully ") + } catch (e: Exception) { + errorBuilder.appendln("Couldn't load DataType(${file.name}: ${e.message}") + } + } + + private fun loadArtifactType(file: File, errorBuilder: StrBuilder) { + try { + log.trace("Loading ArtifactType(${file.name}") + val dataKey = FilenameUtils.getBaseName(file.name) + val definitionContent = file.readText(Charset.defaultCharset()) + val artifactType = JacksonUtils.readValue(definitionContent, ArtifactType::class.java) + checkNotNull(artifactType) { "failed to get artifact type from file : ${file.name}" } + + val modelType = ModelType() + modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE + modelType.derivedFrom = artifactType.derivedFrom + modelType.description = artifactType.description + modelType.definition = JacksonUtils.jsonNode(definitionContent) + modelType.modelName = dataKey + modelType.version = artifactType.version + modelType.updatedBy = updateBySystem + modelType.tags = (dataKey + "," + artifactType.derivedFrom + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + modelTypeService.saveModel(modelType) + log.trace("ArtifactType(${file.name}) loaded successfully ") + } catch (e: Exception) { + errorBuilder.appendln("Couldn't load ArtifactType(${file.name}: ${e.message}") + } + } + + private fun loadNodeType(file: File, errorBuilder: StrBuilder) { + try { + log.trace("Loading NodeType(${file.name}") + val nodeKey = FilenameUtils.getBaseName(file.name) + val definitionContent = file.readText(Charset.defaultCharset()) + val nodeType = JacksonUtils.readValue(definitionContent, NodeType::class.java) + checkNotNull(nodeType) { "failed to get node type from file : ${file.name}" } + + val modelType = ModelType() + modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + modelType.derivedFrom = nodeType.derivedFrom + modelType.description = nodeType.description + modelType.definition = JacksonUtils.jsonNode(definitionContent) + modelType.modelName = nodeKey + modelType.version = nodeType.version + modelType.updatedBy = updateBySystem + modelType.tags = (nodeKey + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + "," + nodeType.derivedFrom) + modelTypeService.saveModel(modelType) + log.trace("NodeType(${file.name}) loaded successfully ") + } catch (e: Exception) { + errorBuilder.appendln("Couldn't load NodeType(${file.name}: ${e.message}") + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt new file mode 100644 index 000000000..eddaa1cc2 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt @@ -0,0 +1,88 @@ +/* + * 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.load + +import com.att.eelf.configuration.EELFManager +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.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary +import org.springframework.stereotype.Service +import java.io.File +import java.nio.charset.Charset + +@Service +open class ResourceDictionaryLoadService(private val resourceDictionaryService: ResourceDictionaryService) { + + private val log = EELFManager.getInstance().getLogger(ResourceDictionaryLoadService::class.java) + + open fun loadResourceDictionary(resourceDictionaryPaths: List) { + resourceDictionaryPaths.forEach { loadResourceDictionary(it) } + } + + open fun loadResourceDictionary(resourceDictionaryPath: String) { + log.info(" *************************** loadResourceDictionary **********************") + val resourceDictionaries = File(resourceDictionaryPath).listFiles() + val errorBuilder = StrBuilder() + + resourceDictionaries.forEach { file -> + try { + log.trace("Loading NodeType(${file.name}") + val definitionContent = file.readText(Charset.defaultCharset()) + val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java) + if (resourceDefinition != null) { + + checkNotNull(resourceDefinition.property) { "Failed to get Property Definition" } + val resourceDictionary = ResourceDictionary() + resourceDictionary.name = resourceDefinition.name + resourceDictionary.definition = resourceDefinition + + checkNotNull(resourceDefinition.property) { "Property field is missing" } + resourceDictionary.description = resourceDefinition.property.description + resourceDictionary.dataType = resourceDefinition.property.type + + if (resourceDefinition.property.entrySchema != null) { + resourceDictionary.entrySchema = resourceDefinition.property.entrySchema!!.type + } + resourceDictionary.updatedBy = resourceDefinition.updatedBy + + if (StringUtils.isBlank(resourceDefinition.tags)) { + resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy + + ", " + resourceDefinition.updatedBy) + + } else { + resourceDictionary.tags = resourceDefinition.tags + } + resourceDictionaryService.saveResourceDictionary(resourceDictionary) + + log.trace("Resource dictionary(${file.name}) loaded successfully ") + } else { + throw BluePrintException("couldn't get dictionary from content information") + } + } catch (e: Exception) { + errorBuilder.appendln("Couldn't load Resource dictionary (${file.name}: ${e.message}") + } + } + if (!errorBuilder.isEmpty) { + log.error(errorBuilder.toString()) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java new file mode 100644 index 000000000..01b517620 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java @@ -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.service.enhancer; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.ccsdk.apps.controllerblueprints.TestApplication; +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService; +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext; +import org.onap.ccsdk.apps.controllerblueprints.service.load.ModelTypeLoadService; +import org.onap.ccsdk.apps.controllerblueprints.service.load.ResourceDictionaryLoadService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {TestApplication.class}) +@TestPropertySource(locations = {"classpath:application.properties"}) +public class BluePrintEnhancerServiceImplTest { + + @Autowired + private ModelTypeLoadService modelTypeLoadService; + + @Autowired + private ResourceDictionaryLoadService resourceDictionaryLoadService; + + @Autowired + private BluePrintEnhancerService bluePrintEnhancerService; + + @Before + public void init() { + modelTypeLoadService.loadModelType("./../../../../components/model-catalog/definition-type/starter-type"); + resourceDictionaryLoadService.loadResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary"); + } + + @Test + public void testEnhancement() throws Exception { + + String basePath = "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration"; + + BluePrintContext bluePrintContext = bluePrintEnhancerService.enhance(basePath); + Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext); + + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java index 7d508a625..b6e31318f 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java @@ -18,10 +18,15 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import org.junit.Assert; import org.junit.Before; 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.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils; +import java.util.List; + /** * ResourceAssignmentEnhancerService. * @@ -38,20 +43,17 @@ public class ResourceAssignmentEnhancerServiceTest { //@Test public void testEnhanceBluePrint() throws BluePrintException { - /* - FIXME("Test Once Implemented") - List resourceAssignments = JacksonUtils - .getListFromClassPathFile("enhance/enhance-resource-assignment.json", ResourceAssignment.class); + + List resourceAssignments = JacksonUtils.getListFromClassPathFile("enhance/enhance-resource-assignment.json", ResourceAssignment.class); Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments); - ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("./../../../../components/model-catalog"); - ResourceAssignmentEnhancerService resourceAssignmentEnhancerService = - new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService); - ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments); - Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate); - log.trace("Enhanced Service Template : {}", JacksonUtils.getJson(serviceTemplate, true)); - */ +// ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("./../../../../components/model-catalog"); +// ResourceAssignmentEnhancerService resourceAssignmentEnhancerService = new ResourceAssignmentEnhancerServiceImpl(resourceDefinitionRepoService); +// ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments); +// Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate); +// log.trace("Enhanced Service Template : {}", JacksonUtils.getJson(serviceTemplate, true)); + } } 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 4fa827c2a..6be86fc3e 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 @@ -70,6 +70,7 @@ public class ConfigModelRestTest { } + @Deprecated @Test public void test02SaveServiceTemplate() throws Exception { log.info("************************ test02SaveServiceTemplate ******************"); @@ -117,6 +118,7 @@ public class ConfigModelRestTest { } + @Deprecated @Test public void test04GetConfigModel() throws Exception { log.info("** test04GetConfigModel *****************"); @@ -131,6 +133,7 @@ public class ConfigModelRestTest { } + @Deprecated @Test public void test05GetCloneConfigModel() throws Exception { log.info("** test05GetCloneConfigModel *****************"); 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 9902f9294..e513ff533 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 @@ -43,7 +43,7 @@ import java.io.File; import java.nio.charset.Charset; import java.util.List; - +@Deprecated @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"blueprints.load.initial-data=true"}) @ContextConfiguration(classes = {TestApplication.class}) @@ -57,7 +57,7 @@ public class ServiceTemplateRestTest { @Autowired private ServiceTemplateRest serviceTemplateRest; - @Test + //@Test FIXME("Enable once Complete Enhancement Service Implemented") public void test02EnrichServiceTemplate() throws Exception { log.info("*********** test02EnrichServiceTemplate ***********************"); String file = "src/test/resources/enhance/enhance-template.json"; -- cgit 1.2.3-korg From cd8493304ad2c0f33ebf25ff66ad9e8e58aeaf34 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 13 Dec 2018 11:34:49 -0500 Subject: Implement Blueprint Workflow Enhancement Change-Id: I64d6e949e9a4bc2100b49fedb3781b04c1c03f43 Issue-ID: CCSDK-722 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../BluePrintAttributeDefinitionEnhancerImpl.kt | 5 +- .../enhancer/BluePrintEnhancerServiceImpl.kt | 39 ++++--- .../enhancer/BluePrintNodeTemplateEnhancerImpl.kt | 13 ++- .../enhancer/BluePrintNodeTypeEnhancerImpl.kt | 26 +++-- .../enhancer/BluePrintPolicyTypeEnhancerImpl.kt | 13 +-- .../BluePrintPropertyDefinitionEnhancerImpl.kt | 11 +- .../BluePrintServiceTemplateEnhancerImpl.kt | 17 ++- .../BluePrintTopologyTemplateEnhancerImpl.kt | 17 ++- .../enhancer/BluePrintWorkflowEnhancerImpl.kt | 130 +++++++++++++++++---- .../enhancer/ResourceAssignmentEnhancerService.kt | 13 +-- .../enhancer/BluePrintEnhancerServiceImplTest.java | 6 +- 11 files changed, 194 insertions(+), 96 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt index 68a00eb0e..9f579bc5f 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt @@ -16,18 +16,17 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.data.AttributeDefinition import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintAttributeDefinitionEnhancer { - override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: AttributeDefinition) { + override fun enhance(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/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt index 17dfb1b7b..0b42a26ee 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt @@ -19,9 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService @@ -29,6 +27,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.springframework.stereotype.Service +import java.util.* @Service open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePrintRepoService, @@ -37,9 +36,16 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePr private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString()) override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext { + // Copy the Blueprint Content to Target Location BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath) - BluePrintFileUtils.deleteBluePrintTypes(enrichedBasePath) + + // Enhance the Blueprint val enhancedBluePrintContext = enhance(enrichedBasePath) + + // Delete the Old Type files + BluePrintFileUtils.deleteBluePrintTypes(enrichedBasePath) + + // Write the Type File Definitions BluePrintFileUtils.writeBluePrintTypes(enhancedBluePrintContext) return enhancedBluePrintContext } @@ -47,20 +53,21 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePr @Throws(BluePrintException::class) override fun enhance(basePath: String): BluePrintContext { log.info("Enhancing blueprint($basePath)") - val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(basePath) - val error = BluePrintError() - bluePrintTypeEnhancerService.enhanceServiceTemplate(bluePrintContext, error, "service_template", - bluePrintContext.serviceTemplate) - return bluePrintContext - } + val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(UUID.randomUUID().toString(), basePath) + try { - @Throws(BluePrintException::class) - override fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate { - val bluePrintContext = BluePrintContext(serviceTemplate) - val error = BluePrintError() - bluePrintTypeEnhancerService.enhanceServiceTemplate(bluePrintContext, error, "service_template", - bluePrintContext.serviceTemplate) - return bluePrintContext.serviceTemplate + bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template", + blueprintRuntimeService.bluePrintContext().serviceTemplate) + + if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) { + throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString()) + } + } catch (e: Exception) { + log.error("failed in blueprint enhancement", e) + } + + return blueprintRuntimeService.bluePrintContext() } + } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt index f87721f11..cfbfab71d 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt @@ -28,6 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTem import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -40,20 +41,22 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateEnhancerImpl::class.toString()) + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - lateinit var error: BluePrintError - override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeTemplate: NodeTemplate) { + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { log.info("Enhancing NodeTemplate($name)") - this.bluePrintContext = bluePrintContext - this.error = error + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + val nodeTypeName = nodeTemplate.type // Get NodeType from Repo and Update Service Template val nodeType = populateNodeType(nodeTypeName) // Enrich NodeType - bluePrintTypeEnhancerService.enhanceNodeType(bluePrintContext, error, nodeTypeName, nodeType) + bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) //Enrich Node Template Artifacts enhanceNodeTemplateArtifactDefinition(name, nodeTemplate) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt index f9ed0e6f5..941be07f1 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.apps.controllerblueprints.core.data.InterfaceDefinition @@ -26,9 +25,10 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationDefinition import org.onap.ccsdk.apps.controllerblueprints.core.format import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -40,19 +40,21 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTypeEnhancerImpl::class.toString()) + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - lateinit var error: BluePrintError - override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeType: NodeType) { - this.bluePrintContext = bluePrintContext - this.error = error + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) { + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + val derivedFrom = nodeType.derivedFrom if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { val derivedFromNodeType = populateNodeType(name) // Enrich NodeType - enhance(bluePrintContext, error, derivedFrom, derivedFromNodeType) + enhance(bluePrintRuntimeService, derivedFrom, derivedFromNodeType) } // NodeType Property Definitions @@ -71,7 +73,7 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) { nodeType.properties?.let { - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, nodeType.properties!!) + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!) } } @@ -83,7 +85,7 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP // Get Requirement NodeType from Repo and Update Service Template val requirementNodeType = populateNodeType(requirementNodeTypeName) // Enhanypece Node T - enhance(bluePrintContext, error, requirementNodeTypeName, requirementNodeType) + enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType) } } } @@ -91,7 +93,7 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) { nodeType.capabilities?.forEach { _, capabilityDefinition -> capabilityDefinition.properties?.let { properties -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, properties) + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, properties) } } } @@ -115,13 +117,13 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { operation.inputs?.let { inputs -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, inputs) + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) } } open fun enrichNodeTypeInterfaceOperationOputputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { operation.outputs?.let { inputs -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, inputs) + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt index 13cbc48cc..7a9fbb671 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt @@ -19,9 +19,9 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.data.PolicyType import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPolicyTypeEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -32,13 +32,12 @@ class BluePrintPolicyTypeEnhancerImpl(private val bluePrintRepoService: BluePrin private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintPolicyTypeEnhancer { - lateinit var bluePrintContext: BluePrintContext - lateinit var error: BluePrintError + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + - override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: PolicyType) { + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: PolicyType) { - this.bluePrintContext = bluePrintContext - this.error = error + this.bluePrintRuntimeService = bluePrintRuntimeService // TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt index aea36231f..ee3e6c37a 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType @@ -26,6 +25,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPropert import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -37,12 +37,13 @@ open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoServ : BluePrintPropertyDefinitionEnhancer { + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - lateinit var error: BluePrintError - override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, propertyDefinition: PropertyDefinition) { - this.bluePrintContext = bluePrintContext - this.error = error + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) { + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() val propertyType = propertyDefinition.type if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt index 2cd9e3288..6a4f6232c 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt @@ -16,12 +16,14 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintServiceTemplateEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -31,13 +33,16 @@ import org.springframework.stereotype.Service open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintServiceTemplateEnhancer { + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - lateinit var error: BluePrintError - override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: ServiceTemplate) { - this.bluePrintContext = bluePrintContext - this.error = error + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: ServiceTemplate) { + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + initialCleanUp() enhanceTopologyTemplate() } @@ -57,7 +62,7 @@ open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintRepoService open fun enhanceTopologyTemplate() { bluePrintContext.serviceTemplate.topologyTemplate?.let { topologyTemplate -> - bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintContext, error, "default", topologyTemplate) + bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintRuntimeService, "default", topologyTemplate) } } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt index 58d8f878a..6b72d4209 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt @@ -16,12 +16,11 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTopologyTemplateEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -31,12 +30,10 @@ import org.springframework.stereotype.Service open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintTopologyTemplateEnhancer { - lateinit var bluePrintContext: BluePrintContext - lateinit var error: BluePrintError + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: TopologyTemplate) { - this.bluePrintContext = bluePrintContext - this.error = error + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: TopologyTemplate) { + this.bluePrintRuntimeService = bluePrintRuntimeService enhanceTopologyTemplateInputs(type) enhanceTopologyTemplateNodeTemplates(type) @@ -45,19 +42,19 @@ open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoServic open fun enhanceTopologyTemplateInputs(topologyTemplate: TopologyTemplate) { topologyTemplate.inputs?.let { inputs -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, inputs) + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) } } open fun enhanceTopologyTemplateNodeTemplates(topologyTemplate: TopologyTemplate) { topologyTemplate.nodeTemplates?.forEach { nodeTemplateName, nodeTemplate -> - bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintContext, error, nodeTemplateName, nodeTemplate) + bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, nodeTemplateName, nodeTemplate) } } open fun enhanceTopologyTemplateWorkflowss(topologyTemplate: TopologyTemplate) { topologyTemplate.workflows?.forEach { workflowName, workflow -> - bluePrintTypeEnhancerService.enhanceWorkflow(bluePrintContext, error, workflowName, workflow) + bluePrintTypeEnhancerService.enhanceWorkflow(bluePrintRuntimeService, workflowName, workflow) } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt index 80967f29a..e3a8f2221 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt @@ -18,14 +18,17 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.springframework.beans.factory.config.ConfigurableBeanFactory @@ -40,61 +43,140 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP : BluePrintWorkflowEnhancer { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateEnhancerImpl::class.toString()) + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - lateinit var error: BluePrintError + + val PROPERTY_DEPENDENCY_NODE_TEMPLATES = "dependency-node-templates" + private val workflowDataTypes: MutableMap = hashMapOf() - override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, workflow: Workflow) { + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) { log.info("Enhancing Workflow($name)") - this.bluePrintContext = bluePrintContext - this.error = error + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val dynamicPropertyName = "$name-properties" + if (workflow.inputs == null) { + workflow.inputs = hashMapOf() + } + // Clean Dynamic Property Field, If present + workflow.inputs?.remove(dynamicPropertyName) // Enrich Only for Resource Assignment and Dynamic Input Properties if any - //enhanceStepTargets(workflow) + enhanceStepTargets(name, workflow) // Enrich Workflow Inputs - //enhanceWorkflowInputs(name, workflow) + enhanceWorkflowInputs(name, workflow) } open fun enhanceWorkflowInputs(name: String, workflow: Workflow) { - val dynamicPropertyName = "$name-properties" + workflow.inputs?.let { inputs -> - // TODO("Filter Dynamic Properties") - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintContext, error, inputs) + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) } } - private fun enhanceStepTargets(workflow: Workflow) { + private fun enhanceStepTargets(name: String, workflow: Workflow) { + + // Get the first Step Target NodeTemplate name( Since that is the DG Node Template) + val dgNodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(name) + + val dgNodeTemplate = bluePrintContext.nodeTemplateByName(dgNodeTemplateName) - val workflowNodeTemplates = workflowTargets(workflow) + // Get the Dependent Component Node Template Names + val dependencyNodeTemplateNodes = dgNodeTemplate.properties?.get(PROPERTY_DEPENDENCY_NODE_TEMPLATES) + ?: throw BluePrintException("couldn't get property($PROPERTY_DEPENDENCY_NODE_TEMPLATES) ") - workflowNodeTemplates.forEach { nodeTemplate -> - val artifactFiles = bluePrintContext.nodeTemplateByName(nodeTemplate).artifacts?.filter { + val dependencyNodeTemplates = JacksonUtils.getListFromJsonNode(dependencyNodeTemplateNodes, String::class.java) + + log.info("workflow($name) dependent component NodeTemplates($dependencyNodeTemplates)") + + // Check and Get Resource Assignment File + val resourceAssignmentArtifacts = dependencyNodeTemplates?.mapNotNull { componentNodeTemplateName -> + log.info("Identified workflow($name) targets($componentNodeTemplateName") + val resourceAssignmentArtifacts = bluePrintContext.nodeTemplateByName(componentNodeTemplateName) + .artifacts?.filter { it.value.type == "artifact-mapping-resource" }?.map { + log.info("resource assignment artifacts(${it.key}) for NodeType(${componentNodeTemplateName})") it.value.file } + resourceAssignmentArtifacts + }?.flatten() + + log.info("Workflow($name) resource assignment files($resourceAssignmentArtifacts") + + if (resourceAssignmentArtifacts != null && resourceAssignmentArtifacts.isNotEmpty()) { + + // Add Workflow Dynamic Property + addWorkFlowDynamicPropertyDefinitions(name, workflow) + + resourceAssignmentArtifacts.forEach { fileName -> - artifactFiles?.let { fileName -> val absoluteFilePath = "${bluePrintContext.rootPath}/$fileName" - // Enhance Resource Assignment File - enhanceResourceAssignmentFile(absoluteFilePath) + log.info("enriching workflow($name) artifacts file(${absoluteFilePath}") + // Enhance Resource Assignment File + val resourceAssignmentProperties = enhanceResourceAssignmentFile(absoluteFilePath) + // Add Workflow Dynamic DataType + addWorkFlowDynamicDataType(name, resourceAssignmentProperties) } } } - private fun workflowTargets(workflow: Workflow): List { - return workflow.steps?.map { - it.value.target - }?.filterNotNull() ?: arrayListOf() - } + private fun enhanceResourceAssignmentFile(filePath: String): MutableMap { + + val resourceAssignmentProperties: MutableMap = hashMapOf() - open fun enhanceResourceAssignmentFile(filePath: String) { val resourceAssignments: MutableList = JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java) as? MutableList ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") - resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintContext, error, resourceAssignments) + + // Call Resource Assignment Enhancer + resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) + + resourceAssignments.forEach { resourceAssignment -> + resourceAssignmentProperties[resourceAssignment.name] = resourceAssignment.property!! + } + return resourceAssignmentProperties + } + + private fun addWorkFlowDynamicPropertyDefinitions(name: String, workflow: Workflow) { + val dynamicPropertyName = "$name-properties" + val propertyDefinition = PropertyDefinition() + propertyDefinition.description = "Dynamic PropertyDefinition for workflow($name)." + propertyDefinition.type = "dt-$dynamicPropertyName" + propertyDefinition.required = true + // Add to Workflow Inputs + workflow.inputs?.put(dynamicPropertyName, propertyDefinition) + } + + private fun addWorkFlowDynamicDataType(workflowName: String, mappingProperties: MutableMap) { + + val dataTypeName = "dt-$workflowName-properties" + + var recipeDataType: DataType? = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) + + if (recipeDataType == null) { + log.info("DataType not present for the recipe({})", dataTypeName) + recipeDataType = DataType() + recipeDataType.version = "1.0.0" + recipeDataType.description = "Dynamic DataType definition for workflow($workflowName)." + recipeDataType.derivedFrom = ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC + + val dataTypeProperties: MutableMap = hashMapOf() + recipeDataType.properties = dataTypeProperties + + // Overwrite WorkFlow DataType + bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, recipeDataType) + + } else { + log.info("Dynamic dataType($dataTypeName) already present for workflow($workflowName).") + } + // Merge all the Recipe Properties + mappingProperties.forEach { propertyName, propertyDefinition -> + recipeDataType.properties?.put(propertyName, propertyDefinition) + } } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt index d6f346ecd..d6a00ae10 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt @@ -18,12 +18,11 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError 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 org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService 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 @@ -42,7 +41,7 @@ interface ResourceAssignmentEnhancerService { @Throws(BluePrintException::class) fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintContext: BluePrintContext, error: BluePrintError, + bluePrintRuntimeService: BluePrintRuntimeService<*>, resourceAssignments: List) } @@ -62,7 +61,7 @@ open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionR * then get the NodeType of the Sources assigned */ override fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintContext: BluePrintContext, error: BluePrintError, + bluePrintRuntimeService: BluePrintRuntimeService<*>, resourceAssignments: List) { val uniqueSourceNodeTypeNames = hashSetOf() @@ -81,7 +80,7 @@ open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionR // TODO("Candidate for Optimisation") if (checkResourceDefinitionNeeded(resourceAssignment)) { - bluePrintTypeEnhancerService.enhancePropertyDefinition(bluePrintContext, error, resourceAssignment.name, + bluePrintTypeEnhancerService.enhancePropertyDefinition(bluePrintRuntimeService, resourceAssignment.name, resourceAssignment.property!!); // Get the Resource Definition from Repo @@ -91,13 +90,13 @@ open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionR ?: throw BluePrintException(format("failed to get assigned dictionarySource({}) from resourceDefinition({})", dictionarySource, dictionaryName)) // Enrich as NodeTemplate - bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintContext, error, dictionarySource, sourceNodeTemplate) + bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, dictionarySource, sourceNodeTemplate) } } // Enrich the ResourceSource NodeTypes uniqueSourceNodeTypeNames.map { nodeTypeName -> val nodeType = resourceDefinitionRepoService.getNodeType(nodeTypeName) - bluePrintTypeEnhancerService.enhanceNodeType(bluePrintContext, error, nodeTypeName, nodeType) + bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) } } diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java index 01b517620..abc3d56f3 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import java.nio.file.Paths; @RunWith(SpringRunner.class) @ContextConfiguration(classes = {TestApplication.class}) @@ -55,8 +56,11 @@ public class BluePrintEnhancerServiceImplTest { String basePath = "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration"; - BluePrintContext bluePrintContext = bluePrintEnhancerService.enhance(basePath); + String targetPath = Paths.get("target", "bp-enhance").toUri().getPath(); + + BluePrintContext bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath); Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext); + } } \ No newline at end of file -- cgit 1.2.3-korg From 3854151c6f07ae1bb4c68ce114aae247011f98c8 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 13 Dec 2018 15:10:35 -0500 Subject: Add blueprint runtime service to validator Change-Id: I0e4375e422b55002f1666ee9e61a1469482f77d2 Issue-ID: CCSDK-757 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ConfigModelCreateService.java | 19 ++-- .../service/ConfigModelValidatorService.java | 67 -------------- .../ResourceAssignmentValidationService.java | 29 ------ .../ResourceDefinitionValidationService.java | 29 ------ .../service/ResourceDictionaryService.java | 4 +- .../service/ServiceTemplateService.java | 1 + .../service/rs/ResourceDictionaryRest.java | 2 +- .../validator/ServiceTemplateValidator.java | 4 +- .../validator/BluePrintTypeValidatorServiceImpl.kt | 66 +++++++++++++ .../validator/BluePrintValidatorDefaultService.kt | 103 +++++++++++++++++++++ .../enhancer/BluePrintEnhancerServiceImplTest.java | 9 +- .../ResourceAssignmentEnhancerServiceTest.java | 59 ------------ .../validator/ServiceTemplateValidationTest.java | 72 -------------- 13 files changed, 191 insertions(+), 273 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/BluePrintTypeValidatorServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/BluePrintValidatorDefaultService.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java (limited to 'ms/controllerblueprints/modules/service/src/test') 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 1875a8022..fa8e32b69 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 @@ -17,6 +17,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; @@ -31,8 +33,6 @@ 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 com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.io.IOException; @@ -48,25 +48,21 @@ import java.util.Optional; * @author Brinda Santh * @version 1.0 */ - +@Deprecated @Service public class ConfigModelCreateService { private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelCreateService.class); private ConfigModelRepository configModelRepository; - private ConfigModelValidatorService configModelValidatorService; /** * This is a ConfigModelCreateService * - * @param configModelRepository ConfigModelRepository - * @param configModelValidatorService ConfigModelValidatorService + * @param configModelRepository ConfigModelRepository */ - public ConfigModelCreateService(ConfigModelRepository configModelRepository, - ConfigModelValidatorService configModelValidatorService) { + public ConfigModelCreateService(ConfigModelRepository configModelRepository) { this.configModelRepository = configModelRepository; - this.configModelValidatorService = configModelValidatorService; } /** @@ -127,7 +123,7 @@ public class ConfigModelCreateService { String artifactName = configModel.getArtifactName(); String artifactVersion = configModel.getArtifactVersion(); String author = configModel.getUpdatedBy(); - + if (StringUtils.isBlank(author)) { throw new BluePrintException("Artifact Author is missing in the Service Template"); @@ -326,6 +322,7 @@ public class ConfigModelCreateService { * @throws BluePrintException BluePrintException */ public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - return this.configModelValidatorService.validateServiceTemplate(serviceTemplate); + // FIXME("Plug right Validator") + return serviceTemplate; } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java deleted file mode 100644 index 3abdc04d2..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java +++ /dev/null @@ -1,67 +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.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.validator.ServiceTemplateValidator; -import org.springframework.stereotype.Service; - -/** - * ServiceTemplateValidatorService.java Purpose: Provide Service to Validate Service Model Template - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -@Service -public class ConfigModelValidatorService { - - /** - * This is a validateServiceTemplate - * - * @param serviceTemplateContent - * @return ServiceTemplate - * @throws BluePrintException - */ - public ServiceTemplate validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateContent), "Service Template Content is (" + serviceTemplateContent + ") not Defined."); - ServiceTemplate serviceTemplate = - JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); - return validateServiceTemplate(serviceTemplate); - } - - /** - * This is a enhanceServiceTemplate - * - * @param serviceTemplate - * @return ServiceTemplate - * @throws BluePrintException - */ - @SuppressWarnings("squid:S00112") - public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - Preconditions.checkNotNull(serviceTemplate, "Service Template is not defined."); - ServiceTemplateValidator validator = new ServiceTemplateValidator(); - validator.validateServiceTemplate(serviceTemplate); - return serviceTemplate; - } - - -} 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 deleted file mode 100644 index 1228e2eeb..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java +++ /dev/null @@ -1,29 +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 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/ResourceDefinitionValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java deleted file mode 100644 index 485896627..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java +++ /dev/null @@ -1,29 +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.interfaces.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 fd73db3b6..eacc90251 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 @@ -25,6 +25,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; 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; @@ -104,7 +105,7 @@ public class ResourceDictionaryService { * @param resourceDictionary resourceDictionary * @return DataDictionary */ - public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { + public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) throws BluePrintException { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); Preconditions.checkNotNull(resourceDictionary.getDefinition(), "Resource Dictionary definition information is missing"); @@ -157,7 +158,6 @@ public class ResourceDictionaryService { /** * This is a getResourceSourceMapping service - * */ public ResourceSourceMapping getResourceSourceMapping() { return ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); 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 57096c7fd..60a83f9bd 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,6 +20,7 @@ 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.service.ResourceAssignmentValidationService; 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; 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 932cdfac8..504420426 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 @@ -48,7 +48,7 @@ public class ResourceDictionaryRest { @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) { + ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { return resourceDictionaryService.saveResourceDictionary(dataDictionary); } 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 42adf1a3e..c5e9e86f4 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 @@ -29,7 +29,7 @@ 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.ResourceAssignmentValidationDefaultService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService; import java.util.HashMap; @@ -114,7 +114,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) { List resourceAssignment = getResourceAssignments(nodeTemplate); - ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationDefaultService(); + ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl(); resourceAssignmentValidationService.validate(resourceAssignment); } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/BluePrintTypeValidatorServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/BluePrintTypeValidatorServiceImpl.kt new file mode 100644 index 000000000..9d4797ff9 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/BluePrintTypeValidatorServiceImpl.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.service.validator + +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.* +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service + +@Service +class BluePrintTypeValidatorServiceImpl : BluePrintTypeValidatorService { + + @Autowired + private lateinit var context: ApplicationContext + + override fun getServiceTemplateValidators(): List { + return context.getBeansOfType(BluePrintServiceTemplateValidator::class.java).mapNotNull { it.value } + } + + override fun getDataTypeValidators(): List { + return context.getBeansOfType(BluePrintDataTypeValidator::class.java).mapNotNull { it.value } + } + + override fun getArtifactTypeValidators(): List { + return context.getBeansOfType(BluePrintArtifactTypeValidator::class.java).mapNotNull { it.value } + } + + override fun getNodeTypeValidators(): List { + return context.getBeansOfType(BluePrintNodeTypeValidator::class.java).mapNotNull { it.value } + } + + override fun getTopologyTemplateValidators(): List { + return context.getBeansOfType(BluePrintTopologyTemplateValidator::class.java).mapNotNull { it.value } + } + + override fun getNodeTemplateValidators(): List { + return context.getBeansOfType(BluePrintNodeTemplateValidator::class.java).mapNotNull { it.value } + } + + override fun getWorkflowValidators(): List { + return context.getBeansOfType(BluePrintWorkflowValidator::class.java).mapNotNull { it.value } + } + + override fun getPropertyDefinitionValidators(): List { + return context.getBeansOfType(BluePrintPropertyDefinitionValidator::class.java).mapNotNull { it.value } + } + + override fun getAttributeDefinitionValidators(): List { + return context.getBeansOfType(BluePrintAttributeDefinitionValidator::class.java).mapNotNull { it.value } + } +} + diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/BluePrintValidatorDefaultService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/BluePrintValidatorDefaultService.kt new file mode 100644 index 000000000..89f4d9e38 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/BluePrintValidatorDefaultService.kt @@ -0,0 +1,103 @@ +/* + * 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.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.BluePrintRepoService +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.validation.* +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationServiceImpl +import org.springframework.stereotype.Service +import java.util.* + +@Service +class BluePrintTypeValidatorDefaultService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintValidatorService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorServiceImpl::class.toString()) + + override fun validateBluePrints(basePath: String): Boolean { + + log.info("validating blueprint($basePath)") + 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 + } +} + +// Core Validator Services + +@Service +class DefaultBluePrintServiceTemplateValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintServiceTemplateValidatorImpl(bluePrintTypeValidatorService) + +@Service +class DefaultBluePrintDataTypeValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintDataTypeValidatorImpl(bluePrintTypeValidatorService) + +@Service +class DefaultBluePrintArtifactTypeValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintArtifactTypeValidatorImpl(bluePrintTypeValidatorService) + +@Service +class DefaultBluePrintNodeTypeValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintNodeTypeValidatorImpl(bluePrintTypeValidatorService) + +@Service +class DefaultBluePrintTopologyTemplateValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintTopologyTemplateValidatorImpl(bluePrintTypeValidatorService) + +@Service +class DefaulBluePrintNodeTemplateValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintNodeTemplateValidatorImpl(bluePrintTypeValidatorService) + +@Service +class DefaultBluePrintWorkflowValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintWorkflowValidatorImpl(bluePrintTypeValidatorService) + +@Service +class DefaulBluePrintPropertyDefinitionValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintPropertyDefinitionValidatorImpl(bluePrintTypeValidatorService) + +@Service +class DefaultBluePrintAttributeDefinitionValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintAttributeDefinitionValidatorImpl(bluePrintTypeValidatorService) + +// Resource Dictionary Validation Services + +@Service +class DefaultResourceAssignmentValidationService : ResourceAssignmentValidationServiceImpl() + +@Service +class DefalutResourceDefinitionValidationService(bluePrintRepoService: BluePrintRepoService) + : ResourceDefinitionValidationServiceImpl(bluePrintRepoService) \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java index abc3d56f3..7d9c2e1a2 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java @@ -22,6 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService; +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService; import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext; import org.onap.ccsdk.apps.controllerblueprints.service.load.ModelTypeLoadService; import org.onap.ccsdk.apps.controllerblueprints.service.load.ResourceDictionaryLoadService; @@ -29,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; + import java.nio.file.Paths; @RunWith(SpringRunner.class) @@ -45,6 +47,9 @@ public class BluePrintEnhancerServiceImplTest { @Autowired private BluePrintEnhancerService bluePrintEnhancerService; + @Autowired + private BluePrintValidatorService bluePrintValidatorService; + @Before public void init() { modelTypeLoadService.loadModelType("./../../../../components/model-catalog/definition-type/starter-type"); @@ -52,7 +57,7 @@ public class BluePrintEnhancerServiceImplTest { } @Test - public void testEnhancement() throws Exception { + public void testEnhancementAndValidation() throws Exception { String basePath = "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration"; @@ -61,6 +66,8 @@ public class BluePrintEnhancerServiceImplTest { BluePrintContext bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath); Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext); + // Validate the Generated BluePrints + bluePrintValidatorService.validateBluePrints(targetPath); } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java deleted file mode 100644 index b6e31318f..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java +++ /dev/null @@ -1,59 +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.enhancer; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.junit.Assert; -import org.junit.Before; -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.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils; - -import java.util.List; - -/** - * ResourceAssignmentEnhancerService. - * - * @author Brinda Santh - */ -public class ResourceAssignmentEnhancerServiceTest { - private static EELFLogger log = EELFManager.getInstance().getLogger(ResourceAssignmentEnhancerServiceTest.class); - - @Before - public void setUp() { - // Setup dummy Source Instance Mapping - ResourceDictionaryTestUtils.setUpResourceSourceMapping(); - } - - //@Test - public void testEnhanceBluePrint() throws BluePrintException { - - - List resourceAssignments = JacksonUtils.getListFromClassPathFile("enhance/enhance-resource-assignment.json", ResourceAssignment.class); - Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments); - -// ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("./../../../../components/model-catalog"); -// ResourceAssignmentEnhancerService resourceAssignmentEnhancerService = new ResourceAssignmentEnhancerServiceImpl(resourceDefinitionRepoService); -// ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments); -// Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate); -// log.trace("Enhanced Service Template : {}", JacksonUtils.getJson(serviceTemplate, true)); - - } -} - 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 deleted file mode 100644 index d5638ec27..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java +++ /dev/null @@ -1,72 +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.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -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.resource.dict.utils.ResourceDictionaryTestUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.List; - -public class ServiceTemplateValidationTest { - private static EELFLogger log = EELFManager.getInstance().getLogger(ServiceTemplateValidationTest.class); - - @Before - public void setUp(){ - // Setup dummy Source Instance Mapping - ResourceDictionaryTestUtils.setUpResourceSourceMapping(); - } - - @Test - public void testBluePrintDirs() { - List dirs = ConfigModelUtils.getBlueprintNames("./../../../../components/model-catalog/blueprint-model/starter-blueprint"); - Assert.assertNotNull("Failed to get blueprint directories", dirs); - //Assert.assertEquals("Failed to get actual directories", 1, dirs.size()); - } - - @Test - public void validateServiceTemplate() throws Exception { - validateServiceTemplate("load/blueprints/vrr-test/Definitions/vrr-test.json"); - } - - //@Test FIXME("Enable once Complete Enhancement Service Implemented") - 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(fileName), Charset.defaultCharset()); - ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); - serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); - Assert.assertNotNull("Failed to validate blueprints", serviceTemplateValidator); - } -} -- cgit 1.2.3-korg From 30dd26ed05f3916c313bbe0024bfefc0e42ffd19 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 14 Dec 2018 12:30:51 -0500 Subject: Add blueprint artifact definition enrichment. Change-Id: I3b03a1f76472ce6b44929457a42805d281950ff7 Issue-ID: CCSDK-839 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../BluePrintArtifactDefinitionEnhancerImpl.kt | 101 ++++ .../enhancer/BluePrintNodeTemplateEnhancerImpl.kt | 19 +- .../BluePrintServiceTemplateEnhancerImpl.kt | 2 +- .../enhancer/BluePrintTypeEnhancerServiceImpl.kt | 4 + .../enhancer/BluePrintWorkflowEnhancerImpl.kt | 51 +- .../test/resources/enhance/enhanced-template.json | 603 --------------------- 6 files changed, 141 insertions(+), 639 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt new file mode 100644 index 000000000..986ce9861 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt @@ -0,0 +1,101 @@ +/* + * 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.enhancer + +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.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionEnhancer +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.springframework.stereotype.Service + +@Service +open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) + : BluePrintArtifactDefinitionEnhancer { + + companion object { + const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" + } + + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintArtifactDefinitionEnhancerImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) { + log.info("enhancing ArtifactDefinition($name)") + + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val artifactTypeName = artifactDefinition.type + ?: throw BluePrintException("Artifact type is missing for ArtifactDefinition($name)") + + // Populate Artifact Type + populateArtifactType(artifactTypeName) + + when (artifactTypeName) { + ARTIFACT_TYPE_MAPPING_SOURCE -> { + enhanceMappingType(name, artifactDefinition) + } + } + } + + // Enhance Resource Mapping + open fun enhanceMappingType(name: String, artifactDefinition: ArtifactDefinition) { + + val artifactFilePath = "${bluePrintContext.rootPath}/${artifactDefinition.file}" + + val alreadyEnhancedKey = "enhanced-${artifactDefinition.file}" + val alreadyEnhanced = bluePrintRuntimeService.check(alreadyEnhancedKey) + + log.info("enhancing resource mapping file(${artifactDefinition.file}) already enhanced($alreadyEnhanced)") + + if (!alreadyEnhanced) { + val resourceAssignments: MutableList = JacksonUtils.getListFromFile(artifactFilePath, ResourceAssignment::class.java) + as? MutableList + ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($artifactFilePath)") + + // Call Resource Assignment Enhancer + resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) + + bluePrintRuntimeService.put(alreadyEnhancedKey, true.asJsonPrimitive()) + } + } + + open fun populateArtifactType(artifactTypeName: String): ArtifactType { + + val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName) + ?: bluePrintRepoService.getArtifactType(artifactTypeName) + ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName) from repo.") + bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) + return artifactType + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt index cfbfab71d..fb6c06afb 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt @@ -18,9 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType 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.format @@ -46,7 +44,7 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { - log.info("Enhancing NodeTemplate($name)") + log.info("***** Enhancing NodeTemplate($name)") this.bluePrintRuntimeService = bluePrintRuntimeService this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() @@ -75,20 +73,9 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B open fun enhanceNodeTemplateArtifactDefinition(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) + // Enhance Artifacct Definitions + bluePrintTypeEnhancerService.enhanceArtifactDefinition(bluePrintRuntimeService, artifactDefinitionName, artifactDefinition) } } - open fun populateArtifactType(artifactTypeName: String): ArtifactType { - val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName) - ?: bluePrintRepoService.getArtifactType(artifactTypeName) - ?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName)) - bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) - return artifactType - } - } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt index 6a4f6232c..2ad0583e1 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt @@ -33,7 +33,7 @@ import org.springframework.stereotype.Service open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintServiceTemplateEnhancer { - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString()) + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateEnhancerImpl::class.toString()) lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt index 3128b6c64..02a19c3fc 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt @@ -47,6 +47,10 @@ open class BluePrintTypeEnhancerServiceImpl : BluePrintTypeEnhancerService { return context.getBeansOfType(BluePrintNodeTypeEnhancer::class.java).map { it.value } } + override fun getArtifactDefinitionEnhancers(): List { + return context.getBeansOfType(BluePrintArtifactDefinitionEnhancer::class.java).map { it.value } + } + override fun getPolicyTypeEnhancers(): List { return context.getBeansOfType(BluePrintPolicyTypeEnhancer::class.java).map { it.value } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt index e3a8f2221..a620e9bf3 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt @@ -21,6 +21,7 @@ import com.att.eelf.configuration.EELFManager import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow @@ -41,19 +42,21 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) : BluePrintWorkflowEnhancer { - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateEnhancerImpl::class.toString()) + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintWorkflowEnhancerImpl::class.toString()) + + companion object { + const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" + const val PROPERTY_DEPENDENCY_NODE_TEMPLATES = "dependency-node-templates" + } lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - val PROPERTY_DEPENDENCY_NODE_TEMPLATES = "dependency-node-templates" - - private val workflowDataTypes: MutableMap = hashMapOf() override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) { - log.info("Enhancing Workflow($name)") - this.bluePrintRuntimeService = bluePrintRuntimeService + log.info("##### Enhancing Workflow($name)") + this.bluePrintRuntimeService = bluePrintRuntimeService this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() val dynamicPropertyName = "$name-properties" @@ -94,10 +97,11 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP // Check and Get Resource Assignment File val resourceAssignmentArtifacts = dependencyNodeTemplates?.mapNotNull { componentNodeTemplateName -> - log.info("Identified workflow($name) targets($componentNodeTemplateName") + log.info("identified workflow($name) targets($componentNodeTemplateName)") + val resourceAssignmentArtifacts = bluePrintContext.nodeTemplateByName(componentNodeTemplateName) .artifacts?.filter { - it.value.type == "artifact-mapping-resource" + it.value.type == ARTIFACT_TYPE_MAPPING_SOURCE }?.map { log.info("resource assignment artifacts(${it.key}) for NodeType(${componentNodeTemplateName})") it.value.file @@ -105,7 +109,7 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP resourceAssignmentArtifacts }?.flatten() - log.info("Workflow($name) resource assignment files($resourceAssignmentArtifacts") + log.info("workflow($name) resource assignment files($resourceAssignmentArtifacts") if (resourceAssignmentArtifacts != null && resourceAssignmentArtifacts.isNotEmpty()) { @@ -113,19 +117,20 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP addWorkFlowDynamicPropertyDefinitions(name, workflow) resourceAssignmentArtifacts.forEach { fileName -> - - val absoluteFilePath = "${bluePrintContext.rootPath}/$fileName" - - log.info("enriching workflow($name) artifacts file(${absoluteFilePath}") // Enhance Resource Assignment File - val resourceAssignmentProperties = enhanceResourceAssignmentFile(absoluteFilePath) + val resourceAssignmentProperties = enhanceResourceAssignmentFile(fileName!!) // Add Workflow Dynamic DataType addWorkFlowDynamicDataType(name, resourceAssignmentProperties) } } } - private fun enhanceResourceAssignmentFile(filePath: String): MutableMap { + // Enhancement for Dynamic Properties, Resource Assignment Properties, Resource Sources + private fun enhanceResourceAssignmentFile(fileName: String): MutableMap { + + val filePath = "${bluePrintContext.rootPath}/$fileName" + + log.info("enriching artifacts file(${filePath}") val resourceAssignmentProperties: MutableMap = hashMapOf() @@ -133,8 +138,16 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP as? MutableList ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") - // Call Resource Assignment Enhancer - resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) + val alreadyEnhancedKey = "enhanced-$fileName" + val alreadyEnhanced = bluePrintRuntimeService.check(alreadyEnhancedKey) + + log.info("enhancing workflow resource mapping file($fileName) already enhanced($alreadyEnhanced)") + + if (!alreadyEnhanced) { + // Call Resource Assignment Enhancer + resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) + bluePrintRuntimeService.put(alreadyEnhancedKey, true.asJsonPrimitive()) + } resourceAssignments.forEach { resourceAssignment -> resourceAssignmentProperties[resourceAssignment.name] = resourceAssignment.property!! @@ -159,7 +172,7 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP var recipeDataType: DataType? = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) if (recipeDataType == null) { - log.info("DataType not present for the recipe({})", dataTypeName) + log.info("dataType not present for the recipe({})", dataTypeName) recipeDataType = DataType() recipeDataType.version = "1.0.0" recipeDataType.description = "Dynamic DataType definition for workflow($workflowName)." @@ -172,7 +185,7 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, recipeDataType) } else { - log.info("Dynamic dataType($dataTypeName) already present for workflow($workflowName).") + log.info("dynamic dataType($dataTypeName) already present for workflow($workflowName).") } // Merge all the Recipe Properties mappingProperties.forEach { propertyName, propertyDefinition -> 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 5e41a507e..b13932b7f 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 @@ -11,611 +11,8 @@ "tosca_definitions_version" : "controller_blueprint_1_0_0", "artifact_types" : { }, "data_types" : { - "dt-v4-aggregate" : { - "description" : "This is dt-v4-aggregate Data Type", - "version" : "1.0.0", - "properties" : { - "ipv4-address" : { - "required" : true, - "type" : "string" - }, - "ipv4-plen" : { - "required" : false, - "type" : "integer" - } - }, - "derived_from" : "tosca.datatypes.Root" - }, - "dt-license-key" : { - "description" : "This is dt-plicense-key Data Type", - "version" : "1.0.0", - "properties" : { - "license-key" : { - "required" : true, - "type" : "string" - } - }, - "derived_from" : "tosca.datatypes.Root" - }, - "datatype-resource-assignment" : { - "description" : "This is Resource Assignment Data Type", - "version" : "1.0.0", - "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" - }, - "datatype-property" : { - "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", - "version" : "1.0.0", - "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" - }, - "dt-resource-assignment-request" : { - "description" : "This is Dynamic Data type definition generated from resource mapping for the config template name base-config-template.", - "version" : "1.0.0", - "properties" : { - "hostname" : { - "required" : true, - "type" : "string" - }, - "licenses" : { - "required" : true, - "type" : "list", - "entry_schema" : { - "type" : "dt-license-key" - } - }, - "rs-db-source" : { - "required" : true, - "type" : "string" - }, - "service" : { - "required" : true, - "type" : "string" - }, - "service-instance-id" : { - "required" : true, - "type" : "string" - }, - "mdsal-source" : { - "description" : "", - "required" : true, - "type" : "list", - "entry_schema" : { - "type" : "dt-v4-aggregate" - } - } - }, - "derived_from" : "tosca.datatypes.Dynamic" - } }, "node_types" : { - "dg-resource-assignment" : { - "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" - }, - "tosca.nodes.Component" : { - "description" : "This is default Component Node", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" - }, - "artifact-config-template" : { - "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" - }, - "tosca.nodes.Vnf" : { - "description" : "This is VNF Node Type", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" - }, - "tosca.nodes.Artifact" : { - "description" : "This is Deprecated Artifact Node Type.", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" - }, - "dg-activate-netconf" : { - "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" - }, - "source-input" : { - "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" - }, - "tosca.nodes.ResourceSource" : { - "description" : "TOSCA base type for Resource Sources", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" - }, - "component-resource-assignment" : { - "description" : "This is Resource Assignment Component API", - "version" : "1.0.0", - "capabilities" : { - "component-node" : { - "type" : "tosca.capabilities.Node" - } - }, - "interfaces" : { - "ResourceAssignmentComponent" : { - "operations" : { - "process" : { - "inputs" : { - "template-name" : { - "description" : "Service Template Name.", - "required" : true, - "type" : "string" - }, - "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" - }, - "tosca.nodes.component.Jython" : { - "description" : "This is Jython Component", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" - }, - "tosca.nodes.DG" : { - "description" : "This is Directed Graph Node Type", - "version" : "1.0.0", - "derived_from" : "tosca.nodes.Root" - }, - "source-db" : { - "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" - }, - "vnf-netconf-device" : { - "description" : "This is VNF Device with Netconf Capability", - "version" : "1.0.0", - "capabilities" : { - "netconf" : { - "type" : "tosca.capabilities.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" - }, - "source-rest" : { - "description" : "This is Rest Resource Source Node Type", - "version" : "1.0.0", - "properties" : { - "type" : { - "required" : false, - "type" : "string", - "constraints" : [ { - "valid_values" : [ "JSON" ] - } ], - "default" : "JSON" - }, - "url-path" : { - "required" : true, - "type" : "string" - }, - "path" : { - "required" : true, - "type" : "string" - }, - "expression-type" : { - "required" : false, - "type" : "string", - "constraints" : [ { - "valid_values" : [ "JSON_PATH", "JSON_POINTER" ] - } ], - "default" : "JSON_PATH" - }, - "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" - }, - "component-netconf-executor" : { - "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" : { - "NetconfExecutorComponent" : { - "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" - }, - "template-name" : { - "description" : "Service Template Name", - "required" : true, - "type" : "string" - }, - "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.Jython" - } }, "topology_template" : { "inputs" : { -- cgit 1.2.3-korg From ed2e6c9ab708184398718ed0c112806e32a23d05 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 14 Dec 2018 16:41:37 -0500 Subject: Add blueprint resource definition enrichment. Change-Id: I01234093028ffdc8bf1688e41baba20fae7da5ce Issue-ID: CCSDK-747 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintEnhancerService.java | 174 --------------------- .../enhancer/BluePrintEnhancerServiceImpl.kt | 31 ++-- .../enhancer/ResourceDefinitionEnhancerService.kt | 124 +++++++++++++++ .../enhancer/BluePrintEnhancerServiceImplTest.java | 4 +- .../modules/service/src/test/resources/logback.xml | 2 +- 5 files changed, 148 insertions(+), 187 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt (limited to 'ms/controllerblueprints/modules/service/src/test') 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 deleted file mode 100644 index 930c88d8d..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java +++ /dev/null @@ -1,174 +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; - -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.collections.MapUtils; -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.ConfigModelConstant; -import org.onap.ccsdk.apps.controllerblueprints.core.data.*; -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.enhancer.ResourceAssignmentEnhancerService; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * BluePrintEnhancerService - * - * @author Brinda Santh DATE : 8/8/2018 - */ - -@Deprecated -public class BluePrintEnhancerService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); - - private ResourceAssignmentEnhancerService resourceAssignmentEnhancerService; - - private Map recipeDataTypes = new HashMap<>(); - - - private void populateArtifactTemplateMappingDataType(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) - throws BluePrintException { - log.info("****** Processing Artifact Node Template : {}", nodeTemplateName); - - if (nodeTemplate.getProperties() != null) { - - if (!nodeTemplate.getProperties().containsKey(ConfigModelConstant.PROPERTY_RECIPE_NAMES)) { - throw new BluePrintException("Node Template (" + nodeTemplateName + ") doesn't have " - + ConfigModelConstant.PROPERTY_RECIPE_NAMES + " property."); - } - - // Modified for ONAP converted Object to JsonNode - JsonNode recipeNames = nodeTemplate.getProperties().get(ConfigModelConstant.PROPERTY_RECIPE_NAMES); - - log.info("Processing Recipe Names : {} ", recipeNames); - - if (recipeNames != null && recipeNames.isArray() && recipeNames.size() > 0) { - - Map mappingProperties = - getCapabilityMappingProperties(nodeTemplateName, nodeTemplate); - - for (JsonNode recipeNameNode : recipeNames) { - String recipeName = recipeNameNode.textValue(); - processRecipe(nodeTemplateName, mappingProperties, recipeName); - } - } - } - } - - private void processRecipe(@NotNull String nodeTemplateName, Map mappingProperties, String recipeName) { - if (StringUtils.isNotBlank(recipeName)) { - DataType recipeDataType = this.recipeDataTypes.get(recipeName); - if (recipeDataType == null) { - log.info("DataType not present for the recipe({})", recipeName); - recipeDataType = new DataType(); - recipeDataType.setVersion("1.0.0"); - recipeDataType.setDescription( - "This is Dynamic Data type definition generated from resource mapping for the config template name " - + nodeTemplateName + "."); - recipeDataType.setDerivedFrom(ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC); - Map dataTypeProperties = new HashMap<>(); - recipeDataType.setProperties(dataTypeProperties); - } else { - log.info("DataType Already present for the recipe({})", recipeName); - } - - // Merge all the Recipe Properties - mergeDataTypeProperties(recipeDataType, mappingProperties); - - // Overwrite Recipe DataType - this.recipeDataTypes.put(recipeName, recipeDataType); - - } - } - - private Map getCapabilityMappingProperties(String nodeTemplateName, - NodeTemplate nodeTemplate) throws BluePrintException { - - Map dataTypeProperties = null; - if (nodeTemplate != null && MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) { - CapabilityAssignment capability = - nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - - if (capability != null && capability.getProperties() != null) { - - String resourceAssignmentContent = JacksonUtils - .getJson(capability.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)); - - List resourceAssignments = - JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); - - Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent); - // Enhance Resource Assignment TODO("Plug Resource Assignment Enhancer Service") - //resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); - - dataTypeProperties = new HashMap<>(); - - for (ResourceAssignment resourceAssignment : resourceAssignments) { - if (resourceAssignment != null - // && Boolean.valueOf(resourceAssignment.getInputParameter()) - && resourceAssignment.getProperty() != null - && StringUtils.isNotBlank(resourceAssignment.getName())) { - - dataTypeProperties.put(resourceAssignment.getName(), resourceAssignment.getProperty()); - - } - } - - } - } - return dataTypeProperties; - } - - private void mergeDataTypeProperties(DataType dataType, Map mergeProperties) { - if (dataType != null && dataType.getProperties() != null && mergeProperties != null) { - // Add the Other Template Properties - mergeProperties.forEach((mappingKey, propertyDefinition) -> dataType.getProperties().put(mappingKey, propertyDefinition)); - } - } - - private void populateRecipeInputs(ServiceTemplate serviceTemplate) { - if (serviceTemplate.getTopologyTemplate() != null - && MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs()) - && MapUtils.isNotEmpty(this.recipeDataTypes) - && MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) { - this.recipeDataTypes.forEach((recipeName, recipeDataType) -> { - String dataTypePrefix = recipeName.replace("-action", "") + "-request"; - String dataTypeName = "dt-" + dataTypePrefix; - - serviceTemplate.getDataTypes().put(dataTypeName, recipeDataType); - - PropertyDefinition customInputProperty = new PropertyDefinition(); - customInputProperty.setDescription("This is Dynamic Data type for the receipe " + recipeName + "."); - customInputProperty.setRequired(Boolean.FALSE); - customInputProperty.setType(dataTypeName); - serviceTemplate.getTopologyTemplate().getInputs().put(dataTypePrefix, customInputProperty); - - }); - } - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt index 0b42a26ee..6c7b6e08b 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt @@ -24,6 +24,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhance import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.springframework.stereotype.Service @@ -31,37 +32,42 @@ import java.util.* @Service open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintEnhancerService { + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService) : BluePrintEnhancerService { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString()) override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext { + // Copy the Blueprint Content to Target Location BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath) // Enhance the Blueprint - val enhancedBluePrintContext = enhance(enrichedBasePath) - - // Delete the Old Type files - BluePrintFileUtils.deleteBluePrintTypes(enrichedBasePath) - - // Write the Type File Definitions - BluePrintFileUtils.writeBluePrintTypes(enhancedBluePrintContext) - return enhancedBluePrintContext + return enhance(enrichedBasePath) } @Throws(BluePrintException::class) override fun enhance(basePath: String): BluePrintContext { + log.info("Enhancing blueprint($basePath)") - val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(UUID.randomUUID().toString(), basePath) + val blueprintRuntimeService = BluePrintMetadataUtils + .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath) + try { bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template", blueprintRuntimeService.bluePrintContext().serviceTemplate) + // Write the Type File Definitions + BluePrintFileUtils.writeBluePrintTypes(blueprintRuntimeService.bluePrintContext()) + + // Enhance Resource Dictionary + enhanceResourceDefinition(blueprintRuntimeService) + if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) { throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString()) } + } catch (e: Exception) { log.error("failed in blueprint enhancement", e) } @@ -69,5 +75,10 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePr return blueprintRuntimeService.bluePrintContext() } + private fun enhanceResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>) { + + resourceDefinitionEnhancerService.enhance(blueprintRuntimeService) + } + } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt new file mode 100644 index 000000000..ab5ca74cb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt @@ -0,0 +1,124 @@ +/* + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +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.utils.ResourceDictionaryUtils +import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDefinitionRepoService +import org.springframework.stereotype.Service + +interface ResourceDefinitionEnhancerService { + + @Throws(BluePrintException::class) + fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>) +} + +@Service +class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) : + ResourceDefinitionEnhancerService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionEnhancerService::class.toString()) + + companion object { + const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" + const val PROPERTY_DEPENDENCY_NODE_TEMPLATES = "dependency-node-templates" + } + + // Enhance the Resource Definition + // 1. Get the Resource Mapping files from all NodeTemplates. + // 2. Get all the Unique Resource assignments from all mapping files + // 3. Collect the Resource Definition for Resource Assignment names from database. + // 4. Create the Resource Definition under blueprint base path. + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>) { + + val blueprintContext = bluePrintRuntimeService.bluePrintContext() + + val mappingFiles = getAllResourceMappingFiles(blueprintContext) + log.info("resources assignment files ($mappingFiles)") + if (mappingFiles != null) { + getResourceDefinition(blueprintContext, mappingFiles) + } + } + + // Get all the Mapping files from all node templates. + private fun getAllResourceMappingFiles(blueprintContext: BluePrintContext): List? { + + return blueprintContext.nodeTemplates?.mapNotNull { nodeTemplateMap -> + + // Return only Mapping Artifact File Names + nodeTemplateMap.value.artifacts?.filter { artifactDefinitionMap -> + artifactDefinitionMap.value.type == ARTIFACT_TYPE_MAPPING_SOURCE + }?.mapNotNull { artifactDefinitionMap -> + artifactDefinitionMap.value.file + } + + }?.single { it.isNotEmpty() }?.distinct() + } + + // Convert file content to ResourceAssignments asynchronously + private fun getResourceDefinition(blueprintContext: BluePrintContext, files: List) { + runBlocking { + val blueprintBasePath = blueprintContext.rootPath + val deferredResourceAssignments = mutableListOf>>() + for (file in files) { + log.info("processing file ($file)") + deferredResourceAssignments += async { + ResourceDictionaryUtils.getResourceAssignmentFromFile("$blueprintBasePath/$file") + } + } + + val resourceAssignments = mutableListOf() + for (deferredResourceAssignment in deferredResourceAssignments) { + resourceAssignments.addAll(deferredResourceAssignment.await()) + } + + val distinctResourceAssignments = resourceAssignments.distinctBy { it.name } + generateResourceDictionaryFile(blueprintBasePath, distinctResourceAssignments) + //log.info("distinct Resource assignment ($distinctResourceAssignments)") + } + } + + // Read the Resource Definitions from the Database and write to type file. + private fun generateResourceDictionaryFile(blueprintBasePath: String, resourceAssignments: List) { + val resourcekeys = resourceAssignments.mapNotNull { it.dictionaryName }.distinct() + log.info("distinct resource keys ($resourcekeys)") + + //TODO("Optimise DB single Query to multiple Query") + // Collect the Resource Definition from database and convert to map to save in file + val resourceDefinitionMap = resourcekeys.map { resourceKey -> + getResourceDefinition(resourceKey) + }.map { it.name to it }.toMap() + + // Recreate the Resource Definition File + ResourceDictionaryUtils.writeResourceDefinitionTypes(blueprintBasePath, resourceDefinitionMap) + log.info("resource definition file created successfully") + } + + // Get the Resource Definition from Database + private fun getResourceDefinition(name: String): ResourceDefinition { + return resourceDefinitionRepoService.getResourceDefinition(name) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java index 7d9c2e1a2..06f2f9088 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.java @@ -67,7 +67,7 @@ public class BluePrintEnhancerServiceImplTest { Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext); // Validate the Generated BluePrints - - bluePrintValidatorService.validateBluePrints(targetPath); + Boolean valid = bluePrintValidatorService.validateBluePrints(targetPath); + Assert.assertTrue("blueprint validation failed ", valid); } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml index 7b7ef7565..fc1f6698e 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml +++ b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml @@ -17,7 +17,7 @@ - + - + 4.0.0 org.onap.ccsdk.apps.controllerblueprints @@ -36,6 +37,40 @@ service + + + + io.mockk + mockk + test + + + org.powermock + powermock-api-mockito2 + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.jetbrains.kotlin + kotlin-test-junit + test + + + org.jetbrains.kotlinx + kotlinx-coroutines-test + test + + + io.projectreactor + reactor-test + test + + + diff --git a/ms/controllerblueprints/modules/service/pom.xml b/ms/controllerblueprints/modules/service/pom.xml index 7ca7e0db0..cb2cf6ab2 100644 --- a/ms/controllerblueprints/modules/service/pom.xml +++ b/ms/controllerblueprints/modules/service/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.controllerblueprints @@ -30,6 +31,10 @@ + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + org.onap.ccsdk.apps.controllerblueprints db-resources @@ -63,25 +68,5 @@ org.mariadb.jdbc mariadb-java-client - - org.powermock - powermock-api-mockito2 - test - - - org.springframework.boot - spring-boot-starter-test - test - - - org.jetbrains.kotlin - kotlin-test-junit - test - - - io.projectreactor - reactor-test - test - diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt index 60c07ad2c..d6ce286fc 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.controller +import kotlinx.coroutines.runBlocking import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch import org.onap.ccsdk.apps.controllerblueprints.service.handler.BluePrintModelHandler @@ -86,6 +87,14 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint return this.bluePrintModelHandler.downloadBlueprintModelFile(id) } + @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType + .MULTIPART_FORM_DATA_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity = runBlocking { + bluePrintModelHandler.enrichBlueprint(file) + } + @PutMapping("/publish/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt index 907566c32..4239abbab 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt @@ -1,6 +1,7 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. * Modifications Copyright © 2019 Bell Canada. + * 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. @@ -22,6 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch @@ -38,7 +40,9 @@ import org.springframework.http.codec.multipart.FilePart import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import reactor.core.publisher.Mono +import java.io.File import java.io.IOException +import java.util.* /** * BlueprintModelHandler Purpose: Handler service to handle the request from BlurPrintModelRest @@ -48,10 +52,12 @@ import java.io.IOException */ @Service -open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintCatalogService, private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, +open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintCatalogService, + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, private val blueprintModelSearchRepository: ControllerBlueprintModelSearchRepository, private val blueprintModelRepository: ControllerBlueprintModelRepository, - private val blueprintModelContentRepository: ControllerBlueprintModelContentRepository) { + private val blueprintModelContentRepository: ControllerBlueprintModelContentRepository, + private val bluePrintEnhancerService: BluePrintEnhancerService) { /** * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database @@ -275,6 +281,40 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC } } + /** + * This is a CBA enrichBlueprint method + * Save the Zip File in archive location and extract the cba content. + * Populate the Enhancement Location + * Enhance the CBA content + * Compress the Enhanced Content + * Return back the the compressed content back to the caller. + * + * @param filePart filePart + * @return ResponseEntity + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open suspend fun enrichBlueprint(filePart: FilePart): ResponseEntity { + val enhanceId = UUID.randomUUID().toString() + val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(enhanceId) + val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(enhanceId) + + try { + BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir) + + // Enhance the Blue Prints + bluePrintEnhancerService.enhance(blueprintEnrichmentDir) + + return BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentDir, blueprintArchive) + + } catch (e: IOException) { + throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, + String.format("I/O Error while uploading the CBA file: %s", e.message), e) + } finally { + BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir) + } + } + companion object { private const val BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo" diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt index 5e715f784..02140ebf7 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt @@ -1,6 +1,7 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. * Modifications Copyright © 2019 Bell Canada. + * 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. @@ -17,20 +18,29 @@ package org.onap.ccsdk.apps.controllerblueprints.service.utils +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.reactive.awaitSingle +import kotlinx.coroutines.withContext +import org.apache.commons.io.FileUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -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.ErrorCode -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.apps.controllerblueprints.core.data.RelationshipType +import org.onap.ccsdk.apps.controllerblueprints.core.data.* +import org.onap.ccsdk.apps.controllerblueprints.core.deCompress import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils +import org.springframework.core.io.ByteArrayResource +import org.springframework.core.io.Resource +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity import org.springframework.http.codec.multipart.FilePart import org.springframework.util.StringUtils import reactor.core.publisher.Mono import java.io.File import java.io.IOException import java.nio.file.Path +import java.nio.file.Paths import java.util.* @@ -47,7 +57,7 @@ class BluePrintEnhancerUtils { } fun populateRelationshipType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - relationshipName: String): RelationshipType { + relationshipName: String): RelationshipType { val relationshipType = bluePrintContext.serviceTemplate.relationshipTypes?.get(relationshipName) ?: bluePrintRepoService.getRelationshipType(relationshipName) @@ -77,6 +87,47 @@ class BluePrintEnhancerUtils { return artifactType } + suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File { + // Delete the Directory + targetFile.deleteRecursively() + return filePart.transferTo(targetFile) + .thenReturn(targetFile) + .awaitSingle() + } + + suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { + //Recreate the Base Directories + Paths.get(archiveDir).toFile().reCreateDirs() + Paths.get(enhanceDir).toFile().reCreateDirs() + + val filePartFile = Paths.get(archiveDir, "cba.zip").toFile() + // Copy the File Part to ZIP + copyFromFilePart(filePart, filePartFile) + val deCompressFileName = Paths.get(enhanceDir).toUri().path + return filePartFile.deCompress(deCompressFileName) + } + + suspend fun compressToFilePart(enhanceDir: String, archiveDir: String): ResponseEntity { + val compressedFile = Paths.get(archiveDir, "enhanced-cba.zip").toFile() + BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile, true) + return prepareResourceEntity(compressedFile.name, compressedFile.readBytes()) + } + + suspend fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity { + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") + .body(ByteArrayResource(file)) + } + + suspend fun cleanEnhancer(archiveLocation: String, enhancementLocation: String) = withContext(Dispatchers.Default) { + val enrichDir = File(enhancementLocation) + FileUtils.forceDeleteOnExit(enrichDir) + + val archiveDir = File(archiveLocation) + FileUtils.forceDeleteOnExit(archiveDir) + } + /** * This is a saveCBAFile method * take a [FilePart], transfer it to disk using a Flux of FilePart and return a [Mono] representing the CBA file name diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt new file mode 100644 index 000000000..60420aa64 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt @@ -0,0 +1,53 @@ +/* + * 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.service.controller.mock + +import org.apache.commons.io.FilenameUtils +import org.slf4j.LoggerFactory +import org.springframework.core.io.buffer.DataBuffer +import org.springframework.http.HttpHeaders +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.FileCopyUtils +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import java.io.File +import java.nio.file.Path + +class MockFilePart(private val fileName: String) : FilePart { + val log = LoggerFactory.getLogger(MockFilePart::class.java)!! + override fun content(): Flux { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun headers(): HttpHeaders { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun filename(): String { + return FilenameUtils.getName(fileName) + } + + override fun name(): String { + return FilenameUtils.getBaseName(fileName) + } + + override fun transferTo(path: Path): Mono { + log.info("Copying file($fileName to ${path}") + FileCopyUtils.copy(File(fileName), path.toFile()) + return Mono.empty() + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt new file mode 100644 index 000000000..2e7ca2cdc --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt @@ -0,0 +1,71 @@ +/* + * 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.service.utils + +import kotlinx.coroutines.runBlocking +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.compress +import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir +import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs +import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart +import java.nio.file.Paths +import java.util.* +import kotlin.test.assertTrue + +class BluePrintEnhancerUtilsTest { + + private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + private val blueprintArchivePath: String = "./target/blueprints/archive" + private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" + private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").toFile().normalize().absolutePath + + @Before + @Throws(Exception::class) + fun setUp() { + val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs() + assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}") + val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs() + assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}") + val blueprintFile = Paths.get(blueprintDir).toFile().normalize() + val testZipFile = blueprintFile.compress(zipBlueprintFileName) + assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}") + } + + @After + @Throws(Exception::class) + fun tearDown() { + deleteDir(blueprintArchivePath) + deleteDir(blueprintEnrichmentPath) + } + + @Test + fun testDecompressFilePart() { + val filePart = MockFilePart(zipBlueprintFileName) + + runBlocking { + val enhanceId = UUID.randomUUID().toString() + val blueprintArchiveLocation = "$blueprintArchivePath/$enhanceId" + val blueprintEnrichmentLocation = "$blueprintEnrichmentPath/$enhanceId" + BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation) + BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation) + } + } +} + -- cgit 1.2.3-korg From 0e86613ab9cbe5c6b87746bb7bff09fc3a324d0b Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Wed, 20 Mar 2019 18:27:53 -0400 Subject: Improve publish api Change-Id: I245fc765bf4e7916c36126d7a9597e9db80a1713 Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh --- .../core/BluePrintConstants.kt | 6 +- .../core/FileExtensionFunctions.kt | 15 ++- .../core/interfaces/BluePrintEnhancer.kt | 5 +- .../core/service/BluePrintImportService.kt | 7 +- .../core/service/BluePrintParserService.kt | 62 ---------- .../core/service/PropertyAssignmentService.kt | 2 +- .../core/utils/BluePrintMetadataUtils.kt | 19 +-- .../core/utils/JacksonReactorUtils.kt | 129 +++++++++------------ .../core/utils/JacksonUtils.kt | 23 ++-- .../core/utils/ResourceResolverUtils.kt | 36 +++--- .../core/utils/ServiceTemplateUtils.kt | 28 +++-- .../core/utils/JacksonReactorUtilsTest.kt | 43 +++++++ .../db/resources/BlueprintCatalogServiceImpl.kt | 4 + .../service/controller/BlueprintModelController.kt | 6 +- .../enhancer/BluePrintEnhancerServiceImpl.kt | 5 +- .../service/handler/BluePrintModelHandler.kt | 57 +++++---- .../load/ControllerBlueprintCatalogServiceImpl.kt | 4 +- .../service/utils/BluePrintEnhancerUtils.kt | 31 +++-- .../enhancer/BluePrintEnhancerServiceImplTest.kt | 17 +-- .../service/utils/BluePrintEnhancerUtilsTest.kt | 15 +-- 20 files changed, 244 insertions(+), 270 deletions(-) delete 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/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt (limited to 'ms/controllerblueprints/modules/service/src/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 index e3545dff3..4b5789121 100644 --- 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 @@ -33,6 +33,9 @@ object BluePrintConstants { const val STATUS_PROCESSING: String = "processing" const val STATUS_FAILURE: String = "failure" + const val FLAG_Y: String = "Y" + const val FLAG_N: String = "N" + const val TYPE_DEFAULT: String = "default" const val DATA_TYPE_STRING: String = "string" @@ -98,8 +101,6 @@ object BluePrintConstants { 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" @@ -141,6 +142,7 @@ object BluePrintConstants { 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_VALID: String = "blueprint-valid" 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" diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt index a433a31b1..11553ba6b 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt @@ -20,6 +20,7 @@ import org.apache.commons.io.FileUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils import java.io.File import java.io.InputStream +import java.nio.file.Path import java.nio.file.Paths fun InputStream.toFile(path: String): File { @@ -65,10 +66,18 @@ fun File.deCompress(targetFile: File): File { } fun deleteDir(path: String) { - Paths.get(path).toFile().deleteRecursively() + normalizedFile(path).deleteRecursively() } +fun normalizedFile(path: String, vararg more: String?): File { + return Paths.get(path, *more).toFile().normalize() +} + +fun normalizedPath(path: String, vararg more: String?): Path { + return Paths.get(path, *more).normalize().toAbsolutePath() +} -fun normalizedFile(path: String): File { - return Paths.get(path).toFile().normalize() +fun normalizedPathName(path: String, vararg more: String?): String { + return normalizedPath(path, *more).toUri().path } + 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 index f01f12620..0aa01e8f6 100644 --- 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 @@ -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. @@ -47,10 +48,10 @@ interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer = hashMapOf() - fun getImportResolvedServiceTemplate(): ServiceTemplate { + suspend fun getImportResolvedServiceTemplate(): ServiceTemplate { // Populate Imported Service Templates traverseSchema(PARENT_SERVICE_TEMPLATE, parentServiceTemplate) @@ -48,7 +49,7 @@ class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate, return parentServiceTemplate } - private fun traverseSchema(key: String, serviceTemplate: ServiceTemplate) { + private suspend fun traverseSchema(key: String, serviceTemplate: ServiceTemplate) { if (key != PARENT_SERVICE_TEMPLATE) { importServiceTemplateMap[key] = serviceTemplate } @@ -63,7 +64,7 @@ class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate, } } - private fun resolveImportDefinition(importDefinition: ImportDefinition): ServiceTemplate { + private suspend fun resolveImportDefinition(importDefinition: ImportDefinition): ServiceTemplate { var serviceTemplate: ServiceTemplate? = null val file: String = importDefinition.file val decodedSystemId: String = URLDecoder.decode(file, Charset.defaultCharset().toString()) 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 deleted file mode 100644 index b1d67ece9..000000000 --- a/ms/controllerblueprints/modules/blueprint-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/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 index 7905b8fb4..62a7b09ea 100644 --- 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 @@ -219,7 +219,7 @@ If Property Assignment is Expression. if (artifactDefinition.repository != null) { TODO() } else if (artifactDefinition.file != null) { - return ResourceResolverUtils.getFileContent(artifactDefinition.file!!, bluePrintBasePath) + 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/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt index ce11d97eb..8ba2e2755 100644 --- 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 @@ -21,16 +21,17 @@ 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 kotlinx.coroutines.runBlocking 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.normalizedFile 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 -import java.nio.file.Paths import java.util.* class BluePrintMetadataUtils { @@ -73,7 +74,7 @@ class BluePrintMetadataUtils { fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData { val toscaMetaData = ToscaMetaData() - val lines = Paths.get(metaFilePath).toFile().readLines(Charset.defaultCharset()) + val lines = normalizedFile(metaFilePath).readLines(Charset.defaultCharset()) lines.forEach { line -> if (line.contains(":")) { val keyValue = line.split(":") @@ -104,7 +105,8 @@ class BluePrintMetadataUtils { return bluePrintRuntimeService } - fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService> { + suspend fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String) + : BluePrintRuntimeService> { val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath) @@ -115,7 +117,8 @@ class BluePrintMetadataUtils { return bluePrintRuntimeService } - fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap): BluePrintRuntimeService> { + fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap): + BluePrintRuntimeService> { val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath) val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) executionContext.forEach { @@ -126,16 +129,16 @@ class BluePrintMetadataUtils { return bluePrintRuntimeService } - fun getBluePrintContext(blueprintBasePath: String): BluePrintContext { + fun getBluePrintContext(blueprintBasePath: String): BluePrintContext = runBlocking { val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath) log.info("Reading blueprint path($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})") - return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath) + readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath) } - private fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext { + private suspend fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext { val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath) // Clean Type files BluePrintFileUtils.deleteBluePrintTypes(blueprintBasePath) @@ -151,7 +154,7 @@ class BluePrintMetadataUtils { return blueprintContext } - private fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext { + private suspend 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 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 index 0522e1f5e..45d8fd4e8 100644 --- 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 @@ -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. @@ -19,91 +20,73 @@ 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 +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import org.apache.commons.io.IOUtils +import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile +import java.io.File +import java.nio.charset.Charset -@Deprecated("Reactor will be replaced by coroutines by default") -object JacksonReactorUtils { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) +class JacksonReactorUtils { + companion object { - @JvmStatic - fun getContent(fileName: String): Mono { - return JacksonUtils.getContent(fileName).toMono() - } + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - @JvmStatic - fun getClassPathFileContent(fileName: String): Mono { - return JacksonUtils.getClassPathFileContent(fileName).toMono() - } + suspend fun getContent(fileName: String): String { + //log.info("Reading File($fileName)") + return getContent(normalizedFile(fileName)) + } - @JvmStatic - fun readValue(content: String, valueType: Class): Mono { - return Mono.just(jacksonObjectMapper().readValue(content, valueType)) - } + suspend fun getContent(file: File): String = withContext(Dispatchers.IO) { + // log.info("Reading File(${file.absolutePath})") + file.readText(Charsets.UTF_8) + } - @JvmStatic - fun jsonNode(content: String): Mono { - return Mono.just(jacksonObjectMapper().readTree(content)) - } + suspend fun getClassPathFileContent(fileName: String): String = withContext(Dispatchers.IO) { + //log.trace("Reading Classpath File($fileName)") + IOUtils.toString(JacksonUtils::class.java.classLoader + .getResourceAsStream(fileName), Charset.defaultCharset()) + } - @JvmStatic - fun getJson(any: kotlin.Any, pretty: Boolean = false): Mono { - return Mono.just(JacksonUtils.getJson(any, pretty)) - } + suspend fun readValueFromFile(fileName: String, valueType: Class): T? { + val content: String = getContent(fileName) + return JacksonUtils.readValue(content, valueType) + } - @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() - } + suspend fun readValueFromClassPathFile(fileName: String, valueType: Class): T? { + val content: String = getClassPathFileContent(fileName) + return JacksonUtils.readValue(content, valueType) + } - @JvmStatic - fun readValueFromFile(fileName: String, valueType: Class): Mono { - return getContent(fileName) - .flatMap { content -> - readValue(content, valueType) - } - } + suspend fun jsonNodeFromClassPathFile(fileName: String): JsonNode { + val content: String = getClassPathFileContent(fileName) + return JacksonUtils.jsonNode(content) + } - @JvmStatic - fun readValueFromClassPathFile(fileName: String, valueType: Class): Mono { - return getClassPathFileContent(fileName) - .flatMap { content -> - readValue(content, valueType) - } - } + suspend fun jsonNodeFromFile(fileName: String): JsonNode { + val content: String = getContent(fileName) + return JacksonUtils.jsonNode(content) + } - @JvmStatic - fun jsonNodeFromFile(fileName: String): Mono { - return getContent(fileName) - .flatMap { content -> - jsonNode(content) - } - } + suspend fun getListFromFile(fileName: String, valueType: Class): List { + val content: String = getContent(fileName) + return JacksonUtils.getListFromJson(content, valueType) + } - @JvmStatic - fun jsonNodeFromClassPathFile(fileName: String): Mono { - return getClassPathFileContent(fileName) - .flatMap { content -> - jsonNode(content) - } - } + suspend fun getListFromClassPathFile(fileName: String, valueType: Class): List { + val content: String = getClassPathFileContent(fileName) + return JacksonUtils.getListFromJson(content, valueType) + } - @JvmStatic - fun getListFromFile(fileName: String, valueType: Class): Mono> { - return getContent(fileName) - .flatMap { content -> - getListFromJson(content, valueType) - } - } + suspend fun getMapFromFile(file: File, valueType: Class): MutableMap { + val content: String = getContent(file) + return JacksonUtils.getMapFromJson(content, valueType) + } + + suspend fun getMapFromClassPathFile(fileName: String, valueType: Class): MutableMap { + val content: String = getClassPathFileContent(fileName) + return JacksonUtils.getMapFromJson(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 index e0341b8a4..7c515984c 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 @@ -21,24 +21,14 @@ import com.att.eelf.configuration.EELFManager import com.fasterxml.jackson.annotation.JsonInclude 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.BooleanNode -import com.fasterxml.jackson.databind.node.DoubleNode -import com.fasterxml.jackson.databind.node.FloatNode -import com.fasterxml.jackson.databind.node.IntNode -import com.fasterxml.jackson.databind.node.NullNode -import com.fasterxml.jackson.databind.node.ObjectNode -import com.fasterxml.jackson.databind.node.TextNode +import com.fasterxml.jackson.databind.node.* 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 org.onap.ccsdk.apps.controllerblueprints.core.* import java.io.File import java.nio.charset.Charset @@ -51,7 +41,7 @@ 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) + jacksonObjectMapper().readValue(content, T::class.java) fun readValue(content: String, valueType: Class): T? { return jacksonObjectMapper().readValue(content, valueType) @@ -73,7 +63,8 @@ class JacksonUtils { } } - fun getContent(fileName: String): String = getContent(File(fileName)) + + fun getContent(fileName: String): String = getContent(normalizedFile(fileName)) fun getContent(file: File): String = runBlocking { async { @@ -89,7 +80,7 @@ class JacksonUtils { return runBlocking { withContext(Dispatchers.Default) { IOUtils.toString(JacksonUtils::class.java.classLoader - .getResourceAsStream(fileName), Charset.defaultCharset()) + .getResourceAsStream(fileName), Charset.defaultCharset()) } } } @@ -189,7 +180,7 @@ class JacksonUtils { fun getInstanceFromMap(properties: MutableMap, classType: Class): T { return readValue(getJson(properties), classType) - ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)") + ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)") } fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean { 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 index 965e965c6..762e47fbf 100644 --- 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 @@ -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. @@ -16,14 +17,13 @@ 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 org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty import java.io.File import java.net.URL -import java.nio.charset.Charset + /** * * @@ -32,30 +32,30 @@ import java.nio.charset.Charset object ResourceResolverUtils { private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - @JvmStatic - fun getFileContent(filename : String, basePath : String?): String { + 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() + 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)){ + if (givenUrl.startsWith(systemUrl)) { } - }else{ - if(!filename.startsWith("/")){ + } else { + if (!filename.startsWith("/")) { if (checkNotEmpty(basePath)) { resolvedFileName = basePath.plus(File.separator).plus(filename) - }else{ + } else { resolvedFileName = javaClass.classLoader.getResource(".").path.plus(filename) } } } - return FileUtils.readFileToString(File(resolvedFileName), Charset.defaultCharset()) - }catch (e : Exception){ + //FIXME("Convert into reactive") + return JacksonUtils.getContent(resolvedFileName) + } catch (e: Exception) { throw BluePrintException(e, "failed to file (%s), basePath (%s) ", filename, basePath) } } 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 index 933161323..28916772e 100644 --- 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 @@ -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. @@ -16,11 +17,8 @@ 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 /** * @@ -29,14 +27,11 @@ import java.nio.charset.Charset */ object ServiceTemplateUtils { - @JvmStatic - fun getServiceTemplate(fileName: String): ServiceTemplate { - val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + suspend fun getServiceTemplate(fileName: String): ServiceTemplate { + val content: String = JacksonReactorUtils.getContent(fileName) return getServiceTemplateFromContent(content) } - - @JvmStatic fun getServiceTemplateFromContent(content: String): ServiceTemplate { return JacksonUtils.readValue(content) } @@ -80,31 +75,34 @@ object ServiceTemplateUtils { parentServiceTemplate.topologyTemplate = parentServiceTemplate.topologyTemplate ?: TopologyTemplate() toMerge.topologyTemplate?.inputs?.let { - parentServiceTemplate.topologyTemplate?.inputs = parentServiceTemplate.topologyTemplate?.inputs ?: hashMapOf() + 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 = 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 = 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 = 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 = 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/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt new file mode 100644 index 000000000..9cf8d62af --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt @@ -0,0 +1,43 @@ +/* + * 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.core.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import kotlinx.coroutines.runBlocking +import org.junit.Test + +class JacksonReactorUtilsTest { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + @Test + fun testJsonNodeFromClassPathFile() { + runBlocking { + val filePath = "data/default-context.json" + JacksonReactorUtils.jsonNodeFromClassPathFile(filePath) + } + } + + @Test + fun testJsonNodeFromFile() { + runBlocking { + val filePath = "src/test/resources/data/default-context.json" + JacksonReactorUtils.jsonNodeFromFile(filePath) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt index cfde86aac..e43231527 100644 --- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt @@ -1,6 +1,7 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. * Modifications Copyright © 2019 Bell Canada. + * 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. @@ -55,13 +56,16 @@ abstract class BlueprintCatalogServiceImpl(private val blueprintValidator: BlueP toDeleteDirectory = extractedDirectory } + var valid = BluePrintConstants.FLAG_N if (validate) { blueprintValidator.validateBluePrints(extractedDirectory.path) + valid = BluePrintConstants.FLAG_Y } val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId, extractedDirectory.path) val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId + metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid save(metadata, archivedDirectory) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt index d6ce286fc..4974bcd12 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt @@ -95,11 +95,11 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint bluePrintModelHandler.enrichBlueprint(file) } - @PutMapping("/publish/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun publishBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { - return this.bluePrintModelHandler.publishBlueprintModel(id) + fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = runBlocking { + bluePrintModelHandler.publishBlueprint(file) } @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE]) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt index fb49dc465..da755d166 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt @@ -35,7 +35,7 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString()) - override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext { + override suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext { // Copy the Blueprint Content to Target Location BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath) @@ -45,7 +45,7 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService } @Throws(BluePrintException::class) - override fun enhance(basePath: String): BluePrintContext { + override suspend fun enhance(basePath: String): BluePrintContext { log.info("Enhancing blueprint($basePath)") val blueprintRuntimeService = BluePrintMetadataUtils @@ -73,7 +73,6 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService } catch (e: Exception) { throw e } - return blueprintRuntimeService.bluePrintContext() } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt index 4239abbab..11087bc52 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt @@ -19,11 +19,11 @@ package org.onap.ccsdk.apps.controllerblueprints.service.handler import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService +import org.onap.ccsdk.apps.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch @@ -95,26 +95,6 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC } - /** - * This is a publishBlueprintModel method to change the status published to YES - * - * @param id id - * @return BlueprintModelSearch - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun publishBlueprintModel(id: String): BlueprintModelSearch { - val blueprintModelSearch: BlueprintModelSearch - val dbBlueprintModel = blueprintModelSearchRepository.findById(id) - if (dbBlueprintModel.isPresent) { - blueprintModelSearch = dbBlueprintModel.get() - } else { - val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id) - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) - } - blueprintModelSearch.published = ApplicationConstants.ACTIVE_Y - return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch) - } /** * This is a searchBlueprintModels method @@ -296,9 +276,8 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC @Throws(BluePrintException::class) open suspend fun enrichBlueprint(filePart: FilePart): ResponseEntity { val enhanceId = UUID.randomUUID().toString() - val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(enhanceId) - val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(enhanceId) - + val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, enhanceId) + val blueprintEnrichmentDir = normalizedPathName(bluePrintLoadConfiguration.blueprintEnrichmentPath, enhanceId) try { BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir) @@ -309,7 +288,35 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC } catch (e: IOException) { throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - String.format("I/O Error while uploading the CBA file: %s", e.message), e) + "Error in Enriching CBA: ${e.message}", e) + } finally { + BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir) + } + } + + /** + * This is a publishBlueprintModel method to change the status published to YES + * + * @param filePart filePart + * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch { + val publishId = UUID.randomUUID().toString() + val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(publishId) + val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(publishId) + try { + val compressedFilePart = BluePrintEnhancerUtils + .extractCompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir) + + val blueprintId = bluePrintCatalogService.saveToDatabase(compressedFilePart, true) + + return blueprintModelSearchRepository.findById(blueprintId).get() + + } catch (e: Exception) { + throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, + "Error in Publishing CBA: ${e.message}", e) } finally { BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir) } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt index 892cdbd5b..17149e466 100755 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt @@ -1,6 +1,7 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. * Modifications Copyright © 2019 Bell Canada. + * 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. @@ -83,7 +84,8 @@ class ControllerBlueprintCatalogServiceImpl(bluePrintValidatorService: BluePrint val blueprintModel = BlueprintModel() blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL - blueprintModel.published = ApplicationConstants.ACTIVE_N + blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] + ?: BluePrintConstants.FLAG_N blueprintModel.artifactName = artifactName blueprintModel.artifactVersion = artifactVersion blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt index 02140ebf7..cf1bfb578 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt @@ -21,12 +21,9 @@ package org.onap.ccsdk.apps.controllerblueprints.service.utils import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.reactive.awaitSingle import kotlinx.coroutines.withContext -import org.apache.commons.io.FileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.* import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.deCompress import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils import org.springframework.core.io.ByteArrayResource @@ -87,7 +84,7 @@ class BluePrintEnhancerUtils { return artifactType } - suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File { + private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File { // Delete the Directory targetFile.deleteRecursively() return filePart.transferTo(targetFile) @@ -95,20 +92,23 @@ class BluePrintEnhancerUtils { .awaitSingle() } - suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { + suspend fun extractCompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { //Recreate the Base Directories - Paths.get(archiveDir).toFile().reCreateDirs() - Paths.get(enhanceDir).toFile().reCreateDirs() - - val filePartFile = Paths.get(archiveDir, "cba.zip").toFile() + normalizedFile(archiveDir).reCreateDirs() + normalizedFile(enhanceDir).reCreateDirs() + val filePartFile = normalizedFile(archiveDir, "cba.zip") // Copy the File Part to ZIP - copyFromFilePart(filePart, filePartFile) + return copyFromFilePart(filePart, filePartFile) + } + + suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { + val filePartFile = extractCompressFilePart(filePart, archiveDir, enhanceDir) val deCompressFileName = Paths.get(enhanceDir).toUri().path return filePartFile.deCompress(deCompressFileName) } suspend fun compressToFilePart(enhanceDir: String, archiveDir: String): ResponseEntity { - val compressedFile = Paths.get(archiveDir, "enhanced-cba.zip").toFile() + val compressedFile = normalizedFile(archiveDir, "enhanced-cba.zip") BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile, true) return prepareResourceEntity(compressedFile.name, compressedFile.readBytes()) } @@ -121,11 +121,8 @@ class BluePrintEnhancerUtils { } suspend fun cleanEnhancer(archiveLocation: String, enhancementLocation: String) = withContext(Dispatchers.Default) { - val enrichDir = File(enhancementLocation) - FileUtils.forceDeleteOnExit(enrichDir) - - val archiveDir = File(archiveLocation) - FileUtils.forceDeleteOnExit(archiveDir) + deleteDir(archiveLocation) + deleteDir(enhancementLocation) } /** diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt index e0ecf0397..74f225a5b 100644 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt @@ -91,17 +91,18 @@ class BluePrintEnhancerServiceImplTest { } private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) { + runBlocking { + val targetPath = Paths.get("target", targetDirName).toUri().path - val targetPath = Paths.get("target", targetDirName).toUri().path - - deleteTargetDirectory(targetPath) + deleteTargetDirectory(targetPath) - val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) - Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) + val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) + Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) - // Validate the Generated BluePrints - val valid = bluePrintValidatorService.validateBluePrints(targetPath) - Assert.assertTrue("blueprint($basePath) validation failed ", valid) + // Validate the Generated BluePrints + val valid = bluePrintValidatorService.validateBluePrints(targetPath) + Assert.assertTrue("blueprint($basePath) validation failed ", valid) + } } private fun deleteTargetDirectory(targetPath: String) { diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt index 2e7ca2cdc..026561e10 100644 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt @@ -20,10 +20,7 @@ import kotlinx.coroutines.runBlocking import org.junit.After import org.junit.Before import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.compress -import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir -import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile -import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs +import org.onap.ccsdk.apps.controllerblueprints.core.* import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart import java.nio.file.Paths import java.util.* @@ -34,10 +31,9 @@ class BluePrintEnhancerUtilsTest { private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" private val blueprintArchivePath: String = "./target/blueprints/archive" private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" - private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").toFile().normalize().absolutePath + private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").normalize().toUri().path @Before - @Throws(Exception::class) fun setUp() { val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs() assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}") @@ -49,20 +45,19 @@ class BluePrintEnhancerUtilsTest { } @After - @Throws(Exception::class) fun tearDown() { deleteDir(blueprintArchivePath) deleteDir(blueprintEnrichmentPath) } @Test - fun testDecompressFilePart() { + fun testFilePartCompressionNDeCompression() { val filePart = MockFilePart(zipBlueprintFileName) runBlocking { val enhanceId = UUID.randomUUID().toString() - val blueprintArchiveLocation = "$blueprintArchivePath/$enhanceId" - val blueprintEnrichmentLocation = "$blueprintEnrichmentPath/$enhanceId" + val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId) + val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId) BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation) BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation) } -- cgit 1.2.3-korg From 1f32a2c10bdd5a39fd93221406b8ac5aaaef88f6 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Thu, 21 Mar 2019 15:56:38 -0400 Subject: Add workflow output resolution Change-Id: I3d5bb339fd07257e86ada85e4a30040183808848 Issue-ID: CCSDK-1175 Signed-off-by: Muthuramalingam, Brinda Santh --- .../core/FileExtensionFunctions.kt | 6 +-- .../core/data/BluePrintModel.kt | 6 ++- .../core/service/BluePrintRuntimeService.kt | 44 +++++++++++++++++++++- .../core/service/BluePrintRuntimeServiceTest.kt | 16 +++++++- .../service/utils/BluePrintEnhancerUtils.kt | 2 +- .../enhancer/BluePrintEnhancerServiceImplTest.kt | 14 +++---- .../service/utils/BluePrintEnhancerUtilsTest.kt | 2 +- 7 files changed, 73 insertions(+), 17 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt index 11553ba6b..ff896ba92 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt @@ -65,8 +65,8 @@ fun File.deCompress(targetFile: File): File { return targetFile } -fun deleteDir(path: String) { - normalizedFile(path).deleteRecursively() +fun deleteDir(path: String, vararg more: String?) { + normalizedFile(path, *more).deleteRecursively() } fun normalizedFile(path: String, vararg more: String?): File { @@ -78,6 +78,6 @@ fun normalizedPath(path: String, vararg more: String?): Path { } fun normalizedPathName(path: String, vararg more: String?): String { - return normalizedPath(path, *more).toUri().path + return normalizedPath(path, *more).toString() } 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 index aab4e7c78..56acf6126 100644 --- 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 @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -163,7 +163,8 @@ class PropertyDefinition { 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") + // Mainly used in Workflow Outputs + @get:ApiModelProperty(notes = "Property Value, It may be Expression or Json type values") var value: JsonNode? = null } @@ -565,6 +566,7 @@ class Workflow { var steps: MutableMap? = null var preconditions: ArrayList? = null var inputs: MutableMap? = null + var outputs: MutableMap? = null } 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 c16d1ecc6..7958adf7c 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 @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,6 +67,12 @@ interface BluePrintRuntimeService { propertyDefinitions: MutableMap, propertyAssignments: MutableMap): MutableMap + fun resolvePropertyDefinitions(name: String, propertyDefinitions: MutableMap) + : MutableMap + + fun resolvePropertyAssignments(name: String, propertyAssignments: MutableMap) + : MutableMap + fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap fun resolveNodeTemplateCapabilityProperties(nodeTemplateName: String, capabilityName: String): MutableMap { fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) + fun resolveWorkflowOutputs(workflowName: String): MutableMap + fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List): JsonNode } @@ -242,6 +250,34 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl return propertyAssignmentValue } + override fun resolvePropertyDefinitions(name: String, propertyDefinitions: MutableMap) + : MutableMap { + val propertyAssignmentValue: MutableMap = hashMapOf() + + propertyDefinitions.forEach { propertyName, propertyDefinition -> + val propertyAssignmentExpression = PropertyAssignmentService(this) + val expression = propertyDefinition.value ?: propertyDefinition.defaultValue + if (expression != null) { + propertyAssignmentValue[propertyName] = propertyAssignmentExpression.resolveAssignmentExpression(name, + propertyName, expression) + } + } + return propertyAssignmentValue + } + + override fun resolvePropertyAssignments(name: String, propertyAssignments: MutableMap) + : MutableMap { + + val propertyAssignmentValue: MutableMap = hashMapOf() + + propertyAssignments.forEach { propertyName, propertyExpression -> + val propertyAssignmentExpression = PropertyAssignmentService(this) + propertyAssignmentValue[propertyName] = propertyAssignmentExpression.resolveAssignmentExpression(name, + propertyName, propertyExpression) + } + return propertyAssignmentValue + } + override fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { log.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName) @@ -520,6 +556,12 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl } } + override fun resolveWorkflowOutputs(workflowName: String): MutableMap { + log.info("resolveWorkflowOutputs for workflow($workflowName)") + val outputs = bluePrintContext.workflowByName(workflowName).outputs ?: mutableMapOf() + return resolvePropertyDefinitions("WORKFLOW", outputs) + } + override fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List): JsonNode { val jsonNode: ObjectNode = jacksonObjectMapper().createObjectNode() 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 index c0bfd0f5f..dc56b5207 100644 --- 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 @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,6 +153,20 @@ class BluePrintRuntimeServiceTest { assertNotNull(resolvedJsonNode, "Failed to populate dsl property values") } + @Test + fun `test Resolve Workflow Outputs`() { + log.info("************************ resolvePropertyAssignments **********************") + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}" + + bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", + JacksonUtils.jsonNode(assignmentParams)) + + val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment") + assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values") + } + private fun getBluePrintRuntimeService(): BluePrintRuntimeService> { val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt index cf1bfb578..41a7bf8a5 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt @@ -103,7 +103,7 @@ class BluePrintEnhancerUtils { suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { val filePartFile = extractCompressFilePart(filePart, archiveDir, enhanceDir) - val deCompressFileName = Paths.get(enhanceDir).toUri().path + val deCompressFileName = normalizedPathName(enhanceDir) return filePartFile.deCompress(deCompressFileName) } diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt index 74f225a5b..62a37bef1 100644 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt @@ -23,16 +23,16 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.apps.controllerblueprints.TestApplication +import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.apps.controllerblueprints.service.load.ModelTypeLoadService import org.onap.ccsdk.apps.controllerblueprints.service.load.ResourceDictionaryLoadService import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner -import java.io.File -import java.nio.file.Paths @RunWith(SpringRunner::class) @ContextConfiguration(classes = arrayOf(TestApplication::class)) @@ -92,9 +92,9 @@ class BluePrintEnhancerServiceImplTest { private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) { runBlocking { - val targetPath = Paths.get("target", targetDirName).toUri().path + val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName) - deleteTargetDirectory(targetPath) + deleteDir(targetPath) val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) @@ -102,12 +102,10 @@ class BluePrintEnhancerServiceImplTest { // Validate the Generated BluePrints val valid = bluePrintValidatorService.validateBluePrints(targetPath) Assert.assertTrue("blueprint($basePath) validation failed ", valid) + + deleteDir(targetPath) } } - private fun deleteTargetDirectory(targetPath: String) { - val targetDirectory = File(targetPath) - targetDirectory.deleteRecursively() - } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt index 026561e10..6bd10525e 100644 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt @@ -31,7 +31,7 @@ class BluePrintEnhancerUtilsTest { private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" private val blueprintArchivePath: String = "./target/blueprints/archive" private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" - private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").normalize().toUri().path + private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip") @Before fun setUp() { -- cgit 1.2.3-korg