diff options
Diffstat (limited to 'mod/bpgenerator/src')
24 files changed, 830 insertions, 180 deletions
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<String> lines = new ArrayList<String>(); @@ -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<String> lines = new ArrayList<String>(); + + 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<String, Node> nodeTemplate, TreeMap<String, LinkedHashMap<String, Object>> inps) { + TreeMap<String, String> databases = cs.getAuxilary().getDatabases(); + if(databases == null){ + throw new DatabasesNotFoundException("databases section not found in componentspec"); + } + for(Map.Entry<String, String> database : databases.entrySet()){ + addPgaasNode(database, nodeTemplate); + addPgaasInputs(database, inps); + } + } + + private static void addPgaasInputs(Map.Entry<String, String> database, TreeMap<String, LinkedHashMap<String, Object>> 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<String, Object> getInputValue(String type, String description, Object defaultValue) { + LinkedHashMap<String, Object> inputValueMap = new LinkedHashMap(); + inputValueMap.put("type", type); + inputValueMap.put("description", description); + inputValueMap.put("default", defaultValue); + return inputValueMap; + } + + private static void addPgaasNode(Map.Entry<String, String> database, TreeMap<String, Node> 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<LinkedHashMap<String, String>> getPgaasNodeRelationships(ComponentSpec cs) { + ArrayList<LinkedHashMap<String, String>> relationships = new ArrayList<>(); + for(Map.Entry<String, String> database : cs.getAuxilary().getDatabases().entrySet()){ + LinkedHashMap<String, String> 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<String, Object> getEnvVariables(TreeMap<String, String> databases) { + LinkedHashMap<String, Object> envVariables = new LinkedHashMap<String, Object>(); + for(Map.Entry<String, String> 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<String, Node> nodeTemplate, TreeMap<String, LinkedHashMap<String, Object>> inps) { + List<TypePolicy> policyList = cs.getPolicyInfo().getTypePolicyList(); + for(TypePolicy policy: policyList){ + addPolicyNodesToNodeTemplate(policy, nodeTemplate); + addPolicyInputs(policy, inps); + } + } + + private static void addPolicyInputs(TypePolicy policy, TreeMap<String, LinkedHashMap<String, Object>> 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<String, Object> getInputValue(String type, String description, Object defaultValue) { + LinkedHashMap<String, Object> inputValueMap = new LinkedHashMap(); + inputValueMap.put("type", type); + inputValueMap.put("description", description); + inputValueMap.put("default", defaultValue); + return inputValueMap; + } + + private static void addPolicyNodesToNodeTemplate(TypePolicy policy, TreeMap<String, Node> 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<LinkedHashMap<String, String>> getPolicyRelationships(ComponentSpec cs) { + ArrayList<LinkedHashMap<String, String>> relationships = new ArrayList<>(); + List<TypePolicy> policyList = cs.getPolicyInfo().getTypePolicyList(); + for(TypePolicy policy: policyList){ + LinkedHashMap<String, String> 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<String, LinkedHashMap<String, Object>> createAppconfig(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) { + public TreeMap<String, LinkedHashMap<String, Object>> createAppconfig(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override, + boolean isDmaap) { TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); retInputs = inps; @@ -58,26 +59,24 @@ public class Appconfig { //set the stream publishes TreeMap<String, DmaapObj> streamPublishes = new TreeMap<String, DmaapObj>(); - 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<String, LinkedHashMap<String, Object>> createOnapDmaapMRObj(TreeMap<String, LinkedHashMap<String, Object>> inps, String config, char type, String n, String num) { + public TreeMap<String, LinkedHashMap<String, Object>> createOnapDmaapMRObj(TreeMap<String, LinkedHashMap<String, Object>> inps, + String config, char type, String n, String num, boolean isDmaap) { TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); LinkedHashMap<String, Object> 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<String, LinkedHashMap<String, Object>> createOnapDmaapDRObj(TreeMap<String, LinkedHashMap<String, Object>> inps, String config, char type, String n, String num) { + public TreeMap<String, LinkedHashMap<String, Object>> createOnapDmaapDRObj(TreeMap<String, LinkedHashMap<String, Object>> inps, String config, char type, String n, String num, boolean isDmaap) { TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); 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<DmaapStreams> streams_publishes; ArrayList<DmaapStreams> streams_subscribes; - private TreeMap<String, Object> tls_info; + private TlsInfo tls_info; private ResourceConfig resource_config; + private GetInput always_pull_image; //private boolean useExisting; public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) { @@ -77,18 +75,11 @@ public class Properties { this.setLocation_id(location); LinkedHashMap<String, Object> 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<String, Object> l = new TreeMap(); - l.put("log_directory", logD); - this.setLog_info(l); - LinkedHashMap<String, Object> 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<String, Object> tlsInfo = new TreeMap(); - tlsInfo.put("cert_directory", cert); - tlsInfo.put("use_tls", tls); - this.setTls_info(tlsInfo); - - LinkedHashMap<String, Object> 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<String, Object> inputAlwaysPullImage = new LinkedHashMap<String, Object>(); + 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<String, Object> 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<String, Object> l = new TreeMap(); - l.put("log_directory", logD); - this.setLog_info(l); - LinkedHashMap<String, Object> 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<String, Object> tlsInfo = new TreeMap(); - tlsInfo.put("cert_directory", cert); - tlsInfo.put("use_tls", tls); - this.setTls_info(tlsInfo); - - LinkedHashMap<String, Object> certMap = new LinkedHashMap(); - certMap.put("type", "string"); - certMap.put("default", "''"); - retInputs.put("cert_directory", certMap); - - LinkedHashMap<String, Object> 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<DmaapStreams> 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<String, LinkedHashMap<String, Object>> 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<String, Object> useTlsFlagInput = new LinkedHashMap<String, Object>(); + 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<String> ports; - private GetInput envs; + private ArrayList<String> ports; + private Object envs; public TreeMap<String, LinkedHashMap<String, Object>> createOnapStartInputs(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs){ - TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); - retInputs = inps; - LinkedHashMap<String, Object> stringType = new LinkedHashMap<String, Object>(); + TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; + int count = 0; + ArrayList<String> 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<String, Object> portType = new LinkedHashMap(); + portType.put("type", "string"); + portType.put("default", ports[1]); + retInputs.put("external_port_" + count, portType); + + count++; + } + + } + + this.setPorts(portList); // ArrayList<String> port = new ArrayList<String>(); // 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<String, Object> eMap = new LinkedHashMap(); - eMap.put("default", "{}"); + if(cs.getAuxilary().getDatabases() != null){ + //set db env variables + LinkedHashMap<String, Object> 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<String, Object> log_info; + + /**tls-info**/ + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private TreeMap<String, Object> 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<Object> ports; /** The reconfigs. */ @@ -84,35 +94,35 @@ public class Auxilary { private TreeMap<String, String> databases; - public TreeMap<String, LinkedHashMap<String, Object>> createPorts(TreeMap<String, LinkedHashMap<String, Object>> inps) { - TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; - LinkedHashMap<String, Object> portType = new LinkedHashMap(); - portType.put("type", "string"); - - ArrayList<Object> 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<String, LinkedHashMap<String, Object>> createPorts(TreeMap<String, LinkedHashMap<String, Object>> inps) { +// TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; +// LinkedHashMap<String, Object> portType = new LinkedHashMap(); +// portType.put("type", "string"); +// +// ArrayList<Object> 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<TypePolicy> 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<LinkedHashMap<String, String>> rets = new ArrayList(); //go through the streams publishes - int counter = 0; if(cs.getStreams().getPublishes() != null) { for(Publishes p: cs.getStreams().getPublishes()) { LinkedHashMap<String, String> 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<String, String> 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<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs); + rets.addAll(policyRelationshipsList); + } + + //add relationships and env_variables for pgaas dbs if exist + if(cs.getAuxilary().getDatabases() != null){ + ArrayList<LinkedHashMap<String, String>> 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<String, Interfaces> interfaces; private Properties properties; + private ArrayList<LinkedHashMap<String, String>> relationships; + public TreeMap<String, LinkedHashMap<String, Object>> createOnapNode(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) { TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); 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<LinkedHashMap<String, String>> rets = new ArrayList(); + + //add relationship for policy if exist + if(cs.getPolicyInfo() != null){ + ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs); + rets.addAll(policyRelationshipsList); + } + + //add relationships and env_variables for pgaas dbs if exist + if(cs.getAuxilary().getDatabases() != null){ + ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs); + rets.addAll(pgaasRelationshipsList); + } + + this.setRelationships(rets); + //set the properties Properties props = new Properties(); retInputs = props.createOnapProperties(retInputs, cs, override); |