From 7b27a8acf25d5d92a0160360175b5d0ecd2ef4d7 Mon Sep 17 00:00:00 2001 From: Dhrumin Desai Date: Thu, 6 Feb 2020 14:26:41 -0500 Subject: Added policyNodes, db, tls support Change-Id: Id960c156eb8da67e6792c6dbc1a60892d28703b0 Issue-ID: DCAEGEN2-164 Issue-ID: DCAEGEN2-1873 Issue-ID: DCAEGEN2-1995 Issue-ID: DCAEGEN2-1859 Signed-off-by: Dhrumin Desai --- .../org/onap/blueprintgenerator/core/Fixes.java | 34 ++++++ .../blueprintgenerator/core/PgaasNodeBuilder.java | 130 +++++++++++++++++++++ .../blueprintgenerator/core/PolicyNodeBuilder.java | 90 ++++++++++++++ .../exception/DatabasesNotFoundException.java | 24 ++++ .../blueprintgenerator/models/GetAttribute.java | 34 ++++++ .../models/blueprint/Appconfig.java | 22 ++-- .../models/blueprint/Blueprint.java | 11 +- .../models/blueprint/DmaapObj.java | 51 ++++---- .../models/blueprint/Properties.java | 121 ++++++++----------- .../models/blueprint/StartInputs.java | 51 ++++++-- .../models/blueprint/TlsInfo.java | 37 ++++++ .../models/blueprint/pgaas/PgaasNode.java | 35 ++++++ .../blueprint/pgaas/PgaasNodeProperties.java | 40 +++++++ .../models/blueprint/policy/PolicyNode.java | 34 ++++++ .../blueprint/policy/PolicyNodeProperties.java | 37 ++++++ .../models/componentspec/Auxilary.java | 72 +++++++----- .../models/componentspec/ComponentSpec.java | 14 +-- .../componentspec/policy_info/PolicyInfo.java | 35 ++++++ .../componentspec/policy_info/TypePolicy.java | 36 ++++++ .../models/dmaapbp/DmaapBlueprint.java | 26 +++-- .../models/dmaapbp/DmaapNode.java | 25 ++-- .../models/dmaapbp/DmaapStreams.java | 16 +++ .../models/onapbp/OnapBlueprint.java | 13 +++ .../blueprintgenerator/models/onapbp/OnapNode.java | 22 ++++ 24 files changed, 830 insertions(+), 180 deletions(-) create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PgaasNodeBuilder.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PolicyNodeBuilder.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/exception/DatabasesNotFoundException.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/GetAttribute.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/TlsInfo.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/pgaas/PgaasNode.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/pgaas/PgaasNodeProperties.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/policy/PolicyNode.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/policy/PolicyNodeProperties.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/policy_info/PolicyInfo.java create mode 100644 mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/policy_info/TypePolicy.java (limited to 'mod/bpgenerator/src') diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/Fixes.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/Fixes.java index cbff42b..3a4b457 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/Fixes.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/Fixes.java @@ -29,6 +29,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.List; public class Fixes { private static ArrayList lines = new ArrayList(); @@ -40,6 +41,7 @@ public class Fixes { FileReader fr = new FileReader(translateFile); BufferedReader br = new BufferedReader(fr); while((line = br.readLine()) != null) { +// lines.add(ensureNoSingleQuotes(line)); if(line.contains("'")) { line = line.replace("'", ""); } @@ -67,4 +69,36 @@ public class Fixes { throw new RuntimeException(e); } } + + /** + * Remove single quotes from a line from a blueprint + */ + private static String ensureNoSingleQuotes(String line) { + // TODO: Should probably use regex instead + // REVIEW: The condition under which to remove the single quotes + if ((line.contains("concat") || line.contains("default: ")) && line.contains("'")) { + return line.replace("'", ""); + } else { + return line; + } + } + + /** + * Takes in an entire blueprint (YAML) in a string buffer and post processes it to apply + * "fixes" like removing unwanted single quotes. + */ + public static String applyFixes(String bp) { + List lines = new ArrayList(); + + String[] linesPre = bp.split("\n"); + System.out.println(String.format("To post-processing #lines: %d", linesPre.length)); + + for (String line : linesPre) { + lines.add(ensureNoSingleQuotes(line)); + } + + return String.join("\n", lines); + } + + } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PgaasNodeBuilder.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PgaasNodeBuilder.java new file mode 100644 index 0000000..a22d588 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PgaasNodeBuilder.java @@ -0,0 +1,130 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019-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.core; + +import org.onap.blueprintgenerator.exception.DatabasesNotFoundException; +import org.onap.blueprintgenerator.models.GetAttribute; +import org.onap.blueprintgenerator.models.blueprint.GetInput; +import org.onap.blueprintgenerator.models.blueprint.Node; +import org.onap.blueprintgenerator.models.blueprint.pgaas.PgaasNode; +import org.onap.blueprintgenerator.models.blueprint.pgaas.PgaasNodeProperties; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +import java.util.*; + +public class PgaasNodeBuilder { + + private static final String PGAAS_NODE_TYPE = "dcae.nodes.pgaas.database"; + private static final String PGAAS_NODE_NAME_POSTFIX = "_pgaasdb"; + private static final String WRITER_FQDN_POSTFIX = "_database_writerfqdn"; + private static final String NAME_POSTFIX = "_database_name"; + private static final boolean USE_EXISTING = true; + private static final String DB_RELATIONSHIP_TYPE = "cloudify.relationships.depends_on"; + + + + public static void addPgaasNodesAndInputs(ComponentSpec cs, TreeMap nodeTemplate, TreeMap> inps) { + TreeMap databases = cs.getAuxilary().getDatabases(); + if(databases == null){ + throw new DatabasesNotFoundException("databases section not found in componentspec"); + } + for(Map.Entry database : databases.entrySet()){ + addPgaasNode(database, nodeTemplate); + addPgaasInputs(database, inps); + } + } + + private static void addPgaasInputs(Map.Entry database, TreeMap> inps) { + inps.put(database.getKey() + NAME_POSTFIX, getInputValue("string", "db name", "")); + inps.put(database.getKey() + WRITER_FQDN_POSTFIX, getInputValue("string", "db writerfqdn", "")); + } + + private static LinkedHashMap getInputValue(String type, String description, Object defaultValue) { + LinkedHashMap inputValueMap = new LinkedHashMap(); + inputValueMap.put("type", type); + inputValueMap.put("description", description); + inputValueMap.put("default", defaultValue); + return inputValueMap; + } + + private static void addPgaasNode(Map.Entry database, TreeMap nodeTemplate) { + PgaasNode pgaasNode = new PgaasNode(); + String dbName = database.getKey(); + pgaasNode.setType(PGAAS_NODE_TYPE); + pgaasNode.setPgaasNodeProperties(buildPgaasNodeProperties(dbName)); + nodeTemplate.put(dbName + PGAAS_NODE_NAME_POSTFIX , pgaasNode); + } + + private static PgaasNodeProperties buildPgaasNodeProperties(String dbName) { + PgaasNodeProperties pgaasNodeProperties = new PgaasNodeProperties(); + + GetInput nameValue = new GetInput(); + nameValue.setGet_input(dbName + NAME_POSTFIX); + pgaasNodeProperties.setName(nameValue); + + GetInput writerfqdnValue = new GetInput(); + writerfqdnValue.setGet_input(dbName + WRITER_FQDN_POSTFIX); + pgaasNodeProperties.setWriterfqdn(writerfqdnValue); + + pgaasNodeProperties.setUseExisting(USE_EXISTING); + + return pgaasNodeProperties; + } + + public static ArrayList> getPgaasNodeRelationships(ComponentSpec cs) { + ArrayList> relationships = new ArrayList<>(); + for(Map.Entry database : cs.getAuxilary().getDatabases().entrySet()){ + LinkedHashMap relationship = new LinkedHashMap<>(); + relationship.put("type", DB_RELATIONSHIP_TYPE); + relationship.put("target", database.getKey() + PGAAS_NODE_NAME_POSTFIX); + relationships.add(relationship); + } + return relationships; + } + + public static LinkedHashMap getEnvVariables(TreeMap databases) { + LinkedHashMap envVariables = new LinkedHashMap(); + for(Map.Entry database : databases.entrySet()){ + String name = database.getKey().toUpperCase(); + + envVariables.put("<<", "*envs"); + + GetInput nameValue = new GetInput(); + nameValue.setGet_input(name.toLowerCase() + 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 static GetAttribute buildGetAttributeValue(String dbName, String owner, String type) { + GetAttribute attribute = new GetAttribute(); + attribute.setAttribute(Arrays.asList(dbName + PGAAS_NODE_NAME_POSTFIX, owner, type)); + return attribute; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PolicyNodeBuilder.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PolicyNodeBuilder.java new file mode 100644 index 0000000..a947ab7 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PolicyNodeBuilder.java @@ -0,0 +1,90 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 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.core; + +import org.onap.blueprintgenerator.models.blueprint.GetInput; +import org.onap.blueprintgenerator.models.blueprint.Node; +import org.onap.blueprintgenerator.models.blueprint.policy.PolicyNode; +import org.onap.blueprintgenerator.models.blueprint.policy.PolicyNodeProperties; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.policy_info.TypePolicy; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.TreeMap; + +public class PolicyNodeBuilder { + + private static final String POLICY_NODE_TYPE = "clamp.nodes.policy"; + private static final String POLICY_RELATIONSHIP_TYPE = "cloudify.relationships.depends_on"; + + public static void addPolicyNodesAndInputs(ComponentSpec cs, TreeMap nodeTemplate, TreeMap> inps) { + List policyList = cs.getPolicyInfo().getTypePolicyList(); + for(TypePolicy policy: policyList){ + addPolicyNodesToNodeTemplate(policy, nodeTemplate); + addPolicyInputs(policy, inps); + } + } + + private static void addPolicyInputs(TypePolicy policy, TreeMap> inps) { + String defaultValue = policy.getPolicy_id() != null ? policy.getPolicy_id() : ""; + inps.put(policy.getNode_label() + "_policy_id", getInputValue("string", "policy_id", defaultValue)); + } + + private static LinkedHashMap getInputValue(String type, String description, Object defaultValue) { + LinkedHashMap inputValueMap = new LinkedHashMap(); + inputValueMap.put("type", type); + inputValueMap.put("description", description); + inputValueMap.put("default", defaultValue); + return inputValueMap; + } + + private static void addPolicyNodesToNodeTemplate(TypePolicy policy, TreeMap nodeTemplate) { + PolicyNode policyNode = new PolicyNode(); + policyNode.setType(POLICY_NODE_TYPE); + policyNode.setPolicyNodeProperties(getPolicyNodeProperties(policy)); + nodeTemplate.put(policy.getNode_label(), policyNode); + } + + private static PolicyNodeProperties getPolicyNodeProperties(TypePolicy policy) { + PolicyNodeProperties policyNodeProperties = new PolicyNodeProperties(); + + GetInput policyIdGetInput = new GetInput(); + policyIdGetInput.setGet_input(policy.getNode_label() + "_policy_id"); + policyNodeProperties.setPolicyId(policyIdGetInput); + + policyNodeProperties.setPolicyModelId(policy.getPolicy_model_id()); + + return policyNodeProperties; + } + + public static ArrayList> getPolicyRelationships(ComponentSpec cs) { + ArrayList> relationships = new ArrayList<>(); + List policyList = cs.getPolicyInfo().getTypePolicyList(); + for(TypePolicy policy: policyList){ + LinkedHashMap relationship = new LinkedHashMap<>(); + relationship.put("type", POLICY_RELATIONSHIP_TYPE); + relationship.put("target", policy.getNode_label()); + relationships.add(relationship); + } + return relationships; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/exception/DatabasesNotFoundException.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/exception/DatabasesNotFoundException.java new file mode 100644 index 0000000..c9b2149 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/exception/DatabasesNotFoundException.java @@ -0,0 +1,24 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 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.exception; + +public class DatabasesNotFoundException extends RuntimeException { + public DatabasesNotFoundException(String message) { super(message);} +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/GetAttribute.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/GetAttribute.java new file mode 100644 index 0000000..56184ff --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/GetAttribute.java @@ -0,0 +1,34 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019-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.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class GetAttribute { + + @JsonProperty("get_attribute") + private Object attribute; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java index 6d5b7d7..04745dc 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java @@ -48,7 +48,8 @@ public class Appconfig { return params; } - public TreeMap> createAppconfig(TreeMap> inps, ComponentSpec cs, String override) { + public TreeMap> createAppconfig(TreeMap> inps, ComponentSpec cs, String override, + boolean isDmaap) { TreeMap> retInputs = new TreeMap>(); retInputs = inps; @@ -58,26 +59,24 @@ public class Appconfig { //set the stream publishes TreeMap streamPublishes = new TreeMap(); - int counter = 0; if(cs.getStreams().getPublishes().length != 0) { for(Publishes p: cs.getStreams().getPublishes()) { if(p.getType().equals("data_router") || p.getType().equals("data router")) { //in this case the data router information gets added to the params so for now leave it alone String config = p.getConfig_key(); DmaapObj pub = new DmaapObj(); - String name = "feed" + counter; - retInputs = pub.createOnapDmaapDRObj(retInputs, config, 'p', "feed" + counter, name); + String name = p.getConfig_key() +"_feed"; + retInputs = pub.createOnapDmaapDRObj(retInputs, config, 'p', name, name, isDmaap); pub.setType(p.getType()); streamPublishes.put(config, pub); } else if(p.getType().equals("message_router") || p.getType().equals("message router")) { String config = p.getConfig_key(); DmaapObj pub = new DmaapObj(); - String name = "topic" + counter; - retInputs = pub.createOnapDmaapMRObj(retInputs, config, 'p', "topic" + counter, name); + String name = p.getConfig_key() + "_topic"; + retInputs = pub.createOnapDmaapMRObj(retInputs, config, 'p', name, name, isDmaap); pub.setType(p.getType()); streamPublishes.put(config, pub); } - counter++; } } @@ -90,19 +89,18 @@ public class Appconfig { //in this case the data router information gets added to the params so for now leave it alone String config = s.getConfig_key(); DmaapObj sub = new DmaapObj(); - String name = "feed" + counter; - retInputs = sub.createOnapDmaapDRObj(retInputs, config, 'p', "feed" + counter, name); + String name = s.getConfig_key() + "_feed"; + retInputs = sub.createOnapDmaapDRObj(retInputs, config, 'p', name, name, isDmaap); sub.setType(s.getType()); streamSubscribes.put(config, sub); } else if(s.getType().equals("message_router") || s.getType().equals("message router")) { String config = s.getConfig_key(); DmaapObj sub = new DmaapObj(); - String name = "topic" + counter; - retInputs = sub.createOnapDmaapMRObj(retInputs, config, 's', "topic" + counter, name); + String name = s.getConfig_key() + "_topic"; + retInputs = sub.createOnapDmaapMRObj(retInputs, config, 's', name, name, isDmaap); sub.setType(s.getType()); streamSubscribes.put(config, sub); } - counter++; } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java index 06c42c5..75c79ba 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java @@ -20,11 +20,7 @@ package org.onap.blueprintgenerator.models.blueprint; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; +import java.io.*; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.TreeMap; @@ -50,7 +46,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; - +import org.yaml.snakeyaml.Yaml; @Getter @Setter @@ -194,7 +190,6 @@ public class Blueprint { System.out.println("Blueprint created"); } - public String blueprintToString() { String ret = ""; @@ -206,6 +201,6 @@ public class Blueprint { } - return ret; + return Fixes.applyFixes(ret); } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapObj.java index 10092c8..7d78e3d 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapObj.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapObj.java @@ -23,8 +23,6 @@ package org.onap.blueprintgenerator.models.blueprint; import java.util.LinkedHashMap; import java.util.TreeMap; -import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -32,12 +30,13 @@ import lombok.Getter; import lombok.Setter; @JsonInclude(value=Include.NON_NULL) @Getter @Setter public class DmaapObj { - private String dmaap_info; + private Object dmaap_info; private String type; private GetInput pass; private GetInput user; - public TreeMap> createOnapDmaapMRObj(TreeMap> inps, String config, char type, String n, String num) { + public TreeMap> createOnapDmaapMRObj(TreeMap> inps, + String config, char type, String n, String num, boolean isDmaap) { TreeMap> retInputs = new TreeMap>(); LinkedHashMap stringType = new LinkedHashMap(); stringType.put("type", "string"); @@ -45,31 +44,41 @@ public class DmaapObj { //set the dmaapinfo DmaapInfo info = new DmaapInfo(); - String infoType = "<<" + n + ">>"; - this.setDmaap_info(infoType); - - //set username - GetInput u = new GetInput(); - u.setGet_input(config + "_" + num +"_aaf_username"); - this.setUser(u); - retInputs.put(config + "_" + num +"_aaf_username", stringType); - - //set password - GetInput p = new GetInput(); - p.setGet_input(config + "_" + num +"_aaf_password"); - this.setPass(p); - retInputs.put(config + "_" + num +"_aaf_password", stringType); + if(!isDmaap){ + info.createOnapDmaapMRInfo(inps, config, type); + this.setDmaap_info(info); + } + else{ + String infoType = "<<" + n + ">>"; + this.setDmaap_info(infoType); + //set username + GetInput u = new GetInput(); + u.setGet_input(config + "_" + num +"_aaf_username"); + this.setUser(u); + retInputs.put(config + "_" + num +"_aaf_username", stringType); + //set password + GetInput p = new GetInput(); + p.setGet_input(config + "_" + num +"_aaf_password"); + this.setPass(p); + retInputs.put(config + "_" + num +"_aaf_password", stringType); + } return retInputs; } - public TreeMap> createOnapDmaapDRObj(TreeMap> inps, String config, char type, String n, String num) { + public TreeMap> createOnapDmaapDRObj(TreeMap> inps, String config, char type, String n, String num, boolean isDmaap) { TreeMap> retInputs = new TreeMap>(); retInputs = inps; //set the dmaapinfo DmaapInfo info = new DmaapInfo(); - String infoType = "<<" + n + ">>"; - this.setDmaap_info(infoType); + if(!isDmaap){ + info.createOnapDmaapDRInfo(inps, config, type); + this.setDmaap_info(info); + } + else { + String infoType = "<<" + n + ">>"; + this.setDmaap_info(infoType); + } return retInputs; } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java index 25c4c53..31df9c3 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java @@ -26,12 +26,9 @@ import java.util.TreeMap; import org.onap.blueprintgenerator.models.componentspec.Auxilary; import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; -import org.onap.blueprintgenerator.models.componentspec.HealthCheck; import org.onap.blueprintgenerator.models.componentspec.Publishes; import org.onap.blueprintgenerator.models.componentspec.Subscribes; -import org.onap.blueprintgenerator.models.componentspec.Volumes; import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams; -import org.onap.blueprintgenerator.models.onapbp.LogDirectory; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -54,8 +51,9 @@ public class Properties { private GetInput feed_name; ArrayList streams_publishes; ArrayList streams_subscribes; - private TreeMap tls_info; + private TlsInfo tls_info; private ResourceConfig resource_config; + private GetInput always_pull_image; //private boolean useExisting; public TreeMap> createOnapProperties(TreeMap> inps, ComponentSpec cs, String override) { @@ -77,18 +75,11 @@ public class Properties { this.setLocation_id(location); LinkedHashMap locMap = new LinkedHashMap(); locMap.put("type", "string"); - locMap.put("default", "central"); + locMap.put("default", ""); + retInputs.put("location_id", locMap); //set the log info - GetInput logD = new GetInput(); - logD.setGet_input("log_directory"); - TreeMap l = new TreeMap(); - l.put("log_directory", logD); - this.setLog_info(l); - LinkedHashMap logMap = new LinkedHashMap(); - logMap.put("type", "string"); - logMap.put("default", "''"); - retInputs.put("log_directory", logMap); + this.setLog_info(cs.getAuxilary().getLog_info()); //set the replicas GetInput replica = new GetInput(); @@ -108,35 +99,29 @@ public class Properties { //set the docker config Auxilary aux = cs.getAuxilary(); - if(aux.getPorts() != null) { - retInputs = aux.createPorts(retInputs); - } +// if(aux.getPorts() != null) { +// retInputs = aux.createPorts(retInputs); +// } this.setDocker_config(aux); //set the app config Appconfig app = new Appconfig(); - retInputs = app.createAppconfig(retInputs, cs, override); + retInputs = app.createAppconfig(retInputs, cs, override, false); this.setApplication_config(app); - //set the tls info - GetInput tls = new GetInput(); - tls.setGet_input("use_tls"); - GetInput cert = new GetInput(); - cert.setGet_input("cert_directory"); - TreeMap tlsInfo = new TreeMap(); - tlsInfo.put("cert_directory", cert); - tlsInfo.put("use_tls", tls); - this.setTls_info(tlsInfo); - - LinkedHashMap certMap = new LinkedHashMap(); - certMap.put("type", "string"); - certMap.put("default", "''"); - retInputs.put("cert_directory", certMap); + // set always_pull_image + this.always_pull_image = new GetInput(); + this.always_pull_image.setGet_input("always_pull_image"); + LinkedHashMap inputAlwaysPullImage = new LinkedHashMap(); + inputAlwaysPullImage.put("type", "boolean"); + inputAlwaysPullImage.put("description", "Set to true if the image should always be pulled"); + inputAlwaysPullImage.put("default", true); + retInputs.put("always_pull_image", inputAlwaysPullImage); - LinkedHashMap useMap = new LinkedHashMap(); - useMap.put("type", "boolean"); - useMap.put("default", false); - retInputs.put("use_tls", useMap); + //set the tls info + if(cs.getAuxilary().getTls_info() != null){ + addTlsInfo(cs,retInputs); + } //set the reource config ResourceConfig resource = new ResourceConfig(); @@ -160,15 +145,7 @@ public class Properties { retInputs.put("tag_version", img); //set the log info - GetInput logD = new GetInput(); - logD.setGet_input("log_directory"); - TreeMap l = new TreeMap(); - l.put("log_directory", logD); - this.setLog_info(l); - LinkedHashMap logMap = new LinkedHashMap(); - logMap.put("type", "string"); - logMap.put("default", "''"); - retInputs.put("log_directory", logMap); + this.setLog_info(cs.getAuxilary().getLog_info()); //set service component type String sType = cs.getSelf().getName(); @@ -176,24 +153,9 @@ public class Properties { this.setService_component_type(sType); //set the tls info - GetInput tls = new GetInput(); - tls.setGet_input("use_tls"); - GetInput cert = new GetInput(); - cert.setGet_input("cert_directory"); - TreeMap tlsInfo = new TreeMap(); - tlsInfo.put("cert_directory", cert); - tlsInfo.put("use_tls", tls); - this.setTls_info(tlsInfo); - - LinkedHashMap certMap = new LinkedHashMap(); - certMap.put("type", "string"); - certMap.put("default", "''"); - retInputs.put("cert_directory", certMap); - - LinkedHashMap useMap = new LinkedHashMap(); - useMap.put("type", "boolean"); - useMap.put("default", false); - retInputs.put("use_tls", useMap); + if(cs.getAuxilary().getTls_info() != null){ + addTlsInfo(cs,retInputs); + } //set the replicas GetInput replica = new GetInput(); @@ -213,34 +175,32 @@ public class Properties { //set the docker config Auxilary aux = cs.getAuxilary(); - if(aux.getPorts() != null) { - retInputs = aux.createPorts(retInputs); - } +// if(aux.getPorts() != null) { +// retInputs = aux.createPorts(retInputs); +// } this.setDocker_config(aux); //set the appconfig Appconfig app = new Appconfig(); - retInputs = app.createAppconfig(retInputs, cs, override); + retInputs = app.createAppconfig(retInputs, cs, override, true); this.setApplication_config(app); //set the stream publishes ArrayList pubStreams = new ArrayList(); - int counter = 0; if(cs.getStreams().getPublishes() != null) { for(Publishes p: cs.getStreams().getPublishes()) { if(p.getType().equals("message_router") || p.getType().equals("message router")) { - String topic = "topic" + counter; + String topic = p.getConfig_key() + "_topic"; DmaapStreams mrStreams = new DmaapStreams(); retInputs = mrStreams.createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p'); pubStreams.add(mrStreams); } else if(p.getType().equals("data_router") || p.getType().equals("data router")){ - String feed = "feed" + counter; + String feed = p.getConfig_key() + "_feed"; DmaapStreams drStreams = new DmaapStreams(); retInputs = drStreams.createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p'); pubStreams.add(drStreams); } - counter++; } } @@ -249,18 +209,17 @@ public class Properties { if(cs.getStreams().getSubscribes() != null) { for(Subscribes s: cs.getStreams().getSubscribes()) { if(s.getType().equals("message_router") || s.getType().equals("message router")) { - String topic = "topic" + counter; + String topic = s.getConfig_key() + "_topic"; DmaapStreams mrStreams = new DmaapStreams(); retInputs = mrStreams.createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's'); subStreams.add(mrStreams); } else if(s.getType().equals("data_router") || s.getType().equals("data router")){ - String feed = "feed" + counter; + String feed = s.getConfig_key() + "_feed"; DmaapStreams drStreams = new DmaapStreams(); retInputs = drStreams.createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's'); subStreams.add(drStreams); } - counter++; } } @@ -279,4 +238,18 @@ public class Properties { return retInputs; } + + private void addTlsInfo(ComponentSpec cs, TreeMap> retInputs) { + TlsInfo tlsInfo = new TlsInfo(); + tlsInfo.setCertDirectory((String) cs.getAuxilary().getTls_info().get("cert_directory")); + GetInput useTLSFlag = new GetInput(); + useTLSFlag.setGet_input("use_tls"); + tlsInfo.setUseTls(useTLSFlag); + this.setTls_info(tlsInfo); + LinkedHashMap useTlsFlagInput = new LinkedHashMap(); + useTlsFlagInput.put("type", "boolean"); + useTlsFlagInput.put("description", "flag to indicate tls enable/disable"); + useTlsFlagInput.put("default", cs.getAuxilary().getTls_info().get("use_tls")); + retInputs.put("use_tls", useTlsFlagInput); + } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java index 1c1cf6c..f81bf9a 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.TreeMap; +import org.onap.blueprintgenerator.core.PgaasNodeBuilder; +import org.onap.blueprintgenerator.models.componentspec.Auxilary; import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; import com.fasterxml.jackson.annotation.JsonInclude; @@ -34,14 +36,36 @@ import lombok.Getter; import lombok.Setter; @Getter @Setter @JsonInclude(value=Include.NON_NULL) public class StartInputs { - //private ArrayList ports; - private GetInput envs; + private ArrayList ports; + private Object envs; public TreeMap> createOnapStartInputs(TreeMap> inps, ComponentSpec cs){ - TreeMap> retInputs = new TreeMap>(); - retInputs = inps; - LinkedHashMap stringType = new LinkedHashMap(); + TreeMap> retInputs = inps; + int count = 0; + ArrayList portList = new ArrayList(); + Auxilary aux = cs.getAuxilary(); + + if (aux.getPorts() != null) { + + for(Object p : aux.getPorts()) { + String[] ports = p.toString().split(":"); + String internal + = String.format("concat: [\"%s:\", {get_input: external_port_%d}]" + , ports[0], count); + portList.add(internal); + + LinkedHashMap portType = new LinkedHashMap(); + portType.put("type", "string"); + portType.put("default", ports[1]); + retInputs.put("external_port_" + count, portType); + + count++; + } + + } + + this.setPorts(portList); // ArrayList port = new ArrayList(); // String external = ""; // if(cs.getAuxilary().getPorts() != null) { @@ -73,13 +97,22 @@ public class StartInputs { // } //set the envs - GetInput env = new GetInput(); - env.setGet_input("envs"); - this.setEnvs(env); LinkedHashMap eMap = new LinkedHashMap(); - eMap.put("default", "{}"); + if(cs.getAuxilary().getDatabases() != null){ + //set db env variables + LinkedHashMap envVars = PgaasNodeBuilder.getEnvVariables(cs.getAuxilary().getDatabases()); + this.setEnvs(envVars); + eMap.put("default", "&envs {}"); + } + else { + GetInput env = new GetInput(); + env.setGet_input("envs"); + this.setEnvs(env); + eMap.put("default", "{}"); + } retInputs.put("envs", eMap); + return retInputs; } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/TlsInfo.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/TlsInfo.java new file mode 100644 index 0000000..2130fe3 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/TlsInfo.java @@ -0,0 +1,37 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 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.models.blueprint; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class TlsInfo { + + @JsonProperty("cert_directory") + private String certDirectory; + + @JsonProperty("use_tls") + private GetInput useTls; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/pgaas/PgaasNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/pgaas/PgaasNode.java new file mode 100644 index 0000000..35f958e --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/pgaas/PgaasNode.java @@ -0,0 +1,35 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 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.models.blueprint.pgaas; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.blueprintgenerator.models.blueprint.Node; + +@Getter +@Setter +@NoArgsConstructor +public class PgaasNode extends Node { + + @JsonProperty("properties") + private PgaasNodeProperties pgaasNodeProperties; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/pgaas/PgaasNodeProperties.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/pgaas/PgaasNodeProperties.java new file mode 100644 index 0000000..709c66e --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/pgaas/PgaasNodeProperties.java @@ -0,0 +1,40 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 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.models.blueprint.pgaas; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.blueprintgenerator.models.blueprint.GetInput; + +@Getter @Setter +@NoArgsConstructor +public class PgaasNodeProperties { + + @JsonProperty("writerfqdn") + private GetInput writerfqdn; + + @JsonProperty("name") + private GetInput name; + + @JsonProperty("use_existing") + private boolean useExisting; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/policy/PolicyNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/policy/PolicyNode.java new file mode 100644 index 0000000..b4740df --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/policy/PolicyNode.java @@ -0,0 +1,34 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 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.models.blueprint.policy; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.blueprintgenerator.models.blueprint.Node; + +@Getter @Setter +@NoArgsConstructor +public class PolicyNode extends Node { + + @JsonProperty("properties") + private PolicyNodeProperties policyNodeProperties; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/policy/PolicyNodeProperties.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/policy/PolicyNodeProperties.java new file mode 100644 index 0000000..6d23b23 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/policy/PolicyNodeProperties.java @@ -0,0 +1,37 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 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.models.blueprint.policy; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.blueprintgenerator.models.blueprint.GetInput; + +@Getter @Setter +@NoArgsConstructor +public class PolicyNodeProperties { + + @JsonProperty("policy_id") + private GetInput policyId; + + @JsonProperty("policy_model_id") + private String policyModelId; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Auxilary.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Auxilary.java index 01844f9..73acda8 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Auxilary.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Auxilary.java @@ -67,6 +67,15 @@ public class Auxilary { /** The healthcheck. */ private HealthCheck healthcheck; + + /**log-directory**/ + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private TreeMap log_info; + + /**tls-info**/ + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private TreeMap tls_info; + /** The volumes. */ private Volumes[] volumes; @@ -74,6 +83,7 @@ public class Auxilary { private Policy policy; /** The ports. */ + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) private ArrayList ports; /** The reconfigs. */ @@ -84,35 +94,35 @@ public class Auxilary { private TreeMap databases; - public TreeMap> createPorts(TreeMap> inps) { - TreeMap> retInputs = inps; - LinkedHashMap portType = new LinkedHashMap(); - portType.put("type", "string"); - - ArrayList ports = new ArrayList(); - String external = ""; - boolean foundPort = false; - for(Object o: this.getPorts()) { - String internal = ""; - String p = o.toString(); - for(int i = 0; i < p.length(); i++) { - if(p.charAt(i) == ':') { - internal = '"' + internal + '"'; - internal = "concat: ['" + internal + "', {get_input: external_port}]"; - ports.add(internal); - } - if(p.charAt(i) == ':' && !foundPort) { - external = p.substring(i); - portType.put("default", external); - retInputs.put("external_port", portType); - - } - internal = internal + p.charAt(i); - - } - } - - this.setPorts(ports); - return retInputs; - } +// public TreeMap> createPorts(TreeMap> inps) { +// TreeMap> retInputs = inps; +// LinkedHashMap portType = new LinkedHashMap(); +// portType.put("type", "string"); +// +// ArrayList ports = new ArrayList(); +// String external = ""; +// boolean foundPort = false; +// for(Object o: this.getPorts()) { +// String internal = ""; +// String p = o.toString(); +// for(int i = 0; i < p.length(); i++) { +// if(p.charAt(i) == ':') { +// internal = '"' + internal + '"'; +// internal = "concat: ['" + internal + "', {get_input: external_port}]"; +// ports.add(internal); +// } +// if(p.charAt(i) == ':' && !foundPort) { +// external = p.substring(i); +// portType.put("default", external); +// retInputs.put("external_port", portType); +// +// } +// internal = internal + p.charAt(i); +// +// } +// } +// +// this.setPorts(ports); +// return retInputs; +// } } \ No newline at end of file diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ComponentSpec.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ComponentSpec.java index b6bc0a1..3876b53 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ComponentSpec.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ComponentSpec.java @@ -22,23 +22,17 @@ package org.onap.blueprintgenerator.models.componentspec; import java.io.File; import java.io.IOException; -import java.util.Map; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.NoArgsConstructor; +import org.onap.blueprintgenerator.models.componentspec.policy_info.PolicyInfo; // TODO: Auto-generated Javadoc /** @@ -90,6 +84,9 @@ public class ComponentSpec { /** The auxilary. */ private Auxilary auxilary; + + @JsonProperty("policy_info") + private PolicyInfo policyInfo; /** The artifacts. */ private Artifacts[] artifacts; @@ -119,6 +116,7 @@ public class ComponentSpec { this.setParameters(cs.getParameters()); this.setServices(cs.getServices()); this.setStreams(cs.getStreams()); + this.setPolicyInfo(cs.getPolicyInfo()); } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/policy_info/PolicyInfo.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/policy_info/PolicyInfo.java new file mode 100644 index 0000000..da746a7 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/policy_info/PolicyInfo.java @@ -0,0 +1,35 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019-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.models.componentspec.policy_info; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.List; + +@Getter @Setter +@NoArgsConstructor +public class PolicyInfo { + + @JsonProperty("policy") + private List typePolicyList; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/policy_info/TypePolicy.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/policy_info/TypePolicy.java new file mode 100644 index 0000000..038c601 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/policy_info/TypePolicy.java @@ -0,0 +1,36 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019-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.models.componentspec.policy_info; + +import com.fasterxml.jackson.annotation.JsonCreator; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter @Setter +@NoArgsConstructor +public class TypePolicy { + + private String node_label; + private String policy_id; + private String policy_model_id; + +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java index d3cff67..21eabf0 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java @@ -20,15 +20,14 @@ package org.onap.blueprintgenerator.models.dmaapbp; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.TreeMap; +import org.onap.blueprintgenerator.core.PgaasNodeBuilder; +import org.onap.blueprintgenerator.core.PolicyNodeBuilder; import org.onap.blueprintgenerator.models.blueprint.Blueprint; import org.onap.blueprintgenerator.models.blueprint.Imports; -import org.onap.blueprintgenerator.models.blueprint.Interfaces; import org.onap.blueprintgenerator.models.blueprint.Node; -import org.onap.blueprintgenerator.models.blueprint.Properties; import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; import org.onap.blueprintgenerator.models.componentspec.Publishes; import org.onap.blueprintgenerator.models.componentspec.Subscribes; @@ -68,41 +67,48 @@ public class DmaapBlueprint extends Blueprint{ //create and add the topic/feed nodes //go through the streams publishes - int counter = 0; if(cs.getStreams().getPublishes() != null) { for(Publishes p: cs.getStreams().getPublishes()) { if(p.getType().equals("message_router") || p.getType().equals("message router")) { - String topic = "topic" + counter; + String topic = p.getConfig_key() + "_topic"; DmaapNode topicNode = new DmaapNode(); inps = topicNode.createTopicNode(cs, inps, topic); nodeTemplate.put(topic, topicNode); } else if(p.getType().equals("data_router") || p.getType().equals("data router")) { - String feed = "feed" + counter; + String feed = p.getConfig_key() + "_feed"; DmaapNode feedNode = new DmaapNode(); inps = feedNode.createFeedNode(cs, inps, feed); nodeTemplate.put(feed, feedNode); } - counter++; } } //go through the stream subscribes if(cs.getStreams().getSubscribes() != null) { for(Subscribes s: cs.getStreams().getSubscribes()) { if(s.getType().equals("message_router") || s.getType().equals("message router")) { - String topic = "topic" + counter; + String topic = s.getConfig_key() + "_topic"; DmaapNode topicNode = new DmaapNode(); inps = topicNode.createTopicNode(cs, inps, topic); nodeTemplate.put(topic, topicNode); } else if(s.getType().equals("data_router") || s.getType().equals("data router")) { - String feed = "feed" + counter; + String feed = s.getConfig_key() + "_feed"; DmaapNode feedNode = new DmaapNode(); inps = feedNode.createFeedNode(cs, inps, feed); nodeTemplate.put(feed, feedNode); } - counter++; } } + //if present in component spec, populate policyNodes information in the blueprint + if(cs.getPolicyInfo() != null){ + PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inps); + } + + //if present in component spec, populate pgaasNodes information in the blueprint + if(cs.getAuxilary().getDatabases() != null){ + PgaasNodeBuilder.addPgaasNodesAndInputs(cs, nodeTemplate, inps); + } + bp.setNode_templates(nodeTemplate); bp.setInputs(inps); diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNode.java index bfa7ae9..6c74347 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNode.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNode.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.TreeMap; +import org.onap.blueprintgenerator.core.PgaasNodeBuilder; +import org.onap.blueprintgenerator.core.PolicyNodeBuilder; import org.onap.blueprintgenerator.models.blueprint.GetInput; import org.onap.blueprintgenerator.models.blueprint.Interfaces; import org.onap.blueprintgenerator.models.blueprint.Node; @@ -71,19 +73,17 @@ public class DmaapNode extends Node{ ArrayList> rets = new ArrayList(); //go through the streams publishes - int counter = 0; if(cs.getStreams().getPublishes() != null) { for(Publishes p: cs.getStreams().getPublishes()) { LinkedHashMap pubRelations = new LinkedHashMap(); if(p.getType().equals("message_router") || p.getType().equals("message router")) { pubRelations.put("type", "ccsdk.relationships.publish_events"); - pubRelations.put("target", "topic" + counter); + pubRelations.put("target", p.getConfig_key() + "_topic"); } else if(p.getType().equals("data_router") || p.getType().equals("data router")) { pubRelations.put("type", "ccsdk.relationships.publish_files"); - pubRelations.put("target", "feed" + counter); + pubRelations.put("target", p.getConfig_key() + "_feed"); } rets.add(pubRelations); - counter++; } } //go through the stream subscribes @@ -92,15 +92,26 @@ public class DmaapNode extends Node{ LinkedHashMap subRelations = new LinkedHashMap(); if(s.getType().equals("message_router") || s.getType().equals("message router")) { subRelations.put("type", "ccsdk.relationships.subscribe_to_events"); - subRelations.put("target", "topic" + counter); + subRelations.put("target", s.getConfig_key() + "_topic"); } else if(s.getType().equals("data_router") || s.getType().equals("data router")) { subRelations.put("type", "ccsdk.relationships.subscribe_to_files"); - subRelations.put("target", "feed" + counter); + subRelations.put("target", s.getConfig_key() + "_feed"); } rets.add(subRelations); - counter++; } } + + //add relationship for policy if exist + if(cs.getPolicyInfo() != null){ + ArrayList> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs); + rets.addAll(policyRelationshipsList); + } + + //add relationships and env_variables for pgaas dbs if exist + if(cs.getAuxilary().getDatabases() != null){ + ArrayList> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs); + rets.addAll(pgaasRelationshipsList); + } this.setRelationships(rets); diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapStreams.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapStreams.java index 1640a6e..b26d45d 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapStreams.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapStreams.java @@ -46,6 +46,10 @@ public class DmaapStreams { private GetInput username; private GetInput password; //private GetInput delivery_url; + + private GetInput privileged; + private GetInput decompress; + private String route; private String scheme; @@ -81,6 +85,18 @@ public class DmaapStreams { this.setPassword(password); retInputs.put(key + "_" + name + "_password", stringType); + //set privileged + GetInput priviliged = new GetInput(); + priviliged.setGet_input(key + "_" + name + "_priviliged"); + this.setPrivileged(priviliged); + retInputs.put(key + "_" + name + "_priviliged", stringType); + + //set decompress + GetInput decompress = new GetInput(); + decompress.setGet_input(key + "_" + name + "_decompress"); + this.setDecompress(decompress); + retInputs.put(key + "_" + name + "_decompress", stringType); + this.setRoute(route); this.setScheme("https"); } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapBlueprint.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapBlueprint.java index 8342020..c0ef8b3 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapBlueprint.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapBlueprint.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.TreeMap; +import org.onap.blueprintgenerator.core.PgaasNodeBuilder; +import org.onap.blueprintgenerator.core.PolicyNodeBuilder; import org.onap.blueprintgenerator.models.blueprint.Blueprint; import org.onap.blueprintgenerator.models.blueprint.Imports; import org.onap.blueprintgenerator.models.blueprint.Node; @@ -69,9 +71,20 @@ public class OnapBlueprint extends Blueprint{ nodeTemplate.put(nodeName, node); this.setNode_templates(nodeTemplate); + //if present in component spec, populate policyNode information in the blueprint + if(cs.getPolicyInfo() != null){ + PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inputs); + } + + //if present in component spec, populate pgaasNodes information in the blueprint + if(cs.getAuxilary().getDatabases() != null){ + PgaasNodeBuilder.addPgaasNodesAndInputs(cs, nodeTemplate, inputs); + } + //set the inputs this.setInputs(inputs); + Blueprint bp = new Blueprint(); bp.setImports(this.getImports()); bp.setInputs(this.getInputs()); diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapNode.java index 2b0b8c0..a3d8e3e 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapNode.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapNode.java @@ -20,9 +20,12 @@ package org.onap.blueprintgenerator.models.onapbp; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.TreeMap; +import org.onap.blueprintgenerator.core.PgaasNodeBuilder; +import org.onap.blueprintgenerator.core.PolicyNodeBuilder; import org.onap.blueprintgenerator.models.blueprint.Interfaces; import org.onap.blueprintgenerator.models.blueprint.Node; import org.onap.blueprintgenerator.models.blueprint.Properties; @@ -47,6 +50,8 @@ import lombok.NoArgsConstructor; public class OnapNode extends Node{ private TreeMap interfaces; private Properties properties; + private ArrayList> relationships; + public TreeMap> createOnapNode(TreeMap> inps, ComponentSpec cs, String override) { TreeMap> retInputs = new TreeMap>(); retInputs = inps; @@ -61,6 +66,23 @@ public class OnapNode extends Node{ //set the type this.setType("dcae.nodes.ContainerizedPlatformComponent"); + //create and set the relationships + ArrayList> rets = new ArrayList(); + + //add relationship for policy if exist + if(cs.getPolicyInfo() != null){ + ArrayList> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs); + rets.addAll(policyRelationshipsList); + } + + //add relationships and env_variables for pgaas dbs if exist + if(cs.getAuxilary().getDatabases() != null){ + ArrayList> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs); + rets.addAll(pgaasRelationshipsList); + } + + this.setRelationships(rets); + //set the properties Properties props = new Properties(); retInputs = props.createOnapProperties(retInputs, cs, override); -- cgit 1.2.3-korg