From 55dcf3197958c76b1622a0c26489e68fe77e0314 Mon Sep 17 00:00:00 2001 From: Ravi Mantena Date: Wed, 21 Oct 2020 15:47:38 -0400 Subject: Blueprint Generator Refactored Code Issue-ID: DCAEGEN2-2472 Change-Id: I2ade7fb3b4196554eb4ecadd918fd45cb6ba8a52 Signed-off-by: Ravi Mantena --- mod/bpgenerator/onap/pom.xml | 71 +++++ .../BlueprintGeneratorMainApplication.java | 110 +++++++ .../common/ExternalCertificateParameters.java | 47 +++ .../model/common/ExternalTlsInfo.java | 60 ++++ .../model/common/GetAttribute.java | 44 +++ .../onap/blueprintgenerator/model/common/Info.java | 54 ++++ .../model/common/Interfaces.java | 42 +++ .../onap/blueprintgenerator/model/common/Node.java | 51 ++++ .../model/common/OnapBlueprint.java | 48 +++ .../blueprintgenerator/model/common/PgaasNode.java | 46 +++ .../model/common/PgaasNodeProperties.java | 49 +++ .../model/common/PolicyModel.java | 48 +++ .../model/common/PolicyModelNode.java | 47 +++ .../model/common/PolicyNode.java | 46 +++ .../model/common/PolicyNodeProperties.java | 48 +++ .../model/common/PolicyProperties.java | 45 +++ .../model/common/Properties.java | 89 ++++++ .../model/common/ResourceConfig.java | 45 +++ .../blueprintgenerator/model/common/Services.java | 50 +++ .../blueprintgenerator/model/common/Start.java | 49 +++ .../model/common/StartInputs.java | 49 +++ .../model/componentspec/OnapAuxilary.java | 60 ++++ .../model/componentspec/OnapComponentSpec.java | 52 ++++ .../model/componentspec/PolicyInfo.java | 45 +++ .../model/componentspec/Services.java | 51 ++++ .../model/componentspec/TypePolicy.java | 43 +++ .../blueprintgenerator/model/dmaap/Streams.java | 66 ++++ .../blueprintgenerator/model/dmaap/TlsInfo.java | 49 +++ .../blueprintgenerator/service/InfoService.java | 116 +++++++ .../service/OnapBlueprintService.java | 111 +++++++ .../service/common/AppConfigService.java | 166 ++++++++++ .../service/common/CommonUtils.java | 152 ++++++++++ .../service/common/ComponentSpecService.java | 66 ++++ .../service/common/DmaapService.java | 103 +++++++ .../ExternalCertificateDataFactoryService.java | 50 +++ ...xternalCertificateParametersFactoryService.java | 71 +++++ .../common/ExternalTlsInfoFactoryService.java | 87 ++++++ .../service/common/ImportsService.java | 98 ++++++ .../service/common/InterfacesService.java | 67 ++++ .../service/common/NodeService.java | 222 ++++++++++++++ .../service/common/PgaasNodeService.java | 138 +++++++++ .../service/common/PolicyNodeService.java | 99 ++++++ .../service/common/PropertiesService.java | 259 ++++++++++++++++ .../service/common/QuotationService.java | 59 ++++ .../service/common/ResourceConfigService.java | 98 ++++++ .../service/common/StartInputsService.java | 97 ++++++ .../service/common/StartService.java | 65 ++++ .../service/dmaap/DmaapBlueprintService.java | 144 +++++++++ .../service/dmaap/StreamsService.java | 104 +++++++ .../service/PolicyModelNodeService.java | 150 +++++++++ .../policycreate/service/PolicyModelService.java | 105 +++++++ .../onap/src/main/resources/application.properties | 36 +++ .../test/BlueprintGeneratorTestSuite.java | 40 +++ .../test/BlueprintGeneratorTests.java | 109 +++++++ .../test/BlueprintJarComparatorTest.java | 115 +++++++ ...nalCertificateParametersFactoryServiceTest.java | 61 ++++ .../test/OnapBlueprintServiceTest.java | 257 ++++++++++++++++ .../test/OnapComponentSpecTest.java | 58 ++++ .../blueprintgenerator/test/OnapTestUtils.java | 207 +++++++++++++ .../onap/blueprintgenerator/test/TlsInfoTest.java | 168 ++++++++++ ...ponentSpec_withTlsFalseAndExternalTlsFalse.json | 43 +++ ...omponentSpec_withTlsTrueAndExternalTlsTrue.json | 43 +++ ...tComponentSpec_withTlsTrueAndNoExternalTls.json | 42 +++ .../testComponentSpec_withoutTlsInfo.json | 38 +++ .../test/resources/componentspecs/testImports.yaml | 4 + .../src/test/resources/componentspecs/ves.json | 337 +++++++++++++++++++++ .../src/test/resources/policyjson/policyInput.json | 28 ++ mod/bpgenerator/onap/version.properties | 29 ++ 68 files changed, 5746 insertions(+) create mode 100644 mod/bpgenerator/onap/pom.xml create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/BlueprintGeneratorMainApplication.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ExternalCertificateParameters.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ExternalTlsInfo.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/GetAttribute.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Info.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Interfaces.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Node.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/OnapBlueprint.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PgaasNode.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PgaasNodeProperties.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyModel.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyModelNode.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyNode.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyNodeProperties.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyProperties.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ResourceConfig.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Services.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Start.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/StartInputs.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/OnapAuxilary.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/OnapComponentSpec.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/PolicyInfo.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/Services.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/TypePolicy.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/dmaap/Streams.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/dmaap/TlsInfo.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/InfoService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/OnapBlueprintService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/CommonUtils.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ComponentSpecService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/DmaapService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalCertificateDataFactoryService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalCertificateParametersFactoryService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalTlsInfoFactoryService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ImportsService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/InterfacesService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PgaasNodeService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PolicyNodeService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/QuotationService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ResourceConfigService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/StartInputsService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/StartService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/StreamsService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/policycreate/service/PolicyModelNodeService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/policycreate/service/PolicyModelService.java create mode 100644 mod/bpgenerator/onap/src/main/resources/application.properties create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTestSuite.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTests.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintJarComparatorTest.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/ExternalCertificateParametersFactoryServiceTest.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintServiceTest.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapComponentSpecTest.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapTestUtils.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/TlsInfoTest.java create mode 100644 mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsFalseAndExternalTlsFalse.json create mode 100644 mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsTrueAndExternalTlsTrue.json create mode 100644 mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsTrueAndNoExternalTls.json create mode 100644 mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withoutTlsInfo.json create mode 100644 mod/bpgenerator/onap/src/test/resources/componentspecs/testImports.yaml create mode 100644 mod/bpgenerator/onap/src/test/resources/componentspecs/ves.json create mode 100644 mod/bpgenerator/onap/src/test/resources/policyjson/policyInput.json create mode 100644 mod/bpgenerator/onap/version.properties (limited to 'mod/bpgenerator/onap') diff --git a/mod/bpgenerator/onap/pom.xml b/mod/bpgenerator/onap/pom.xml new file mode 100644 index 0000000..799a683 --- /dev/null +++ b/mod/bpgenerator/onap/pom.xml @@ -0,0 +1,71 @@ + + + + + 4.0.0 + + org.onap.dcaegen2.platform + blueprint-generator-onap + 1.7.0 + jar + + Onap + This Application is used to generate ONAP Blueprint YAML Files for given Component Specs + + + org.onap.dcaegen2.platform + blueprint-generator + 1.7.0-SNAPSHOT + + + + + org.onap.dcaegen2.platform + blueprint-generator-common + 2.0.0 + compile + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.2.5.RELEASE + + + + repackage + + + + + + onap-blueprint-generator-${project.version} + + + \ No newline at end of file diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/BlueprintGeneratorMainApplication.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/BlueprintGeneratorMainApplication.java new file mode 100644 index 0000000..3b9dd49 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/BlueprintGeneratorMainApplication.java @@ -0,0 +1,110 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator; + + +import org.onap.blueprintgenerator.model.base.Blueprint; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec; +import org.onap.blueprintgenerator.service.OnapBlueprintService; +import org.onap.blueprintgenerator.service.common.CommonUtils; +import org.onap.blueprintgenerator.service.common.ComponentSpecService; +import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintService; +import org.onap.policycreate.service.PolicyModelService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +import static java.lang.System.exit; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP - Blueprint Generator Main Application to create Policy Models or Blueprints + */ + +@ComponentScan({"org.onap.blueprintgenerator","org.onap.policycreate"}) +@SpringBootApplication +public class BlueprintGeneratorMainApplication implements CommandLineRunner { + + @Autowired + private ComponentSpecService componentSpecService; + + @Autowired + private PolicyModelService policyModelService; + + @Autowired + private CommonUtils commonUtils; + + @Autowired + private PolicyModelService onapPolicyModelNodeService; + + @Autowired + private ComponentSpecService onapComponentSpecService; + + @Autowired + private CommonUtils onapCommonUtils; + + @Autowired + private OnapBlueprintService onapBlueprintService; + + @Autowired + private DmaapBlueprintService dmaapBlueprintService; + + public static void main(String[] args) { + SpringApplication.run(BlueprintGeneratorMainApplication.class, args); + } + + @Override + public void run(String... args) { + if (args.length >=2 && args[0].equals("app") && args[1].equals("ONAP")) { + onapCommonUtils.printInstructions(); + if(args.length >=4 && args[2].equals("-type") && args[3].equals("policycreate")){ + Input input = onapCommonUtils.parseInputs(args); + ComponentSpec componentSpec = componentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + onapPolicyModelNodeService.createPolicyModels(componentSpec.getParameters(), input.getOutputPath()); + } + else { + Input input = onapCommonUtils.parseInputs(args); + OnapComponentSpec onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + if (input.getBpType().equals("o")) { + Blueprint blueprint = onapBlueprintService.createBlueprint(onapComponentSpec, input); + onapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input); + System.out.println(onapBlueprintService.blueprintToString(onapComponentSpec, blueprint, input)); + } else if (input.getBpType().equals("d")) { + Blueprint blueprint = dmaapBlueprintService.createBlueprint(onapComponentSpec, input); + dmaapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input); + System.out.println(dmaapBlueprintService.blueprintToString(onapComponentSpec, blueprint, input)); + } + } + } + + exit(0); + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ExternalCertificateParameters.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ExternalCertificateParameters.java new file mode 100644 index 0000000..d7c76a9 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ExternalCertificateParameters.java @@ -0,0 +1,47 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import org.onap.blueprintgenerator.constants.Constants; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: External Certificate Parameters + */ + + +@Data +public class ExternalCertificateParameters { + + @JsonProperty(Constants.COMMON_NAME_FIELD) + private GetInput commonName; + + @JsonProperty(Constants.SANS_FIELD) + private GetInput sans; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ExternalTlsInfo.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ExternalTlsInfo.java new file mode 100644 index 0000000..197104d --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ExternalTlsInfo.java @@ -0,0 +1,60 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import org.onap.blueprintgenerator.constants.Constants; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: External TLS Info + */ + + +@Data +@JsonInclude(value = JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class ExternalTlsInfo { + + @JsonProperty(Constants.EXTERNAL_CERT_DIRECTORY_FIELD) + private String externalCertDirectory; + + @JsonProperty(Constants.USE_EXTERNAL_TLS_FIELD) + private GetInput useExternalTls; + + @JsonProperty(Constants.CA_NAME_FIELD) + private GetInput caName; + + @JsonProperty(Constants.CERT_TYPE_FIELD) + private GetInput certType; + + @JsonProperty(Constants.EXTERNAL_CERTIFICATE_PARAMETERS_FIELD) + private ExternalCertificateParameters externalCertificateParameters; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/GetAttribute.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/GetAttribute.java new file mode 100644 index 0000000..2d5bca7 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/GetAttribute.java @@ -0,0 +1,44 @@ + +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Get Attribute + */ + + +@Data +public class GetAttribute { + + @JsonProperty("get_attribute") + private Object attribute; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Info.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Info.java new file mode 100644 index 0000000..3721d55 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Info.java @@ -0,0 +1,54 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Info + */ + + +@Data +@JsonInclude(value= Include.NON_NULL) +public class Info { + + private GetInput topic_url; + + private GetInput username; + + private GetInput password; + + private GetInput location; + + private GetInput delivery_url; + + private GetInput subscriber_id; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Interfaces.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Interfaces.java new file mode 100644 index 0000000..04ef7e7 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Interfaces.java @@ -0,0 +1,42 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + + +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Interfaces + */ + + +@Data +public class Interfaces { + + private Start start; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Node.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Node.java new file mode 100644 index 0000000..ea28d62 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Node.java @@ -0,0 +1,51 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Node derived from Common Module Node Model used by both DCAE and ONAP + */ + + +@Data +@JsonInclude(value = JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class Node extends org.onap.blueprintgenerator.model.base.Node { + + private Map interfaces; + + private Properties properties; + + private List> relationships; +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/OnapBlueprint.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/OnapBlueprint.java new file mode 100644 index 0000000..4dd7b0f --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/OnapBlueprint.java @@ -0,0 +1,48 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import org.onap.blueprintgenerator.model.base.Blueprint; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Blueprint derived from Common Module Blueprint Model used by both DCAE and ONAP + */ + + +@Data +@JsonInclude(value = JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class OnapBlueprint extends Blueprint { + + private Map node_templates; + +} \ No newline at end of file diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PgaasNode.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PgaasNode.java new file mode 100644 index 0000000..af6fb54 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PgaasNode.java @@ -0,0 +1,46 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Pgaas Node + */ + + +@Data +@NoArgsConstructor +public class PgaasNode extends Node { + + @JsonProperty("properties") + private PgaasNodeProperties pgaasNodeProperties; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PgaasNodeProperties.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PgaasNodeProperties.java new file mode 100644 index 0000000..37ddb73 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PgaasNodeProperties.java @@ -0,0 +1,49 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Pgaas Node Properties + */ + + + +@Data +public class PgaasNodeProperties { + + @JsonProperty("writerfqdn") + private GetInput writerfqdn; + + @JsonProperty("name") + private GetInput name; + + @JsonProperty("use_existing") + private boolean useExisting; +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyModel.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyModel.java new file mode 100644 index 0000000..08b9096 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyModel.java @@ -0,0 +1,48 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Policy Model + */ + + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class PolicyModel { + + private String tosca_definition_version; + private Map node_types; + private Map data_types; + + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyModelNode.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyModelNode.java new file mode 100644 index 0000000..c418b8e --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyModelNode.java @@ -0,0 +1,47 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Policy Model Node + */ + + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class PolicyModelNode { + + private String derived_from; + + private Map properties; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyNode.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyNode.java new file mode 100644 index 0000000..cc08814 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyNode.java @@ -0,0 +1,46 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Policy Node derived from Common Module Node Model used by both DCAE and ONAP + */ + + +@Data +@NoArgsConstructor +public class PolicyNode extends Node { + + @JsonProperty("properties") + private PolicyNodeProperties policyNodeProperties; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyNodeProperties.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyNodeProperties.java new file mode 100644 index 0000000..3f472c8 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyNodeProperties.java @@ -0,0 +1,48 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Policy Node Properties + */ + + +@Data +@NoArgsConstructor +public class PolicyNodeProperties { + + @JsonProperty("policy_id") + private GetInput policyId; + + @JsonProperty("policy_model_id") + private String policyModelId; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyProperties.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyProperties.java new file mode 100644 index 0000000..5a63b00 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/PolicyProperties.java @@ -0,0 +1,45 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Policy Properties + */ + + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class PolicyProperties { + + private String type; + + private Object entry_schema; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java new file mode 100644 index 0000000..11fc06e --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java @@ -0,0 +1,89 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary; +import org.onap.blueprintgenerator.model.dmaap.Streams; +import org.onap.blueprintgenerator.model.dmaap.TlsInfo; +import org.onap.blueprintgenerator.service.common.ExternalTlsInfoFactoryService; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Properties + */ + + +@Data +@JsonInclude(value = Include.NON_NULL) +public class Properties { + + private Appconfig application_config; + + private OnapAuxilary docker_config; + + private Object image; + + private GetInput location_id; + + private String service_component_type; + + private Map log_info; + + private String dns_name; + + private Object replicas; + + private String name; + + private GetInput topic_name; + + private GetInput feed_name; + + private List streams_publishes; + + private List streams_subscribes; + + private TlsInfo tls_info; + + private ResourceConfig resource_config; + + private GetInput always_pull_image; + + private Boolean useExisting; + + @JsonIgnore + private ExternalTlsInfoFactoryService externalCertFactory; + + private ExternalTlsInfo external_cert; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ResourceConfig.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ResourceConfig.java new file mode 100644 index 0000000..8b41fd2 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/ResourceConfig.java @@ -0,0 +1,45 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import lombok.Data; + +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Resource Config + */ + + +@Data +public class ResourceConfig { + + private Map limits; + + private Map requests; + +} \ No newline at end of file diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Services.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Services.java new file mode 100644 index 0000000..7aa1566 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Services.java @@ -0,0 +1,50 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import org.onap.blueprintgenerator.model.componentspec.common.Calls; +import org.onap.blueprintgenerator.model.componentspec.common.Provides; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Services + */ + + +@Data +@JsonInclude(value=Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class Services { + + private Calls[] calls; + + private Provides[] provides; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Start.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Start.java new file mode 100644 index 0000000..3740668 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Start.java @@ -0,0 +1,49 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Start + */ + + +@Data +@JsonInclude(value= JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class Start { + + private StartInputs inputs; + + private Map envs; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/StartInputs.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/StartInputs.java new file mode 100644 index 0000000..458852e --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/StartInputs.java @@ -0,0 +1,49 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.common; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.List; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Common Model used by both ONAP and DMAAP: Start Inputs under Start + */ + + +@Data +@JsonInclude(value= JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class StartInputs { + + private Object envs; + + private List ports; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/OnapAuxilary.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/OnapAuxilary.java new file mode 100644 index 0000000..0923195 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/OnapAuxilary.java @@ -0,0 +1,60 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.componentspec; + +import org.onap.blueprintgenerator.model.componentspec.base.Auxilary; +import org.onap.blueprintgenerator.model.componentspec.common.Volumes; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Component Spec Model for ONAP Auxillary derived from Common Module Auxillary used by both DCAE and ONAP + */ + + +@Data +@JsonInclude(value = JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class OnapAuxilary extends Auxilary { + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private List ports; + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private Map log_info; + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private Map tls_info; + + private Volumes[] volumes; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/OnapComponentSpec.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/OnapComponentSpec.java new file mode 100644 index 0000000..5a64366 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/OnapComponentSpec.java @@ -0,0 +1,52 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.componentspec; + +import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Component Spec Model for ONAP Component Spec derived from Common Module Component Spec used by both DCAE and ONAP + */ + + +@Data +@JsonInclude(value = JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class OnapComponentSpec extends ComponentSpec { + + private Services services; + + private OnapAuxilary auxilary; + + @JsonProperty("policy_info") + private PolicyInfo policyInfo; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/PolicyInfo.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/PolicyInfo.java new file mode 100644 index 0000000..3ec5fe3 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/PolicyInfo.java @@ -0,0 +1,45 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.componentspec; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Component Spec Model for Policy Info + */ + + +@Data +public class PolicyInfo { + + @JsonProperty("policy") + private List typePolicyList; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/Services.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/Services.java new file mode 100644 index 0000000..b7d32a4 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/Services.java @@ -0,0 +1,51 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.componentspec; + + +import org.onap.blueprintgenerator.model.componentspec.common.Calls; +import org.onap.blueprintgenerator.model.componentspec.common.Provides; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Component Spec Model for Services + */ + + +@Data +@JsonInclude(value= Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class Services { + + private Calls[] calls; + + private Provides[] provides; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/TypePolicy.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/TypePolicy.java new file mode 100644 index 0000000..6ba7daf --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/componentspec/TypePolicy.java @@ -0,0 +1,43 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.componentspec; + +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Component Spec Model for Type Policy + */ + + +@Data +public class TypePolicy { + + private String node_label; + private String policy_id; + private String policy_model_id; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/dmaap/Streams.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/dmaap/Streams.java new file mode 100644 index 0000000..14d0c51 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/dmaap/Streams.java @@ -0,0 +1,66 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.dmaap; + +import org.onap.blueprintgenerator.model.common.GetInput; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.Data; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * DMAAP Model for Streams + */ + + +@Data +@JsonInclude(value= Include.NON_NULL) +public class Streams { + + private String name; + + private GetInput location; + + private GetInput client_role; + + private String type; + + private GetInput username; + + private GetInput password; + + //private GetInput delivery_url; + + private GetInput privileged; + + private GetInput decompress; + + private String route; + + private String scheme; + + +} \ No newline at end of file diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/dmaap/TlsInfo.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/dmaap/TlsInfo.java new file mode 100644 index 0000000..9290bf9 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/dmaap/TlsInfo.java @@ -0,0 +1,49 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.model.dmaap; + +import org.onap.blueprintgenerator.model.common.GetInput; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * DMAAP Model for TLS Info + */ + + +@Data +@NoArgsConstructor +public class TlsInfo { + + @JsonProperty("cert_directory") + private String certDirectory; + + @JsonProperty("use_tls") + private GetInput useTls; + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/InfoService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/InfoService.java new file mode 100644 index 0000000..fed3707 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/InfoService.java @@ -0,0 +1,116 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service; + +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.Info; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Service to create Message Router and Data Router Information + */ + +@Service +public class InfoService { + + @Autowired + private BlueprintHelperService blueprintHelperService; + + // Method to create info for Message Router + public Map createMessageRouterInfo(Map> inputs, String config, char type) { + + Map response = new HashMap<>(); + Info info = new Info(); + + LinkedHashMap stringType = new LinkedHashMap<>(); + stringType.put("type", "string"); + + config = config.replaceAll("-", "_"); + if(type == 'p') { + config = config + "_publish_url"; + } + else if(type == 's') { + config = config+ "_subscribe_url"; + } + + GetInput topic = new GetInput(); + topic.setBpInputName(config); + info.setTopic_url(topic); + + inputs.put(config, stringType); + + response.put("info", info); + response.put("inputs", inputs); + return response; + } + + // Method to create info for Data Router + public Map createDataRouterInfo(Map> inputs, String config) { + + Map response = new HashMap<>(); + Info info = new Info(); + + LinkedHashMap stringType = new LinkedHashMap<>(); + stringType.put("type", "string"); + + String userNameInputName = blueprintHelperService.joinUnderscore(config, "username"); + GetInput username = new GetInput(userNameInputName); + info.setUsername(username); + inputs.put(userNameInputName, stringType); + + String userpasswordInputName = blueprintHelperService.joinUnderscore(config, "password"); + GetInput password = new GetInput(userpasswordInputName); + info.setPassword(password); + inputs.put(userpasswordInputName, stringType); + + String userlocationInputName = blueprintHelperService.joinUnderscore(config, "location"); + GetInput location = new GetInput(userlocationInputName); + info.setLocation(location); + inputs.put(userlocationInputName, stringType); + + String userdeliveryUrlInputName = blueprintHelperService.joinUnderscore(config, "delivery_url"); + GetInput deliveryUrl = new GetInput(userdeliveryUrlInputName); + info.setDelivery_url(deliveryUrl); + inputs.put(userdeliveryUrlInputName, stringType); + + String usersubscriberIDInputName = blueprintHelperService.joinUnderscore(config, "subscriber_id"); + GetInput subscriberID = new GetInput(usersubscriberIDInputName); + info.setSubscriber_id(subscriberID); + inputs.put(usersubscriberIDInputName, stringType); + + response.put("info", info); + response.put("inputs", inputs); + return response; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/OnapBlueprintService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/OnapBlueprintService.java new file mode 100644 index 0000000..f25c18c --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/OnapBlueprintService.java @@ -0,0 +1,111 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service; + + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.exception.BlueprintException; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.service.base.BlueprintService; +import org.onap.blueprintgenerator.service.common.ImportsService; +import org.onap.blueprintgenerator.service.common.NodeService; +import org.onap.blueprintgenerator.service.common.PgaasNodeService; +import org.onap.blueprintgenerator.service.common.PolicyNodeService; +import org.onap.blueprintgenerator.service.common.QuotationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Service to create ONAP Blueprint + */ + +@Service +public class OnapBlueprintService extends BlueprintService { + + @Autowired + private NodeService nodeService; + + @Autowired + private PolicyNodeService policyNodeService; + + @Autowired + private PgaasNodeService pgaasNodeService; + + @Autowired + private QuotationService quotationService; + + @Autowired + protected ImportsService importsService; + + // Method to generate Onap Blueprint + public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) { + try { + OnapBlueprint blueprint = new OnapBlueprint(); + blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION); + + //if (!"".equals(input.getImportPath())) + if (!StringUtils.isEmpty(input.getImportPath())) + blueprint.setImports(importsService.createImportsFromFile(input.getImportPath())); + else + blueprint.setImports(importsService.createImports(input.getBpType())); + + Map nodeTemplate = new TreeMap<>(); + String nodeName = onapComponentSpec.getSelf().getName(); + Map> inputs = new TreeMap<>(); + + Map onapNodeResponse = nodeService.createOnapNode(inputs, onapComponentSpec, input.getServiceNameOverride()); + inputs = (Map>) onapNodeResponse.get("inputs"); + nodeTemplate.put(nodeName, (Node) onapNodeResponse.get("onapNode")); + blueprint.setNode_templates(nodeTemplate); + + if (onapComponentSpec.getPolicyInfo() != null) + policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); + + if (onapComponentSpec.getAuxilary() != null && onapComponentSpec.getAuxilary().getDatabases() != null) + pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); + + blueprint.setInputs(inputs); + + return quotationService.setQuotations(blueprint); + } catch (Exception ex) { + throw new BlueprintException("Unable to create ONAP Blueprint Object from given input parameters", ex); + } + } + + +} + + + diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java new file mode 100644 index 0000000..c6d744c --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java @@ -0,0 +1,166 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.Appconfig; +import org.onap.blueprintgenerator.model.common.Dmaap; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.common.Calls; +import org.onap.blueprintgenerator.model.componentspec.common.Parameters; +import org.onap.blueprintgenerator.model.componentspec.common.Publishes; +import org.onap.blueprintgenerator.model.componentspec.common.Subscribes; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to create App Config + */ + + +@Service("onapAppConfigService") +public class AppConfigService { + + @Autowired + private DmaapService dmaapService; + + @Autowired + private BlueprintHelperService blueprintHelperService; + + public Map createAppconfig(Map> inputs, OnapComponentSpec onapComponentSpec, String override, boolean isDmaap) { + + Map response = new HashMap<>(); + Appconfig appconfig = new Appconfig(); + + Calls[] call = new Calls[0]; + appconfig.setService_calls(call); + + Map streamPublishes = new TreeMap<>(); + if(onapComponentSpec.getStreams() != null) { + if (onapComponentSpec.getStreams().getPublishes() != null) { + for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) { + if (blueprintHelperService.isDataRouterType(publishes.getType())) { + String config = publishes.getConfig_key(); + String name = config + Constants._FEED; + Map dmaapDataRouterResponse = dmaapService.createDmaapDataRouter(inputs, config, name, isDmaap); + inputs = (Map>) dmaapDataRouterResponse.get("inputs"); + Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap"); + dmaap.setType(publishes.getType()); + streamPublishes.put(config, dmaap); + } else if (blueprintHelperService.isMessageRouterType(publishes.getType())) { + String config = publishes.getConfig_key(); + String name = config + Constants._TOPIC; + Map dmaapDataRouterResponse = dmaapService.createDmaapMessageRouter(inputs, config, 'p', name, name, isDmaap); + inputs = (Map>) dmaapDataRouterResponse.get("inputs"); + Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap"); + dmaap.setType(publishes.getType()); + streamPublishes.put(config, dmaap); + } + } + } + } + + Map streamSubscribes = new TreeMap<>(); + + if(onapComponentSpec.getStreams() != null) { + if (onapComponentSpec.getStreams().getSubscribes() != null) { + for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) { + if (blueprintHelperService.isDataRouterType(subscribes.getType())) { + String config = subscribes.getConfig_key(); + String name = config + Constants._FEED; + Map dmaapDataRouterResponse = dmaapService.createDmaapDataRouter(inputs, config, name, isDmaap); + inputs = (Map>) dmaapDataRouterResponse.get("inputs"); + Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap"); + dmaap.setType(subscribes.getType()); + streamSubscribes.put(config, dmaap); + } else if (blueprintHelperService.isMessageRouterType(subscribes.getType())) { + String config = subscribes.getConfig_key(); + String name = config + Constants._TOPIC; + Map dmaapDataRouterResponse = dmaapService.createDmaapMessageRouter(inputs, config, 's', name, name, isDmaap); + inputs = (Map>) dmaapDataRouterResponse.get("inputs"); + Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap"); + dmaap.setType(subscribes.getType()); + streamSubscribes.put(config, dmaap); + } + } + } + } + + appconfig.setStreams_publishes(streamPublishes); + appconfig.setStreams_subscribes(streamSubscribes); + + Map parameters = new TreeMap<>(); + for(Parameters p: onapComponentSpec.getParameters()) { + String pName = p.getName(); + if(p.isSourced_at_deployment()) { + GetInput paramInput = new GetInput(); + paramInput.setBpInputName(pName); + parameters.put(pName, paramInput); + if(!"".equals(p.getValue())) { + LinkedHashMap pInputs = blueprintHelperService.createStringInput( p.getValue()); + inputs.put(pName, pInputs); + } else { + LinkedHashMap pInputs = new LinkedHashMap<>(); + pInputs.put("type", "string"); + inputs.put(pName, pInputs); + } + } else { + if("string".equals(p.getType())) { + String val =(String) p.getValue(); + val = '"' + val + '"'; + parameters.put(pName, val); + } + else { + parameters.put(pName, p.getValue()); + // Updated code to resolve the issue of missing \ for collector.schema.file + //parameters.put(pName, pName.equals("collector.schema.file") ? ((String)p.getValue()).replace("\"", "\\\"") : p.getValue()); + } + } + } + if(override != null) { + GetInput ov = new GetInput(); + ov.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE); + parameters.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, ov); + LinkedHashMap over = blueprintHelperService.createStringInput( override); + inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, over); + } + appconfig.setParams(parameters); + + response.put("appconfig", appconfig); + response.put("inputs", inputs); + return response; + + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/CommonUtils.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/CommonUtils.java new file mode 100644 index 0000000..97ed47f --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/CommonUtils.java @@ -0,0 +1,152 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + + + +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.CommandLine; +import org.onap.blueprintgenerator.model.common.Input; + +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import static java.lang.System.exit; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to Print Instructions and Parse Inputs + */ + + +@Service("onapCommonUtilsService") +public class CommonUtils { + + public void printInstructions() { + System.out.println("OPTIONS:"); + System.out.println("-i OR --component-spec: The path of the ONAP Blueprint INPUT JSON SPEC FILE (Required)"); + System.out.println("-p OR --blueprint-path: The path of the ONAP Blueprint OUTPUT where it will be saved (Required)"); + System.out.println("-n OR --blueprint-name: The NAME of the ONAP Blueprint OUTPUT that will be created (Optional)"); + System.out.println("-t OR --imports: The path of the ONAP Blueprint IMPORT FILE (Optional)"); + System.out.println("-o OR --service-name-override: The Value used to OVERRIDE the SERVICE NAME of the ONAP Blueprint (Optional)"); + System.out.println("-d OR --dmaap-plugin: The option to create a ONAP Blueprint with DMAAP Plugin (Optional)"); + System.out.println("Syntax to run from command line: \n For Blueprint : java -jar target/.jar app ONAP -i componentspec -p OutputBlueprintPath -n Blueprintname -d \n For PolicyCreate: java -jar target/.jar app ONAP -type policycreate -i componentspec -p OutputPolicyPath"); + } + + public Input parseInputs(String[] args) { + String[] modArgs = new String[args.length]; + for(int i=0; i createDmaapMessageRouter(Map> inputs,String config, char type, String counter, String num, boolean isDmaap) { + + Map response = new HashMap<>(); + Dmaap dmaap = new Dmaap(); + + LinkedHashMap stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + if(!isDmaap){ + Map infoResponse = infoService.createMessageRouterInfo(inputs, config, type); + inputs = (Map>) infoResponse.get("inputs"); + dmaap.setDmaap_info(infoResponse.get("info")); + } + else{ + String infoType = "<<" + counter + ">>"; + dmaap.setDmaap_info(infoType); + + GetInput u = new GetInput(); + u.setBpInputName(config + "_" + num +"_aaf_username"); + dmaap.setUser(u); + inputs.put(config + "_" + num +"_aaf_username", stringType); + + GetInput p = new GetInput(); + p.setBpInputName(config + "_" + num +"_aaf_password"); + dmaap.setPass(p); + inputs.put(config + "_" + num +"_aaf_password", stringType); + } + response.put("dmaap", dmaap); + response.put("inputs", inputs); + return response; + } + + // Method is used to create the Dmaap Data Router + public Map createDmaapDataRouter(Map> inputs, String config, String counter, boolean isDmaap) { + + Map response = new HashMap<>(); + Dmaap dmaap = new Dmaap(); + + if(!isDmaap){ + Map infoResponse = infoService.createDataRouterInfo(inputs, config); + inputs = (Map>) infoResponse.get("inputs"); + dmaap.setDmaap_info(infoResponse.get("info")); + } + else { + String infoType = "<<" + counter + ">>"; + dmaap.setDmaap_info(infoType); + } + response.put("dmaap", dmaap); + response.put("inputs", inputs); + return response; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalCertificateDataFactoryService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalCertificateDataFactoryService.java new file mode 100644 index 0000000..ab48ada --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalCertificateDataFactoryService.java @@ -0,0 +1,50 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 Nokia. All rights reserved. + * * Copyright (c) 2020 AT&T. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.springframework.stereotype.Service; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add External Certificate Data Factory + */ + + +@Service +public abstract class ExternalCertificateDataFactoryService { + + // Method to concatenate Constant with field + protected static GetInput createPrefixedGetInput(String fieldName) { + return new GetInput(addPrefix(fieldName)); + } + + // Method to concatenate the Constant INPUT_PREFIX to the input field + protected static String addPrefix(String fieldName) { return Constants.INPUT_PREFIX + fieldName; } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalCertificateParametersFactoryService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalCertificateParametersFactoryService.java new file mode 100644 index 0000000..b739e4b --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalCertificateParametersFactoryService.java @@ -0,0 +1,71 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.ExternalCertificateParameters; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add External Certificate Parameters + */ + + +@Service +public class ExternalCertificateParametersFactoryService extends ExternalCertificateDataFactoryService { + + @Autowired + private BlueprintHelperService blueprintHelperService; + + // method to create external certificate parameters + public ExternalCertificateParameters create() { + ExternalCertificateParameters externalCertificateParameters = new ExternalCertificateParameters(); + externalCertificateParameters.setCommonName(createPrefixedGetInput(Constants.COMMON_NAME_FIELD)); + externalCertificateParameters.setSans(createPrefixedGetInput(Constants.SANS_FIELD)); + return externalCertificateParameters; + } + + // method to create input list for external certificate parameters factory + public Map> createInputList() { + Map> retInputs = new LinkedHashMap<>(); + + LinkedHashMap commonNameInputMap = blueprintHelperService.createStringInput("Common name which should be present in certificate.",Constants.DEFAULT_COMMON_NAME); + retInputs.put(addPrefix(Constants.COMMON_NAME_FIELD), commonNameInputMap); + + LinkedHashMap sansInputMap = blueprintHelperService.createStringInput("\"List of Subject Alternative Names (SANs) which should be present in certificate. " + + "Delimiter - : Should contain a common_name value and other FQDNs under which the given " +"component is accessible.\"",Constants.DEFAULT_SANS); + retInputs.put(addPrefix(Constants.SANS_FIELD), sansInputMap); + + return retInputs; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalTlsInfoFactoryService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalTlsInfoFactoryService.java new file mode 100644 index 0000000..10364ab --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ExternalTlsInfoFactoryService.java @@ -0,0 +1,87 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.ExternalTlsInfo; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add External TLS Info + */ + + +@Service +public class ExternalTlsInfoFactoryService extends ExternalCertificateDataFactoryService { + + @Autowired + private ExternalCertificateParametersFactoryService externalCertificateParametersFactoryService; + + @Autowired + private BlueprintHelperService blueprintHelperService; + + //Method to create External TLS Info from Component Spec + public ExternalTlsInfo createFromComponentSpec(OnapComponentSpec cs) { + ExternalTlsInfo externalTlsInfoBp = new ExternalTlsInfo(); + Map tlsInfoCs = cs.getAuxilary().getTls_info(); + + externalTlsInfoBp.setExternalCertDirectory((String) tlsInfoCs.get(Constants.CERT_DIRECTORY_FIELD)); + externalTlsInfoBp.setUseExternalTls(createPrefixedGetInput(Constants.USE_EXTERNAL_TLS_FIELD)); + externalTlsInfoBp.setCaName(createPrefixedGetInput(Constants.CA_NAME_FIELD)); + externalTlsInfoBp.setCertType(createPrefixedGetInput(Constants.CERT_TYPE_FIELD)); + externalTlsInfoBp.setExternalCertificateParameters(externalCertificateParametersFactoryService.create()); + + return externalTlsInfoBp; + } + + //Method to create Input List for External TLS Info from Component Spec + public Map> createInputListFromComponentSpec(OnapComponentSpec cs) { + + Map> retInputs = new HashMap<>(); + + Map externalTlsInfoCs = cs.getAuxilary().getTls_info(); + LinkedHashMap useTlsFlagInput = blueprintHelperService.createBooleanInput("Flag to indicate external tls enable/disable.",externalTlsInfoCs.get(Constants.USE_EXTERNAL_TLS_FIELD)); + retInputs.put(addPrefix(Constants.USE_EXTERNAL_TLS_FIELD), useTlsFlagInput); + + LinkedHashMap caNameInputMap = blueprintHelperService.createStringInput("Name of Certificate Authority configured on CertService side.",Constants.DEFAULT_CA); + retInputs.put(addPrefix(Constants.CA_NAME_FIELD), caNameInputMap); + + LinkedHashMap certTypeInputMap = blueprintHelperService.createStringInput("Format of provided certificates",Constants.DEFAULT_CERT_TYPE); + retInputs.put(addPrefix(Constants.CERT_TYPE_FIELD), certTypeInputMap); + + retInputs.putAll(externalCertificateParametersFactoryService.createInputList()); + return retInputs; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ImportsService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ImportsService.java new file mode 100644 index 0000000..cb9c03c --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ImportsService.java @@ -0,0 +1,98 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.blueprintgenerator.model.common.Imports; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: DCAE/ONAP - Blueprint Generator + * Common Module: Used by ONAP Blueprint Application + * Service: For Imports + */ + +@Service +public class ImportsService { + + @Value("${imports.onap.types}") + private String importsOnapTypes; + + @Value("${imports.onap.K8s.plugintypes}") + private String importsOnapK8sPlugintypes; + + @Value("${imports.onap.K8s.dcaepolicyplugin}") + private String importsOnapK8sDcaepolicyplugin; + + @Value("${imports.dmaap.dmaapplugin}") + private String importsDmaapDmaapplugin; + + @Value("${import.Postgres}") + private String importPostgres; + + @Value("${import.Clamp}") + private String importClamp; + + + @Qualifier("yamlObjectMapper") + @Autowired + protected ObjectMapper yamlObjectMapper; + + public List createImports(String bpType) { + List imports = new ArrayList<>(); + if (bpType.equals("o")) { + imports.add(importsOnapTypes); + imports.add(importsOnapK8sPlugintypes); + imports.add(importsOnapK8sDcaepolicyplugin); + imports.add(importPostgres); + imports.add(importClamp); + } + else { + imports.add(importsOnapTypes); + imports.add(importsOnapK8sPlugintypes); + imports.add(importsDmaapDmaapplugin); + imports.add(importPostgres); + imports.add(importClamp); + } + return imports; + } + + public List createImportsFromFile(String path) throws IOException { + File importPath = new File(path); + Imports imports = yamlObjectMapper.readValue(importPath, Imports.class); + imports.getImports().removeIf(String::isBlank); + return imports.getImports(); + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/InterfacesService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/InterfacesService.java new file mode 100644 index 0000000..bfd14a4 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/InterfacesService.java @@ -0,0 +1,67 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.model.common.Interfaces; +import org.onap.blueprintgenerator.model.common.Start; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add Interfaces + */ + + +@Service +public class InterfacesService { + + @Autowired + private StartService startService; + + // Method to create Interface to include Start and Start inputs sections in BP + public Map createInterface(Map> inputs, OnapComponentSpec onapComponentSpec){ + + Map response = new HashMap<>(); + Interfaces interfaces = new Interfaces(); + + Map startResponse = startService.createStart(inputs, onapComponentSpec); + inputs = (Map>) startResponse.get("inputs"); + + interfaces.setStart((Start) startResponse.get("start")); + + response.put("interfaces", interfaces); + response.put("inputs", inputs); + return response; + } + +} + diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java new file mode 100644 index 0000000..b8da0d7 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java @@ -0,0 +1,222 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.Interfaces; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.Properties; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.common.Publishes; +import org.onap.blueprintgenerator.model.componentspec.common.Subscribes; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.TreeMap; +import java.util.List; + + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add ONAP/DMAAP/Feed/Topic Nodes + */ + + +@Service +public class NodeService { + + @Autowired + private InterfacesService interfacesService; + + @Autowired + private PolicyNodeService policyNodeService; + + @Autowired + private PgaasNodeService pgaasNodeService; + + @Autowired + private PropertiesService propertiesService; + + @Autowired + private BlueprintHelperService blueprintHelperService; + + // method to create Onap Node to include interface + public Map createOnapNode(Map> inputs, OnapComponentSpec onapComponentSpec, String override) { + + Map response = new HashMap<>(); + Node onapNode = new Node(); + + Map onapResponse = interfacesService.createInterface(inputs, onapComponentSpec); + inputs = (Map>) onapResponse.get("inputs"); + + Map interfaces = new TreeMap<>(); + interfaces.put(Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) onapResponse.get("interfaces")); + onapNode.setInterfaces(interfaces); + + onapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT); + + List> relationships = new ArrayList(); + + if(onapComponentSpec.getPolicyInfo() != null){ + List> policyRelationshipsList = policyNodeService.getPolicyRelationships(onapComponentSpec); + relationships.addAll(policyRelationshipsList); + } + + if(onapComponentSpec.getAuxilary().getDatabases() != null){ + List> pgaasRelationshipsList = pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec); + relationships.addAll(pgaasRelationshipsList); + } + + onapNode.setRelationships(relationships); + + Map propertiesResponse = propertiesService.createOnapProperties(inputs, onapComponentSpec, override); + inputs = (Map>) propertiesResponse.get("inputs"); + onapNode.setProperties((org.onap.blueprintgenerator.model.common.Properties)propertiesResponse.get("properties")); + + response.put("onapNode", onapNode); + response.put("inputs", inputs); + return response; + } + + // method to create Dmaap Node to include interface + public Map createDmaapNode(OnapComponentSpec onapComponentSpec, Map> inputs, String override) { + + Map response = new HashMap<>(); + Node dmaapNode = new Node(); + + dmaapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT_USING_DMAAP); + + Map dmaapResponse = interfacesService.createInterface(inputs, onapComponentSpec); + inputs = (Map>) dmaapResponse.get("inputs"); + + Map interfaces = new TreeMap<>(); + interfaces.put(Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) dmaapResponse.get("interfaces")); + dmaapNode.setInterfaces(interfaces); + + List> relationships = new ArrayList(); + + if(onapComponentSpec.getStreams().getPublishes() != null) { + for(Publishes publishes: onapComponentSpec.getStreams().getPublishes()) { + Map pubRelations = new LinkedHashMap(); + if(blueprintHelperService.isMessageRouterType(publishes.getType())){ + pubRelations.put("type", Constants.PUBLISH_EVENTS); + pubRelations.put("target", publishes.getConfig_key() + Constants._TOPIC); + } else if(blueprintHelperService.isDataRouterType(publishes.getType())){ + pubRelations.put("type", Constants.PUBLISH_FILES); + pubRelations.put("target", publishes.getConfig_key() + Constants._FEED); + } + relationships.add(pubRelations); + } + } + + if(onapComponentSpec.getStreams().getSubscribes() != null) { + for(Subscribes subscribes: onapComponentSpec.getStreams().getSubscribes()) { + Map subRelations = new LinkedHashMap(); + if(blueprintHelperService.isMessageRouterType(subscribes.getType())){ + subRelations.put("type", Constants.SUBSCRIBE_TO_EVENTS); + subRelations.put("target", subscribes.getConfig_key() + Constants._TOPIC); + } else if(blueprintHelperService.isDataRouterType(subscribes.getType())){ + subRelations.put("type", Constants.SUBSCRIBE_TO_FILES); + subRelations.put("target", subscribes.getConfig_key() + Constants._FEED); + } + relationships.add(subRelations); + } + } + + if(onapComponentSpec.getPolicyInfo() != null){ + List> policyRelationshipsList = policyNodeService.getPolicyRelationships(onapComponentSpec); + relationships.addAll(policyRelationshipsList); + } + + if(onapComponentSpec.getAuxilary().getDatabases() != null){ + List> pgaasRelationshipsList = pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec); + relationships.addAll(pgaasRelationshipsList); + } + + dmaapNode.setRelationships(relationships); + + Map propertiesResponse = propertiesService.createDmaapProperties(inputs, onapComponentSpec, override); + inputs = (Map>) propertiesResponse.get("inputs"); + dmaapNode.setProperties((org.onap.blueprintgenerator.model.common.Properties)propertiesResponse.get("properties")); + + response.put("dmaapNode", dmaapNode); + response.put("inputs", inputs); + return response; + } + + // method to create Feed Node for Streams + public Map createFeedNode(Map> inputs, String name){ + Map response = new HashMap<>(); + Node feedNode = new Node(); + + LinkedHashMap stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + feedNode.setType(Constants.FEED); + + org.onap.blueprintgenerator.model.common.Properties props = new org.onap.blueprintgenerator.model.common.Properties(); + GetInput topicInput = new GetInput(); + topicInput.setBpInputName(name + "_name"); + props.setFeed_name(topicInput); + props.setUseExisting(true); + inputs.put(name + "_name", stringType); + feedNode.setProperties(props); + + response.put("feedNode", feedNode); + response.put("inputs", inputs); + return response; + } + + // method to create Topic Node for Streams + public Map createTopicNode(Map> inputs, String name){ + Map response = new HashMap<>(); + Node topicNode = new Node(); + + LinkedHashMap stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + topicNode.setType(Constants.TOPIC); + + org.onap.blueprintgenerator.model.common.Properties props = new Properties(); + GetInput topicInput = new GetInput(); + topicInput.setBpInputName(name + "_name"); + props.setTopic_name(topicInput); + inputs.put(name + "_name", stringType); + topicNode.setProperties(props); + + response.put("topicNode", topicNode); + response.put("inputs", inputs); + return response; + } + + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PgaasNodeService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PgaasNodeService.java new file mode 100644 index 0000000..ff45701 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PgaasNodeService.java @@ -0,0 +1,138 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.exception.DatabasesNotFoundException; + + +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.PgaasNode; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.PgaasNodeProperties; +import org.onap.blueprintgenerator.model.common.GetAttribute; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.ArrayList; +import java.util.List; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add Pgaas Node + */ + + +@Service +public class PgaasNodeService { + + @Autowired + private BlueprintHelperService blueprintHelperService; + + // method to create Pgaas Nodes and Inputs for Databases + public void addPgaasNodesAndInputs(OnapComponentSpec onapComponentSpec, Map nodeTemplate, Map> inputs) { + Map databases = onapComponentSpec.getAuxilary().getDatabases(); + for(Map.Entry database : databases.entrySet()){ + addPgaasNode(database, nodeTemplate); + addPgaasInputs(database, inputs); + } + } + + private void addPgaasInputs(Map.Entry database, Map> inputs) { + inputs.put(database.getKey() + Constants.NAME_POSTFIX, blueprintHelperService.createStringInput( "db name", "")); + inputs.put(database.getKey() + Constants.WRITER_FQDN_POSTFIX, blueprintHelperService.createStringInput( "db writerfqdn", "")); + } + + private void addPgaasNode(Map.Entry database, Map nodeTemplate) { + PgaasNode pgaasNode = new PgaasNode(); + String dbName = database.getKey(); + pgaasNode.setType(Constants.PGAAS_NODE_TYPE); + pgaasNode.setPgaasNodeProperties(buildPgaasNodeProperties(dbName)); + nodeTemplate.put(dbName + Constants.PGAAS_NODE_NAME_POSTFIX , pgaasNode); + } + + private PgaasNodeProperties buildPgaasNodeProperties(String dbName) { + PgaasNodeProperties pgaasNodeProperties = new PgaasNodeProperties(); + + GetInput nameValue = new GetInput(); + nameValue.setBpInputName(dbName + Constants.NAME_POSTFIX); + pgaasNodeProperties.setName(nameValue); + + GetInput writerfqdnValue = new GetInput(); + writerfqdnValue.setBpInputName(dbName + Constants.WRITER_FQDN_POSTFIX); + pgaasNodeProperties.setWriterfqdn(writerfqdnValue); + + pgaasNodeProperties.setUseExisting(Constants.USE_EXISTING); + + return pgaasNodeProperties; + } + + // method to create Pgaas Node Relationships for Databases + public List> getPgaasNodeRelationships(OnapComponentSpec onapComponentSpec) { + List> relationships = new ArrayList<>(); + for(Map.Entry database : onapComponentSpec.getAuxilary().getDatabases().entrySet()){ + Map relationship = new LinkedHashMap<>(); + relationship.put("type", Constants.DB_RELATIONSHIP_TYPE); + relationship.put("target", database.getKey() + Constants.PGAAS_NODE_NAME_POSTFIX); + relationships.add(relationship); + } + return relationships; + } + + // method to create Env Variables for Databases + public Map getEnvVariables(Map databases) { + Map envVariables = new LinkedHashMap<>(); + for(Map.Entry database : databases.entrySet()){ + String name = database.getKey().toUpperCase(); + envVariables.put("<<", "*envs"); + + GetInput nameValue = new GetInput(); + nameValue.setBpInputName(name.toLowerCase() + Constants.NAME_POSTFIX); + envVariables.put(name + "_DB_NAME", nameValue); + + GetAttribute adminHostValue = buildGetAttributeValue(name.toLowerCase(), "admin", "host"); + envVariables.put( name.toUpperCase() + "_DB_ADMIN_HOST", adminHostValue); + + GetAttribute adminUserValue = buildGetAttributeValue(name.toLowerCase(), "admin", "user"); + envVariables.put( name.toUpperCase() + "_DB_ADMIN_USER", adminUserValue); + + GetAttribute adminPasswordValue = buildGetAttributeValue(name.toLowerCase(), "admin", "password"); + envVariables.put( name.toUpperCase() + "_DB_ADMIN_PASS", adminPasswordValue); + } + return envVariables; + } + + private GetAttribute buildGetAttributeValue(String dbName, String owner, String type) { + GetAttribute attribute = new GetAttribute(); + attribute.setAttribute(Arrays.asList(dbName + Constants.PGAAS_NODE_NAME_POSTFIX, owner, type)); + return attribute; + } +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PolicyNodeService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PolicyNodeService.java new file mode 100644 index 0000000..7f6c63d --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PolicyNodeService.java @@ -0,0 +1,99 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.PolicyNode; +import org.onap.blueprintgenerator.model.common.PolicyNodeProperties; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.TypePolicy; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add Policy Node + */ + + +@Service("onapPolicyNodeService") +public class PolicyNodeService { + + @Autowired + private BlueprintHelperService blueprintHelperService; + + // Method to add Policy Nodes and Inputs + public void addPolicyNodesAndInputs(OnapComponentSpec onapComponentSpec, Map nodeTemplate, Map> inputs) { + List policyList = onapComponentSpec.getPolicyInfo().getTypePolicyList(); + for(TypePolicy policy: policyList){ + addPolicyNodesToNodeTemplate(policy, nodeTemplate); + addPolicyInputs(policy, inputs); + } + } + + private void addPolicyInputs(TypePolicy policy, Map> inputs) { + String defaultValue = policy.getPolicy_id(); + defaultValue = defaultValue != null ? defaultValue : ""; + inputs.put(policy.getNode_label() + "_policy_id", blueprintHelperService.createStringInput("policy_id", defaultValue)); + } + + private void addPolicyNodesToNodeTemplate(TypePolicy policy, Map nodeTemplate) { + PolicyNode policyNode = new PolicyNode(); + policyNode.setType(Constants.POLICY_NODE_TYPE); + policyNode.setPolicyNodeProperties(getPolicyNodeProperties(policy)); + nodeTemplate.put(policy.getNode_label(), policyNode); + } + + private PolicyNodeProperties getPolicyNodeProperties(TypePolicy policy) { + PolicyNodeProperties policyNodeProperties = new PolicyNodeProperties(); + GetInput policyIdGetInput = new GetInput(); + policyIdGetInput.setBpInputName(policy.getNode_label() + "_policy_id"); + policyNodeProperties.setPolicyId(policyIdGetInput); + policyNodeProperties.setPolicyModelId(policy.getPolicy_model_id()); + return policyNodeProperties; + } + + // Method to add Policy Relationships + public List> getPolicyRelationships(OnapComponentSpec onapComponentSpec) { + List> relationships = new ArrayList<>(); + List policyList = onapComponentSpec.getPolicyInfo().getTypePolicyList(); + for(TypePolicy policy: policyList){ + Map relationship = new LinkedHashMap<>(); + relationship.put("type", Constants.POLICY_RELATIONSHIP_TYPE); + relationship.put("target", policy.getNode_label()); + relationships.add(relationship); + } + return relationships; + } +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java new file mode 100644 index 0000000..e858d88 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java @@ -0,0 +1,259 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.Appconfig; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.ResourceConfig; +import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.common.Publishes; +import org.onap.blueprintgenerator.model.componentspec.common.Subscribes; +import org.onap.blueprintgenerator.model.dmaap.Streams; +import org.onap.blueprintgenerator.model.dmaap.TlsInfo; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.onap.blueprintgenerator.service.dmaap.StreamsService; +import org.onap.blueprintgenerator.model.common.Properties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; +import java.util.List; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to create Properties Node + */ + + + +@Service("onapPropertiesService") +public class PropertiesService { + + @Autowired + private AppConfigService appConfigService; + + @Autowired + private ResourceConfigService resourceConfigService; + + @Autowired + private StreamsService streamsService; + + @Autowired + private ExternalTlsInfoFactoryService externalTlsInfoFactoryService; + + @Autowired + private BlueprintHelperService blueprintHelperService; + + // Method to create ONAP properties + public Map createOnapProperties(Map> inputs, OnapComponentSpec onapComponentSpec, String override) { + Map response = new HashMap<>(); + org.onap.blueprintgenerator.model.common.Properties properties = new org.onap.blueprintgenerator.model.common.Properties(); + + GetInput image = new GetInput(); + image.setBpInputName("image"); + properties.setImage(image); + + LinkedHashMap img = new LinkedHashMap<>(); + inputs.put("image", blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri())); + + + GetInput location = new GetInput(); + location.setBpInputName("location_id"); + properties.setLocation_id(location); + + LinkedHashMap locMap = new LinkedHashMap(); + inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE)); + + properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info()); + + GetInput replica = new GetInput(); + replica.setBpInputName("replicas"); + properties.setReplicas(replica); + + LinkedHashMap replicas = blueprintHelperService.createIntegerInput("number of instances", 1); + inputs.put("replicas", replicas); + + OnapAuxilary onapAuxilary = onapComponentSpec.getAuxilary(); + + properties.setDocker_config(onapAuxilary); + + Map appConfigResponse = appConfigService.createAppconfig(inputs, onapComponentSpec, override, false); + inputs = (Map>) appConfigResponse.get("inputs"); + properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig")); + + GetInput always_pull_image = new GetInput(); + always_pull_image.setBpInputName("always_pull_image"); + + properties.setAlways_pull_image(always_pull_image); + + LinkedHashMap inputAlwaysPullImage = blueprintHelperService.createBooleanInput("Set to true if the image should always be pulled",true); + inputs.put("always_pull_image", inputAlwaysPullImage); + + String sType = onapComponentSpec.getSelf().getName(); + sType = sType.replace('.', '-'); + properties.setService_component_type(sType); + + Map tls_info = onapComponentSpec.getAuxilary().getTls_info(); + if(tls_info != null) { + addTlsInfo(onapComponentSpec, inputs, properties); + if (tls_info.get(Constants.USE_EXTERNAL_TLS_FIELD) != null) { + inputs.putAll(addExternalTlsInfo(onapComponentSpec,properties)); + } + } + + Map resourceConfigResponse = resourceConfigService.createResourceConfig(inputs, onapComponentSpec.getSelf().getName()); + inputs = (Map>) resourceConfigResponse.get("inputs"); + properties.setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig")); + + response.put("properties", properties); + response.put("inputs", inputs); + return response; + } + + // Method to create Dmaap properties + public Map createDmaapProperties(Map> inputs, OnapComponentSpec onapComponentSpec, String override) { + Map response = new HashMap<>(); + org.onap.blueprintgenerator.model.common.Properties properties = new org.onap.blueprintgenerator.model.common.Properties(); + + GetInput image = new GetInput(); + image.setBpInputName("tag_version"); + properties.setImage(image); + + LinkedHashMap img = new LinkedHashMap<>(); + inputs.put("tag_version", blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri())); + + GetInput location = new GetInput(); + location.setBpInputName("location_id"); + properties.setLocation_id(location); + + LinkedHashMap locMap = new LinkedHashMap(); + inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE)); + + properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info()); + + String sType = onapComponentSpec.getSelf().getName(); + sType = sType.replace('.', '-'); + properties.setService_component_type(sType); + + Map tls_info = onapComponentSpec.getAuxilary().getTls_info(); + if(tls_info != null) { + addTlsInfo(onapComponentSpec, inputs, properties); + if (tls_info.get(Constants.USE_EXTERNAL_TLS_FIELD) != null) { + inputs.putAll(addExternalTlsInfo(onapComponentSpec,properties)); + } + } + + GetInput replica = new GetInput(); + replica.setBpInputName("replicas"); + properties.setReplicas(replica); + + LinkedHashMap rep = blueprintHelperService.createIntegerInput( "number of instances", 1); + inputs.put("replicas", rep); + + OnapAuxilary onapAuxilary = onapComponentSpec.getAuxilary(); + + properties.setDocker_config(onapAuxilary); + + Map appConfigResponse = appConfigService.createAppconfig(inputs, onapComponentSpec, override, true); + inputs = (Map>) appConfigResponse.get("inputs"); + properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig")); + + + List pubStreams = new ArrayList(); + if(onapComponentSpec.getStreams() != null) { + if (onapComponentSpec.getStreams().getPublishes() != null) { + for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) { + if (blueprintHelperService.isMessageRouterType(publishes.getType())) { + String topic = publishes.getConfig_key() + Constants._TOPIC; + Map streamsMessageRouterResponse = streamsService.createStreams(inputs, topic, publishes.getType(), publishes.getConfig_key(), publishes.getRoute(), 'p'); + inputs = (Map>) streamsMessageRouterResponse.get("inputs"); + pubStreams.add((Streams) streamsMessageRouterResponse.get("streams")); + } else if (blueprintHelperService.isDataRouterType(publishes.getType())) { + String feed = publishes.getConfig_key() + Constants._FEED; + Map streamsDataRouterResponse = streamsService.createStreams(inputs, feed, publishes.getType(), publishes.getConfig_key(), publishes.getRoute(), 'p'); + inputs = (Map>) streamsDataRouterResponse.get("inputs"); + pubStreams.add((Streams) streamsDataRouterResponse.get("streams")); + } + } + } + } + + ArrayList subStreams = new ArrayList(); + if(onapComponentSpec.getStreams() != null) { + if (onapComponentSpec.getStreams().getSubscribes() != null) { + for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) { + if (blueprintHelperService.isMessageRouterType(subscribes.getType())) { + String topic = subscribes.getConfig_key() + Constants._TOPIC; + Map streamsMessageRouterResponse = streamsService.createStreams(inputs, topic, subscribes.getType(), subscribes.getConfig_key(), subscribes.getRoute(), 's'); + inputs = (Map>) streamsMessageRouterResponse.get("inputs"); + subStreams.add((Streams) streamsMessageRouterResponse.get("streams")); + } else if (blueprintHelperService.isDataRouterType(subscribes.getType())) { + String feed = subscribes.getConfig_key() + Constants._FEED; + Map streamsDataRouterResponse = streamsService.createStreams(inputs, feed, subscribes.getType(), subscribes.getConfig_key(), subscribes.getRoute(), 's'); + inputs = (Map>) streamsDataRouterResponse.get("inputs"); + subStreams.add((Streams) streamsDataRouterResponse.get("streams")); + } + } + } + } + + if(!pubStreams.isEmpty()) + properties.setStreams_publishes(pubStreams); + + if(!subStreams.isEmpty()) + properties.setStreams_subscribes(subStreams); + + Map resourceConfigResponse = resourceConfigService.createResourceConfig(inputs, onapComponentSpec.getSelf().getName()); + inputs = (Map>) resourceConfigResponse.get("inputs"); + properties.setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig")); + + response.put("properties", properties); + response.put("inputs", inputs); + return response; + } + + private void addTlsInfo(OnapComponentSpec onapComponentSpec, Map> inputs, Properties properties) { + TlsInfo tlsInfo = new TlsInfo(); + tlsInfo.setCertDirectory((String) onapComponentSpec.getAuxilary().getTls_info().get("cert_directory")); + GetInput useTLSFlag = new GetInput(); + useTLSFlag.setBpInputName("use_tls"); + tlsInfo.setUseTls(useTLSFlag); + properties.setTls_info(tlsInfo); + LinkedHashMap useTlsFlagInput = blueprintHelperService.createBooleanInput("flag to indicate tls enable/disable",onapComponentSpec.getAuxilary().getTls_info().get("use_tls")); + inputs.put("use_tls", useTlsFlagInput); + } + + private Map> addExternalTlsInfo(OnapComponentSpec onapComponentSpec, Properties properties) { + properties.setExternal_cert(externalTlsInfoFactoryService.createFromComponentSpec(onapComponentSpec)); + return externalTlsInfoFactoryService.createInputListFromComponentSpec(onapComponentSpec); + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/QuotationService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/QuotationService.java new file mode 100644 index 0000000..c79ec56 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/QuotationService.java @@ -0,0 +1,59 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.springframework.stereotype.Service; + +import java.util.LinkedHashMap; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to set Quotations of generated Blueprint + */ + + +@Service +public class QuotationService { + + // Method to add Quotes for String Types + public OnapBlueprint setQuotations(OnapBlueprint bp) { + for(String s: bp.getInputs().keySet()) { + LinkedHashMap temp = bp.getInputs().get(s); + if(temp.get("type") == "string") { + String def = (String) temp.get("default"); + if(def != null){ + def = def.replaceAll("\"$", "").replaceAll("^\"", ""); + } + def = '"' + def + '"'; + temp.replace("default", def); + bp.getInputs().replace(s, temp); + } + } + return bp; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ResourceConfigService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ResourceConfigService.java new file mode 100644 index 0000000..7b03372 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/ResourceConfigService.java @@ -0,0 +1,98 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.ResourceConfig; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add ResourceConfig + */ + + +@Service("onapResourceConfigService") +public class ResourceConfigService { + + @Autowired + private BlueprintHelperService blueprintHelperService; + + //Method to create Resouce Config for properties + public Map createResourceConfig(Map> inputs, String name){ + Map response = new HashMap<>(); + ResourceConfig resourceConfig = new ResourceConfig(); + + LinkedHashMap memoryLimit = blueprintHelperService.createStringInput(Constants.MEMORY_LIMIT_128Mi); + + LinkedHashMap cpuLimit = blueprintHelperService.createStringInput( Constants.CPU_LIMIT_250m); + + name = blueprintHelperService.getNamePrefix(name); + + Map lim = new TreeMap<>(); + + GetInput cpu = new GetInput(); + cpu.setBpInputName(name + Constants.CPU_LIMIT); + lim.put("cpu", cpu); + + GetInput memL = new GetInput(); + memL.setBpInputName(name + Constants.MEMORY_LIMIT); + lim.put("memory", memL); + + inputs.put(name + Constants.CPU_LIMIT, cpuLimit); + inputs.put(name + Constants.MEMORY_LIMIT, memoryLimit); + + resourceConfig.setLimits(lim); + + Map req = new TreeMap<>(); + + GetInput cpuR = new GetInput(); + cpuR.setBpInputName(name + Constants.CPU_REQUEST); + req.put("cpu", cpuR); + + GetInput memR = new GetInput(); + memR.setBpInputName(name + Constants.MEMORY_REQUEST); + req.put("memory", memR); + + inputs.put(name + Constants.CPU_REQUEST, cpuLimit); + inputs.put(name + Constants.MEMORY_REQUEST, memoryLimit); + + resourceConfig.setRequests(req); + + response.put("resourceConfig", resourceConfig); + response.put("inputs", inputs); + return response; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/StartInputsService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/StartInputsService.java new file mode 100644 index 0000000..20c3656 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/StartInputsService.java @@ -0,0 +1,97 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.StartInputs; +import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add Start Inputs Node under Start + */ + + +@Service +public class StartInputsService { + + @Autowired + private PgaasNodeService pgaasNodeService; + + //Method to create Start Inputs for Start in Interfaces + public Map createStartInputs(Map> inputs, OnapComponentSpec onapComponentSpec){ + + Map response = new HashMap<>(); + StartInputs startInputs = new StartInputs(); + + int count = 0; + List portList = new ArrayList(); + OnapAuxilary aux = onapComponentSpec.getAuxilary(); + + if (aux.getPorts() != null) { + for(Object p : aux.getPorts()) { + String[] ports = p.toString().split(":"); + portList.add(String.format("concat: [\"%s:\", {get_input: external_port_%d}]" , ports[0], count)); + + LinkedHashMap portType = new LinkedHashMap(); + portType.put("type", "string"); + portType.put("default", ports[1]); + inputs.put("external_port_" + count, portType); + count++; + } + } + + startInputs.setPorts(portList); + + LinkedHashMap envMap = new LinkedHashMap(); + if(onapComponentSpec.getAuxilary().getDatabases() != null){ + Map envVars = pgaasNodeService.getEnvVariables(onapComponentSpec.getAuxilary().getDatabases()); + startInputs.setEnvs(envVars); + envMap.put("default", "&envs {}"); + } + else { + GetInput env = new GetInput(); + env.setBpInputName("envs"); + startInputs.setEnvs(env); + envMap.put("default", "{}"); + } + inputs.put("envs", envMap); + + response.put("startInputs", startInputs); + response.put("inputs", inputs); + return response; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/StartService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/StartService.java new file mode 100644 index 0000000..3fbfdb1 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/StartService.java @@ -0,0 +1,65 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + + +import org.onap.blueprintgenerator.model.common.Start; +import org.onap.blueprintgenerator.model.common.StartInputs; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add Start Node + */ + + +@Service +public class StartService { + + @Autowired + private StartInputsService startInputsService; + + // Method to create Start for Interfaces + public Map createStart(Map> inputs, OnapComponentSpec onapComponentSpec) { + Map response = new HashMap<>(); + Start start = new Start(); + + Map startInputsResponse = startInputsService.createStartInputs(inputs, onapComponentSpec); + inputs = (Map>) startInputsResponse.get("inputs"); + start.setInputs((StartInputs) startInputsResponse.get("startInputs")); + + response.put("start", start); + response.put("inputs", inputs); + return response; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintService.java new file mode 100644 index 0000000..002bd6c --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintService.java @@ -0,0 +1,144 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.dmaap; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.exception.BlueprintException; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.common.Publishes; +import org.onap.blueprintgenerator.model.componentspec.common.Subscribes; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.onap.blueprintgenerator.service.base.BlueprintService; +import org.onap.blueprintgenerator.service.common.ImportsService; +import org.onap.blueprintgenerator.service.common.NodeService; +import org.onap.blueprintgenerator.service.common.PgaasNodeService; +import org.onap.blueprintgenerator.service.common.PolicyNodeService; +import org.onap.blueprintgenerator.service.common.QuotationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Service to create DMAAP Blueprint + */ + +@Service +public class DmaapBlueprintService extends BlueprintService { + + @Autowired + protected ImportsService importsService; + + @Autowired + private NodeService nodeService; + + @Autowired + private PolicyNodeService policyNodeService; + + @Autowired + private PgaasNodeService pgaasNodeService; + + @Autowired + private QuotationService quotationService; + + @Autowired + private BlueprintHelperService blueprintHelperService; + + // method to generate Dmaap Blueprint + public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) { + try { + OnapBlueprint blueprint = new OnapBlueprint(); + blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION); + blueprint.setDescription(onapComponentSpec.getSelf().getDescription()); + + Map> inputs = new TreeMap<>(); + + //if (!"".equals(input.getImportPath())) + if (!StringUtils.isEmpty(input.getImportPath()) ) + blueprint.setImports(importsService.createImportsFromFile(input.getImportPath())); + else + blueprint.setImports(importsService.createImports(input.getBpType())); + + Map nodeTemplate = new TreeMap(); + + Map dmaapNodeResponse = nodeService.createDmaapNode(onapComponentSpec, inputs, input.getServiceNameOverride()); + inputs = (Map>) dmaapNodeResponse.get("inputs"); + nodeTemplate.put(onapComponentSpec.getSelf().getName(), (Node) dmaapNodeResponse.get("dmaapNode")); + + if (onapComponentSpec.getStreams() != null) { + if (onapComponentSpec.getStreams().getPublishes() != null) { + for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) { + if (blueprintHelperService.isMessageRouterType(publishes.getType())) { + String topic = publishes.getConfig_key() + Constants._TOPIC; + Map topicNodeResponse = nodeService.createTopicNode(inputs, topic); + inputs = (Map>) topicNodeResponse.get("inputs"); + nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode")); + } else if (blueprintHelperService.isDataRouterType(publishes.getType())) { + String feed = publishes.getConfig_key() + Constants._FEED; + Map feedNodeResponse = nodeService.createFeedNode(inputs, feed); + inputs = (Map>) feedNodeResponse.get("inputs"); + nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode")); + } + } + } + if (onapComponentSpec.getStreams().getSubscribes() != null) { + for (Subscribes s : onapComponentSpec.getStreams().getSubscribes()) { + if (blueprintHelperService.isMessageRouterType(s.getType())) { + String topic = s.getConfig_key() + Constants._TOPIC; + Map topicNodeResponse = nodeService.createTopicNode(inputs, topic); + inputs = (Map>) topicNodeResponse.get("inputs"); + nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode")); + } else if (blueprintHelperService.isDataRouterType(s.getType())) { + String feed = s.getConfig_key() + Constants._FEED; + Map feedNodeResponse = nodeService.createFeedNode(inputs, feed); + inputs = (Map>) feedNodeResponse.get("inputs"); + nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode")); + } + } + } + } + + if (onapComponentSpec.getPolicyInfo() != null) + policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); + + if (onapComponentSpec.getAuxilary() != null && onapComponentSpec.getAuxilary().getDatabases() != null) + pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); + + blueprint.setNode_templates(nodeTemplate); + blueprint.setInputs(inputs); + return quotationService.setQuotations(blueprint); + } catch (Exception ex) { + throw new BlueprintException("Unable to create ONAP DMAAP Blueprint Object from given input parameters", ex); + } + } +} \ No newline at end of file diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/StreamsService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/StreamsService.java new file mode 100644 index 0000000..16687fc --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/StreamsService.java @@ -0,0 +1,104 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.dmaap; + +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.dmaap.Streams; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Service to create Streams + */ + + +@Service +public class StreamsService { + + @Autowired + private BlueprintHelperService blueprintHelperService; + + //Methos to create streams for Dmaap Blueprint + public Map createStreams(Map> inputs, String name, String type, String key, String route, char o){ + Map response = new HashMap<>(); + Streams streams = new Streams(); + + LinkedHashMap stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + streams.setName(name); + streams.setType(type); + + GetInput location = new GetInput(); + location.setBpInputName(key + "_" + name + "_location"); + inputs.put(key + "_" + name + "_location", stringType); + streams.setLocation(location); + + if(blueprintHelperService.isDataRouterType(type)) { + if('s' == o) { + GetInput username = new GetInput(); + username.setBpInputName(key + "_" + name + "_username"); + streams.setUsername(username); + inputs.put(key + "_" + name + "_username", stringType); + + GetInput password = new GetInput(); + password.setBpInputName(key + "_" + name + "_password"); + streams.setPassword(password); + inputs.put(key + "_" + name + "_password", stringType); + + GetInput priviliged = new GetInput(); + priviliged.setBpInputName(key + "_" + name + "_priviliged"); + streams.setPrivileged(priviliged); + inputs.put(key + "_" + name + "_priviliged", stringType); + + GetInput decompress = new GetInput(); + decompress.setBpInputName(key + "_" + name + "_decompress"); + streams.setDecompress(decompress); + inputs.put(key + "_" + name + "_decompress", stringType); + + streams.setRoute(route); + streams.setScheme("https"); + } + + + } else { + GetInput client = new GetInput(); + client.setBpInputName(key + "_" + name + "_client_role"); + streams.setClient_role(client); + inputs.put(key + "_" + name + "_client_role", stringType); + } + response.put("streams", streams); + response.put("inputs", inputs); + return response; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/policycreate/service/PolicyModelNodeService.java b/mod/bpgenerator/onap/src/main/java/org/onap/policycreate/service/PolicyModelNodeService.java new file mode 100644 index 0000000..05dbcae --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/policycreate/service/PolicyModelNodeService.java @@ -0,0 +1,150 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.policycreate.service; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.componentspec.common.EntrySchema; +import org.onap.blueprintgenerator.model.componentspec.common.Parameters; +import org.onap.blueprintgenerator.model.componentspec.common.PolicySchema; +import org.onap.policycreate.model.PolicyModelNode; +import org.onap.policycreate.model.PolicyProperties; +import org.springframework.stereotype.Service; + +import java.util.Map; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.TreeMap; +import java.util.List; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * To create Node Type, Data Type and Translate Entry Schema for Policy Model Node + */ + + +@Service("onapPolicyModelNodeService") +public class PolicyModelNodeService { + + // Method to create Nodes for Policy + public Map creatNodeType(String policyName, Parameters[] params) { + String hasEntrySchema = ""; + Map response = new HashMap<>(); + PolicyModelNode policyModelNode = new PolicyModelNode(); + + Map props = new TreeMap<>(); + for(Parameters p: params) { + if(p.getPolicy_group() != null && p.getPolicy_group().equals(policyName)) { + String name = p.getName(); + String type = p.getType(); + PolicyProperties polProps = new PolicyProperties(); + if(p.getPolicy_schema() != null) { + polProps.setType("map"); + ArrayList entrySchema = new ArrayList(); + entrySchema.add("type: onap.datatypes." + name); + polProps.setEntry_schema(entrySchema); + hasEntrySchema = name; + props.put(name, polProps); + } + else { + polProps.setType(type); + props.put(name, polProps); + } + } + } + policyModelNode.setDerived_from(Constants.TOSCA_DATATYPES_ROOT); + policyModelNode.setProperties(props); + response.put("hasEntrySchema", hasEntrySchema); + response.put("policyModelNode", policyModelNode); + return response; + } + + // Method to create Data Types for Policy + public Map createDataTypes(String param, Parameters[] parameters){ + Map dataType = new TreeMap<>(); + PolicyModelNode node = new PolicyModelNode(); + node.setDerived_from(Constants.TOSCA_DATATYPES_ROOT); + + Map properties = new TreeMap<>(); + Parameters par = new Parameters(); + for(Parameters p: parameters) { + if(param.equals(p.getName())) { + par = p; + break; + } + } + + for(PolicySchema pol: par.getPolicy_schema()) { + if(pol.getEntry_schema() != null) { + PolicyProperties prop =new PolicyProperties(); + prop.setType("map"); + ArrayList schema = new ArrayList(); + schema.add("type: onap.datatypes." + pol.getName()); + prop.setEntry_schema(schema); + properties.put(pol.getName(), prop); + dataType = translateEntrySchema(dataType, pol.getEntry_schema(), pol.getName()); + } + else { + PolicyProperties prop = new PolicyProperties(); + prop.setType(pol.getType()); + properties.put(pol.getName(), prop); + } + } + + node.setProperties(properties); + dataType.put("onap.datatypes." + param, node); + return dataType; + } + + private Map translateEntrySchema(Map dataType, EntrySchema[] entry, String name){ + Map data = dataType; + PolicyModelNode node = new PolicyModelNode(); + node.setDerived_from(Constants.TOSCA_NODES_ROOT); + Map properties = new TreeMap<>(); + + for(EntrySchema e: entry) { + if(e.getEntry_schema() != null) { + PolicyProperties prop = new PolicyProperties(); + prop.setType("list"); + List schema = new ArrayList<>(); + schema.add("type: onap.datatypes." + e.getName()); + prop.setEntry_schema(schema); + properties.put(e.getName(), prop); + data = translateEntrySchema(data, e.getEntry_schema(), e.getName()); + node.setProperties(properties); + } else { + PolicyProperties prop = new PolicyProperties(); + prop.setType(e.getType()); + properties.put(e.getName(), prop); + node.setProperties(properties); + } + } + + dataType.put("onap.datatypes." + name, node); + return data; + } + +} + diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/policycreate/service/PolicyModelService.java b/mod/bpgenerator/onap/src/main/java/org/onap/policycreate/service/PolicyModelService.java new file mode 100644 index 0000000..bbc6259 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/policycreate/service/PolicyModelService.java @@ -0,0 +1,105 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.policycreate.service; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.componentspec.common.Parameters; +import org.onap.policycreate.exception.PolicyCreateException; +import org.onap.policycreate.model.PolicyModel; +import org.onap.policycreate.model.PolicyModelNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Service for Policy Model to create Policy Models, Policy Group Names and Convert Policy to Yaml + */ + + +@Service("onapPolicyModelService") +public class PolicyModelService { + + @Qualifier("yamlObjectMapper") + @Autowired + protected ObjectMapper yamlObjectMapper; + + @Autowired + private PolicyModelNodeService policyModelNodeService; + + // Method to create Policy Models + public void createPolicyModels(Parameters[] params, String filePath) { + try { + List policyGroups = getPolicyGroupNames(params); + for (String s : policyGroups) { + PolicyModel model = new PolicyModel(); + model.setTosca_definition_version(Constants.TOSCA_SIMPLE_YAML); + + Map response = policyModelNodeService.creatNodeType(s, params); + String nodeTypeName = "onap.policy." + s; + Map nodeType = new TreeMap<>(); + nodeType.put(nodeTypeName, (PolicyModelNode) response.get("policyModelNode")); + model.setNode_types(nodeType); + + if (!"".equals(response.get("hasEntrySchema"))) + model.setData_types(policyModelNodeService.createDataTypes((String) response.get("hasEntrySchema"), params)); + policyModelToYaml(filePath, model, s); + } + } catch (Exception ex) { + throw new PolicyCreateException("Unable to create Policies from given input parameters", ex); + } + } + + private List getPolicyGroupNames(Parameters[] params) { + List names = new ArrayList<>(); + for (Parameters p : params) { + if (p.isPolicy_editable()) { + if (names.isEmpty()) { + names.add(p.getPolicy_group()); + } else if (!names.contains(p.getPolicy_group())) { + names.add(p.getPolicy_group()); + } + } + } + return names; + } + + private void policyModelToYaml(String path, PolicyModel model, String name) throws IOException { + File outputFile = new File(path, name + ".yml"); + outputFile.getParentFile().mkdirs(); + yamlObjectMapper.writeValue(outputFile, model); + } + +} + diff --git a/mod/bpgenerator/onap/src/main/resources/application.properties b/mod/bpgenerator/onap/src/main/resources/application.properties new file mode 100644 index 0000000..3b70df6 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/resources/application.properties @@ -0,0 +1,36 @@ +# +# /* +# * ============LICENSE_START======================================================= +# * org.onap.dcae +# * ================================================================================ +# * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. +# * ================================================================================ +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * ============LICENSE_END========================================================= +# */ +# +# + +spring.main.banner-mode=off +spring.output.ansi.enabled=ALWAYS + +imports.onap.types=https://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml +imports.onap.K8s.plugintypes=plugin:k8splugin?version=3.4.2 +imports.onap.K8s.dcaepolicyplugin=plugin:dcaepolicyplugin?version=2.4.0 + +imports.dmaap.dmaapplugin=plugin:dmaap?version=1.5.0 + +import.Postgres=plugin:pgaas?version=1.3.0 +import.Clamp=plugin:clamppolicyplugin?version=1.1.0 + + diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTestSuite.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTestSuite.java new file mode 100644 index 0000000..b19a823 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTestSuite.java @@ -0,0 +1,40 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.test; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Test Suite for Test Cases + */ + + +@RunWith(Suite.class) +@Suite.SuiteClasses({ OnapComponentSpecTest.class, OnapBlueprintServiceTest.class,ExternalCertificateParametersFactoryServiceTest.class/*, BlueprintJarComparatorTest.class*/}) +public class BlueprintGeneratorTestSuite { +} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTests.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTests.java new file mode 100644 index 0000000..ea324da --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTests.java @@ -0,0 +1,109 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.test; + +import org.onap.blueprintgenerator.BlueprintGeneratorMainApplication; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.service.OnapBlueprintService; +import org.onap.blueprintgenerator.service.common.ComponentSpecService; +import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintService; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.onap.policycreate.service.PolicyModelService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Test Cases + */ + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = BlueprintGeneratorMainApplication.class, initializers = ConfigFileApplicationContextInitializer.class) +@TestPropertySource( + properties = { + "ves=ves.json", + "testImports=testImports.yaml", + "useTlsTrueAndUseExternalTlsTrueTest=testComponentSpec_withTlsTrueAndExternalTlsTrue.json", + "useTlsFalseAndUseExternalTlsFalseTest=testComponentSpec_withTlsFalseAndExternalTlsFalse.json", + "useTlsTrueAndNoExternalTlsFlagTest=testComponentSpec_withTlsTrueAndNoExternalTls.json", + "noTlsInfo=testComponentSpec_withoutTlsInfo.json" + } +) +@Ignore +public class BlueprintGeneratorTests { + + @Qualifier("objectMapper") + @Autowired + protected ObjectMapper objectMapper; + + @Qualifier("yamlObjectMapper") + @Autowired + protected ObjectMapper yamlObjectMapper; + + @Value("${ves}") + protected String ves; + + @Value("${testImports}") + protected String testImports; + + @Value("${useTlsTrueAndUseExternalTlsTrueTest}") + protected String useTlsTrueAndUseExternalTlsTrueTest; + + @Value("${useTlsFalseAndUseExternalTlsFalseTest}") + protected String useTlsFalseAndUseExternalTlsFalseTest; + + @Value("${useTlsTrueAndNoExternalTlsFlagTest}") + protected String useTlsTrueAndNoExternalTlsFlagTest; + + @Value("${noTlsInfo}") + protected String noTlsInfo; + + @Autowired + protected ComponentSpecService onapComponentSpecService; + + @Autowired + protected DmaapBlueprintService dmaapBlueprintService; + + @Autowired + protected OnapBlueprintService onapBlueprintService; + + @Autowired + protected PolicyModelService policyModelService; + + @Autowired + protected OnapTestUtils onapTestUtils; + + protected OnapComponentSpec onapComponentSpec = null; + +} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintJarComparatorTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintJarComparatorTest.java new file mode 100644 index 0000000..d10d3ff --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintJarComparatorTest.java @@ -0,0 +1,115 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + + +package org.onap.blueprintgenerator.test; + +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.jupiter.api.Order; +import org.junit.runners.MethodSorters; +import org.onap.blueprintgenerator.test.BlueprintGeneratorTests; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; + + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Bueprint Jar Comparision with Previos version to make sure Bps are not broken with new changes + */ + + +@Ignore +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class BlueprintJarComparatorTest extends BlueprintGeneratorTests { + + private String previousJarVersion = "0.1"; + private String latestJarVersion = "1.0"; + private String previousVersion = "0_1"; + private String latestVersion = "1_0"; + private String latestJarPath = Paths.get("target").toAbsolutePath().toString() + "\\"; + private String previousJarPath = Paths.get("src", "test", "resources", "archives").toAbsolutePath().toString() + "\\"; + private String inputPath = Paths.get("src", "test", "resources", "componentspecs").toAbsolutePath().toString() + "\\"; + private String inputPolicyPath = Paths.get("src", "test", "resources", "policyjson").toAbsolutePath().toString() + "\\"; + private String outputPath = Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString() + "\\"; + private String previousJar = "onap-blueprint-generator-" + previousJarVersion + ".jar"; + private String latestJar = "onap-blueprint-generator-" + latestJarVersion + ".jar"; + + @Test + @Order(value=1) + public void filesCleanup() throws IOException { + FileUtils.deleteDirectory(new File(outputPath)); + } + + @Test + public void jarTestVeswithDmaapK8s() throws IOException, InterruptedException { + String inputFileName = ves; + String outputFileName = "dcae-ves-collector-dmaap-"; + String inputImportsFileName = testImports; + + String previousJarCommand = "java -jar " + previousJarPath + previousJar + " app ONAP -i " + inputPath + inputFileName + " -p " + outputPath + + " -n " + outputFileName + previousVersion + " -t " + inputPath + inputImportsFileName + " -d"; + Runtime.getRuntime().exec(previousJarCommand); + + String latestJarCommand = "java -jar " + latestJarPath + latestJar + " app ONAP -i " + inputPath + inputFileName + " -p " + outputPath + + " -n " + outputFileName + latestVersion + " -t " + inputPath + inputImportsFileName + " -d"; + Runtime.getRuntime().exec(latestJarCommand); + + Thread.sleep(8000); + + Assert.assertEquals("The BluePrint files (" + outputFileName + ") for " + inputFileName + " with -m option don't match!", + FileUtils.readFileToString(new File(outputPath + outputFileName + previousVersion + ".yaml"), "utf-8"), + FileUtils.readFileToString(new File(outputPath + outputFileName + latestVersion + ".yaml"), "utf-8")); + } + + @Test + public void jarTestVeswithoutDmaapK8s() throws IOException, InterruptedException { + String inputFileName = ves; + String outputFileName = "dcae-ves-collector-"; + String inputImportsFileName = testImports; + + String previousJarCommand = "java -jar " + previousJarPath + previousJar + " app ONAP -i " + inputPath + inputFileName + " -p " + outputPath + + " -n " + outputFileName + previousVersion + " -t " + inputPath + inputImportsFileName ; + Runtime.getRuntime().exec(previousJarCommand); + + String latestJarCommand = "java -jar " + latestJarPath + latestJar + " app ONAP -i " + inputPath + inputFileName + " -p " + outputPath + + " -n " + outputFileName + latestVersion + " -t " + inputPath + inputImportsFileName ; + Runtime.getRuntime().exec(latestJarCommand); + + Thread.sleep(8000); + + Assert.assertEquals("The BluePrint files (" + outputFileName + ") for " + inputFileName + " with -m option dont match!", + FileUtils.readFileToString(new File(outputPath + outputFileName + previousVersion + ".yaml"), "utf-8"), + FileUtils.readFileToString(new File(outputPath + outputFileName + latestVersion + ".yaml"), "utf-8")); + } + + +} + diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/ExternalCertificateParametersFactoryServiceTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/ExternalCertificateParametersFactoryServiceTest.java new file mode 100644 index 0000000..021bc49 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/ExternalCertificateParametersFactoryServiceTest.java @@ -0,0 +1,61 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia Intellectual Property. All rights reserved. + Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.test; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.ExternalCertificateParameters; +import org.onap.blueprintgenerator.service.common.ExternalCertificateParametersFactoryService; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + + +import java.util.LinkedHashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.onap.blueprintgenerator.constants.Constants.COMMON_NAME_FIELD; +import static org.onap.blueprintgenerator.constants.Constants.SANS_FIELD; + +public class ExternalCertificateParametersFactoryServiceTest extends BlueprintGeneratorTests{ + + private static final String PREFIXED_COMMON_NAME_FIELD = Constants.INPUT_PREFIX + COMMON_NAME_FIELD; + private static final String PREFIXED_SANS_FIELD = Constants.INPUT_PREFIX + SANS_FIELD; + private static final String DEFAULT = "default"; + + @Autowired + private ExternalCertificateParametersFactoryService externalCertificateParametersFactoryService; + + @Test + public void shouldCreateExternalCertificatePropertiesObject() { + + ExternalCertificateParameters result = externalCertificateParametersFactoryService.create(); + assertEquals(result.getCommonName().getBpInputName(), PREFIXED_COMMON_NAME_FIELD); + assertEquals(result.getSans().getBpInputName(), PREFIXED_SANS_FIELD); + } + + @Test + public void shouldCreateCorrectInputListWithDefaultValuesTakenFromComponentSpec() { + + Map> result = externalCertificateParametersFactoryService.createInputList(); + assertEquals(Constants.DEFAULT_COMMON_NAME, result.get(PREFIXED_COMMON_NAME_FIELD).get(DEFAULT)); + assertEquals(Constants.DEFAULT_SANS, result.get(PREFIXED_SANS_FIELD).get(DEFAULT)); + } +} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintServiceTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintServiceTest.java new file mode 100644 index 0000000..351f94e --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintServiceTest.java @@ -0,0 +1,257 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.test; + +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.onap.blueprintgenerator.model.common.Properties; +import org.junit.Test; +import org.junit.jupiter.api.DisplayName; +import picocli.CommandLine; + +import java.io.IOException; +import java.io.PrintStream; +import java.nio.file.Paths; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertArrayEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP Blueprint Test Cases for ONAP and DMAAP + */ + + +public class OnapBlueprintServiceTest extends BlueprintGeneratorTests { + + private String outputfilesPath = Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString(); + + @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File") + @Test + public void testServiceNameOverrideK8sBlueprint() throws IOException { + Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs" , ves).toFile().getAbsolutePath(), outputfilesPath, "testServiceNameOverrideK8sBlueprint", "", "o", ""); + onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull("K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = onapBlueprintService.createBlueprint(onapComponentSpec, input); + onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); + System.out.println(onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input)); + + onapTestUtils.verifyToscaDefVersion("Service Name Override K8s",onapBlueprint, Constants.TOSCA_DEF_VERSION); + onapTestUtils.verifyBpImports("Service Name Override K8s",onapBlueprint,false); + + Map> k8sBpInputs = onapBlueprint.getInputs(); + assertNotNull("Service Name Override K8s Blueprint Inputs Section is NULL", k8sBpInputs); + assertTrue("Service Name Override K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); + + assertEquals("Service Name Override K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + " Default is not matching", k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), Constants.ONAP_DEFAULT250m); + assertEquals("Service Name Override K8s Blueprint:Inputs " + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + " Default is not matching", k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); + + Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); + assertNotNull("Service Name Override K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", k8sBpNodeTemplates); + assertTrue("Service Name Override K8s Blueprint Node Templates Section Size is Empty", k8sBpNodeTemplates.size() > 0); + + assertEquals("Service Name Override K8s Blueprint:NodeTemplates:Type is not Matching", k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), Constants.ONAP_NODETEMPLATES_TYPE); + + Properties k8sBpNodeTemplateProperties = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); + assertNotNull("Service Name Override K8s Blueprint Node Templates:Properties Section is NULL", k8sBpNodeTemplateProperties); + + + Map> bpInputs = onapBlueprint.getInputs(); + onapTestUtils.verifyArtifacts("Service Name Override K8s",onapComponentSpec,bpInputs,"o"); + + onapTestUtils.verifyStreamsPublishes("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyStreamsSubscribes("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyAuxilary("Service Name Override K8s",onapComponentSpec); + onapTestUtils.verifyHealthCheck("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyServicesCalls("Service Name Override K8s",onapComponentSpec); + onapTestUtils.verifyServicesProvides("Service Name Override K8s",onapComponentSpec); + onapTestUtils.verifyDockerConfig("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyParameters("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplates); + onapTestUtils.verifyVolumes("Service Name Override K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + } + + @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File with Import File") + @Test + public void testServiceNameOverrideImportFileK8sBlueprint() throws IOException { + Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs", ves).toFile().getAbsolutePath(), "", "", Paths.get("src", "test", "resources", "componentspecs" , testImports).toFile().getAbsolutePath(), "o", ""); + onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull("K8s Blueprint for Service Name Override with Import File Component Spec is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = onapBlueprintService.createBlueprint(onapComponentSpec, input); + + onapTestUtils.verifyToscaDefVersion("Service Name Override with Import File K8s",onapBlueprint, Constants.TOSCA_DEF_VERSION); + onapTestUtils.verifyBpImportsFromFile("Service Name Override with Import File K8s",onapBlueprint,input.getImportPath()); + + + Map> k8sBpInputs = onapBlueprint.getInputs(); + assertNotNull("Service Name Override with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs); + assertTrue("Service Name Override with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); + + assertEquals("Service Name Override with Import File K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + " Default is not matching", k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), Constants.ONAP_DEFAULT250m); + assertEquals("Service Name Override with Import File K8s Blueprint:Inputs " + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + " Default is not matching", k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); + + Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); + assertNotNull("Service Name Override with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", k8sBpNodeTemplates); + assertTrue("Service Name Override with Import File K8s Blueprint Node Templates Section Size is Empty", k8sBpNodeTemplates.size() > 0); + + assertEquals("Service Name Override with Import File K8s Blueprint:NodeTemplates:Type is not Matching", k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), Constants.ONAP_NODETEMPLATES_TYPE); + + Properties k8sBpNodeTemplateProperties = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); + assertNotNull("Service Name Override with Import File K8s Blueprint Node Templates:Properties Section is NULL", k8sBpNodeTemplateProperties); + + + Map> bpInputs = onapBlueprint.getInputs(); + onapTestUtils.verifyArtifacts("Service Name Override with Import File K8s",onapComponentSpec,bpInputs,"o"); + + onapTestUtils.verifyStreamsPublishes("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyStreamsSubscribes("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyAuxilary("Service Name Override with Import File K8s",onapComponentSpec); + onapTestUtils.verifyHealthCheck("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyServicesCalls("Service Name Override with Import File K8s",onapComponentSpec); + onapTestUtils.verifyServicesProvides("Service Name Override with Import File K8s",onapComponentSpec); + onapTestUtils.verifyDockerConfig("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyParameters("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplates); + onapTestUtils.verifyVolumes("Service Name Override with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + } + + @DisplayName("Testing K8s Blueprint with DB") + @Test + public void testDMAAPK8sBlueprintWithDB() { + Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs", ves).toFile().getAbsolutePath(), outputfilesPath, "testDMAAPK8sBlueprintWithDB", "", "d", ""); + onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = dmaapBlueprintService.createBlueprint(onapComponentSpec, input); + onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); + } + + @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File") + @Test + public void testDMAAPK8sBlueprint() { + Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs" , ves).toFile().getAbsolutePath(), outputfilesPath, "testDMAAPK8sBlueprint", "", "d", ""); + onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = dmaapBlueprintService.createBlueprint(onapComponentSpec, input); + onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); + System.out.println(onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input)); + + policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models"); + + onapTestUtils.verifyToscaDefVersion("DMAAP K8s",onapBlueprint, Constants.TOSCA_DEF_VERSION); + //onapTestUtils.verifyBpImports("DMAAP K8s",onapBlueprint,false); + + Map> k8sBpInputs = onapBlueprint.getInputs(); + assertNotNull("DMAAP K8s Blueprint Inputs Section is NULL", k8sBpInputs); + assertTrue("DMAAP K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); + + //assertEquals("DMAAP K8s Blueprint:Inputs " + Constants.ALWAYS_PULL_IMAGE + " Type is not matching", k8sBpInputs.get(Constants.ALWAYS_PULL_IMAGE).get("type"), "boolean"); + //assertEquals("DMAAP K8s Blueprint:Inputs Always Pull Image Default is not matching", k8sBpInputs.get(Constants.ALWAYS_PULL_IMAGE).get("default"), Constants.ALWAYS_PULL_IMAGE_DEFAULT); + assertEquals("DMAAP K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + " Default is not matching", k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), Constants.ONAP_DEFAULT250m); + assertEquals("DMAAP K8s Blueprint:Inputs " + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + " Default is not matching", k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); + + Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); + assertNotNull("DMAAP K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", k8sBpNodeTemplates); + assertTrue("DMAAP K8s Blueprint Node Templates Section Size is Empty", k8sBpNodeTemplates.size() > 0); + + assertEquals("DMAAP K8s Blueprint:NodeTemplates:Type is not Matching", k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), Constants.DMAAP_NODETEMPLATES_TYPE); + + Properties k8sBpNodeTemplateProperties = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); + assertNotNull("DMAAP K8s Blueprint Node Templates:Properties Section is NULL", k8sBpNodeTemplateProperties); + + List bpNodeTemplateRelationships = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships(); + assertNotNull("DMAAP K8s Blueprint Node Templates:Relationships Section is NULL", bpNodeTemplateRelationships); + + onapTestUtils.verifyStreamsPublishes("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyStreamsSubscribes("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyAuxilary("DMAAP K8s",onapComponentSpec); + onapTestUtils.verifyHealthCheck("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyServicesCalls("DMAAP K8s",onapComponentSpec); + onapTestUtils.verifyServicesProvides("DMAAP K8s",onapComponentSpec); + onapTestUtils.verifyDockerConfig("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyParameters("DMAAP K8s",onapComponentSpec,k8sBpNodeTemplates); + } + + @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File with Import File") + @Test + public void testDMAAPK8sImportFileBlueprint() throws IOException { + Input input = onapTestUtils.getInput(Paths.get("src", "test", "resources", "componentspecs" , ves).toFile().getAbsolutePath(), "", "", Paths.get("src", "test", "resources", "componentspecs" , testImports).toFile().getAbsolutePath(), "d", ""); + onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull("K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = dmaapBlueprintService.createBlueprint(onapComponentSpec, input); + + onapTestUtils.verifyToscaDefVersion("DMAAP with Import File K8s",onapBlueprint, Constants.TOSCA_DEF_VERSION); + onapTestUtils.verifyBpImportsFromFile("DMAAP with Import File K8s",onapBlueprint,input.getImportPath()); + + Map> k8sBpInputs = onapBlueprint.getInputs(); + assertNotNull("DMAAP with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs); + assertTrue("DMAAP with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); + + //assertEquals("DMAAP with Import File K8s Blueprint:Inputs " + Constants.ALWAYS_PULL_IMAGE + " Type is not matching", k8sBpInputs.get(Constants.ALWAYS_PULL_IMAGE).get("type"), "boolean"); + //assertEquals("DMAAP with Import File K8s Blueprint:Inputs Always Pull Image Default is not matching", k8sBpInputs.get(Constants.ALWAYS_PULL_IMAGE).get("default"), Constants.ALWAYS_PULL_IMAGE_DEFAULT); + assertEquals("DMAAP with Import File K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + " Default is not matching", k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), Constants.ONAP_DEFAULT250m); + assertEquals("DMAAP with Import File K8s Blueprint:Inputs " + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + " Default is not matching", k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); + + Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); + assertNotNull("DMAAP with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", k8sBpNodeTemplates); + assertTrue("DMAAP with Import File K8s Blueprint Node Templates Section Size is Empty", k8sBpNodeTemplates.size() > 0); + + assertEquals("DMAAP with Import File K8s Blueprint:NodeTemplates:Type is not Matching", k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), Constants.DMAAP_NODETEMPLATES_TYPE); + + Properties k8sBpNodeTemplateProperties = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); + assertNotNull("DMAAP with Import File K8s Blueprint Node Templates:Properties Section is NULL", k8sBpNodeTemplateProperties); + + List bpNodeTemplateRelationships = ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships(); + assertNotNull("DMAAP with Import File K8s Blueprint Node Templates:Relationships Section is NULL", bpNodeTemplateRelationships); + + onapTestUtils.verifyStreamsPublishes("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyStreamsSubscribes("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyAuxilary("DMAAP with Import File K8s",onapComponentSpec); + onapTestUtils.verifyHealthCheck("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyServicesCalls("DMAAP with Import File K8s",onapComponentSpec); + onapTestUtils.verifyServicesProvides("DMAAP with Import File K8s",onapComponentSpec); + onapTestUtils.verifyDockerConfig("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplateProperties); + onapTestUtils.verifyParameters("DMAAP with Import File K8s",onapComponentSpec,k8sBpNodeTemplates); + } + +} + + + diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapComponentSpecTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapComponentSpecTest.java new file mode 100644 index 0000000..633c205 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapComponentSpecTest.java @@ -0,0 +1,58 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.test; + + +import org.onap.blueprintgenerator.exception.ComponentSpecException; +import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec; +import org.junit.Test; +import org.junit.jupiter.api.DisplayName; + +import java.nio.file.Paths; + +import static org.junit.Assert.assertEquals; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * ONAP ComponentSpec Test Cases + */ + +public class OnapComponentSpecTest extends BlueprintGeneratorTests { + + @DisplayName("Testing ComponentSpec File Generation for Invalid File") + @Test(expected = ComponentSpecException.class) + public void testComponentSpecForInvalidFile() { + onapComponentSpecService.createComponentSpecFromFile("invalid.json"); + } + + @DisplayName("Testing ComponentSpec File Generation for Valid DMAAP File") + @Test + public void testComponentSpecForValidVesFile(){ + ComponentSpec onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(Paths.get("src", "test", "resources", "componentspecs", ves).toFile().getAbsolutePath()); + assertEquals("ComponentSpec name not matching for Valid Ves File",onapComponentSpec.getSelf().getName(), "dcae-ves-collector"); + } + +} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapTestUtils.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapTestUtils.java new file mode 100644 index 0000000..9033fbe --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapTestUtils.java @@ -0,0 +1,207 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.test; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.base.Blueprint; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.Properties; +import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; + +import org.onap.blueprintgenerator.model.componentspec.common.Calls; +import org.onap.blueprintgenerator.model.componentspec.common.Provides; +import org.onap.blueprintgenerator.model.componentspec.common.HealthCheck; +import org.onap.blueprintgenerator.model.componentspec.common.Parameters; +import org.onap.blueprintgenerator.model.componentspec.common.Volumes; +import org.onap.blueprintgenerator.model.componentspec.common.Artifacts; +import org.onap.blueprintgenerator.model.dmaap.Streams; +import org.junit.Ignore; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Test Utilities used in Test Suite and Test Cases + */ + +@Component +@Ignore +public class OnapTestUtils extends BlueprintGeneratorTests { + + @Value("${imports.onap.types}") + private String importsOnapTypes; + + @Value("${imports.onap.K8s.plugintypes}") + private String importsOnapK8sPlugintypes; + + @Value("${imports.onap.K8s.dcaepolicyplugin}") + private String importsOnapK8sDcaepolicyplugin; + + @Value("${imports.dmaap.dmaapplugin}") + private String importsDmaapDmaapplugin; + + @Value("${import.Postgres}") + private String importPostgres; + + @Value("${import.Clamp}") + private String importClamp; + + + + public Input getInput(String componentSpecPath,String outputPath,String bluePrintName,String importPath,String bpType,String serviceNameOverride){ + Input input = new Input(); + input.setComponentSpecPath(componentSpecPath); + input.setBluePrintName(bluePrintName); + input.setOutputPath(outputPath); + input.setBpType(bpType); + input.setServiceNameOverride(serviceNameOverride); + input.setImportPath(importPath); + return input; + } + + public Input getInput(String componentSpecPath){ + Input input = new Input(); + input.setComponentSpecPath(componentSpecPath); + return input; + } + + public void verifyToscaDefVersion(String type,Blueprint blueprint,String toscaDefVersion){ + String bpToscaDefVersion = blueprint.getTosca_definitions_version(); + assertNotNull(type + " TOSCA Definition Version is NULL", bpToscaDefVersion); + assertEquals(type + " TOSCA Definition Version is not Matching", bpToscaDefVersion, toscaDefVersion); + } + + public void verifyBpImports(String type,Blueprint blueprint, boolean validateimps) { + String[] bpImports = blueprint.getImports().toArray(new String[blueprint.getImports().size()]); + if (validateimps) { + String[] testImports = {importsOnapTypes,importsOnapK8sPlugintypes,importsDmaapDmaapplugin,importPostgres,importClamp}; + assertArrayEquals(type + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports", bpImports, testImports); + } + else{ + String[] testImports = {importsOnapTypes,importsOnapK8sPlugintypes,importsOnapK8sDcaepolicyplugin,importPostgres,importClamp}; + assertArrayEquals(type + " Blueprint Imports is not matching with default Onap K8s Blueprint imports", bpImports, testImports); + } + + } + + public void verifyBpImportsFromFile(String type,Blueprint blueprint, String importPath) throws IOException { + Blueprint importFileRead = yamlObjectMapper.readValue(new File(importPath), Blueprint.class); + String[] importFileImports = importFileRead.getImports().toArray(new String[importFileRead.getImports().size()]); + String[] bpImports = blueprint.getImports().toArray(new String[blueprint.getImports().size()]); + assertArrayEquals(type + " Blueprint Imports is not matching with default Dmaap K8s Blueprint imports", bpImports, importFileImports); + + } + + public void verifyStreamsPublishes(String type, OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties) { + List streamsPublishes = nodeTemplateProperties.getStreams_publishes(); + if (!(streamsPublishes == null)) { + assertNotNull(type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is NULL", streamsPublishes); + assertTrue(type + " Blueprint:NodeTemplates:Properties:StreamsPublishes Section Size is 0", streamsPublishes.size() > 0); + assertEquals(type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching", streamsPublishes.get(0).getType(), Constants.MESSAGEROUTER_VALUE); + assertEquals(type + " Blueprint:NodeTemplates:Properties:StreamsPublishes is Not Matching", streamsPublishes.get(1).getType(), Constants.MESSAGEROUTER_VALUE); + } + } + + public void verifyStreamsSubscribes(String type,OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties){ + List streamsSubscribes = nodeTemplateProperties.getStreams_subscribes(); + if (!(streamsSubscribes == null)) { + assertNotNull(type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is NULL", streamsSubscribes); + assertTrue(type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes Section Size is 0", streamsSubscribes.size() > 0); + assertEquals(type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching", streamsSubscribes.get(0).getType(), Constants.MESSAGE_ROUTER); + assertEquals(type + " Blueprint:NodeTemplates:Properties:StreamsSubscribes is Not Matching", streamsSubscribes.get(1).getType(), Constants.DATA_ROUTER); + } + } + + public void verifyServicesCalls(String type, OnapComponentSpec onapComponentSpec){ + Calls[] csServicesCalls = onapComponentSpec.getServices().getCalls(); + assertNotNull(type + " ComponentSpec Services Calls is NULL", csServicesCalls); + //assertTrue(type + " ComponentSpec Services Calls Section Size is 0", csServicesCalls.length > 0); + } + + public void verifyServicesProvides(String type, OnapComponentSpec onapComponentSpec){ + Provides[] csServicesProvides = onapComponentSpec.getServices().getProvides(); + assertNotNull(type + " ComponentSpec Services Provides is NULL", csServicesProvides); + assertTrue(type + " ComponentSpec Services Provides Section Size is 0", csServicesProvides.length > 0); + } + + public void verifyDockerConfig(String type,OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties){ + OnapAuxilary dockerConfig = nodeTemplateProperties.getDocker_config(); + assertNotNull(type +" Blueprint Docker Config Section is NULL", dockerConfig); + } + + + public void verifyParameters(String type, OnapComponentSpec onapComponentSpec, Map nodeTemplates) { + Parameters[] csParameters = onapComponentSpec.getParameters(); + assertNotNull(type +" ComponentSpec Parameters Section is NULL", csParameters); + assertTrue(type + " ComponentSpec Parameters Section Size is 0", csParameters.length > 0); + } + + public void verifyAuxilary(String type, OnapComponentSpec onapComponentSpec){ + OnapAuxilary csAuxilary = onapComponentSpec.getAuxilary(); + assertNotNull(type +" ComponentSpec Auxilary Section is NULL", csAuxilary); + } + + public void verifyHealthCheck(String type,OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties){ + HealthCheck csAuxilaryHealthcheck = onapComponentSpec.getAuxilary().getHealthcheck(); + assertNotNull(type +" ComponentSpec Auxilary Health Check Section is NULL", csAuxilaryHealthcheck); + HealthCheck healthCheck = nodeTemplateProperties.getDocker_config().getHealthcheck(); + assertNotNull(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck Section is NULL", healthCheck); + assertEquals(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Interval Tag is not matching", healthCheck.getInterval(), csAuxilaryHealthcheck.getInterval()); + assertEquals(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Timeout Tag is not matching", healthCheck.getTimeout(), csAuxilaryHealthcheck.getTimeout()); + assertEquals(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Script Tag is not matching", healthCheck.getEndpoint(), csAuxilaryHealthcheck.getEndpoint()); + assertEquals(type + " Blueprint:NodeTemplates:DockerConfig:Healthcheck:Type Tag is not matching", healthCheck.getType(), csAuxilaryHealthcheck.getType()); + } + + public void verifyVolumes(String type,OnapComponentSpec onapComponentSpec, Properties nodeTemplateProperties){ + Volumes[] csAuxilaryVolumes = onapComponentSpec.getAuxilary().getVolumes(); + assertNotNull(type +" ComponentSpec Auxilary Live Health Check Section is NULL", csAuxilaryVolumes); + Volumes[] onapVolumes = nodeTemplateProperties.getDocker_config().getVolumes(); + assertNotNull(type + " Blueprint:NodeTemplates:DockerConfig:LiveHealthcheck Section is NULL", onapVolumes); + } + + public void verifyArtifacts(String type,OnapComponentSpec onapComponentSpec, Map> inputs,String bptype){ + Artifacts[] csArtifacts = onapComponentSpec.getArtifacts(); + assertNotNull(type + " ComponentSpec Artifacts Section is NULL", csArtifacts); + assertEquals(type + " Blueprint:Artifacts:image is not matching", ((String) inputs.get("image").get("default")), "\"" + csArtifacts[0].getUri() + "\""); + //assertEquals(type + " Blueprint:Artifacts:image is not matching", ((String) inputs.get("tag_version").get("default")), "\"" + csArtifacts[0].getUri() + "\""); + + } + +} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/TlsInfoTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/TlsInfoTest.java new file mode 100644 index 0000000..f4bbe3e --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/TlsInfoTest.java @@ -0,0 +1,168 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia. All rights reserved. + Copyright (c) 2020 AT&T. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.test; + + +import org.junit.Test; +import org.junit.runners.Parameterized; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.onap.blueprintgenerator.model.common.ExternalCertificateParameters; +import org.onap.blueprintgenerator.model.common.ExternalTlsInfo; +import org.onap.blueprintgenerator.model.dmaap.TlsInfo; + + +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + + + +//@RunWith(Parameterized.class) +public class TlsInfoTest extends BlueprintGeneratorTests { + + @Parameterized.Parameter + public char bpType; + + @Parameterized.Parameters(name = "Blueprint type: {0}") + public static List data() { + return Arrays.asList('o', 'd'); + } + + + @Test + public void useTlsTrueAndUseExternalTlsTrueTest(){ + //Input input = input.setComponentSpecPath(componentSpecPath + "testComponentSpec_withTlsTrueAndExternalTlsTrue.json"); + OnapBlueprint bp = createBlueprintFromFile(Paths.get("src", "test", "resources", "componentspecs", useTlsTrueAndUseExternalTlsTrueTest).toFile().getAbsolutePath()); + + assertBlueprintContainsExternalTlsInfoWithUseFlagDefault(bp, true); + assertBlueprintContainsTlsInfoWithUseFlagDefault(bp, true); + } + + @Test + public void useTlsFalseAndUseExternalTlsFalseTest(){ + OnapBlueprint bp = createBlueprintFromFile(Paths.get("src", "test", "resources", "componentspecs", useTlsFalseAndUseExternalTlsFalseTest).toFile().getAbsolutePath()); + + assertBlueprintContainsExternalTlsInfoWithUseFlagDefault(bp, false); + assertBlueprintContainsTlsInfoWithUseFlagDefault(bp, false); + } + + @Test + public void useTlsTrueAndNoExternalTlsFlagTest(){ + OnapBlueprint bp = createBlueprintFromFile(Paths.get("src", "test", "resources", "componentspecs", useTlsTrueAndNoExternalTlsFlagTest).toFile().getAbsolutePath()); + + assertBlueprintContainsTlsInfoWithUseFlagDefault(bp, true); + assertBlueprintHasNoExternalTlsInfo(bp); + } + + @Test + public void noTlsInfo(){ + OnapBlueprint bp = createBlueprintFromFile(Paths.get("src", "test", "resources", "componentspecs", noTlsInfo).toFile().getAbsolutePath()); + + assertBlueprintHasNoTlsInfo(bp); + assertBlueprintHasNoExternalTlsInfo(bp); + } + + private void assertBlueprintContainsExternalTlsInfoWithUseFlagDefault(OnapBlueprint bp, boolean useFlagDefault) { + //should create proper inputs + assertContainsInputWithDefault(bp, "external_cert_use_external_tls", useFlagDefault); + assertContainsInputWithDefault(bp, "external_cert_ca_name", "\"RA\""); + assertContainsInputWithDefault(bp, "external_cert_cert_type", "\"P12\""); + assertContainsInputWithDefault(bp, "external_cert_common_name", "\"sample.onap.org\""); + assertContainsInputWithDefault(bp, "external_cert_sans", + "\"sample.onap.org:component.sample.onap.org\""); + + Node node = bp.getNode_templates().get("test.component.spec"); + + //should create proper externalTlsInfo object in node properties + ExternalTlsInfo externalTlsInfo = node.getProperties().getExternal_cert(); + assertNotNull(externalTlsInfo); + + assertEquals("external_cert_ca_name", externalTlsInfo.getCaName().getBpInputName()); + assertEquals("external_cert_cert_type", externalTlsInfo.getCertType().getBpInputName()); + assertEquals("external_cert_use_external_tls", externalTlsInfo.getUseExternalTls().getBpInputName()); + assertEquals("/opt/app/dcae-certificate/", externalTlsInfo.getExternalCertDirectory()); + + ExternalCertificateParameters extCertParams = externalTlsInfo.getExternalCertificateParameters(); + assertNotNull(extCertParams); + + assertEquals("external_cert_common_name", extCertParams.getCommonName().getBpInputName()); + assertEquals("external_cert_sans", extCertParams.getSans().getBpInputName()); + } + + private void assertBlueprintContainsTlsInfoWithUseFlagDefault(OnapBlueprint bp, boolean useFlagDefault) { + //shold create proper inputs + assertContainsInputWithDefault(bp, "use_tls", useFlagDefault); + + Node node = bp.getNode_templates().get("test.component.spec"); + + //should create proper tlsInfo object in node properties + TlsInfo tlsInfo = node.getProperties().getTls_info(); + assertEquals("use_tls", tlsInfo.getUseTls().getBpInputName()); + assertEquals("/opt/app/dcae-certificate/", tlsInfo.getCertDirectory()); + + } + + private void assertBlueprintHasNoExternalTlsInfo(OnapBlueprint bp) { + //should not create inputs for external tls + assertFalse(bp.getInputs().containsKey("external_cert_use_external_tls")); + assertFalse(bp.getInputs().containsKey("external_cert_common_name")); + assertFalse(bp.getInputs().containsKey("external_cert_ca_name")); + assertFalse(bp.getInputs().containsKey("external_cert_sans")); + + Node node = bp.getNode_templates().get("test.component.spec"); + + //should not create externalTlsInfo object in node properties + ExternalTlsInfo externalTlsInfo = node.getProperties().getExternal_cert(); + assertNull(externalTlsInfo); + } + + + private void assertBlueprintHasNoTlsInfo(OnapBlueprint bp) { + //should not create inputs for tls + assertFalse(bp.getInputs().containsKey("use_tls")); + + Node node = bp.getNode_templates().get("test.component.spec"); + + //should not create tlsInfo object in node properties + assertNull(node.getProperties().getTls_info()); + } + + private void assertContainsInputWithDefault(OnapBlueprint bp, String inputName, Object defaultValue) { + LinkedHashMap input = bp.getInputs().get(inputName); + assertNotNull(input); + assertEquals(defaultValue, input.get("default")); + } + + private OnapBlueprint createBlueprintFromFile(String path) { + onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(path); + Input input = onapTestUtils.getInput(path, "", "", "", "o", ""); + OnapBlueprint onapBlueprint = onapBlueprintService.createBlueprint(onapComponentSpec, input); + return onapBlueprint; + } +} diff --git a/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsFalseAndExternalTlsFalse.json b/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsFalseAndExternalTlsFalse.json new file mode 100644 index 0000000..da75ab8 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsFalseAndExternalTlsFalse.json @@ -0,0 +1,43 @@ +{ + "self": { + "component_type": "docker", + "description": "Test component spec", + "name": "test.component.spec", + "version": "1.0.1" + }, + + "services": { + "calls": [], + "provides": [] + }, + + "streams": { + "publishes": [], + "subscribes": [] + }, + + "parameters": [], + + "auxilary": { + "healthcheck": { + "type": "docker", + "interval": "300s", + "timeout": "120s", + "script": "/etc/init.d/nagios status" + }, + "ports": [ + "80:80", + "99:99" + ], + "tls_info": { + "cert_directory": "/opt/app/dcae-certificate/", + "use_tls": false, + "use_external_tls": false + } + }, + "artifacts": [{ + "type": "docker image", + "uri": "test.tester" + }] + +} diff --git a/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsTrueAndExternalTlsTrue.json b/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsTrueAndExternalTlsTrue.json new file mode 100644 index 0000000..f13e3fd --- /dev/null +++ b/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsTrueAndExternalTlsTrue.json @@ -0,0 +1,43 @@ +{ + "self": { + "component_type": "docker", + "description": "Test component spec", + "name": "test.component.spec", + "version": "1.0.1" + }, + + "services": { + "calls": [], + "provides": [] + }, + + "streams": { + "publishes": [], + "subscribes": [] + }, + + "parameters": [], + + "auxilary": { + "healthcheck": { + "type": "docker", + "interval": "300s", + "timeout": "120s", + "script": "/etc/init.d/nagios status" + }, + "ports": [ + "80:80", + "99:99" + ], + "tls_info": { + "cert_directory": "/opt/app/dcae-certificate/", + "use_tls": true, + "use_external_tls": true + } + }, + "artifacts": [{ + "type": "docker image", + "uri": "test.tester" + }] + +} diff --git a/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsTrueAndNoExternalTls.json b/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsTrueAndNoExternalTls.json new file mode 100644 index 0000000..517c461 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withTlsTrueAndNoExternalTls.json @@ -0,0 +1,42 @@ +{ + "self": { + "component_type": "docker", + "description": "Test component spec", + "name": "test.component.spec", + "version": "1.0.1" + }, + + "services": { + "calls": [], + "provides": [] + }, + + "streams": { + "publishes": [], + "subscribes": [] + }, + + "parameters": [], + + "auxilary": { + "healthcheck": { + "type": "docker", + "interval": "300s", + "timeout": "120s", + "script": "/etc/init.d/nagios status" + }, + "ports": [ + "80:80", + "99:99" + ], + "tls_info": { + "cert_directory": "/opt/app/dcae-certificate/", + "use_tls": true + } + }, + "artifacts": [{ + "type": "docker image", + "uri": "test.tester" + }] + +} diff --git a/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withoutTlsInfo.json b/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withoutTlsInfo.json new file mode 100644 index 0000000..a94c987 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/resources/componentspecs/testComponentSpec_withoutTlsInfo.json @@ -0,0 +1,38 @@ +{ + "self": { + "component_type": "docker", + "description": "Test component spec", + "name": "test.component.spec", + "version": "1.0.1" + }, + + "services": { + "calls": [], + "provides": [] + }, + + "streams": { + "publishes": [], + "subscribes": [] + }, + + "parameters": [], + + "auxilary": { + "healthcheck": { + "type": "docker", + "interval": "300s", + "timeout": "120s", + "script": "/etc/init.d/nagios status" + }, + "ports": [ + "80:80", + "99:99" + ] + }, + "artifacts": [{ + "type": "docker image", + "uri": "test.tester" + }] + +} diff --git a/mod/bpgenerator/onap/src/test/resources/componentspecs/testImports.yaml b/mod/bpgenerator/onap/src/test/resources/componentspecs/testImports.yaml new file mode 100644 index 0000000..42a482d --- /dev/null +++ b/mod/bpgenerator/onap/src/test/resources/componentspecs/testImports.yaml @@ -0,0 +1,4 @@ +imports: + - https://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml + - plugin:k8splugin?version=3.0.0 + - plugin:dcaepolicyplugin?version=2.4.0 \ No newline at end of file diff --git a/mod/bpgenerator/onap/src/test/resources/componentspecs/ves.json b/mod/bpgenerator/onap/src/test/resources/componentspecs/ves.json new file mode 100644 index 0000000..6655a2c --- /dev/null +++ b/mod/bpgenerator/onap/src/test/resources/componentspecs/ves.json @@ -0,0 +1,337 @@ +{ + "self": { + "version": "1.5.0", + "name": "dcae-ves-collector", + "description": "Collector for receiving VES events through restful interface", + "component_type": "docker" + }, + "streams": { + "subscribes": [ + { + "format": "dataformat_Hello_World_PM", + "version": "1.0.0", + "route": "/TEST_HELLO_WORLD_SUB_MR", + "type": "message_router", + "config_key": "TEST-SUB-MR" + }, + { + "format": "dataformat_Hello_World_PM DR", + "version": "1.0.0", + "route": "/TEST_HELLO_WORLD_SUB_DR", + "type": "data_router", + "config_key": "TEST-SUB-DR" + } + ], + "publishes": [ + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-fault" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-measurement" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-other" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-heartbeat-secondary" + }, + { + "format": "VES_specification", + "version": "7.30.0", + "type": "message router", + "config_key": "ves-pnfRegistration" + }, + { + "format": "VES_specification", + "version": "7.30.0", + "type": "message router", + "config_key": "ves-notification" + } + ] + }, + "services": { + "calls": [], + "provides": [ + { + "route": "/eventListener/v1", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v2", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v3", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v4", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v5", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "5.28.4" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v7", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "7.30.0" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + } + ] + }, + "parameters": [ + { + "name": "collector.service.port", + "value": 8080, + "description": "standard http port collector will open for listening;", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.service.secure.port", + "value": 8443, + "description": "secure http port collector will open for listening ", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": true + }, + { + "name": "collector.keystore.file.location", + "value": "/opt/app/dcae-certificate/keystore.jks", + "description": "fs location of keystore file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.keystore.passwordfile", + "value": "/opt/app/dcae-certificate/.password", + "description": "location of keystore password file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.truststore.file.location", + "value": "/opt/app/dcae-certificate/truststore.jks", + "description": "fs location of truststore file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.truststore.passwordfile", + "value": "/opt/app/dcae-certificate/.trustpassword", + "description": "location of truststore password file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.dmaap.streamid", + "value": "fault=ves-fault,ves-fault-secondary|syslog=ves-syslog,ves-syslog-secondary|heartbeat=ves-heartbeat,ves-heartbeat-secondary|measurementsForVfScaling=ves-measurement,ves-measurement-secondary|mobileFlow=ves-mobileflow,ves-mobileflow-secondary|other=ves-other,ves-other-secondary|stateChange=ves-statechange,ves-statechange-secondary|thresholdCrossingAlert=ves-thresholdCrossingAlert,ves-thresholdCrossingAlert-secondary|voiceQuality=ves-voicequality,ves-voicequality-secondary|sipSignaling=ves-sipsignaling,ves-sipsignaling-secondary|notification=ves-notification,ves-notification-secondary|pnfRegistration=ves-pnfRegistration,ves-pnfRegistration-secondary", + "description": "domain-to-streamid mapping used by VESCollector to distributes events based on domain. Both primary and secondary config_key are included for resilency (multiple streamid can be included commma separated). The streamids MUST match to topic config_keys. For single site without resiliency deployment - configkeys with -secondary suffix can be removed", + "sourced_at_deployment": true, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "auth.method", + "value": "noAuth", + "description": "Property to manage application mode, possible configurations: noAuth - default option - no security (http) , certOnly - auth by certificate (https), basicAuth - auth by basic auth username and password (https),certBasicAuth - auth by certificate and basic auth username / password (https),", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "header.authlist", + "value": "sample1,$2a$10$pgjaxDzSuc6XVFEeqvxQ5u90DKJnM/u7TJTcinAlFJVaavXMWf/Zi|userid1,$2a$10$61gNubgJJl9lh3nvQvY9X.x4e5ETWJJ7ao7ZhJEvmfJigov26Z6uq|userid2,$2a$10$G52y/3uhuhWAMy.bx9Se8uzWinmbJa.dlm1LW6bYPdPkkywLDPLiy", + "description": "List of id and base 64 encoded password.For each onboarding VNF - unique userid and password should be assigned and communicated to VNF owner. Password value should be base64 encoded in config here", + "policy_editable": false, + "sourced_at_deployment": true, + "designer_editable": true + }, + { + "name": "collector.schema.checkflag", + "value": 1, + "description": "Schema check validation flag. When enabled, collector will validate input VES events against VES Schema defined on collector.schema.file ", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.schema.file", + "value": "{\"v1\":\"./etc/CommonEventFormat_27.2.json\",\"v2\":\"./etc/CommonEventFormat_27.2.json\",\"v3\":\"./etc/CommonEventFormat_27.2.json\",\"v4\":\"./etc/CommonEventFormat_27.2.json\",\"v5\":\"./etc/CommonEventFormat_28.4.1.json\",\"v7\":\"./etc/CommonEventFormat_30.json\"}", + "description": "VES schema file name per version used for validation", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false + }, + { + "name": "event.transform.flag", + "value": 1, + "description": "flag to enable tranformation rules defined under eventTransform.json; this is applicable when event tranformation rules preset should be activated for transforming