X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=mod%2Fbpgenerator%2Fonap%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fblueprintgenerator%2Fservice%2Fcommon%2FPgaasNodeService.java;h=e7dd0ab74d9b9f95fab0845f3eaa0748500d1a91;hb=72c2d38329865afa6692454b4fb90ab6f8a70638;hp=ff457017f767ec7f25b7e99bedba09e89bb08ec8;hpb=3f0bbed7e1b96d1982d55e26c27169885aa3067c;p=dcaegen2%2Fplatform.git diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PgaasNodeService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PgaasNodeService.java index ff45701..e7dd0ab 100644 --- a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PgaasNodeService.java +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PgaasNodeService.java @@ -4,6 +4,7 @@ * * org.onap.dcae * * ================================================================================ * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2021 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. @@ -26,7 +27,6 @@ package org.onap.blueprintgenerator.service.common; import org.onap.blueprintgenerator.constants.Constants; import org.onap.blueprintgenerator.exception.DatabasesNotFoundException; - import org.onap.blueprintgenerator.model.common.Node; import org.onap.blueprintgenerator.model.common.PgaasNode; import org.onap.blueprintgenerator.model.common.GetInput; @@ -45,30 +45,43 @@ import java.util.List; /** * @author : Ravi Mantena - * @date 10/16/2020 - * Application: ONAP - Blueprint Generator - * Common ONAP Service used by ONAP and DMAAP Blueprint to add Pgaas Node + * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to add Pgaas Node */ - - @Service public class PgaasNodeService { @Autowired private BlueprintHelperService blueprintHelperService; - // method to create Pgaas Nodes and Inputs for Databases - public void addPgaasNodesAndInputs(OnapComponentSpec onapComponentSpec, Map nodeTemplate, Map> inputs) { + /** + * Creates Pgaas Nodes and Inputs for Databases + * + * @param onapComponentSpec OnapComponentSpec + * @param nodeTemplate Node template + * @param inputs Inputs + * @return + */ + public void addPgaasNodesAndInputs( + OnapComponentSpec onapComponentSpec, + Map nodeTemplate, + Map> inputs) { Map databases = onapComponentSpec.getAuxilary().getDatabases(); - for(Map.Entry database : databases.entrySet()){ - addPgaasNode(database, nodeTemplate); - addPgaasInputs(database, inputs); + if (databases != null) { + for (Map.Entry database : databases.entrySet()) { + addPgaasNode(database, nodeTemplate); + addPgaasInputs(database, inputs); + } } } - private void addPgaasInputs(Map.Entry database, Map> inputs) { - inputs.put(database.getKey() + Constants.NAME_POSTFIX, blueprintHelperService.createStringInput( "db name", "")); - inputs.put(database.getKey() + Constants.WRITER_FQDN_POSTFIX, blueprintHelperService.createStringInput( "db writerfqdn", "")); + private void addPgaasInputs( + Map.Entry database, Map> inputs) { + inputs.put( + database.getKey() + Constants.NAME_POSTFIX, + blueprintHelperService.createStringInput("db name", "")); + inputs.put( + database.getKey() + Constants.WRITER_FQDN_POSTFIX, + blueprintHelperService.createStringInput("db writerfqdn", "")); } private void addPgaasNode(Map.Entry database, Map nodeTemplate) { @@ -76,7 +89,7 @@ public class PgaasNodeService { String dbName = database.getKey(); pgaasNode.setType(Constants.PGAAS_NODE_TYPE); pgaasNode.setPgaasNodeProperties(buildPgaasNodeProperties(dbName)); - nodeTemplate.put(dbName + Constants.PGAAS_NODE_NAME_POSTFIX , pgaasNode); + nodeTemplate.put(dbName + Constants.PGAAS_NODE_NAME_POSTFIX, pgaasNode); } private PgaasNodeProperties buildPgaasNodeProperties(String dbName) { @@ -95,10 +108,17 @@ public class PgaasNodeService { return pgaasNodeProperties; } - // method to create Pgaas Node Relationships for Databases - public List> getPgaasNodeRelationships(OnapComponentSpec onapComponentSpec) { + /** + * Creates Pgaas Nodes Relationships for Databases + * + * @param onapComponentSpec OnapComponentSpec + * @return + */ + public List> getPgaasNodeRelationships( + OnapComponentSpec onapComponentSpec) { List> relationships = new ArrayList<>(); - for(Map.Entry database : onapComponentSpec.getAuxilary().getDatabases().entrySet()){ + for (Map.Entry database : + onapComponentSpec.getAuxilary().getDatabases().entrySet()) { Map relationship = new LinkedHashMap<>(); relationship.put("type", Constants.DB_RELATIONSHIP_TYPE); relationship.put("target", database.getKey() + Constants.PGAAS_NODE_NAME_POSTFIX); @@ -107,10 +127,15 @@ public class PgaasNodeService { return relationships; } - // method to create Env Variables for Databases + /** + * Creates Env Variables for Databases + * + * @param databases Database + * @return + */ public Map getEnvVariables(Map databases) { Map envVariables = new LinkedHashMap<>(); - for(Map.Entry database : databases.entrySet()){ + for (Map.Entry database : databases.entrySet()) { String name = database.getKey().toUpperCase(); envVariables.put("<<", "*envs"); @@ -118,21 +143,25 @@ public class PgaasNodeService { nameValue.setBpInputName(name.toLowerCase() + Constants.NAME_POSTFIX); envVariables.put(name + "_DB_NAME", nameValue); - GetAttribute adminHostValue = buildGetAttributeValue(name.toLowerCase(), "admin", "host"); - envVariables.put( name.toUpperCase() + "_DB_ADMIN_HOST", adminHostValue); + GetAttribute 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 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); + GetAttribute adminPasswordValue = + buildGetAttributeValue(name.toLowerCase(), "admin", "password"); + envVariables.put(name.toUpperCase() + "_DB_ADMIN_PASS", adminPasswordValue); } return envVariables; } private GetAttribute buildGetAttributeValue(String dbName, String owner, String type) { GetAttribute attribute = new GetAttribute(); - attribute.setAttribute(Arrays.asList(dbName + Constants.PGAAS_NODE_NAME_POSTFIX, owner, type)); + attribute + .setAttribute(Arrays.asList(dbName + Constants.PGAAS_NODE_NAME_POSTFIX, owner, type)); return attribute; } }