diff options
author | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2020-09-30 11:39:25 +0200 |
---|---|---|
committer | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2020-09-30 14:47:59 +0200 |
commit | 04f13ef80c6e79d8c0b7b3fa1faeeaa0def1584e (patch) | |
tree | 894d637bc63f782439c068c0cbd0991a96a17643 /mod/bpgenerator/src | |
parent | f51b3e1a957ede6c263d0c3634f36c7fcfbb95ff (diff) |
Adjust BP-gen to correctly support DFC component spec - types
- Update relationshipsType and feedNode values in DmaapNode
- Create a class for hardcoded values
- Update unit tests
Issue-ID: DCAEGEN2-2459
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
Change-Id: Ic5dc91844b4aefcf7d3d9d25c866a60e63875deb
Diffstat (limited to 'mod/bpgenerator/src')
8 files changed, 405 insertions, 358 deletions
diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/BpConstants.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/BpConstants.java new file mode 100644 index 0000000..ac14b47 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/BpConstants.java @@ -0,0 +1,40 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia 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; + +public final class BpConstants { + + private BpConstants() {} + + public static final String CLOUDIFY_DSL_1_3 = "cloudify_dsl_1_3"; + + public static final String CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP = "dcae.nodes.ContainerizedServiceComponentUsingDmaap"; + public static final String CONTENERIZED_SERVICE_COMPONENT = "dcae.nodes.ContainerizedServiceComponent"; + public static final String FEED = "dcaegen2.nodes.Feed"; + public static final String TOPIC = "dcaegen2.nodes.Topic"; + public static final String PUBLISH_EVENTS = "dcaegen2.relationships.publish_events"; + public static final String PUBLISH_FILES = "dcaegen2.relationships.publish_files"; + public static final String SUBSCRIBE_TO_EVENTS = "dcaegen2.relationships.subscribe_to_events"; + public static final String SUBSCRIBE_TO_FILES = "dcaegen2.relationships.subscribe_to_files"; + + public static final String TOSCA_DATATYPES_ROOT = "tosca.datatypes.Root"; + public static final String TOSCA_NODES_ROOT = "tosca.nodes.Root"; + public static final String TOSCA_SIMPLE_YAML = "tosca_simple_yaml_1_0_0"; +} 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 84c5fc5..0c8f8a9 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 @@ -38,6 +38,7 @@ import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMes import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.joinUnderscore; import static org.onap.blueprintgenerator.models.blueprint.Imports.createDmaapImports; import static org.onap.blueprintgenerator.models.blueprint.Imports.createImportsFromFile; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CLOUDIFY_DSL_1_3; public class DmaapBlueprint extends Blueprint { @@ -48,7 +49,7 @@ public class DmaapBlueprint extends Blueprint { Blueprint blueprint = new Blueprint(); //set tosca definition - blueprint.setTosca_definitions_version("cloudify_dsl_1_3"); + blueprint.setTosca_definitions_version(CLOUDIFY_DSL_1_3); //set the description blueprint.setDescription(componentSpec.getSelf().getDescription()); 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 e28e49a..9069f82 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 @@ -46,6 +46,14 @@ import lombok.Setter; import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType; import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMessageRouterType; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.FEED; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOPIC; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.PUBLISH_EVENTS; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.PUBLISH_FILES; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_EVENTS; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_FILES; + @JsonIgnoreProperties(ignoreUnknown = true) @Getter @Setter @@ -60,7 +68,7 @@ public class DmaapNode extends Node { TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; //set the type - this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap"); + this.setType(CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP); //create the interface Interfaces inter = new Interfaces(); @@ -116,7 +124,7 @@ public class DmaapNode extends Node { stringType.put("type", "string"); //set the type - this.setType("ccsdk.nodes.Feed"); + this.setType(FEED); //create and set the properties Properties props = new Properties(); @@ -137,7 +145,7 @@ public class DmaapNode extends Node { stringType.put("type", "string"); //set the type - this.setType("ccsdk.nodes.Topic"); + this.setType(TOPIC); //create and set the properties Properties props = new Properties(); @@ -154,10 +162,10 @@ public class DmaapNode extends Node { private LinkedHashMap<String, String> createTypeAndTargetPubRelations(Publishes publishes) { LinkedHashMap<String, String> pubRelations = new LinkedHashMap<>(); if (isMessageRouterType(publishes.getType())) { - pubRelations.put("type", "ccsdk.relationships.publish_events"); + pubRelations.put("type", PUBLISH_EVENTS); pubRelations.put("target", publishes.getConfig_key() + "_topic"); } else if (isDataRouterType(publishes.getType())) { - pubRelations.put("type", "ccsdk.relationships.publish_files"); + pubRelations.put("type", PUBLISH_FILES); pubRelations.put("target", publishes.getConfig_key() + "_feed"); } return pubRelations; @@ -166,10 +174,10 @@ public class DmaapNode extends Node { private LinkedHashMap<String, String> createTypeAndTargetSubRelations(Subscribes subscribes) { LinkedHashMap<String, String> subRelations = new LinkedHashMap<>(); if (isMessageRouterType(subscribes.getType())) { - subRelations.put("type", "ccsdk.relationships.subscribe_to_events"); + subRelations.put("type", SUBSCRIBE_TO_EVENTS); subRelations.put("target", subscribes.getConfig_key() + "_topic"); } else if (isDataRouterType(subscribes.getType())) { - subRelations.put("type", "ccsdk.relationships.subscribe_to_files"); + subRelations.put("type", SUBSCRIBE_TO_FILES); subRelations.put("target", subscribes.getConfig_key() + "_feed"); } return subRelations; 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 9f6f560..d9f3c16 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 @@ -1,4 +1,4 @@ -/**============LICENSE_START======================================================= +/*============LICENSE_START======================================================= org.onap.dcae ================================================================================ Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. @@ -22,10 +22,14 @@ package org.onap.blueprintgenerator.models.onapbp; -import java.util.ArrayList; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CLOUDIFY_DSL_1_3; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import java.util.LinkedHashMap; import java.util.TreeMap; - +import lombok.Getter; +import lombok.Setter; import org.onap.blueprintgenerator.core.PgaasNodeBuilder; import org.onap.blueprintgenerator.core.PolicyNodeBuilder; import org.onap.blueprintgenerator.models.blueprint.Blueprint; @@ -33,67 +37,59 @@ import org.onap.blueprintgenerator.models.blueprint.Imports; import org.onap.blueprintgenerator.models.blueprint.Node; import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -import lombok.Getter; import lombok.Setter; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@Getter @Setter -@JsonInclude(value=Include.NON_NULL) +@Getter +@Setter +@JsonInclude(value = Include.NON_NULL) -public class OnapBlueprint extends Blueprint{ - public Blueprint createOnapBlueprint(ComponentSpec cs, String importPath, String override) { +public class OnapBlueprint extends Blueprint { - //create the inputs that will be used - TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<String, LinkedHashMap<String, Object>>(); - //set the tosca definition which is the same for everything - this.setTosca_definitions_version("cloudify_dsl_1_3"); + public Blueprint createOnapBlueprint(ComponentSpec cs, String importPath, String override) { - //set the imports - if(!"".equals(importPath)) { - Imports imps = new Imports(); - this.setImports(imps.createImportsFromFile(importPath)); - } - else { - Imports imps = new Imports(); - this.setImports(imps.createOnapImports()); - } + //create the inputs that will be used + TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + //set the tosca definition which is the same for everything + this.setTosca_definitions_version(CLOUDIFY_DSL_1_3); - //create the node template - TreeMap<String, Node> nodeTemplate = new TreeMap<String, Node>(); - String nodeName = cs.getSelf().getName(); + //set the imports + if (!"".equals(importPath)) { + Imports imps = new Imports(); + this.setImports(imps.createImportsFromFile(importPath)); + } else { + Imports imps = new Imports(); + this.setImports(imps.createOnapImports()); + } - //create the onap node that will be used - OnapNode node = new OnapNode(); - inputs = node.createOnapNode(inputs, cs, override); - nodeTemplate.put(nodeName, node); - this.setNode_templates(nodeTemplate); + //create the node template + TreeMap<String, Node> nodeTemplate = new TreeMap<String, Node>(); + String nodeName = cs.getSelf().getName(); - //if present in component spec, populate policyNode information in the blueprint - if(cs.getPolicyInfo() != null){ - PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inputs); - } + //create the onap node that will be used + OnapNode node = new OnapNode(); + inputs = node.createOnapNode(inputs, cs, override); + nodeTemplate.put(nodeName, node); + this.setNode_templates(nodeTemplate); - //if present in component spec, populate pgaasNodes information in the blueprint - if(cs.getAuxilary().getDatabases() != null){ - PgaasNodeBuilder.addPgaasNodesAndInputs(cs, nodeTemplate, inputs); - } + //if present in component spec, populate policyNode information in the blueprint + if (cs.getPolicyInfo() != null) { + PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inputs); + } - //set the inputs - this.setInputs(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()); - bp.setNode_templates(this.getNode_templates()); - bp.setTosca_definitions_version(this.getTosca_definitions_version()); + Blueprint bp = new Blueprint(); + bp.setImports(this.getImports()); + bp.setInputs(this.getInputs()); + bp.setNode_templates(this.getNode_templates()); + bp.setTosca_definitions_version(this.getTosca_definitions_version()); - return bp; + return bp; - } + } } 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 b0d1302..9daea56 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 @@ -1,8 +1,10 @@ -/**============LICENSE_START======================================================= +/*============LICENSE_START======================================================= org.onap.dcae ================================================================================ Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - ================================================================================ + ================================================================================ + Modifications Copyright (c) 2020 Nokia. 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 @@ -20,10 +22,18 @@ package org.onap.blueprintgenerator.models.onapbp; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CONTENERIZED_SERVICE_COMPONENT; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.TreeMap; - +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import org.onap.blueprintgenerator.core.PgaasNodeBuilder; import org.onap.blueprintgenerator.core.PolicyNodeBuilder; import org.onap.blueprintgenerator.models.blueprint.Interfaces; @@ -31,60 +41,54 @@ import org.onap.blueprintgenerator.models.blueprint.Node; import org.onap.blueprintgenerator.models.blueprint.Properties; import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; import lombok.Setter; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - @JsonIgnoreProperties(ignoreUnknown = true) -@Getter @Setter -@EqualsAndHashCode(callSuper=false) +@Getter +@Setter +@EqualsAndHashCode(callSuper = false) @NoArgsConstructor -@JsonInclude(value=Include.NON_NULL) - -public class OnapNode extends Node{ - - 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; - - //create and set the interfaces - Interfaces inter = new Interfaces(); - retInputs = inter.createInterface(retInputs, cs); - TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>(); - interfaces.put("cloudify.interfaces.lifecycle", inter); - this.setInterfaces(interfaces); - - //set the type - this.setType("dcae.nodes.ContainerizedServiceComponent"); - - //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); - this.setProperties(props); - - return retInputs; - } +@JsonInclude(value = Include.NON_NULL) + +public class OnapNode extends Node { + + 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; + + //create and set the interfaces + Interfaces inter = new Interfaces(); + retInputs = inter.createInterface(retInputs, cs); + TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>(); + interfaces.put("cloudify.interfaces.lifecycle", inter); + this.setInterfaces(interfaces); + + //set the type + this.setType(CONTENERIZED_SERVICE_COMPONENT); + + //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); + this.setProperties(props); + + return retInputs; + } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java index 9c9bd51..81bc440 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java @@ -1,37 +1,28 @@ -/**============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========================================================= +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Modifications Copyright (c) 2020 Nokia. 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.policymodel; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.TreeMap; - -import org.onap.blueprintgenerator.models.blueprint.Node; -import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; -import org.onap.blueprintgenerator.models.componentspec.Parameters; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_SIMPLE_YAML; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonGenerationException; @@ -39,101 +30,107 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; - +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.TreeMap; import lombok.Getter; import lombok.Setter; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.Parameters; -@Getter @Setter +@Getter +@Setter @JsonInclude(JsonInclude.Include.NON_NULL) public class PolicyModel { - - private String tosca_definition_version; - private TreeMap<String, PolicyModelNode> node_types; - private TreeMap<String, PolicyModelNode> data_types; - - public ArrayList<PolicyModel> createPolicyModels(ComponentSpec cs, String filePath) { - ArrayList<PolicyModel> models = new ArrayList(); - Parameters[] params = cs.getParameters(); - - ArrayList<String> groups = new ArrayList<String>(); - groups = getModelGroups(params); - - for(String s: groups) { - PolicyModel model = new PolicyModel(); - model = model.createPolicyModel(s, params); - //models.add(model); - policyModelToYaml(filePath, model, s); - } - + + private String tosca_definition_version; + private TreeMap<String, PolicyModelNode> node_types; + private TreeMap<String, PolicyModelNode> data_types; + + public ArrayList<PolicyModel> createPolicyModels(ComponentSpec cs, String filePath) { + ArrayList<PolicyModel> models = new ArrayList(); + Parameters[] params = cs.getParameters(); + + ArrayList<String> groups = new ArrayList<String>(); + groups = getModelGroups(params); + + for (String s : groups) { + PolicyModel model = new PolicyModel(); + model = model.createPolicyModel(s, params); + //models.add(model); + policyModelToYaml(filePath, model, s); + } + // for(PolicyModel p: models) { // policyModelToYaml(filePath, p); // } - return models; - } - - public ArrayList<String> getModelGroups(Parameters[] params) { - ArrayList<String> groups = new ArrayList(); - - for(Parameters p: params) { - if(p.isPolicy_editable()) { - if(groups.isEmpty()) { - groups.add(p.getPolicy_group()); - } else { - if(!groups.contains(p.getPolicy_group())) { - groups.add(p.getPolicy_group()); - } - } - } - } - - return groups; - } - - public PolicyModel createPolicyModel(String s, Parameters[] params) { - PolicyModel model = new PolicyModel(); - model.setTosca_definition_version("tosca_simple_yaml_1_0_0"); - - PolicyModelNode node = new PolicyModelNode(); - String hasEntryScheme = node.createNodeType(s, params); - String nodeTypeName = "onap.policy." + s; - TreeMap<String, PolicyModelNode> nodeType = new TreeMap(); - nodeType.put(nodeTypeName, node); - model.setNode_types(nodeType); - - if(!hasEntryScheme.equals("")) { - PolicyModelNode data = new PolicyModelNode(); - TreeMap<String, PolicyModelNode> dataType = data.createDataTypes(hasEntryScheme, params); - model.setData_types(dataType); - } - - return model; - } - - public void policyModelToYaml(String path, PolicyModel p, String name) { - File outputFile; - String filePath = path + "/" + name + ".yml"; - File policyFile = new File(filePath); - ObjectMapper policyMapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); - outputFile = new File(path, name + ".yml"); - outputFile.getParentFile().mkdirs(); - - try { - PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true))); - } catch (IOException e) { - e.printStackTrace(); - } - - try { - policyMapper.writeValue(outputFile, p); - } catch (JsonGenerationException e) { - e.printStackTrace(); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println("model " + name + " created"); - } + return models; + } + + public ArrayList<String> getModelGroups(Parameters[] params) { + ArrayList<String> groups = new ArrayList(); + + for (Parameters p : params) { + if (p.isPolicy_editable()) { + if (groups.isEmpty()) { + groups.add(p.getPolicy_group()); + } else { + if (!groups.contains(p.getPolicy_group())) { + groups.add(p.getPolicy_group()); + } + } + } + } + + return groups; + } + + public PolicyModel createPolicyModel(String s, Parameters[] params) { + PolicyModel model = new PolicyModel(); + model.setTosca_definition_version(TOSCA_SIMPLE_YAML); + + PolicyModelNode node = new PolicyModelNode(); + String hasEntryScheme = node.createNodeType(s, params); + String nodeTypeName = "onap.policy." + s; + TreeMap<String, PolicyModelNode> nodeType = new TreeMap(); + nodeType.put(nodeTypeName, node); + model.setNode_types(nodeType); + + if (!hasEntryScheme.equals("")) { + PolicyModelNode data = new PolicyModelNode(); + TreeMap<String, PolicyModelNode> dataType = data.createDataTypes(hasEntryScheme, params); + model.setData_types(dataType); + } + + return model; + } + + public void policyModelToYaml(String path, PolicyModel p, String name) { + File outputFile; + String filePath = path + "/" + name + ".yml"; + File policyFile = new File(filePath); + ObjectMapper policyMapper = new ObjectMapper( + new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); + outputFile = new File(path, name + ".yml"); + outputFile.getParentFile().mkdirs(); + + try { + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true))); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + policyMapper.writeValue(outputFile, p); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("model " + name + " created"); + } } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java index 56d1d13..89321de 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java @@ -1,8 +1,10 @@ -/**============LICENSE_START======================================================= +/*============LICENSE_START======================================================= org.onap.dcae ================================================================================ Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - ================================================================================ + ================================================================================ + Modifications Copyright (c) 2020 Nokia. 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 @@ -20,128 +22,126 @@ package org.onap.blueprintgenerator.models.policymodel; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_DATATYPES_ROOT; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_NODES_ROOT; + +import com.fasterxml.jackson.annotation.JsonInclude; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.TreeMap; - -import org.onap.blueprintgenerator.models.blueprint.Node; +import lombok.Getter; +import lombok.Setter; import org.onap.blueprintgenerator.models.componentspec.EntrySchemaObj; import org.onap.blueprintgenerator.models.componentspec.Parameters; import org.onap.blueprintgenerator.models.componentspec.PolicySchemaObj; -import com.fasterxml.jackson.annotation.JsonInclude; - -import lombok.Getter; -import lombok.Setter; - -@Getter @Setter +@Getter +@Setter @JsonInclude(JsonInclude.Include.NON_NULL) public class PolicyModelNode { - - private String derived_from; - private TreeMap<String, PolicyProperties> properties; - - public String createNodeType(String policyName, Parameters[] params) { - String hasEntrySchema = ""; - - TreeMap<String, PolicyProperties> props = new TreeMap(); - for(Parameters p: params) { - if(p.getPolicy_group() != null) { - if(p.getPolicy_group().equals(policyName)) { - String name = p.getName(); - String type = p.getType(); - PolicyProperties polProps = new PolicyProperties(); - if(p.getPolicy_schema() != null) { - polProps.setType("map"); - HashMap<String, String> entrySchema = new HashMap(); - entrySchema.put("type", "onap.datatypes." + name); - //ArrayList<String> entrySchema = new ArrayList<String>(); - //entrySchema.add("type: onap.data." + name); - polProps.setEntry_schema(entrySchema); - hasEntrySchema = name; - props.put(name, polProps); - } - else { - polProps.setType(type); - props.put(name, polProps); - } - } - } - } - - this.setDerived_from("tosca.datatypes.Root"); - this.setProperties(props); - return hasEntrySchema; - } - - public TreeMap<String, PolicyModelNode> createDataTypes(String param, Parameters[] parameters) { - TreeMap<String, PolicyModelNode> dataType = new TreeMap<String, PolicyModelNode>(); - - PolicyModelNode node = new PolicyModelNode(); - node.setDerived_from("tosca.datatypes.Root"); - - TreeMap<String, PolicyProperties> properties = new TreeMap(); - - Parameters par = new Parameters(); - for(Parameters p: parameters) { - if(p.getName().equals(param)) { - par = p; - break; - } - } - - for(PolicySchemaObj pol: par.getPolicy_schema()) { - if(pol.getEntry_schema() != null) { - PolicyProperties prop = new PolicyProperties(); - prop.setType("map"); - HashMap<String, String> schema = new HashMap(); - schema.put("type", "onap.datatypes." + pol.getName()); + + private String derived_from; + private TreeMap<String, PolicyProperties> properties; + + public String createNodeType(String policyName, Parameters[] params) { + String hasEntrySchema = ""; + + TreeMap<String, PolicyProperties> props = new TreeMap(); + for (Parameters p : params) { + if (p.getPolicy_group() != null) { + if (p.getPolicy_group().equals(policyName)) { + String name = p.getName(); + String type = p.getType(); + PolicyProperties polProps = new PolicyProperties(); + if (p.getPolicy_schema() != null) { + polProps.setType("map"); + HashMap<String, String> entrySchema = new HashMap(); + entrySchema.put("type", "onap.datatypes." + name); + //ArrayList<String> entrySchema = new ArrayList<String>(); + //entrySchema.add("type: onap.data." + name); + polProps.setEntry_schema(entrySchema); + hasEntrySchema = name; + props.put(name, polProps); + } else { + polProps.setType(type); + props.put(name, polProps); + } + } + } + } + + this.setDerived_from(TOSCA_DATATYPES_ROOT); + this.setProperties(props); + return hasEntrySchema; + } + + public TreeMap<String, PolicyModelNode> createDataTypes(String param, Parameters[] parameters) { + TreeMap<String, PolicyModelNode> dataType = new TreeMap<String, PolicyModelNode>(); + + PolicyModelNode node = new PolicyModelNode(); + node.setDerived_from(TOSCA_DATATYPES_ROOT); + + TreeMap<String, PolicyProperties> properties = new TreeMap(); + + Parameters par = new Parameters(); + for (Parameters p : parameters) { + if (p.getName().equals(param)) { + par = p; + break; + } + } + + for (PolicySchemaObj pol : par.getPolicy_schema()) { + if (pol.getEntry_schema() != null) { + PolicyProperties prop = new PolicyProperties(); + prop.setType("map"); + HashMap<String, String> schema = new HashMap(); + schema.put("type", "onap.datatypes." + pol.getName()); // prop.setType("list"); // ArrayList<String> schema = new ArrayList(); // schema.add("type: onap.data." + pol.getName()); - prop.setEntry_schema(schema); - properties.put(pol.getName(), prop); - dataType = translateEntrySchema(dataType, pol.getEntry_schema(), pol.getName()); - } - else { - PolicyProperties prop = new PolicyProperties(); - prop.setType(pol.getType()); - properties.put(pol.getName(), prop); - } - } - - node.setProperties(properties); - dataType.put("onap.datatypes." + param, node); - return dataType; - } - - private TreeMap<String, PolicyModelNode> translateEntrySchema(TreeMap<String, PolicyModelNode> dataType, EntrySchemaObj[] entry, String name){ - TreeMap<String, PolicyModelNode> data = dataType; - PolicyModelNode node = new PolicyModelNode(); - node.setDerived_from("tosca.nodes.Root"); - TreeMap<String, PolicyProperties> properties = new TreeMap<String, PolicyProperties>(); - - for(EntrySchemaObj e: entry) { - if(e.getEntry_schema() != null) { - PolicyProperties prop = new PolicyProperties(); - prop.setType("list"); - ArrayList<String> schema = new ArrayList<String>(); - schema.add("type: onap.datatypes." + e.getName()); - prop.setEntry_schema(schema); - properties.put(e.getName(), prop); - data = translateEntrySchema(data, e.getEntry_schema(), e.getName()); - node.setProperties(properties); - } else { - PolicyProperties prop = new PolicyProperties(); - prop.setType(e.getType()); - properties.put(e.getName(), prop); - node.setProperties(properties); - } - } - - dataType.put("onap.datatypes." + name, node); - return data; - } + prop.setEntry_schema(schema); + properties.put(pol.getName(), prop); + dataType = translateEntrySchema(dataType, pol.getEntry_schema(), pol.getName()); + } else { + PolicyProperties prop = new PolicyProperties(); + prop.setType(pol.getType()); + properties.put(pol.getName(), prop); + } + } + + node.setProperties(properties); + dataType.put("onap.datatypes." + param, node); + return dataType; + } + + private TreeMap<String, PolicyModelNode> translateEntrySchema(TreeMap<String, PolicyModelNode> dataType, + EntrySchemaObj[] entry, String name) { + TreeMap<String, PolicyModelNode> data = dataType; + PolicyModelNode node = new PolicyModelNode(); + node.setDerived_from(TOSCA_NODES_ROOT); + TreeMap<String, PolicyProperties> properties = new TreeMap<String, PolicyProperties>(); + + for (EntrySchemaObj e : entry) { + if (e.getEntry_schema() != null) { + PolicyProperties prop = new PolicyProperties(); + prop.setType("list"); + ArrayList<String> schema = new ArrayList<String>(); + schema.add("type: onap.datatypes." + e.getName()); + prop.setEntry_schema(schema); + properties.put(e.getName(), prop); + data = translateEntrySchema(data, e.getEntry_schema(), e.getName()); + node.setProperties(properties); + } else { + PolicyProperties prop = new PolicyProperties(); + prop.setType(e.getType()); + properties.put(e.getName(), prop); + node.setProperties(properties); + } + } + + dataType.put("onap.datatypes." + name, node); + return data; + } } diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java index d117cd5..6936393 100644 --- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java +++ b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java @@ -21,9 +21,13 @@ package org.onap.blueprintgenerator.models.dmaapbp; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.FEED; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_EVENTS; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_FILES; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOPIC; import java.util.Map; import java.util.TreeMap; @@ -37,8 +41,6 @@ import org.onap.blueprintgenerator.models.componentspec.Subscribes; public class DmaapNodeTest { - private static final String EXPECTED_DMAAP_NODE_TYPE = "dcae.nodes.ContainerizedServiceComponentUsingDmaap"; - private static final String DATA_ROUTER_TYPE = "data_router"; private static final String MESSAGE_ROUTER_TYPE = "message_router"; @@ -59,7 +61,7 @@ public class DmaapNodeTest { DmaapNode dmaapNode = new DmaapNode(); dmaapNode.createDmaapNode(mockedComponentSpec, new TreeMap<>(), ""); - assertEquals(EXPECTED_DMAAP_NODE_TYPE, dmaapNode.getType()); + assertEquals(CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP, dmaapNode.getType()); } @Test @@ -112,7 +114,7 @@ public class DmaapNodeTest { Map<String, String> relationship = dmaapNode.getRelationships().get(0); - assertNotNull(relationship.get(TYPE)); + assertEquals(SUBSCRIBE_TO_EVENTS, relationship.get(TYPE)); assertNotNull(relationship.get(TARGET)); } @@ -130,7 +132,7 @@ public class DmaapNodeTest { Map<String, String> relationship = dmaapNode.getRelationships().get(0); - assertNotNull(relationship.get(TYPE)); + assertEquals(SUBSCRIBE_TO_FILES, relationship.get(TYPE)); assertNotNull(relationship.get(TARGET)); } @@ -139,9 +141,9 @@ public class DmaapNodeTest { ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships(); DmaapNode dmaapNode = new DmaapNode(); - dmaapNode.createFeedNode(componentSpec, new TreeMap<>() ,""); + dmaapNode.createFeedNode(componentSpec, new TreeMap<>(), ""); - assertTrue(dmaapNode.getType().endsWith("Feed")); + assertEquals(FEED, dmaapNode.getType()); } @Test @@ -150,9 +152,9 @@ public class DmaapNodeTest { ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships(); DmaapNode dmaapNode = new DmaapNode(); - dmaapNode.createTopicNode(componentSpec, new TreeMap<>() ,""); + dmaapNode.createTopicNode(componentSpec, new TreeMap<>(), ""); - assertTrue(dmaapNode.getType().endsWith("Topic")); + assertEquals(TOPIC, dmaapNode.getType()); } private Publishes[] createSamplePublishes(String type) { @@ -196,6 +198,5 @@ public class DmaapNodeTest { when(componentSpec.getPolicyInfo()).thenReturn(null); return componentSpec; - } } |