From 39a4e0cb1b805470ad85ed4cf4fdeb69610ae98c Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Tue, 18 Jul 2017 20:46:42 +0300 Subject: [SDC] rebase 1710 Change-Id: I07fced02f40a57700d9d35ed3ba498bca351fb13 Signed-off-by: Michael Lando --- .../ci/tests/datatypes/enums/ArtifactTypeEnum.java | 2 +- .../ci/tests/execute/imports/ExportToscaTest.java | 28 +- .../execute/imports/ToscaTemplateVersionTest.java | 67 ++ .../sdc/ci/tests/utils/ToscaParserUtils.java | 50 +- .../sdc/ci/tests/utils/rest/ResponseParser.java | 2 +- .../loadBalancerTestVersion.yml | 6 + .../asdctool/impl/validator/ValidationToolBL.java | 43 ++ .../validator/config/ValidationConfigManager.java | 39 ++ .../config/ValidationToolConfiguration.java | 133 ++++ .../executers/ServiceValidatorExecuter.java | 36 + .../TopologyTemplateValidatorExecuter.java | 92 +++ .../validator/executers/ValidatorExecuter.java | 15 + .../validator/executers/VfValidatorExecuter.java | 32 + .../validator/tasks/ServiceValidationTask.java | 25 + .../tasks/TopologyTemplateValidationTask.java | 13 + .../impl/validator/tasks/VfValidationTask.java | 25 + .../tasks/artifacts/ArtifactValidationUtils.java | 106 +++ .../artifacts/ServiceArtifactValidationTask.java | 26 + .../tasks/artifacts/VfArtifactValidationTask.java | 28 + .../impl/validator/utils/ElementTypeEnum.java | 59 ++ .../impl/validator/utils/ReportManager.java | 93 +++ .../impl/validator/utils/ValidationTaskResult.java | 45 ++ .../sdc/asdctool/main/ValidationTool.java | 47 ++ .../src/main/resources/scripts/validationTool.sh | 31 + .../be/components/impl/ArtifactsBusinessLogic.java | 10 +- .../be/components/impl/ComponentBusinessLogic.java | 82 +-- .../sdc/be/components/impl/ImportUtils.java | 5 +- .../be/components/impl/ResourceBusinessLogic.java | 760 ++++++++++----------- .../be/components/impl/ResourceImportManager.java | 17 +- .../lifecycle/LifecycleBusinessLogic.java | 2 +- .../be/servlets/AbstractValidationsServlet.java | 2 +- .../sdc/be/servlets/RepresentationUtils.java | 36 + .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 2 +- .../src/main/resources/config/configuration.yaml | 4 + .../scripts/import/tosca/typesToUpgrade.json | 7 + .../import/tosca/upgradeHeatAndNormativeTypes.py | 110 +++ .../scripts/import/tosca/upgradeNormative.py | 47 +- .../be/components/ResourceImportManagerTest.java | 8 +- .../components/impl/ResourceBusinessLogicTest.java | 6 +- .../servlets/AbstractValidationsServletTest.java | 49 +- .../resources/config/catalog-be/configuration.yaml | 3 + .../sdc/be/dao/cassandra/ArtifactAccessor.java | 19 + .../sdc/be/dao/cassandra/ArtifactCassandraDao.java | 11 + .../java/org/openecomp/sdc/be/model/CsarInfo.java | 89 +++ .../org/openecomp/sdc/be/model/ImportCsarInfo.java | 73 -- .../operations/ToscaElementLifecycleOperation.java | 16 +- catalog-ui/src/app/app.ts | 17 +- .../style/component-instances-nodes-style.ts | 4 +- .../composition-graph.directive.ts | 60 +- .../composition-graph/composition-graph.html | 7 + .../utils/composition-graph-general-utils.ts | 8 + .../utils/composition-graph-nodes-utils.ts | 15 + catalog-ui/src/app/models/components/component.ts | 21 +- catalog-ui/src/app/models/components/resource.ts | 23 +- catalog-ui/src/app/ng2/app.module.ts | 8 +- .../inputs-table/inputs-table.component.less | 2 +- .../properties-table.component.less | 6 +- .../shared/search-bar/search-bar.component.html | 5 + .../shared/search-bar/search-bar.component.less | 58 ++ .../ng2/shared/search-bar/search-bar.component.ts | 30 + .../search-with-autocomplete.component.html | 6 + .../search-with-autocomplete.component.less | 35 + .../search-with-autocomplete.component.ts | 30 + .../shared/notification-custom-template.html | 14 + .../tabs/composition/composition-view-model.ts | 6 +- .../tabs/composition/composition-view.html | 4 +- .../workspace/tabs/composition/composition.less | 65 ++ .../tabs/artifacts/artifacts-view-model.ts | 18 +- .../composition/tabs/artifacts/artifacts-view.html | 2 +- .../composition/tabs/details/details-view.html | 4 +- .../src/app/view-models/workspace/workspace.less | 3 + catalog-ui/src/assets/styles/app.less | 1 + .../assets/styles/images/sprites/sprite-global.png | Bin 93182 -> 98178 bytes .../src/assets/styles/notification-template.less | 53 ++ catalog-ui/src/assets/styles/sprite.less | 25 +- .../src/assets/styles/svg/source/fit-all.svg | 5 + catalog-ui/src/assets/styles/svg/source/minus.svg | 5 + catalog-ui/src/assets/styles/svg/source/plus.svg | 5 + .../assets/styles/svg/source/search-magnify.svg | 5 + .../CytoscapeEdgeEditation.js | 21 +- .../openecomp/sdc/common/api/ArtifactTypeEnum.java | 2 +- .../templates/default/BE-configuration.yaml.erb | 3 + .../templates/default/BE-configuration.yaml.erb | 3 + .../sdc/ci/tests/datatypes/DataTestIdEnum.java | 2 +- .../tests/execute/sanity/CatalogLeftPanelTest.java | 2 +- .../sdc/ci/tests/execute/setup/DriverFactory.java | 2 +- 86 files changed, 2302 insertions(+), 684 deletions(-) create mode 100644 asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ToscaTemplateVersionTest.java create mode 100644 asdc-tests/src/test/resources/CI/tests/importToscaResourceByCreateUrl/loadBalancerTestVersion.yml create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/ServiceValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ValidationTaskResult.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java create mode 100644 asdctool/src/main/resources/scripts/validationTool.sh create mode 100644 catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json create mode 100644 catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py create mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactAccessor.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/CsarInfo.java delete mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/ImportCsarInfo.java create mode 100644 catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.html create mode 100644 catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.less create mode 100644 catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.ts create mode 100644 catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.html create mode 100644 catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.less create mode 100644 catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.ts create mode 100644 catalog-ui/src/app/view-models/shared/notification-custom-template.html create mode 100644 catalog-ui/src/assets/styles/notification-template.less create mode 100644 catalog-ui/src/assets/styles/svg/source/fit-all.svg create mode 100644 catalog-ui/src/assets/styles/svg/source/minus.svg create mode 100644 catalog-ui/src/assets/styles/svg/source/plus.svg create mode 100644 catalog-ui/src/assets/styles/svg/source/search-magnify.svg diff --git a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/datatypes/enums/ArtifactTypeEnum.java b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/datatypes/enums/ArtifactTypeEnum.java index eafdf80a0a..724fca2b4d 100644 --- a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/datatypes/enums/ArtifactTypeEnum.java +++ b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/datatypes/enums/ArtifactTypeEnum.java @@ -33,7 +33,7 @@ public enum ArtifactTypeEnum { TOSCA_TEMPLATE("TOSCA_TEMPLATE"), TOSCA_CSAR("TOSCA_CSAR"), VNF_CATALOG("VNF_CATALOG"), VF_LICENSE("VF_LICENSE"), VENDOR_LICENSE("VENDOR_LICENSE"), MODEL_INVENTORY_PROFILE("MODEL_INVENTORY_PROFILE"), MODEL_QUERY_SPEC("MODEL_QUERY_SPEC"), APPC_CONFIG("APPC_CONFIG"), HEAT_NESTED("HEAT_NESTED"), HEAT_ARTIFACT("HEAT_ARTIFACT"), VF_MODULES_METADATA("VF_MODULES_METADATA"), LIFECYCLE_OPERATIONS("LIFECYCLE_OPERATIONS"), - VES_EVENTS("VES_EVENTS"), PERFORMANCE_COUNTER("PERFORMANCE_COUNTER"), + VES_EVENTS("VES_EVENTS"), PERFORMANCE_COUNTER("PERFORMANCE_COUNTER"), UCPE_LAYER_2_CONFIGURATION("UCPE_LAYER_2_CONFIGURATION"), // DCAE Artifacts DCAE_TOSCA("DCAE_TOSCA"), DCAE_JSON("DCAE_JSON"), DCAE_POLICY("DCAE_POLICY"), DCAE_DOC("DCAE_DOC"), DCAE_EVENT("DCAE_EVENT"), DCAE_INVENTORY_TOSCA("DCAE_INVENTORY_TOSCA"), DCAE_INVENTORY_JSON("DCAE_INVENTORY_JSON"), DCAE_INVENTORY_POLICY("DCAE_INVENTORY_POLICY"), DCAE_INVENTORY_DOC("DCAE_INVENTORY_DOC"), diff --git a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java index 5f0cbaf1c7..2edd3284c4 100644 --- a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java +++ b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ExportToscaTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.openecomp.sdc.ci.tests.utils.ToscaParserUtils.downloadAndParseToscaTemplate; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -67,7 +68,9 @@ import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum; import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum; import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils; import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.general.ImportUtils; import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils; import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils; import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils; @@ -362,7 +365,7 @@ public class ExportToscaTest extends ComponentBaseTest { JsonParser jsonParser = new JsonParser(); - for (Map.Entry> entry : componentInstancesProperties.entrySet()) { + for (Entry> entry : componentInstancesProperties.entrySet()) { Optional findFirst = componentInstances.stream().filter(ci -> ci.getUniqueId().equals(entry.getKey())).findFirst(); assertTrue(findFirst.isPresent()); @@ -627,29 +630,6 @@ public class ExportToscaTest extends ComponentBaseTest { assertEquals("validate input description", inputDef.getDescription(), (String) inputInFile.get("description")); } - private Map downloadAndParseToscaTemplate(User sdncModifierDetails, Component createdComponent) throws Exception { - String artifactUniqeId = createdComponent.getToscaArtifacts().get("assettoscatemplate").getUniqueId(); - RestResponse toscaTemplate; - - if (createdComponent.getComponentType() == ComponentTypeEnum.RESOURCE) { - toscaTemplate = ArtifactRestUtils.downloadResourceArtifactInternalApi(createdComponent.getUniqueId(), sdncModifierDetails, artifactUniqeId); - - } else { - toscaTemplate = ArtifactRestUtils.downloadServiceArtifactInternalApi(createdComponent.getUniqueId(), sdncModifierDetails, artifactUniqeId); - } - BaseRestUtils.checkSuccess(toscaTemplate); - - ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(toscaTemplate.getResponse(), ArtifactUiDownloadData.class); - byte[] fromUiDownload = artifactUiDownloadData.getBase64Contents().getBytes(); - byte[] decodeBase64 = Base64.decodeBase64(fromUiDownload); - Yaml yaml = new Yaml(); - - InputStream inputStream = new ByteArrayInputStream(decodeBase64); - - Map load = (Map) yaml.load(inputStream); - return load; - } - public ArtifactDefinition findMasterArtifact(Map deplymentArtifact, List artifacts, List artifactsList) { for (String artifactUid : artifactsList) { for (Entry entry : deplymentArtifact.entrySet()) { diff --git a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ToscaTemplateVersionTest.java b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ToscaTemplateVersionTest.java new file mode 100644 index 0000000000..1fbcd428ca --- /dev/null +++ b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/ToscaTemplateVersionTest.java @@ -0,0 +1,67 @@ +package org.openecomp.sdc.ci.tests.execute.imports; + +import org.junit.rules.TestName; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.config.Config; +import org.openecomp.sdc.ci.tests.datatypes.ImportReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.general.ImportUtils; +import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; +import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.File; +import java.nio.file.Paths; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class ToscaTemplateVersionTest extends ComponentBaseTest { + + private static final String EXPECTED_EXPORT_TOSCA_VERSION = "tosca_simple_yaml_1_1"; + private static final String YML_110_VERSION = "loadBalancerTestVersion.yml"; + public static TestName name = new TestName(); + private String SOURCE_DIR; + private static String WORK_DIR = "importToscaResourceByCreateUrl"; + + public ToscaTemplateVersionTest() { + super(name, ToscaTemplateVersionTest.class.getName()); + } + + @BeforeMethod + public void setUp() throws Exception { + SOURCE_DIR = config.getResourceConfigDir(); + } + + @Test + public void verifyExportYamlVersion() throws Exception { + User defaultUser = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciYamlVersionTest", ServiceCategoriesEnum.MOBILITY, defaultUser.getUserId()); + RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, defaultUser); + BaseRestUtils.checkCreateResponse(serviceResponse); + Service service = ResponseParser.parseToObjectUsingMapper(serviceResponse.getResponse(), Service.class); + Map load = ToscaParserUtils.downloadAndParseToscaTemplate(defaultUser, service); + assertEquals(ToscaParserUtils.getToscaVersion(load), EXPECTED_EXPORT_TOSCA_VERSION); + } + + @Test + public void testVerifyImportYamlVersion_1_1_0() throws Exception { + String testResourcesPath = Paths.get(SOURCE_DIR, WORK_DIR).toString(); + ImportReqDetails importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(ElementFactory.getDefaultImportResource(), testResourcesPath, + YML_110_VERSION); + RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), + null); + BaseRestUtils.checkCreateResponse(importResourceResponse); + + } +} diff --git a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/utils/ToscaParserUtils.java b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/utils/ToscaParserUtils.java index e5928b327f..5449a5fc6b 100644 --- a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/utils/ToscaParserUtils.java +++ b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/utils/ToscaParserUtils.java @@ -22,19 +22,30 @@ package org.openecomp.sdc.ci.tests.utils; import static org.testng.AssertJUnit.assertNotNull; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.apache.commons.codec.binary.Base64; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.model.ArtifactUiDownloadData; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.ci.tests.datatypes.enums.ToscaKeysEnum; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition; import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaNodeTemplatesTopologyTemplateDefinition; import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaNodeTypesDefinition; import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaPropertiesNodeTemplatesDefinition; import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaRequirementsNodeTemplatesDefinition; import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaTopologyTemplateDefinition; +import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; import org.openecomp.sdc.ci.tests.utils.validation.CsarValidationUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +65,29 @@ public class ToscaParserUtils { return null; } + public static Map downloadAndParseToscaTemplate(User sdncModifierDetails, Component createdComponent) throws Exception { + String artifactUniqeId = createdComponent.getToscaArtifacts().get("assettoscatemplate").getUniqueId(); + RestResponse toscaTemplate; + + if (createdComponent.getComponentType() == ComponentTypeEnum.RESOURCE) { + toscaTemplate = ArtifactRestUtils.downloadResourceArtifactInternalApi(createdComponent.getUniqueId(), sdncModifierDetails, artifactUniqeId); + + } else { + toscaTemplate = ArtifactRestUtils.downloadServiceArtifactInternalApi(createdComponent.getUniqueId(), sdncModifierDetails, artifactUniqeId); + } + BaseRestUtils.checkSuccess(toscaTemplate); + + ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(toscaTemplate.getResponse(), ArtifactUiDownloadData.class); + byte[] fromUiDownload = artifactUiDownloadData.getBase64Contents().getBytes(); + byte[] decodeBase64 = Base64.decodeBase64(fromUiDownload); + Yaml yaml = new Yaml(); + + InputStream inputStream = new ByteArrayInputStream(decodeBase64); + + Map load = (Map) yaml.load(inputStream); + return load; + } + public static ToscaDefinition getToscaDefinitionObjectByCsarUuid(String csarUUID) throws Exception { String TOSCAMetaLocation = "TOSCA-Metadata/TOSCA.meta"; @@ -70,7 +104,7 @@ public class ToscaParserUtils { ToscaKeysEnum toscaKey = ToscaKeysEnum.findToscaKey((String) key); switch (toscaKey) { case TOSCA_DEFINITION_VERSION: - getToscaDefinitionVersion(toscaMap, toscaDefinition); + enrichToscaDefinitionWithToscaVersion(toscaMap, toscaDefinition); break; case NODE_TYPES: getToscaNodeTypes(toscaMap, toscaDefinition); @@ -92,19 +126,23 @@ public class ToscaParserUtils { } - public static void getToscaDefinitionVersion(Map toscaMap, ToscaDefinition toscaDefinition) { + public static void enrichToscaDefinitionWithToscaVersion(Map toscaMap, ToscaDefinition toscaDefinition) { if (toscaMap.get("tosca_definitions_version") != null) { - toscaDefinition.setToscaDefinitionVersion((String) toscaMap.get("tosca_definitions_version")); + toscaDefinition.setToscaDefinitionVersion(getToscaVersion(toscaMap)); } } + public static String getToscaVersion(Map toscaMap) { + return (String) toscaMap.get("tosca_definitions_version"); + } + // spec 90 page public static void getToscaNodeTypes(Map toscaMap, ToscaDefinition toscaDefinition) { @SuppressWarnings("unchecked") Map> nodeTypes = (Map>) toscaMap.get("node_types"); List listToscaNodeTypes = new ArrayList<>(); if (nodeTypes != null) { - for (Map.Entry> entry : nodeTypes.entrySet()) { + for (Entry> entry : nodeTypes.entrySet()) { ToscaNodeTypesDefinition toscaNodeTypes = new ToscaNodeTypesDefinition(); String toscaNodeName = entry.getKey(); toscaNodeTypes.setName(toscaNodeName); @@ -179,7 +217,7 @@ public class ToscaParserUtils { @SuppressWarnings("unchecked") List> requirementList = (List>) node.get("requirements"); for (int i = 0; i < requirementList.size(); i++) { - for (Map.Entry requirement : requirementList.get(i).entrySet()) { + for (Entry requirement : requirementList.get(i).entrySet()) { ToscaRequirementsNodeTemplatesDefinition toscaRequirement = new ToscaRequirementsNodeTemplatesDefinition(); if (requirement.getKey() != null) { String requirementName = requirement.getKey(); @@ -237,7 +275,7 @@ public class ToscaParserUtils { if (node.get("properties") != null) { @SuppressWarnings("unchecked") Map properties = (Map) node.get("properties"); - for (Map.Entry property : properties.entrySet()) { + for (Entry property : properties.entrySet()) { ToscaPropertiesNodeTemplatesDefinition toscaProperty = new ToscaPropertiesNodeTemplatesDefinition(); String propertyName = property.getKey(); Object propertyValue = property.getValue(); diff --git a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java index 39f2c04b55..6ffb2b29b5 100644 --- a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java +++ b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java @@ -436,7 +436,7 @@ public class ResponseParser { } public static List getDerivedListFromJson(RestResponse res) throws JSONException { - JSONArray listFromJson = getListFromJson(res, "derivedList"); + JSONArray listFromJson = getListFromJson(res, "derivedFrom"); List lst = new ArrayList(); for (int i = 0; i < listFromJson.length(); i++) { lst.add(listFromJson.getString(i)); diff --git a/asdc-tests/src/test/resources/CI/tests/importToscaResourceByCreateUrl/loadBalancerTestVersion.yml b/asdc-tests/src/test/resources/CI/tests/importToscaResourceByCreateUrl/loadBalancerTestVersion.yml new file mode 100644 index 0000000000..6b68dd00d4 --- /dev/null +++ b/asdc-tests/src/test/resources/CI/tests/importToscaResourceByCreateUrl/loadBalancerTestVersion.yml @@ -0,0 +1,6 @@ +tosca_definitions_version: tosca_simple_yaml_1_1_0 +node_types: + org.openecomp.resource.vfc.nodes.LoadBalancerTest1: + derived_from: tosca.nodes.Root + properties: + diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java new file mode 100644 index 0000000000..a57a237e76 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java @@ -0,0 +1,43 @@ +package org.openecomp.sdc.asdctool.impl.validator; + +import org.openecomp.sdc.asdctool.impl.validator.executers.ValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.*; + +/** + * Created by chaya on 7/3/2017. + */ +@Component +public class ValidationToolBL { + + private static Logger log = LoggerFactory.getLogger(ValidationToolBL.class.getName()); + + @Autowired + protected List validators; + + @Autowired + protected ReportManager reportManager; + + private boolean allValid = true; + + + public boolean validateAll() { + for (ValidatorExecuter validatorExec: validators) { + System.out.println("ValidatorExecuter "+validatorExec.getName()+" started"); + if (!validatorExec.executeValidations()) { + allValid = false; + System.out.println("ValidatorExecuter "+validatorExec.getName()+" finished with warnings"); + } + else { + System.out.println("ValidatorExecuter "+validatorExec.getName()+" finished successfully"); + } + } + return allValid; + } + +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java new file mode 100644 index 0000000000..facb9d70f2 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java @@ -0,0 +1,39 @@ +package org.openecomp.sdc.asdctool.impl.validator.config; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * Created by chaya on 7/4/2017. + */ +public class ValidationConfigManager { + + private static Properties prop = new Properties(); + + public static String getOutputFilePath() { + return outputFilePath; + } + + public static void setOutputFilePath(String outputFilePath) { + ValidationConfigManager.outputFilePath = outputFilePath; + } + + private static String outputFilePath; + + public static Properties setValidationConfiguration(String path){ + InputStream input = null; + try { + input = new FileInputStream(path); + prop.load(input); + } catch (IOException ex) { + ex.printStackTrace(); + } + return prop; + } + + public static Properties getValidationConfiguration() { + return prop; + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java new file mode 100644 index 0000000000..87b27c7369 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java @@ -0,0 +1,133 @@ +package org.openecomp.sdc.asdctool.impl.validator.config; + +import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationTitanStrategy; +import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ArtifactValidationUtils; +import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ServiceArtifactValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.VfArtifactValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.executers.VfValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL; +import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.openecomp.sdc.be.dao.DAOTitanStrategy; +import org.openecomp.sdc.be.dao.TitanClientStrategy; +import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; +import org.openecomp.sdc.be.dao.jsongraph.TitanDao; +import org.openecomp.sdc.be.dao.titan.TitanGraphClient; +import org.openecomp.sdc.be.model.DerivedNodeTypeResolver; +import org.openecomp.sdc.be.model.jsontitan.operations.*; +import org.openecomp.sdc.be.model.operations.api.ToscaDefinitionPathCalculator; +import org.openecomp.sdc.be.model.operations.impl.ToscaDefinitionPathCalculatorImpl; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Created by chaya on 7/3/2017. + */ +@Configuration +public class ValidationToolConfiguration { + + @Bean + public ServiceValidatorExecuter basicServiceValidator() { return new ServiceValidatorExecuter();} + + @Bean + public VfArtifactValidationTask vfArtifactValidationTask() { return new VfArtifactValidationTask(); } + + @Bean + public ServiceArtifactValidationTask serviceArtifactValidationTask() { return new ServiceArtifactValidationTask();} + + @Bean + public ValidationToolBL validationToolBL() { + return new ValidationToolBL(); + } + + @Bean + public VfValidatorExecuter basicVfValidator() { return new VfValidatorExecuter();} + + @Bean + public ReportManager reportManager() { return new ReportManager();} + + @Bean(name = "artifact-cassandra-dao") + public ArtifactCassandraDao artifactCassandraDao() { + return new ArtifactCassandraDao(); + } + + @Bean + public ArtifactValidationUtils artifactValidationUtils() { return new ArtifactValidationUtils();} + + @Bean(name = "groups-operation") + public GroupsOperation jsonGroupsOperation() { + return new GroupsOperation(); + } + + @Bean(name = "cassandra-client") + public CassandraClient cassandraClient() { + return new CassandraClient(); + } + + @Bean(name = "dao-titan-strategy") + public TitanClientStrategy daoStrategy() { + return new DAOTitanStrategy(); + } + + @Bean(name = "migration-titan-client", initMethod = "createGraph") + public TitanGraphClient titanMigrationClient(@Qualifier("dao-titan-strategy") TitanClientStrategy titanClientStrategy) { + return new TitanGraphClient(titanClientStrategy); + } + + @Bean(name = "tosca-operation-facade") + public ToscaOperationFacade toscaOperationFacade() { + return new ToscaOperationFacade(); + } + + @Bean(name = "node-type-operation") + public NodeTypeOperation nodeTypeOperation(@Qualifier("mig-derived-resolver") DerivedNodeTypeResolver migrationDerivedNodeTypeResolver) { + return new NodeTypeOperation(migrationDerivedNodeTypeResolver); + } + + @Bean(name = "topology-template-operation") + public TopologyTemplateOperation topologyTemplateOperation() { + return new TopologyTemplateOperation(); + } + + @Bean(name = "node-template-operation") + public NodeTemplateOperation nodeTemplateOperation() { + return new NodeTemplateOperation(); + } + + @Bean(name = "mig-derived-resolver") + public DerivedNodeTypeResolver migrationDerivedNodeTypeResolver() { + return new ByToscaNameDerivedNodeTypeResolver(); + } + + @Bean(name = "titan-dao") + public TitanDao titanDao(@Qualifier("migration-titan-client") TitanGraphClient titanGraphClient) { + return new TitanDao(titanGraphClient); + } + + @Bean(name = "category-operation") + public CategoryOperation categoryOperation() { + return new CategoryOperation(); + } + + @Bean(name = "tosca-path-calculator") + public ToscaDefinitionPathCalculator pathCalculator() { + return new ToscaDefinitionPathCalculatorImpl(); + } + + @Bean(name = "artifacts-operation") + public ArtifactsOperations artifactsOperation() { + return new ArtifactsOperations(); + } + + @Bean(name = "tosca-data-operation") + public ToscaDataOperation toscaDataOperation() { + return new ToscaDataOperation(); + } + + @Bean(name = "tosca-element-lifecycle-operation") + public ToscaElementLifecycleOperation toscaElementLifecycleOperation() { + return new ToscaElementLifecycleOperation(); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java new file mode 100644 index 0000000000..817ab15418 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java @@ -0,0 +1,36 @@ +package org.openecomp.sdc.asdctool.impl.validator.executers; + +import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * Created by chaya on 7/4/2017. + */ +public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter { + + @Autowired(required = false) + List tasks = new ArrayList<>(); + + private static Logger log = LoggerFactory.getLogger(VfValidatorExecuter.class.getName()); + + public ServiceValidatorExecuter() { + setName("SERVICE_VALIDATOR"); + } + + @Override + public boolean executeValidations() { + List vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE); + return validate(tasks, vertices); + } + + @Override + public String getName() { + return super.getName(); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java new file mode 100644 index 0000000000..16a479dc75 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java @@ -0,0 +1,92 @@ +package org.openecomp.sdc.asdctool.impl.validator.executers; + +import fj.data.Either; +import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.TitanDao; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation; +import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * Created by chaya on 7/3/2017. + */ +public class TopologyTemplateValidatorExecuter { + + private static Logger log = LoggerFactory.getLogger(VfValidatorExecuter.class.getName()); + + @Autowired + protected TitanDao titanDao; + + @Autowired + protected ToscaOperationFacade toscaOperationFacade; + + @Autowired + protected TopologyTemplateOperation topologyTemplateOperation; + + protected String name; + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void reportValidateTaskStatus(TopologyTemplateValidationTask validationTask, boolean success, GraphVertex vertexScanned) { + ReportManager.reportValidationTaskStatus(vertexScanned, validationTask.getTaskName(), validationTask.getTaskResultStatus(), success); + } + + protected List getVerticesToValidate(ComponentTypeEnum type) { + Map props = new EnumMap<>(GraphPropertyEnum.class); + props.put(GraphPropertyEnum.COMPONENT_TYPE, type.name()); + if(type.equals(ComponentTypeEnum.RESOURCE)) { + props.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF); + } + + Either, TitanOperationStatus> results = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props); + if (results.isRight()) { + System.out.println("getVerticesToValidate failed "+ results.right().value()); + return new ArrayList(); + } + System.out.println("getVerticesToValidate: "+results.left().value().size()+" vertices to scan"); + return results.left().value(); + } + + protected boolean validate(List tasks, List vertices) { + ReportManager.reportStartValidatorRun(getName(), vertices.size()); + Set failedTasks = new HashSet<>(); + Set successTasks = new HashSet<>(); + boolean successAllVertices = true; + for (GraphVertex vertex: vertices) { + boolean successAllTasks = true; + for (TopologyTemplateValidationTask task: tasks) { + ReportManager.reportStartTaskRun(vertex, task.getTaskName()); + boolean success = task.validate(vertex); + if (!success) { + failedTasks.add(task.getTaskName()); + successAllVertices = false; + successAllTasks = false; + } else { + successTasks.add(task.getTaskName()); + } + reportValidateTaskStatus(task, success, vertex); + } + String componentScanStatus = successAllTasks? "success" : "failed"; + System.out.println("Topology Template "+vertex.getUniqueId()+" Validation finished with "+componentScanStatus); + } + ReportManager.reportValidatorTypeSummary(getName(), failedTasks, successTasks); + return successAllVertices; + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java new file mode 100644 index 0000000000..8281d1f353 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java @@ -0,0 +1,15 @@ +package org.openecomp.sdc.asdctool.impl.validator.executers; + +import org.openecomp.sdc.asdctool.impl.validator.utils.ElementTypeEnum; +import org.openecomp.sdc.be.model.Component; + +import java.util.List; + +/** + * Created by chaya on 7/3/2017. + */ +public interface ValidatorExecuter { + + boolean executeValidations(); + String getName(); +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java new file mode 100644 index 0000000000..913a36fbd4 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java @@ -0,0 +1,32 @@ +package org.openecomp.sdc.asdctool.impl.validator.executers; + +import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * Created by chaya on 7/3/2017. + */ +public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter { + + @Autowired(required = false) + private List tasks = new ArrayList<>(); + + public VfValidatorExecuter() { + setName("BASIC_VF_VALIDATOR"); + } + + @Override + public boolean executeValidations() { + List vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE); + return validate(tasks, vertices); + } + + @Override + public String getName() { + return super.getName(); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/ServiceValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/ServiceValidationTask.java new file mode 100644 index 0000000000..89444768a4 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/ServiceValidationTask.java @@ -0,0 +1,25 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks; + +/** + * Created by chaya on 7/5/2017. + */ +public abstract class ServiceValidationTask implements TopologyTemplateValidationTask { + protected String name = ""; + protected String taskStatus = "NOT_STARTED"; + + @Override + public String getTaskName() { + return this.name; + } + + @Override + public String getTaskResultStatus() { + return this.taskStatus; + } + + @Override + public void setTaskResultStatus(String status) { + this.taskStatus = status; + } + +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java new file mode 100644 index 0000000000..6ca012546b --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java @@ -0,0 +1,13 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks; + +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; + +/** + * Created by chaya on 7/5/2017. + */ +public interface TopologyTemplateValidationTask { + boolean validate(GraphVertex vertex); + String getTaskName(); + String getTaskResultStatus(); + void setTaskResultStatus(String status); +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java new file mode 100644 index 0000000000..ec621b86ae --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java @@ -0,0 +1,25 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks; + +/** + * Created by chaya on 7/5/2017. + */ +public abstract class VfValidationTask implements TopologyTemplateValidationTask { + protected String taskStatus = "NOT_STARTED"; + protected String name = ""; + + @Override + public String getTaskName() { + return this.name; + } + + @Override + public String getTaskResultStatus() { + return taskStatus; + } + + @Override + public void setTaskResultStatus(String status) { + this.taskStatus = status; + } + +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java new file mode 100644 index 0000000000..dfdeec8c67 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java @@ -0,0 +1,106 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; + +import fj.data.Either; +import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; +import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement; +import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * Created by chaya on 7/6/2017. + */ +public class ArtifactValidationUtils { + + @Autowired + private ArtifactCassandraDao artifactCassandraDao; + + @Autowired + private TopologyTemplateOperation topologyTemplateOperation; + + public boolean validateArtifactsAreInCassandra(GraphVertex vertex, String taskName, List artifacts) { + boolean allArtifactsExist = true; + for(ArtifactDataDefinition artifact:artifacts) { + boolean isArtifactExist = isArtifcatInCassandra(artifact.getEsId()); + String status = isArtifactExist ? "Artifact " + artifact.getEsId() + " is in Cassandra" : + "Artifact " + artifact.getEsId() + " doesn't exist in Cassandra"; + ReportManager.writeReportLineToFile(status); + if (!isArtifactExist) { + allArtifactsExist = false; + } + } + return allArtifactsExist; + } + + public boolean isArtifcatInCassandra(String uniueId) { + Either countOfArtifactsEither = + artifactCassandraDao.getCountOfArtifactById(uniueId); + if (countOfArtifactsEither.isRight()) { + // print to console + System.out.print("Failed to retrieve artifact with id: "+uniueId+" from Cassandra" ); + return false; + } + Long count = countOfArtifactsEither.left().value(); + if (count <1) { + //System.out.print("Artifact "+uniueId+" count is: "+count); + return false; + } + return true; + } + + public List addRelevantArtifacts(Map artifactsMap) { + List artifacts = new ArrayList<>(); + Optional.ofNullable(artifactsMap).orElse(Collections.emptyMap()).forEach( (key, dataDef) -> { + if (dataDef.getEsId() != null && !dataDef.getEsId().isEmpty()) { + artifacts.add(dataDef); + } + }); + return artifacts; + } + + public boolean validateTopologyTemplateArtifacts(GraphVertex vertex, String taskName) { + ComponentParametersView paramView = new ComponentParametersView(); + paramView.disableAll(); + paramView.setIgnoreArtifacts(false); + paramView.setIgnoreComponentInstances(false); + Either toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView); + if (toscaElementEither.isRight()) { + return false; + } + TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value(); + Map deploymentArtifacts = element.getDeploymentArtifacts(); + Map artifacts = element.getArtifacts(); + Map apiArtifacts = element.getServiceApiArtifacts(); + Map instanceArtifacts = element.getInstanceArtifacts(); + Map instanceDeploymentArtifacts = element.getInstDeploymentArtifacts(); + + List allArtifacts = new ArrayList<>(); + + allArtifacts.addAll(addRelevantArtifacts(deploymentArtifacts)); + allArtifacts.addAll(addRelevantArtifacts(artifacts)); + allArtifacts.addAll(addRelevantArtifacts(apiArtifacts)); + + if (instanceArtifacts != null) { + instanceArtifacts.forEach((key, artifactMap) -> { + allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())); + }); + } + + if (instanceDeploymentArtifacts != null) { + instanceDeploymentArtifacts.forEach((key, artifactMap) -> { + allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())); + }); + } + + return validateArtifactsAreInCassandra(vertex, taskName, allArtifacts); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java new file mode 100644 index 0000000000..410691fb47 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java @@ -0,0 +1,26 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; + +import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.springframework.beans.factory.annotation.Autowired; + + +/** + * Created by chaya on 7/6/2017. + */ +public class ServiceArtifactValidationTask extends ServiceValidationTask { + + @Autowired + private ArtifactValidationUtils artifactValidationUtils; + + + + public ServiceArtifactValidationTask() { + this.name = "Service Artifact Validation Task"; + } + + @Override + public boolean validate(GraphVertex vertex) { + return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName()); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java new file mode 100644 index 0000000000..01bc26fe2b --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java @@ -0,0 +1,28 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; + +import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation; +import org.springframework.beans.factory.annotation.Autowired; + + +/** + * Created by chaya on 7/4/2017. + */ +public class VfArtifactValidationTask extends VfValidationTask { + + @Autowired + ArtifactValidationUtils artifactValidationUtils; + + @Autowired + protected TopologyTemplateOperation topologyTemplateOperation; + + public VfArtifactValidationTask() { + this.name = "Artifact Validation Task"; + } + + @Override + public boolean validate(GraphVertex vertex) { + return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName()); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java new file mode 100644 index 0000000000..245d38c853 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java @@ -0,0 +1,59 @@ +package org.openecomp.sdc.asdctool.impl.validator.utils; + +import org.openecomp.sdc.asdctool.impl.validator.executers.VfValidatorExecuter; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by chaya on 7/4/2017. + */ +public enum ElementTypeEnum { + + VF ("vf", VfValidatorExecuter.class); + //SERVICE("service", ServiceValidatorExecuter.class) + + private String elementType; + private Class clazz; + + ElementTypeEnum(String elementType, Class clazz) { + this. elementType = elementType; + this.clazz = clazz; + } + + public static ElementTypeEnum getByType(String elementType){ + for(ElementTypeEnum currType :ElementTypeEnum.values()){ + if(currType.getElementType().equals(elementType)){ + return currType; + } + } + return null; + } + + public static List getAllTypes() { + + List arrayList = new ArrayList(); + + for (ElementTypeEnum graphType : ElementTypeEnum.values()) { + arrayList.add(graphType.getElementType()); + } + return arrayList; + } + + + public String getElementType() { + return elementType; + } + + public void setElementType(String elementType) { + this.elementType = elementType; + } + + public Class getClazz() { + return clazz; + } + + public void setClazz(Class clazz) { + this.clazz = clazz; + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java new file mode 100644 index 0000000000..1fdde7dd80 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java @@ -0,0 +1,93 @@ +package org.openecomp.sdc.asdctool.impl.validator.utils; + +import org.apache.commons.lang.text.StrBuilder; +import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * Created by chaya on 7/5/2017. + */ +public class ReportManager { + + private static List taskResults; + private static String reportOutputFilePath; + + public ReportManager() { + try { + taskResults = new ArrayList<>(); + // open file for first time + reportOutputFilePath = ValidationConfigManager.getOutputFilePath(); + StrBuilder sb = new StrBuilder(); + sb.appendln("-----------------------Validation Tool Results:-------------------------"); + Files.write(Paths.get(reportOutputFilePath), sb.toString().getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void reportValidationTaskStatus(GraphVertex vertexScanned, String taskName, String taskResultMessage, boolean success) { + taskResults.add(new ValidationTaskResult(vertexScanned, taskName, taskResultMessage, success)); + printValidationTaskStatus(vertexScanned, taskName, success); + } + + private static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success) { + String successStatus = success ? "success" : "failed"; + String line = "-----------------------Vertex: "+vertexScanned.getUniqueId()+", Task " + taskName + " " +successStatus+"-----------------------"; + StrBuilder sb = new StrBuilder(); + writeReportLineToFile(sb.appendNewLine().toString()); + sb.appendln(line); + sb.appendNewLine(); + writeReportLineToFile(line); + } + + public static void reportValidationTaskSummary(TopologyTemplateValidationTask task, int numOfFailedComponents, int numOfSuccessComponents) { + StrBuilder sb = new StrBuilder(); + sb.appendNewLine(); + sb.appendln("-----------------------Task " + task.getTaskName() + " Validation Summary-----------------------"); + sb.appendln("Num of failed components: "+ numOfFailedComponents); + sb.appendln("Num of success components: "+ numOfSuccessComponents); + sb.appendln("Total components scanned: " + numOfFailedComponents+numOfSuccessComponents); + writeReportLineToFile(sb.toString()); + } + + public static void writeReportLineToFile(String message) { + try { + Files.write(Paths.get(reportOutputFilePath), new StrBuilder().appendNewLine().toString().getBytes(), StandardOpenOption.APPEND); + Files.write(Paths.get(reportOutputFilePath), message.getBytes(), StandardOpenOption.APPEND); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void reportValidatorTypeSummary(String validatorName, Set failedTasksNames, Set successTasksNames){ + StrBuilder sb = new StrBuilder(); + sb.appendNewLine().appendNewLine(); + sb.appendln("-----------------------ValidatorExecuter " + validatorName + " Validation Summary-----------------------"); + sb.appendln("Failed tasks: "+ failedTasksNames); + sb.appendln("Success tasks: "+ successTasksNames); + writeReportLineToFile(sb.toString()); + } + + public static void reportStartValidatorRun(String validatorName, int componenentsNum) { + StrBuilder sb = new StrBuilder(); + sb.appendNewLine().appendNewLine(); + sb.appendln("------ValidatorExecuter " + validatorName + " Validation Started, on "+componenentsNum+" components---------"); + writeReportLineToFile(sb.toString()); + } + + public static void reportStartTaskRun(GraphVertex vertex, String taskName){ + StrBuilder sb = new StrBuilder(); + sb.appendNewLine().appendNewLine(); + sb.appendln("-----------------------Vertex: "+vertex.getUniqueId()+", Task " + taskName + " Started-----------------------"); + writeReportLineToFile(sb.toString()); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ValidationTaskResult.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ValidationTaskResult.java new file mode 100644 index 0000000000..8fad932941 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ValidationTaskResult.java @@ -0,0 +1,45 @@ +package org.openecomp.sdc.asdctool.impl.validator.utils; + +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.model.Component; + +/** + * Created by chaya on 7/5/2017. + */ +public class ValidationTaskResult { + public ValidationTaskResult(GraphVertex vertex, String name, String resultMessage, boolean isSuccessful) { + this.vertexScanned = vertex; + this.name = name; + this.resultMessage = resultMessage; + this.isSuccessful = isSuccessful; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getResultMessage() { + return resultMessage; + } + + public void setResultMessage(String resultMessage) { + this.resultMessage = resultMessage; + } + + public boolean isSuccessful() { + return isSuccessful; + } + + public void setSuccessful(boolean successful) { + isSuccessful = successful; + } + + private String name; + private String resultMessage; + private boolean isSuccessful; + private GraphVertex vertexScanned; +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java new file mode 100644 index 0000000000..6b10615ad3 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java @@ -0,0 +1,47 @@ +package org.openecomp.sdc.asdctool.main; + +import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL; +import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager; +import org.openecomp.sdc.asdctool.impl.validator.config.ValidationToolConfiguration; +import org.openecomp.sdc.asdctool.impl.migration.v1604.AppConfig; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.common.api.ConfigurationSource; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +/** + * Created by chaya on 7/3/2017. + */ +public class ValidationTool { + + private static Logger log = LoggerFactory.getLogger(ValidationTool.class.getName()); + + public static void main(String[] args) throws Exception { + + String outputFilePath = args[0]; + ValidationConfigManager.setOutputFilePath(outputFilePath); + + String appConfigDir = args[1]; + AnnotationConfigApplicationContext context = initContext(appConfigDir); + ValidationToolBL validationToolBL = context.getBean(ValidationToolBL.class); + + System.out.println("Start Validation Tool"); + if (validationToolBL.validateAll()) { + System.out.println("Validation finished successfully"); + System.exit(0); + } else { + System.out.println("Validation finished with warnings"); + System.exit(2); + } + } + + private static AnnotationConfigApplicationContext initContext(String appConfigDir) { + ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); + ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ValidationToolConfiguration.class); + return context; + } +} diff --git a/asdctool/src/main/resources/scripts/validationTool.sh b/asdctool/src/main/resources/scripts/validationTool.sh new file mode 100644 index 0000000000..fc82eee72d --- /dev/null +++ b/asdctool/src/main/resources/scripts/validationTool.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +############################## +# Validation Tool # +############################## + +CURRENT_DIR=`pwd` +BASEDIR=$(dirname $0) + +if [ ${BASEDIR:0:1} = "/" ] +then + FULL_PATH=$BASEDIR +else + FULL_PATH=$CURRENT_DIR/$BASEDIR +fi + +source ${FULL_PATH}/baseOperation.sh + +mainClass="org.openecomp.sdc.asdctool.main.ValidationTool" + +command="java $JVM_LOG_FILE -cp $JARS $mainClass reportOutput.txt /apps/jetty/base/be/config/catalog-be/" +echo $command + +$command +result=$? + +echo "***********************************" +echo "***** $result *********************" +echo "***********************************" + +exit $result \ No newline at end of file diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index ebdfe22185..77900efd82 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -2761,8 +2761,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } } else if (ArtifactTypeEnum.YANG_XML.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.VNF_CATALOG.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.VF_LICENSE.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.VENDOR_LICENSE.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.getType().equalsIgnoreCase(artifactType) - || ArtifactTypeEnum.MODEL_QUERY_SPEC.getType().equalsIgnoreCase(artifactType)) { - isValidPayload = validateYangPayload(decodedPayload, artifactType); + || ArtifactTypeEnum.MODEL_QUERY_SPEC.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.UCPE_LAYER_2_CONFIGURATION.getType().equalsIgnoreCase(artifactType)) { + isValidPayload = validateXmlPayload(decodedPayload, artifactType); // else // if(ArtifactTypeEnum.APPC_CONFIG.getType().equalsIgnoreCase(artifactType) // || ){ @@ -2772,7 +2772,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { String fileExtension = GeneralUtility.getFilenameExtension(artifactFileName).toLowerCase(); switch (fileExtension) { case "xml": - isValidPayload = validateYangPayload(decodedPayload, artifactType); + isValidPayload = validateXmlPayload(decodedPayload, artifactType); break; case "json": isValidPayload = validateJsonPayload(decodedPayload, artifactType); @@ -2836,7 +2836,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { return res; } - private Either validateYangPayload(byte[] payload, String artifactType) { + private Either validateXmlPayload(byte[] payload, String artifactType) { boolean isXmlValid = isValidXml(payload); if (!isXmlValid) { ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.INVALID_XML, artifactType); @@ -4294,7 +4294,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { Component component = null; String componentId = null; String artifactId = null; - ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class); + ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinitionForUpdate(data, ArtifactDefinition.class); String origMd5 = request.getHeader(Constants.MD5_HEADER); String userId = request.getHeader(Constants.USER_ID_HEADER); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java index d1be69689e..21f7b3ab7c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java @@ -69,7 +69,6 @@ import org.openecomp.sdc.be.user.Role; import org.openecomp.sdc.be.utils.CommonBeUtils; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.api.ArtifactTypeEnum; -import org.openecomp.sdc.common.config.EcompErrorName; import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum; import org.openecomp.sdc.common.util.ValidationUtils; import org.openecomp.sdc.exception.ResponseFormat; @@ -818,85 +817,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { return Either.left(deleteMarkedElements.left().value()); } - private Either deleteMarkedComponent(String componentToDelete, ComponentTypeEnum componentType) { - - Either result = null; - NodeTypeEnum compNodeType = componentType.getNodeType(); - StorageOperationStatus lockResult = graphLockOperation.lockComponent(componentToDelete, compNodeType); - if (!lockResult.equals(StorageOperationStatus.OK)) { - BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, "Delete marked component"); - log.debug("Failed to lock component {} error - {}", componentToDelete, lockResult); - result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); - return result; - } - try { - - // check if resource has relations - Either isResourceInUse = toscaOperationFacade.isComponentInUse(componentToDelete); - if (isResourceInUse.isRight()) { - log.info("deleteMarkedResource - failed to find relations to resource. id = {}, type = {}, error = {}", componentToDelete, componentType, isResourceInUse.right().value().name()); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR); - result = Either.right(responseFormat); - return result; - } - - if (isResourceInUse.isLeft() && isResourceInUse.left().value() == false) { - - // delete resource and its artifacts in one transaction - Either, StorageOperationStatus> artifactsRes = getComponentArtifactsForDelete(componentToDelete, compNodeType, true); - if (artifactsRes.isRight() && !artifactsRes.right().value().equals(StorageOperationStatus.NOT_FOUND)) { - log.info("failed to check artifacts for component node. id = {}, type = {}, error = {}", componentToDelete, componentType, artifactsRes.right().value().name()); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR); - result = Either.right(responseFormat); - return result; - } - List artifactsToDelete = new ArrayList<>(); - if (artifactsRes.isLeft()) { - artifactsToDelete = artifactsRes.left().value(); - } - - Either deleteComponentRes = toscaOperationFacade.deleteToscaComponent(componentToDelete); - if (deleteComponentRes.isRight()) { - log.info("failed to delete component. id = {}, type = {}, error = {}", componentToDelete, componentType, deleteComponentRes.right().value().name()); - ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteComponentRes.right().value()); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete); - result = Either.right(responseFormat); - } else { - log.trace("component was deleted, id = {}, type = {}", componentToDelete, componentType); - // delete related artifacts - StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(artifactsToDelete); - if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) { - ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete); - result = Either.right(responseFormat); - return result; - } - log.debug("component and all its artifacts were deleted, id = {}, type = {}", componentToDelete, componentType); - result = Either.left(componentToDelete); - } - } else { - // resource in use - log.debug("componentis marked for delete but still in use, id = {}, type = {}", componentToDelete, componentType); - ActionStatus actionStatus = ActionStatus.RESTRICTED_OPERATION; - ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete); - result = Either.right(responseFormat); - return result; - } - } finally { - if (result == null || result.isRight()) { - BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "delete marked component"); - log.debug("operation failed. do rollback"); - titanDao.rollback(); - } else { - log.debug("operation success. do commit"); - titanDao.commit(); - } - graphLockOperation.unlockComponent(componentToDelete, compNodeType); - } - - return result; - } - public Either, StorageOperationStatus> getComponentArtifactsForDelete(String parentId, NodeTypeEnum parentType, boolean inTransacton) { List artifacts = new ArrayList(); Either, StorageOperationStatus> artifactsResponse = artifactToscaOperation.getArtifacts(parentId); @@ -980,7 +900,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { protected Either fetchAndSetDerivedFromGenericType(T component){ String genericTypeToscaName = null; - if(component.getComponentType() == ComponentTypeEnum.RESOURCE && ((Resource)component).getResourceType() == ResourceTypeEnum.CVFC){ + if(component.getComponentType() == ComponentTypeEnum.RESOURCE && ((Resource)component).getResourceType() == ResourceTypeEnum.CVFC && CollectionUtils.isNotEmpty(((Resource)component).getDerivedFrom())){ genericTypeToscaName = ((Resource)component).getDerivedFrom().get(0); } else { genericTypeToscaName = component.fetchGenericTypeToscaNameFromConfig(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java index c85520dbe4..838cd53458 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java @@ -104,8 +104,9 @@ public final class ImportUtils { public static final String DEFAULT_ICON = "defaulticon"; public static final String INNER_VFC_DESCRIPTION = "Not reusable inner VFC"; public static final String USER_DEFINED_RESOURCE_NAMESPACE_PREFIX = "org.openecomp.resource."; - public static final List TOSCA_DEFINITION_VERSIONS = Arrays.asList(new String[] { "tosca_simple_yaml_1_0_0", "tosca_simple_profile_for_nfv_1_0_0", "tosca_simple_yaml_1_0" }); - public static final List TOSCA_YML_CSAR_VALID_SUFFIX = Arrays.asList(new String[] { ".yml", ".yaml", ".csar" }); + public static final String TOSCA_SIMPLE_YAML_PREFIX = "tosca_simple_yaml_"; + public static final List TOSCA_DEFINITION_VERSIONS = Arrays.asList(TOSCA_SIMPLE_YAML_PREFIX + "1_0_0", TOSCA_SIMPLE_YAML_PREFIX + "1_1_0", "tosca_simple_profile_for_nfv_1_0_0", TOSCA_SIMPLE_YAML_PREFIX + "1_0", TOSCA_SIMPLE_YAML_PREFIX + "1_1"); + public static final List TOSCA_YML_CSAR_VALID_SUFFIX = Arrays.asList(".yml", ".yaml", ".csar"); public static final String UI_JSON_PAYLOAD_NAME = "payloadName"; public static final String CVFC_DESCRIPTION = "Complex node type that is used as nested type in VF"; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 37067e6541..0aa4a6f006 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -23,7 +23,6 @@ package org.openecomp.sdc.be.components.impl; import static org.openecomp.sdc.be.tosca.CsarUtils.ARTIFACTS_PATH; import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -46,6 +45,7 @@ import javax.servlet.ServletContext; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo; @@ -87,7 +87,7 @@ import org.openecomp.sdc.be.model.GroupDefinition; import org.openecomp.sdc.be.model.GroupProperty; import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.model.HeatParameterDefinition; -import org.openecomp.sdc.be.model.ImportCsarInfo; +import org.openecomp.sdc.be.model.CsarInfo; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; @@ -135,7 +135,6 @@ import org.openecomp.sdc.be.utils.CommonBeUtils; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.common.api.Constants; -import org.openecomp.sdc.common.config.EcompErrorName; import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum; import org.openecomp.sdc.common.datastructure.FunctionalInterfaces; import org.openecomp.sdc.common.datastructure.Wrapper; @@ -489,7 +488,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } String lockedResourceId = oldRresource.getUniqueId(); List createdArtifacts = new ArrayList<>(); - List nodeTypesNewCreatedArtifacts = new ArrayList<>(); Either, StorageOperationStatus> csar = null; if (csarUIPayload != null && csarUIPayload.left() != null && csarUIPayload.left().value() != null) { @@ -525,35 +523,68 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(lockResult.right().value()); } - Either result = null; String yamlFileName = toscaYamlCsarStatus.left().value().getKey(); String yamlFileContents = toscaYamlCsarStatus.left().value().getValue(); - Either, ResponseFormat> parseNodeTypeInfoYamlEither = null; - ImportCsarInfo importCsarInfo = new ImportCsarInfo(newRresource.getName(), user, csarUUID, csar.left().value()); + CsarInfo csarInfo = new CsarInfo(newRresource.getName(), user, csarUUID, csar.left().value(), true); + Map nodeTypesInfo = extractNodeTypesInfo(csar.left().value(), yamlFileContents); + Either result =null; + + Either>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo.getCsar(), csarInfo.getCsarUUID(), yamlFileName, oldRresource, csarInfo.getModifier()); + if (findNodeTypesArtifactsToHandleRes.isRight()) { + log.debug("failed to find node types for update with artifacts during import csar {}. ", csarInfo.getCsarUUID()); + result = Either.right(findNodeTypesArtifactsToHandleRes.right().value()); + return result; + } + Map>> nodeTypesArtifactsToHandle = findNodeTypesArtifactsToHandleRes.left().value(); + try{ + result = updateResourceFromYaml(oldRresource, newRresource, updateResource, createdArtifacts, isUpdateYaml, yamlFileName, yamlFileContents, csarInfo, nodeTypesInfo, nodeTypesArtifactsToHandle, null); + + } finally { + if (result == null || result.isRight()) { + log.warn("operation failed. do rollback"); + titanDao.rollback(); + if (!createdArtifacts.isEmpty()) { + StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts); + if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) { + ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes); + result = Either.right(componentsUtils.getResponseFormat(actionStatus, oldRresource.getName())); + } + log.debug("component and all its artifacts were deleted, id = {}", oldRresource.getName()); + } + } else { + log.debug("operation success. do commit"); + titanDao.commit(); + } + log.debug("unlock resource {}", lockedResourceId); + graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource); + } + return result; - try { + } + + private Either updateResourceFromYaml(Resource oldRresource, Resource newRresource, AuditingActionEnum updateResource, List createdArtifacts, + boolean isUpdateYaml, String yamlFileName, String yamlFileContent, CsarInfo csarInfo, Map nodeTypesInfo, + Map>> nodeTypesArtifactsToHandle, String nodeName) { + Either result = null; + Either, ResponseFormat> parseNodeTypeInfoYamlEither; + boolean inTransaction = true; + boolean shouldLock = false; + Either, ResponseFormat> prepareForUpdate = null; Resource preparedResource = null; - Either uploadComponentInstanceInfoMap = parseResourceInfoFromYaml(yamlFileName, newRresource, toscaYamlCsarStatus.left().value().getValue(), user, importCsarInfo.getCreatedNodesToscaResourceNames(), null, null); + Either uploadComponentInstanceInfoMap = parseResourceInfoFromYaml(yamlFileName, newRresource, yamlFileContent, csarInfo.getModifier(), csarInfo.getCreatedNodesToscaResourceNames(), nodeTypesInfo, nodeName); if (uploadComponentInstanceInfoMap.isRight()) { ResponseFormat responseFormat = uploadComponentInstanceInfoMap.right().value(); - componentsUtils.auditResource(responseFormat, user, newRresource, "", "", updateResource, null); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), newRresource, "", "", updateResource, null); result = Either.right(responseFormat); return result; } - Map nodeTypesInfo = extractNodeTypesInfo(csar.left().value(), yamlFileContents); + Map instances = uploadComponentInstanceInfoMap.left().value().getInstances(); - Either>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(nodeTypesInfo, csar.left().value(), csarUUID, yamlFileName, oldRresource, user, true, - instances); - if (findNodeTypesArtifactsToHandleRes.isRight()) { - log.debug("failed to find node types for update with artifacts during import csar {}. ", csarUUID); - result = Either.right(findNodeTypesArtifactsToHandleRes.right().value()); - return result; - } - Map>> nodeTypesArtifactsToHandle = findNodeTypesArtifactsToHandleRes.left().value(); + if (isUpdateYaml || !nodeTypesArtifactsToHandle.isEmpty()) { - prepareForUpdate = updateExistingResourceByImport(newRresource, oldRresource, user, true, false); + prepareForUpdate = updateExistingResourceByImport(newRresource, oldRresource, csarInfo.getModifier(), inTransaction, shouldLock); if (prepareForUpdate.isRight()) { log.debug("Failed to prepare resource for update : {}", prepareForUpdate.right().value()); result = Either.right(prepareForUpdate.right().value()); @@ -561,38 +592,38 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } preparedResource = prepareForUpdate.left().value().left; - log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContents); + log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContent); - parseNodeTypeInfoYamlEither = this.handleNodeTypes(yamlFileName, preparedResource, yamlFileContents, false, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, importCsarInfo); + parseNodeTypeInfoYamlEither = this.handleNodeTypes(yamlFileName, preparedResource, yamlFileContent, shouldLock, nodeTypesArtifactsToHandle, createdArtifacts, nodeTypesInfo, csarInfo, nodeName); if (parseNodeTypeInfoYamlEither.isRight()) { ResponseFormat responseFormat = parseNodeTypeInfoYamlEither.right().value(); - componentsUtils.auditResource(responseFormat, user, preparedResource, "", "", updateResource, null); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource, "", "", updateResource, null); result = Either.right(responseFormat); return result; } Map inputs = uploadComponentInstanceInfoMap.left().value().getInputs(); - Either createInputsOnResource = createInputsOnResource(preparedResource, user, inputs, true); + Either createInputsOnResource = createInputsOnResource(preparedResource, csarInfo.getModifier(), inputs, inTransaction); if (createInputsOnResource.isRight()) { log.debug("failed to create resource inputs status is {}", createInputsOnResource.right().value()); ResponseFormat responseFormat = createInputsOnResource.right().value(); - componentsUtils.auditResource(createInputsOnResource.right().value(), user, preparedResource, "", "", updateResource, null); + componentsUtils.auditResource(createInputsOnResource.right().value(), csarInfo.getModifier(), preparedResource, "", "", updateResource, null); result = Either.right(responseFormat); return result; } preparedResource = createInputsOnResource.left().value(); - Either createResourcesInstancesEither = createResourceInstances(user, yamlFileName, preparedResource, instances, true, false, parseNodeTypeInfoYamlEither.left().value()); + Either createResourcesInstancesEither = createResourceInstances(csarInfo.getModifier(), yamlFileName, preparedResource, instances, inTransaction, shouldLock, csarInfo.getCreatedNodes()); if (createResourcesInstancesEither.isRight()) { log.debug("failed to create resource instances status is {}", createResourcesInstancesEither.right().value()); ResponseFormat responseFormat = createResourcesInstancesEither.right().value(); - componentsUtils.auditResource(createResourcesInstancesEither.right().value(), user, preparedResource, "", "", updateResource, null); + componentsUtils.auditResource(createResourcesInstancesEither.right().value(), csarInfo.getModifier(), preparedResource, "", "", updateResource, null); result = Either.right(responseFormat); return result; } preparedResource = createResourcesInstancesEither.left().value(); - - createResourcesInstancesEither = createResourceInstancesRelations(user, yamlFileName, preparedResource, instances, true, false); + + createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, instances, inTransaction, shouldLock); if (createResourcesInstancesEither.isRight()) { log.debug("failed to create relation between resource instances status is {}", createResourcesInstancesEither.right().value()); result = Either.right(createResourcesInstancesEither.right().value()); @@ -614,7 +645,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } else { groups = uploadComponentInstanceInfoMap.left().value().getGroups(); } - Either updatedGroupsOnResource = updateGroupsOnResource(preparedResource, user, groups); + Either updatedGroupsOnResource = updateGroupsOnResource(preparedResource, csarInfo.getModifier(), groups); if (updatedGroupsOnResource.isRight()) { return updatedGroupsOnResource; @@ -622,7 +653,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { preparedResource = updatedGroupsOnResource.left().value(); } else { - Either dataModelResponse = updateResourceMetadata(oldRresource.getUniqueId(), newRresource, user, oldRresource, false, true); + Either dataModelResponse = updateResourceMetadata(oldRresource.getUniqueId(), newRresource, csarInfo.getModifier(), oldRresource, shouldLock, inTransaction); if (dataModelResponse.isRight()) { log.debug("failed to update resource metadata {}", dataModelResponse.right().value()); result = Either.right(dataModelResponse.right().value()); @@ -631,44 +662,32 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { preparedResource = dataModelResponse.left().value(); } - Either createdCsarArtifactsEither = handleVfCsarArtifacts(preparedResource, importCsarInfo, createdArtifacts, - artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Update), false, true); - if (createdCsarArtifactsEither.isRight()) { - - return createdCsarArtifactsEither; + if(preparedResource.getResourceType() == ResourceTypeEnum.CVFC){ + if(nodeName != null && nodeTypesArtifactsToHandle.get(nodeName) != null && !nodeTypesArtifactsToHandle.get(nodeName).isEmpty()){ + Either, ResponseFormat> handleNodeTypeArtifactsRes = + handleNodeTypeArtifacts(preparedResource, nodeTypesArtifactsToHandle.get(nodeName), createdArtifacts, csarInfo.getModifier(), inTransaction, true); + if(handleNodeTypeArtifactsRes.isRight()){ + return Either.right(handleNodeTypeArtifactsRes.right().value()); + } + } + } else { + Either createdCsarArtifactsEither = handleVfCsarArtifacts(preparedResource, csarInfo, createdArtifacts, + artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Update), shouldLock, inTransaction); + log.trace("************* Finished to add artifacts from yaml {}", yamlFileName); + if (createdCsarArtifactsEither.isRight()) { + return createdCsarArtifactsEither; + } + preparedResource = createdCsarArtifactsEither.left().value(); } - preparedResource = createdCsarArtifactsEither.left().value(); - Either, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, user.getUserId()); + Either, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, csarInfo.getModifier().getUserId()); result = eitherSetPosition.isRight() ? Either.right(eitherSetPosition.right().value()) : Either.left(preparedResource); return result; - } finally { - if (result == null || result.isRight()) { - log.warn("operation failed. do rollback"); - titanDao.rollback(); - if (!createdArtifacts.isEmpty() || !nodeTypesNewCreatedArtifacts.isEmpty()) { - createdArtifacts.addAll(nodeTypesNewCreatedArtifacts); - StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts); - if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) { - ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, oldRresource.getName()); - } - log.debug("component and all its artifacts were deleted, id = {}", oldRresource.getName()); - } - } else { - log.debug("operation success. do commit"); - titanDao.commit(); - } - log.debug("unlock resource {}", lockedResourceId); - graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource); - } - } - private Either>>, ResponseFormat> findNodeTypesArtifactsToHandle(Map nodeTypesInfo, Map csar, String csarUUID, String yamlFileName, Resource oldResource, User user, - boolean inTransaction, Map uploadComponentInstanceInfoMap) { + private Either>>, ResponseFormat> findNodeTypesArtifactsToHandle(Map nodeTypesInfo, Map csar, String csarUUID, String yamlFileName, Resource oldResource, User user) { Map> extractedVfcsArtifacts = CsarUtils.extractVfcsArtifactsFromCsar(csar); Map>> nodeTypesArtifactsToHandle = new HashMap<>(); @@ -676,7 +695,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { try { nodeTypesArtifactsToHandleRes = Either.left(nodeTypesArtifactsToHandle); - Map extractedVfcToscaNames = extractVfcToscaNames(nodeTypesInfo, yamlFileName, oldResource.getSystemName(), uploadComponentInstanceInfoMap); + Map extractedVfcToscaNames = extractVfcToscaNames(nodeTypesInfo, yamlFileName, oldResource.getSystemName()); Either>, ResponseFormat> curNodeTypeArtifactsToHandleRes = null; EnumMap> curNodeTypeArtifactsToHandle = null; log.debug("Going to fetch node types for resource with name {} during import csar with UUID {}. ", oldResource.getName(), csarUUID); @@ -844,8 +863,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { * @param inTransaction * @return */ - public Either, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource, Map> nodeTypeArtifactsToHandle, List vfcsNewCreatedArtifacts, - User user, boolean inTransaction) { + public Either, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource, Map> nodeTypeArtifactsToHandle, List createdArtifacts, + User user, boolean inTransaction, boolean ignoreLifecycleState) { Either, ResponseFormat> handleNodeTypeArtifactsRequestRes; Either, ResponseFormat> handleNodeTypeArtifactsRes = null; Either changeStateResponse; @@ -863,14 +882,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { List curArtifactsToHandle = curOperationEntry.getValue(); if (curArtifactsToHandle != null && !curArtifactsToHandle.isEmpty()) { log.debug("************* Going to {} artifact to vfc {}", curOperation.name(), nodeTypeResource.getName()); - handleNodeTypeArtifactsRequestRes = artifactsBusinessLogic.handleArtifactsRequestForInnerVfcComponent(curArtifactsToHandle, nodeTypeResource, user, vfcsNewCreatedArtifacts, - artifactsBusinessLogic.new ArtifactOperationInfo(false, false, curOperation), false, inTransaction); + handleNodeTypeArtifactsRequestRes = artifactsBusinessLogic.handleArtifactsRequestForInnerVfcComponent(curArtifactsToHandle, nodeTypeResource, user, createdArtifacts, + artifactsBusinessLogic.new ArtifactOperationInfo(false, ignoreLifecycleState, curOperation), false, inTransaction); if (handleNodeTypeArtifactsRequestRes.isRight()) { handleNodeTypeArtifactsRes = Either.right(handleNodeTypeArtifactsRequestRes.right().value()); break; } if (curOperation == ArtifactOperationEnum.Create) { - vfcsNewCreatedArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value()); + createdArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value()); } handledNodeTypeArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value()); } @@ -886,8 +905,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return handleNodeTypeArtifactsRes; } - @SuppressWarnings("unchecked") - private Map extractVfcToscaNames(Map nodeTypesInfo, String yamlFileName, String vfResourceName, Map uploadComponentInstanceInfoMap) { + private Map extractVfcToscaNames(Map nodeTypesInfo, String yamlFileName, String vfResourceName) { Map vfcToscaNames = new HashMap<>(); Map nodes = extractAllNodes(nodeTypesInfo); @@ -895,7 +913,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Iterator> nodesNameEntry = nodes.entrySet().iterator(); while (nodesNameEntry.hasNext()) { Entry nodeType = nodesNameEntry.next(); - String toscaResourceName = buildNodeToscaResourceName(vfResourceName, nodeType.getKey()); + String toscaResourceName = buildNestedToscaResourceName(ResourceTypeEnum.VFC.name(), vfResourceName, nodeType.getKey()); vfcToscaNames.put(nodeType.getKey(), toscaResourceName); } } @@ -913,50 +931,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return nodes; } - @SuppressWarnings("unchecked") - private void putNodeTypesFromYaml(Map csar, String yamlFileName, Map nodeTypes) { - - if (csar.containsKey(yamlFileName)) { - Map mappedToscaTemplate; - Either, ResultStatusEnum> eitherNodeTypes; - mappedToscaTemplate = (Map) new Yaml().load(new String(csar.get(yamlFileName), StandardCharsets.UTF_8)); - eitherNodeTypes = ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPES); - if (eitherNodeTypes.isLeft()) { - nodeTypes.putAll(eitherNodeTypes.left().value()); - } - } - } - - private void addSubstituteToscaNamespacesRecursively(Map csar, String yamlFileName, List toscaNameSpaces, Map nestedServiceTemplatesMap) { - - Map nodeTypes = new HashMap<>(); - - if (csar.containsKey(yamlFileName)) { - putNodeTypesFromYaml(csar, yamlFileName, nodeTypes); - } - if (!nodeTypes.isEmpty()) { - Iterator> nodesNameEntry = nodeTypes.entrySet().iterator(); - while (nodesNameEntry.hasNext()) { - Entry nodeType = nodesNameEntry.next(); - String nodeTypeFullName = nodeType.getKey(); - String toscaNameSpace = buildNestedVfcToscaNamespace(nodeTypeFullName); - if (toscaNameSpaces.contains(toscaNameSpace)) { - break; - } - toscaNameSpaces.add(toscaNameSpace); - - String nodeTypeTemplateYamlName = null; - if (nestedServiceTemplatesMap.containsKey(nodeTypeFullName)) { - nodeTypeTemplateYamlName = nestedServiceTemplatesMap.get(nodeTypeFullName); - } - - if (nodeTypeTemplateYamlName != null && csar.containsKey(nodeTypeTemplateYamlName)) { - addSubstituteToscaNamespacesRecursively(csar, nodeTypeTemplateYamlName, toscaNameSpaces, nestedServiceTemplatesMap); - } - } - } - } - public Either createResourceFromCsar(Resource resource, User user, Either, StorageOperationStatus> csarUIPayload, String csarUUID) { log.trace("************* created successfully from YAML, resource TOSCA "); @@ -984,8 +958,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Map nodeTypesInfo = extractNodeTypesInfo(csar.left().value(), yamlFileContents); Map>> nodeTypesArtifactsToCreate = findNodeTypeArtifactsToCreate(csar.left().value(), resource); - ImportCsarInfo importCsarInfo = new ImportCsarInfo(resource.getName(), user, csarUUID, csar.left().value()); - Either createResourceFromYaml = createResourceFromYaml(resource, yamlFileContents, yamlFileName, nodeTypesInfo, importCsarInfo, nodeTypesArtifactsToCreate, true, false, null); + CsarInfo csarInfo = new CsarInfo(resource.getName(), user, csarUUID, csar.left().value(), false); + Either createResourceFromYaml = createResourceFromYaml(resource, yamlFileContents, yamlFileName, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, true, false, null); if (createResourceFromYaml.isRight()) { log.debug("Couldn't create resource from YAML"); return Either.right(createResourceFromYaml.right().value()); @@ -1046,6 +1020,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return nodeTypesInfo; } + + @SuppressWarnings("unchecked") private void markNestedVfc(String yamlFileContent, Map nodeTypesInfo) { Map mappedToscaTemplate = (Map) new Yaml().load(yamlFileContent); Either nodeTemplatesEither = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP); @@ -1119,21 +1095,21 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(validateDerivedFromNotEmpty.right().value()); } } - return validateResourceBeforeCreate(resource, user, AuditingActionEnum.CREATE_RESOURCE, inTransaction); + return validateResourceBeforeCreate(resource, user, AuditingActionEnum.CREATE_RESOURCE, inTransaction, null); } -//resource, yamlFileContents, yamlFileName, nodeTypesInfo,importCsarInfo, nodeTypesArtifactsToCreate, true, false, null +//resource, yamlFileContents, yamlFileName, nodeTypesInfo,csarInfo, nodeTypesArtifactsToCreate, true, false, null private Either createResourceFromYaml(Resource resource, String topologyTemplateYaml, String yamlName, - Map nodeTypesInfo, ImportCsarInfo importCsarInfo, + Map nodeTypesInfo, CsarInfo csarInfo, Map>> nodeTypesArtifactsToCreate, - boolean shouldLock, boolean inTransaction, String nodeTypeName) { + boolean shouldLock, boolean inTransaction, String nodeName) { List createdArtifacts = new ArrayList(); log.trace("************* createResourceFromYaml before parse yaml "); - Either parseResourceInfoFromYamlEither = parseResourceInfoFromYaml(yamlName, resource, topologyTemplateYaml, importCsarInfo.getModifier(), importCsarInfo.getCreatedNodesToscaResourceNames(), nodeTypesInfo, nodeTypeName); + Either parseResourceInfoFromYamlEither = parseResourceInfoFromYaml(yamlName, resource, topologyTemplateYaml, csarInfo.getModifier(), csarInfo.getCreatedNodesToscaResourceNames(), nodeTypesInfo, nodeName); if (parseResourceInfoFromYamlEither.isRight()) { ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value(); - componentsUtils.auditResource(responseFormat, importCsarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); return Either.right(responseFormat); } log.trace("************* createResourceFromYaml after parse yaml "); @@ -1142,11 +1118,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.trace("************* createResourceFromYaml before create "); Either createdResourceResponse = createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo, AuditingActionEnum.IMPORT_RESOURCE, false, createdArtifacts, topologyTemplateYaml, - nodeTypesInfo, importCsarInfo, nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeTypeName); + nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName); log.trace("************* createResourceFromYaml after create "); if (createdResourceResponse.isRight()) { ResponseFormat responseFormat = createdResourceResponse.right().value(); - componentsUtils.auditResource(responseFormat, importCsarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); return Either.right(responseFormat); } @@ -1154,10 +1130,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } - @SuppressWarnings("unchecked") public Either, ResponseFormat> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource, String resourceYml, Map mappedToscaTemplate, boolean needLock, Map>> nodeTypesArtifactsToHandle, List nodeTypesNewCreatedArtifacts, - Map nodeTypesInfo, ImportCsarInfo importCsarInfo) { + Map nodeTypesInfo, CsarInfo csarInfo) { Either tosca_version = ImportUtils.findFirstToscaStringElement(mappedToscaTemplate, ToscaTagNamesEnum.TOSCA_VERSION); if (tosca_version.isRight()) { @@ -1165,8 +1140,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(responseFormat); } Either, ResultStatusEnum> eitherNodeTypes = ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPES); - Map nodeTypesResources = new HashMap<>(); - Either, ResponseFormat> result = Either.left(nodeTypesResources); + Either, ResponseFormat> result = Either.left(csarInfo.getCreatedNodes()); Map mapToConvert = new HashMap(); mapToConvert.put(ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), tosca_version.left().value()); Resource vfcCreated = null; @@ -1178,25 +1152,25 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (nodeTypesInfo.containsKey(nodeType.getKey())) { log.trace("************* Going to handle nested vfc {}", nodeType.getKey()); - Either handleNeatedVfcYaml = handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, importCsarInfo, nodeType.getKey(), nodeTypesResources); + Either handleNeatedVfcYaml = handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeType.getKey()); log.trace("************* Finished to handle nested vfc {}", nodeType.getKey()); if (handleNeatedVfcYaml.isRight()) { return Either.right(handleNeatedVfcYaml.right().value()); } vfcCreated = handleNeatedVfcYaml.left().value(); - } else if(importCsarInfo.getCreatedNodesToscaResourceNames()!= null && !importCsarInfo.getCreatedNodesToscaResourceNames().containsKey(nodeType.getKey())){ + } else if(csarInfo.getCreatedNodesToscaResourceNames()!= null && !csarInfo.getCreatedNodesToscaResourceNames().containsKey(nodeType.getKey())){ log.trace("************* Going to create node {}", nodeType.getKey()); - Either, ResponseFormat> resourceCreated = this.createNodeTypeResourceFromYaml(yamlName, nodeType, importCsarInfo.getModifier(), mapToConvert, resource, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, true); + Either, ResponseFormat> resourceCreated = this.createNodeTypeResourceFromYaml(yamlName, nodeType, csarInfo.getModifier(), mapToConvert, resource, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, true, csarInfo); log.debug("************* Finished to create node {}", nodeType.getKey()); if (resourceCreated.isRight()) { return Either.right(resourceCreated.right().value()); } vfcCreated = resourceCreated.left().value().getLeft(); - importCsarInfo.getCreatedNodesToscaResourceNames().put(nodeType.getKey(),vfcCreated.getToscaResourceName()); + csarInfo.getCreatedNodesToscaResourceNames().put(nodeType.getKey(),vfcCreated.getToscaResourceName()); } if (vfcCreated != null) { - nodeTypesResources.put(nodeType.getKey(), vfcCreated); + csarInfo.getCreatedNodes().put(nodeType.getKey(), vfcCreated); } mapToConvert.remove(ToscaTagNamesEnum.NODE_TYPES.getElementName()); } @@ -1204,59 +1178,113 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return result; } - private Either handleNestedVfc(Resource resource, Map>> nodeTypesArtifactsToHandle, - List nodeTypesNewCreatedArtifacts, Map nodeTypesInfo, ImportCsarInfo importCsarInfo, - String nodeType, Map createdResourcesFromdNodeTypeMap) { + private Either handleNestedVfc(Resource resource, Map>> nodesArtifactsToHandle, + List createdArtifacts, Map nodesInfo, CsarInfo csarInfo, String nodeName) { Either handleNestedVfcRes = Either.left(resource); - String serviceTemplateFileFullName = nodeTypesInfo.get(nodeType).getTemplateFileName(); - String serviceTemplateFileContent = new String(importCsarInfo.getCsar().get(serviceTemplateFileFullName)); - Map nestedVfcJsonMap = nodeTypesInfo.get(nodeType).getMappedToscaTemplate(); - - Either, ResponseFormat> createdResourcesFromdNodeTypeMapEither = createResourcesFromYamlNodeTypesList(serviceTemplateFileFullName, resource, serviceTemplateFileContent, - nestedVfcJsonMap, false, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, importCsarInfo); - log.debug("************* Finished to create all nodes from yaml {}", serviceTemplateFileFullName); - if (createdResourcesFromdNodeTypeMapEither.isRight()) { - log.debug("failed to resources from node types status is {}", createdResourcesFromdNodeTypeMapEither.right().value()); - return Either.right(createdResourcesFromdNodeTypeMapEither.right().value()); + String yamlName = nodesInfo.get(nodeName).getTemplateFileName(); + String yamlContent = new String(csarInfo.getCsar().get(yamlName)); + Map nestedVfcJsonMap = nodesInfo.get(nodeName).getMappedToscaTemplate(); + + log.debug("************* Going to create node types from yaml {}", yamlName); + Either, ResponseFormat> createNodeTypesRes = createResourcesFromYamlNodeTypesList(yamlName, resource, yamlContent, + nestedVfcJsonMap, false, nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo); + if (createNodeTypesRes.isRight()) { + log.debug("Failed to create node types from yaml {}. Status is {}", yamlName, createNodeTypesRes.right().value()); + return Either.right(createNodeTypesRes.right().value()); + } + log.debug("************* Finished to create node types from yaml {}", yamlName); + + if (nestedVfcJsonMap.containsKey(ToscaTagNamesEnum.TOPOLOGY_TEMPLATE.getElementName())) { + log.debug("************* Going to handle complex VFC from yaml {}", yamlName); + handleNestedVfcRes = handleComplexVfc(resource, nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName, yamlContent); } - createdResourcesFromdNodeTypeMap.putAll(createdResourcesFromdNodeTypeMapEither.left().value()); + return handleNestedVfcRes; + } - if (nestedVfcJsonMap.containsKey(ToscaTagNamesEnum.TOPOLOGY_TEMPLATE.getElementName())) { - Resource complexVfc = new Resource(); - fillComplexVfcMetadata(resource, importCsarInfo, complexVfc, nodeType, nodeTypesInfo, false); - if(!importCsarInfo.getCvfcToCreateQueue().contains(nodeType)){ - importCsarInfo.getCvfcToCreateQueue().add(nodeType); - } else { - log.debug("CFVC LOOP DETECTED, VSP {}, CVFC {}", importCsarInfo.getVfResourceName(), complexVfc.getName()); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.CFVC_LOOP_DETECTED, importCsarInfo.getVfResourceName(), complexVfc.getName())); + private Either handleComplexVfc(Resource resource, Map>> nodesArtifactsToHandle, List createdArtifacts, + Map nodesInfo, CsarInfo csarInfo, String nodeName, String yamlName, String yamlContent) { + + Either result = null; + Resource oldComplexVfc = null; + Resource newComplexVfc = null; + + Either buildCvfcRes = buildValidComplexVfc(resource, csarInfo, nodeName, nodesInfo); + if(buildCvfcRes.isRight()){ + log.debug("Failed to validate complex VFC for node {}. ", nodeName); + result = buildCvfcRes; + } + if(result == null){ + newComplexVfc = buildCvfcRes.left().value(); + if(csarInfo.isUpdate()){ + Either oldComplexVfcRes = toscaOperationFacade.getLatestByToscaResourceName(newComplexVfc.getToscaResourceName()); + if(oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() != StorageOperationStatus.NOT_FOUND){ + log.debug("Failed to fetch previous complex VFC by tosca resource name {}. Status is {}. ", newComplexVfc.getToscaResourceName(), oldComplexVfcRes.right().value()); + result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); + } else if(oldComplexVfcRes.isLeft()){ + oldComplexVfc = oldComplexVfcRes.left().value(); + } } - Either validationRes = validateResourceBeforeCreate(complexVfc, importCsarInfo.getModifier(), AuditingActionEnum.IMPORT_RESOURCE, true); - if(validationRes.isRight()){ - log.debug("Failed to validate complex VFC {}. ", complexVfc.getName()); - return validationRes; + } + if(result == null){ + result = handleComplexVfc(nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName, yamlContent, oldComplexVfc, newComplexVfc); + } + if(result.isLeft()){ + newComplexVfc = result.left().value(); + csarInfo.getCreatedNodesToscaResourceNames().put(nodeName, newComplexVfc.getToscaResourceName()); + LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction("certification on import", LifecycleChanceActionEnum.CREATE_FROM_CSAR); + log.debug("Going to certify cvfc {}. ", newComplexVfc.getName()); + result = propagateStateToCertified(csarInfo.getModifier(), newComplexVfc, lifecycleChangeInfo, true, false, true); + if (result.isRight()) { + log.debug("Failed to certify complex VFC resource {}. ", newComplexVfc.getName()); } - Map newNodeTypesInfo = nodeTypesInfo.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().getUnmarkedCopy())); - markNestedVfc(serviceTemplateFileContent, newNodeTypesInfo); - handleNestedVfcRes = createResourceFromYaml(complexVfc, serviceTemplateFileContent, serviceTemplateFileFullName, - newNodeTypesInfo, importCsarInfo, nodeTypesArtifactsToHandle, false, true, nodeType); - if (handleNestedVfcRes.isRight()) { - log.debug("Couldn't create resource from YAML"); - return Either.right(handleNestedVfcRes.right().value()); + } + if(result.isLeft()){ + csarInfo.getCreatedNodes().put(nodeName, result.left().value()); + csarInfo.getCvfcToCreateQueue().remove(); + } + return result; + } + + private Either handleComplexVfc(Map>> nodesArtifactsToHandle, List createdArtifacts, Map nodesInfo, + CsarInfo csarInfo, String nodeName, String yamlName, String yamlContent, Resource oldComplexVfc, Resource newComplexVfc) { + + Either handleComplexVfcRes; + Map newNodeTypesInfo = nodesInfo.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().getUnmarkedCopy())); + markNestedVfc(yamlContent, newNodeTypesInfo); + if(oldComplexVfc == null){ + handleComplexVfcRes = createResourceFromYaml(newComplexVfc, yamlContent, yamlName, newNodeTypesInfo, csarInfo, nodesArtifactsToHandle, false, true, nodeName); + if (handleComplexVfcRes.isRight()) { + log.debug("Failed to create resource {} from YAML {}. ", newComplexVfc.getName(), yamlName); } - importCsarInfo.getCreatedNodesToscaResourceNames().put(nodeType, handleNestedVfcRes.left().value().getToscaResourceName()); - LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction("certification on import", LifecycleChanceActionEnum.CREATE_FROM_CSAR); - log.debug("Going to certify cvfc {}. ", handleNestedVfcRes.left().value().getName()); - Either certRes = propagateStateToCertified(importCsarInfo.getModifier(), handleNestedVfcRes.left().value(), lifecycleChangeInfo, true, false, true); - if (certRes.isRight()) { - log.debug("Couldn't certify resource {}. ", handleNestedVfcRes.left().value()); - return certRes; + } else { + handleComplexVfcRes = updateResourceFromYaml(oldComplexVfc, newComplexVfc, AuditingActionEnum.UPDATE_RESOURCE_METADATA, createdArtifacts, true, yamlContent, yamlName, csarInfo, newNodeTypesInfo, nodesArtifactsToHandle, nodeName); + if (handleComplexVfcRes.isRight()) { + log.debug("Failed to update resource {} from YAML {}. ", oldComplexVfc.getName(), yamlName); } - createdResourcesFromdNodeTypeMap.put(nodeType, certRes.left().value()); - importCsarInfo.getCvfcToCreateQueue().remove(); } + return handleComplexVfcRes; + } - return handleNestedVfcRes; + private Either buildValidComplexVfc(Resource resource, CsarInfo csarInfo, String nodeName, Map nodesInfo) { + + Either result = null; + Resource complexVfc = buildComplexVfcMetadata(resource, csarInfo, nodeName, nodesInfo); + log.debug("************* Going to validate complex VFC from yaml {}", complexVfc.getName()); + + if(!csarInfo.getCvfcToCreateQueue().contains(nodeName)){ + csarInfo.getCvfcToCreateQueue().add(nodeName); + } else { + log.debug("Failed to validate complex VFC {}. Loop detected, VSP {}. ", complexVfc.getName(), csarInfo.getVfResourceName()); + result = Either.right(componentsUtils.getResponseFormat(ActionStatus.CFVC_LOOP_DETECTED, csarInfo.getVfResourceName(), complexVfc.getName())); + } + if(result == null){ + result = validateResourceBeforeCreate(complexVfc, csarInfo.getModifier(), AuditingActionEnum.IMPORT_RESOURCE, true, csarInfo); + if(result.isRight()){ + log.debug("Failed to validate complex VFC {}. ", complexVfc.getName()); + } + } + return result; } private String getNodeTypeActualName(String fullName) { @@ -1267,14 +1295,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } private Either, ResponseFormat> createNodeTypeResourceFromYaml(String yamlName, Entry nodeNameValue, User user, Map mapToConvert, Resource resourceVf, boolean needLock, - Map> nodeTypeArtifactsToHandle, List nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed) { + Map> nodeTypeArtifactsToHandle, List nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo) { Either resourceMetaData = fillResourceMetadata(yamlName, resourceVf, nodeNameValue.getKey(), user); if (resourceMetaData.isRight()) { return Either.right(resourceMetaData.right().value()); } - String csarVfName = resourceVf.getSystemName(); - String singleVfcYaml = buildNodeTypeYaml(nodeNameValue, mapToConvert, resourceMetaData.left().value().getResourceType(), csarVfName); + String singleVfcYaml = buildNodeTypeYaml(nodeNameValue, mapToConvert, resourceMetaData.left().value().getResourceType(), csarInfo.getVfResourceName()); Either eitherCreator = validateUser(user, "CheckIn Resource", resourceVf, AuditingActionEnum.CHECKIN_RESOURCE, true); if (eitherCreator.isRight()) { @@ -1282,7 +1309,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } user = eitherCreator.left().value(); - return this.createResourceFromNodeType(singleVfcYaml, resourceMetaData.left().value(), user, true, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed); + return this.createResourceFromNodeType(singleVfcYaml, resourceMetaData.left().value(), user, true, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo); } private String buildNodeTypeYaml(Entry nodeNameValue, Map mapToConvert, String nodeResourceType, String csarVfName) { @@ -1299,14 +1326,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return yaml.dumpAsMap(mapToConvert); } - private String buildNestedToscaResourceName(String nodeResourceType, String csarVfName, String originToscaResourceName) { - String actualName = getNodeTypeActualName(originToscaResourceName); - if (!actualName.startsWith(Constants.ABSTRACT)) { - actualName = "." + Constants.ABSTRACT + actualName; - } - return ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + nodeResourceType.toLowerCase() + '.' + ValidationUtils.convertToSystemName(csarVfName) + actualName; - } - public Either validateResourceCreationFromNodeType(Resource resource, User creator) { Either validateDerivedFromNotEmpty = this.validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE); @@ -1317,25 +1336,25 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } public Either, ResponseFormat> createResourceFromNodeType(String nodeTypeYaml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction, boolean needLock, - Map> nodeTypeArtifactsToHandle, List nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed) { + Map> nodeTypeArtifactsToHandle, List nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo) { LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction("certification on import", LifecycleChanceActionEnum.CREATE_FROM_CSAR); Function> validator = (resource) -> this.validateResourceCreationFromNodeType(resource, creator); - return this.resourceImportManager.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, true, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed); + return this.resourceImportManager.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, true, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo); } - private Either fillResourceMetadata(String yamlName, Resource resourceVf, String nodeTypeName, User user) { + private Either fillResourceMetadata(String yamlName, Resource resourceVf, String nodeName, User user) { UploadResourceInfo resourceMetaData = new UploadResourceInfo(); // validate nodetype name prefix - if (!nodeTypeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) { - log.debug("invalid nodeTypeName:{} does not start with {}.", nodeTypeName, Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX); - ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeTypeName); + if (!nodeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) { + log.debug("invalid nodeName:{} does not start with {}.", nodeName, Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX); + ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeName); return Either.right(responseFormat); } - String actualName = this.getNodeTypeActualName(nodeTypeName); - String namePrefix = nodeTypeName.replace(actualName, ""); + String actualName = this.getNodeTypeActualName(nodeName); + String namePrefix = nodeName.replace(actualName, ""); String resourceType = namePrefix.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length()); // if we import from csar, the node_type name can be @@ -1347,7 +1366,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { // validating type if (!ResourceTypeEnum.containsName(resourceType.toUpperCase())) { log.debug("invalid resourceType:{} the type is not one of the valide types:{}.", resourceType.toUpperCase(), ResourceTypeEnum.values()); - ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeTypeName); + ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeName); return Either.right(responseFormat); } @@ -1382,9 +1401,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.left(resourceMetaData); } - private void fillComplexVfcMetadata(Resource resourceVf, ImportCsarInfo importCsarInfo, Resource cvfc, String nodeTypeName, Map nodeTypesInfo, boolean shouldBeCertified) { - NodeTypeInfo nodeTypeInfo = nodeTypesInfo.get(nodeTypeName); - cvfc.setName(buildCvfcName(importCsarInfo.getVfResourceName(), nodeTypeName)); + private Resource buildComplexVfcMetadata(Resource resourceVf, CsarInfo csarInfo, String nodeName, Map nodesInfo) { + Resource cvfc = new Resource(); + NodeTypeInfo nodeTypeInfo = nodesInfo.get(nodeName); + cvfc.setName(buildCvfcName(csarInfo.getVfResourceName(), nodeName)); cvfc.setNormalizedName(ValidationUtils.normaliseComponentName(cvfc.getName())); cvfc.setSystemName(ValidationUtils.convertToSystemName(cvfc.getName())); cvfc.setResourceType(ResourceTypeEnum.CVFC); @@ -1392,12 +1412,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { cvfc.setDerivedFrom(nodeTypeInfo.getDerivedFrom()); cvfc.setDescription(ImportUtils.Constants.CVFC_DESCRIPTION); cvfc.setIcon(ImportUtils.Constants.DEFAULT_ICON); - cvfc.setContactId(importCsarInfo.getModifier().getUserId()); - cvfc.setCreatorUserId(importCsarInfo.getModifier().getUserId()); + cvfc.setContactId(csarInfo.getModifier().getUserId()); + cvfc.setCreatorUserId(csarInfo.getModifier().getUserId()); cvfc.setVendorName(resourceVf.getVendorName()); cvfc.setVendorRelease(resourceVf.getVendorRelease()); cvfc.setResourceVendorModelNumber(resourceVf.getResourceVendorModelNumber()); - cvfc.setToscaResourceName(buildNestedToscaResourceName(ResourceTypeEnum.VFC.name(), importCsarInfo.getVfResourceName(), nodeTypeName)); + cvfc.setToscaResourceName(buildNestedToscaResourceName(ResourceTypeEnum.VFC.name(), csarInfo.getVfResourceName(), nodeName)); cvfc.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID()); List tags = new ArrayList<>(); @@ -1413,23 +1433,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { categories.add(category); cvfc.setCategories(categories); - String version; - LifecycleStateEnum state; - - if (shouldBeCertified) { - version = ImportUtils.Constants.FIRST_CERTIFIED_VERSION_VERSION; - state = ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE; - } else { - version = ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION; - state = ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE_NOT_CERTIFIED_CHECKOUT; - } - cvfc.setVersion(version); - cvfc.setLifecycleState(state); + cvfc.setVersion(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION); + cvfc.setLifecycleState(ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE_NOT_CERTIFIED_CHECKOUT); cvfc.setHighestVersion(ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION); + + return cvfc; } - private String buildCvfcName(String resourceVfName, String nodeTypeName) { - String nameWithouNamespacePrefix = nodeTypeName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length()); + private String buildCvfcName(String resourceVfName, String nodeName) { + String nameWithouNamespacePrefix = nodeName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length()); String[] findTypes = nameWithouNamespacePrefix.split("\\."); String resourceType = findTypes[0]; return resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1); @@ -1437,11 +1449,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private Either createResourceAndRIsFromYaml(String yamlName, Resource resource, ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative, List createdArtifacts, String topologyTemplateYaml, Map nodeTypesInfo, - ImportCsarInfo importCsarInfo, Map>> nodeTypesArtifactsToCreate, - boolean shouldLock, boolean inTransaction, String nodeTypeName) { + CsarInfo csarInfo, Map>> nodeTypesArtifactsToCreate, + boolean shouldLock, boolean inTransaction, String nodeName) { boolean result = true; - Map createdVfcs = new HashMap<>(); List nodeTypesNewCreatedArtifacts = new ArrayList<>(); if (shouldLock) { @@ -1459,7 +1470,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { result = false; return genericResourceEither; } - Either createResourcesEither = createResourceTransaction(resource, importCsarInfo.getModifier(), isNormative, inTransaction); + Either createResourcesEither = createResourceTransaction(resource, csarInfo.getModifier(), isNormative, inTransaction); log.trace("************* createResourceFromYaml after full create resource {}", yamlName); if (createResourcesEither.isRight()) { result = false; @@ -1472,7 +1483,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { generateInputsFromGenericTypeProperties(resource, genericResourceEither.left().value()); Map inputs = parsedToscaYamlInfo.getInputs(); - Either createInputsOnResource = createInputsOnResource(resource, importCsarInfo.getModifier(), inputs, inTransaction); + Either createInputsOnResource = createInputsOnResource(resource, csarInfo.getModifier(), inputs, inTransaction); if (createInputsOnResource.isRight()) { result = false; return createInputsOnResource; @@ -1484,7 +1495,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName); createResourcesEither = createRIAndRelationsFromYaml(yamlName, resource, uploadComponentInstanceInfoMap, actionEnum, topologyTemplateYaml, - nodeTypesNewCreatedArtifacts, createdVfcs, nodeTypesInfo, importCsarInfo, nodeTypesArtifactsToCreate); + nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName); log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName); if (createResourcesEither.isRight()) { result = false; @@ -1507,7 +1518,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } else { groups = parsedToscaYamlInfo.getGroups(); } - Either createGroupsOnResource = createGroupsOnResource(resource, importCsarInfo.getModifier(), groups); + Either createGroupsOnResource = createGroupsOnResource(resource, csarInfo.getModifier(), groups); if (createGroupsOnResource.isRight()) { result = false; return createGroupsOnResource; @@ -1518,15 +1529,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.trace("************* Going to add artifacts from yaml {}", yamlName); if(resource.getResourceType() == ResourceTypeEnum.CVFC){ - if(nodeTypesArtifactsToCreate.containsKey(nodeTypeName) && nodeTypesArtifactsToCreate.get(nodeTypeName) !=null && !nodeTypesArtifactsToCreate.get(nodeTypeName).isEmpty()){ + if(nodeTypesArtifactsToCreate.containsKey(nodeName) && nodeTypesArtifactsToCreate.get(nodeName) !=null && !nodeTypesArtifactsToCreate.get(nodeName).isEmpty()){ Either, ResponseFormat> handleNodeTypeArtifactsRes = - handleNodeTypeArtifacts(resource, nodeTypesArtifactsToCreate.get(nodeTypeName), nodeTypesNewCreatedArtifacts, importCsarInfo.getModifier(), true); + handleNodeTypeArtifacts(resource, nodeTypesArtifactsToCreate.get(nodeName), nodeTypesNewCreatedArtifacts, csarInfo.getModifier(), true, false); if(handleNodeTypeArtifactsRes.isRight()){ return Either.right(handleNodeTypeArtifactsRes.right().value()); } } } else { - Either createdCsarArtifactsEither = this.handleVfCsarArtifacts(resource, importCsarInfo, createdArtifacts, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create), false, + Either createdCsarArtifactsEither = this.handleVfCsarArtifacts(resource, csarInfo, createdArtifacts, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create), false, inTransaction); log.trace("************* Finished to add artifacts from yaml {}", yamlName); if (createdCsarArtifactsEither.isRight()) { @@ -1536,7 +1547,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resource = createdCsarArtifactsEither.left().value(); } ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED); - componentsUtils.auditResource(responseFormat, importCsarInfo.getModifier(), resource, "", "", actionEnum, null); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", actionEnum, null); ASDCKpiApi.countCreatedResourcesKPI(); return Either.left(resource); @@ -1550,7 +1561,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts); if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, resource.getName()); + return Either.right(componentsUtils.getResponseFormat(actionStatus, resource.getName())); } log.debug("component and all its artifacts were deleted, id = {}", resource.getName()); } @@ -1832,24 +1843,23 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } private Either createRIAndRelationsFromYaml(String yamlName, Resource resource, Map uploadComponentInstanceInfoMap, AuditingActionEnum actionEnum, - String topologyTemplateYaml, List nodeTypesNewCreatedArtifacts, Map createdVfcs, - Map nodeTypesInfo, ImportCsarInfo importCsarInfo, Map>> nodeTypesArtifactsToCreate) { + String topologyTemplateYaml, List nodeTypesNewCreatedArtifacts, + Map nodeTypesInfo, CsarInfo csarInfo, Map>> nodeTypesArtifactsToCreate, + String nodeName) { Either result; Either createResourcesInstancesEither; log.debug("************* Going to create all nodes {}", yamlName); - Either, ResponseFormat> createdResourcesFromdNodeTypeMap = this.handleNodeTypes(yamlName, resource, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts, nodeTypesInfo, importCsarInfo); + Either, ResponseFormat> createdResourcesFromdNodeTypeMap = this.handleNodeTypes(yamlName, resource, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeName); log.debug("************* Finished to create all nodes {}", yamlName); if (createdResourcesFromdNodeTypeMap.isRight()) { log.debug("failed to resources from node types status is {}", createdResourcesFromdNodeTypeMap.right().value()); return Either.right(createdResourcesFromdNodeTypeMap.right().value()); } - createdVfcs.putAll(createdResourcesFromdNodeTypeMap.left().value()); - log.debug("************* Going to create all resource instances {}", yamlName); - createResourcesInstancesEither = createResourceInstances(importCsarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap, true, false, createdResourcesFromdNodeTypeMap.left().value()); + createResourcesInstancesEither = createResourceInstances(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap, true, false, csarInfo.getCreatedNodes()); log.debug("************* Finished to create all resource instances {}", yamlName); if (createResourcesInstancesEither.isRight()) { @@ -1859,7 +1869,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } resource = createResourcesInstancesEither.left().value(); log.debug("************* Going to create all relations {}", yamlName); - createResourcesInstancesEither = createResourceInstancesRelations(importCsarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap, true, false); + createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap, true, false); log.debug("************* Finished to create all relations {}", yamlName); @@ -1872,7 +1882,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } log.debug("************* Going to create positions {}", yamlName); - Either, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(resource, importCsarInfo.getModifier().getUserId()); + Either, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(resource, csarInfo.getModifier().getUserId()); log.debug("************* Finished to set positions {}", yamlName); result = eitherSetPosition.isRight() ? Either.right(eitherSetPosition.right().value()) : Either.left(resource); @@ -1906,43 +1916,48 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { @SuppressWarnings("unchecked") private Either, ResponseFormat> handleNodeTypes(String yamlName, Resource resource, String topologyTemplateYaml, boolean needLock, Map>> nodeTypesArtifactsToHandle, List nodeTypesNewCreatedArtifacts, - Map nodeTypesInfo, ImportCsarInfo importCsarInfo) { + Map nodeTypesInfo, CsarInfo csarInfo, String nodeName) { - Map createdResourcesFromdNodeTypeMap = new HashMap<>(); - Either, ResponseFormat> result = Either.left(createdResourcesFromdNodeTypeMap); + Either, ResponseFormat> result = Either.left(csarInfo.getCreatedNodes()); for (Entry nodeTypeEntry : nodeTypesInfo.entrySet()) { if (nodeTypeEntry.getValue().isNested()) { Either createResourceFromYaml = handleNestedVfc(resource, nodeTypesArtifactsToHandle, - nodeTypesNewCreatedArtifacts, nodeTypesInfo, importCsarInfo, nodeTypeEntry.getKey(), createdResourcesFromdNodeTypeMap); + nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypeEntry.getKey()); log.trace("************* finished to create node {}", nodeTypeEntry.getKey()); if (createResourceFromYaml.isRight()) { return Either.right(createResourceFromYaml.right().value()); } } } - Map mappedToscaTemplate = (Map) new Yaml().load(topologyTemplateYaml); + + Map mappedToscaTemplate = null; + if(StringUtils.isNotEmpty(nodeName) && MapUtils.isNotEmpty(nodeTypesInfo) && nodeTypesInfo.containsKey(nodeName)){ + mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate(); + } + if(MapUtils.isEmpty(mappedToscaTemplate)){ + mappedToscaTemplate = (Map) new Yaml().load(topologyTemplateYaml); + } + Either, ResponseFormat> createdNodeTypeFromMainTemplateEither = createResourcesFromYamlNodeTypesList(yamlName, resource, topologyTemplateYaml, mappedToscaTemplate, needLock, nodeTypesArtifactsToHandle, - nodeTypesNewCreatedArtifacts, nodeTypesInfo, importCsarInfo); + nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo); if (createdNodeTypeFromMainTemplateEither.isRight()) { ResponseFormat responseFormat = createdNodeTypeFromMainTemplateEither.right().value(); - componentsUtils.auditResource(responseFormat, importCsarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); return Either.right(responseFormat); } - createdResourcesFromdNodeTypeMap.putAll(createdNodeTypeFromMainTemplateEither.left().value()); - // add the created node types to the cache although they are not in the // graph. - createdResourcesFromdNodeTypeMap.values().stream().forEach(p -> cacheManagerOperation.storeComponentInCache(p, NodeTypeEnum.Resource)); + csarInfo.getCreatedNodes().values().stream().forEach(p -> cacheManagerOperation.storeComponentInCache(p, NodeTypeEnum.Resource)); return result; } - private Either handleVfCsarArtifacts(Resource resource, ImportCsarInfo importCsarInfo, List createdArtifacts, ArtifactOperationInfo artifactOperation, boolean shouldLock, + private Either handleVfCsarArtifacts(Resource resource, CsarInfo csarInfo, List createdArtifacts, ArtifactOperationInfo artifactOperation, boolean shouldLock, boolean inTransaction) { - if (importCsarInfo.getCsar() != null) { + if (csarInfo.getCsar() != null) { String vendorLicenseModelId = null; String vfLicenseModelId = null; @@ -1959,26 +1974,26 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } // Specific Behavior for license artifacts - createOrUpdateSingleNonMetaArtifact(resource, importCsarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VENDOR_LICENSE_MODEL, Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, + createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VENDOR_LICENSE_MODEL, Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME, Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId, artifactOperation, null, shouldLock, inTransaction); - createOrUpdateSingleNonMetaArtifact(resource, importCsarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL, ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, + createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL, ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VF_LICENSE_LABEL, Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, artifactOperation, null, shouldLock, inTransaction); - Either eitherCreateResult = createOrUpdateNonMetaArtifacts(importCsarInfo, resource, createdArtifacts, shouldLock, inTransaction, artifactOperation); + Either eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock, inTransaction, artifactOperation); if (eitherCreateResult.isRight()) { return Either.right(eitherCreateResult.right().value()); } - Either, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils.getArtifactsMeta(importCsarInfo.getCsar(), importCsarInfo.getCsarUUID(), componentsUtils); + Either, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils.getArtifactsMeta(csarInfo.getCsar(), csarInfo.getCsarUUID(), componentsUtils); if (artifacsMetaCsarStatus.isLeft()) { String artifactsFileName = artifacsMetaCsarStatus.left().value().getKey(); String artifactsContents = artifacsMetaCsarStatus.left().value().getValue(); Either createArtifactsFromCsar = Either.left(resource); if (artifactOperation.getArtifactOperationEnum() == ArtifactOperationEnum.Create) - createArtifactsFromCsar = createResourceArtifactsFromCsar(importCsarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction); + createArtifactsFromCsar = createResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction); else - createArtifactsFromCsar = updateResourceArtifactsFromCsar(importCsarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction); + createArtifactsFromCsar = updateResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction); if (createArtifactsFromCsar.isRight()) { log.debug("Couldn't create artifacts from artifacts.meta"); return Either.right(createArtifactsFromCsar.right().value()); @@ -1997,7 +2012,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { * Either.right(componentsUtils.getResponseFormat(actionStatus)); } } } */ for (String artifactId : artifactsToDelete) { - Either, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, importCsarInfo.getModifier(), AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, + Either, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, csarInfo.getModifier(), AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, null, null, shouldLock, inTransaction); if (handleDelete.isRight()) { log.debug("Couldn't delete artifact {}", artifactId); @@ -2018,18 +2033,18 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.left(resource); } - private Either createOrUpdateSingleNonMetaArtifact(Resource resource, ImportCsarInfo importCsarInfo, String artifactPath, String artifactFileName, String artifactType, + private Either createOrUpdateSingleNonMetaArtifact(Resource resource, CsarInfo csarInfo, String artifactPath, String artifactFileName, String artifactType, ArtifactGroupTypeEnum artifactGroupType, String artifactLabel, String artifactDisplayName, String artifactDescription, String artifactId, ArtifactOperationInfo operation, List createdArtifacts, boolean shouldLock, boolean inTransaction) { byte[] artifactFileBytes = null; - if (importCsarInfo.getCsar().containsKey(artifactPath)) { - artifactFileBytes = importCsarInfo.getCsar().get(artifactPath); + if (csarInfo.getCsar().containsKey(artifactPath)) { + artifactFileBytes = csarInfo.getCsar().get(artifactPath); } Either result = Either.left(true); if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.Update || operation.getArtifactOperationEnum() == ArtifactOperationEnum.Delete) { if (artifactId != null && !artifactId.isEmpty() && artifactFileBytes == null) { - Either, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, importCsarInfo.getModifier(), AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, null, + Either, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, csarInfo.getModifier(), AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, null, null, shouldLock, inTransaction); if (handleDelete.isRight()) { result = Either.right(handleDelete.right().value()); @@ -2044,10 +2059,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } if (artifactFileBytes != null) { Map vendorLicenseModelJson = buildJsonForUpdateArtifact(artifactId, artifactFileName, artifactType, artifactGroupType, artifactLabel, artifactDisplayName, artifactDescription, artifactFileBytes, null); - Either, ResponseFormat> eitherNonMetaArtifacts = createOrUpdateCsarArtifactFromJson(resource, importCsarInfo.getModifier(), vendorLicenseModelJson, operation, shouldLock, inTransaction); + Either, ResponseFormat> eitherNonMetaArtifacts = createOrUpdateCsarArtifactFromJson(resource, csarInfo.getModifier(), vendorLicenseModelJson, operation, shouldLock, inTransaction); addNonMetaCreatedArtifactsToSupportRollback(operation, createdArtifacts, eitherNonMetaArtifacts); if (eitherNonMetaArtifacts.isRight()) { - BeEcompErrorManager.getInstance().logInternalFlowError("UploadLicenseArtifact", "Failed to upload license artifact: " + artifactFileName + "With csar uuid: " + importCsarInfo.getCsarUUID(), ErrorSeverity.WARNING); + BeEcompErrorManager.getInstance().logInternalFlowError("UploadLicenseArtifact", "Failed to upload license artifact: " + artifactFileName + "With csar uuid: " + csarInfo.getCsarUUID(), ErrorSeverity.WARNING); return Either.right(eitherNonMetaArtifacts.right().value()); } } @@ -2078,13 +2093,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.left(uploadArtifactToService.left().value()); } - public Either updateResourceArtifactsFromCsar(ImportCsarInfo importCsarInfo, Resource resource, String artifactsMetaFile, String artifactsMetaFileName, List createdNewArtifacts, + public Either updateResourceArtifactsFromCsar(CsarInfo csarInfo, Resource resource, String artifactsMetaFile, String artifactsMetaFileName, List createdNewArtifacts, boolean shouldLock, boolean inTransaction) { - Either>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, importCsarInfo.getModifier()); + Either>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, csarInfo.getModifier()); if (parseResourceInfoFromYamlEither.isRight()) { ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value(); - componentsUtils.auditResource(responseFormat, importCsarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); return Either.right(responseFormat); } @@ -2108,7 +2123,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } } - return createResourceArtifacts(importCsarInfo, resource, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdNewArtifacts, shouldLock, inTransaction); + return createResourceArtifacts(csarInfo, resource, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdNewArtifacts, shouldLock, inTransaction); } // find master in group @@ -2138,13 +2153,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Set artifactsToDelete = new HashSet(); Map> groupToDelete = new HashMap>(); - Map> dissocArtifactFromGroup = new HashMap>(); Set jsonMasterArtifacts = parsedGroup.keySet(); Map mergedgroup = mergeGroupInUpdateFlow(groupArtifact, parsedGroup, artifactsToDelete, groupToDelete, jsonMasterArtifacts, createdDeplymentArtifactsAfterDelete); // Set deletedArtifactsName = new HashSet(); - Either, ResponseFormat> deletedArtifactsEither = deleteArtifactsInUpdateCsarFlow(resource, importCsarInfo.getModifier(), shouldLock, inTransaction, artifactsToDelete, groupToDelete); + Either, ResponseFormat> deletedArtifactsEither = deleteArtifactsInUpdateCsarFlow(resource, csarInfo.getModifier(), shouldLock, inTransaction, artifactsToDelete, groupToDelete); if (deletedArtifactsEither.isRight()) { log.debug("Failed to delete artifacts. Status is {} ", deletedArtifactsEither.right().value()); @@ -2171,7 +2185,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ////////////// dissociate, associate or create ////////////// artifacts//////////////////////////// - Either assDissotiateEither = associateAndDissociateArtifactsToGroup(importCsarInfo, resource, createdNewArtifacts, labelCounter, shouldLock, inTransaction, createdDeplymentArtifactsAfterDelete, + Either assDissotiateEither = associateAndDissociateArtifactsToGroup(csarInfo, resource, createdNewArtifacts, labelCounter, shouldLock, inTransaction, createdDeplymentArtifactsAfterDelete, mergedgroup, deletedArtifacts); if (assDissotiateEither.isRight()) { @@ -2251,7 +2265,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (validateGroupNamesRes.isRight()) { return Either.right(validateGroupNamesRes.right().value()); } - Either resStatus = createGroupDeploymentArtifactsFromCsar(importCsarInfo, resource, newArtifactsGroup, createdNewArtifacts, createdDeplymentArtifactsAfterDelete, labelCounter, shouldLock, inTransaction); + Either resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, resource, newArtifactsGroup, createdNewArtifacts, createdDeplymentArtifactsAfterDelete, labelCounter, shouldLock, inTransaction); if (resStatus.isRight()) return resStatus; } @@ -2332,7 +2346,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.left(deletedArtifacts); } - private Either associateAndDissociateArtifactsToGroup(ImportCsarInfo importCsarInfo, Resource resource, List createdNewArtifacts, int labelCounter, boolean shouldLock, + private Either associateAndDissociateArtifactsToGroup(CsarInfo csarInfo, Resource resource, List createdNewArtifacts, int labelCounter, boolean shouldLock, boolean inTransaction, List createdDeplymentArtifactsAfterDelete, Map mergedgroup, List deletedArtifacts) { Map> artifactsToAssotiate = new HashMap>(); Map>> artifactsToUpdateMap = new HashMap>>(); @@ -2365,7 +2379,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { for (ImmutablePair artifact : artifactsToUpdateList) { String prevUUID = artifact.getKey().getArtifactUUID(); String prevId = artifact.getKey().getUniqueId(); - Either updateArtifactEither = updateDeploymentArtifactsFromCsar(importCsarInfo, resource, artifact.getKey(), artifact.getValue(), updatedArtifacts, + Either updateArtifactEither = updateDeploymentArtifactsFromCsar(csarInfo, resource, artifact.getKey(), artifact.getValue(), updatedArtifacts, artifact.getRight().getRelatedArtifactsInfo(), shouldLock, inTransaction); if (updateArtifactEither.isRight()) { log.debug("failed to update artifacts. status is {}", updateArtifactEither.right().value()); @@ -2383,8 +2397,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } - List associateArtifactGroup = new ArrayList(); - for (Entry> associateEntry : artifactsToAssotiate.entrySet()) { List associatedArtifact = associateEntry.getValue(); Set arifactsUids = new HashSet(); @@ -2431,7 +2443,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } if (isCreate) { - Either createArtifactEither = createDeploymentArtifact(importCsarInfo, resource, ARTIFACTS_PATH, artifactTemplate, createdNewArtifacts, labelCounter, shouldLock, inTransaction); + Either createArtifactEither = createDeploymentArtifact(csarInfo, resource, ARTIFACTS_PATH, artifactTemplate, createdNewArtifacts, labelCounter, shouldLock, inTransaction); if (createArtifactEither.isRight()) { resEither = Either.right(createArtifactEither.right().value()); return resEither; @@ -2442,7 +2454,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(createdArtifact.getArtifactType()); if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_VOL) { Either createHeatEnvPlaceHolder = artifactsBusinessLogic.createHeatEnvPlaceHolder(createdArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME, resource.getUniqueId(), NodeTypeEnum.Resource, - resource.getName(), importCsarInfo.getModifier(), resource, null); + resource.getName(), csarInfo.getModifier(), resource, null); if (createHeatEnvPlaceHolder.isRight()) { return Either.right(createHeatEnvPlaceHolder.right().value()); } @@ -2605,20 +2617,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } - public Either createResourceArtifactsFromCsar(ImportCsarInfo importCsarInfo, Resource resource, String artifactsMetaFile, String artifactsMetaFileName, List createdArtifacts, + public Either createResourceArtifactsFromCsar(CsarInfo csarInfo, Resource resource, String artifactsMetaFile, String artifactsMetaFileName, List createdArtifacts, boolean shouldLock, boolean inTransaction) { log.debug("parseResourceArtifactsInfoFromFile start"); - Either>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, importCsarInfo.getModifier()); + Either>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, csarInfo.getModifier()); if (parseResourceInfoFromYamlEither.isRight()) { ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value(); - componentsUtils.auditResource(responseFormat, importCsarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null); return Either.right(responseFormat); } log.debug("parseResourceArtifactsInfoFromFile end"); log.debug("createResourceArtifacts start"); - Either respStatus = createResourceArtifacts(importCsarInfo, resource, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdArtifacts, shouldLock, inTransaction); + Either respStatus = createResourceArtifacts(csarInfo, resource, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdArtifacts, shouldLock, inTransaction); if (respStatus.isRight()) { return respStatus; } @@ -2636,7 +2648,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } - private Either createGroupDeploymentArtifactsFromCsar(ImportCsarInfo importCsarInfo, Resource resource, List artifactsTemplateList, + private Either createGroupDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource, List artifactsTemplateList, List createdNewArtifacts, List artifactsFromResource, int labelCounter, boolean shouldLock, boolean inTransaction) { Either resStatus = Either.left(resource); List createdGroups = resource.getGroups(); @@ -2651,7 +2663,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Set artifactsGroup = new HashSet(); Set artifactsUUIDGroup = new HashSet(); - resStatus = createDeploymentArtifactsFromCsar(importCsarInfo, resource, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdNewArtifacts, artifactsFromResource, labelCounter, shouldLock, inTransaction); + resStatus = createDeploymentArtifactsFromCsar(csarInfo, resource, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdNewArtifacts, artifactsFromResource, labelCounter, shouldLock, inTransaction); if (resStatus.isRight()) return resStatus; @@ -2703,14 +2715,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } resource = component.left().value(); - Either, ResponseFormat> addGroups = groupBusinessLogic.addGroups(resource, importCsarInfo.getModifier(), ComponentTypeEnum.RESOURCE, needToAdd); + Either, ResponseFormat> addGroups = groupBusinessLogic.addGroups(resource, csarInfo.getModifier(), ComponentTypeEnum.RESOURCE, needToAdd); if (addGroups.isRight()) return Either.right(addGroups.right().value()); return resStatus; } - private Either createDeploymentArtifactsFromCsar(ImportCsarInfo importCsarInfo, Resource resource, Set artifactsGroup, Set artifactsUUIDGroup, + private Either createDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource, Set artifactsGroup, Set artifactsUUIDGroup, ArtifactTemplateInfo artifactTemplateInfo, List createdArtifacts, List artifactsFromResource, int labelCounter, boolean shoudLock, boolean inTransaction) { Either resStatus = Either.left(resource); String artifactFileName = artifactTemplateInfo.getFileName(); @@ -2759,7 +2771,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { // if not exist need to create if (!alreadyExist) { - Either newArtifactEither = createDeploymentArtifact(importCsarInfo, resource, ARTIFACTS_PATH, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction); + Either newArtifactEither = createDeploymentArtifact(csarInfo, resource, ARTIFACTS_PATH, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction); if (newArtifactEither.isRight()) { resStatus = Either.right(newArtifactEither.right().value()); return resStatus; @@ -2770,7 +2782,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(newArtifact.getArtifactType()); if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_VOL) { Either createHeatEnvPlaceHolder = artifactsBusinessLogic.createHeatEnvPlaceHolder(newArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME, resource.getUniqueId(), NodeTypeEnum.Resource, - resource.getName(), importCsarInfo.getModifier(), resource, null); + resource.getName(), csarInfo.getModifier(), resource, null); if (createHeatEnvPlaceHolder.isRight()) { return Either.right(createHeatEnvPlaceHolder.right().value()); } @@ -2787,7 +2799,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { List relatedArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo(); if (relatedArtifacts != null) { for (ArtifactTemplateInfo relatedArtifactTemplateInfo : relatedArtifacts) { - resStatus = createDeploymentArtifactsFromCsar(importCsarInfo, resource, artifactsGroup, artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, artifactsFromResource, labelCounter, shoudLock, inTransaction); + resStatus = createDeploymentArtifactsFromCsar(csarInfo, resource, artifactsGroup, artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, artifactsFromResource, labelCounter, shoudLock, inTransaction); if (resStatus.isRight()) return resStatus; } @@ -2795,7 +2807,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return resStatus; } - private Either createResourceArtifacts(ImportCsarInfo importCsarInfo, Resource resource, Map> artifactsMap, AuditingActionEnum createResource, + private Either createResourceArtifacts(CsarInfo csarInfo, Resource resource, Map> artifactsMap, AuditingActionEnum createResource, List createdArtifacts, boolean shouldLock, boolean inTransaction) { Either resStatus = Either.left(resource); @@ -2804,7 +2816,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { for (List groupTemplateList : arifactsCollection) { if (groupTemplateList != null) { - resStatus = createGroupDeploymentArtifactsFromCsar(importCsarInfo, resource, groupTemplateList, createdArtifacts, 0, shouldLock, inTransaction); + resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, resource, groupTemplateList, createdArtifacts, 0, shouldLock, inTransaction); if (resStatus.isRight()) return resStatus; } @@ -2814,7 +2826,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } - private Either createOrUpdateNonMetaArtifacts(ImportCsarInfo importCsarInfo, Resource resource, List createdArtifacts, boolean shouldLock, boolean inTransaction, ArtifactOperationInfo artifactOperation) { + private Either createOrUpdateNonMetaArtifacts(CsarInfo csarInfo, Resource resource, List createdArtifacts, boolean shouldLock, boolean inTransaction, ArtifactOperationInfo artifactOperation) { Either resStatus = null; Map>> collectedWarningMessages = new HashMap<>(); @@ -2822,7 +2834,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { try { List artifactPathAndNameList = // Stream of file paths contained in csar - importCsarInfo.getCsar().entrySet().stream() + csarInfo.getCsar().entrySet().stream() // Filter in only VF artifact path location .filter(e -> Pattern.compile(VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN).matcher(e.getKey()).matches()) // Validate and add warnings @@ -2846,7 +2858,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { vfCsarArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class); vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList); } else { - Either>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, importCsarInfo.getModifier()); + Either>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, csarInfo.getModifier()); if (findVfCsarArtifactsToHandleRes.isRight()) { resStatus = Either.right(findVfCsarArtifactsToHandleRes.right().value()); @@ -2862,7 +2874,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { // Stream of artifacts to be created currArtifactOperationPair.getValue().stream() // create each artifact - .map(e -> createOrUpdateSingleNonMetaArtifact(resource, importCsarInfo, e.getPath(), e.getArtifactName(), e.getArtifactType().getType(), e.getArtifactGroupType(), e.getArtifactLabel(), e.getDisplayName(), + .map(e -> createOrUpdateSingleNonMetaArtifact(resource, csarInfo, e.getPath(), e.getArtifactName(), e.getArtifactType().getType(), e.getArtifactGroupType(), e.getArtifactLabel(), e.getDisplayName(), CsarUtils.ARTIFACT_CREATED_FROM_CSAR, e.getArtifactUniqueId(), artifactsBusinessLogic.new ArtifactOperationInfo(false, false, currArtifactOperationPair.getKey()), createdArtifacts, shouldLock, inTransaction)) // filter in only error @@ -2945,7 +2957,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return result; } - private Either createGroupDeploymentArtifactsFromCsar(ImportCsarInfo importCsarInfo, Resource resource, List artifactsTemplateList, List createdArtifacts, + private Either createGroupDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource, List artifactsTemplateList, List createdArtifacts, int labelCounter, boolean shouldLock, boolean inTransaction) { Either resStatus = Either.left(resource); List createdGroups = resource.getGroups(); @@ -2969,7 +2981,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Set artifactsUUIDGroup = new HashSet(); log.debug("createDeploymentArtifactsFromCsar start"); - resStatus = createDeploymentArtifactFromCsar(importCsarInfo, ARTIFACTS_PATH, resource, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdArtifacts, labelCounter, shouldLock, inTransaction); + resStatus = createDeploymentArtifactFromCsar(csarInfo, ARTIFACTS_PATH, resource, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdArtifacts, labelCounter, shouldLock, inTransaction); log.debug("createDeploymentArtifactsFromCsar end"); if (resStatus.isRight()) return resStatus; @@ -3024,7 +3036,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); } - Either, ResponseFormat> createGroups = groupBusinessLogic.addGroups(component.left().value(), importCsarInfo.getModifier(), ComponentTypeEnum.RESOURCE, needToCreate); + Either, ResponseFormat> createGroups = groupBusinessLogic.addGroups(component.left().value(), csarInfo.getModifier(), ComponentTypeEnum.RESOURCE, needToCreate); if (createGroups.isRight()) { return Either.right(createGroups.right().value()); } @@ -3109,7 +3121,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String heatFileNAme = prop.getValue(); if (null == heatFileNAme || heatFileNAme.isEmpty()) continue; - List artifacts = new ArrayList(); + List artifacts = new ArrayList(); for (String artifactId : artifactsGroup) { Optional opArt = createdArtifacts.stream().filter(p -> p.getUniqueId().equals(artifactId)).findAny(); if (opArt.isPresent()) { @@ -3133,7 +3145,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } - private Either createDeploymentArtifactFromCsar(ImportCsarInfo importCsarInfo, String artifactPath, Resource resource, Set artifactsGroup, Set artifactsUUIDGroup, + private Either createDeploymentArtifactFromCsar(CsarInfo csarInfo, String artifactPath, Resource resource, Set artifactsGroup, Set artifactsUUIDGroup, ArtifactTemplateInfo artifactTemplateInfo, List createdArtifacts, int labelCounter, boolean shoudLock, boolean inTransaction) { Either resStatus = Either.left(resource); String artifactFileName = artifactTemplateInfo.getFileName(); @@ -3160,7 +3172,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { // if not exist need to create if (!alreadyExist) { - Either newArtifactEither = createDeploymentArtifact(importCsarInfo, resource, artifactPath, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction); + Either newArtifactEither = createDeploymentArtifact(csarInfo, resource, artifactPath, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction); if (newArtifactEither.isRight()) { resStatus = Either.right(newArtifactEither.right().value()); return resStatus; @@ -3172,7 +3184,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(newArtifact.getArtifactType()); if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_VOL) { Either createHeatEnvPlaceHolder = artifactsBusinessLogic.createHeatEnvPlaceHolder(newArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME, resource.getUniqueId(), NodeTypeEnum.Resource, - resource.getName(), importCsarInfo.getModifier(), resource, null); + resource.getName(), csarInfo.getModifier(), resource, null); if (createHeatEnvPlaceHolder.isRight()) { return Either.right(createHeatEnvPlaceHolder.right().value()); } @@ -3189,7 +3201,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { List relatedArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo(); if (relatedArtifacts != null) { for (ArtifactTemplateInfo relatedArtifactTemplateInfo : relatedArtifacts) { - resStatus = createDeploymentArtifactFromCsar(importCsarInfo, artifactPath, resource, artifactsGroup, artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction); + resStatus = createDeploymentArtifactFromCsar(csarInfo, artifactPath, resource, artifactsGroup, artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction); if (resStatus.isRight()) return resStatus; } @@ -3206,10 +3218,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return artifactEnvUid; } - private Either createDeploymentArtifact(ImportCsarInfo importCsarInfo, Resource resource, String artifactPath, ArtifactTemplateInfo artifactTemplateInfo, + private Either createDeploymentArtifact(CsarInfo csarInfo, Resource resource, String artifactPath, ArtifactTemplateInfo artifactTemplateInfo, List createdArtifacts, int labelCounter, boolean shoudLock, boolean inTransaction) { final String artifactFileName = artifactTemplateInfo.getFileName(); - Either, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(importCsarInfo.getCsarUUID(), importCsarInfo.getCsar(), artifactPath + artifactFileName, artifactFileName, componentsUtils); + Either, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), artifactPath + artifactFileName, artifactFileName, componentsUtils); if (artifactContententStatus.isRight()) { return Either.right(artifactContententStatus.right().value()); } @@ -3217,7 +3229,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Map json = buildJsonForArtifact(artifactTemplateInfo, artifactContententStatus.left().value().getValue(), labelCounter); - Either, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, importCsarInfo.getModifier(), json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create), + Either, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, csarInfo.getModifier(), json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create), shoudLock, inTransaction); if (uploadArtifactToService.isRight()) @@ -3226,7 +3238,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value(); if (currentInfo.getHeatParameters() != null) { - Either updateEnvEither = updateHeatParamsFromCsar(resource, importCsarInfo, artifactTemplateInfo, currentInfo, false); + Either updateEnvEither = updateHeatParamsFromCsar(resource, csarInfo, artifactTemplateInfo, currentInfo, false); if (updateEnvEither.isRight()) { log.debug("failed to update parameters to artifact {}", artifactFileName); return Either.right(updateEnvEither.right().value()); @@ -3242,17 +3254,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } - private Either updateDeploymentArtifactsFromCsar(ImportCsarInfo importCsarInfo, Resource resource, ArtifactDefinition oldArtifact, ArtifactTemplateInfo artifactTemplateInfo, + private Either updateDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource, ArtifactDefinition oldArtifact, ArtifactTemplateInfo artifactTemplateInfo, List updatedArtifacts, List updatedRequiredArtifacts, boolean shouldLock, boolean inTransaction) { Either resStatus = null; String artifactFileName = artifactTemplateInfo.getFileName(); - String artifactUid = ""; // check if artifacts already exist for (ArtifactDefinition updatedArtifact : updatedArtifacts) { if (updatedArtifact.getArtifactName().equals(artifactFileName)) { - artifactUid = updatedArtifact.getUniqueId(); if (!updatedArtifact.getArtifactType().equalsIgnoreCase(artifactTemplateInfo.getType())) { log.debug("Artifact with name {} and type {} already updated with type {}", artifactFileName, artifactTemplateInfo.getType(), updatedArtifact.getArtifactType()); BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected formatr, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR); @@ -3265,7 +3275,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } - Either, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(importCsarInfo.getCsarUUID(), importCsarInfo.getCsar(), CsarUtils.ARTIFACTS_PATH + artifactFileName, artifactFileName, componentsUtils); + Either, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), CsarUtils.ARTIFACTS_PATH + artifactFileName, artifactFileName, componentsUtils); if (artifactContententStatus.isRight()) { resStatus = Either.right(artifactContententStatus.right().value()); return resStatus; @@ -3274,7 +3284,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Map json = buildJsonForUpdateArtifact(oldArtifact.getUniqueId(), artifactFileName, oldArtifact.getArtifactType(), ArtifactGroupTypeEnum.DEPLOYMENT, oldArtifact.getArtifactLabel(), oldArtifact.getArtifactDisplayName(), oldArtifact.getDescription(), artifactContententStatus.left().value().getRight(), updatedRequiredArtifacts); - Either, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, importCsarInfo.getModifier(), json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Update), + Either, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, csarInfo.getModifier(), json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Update), shouldLock, inTransaction); if (uploadArtifactToService.isRight()) { @@ -3283,7 +3293,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value(); - Either updateEnvEither = updateHeatParamsFromCsar(resource, importCsarInfo, artifactTemplateInfo, currentInfo, true); + Either updateEnvEither = updateHeatParamsFromCsar(resource, csarInfo, artifactTemplateInfo, currentInfo, true); if (updateEnvEither.isRight()) { log.debug("failed to update parameters to artifact {}", artifactFileName); resStatus = Either.right(updateEnvEither.right().value()); @@ -3291,7 +3301,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } // TODO evg update env time ( must be separate US for this!!!!) - artifactUid = updateEnvEither.left().value().getUniqueId(); updatedArtifacts.add(updateEnvEither.left().value()); resStatus = Either.left(updateEnvEither.left().value()); @@ -3299,11 +3308,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } - private Either updateHeatParamsFromCsar(Resource resource, ImportCsarInfo importCsarInfo, ArtifactTemplateInfo artifactTemplateInfo, ArtifactDefinition currentInfo, boolean isUpdateEnv) { + private Either updateHeatParamsFromCsar(Resource resource, CsarInfo csarInfo, ArtifactTemplateInfo artifactTemplateInfo, ArtifactDefinition currentInfo, boolean isUpdateEnv) { Either resStatus = Either.left(currentInfo); if (artifactTemplateInfo.getEnv() != null && !artifactTemplateInfo.getEnv().isEmpty()) { - Either, ResponseFormat> artifactparamsStatus = CsarValidationUtils.getArtifactsContent(importCsarInfo.getCsarUUID(), importCsarInfo.getCsar(), CsarUtils.ARTIFACTS_PATH + artifactTemplateInfo.getEnv(), artifactTemplateInfo.getEnv(), + Either, ResponseFormat> artifactparamsStatus = CsarValidationUtils.getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), CsarUtils.ARTIFACTS_PATH + artifactTemplateInfo.getEnv(), artifactTemplateInfo.getEnv(), componentsUtils); if (artifactparamsStatus.isRight()) { resStatus = Either.right(artifactparamsStatus.right().value()); @@ -3442,6 +3451,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return json; } + @SuppressWarnings({ "unchecked", "static-access" }) private Either>, ResponseFormat> parseResourceArtifactsInfoFromFile(Resource resource, String artifactsMetaFile, String artifactFileName, User user) { try { @@ -3541,7 +3551,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (allDataTypes.isRight()) { TitanOperationStatus status = allDataTypes.right().value(); BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(status)), yamlName); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(status)), yamlName)); } @@ -3575,13 +3585,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String resourceInstanceId = currentCompInstance.getUniqueId(); Resource originResource = null; if (!originCompMap.containsKey(currentCompInstance.getComponentUid())) { - Either getPropertyRes = toscaOperationFacade.getToscaFullElement(currentCompInstance.getComponentUid()); - if (getPropertyRes.isRight()) { - log.debug("failed to find properties of resource {} status is {}", currentCompInstance.getComponentUid(), getPropertyRes); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getPropertyRes.right().value()), yamlName); + Either getOriginResourceRes = toscaOperationFacade.getToscaFullElement(currentCompInstance.getComponentUid()); + if (getOriginResourceRes.isRight()) { + log.debug("failed to fetch resource with uniqueId {} and tosca component name {} status is {}", currentCompInstance.getComponentUid(), currentCompInstance.getToscaComponentName(), getOriginResourceRes); + ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getOriginResourceRes.right().value()), yamlName); return Either.right(responseFormat); } - originResource = getPropertyRes.left().value(); + originResource = getOriginResourceRes.left().value(); originCompMap.put(originResource.getUniqueId(), originResource); } else { originResource = originCompMap.get(currentCompInstance.getComponentUid()); @@ -3628,7 +3638,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(addPropertiesValueToRiRes); } } else { - // TO DO + Either genericResourceEither = fetchAndSetDerivedFromGenericType(originResource); + if (genericResourceEither.isRight()) { + return genericResourceEither; + } + log.trace("************* Going to add inputs from from original resource {} to resource instance. ", originResource.getName()); + if (originResource.shouldGenerateInputs()) + generateInputsFromGenericTypeProperties(originResource, genericResourceEither.left().value()); + ResponseFormat addInputValueToRiRes = addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, yamlName, instInputs, allDataTypes.left().value()); if (addInputValueToRiRes.getStatus() != 200) { return Either.right(addInputValueToRiRes); @@ -3735,8 +3752,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private ResponseFormat addRelationToRI(String yamlName, Resource resource, UploadComponentInstanceInfo nodesInfoValue, List relations) { List componentInstancesList = resource.getComponentInstances(); - long totalCreateRel = 0; - long totalCreatePropVal = 0; UploadComponentInstanceInfo uploadComponentInstanceInfo = nodesInfoValue; @@ -3764,8 +3779,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (regMap != null) { Iterator>> nodesRegValue = regMap.entrySet().iterator(); - long startAddRelation = System.currentTimeMillis(); - while (nodesRegValue.hasNext()) { Entry> nodesRegInfoEntry = nodesRegValue.next(); @@ -3826,7 +3839,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { relations.add(regCapRelDef); } } - totalCreateRel += (System.currentTimeMillis() - startAddRelation); } else if (resource.getResourceType() != ResourceTypeEnum.CVFC) { ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK, yamlName); return responseFormat; @@ -3840,7 +3852,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (propMap != null && propMap.size() > 0) { Map currPropertiesMap = new HashMap(); - int index = 0; List listFromMap = originResource.getInputs(); if (listFromMap == null || listFromMap.isEmpty()) { log.debug("failed to find properties "); @@ -3945,7 +3956,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (propMap != null && propMap.size() > 0) { Map currPropertiesMap = new HashMap(); - int index = 0; List listFromMap = originResource.getProperties(); if (listFromMap == null || listFromMap.isEmpty()) { log.debug("failed to find properties "); @@ -4195,11 +4205,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } @SuppressWarnings("unchecked") - public Either parseResourceInfoFromYaml(String yamlFileName, Resource resource, String resourceYml, User user, Map createdNodesToscaResourceNames, Map nodeTypesInfo, String nodeTypeName) { + public Either parseResourceInfoFromYaml(String yamlFileName, Resource resource, String resourceYml, User user, Map createdNodesToscaResourceNames, Map nodeTypesInfo, String nodeName) { Map mappedToscaTemplate; - if(nodeTypesInfo != null && nodeTypeName != null && nodeTypesInfo.containsKey(nodeTypeName)){ - mappedToscaTemplate = nodeTypesInfo.get(nodeTypeName).getMappedToscaTemplate(); + if(nodeTypesInfo != null && nodeName != null && nodeTypesInfo.containsKey(nodeName)){ + mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate(); } else { mappedToscaTemplate = (Map) new Yaml().load(resourceYml); @@ -4237,7 +4247,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } private Either createResourceInstances(User user, String yamlName, Resource resource, Map uploadResInstancesMap, boolean inTransaction, boolean needLock, - Map nodeTypeNamespaceMap) { + Map nodeNamespaceMap) { Either eitherResource = null; log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName); @@ -4248,8 +4258,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } Map existingnodeTypeMap = new HashMap<>(); - if (nodeTypeNamespaceMap != null && !nodeTypeNamespaceMap.isEmpty()) { - nodeTypeNamespaceMap.entrySet().stream().forEach(x -> existingnodeTypeMap.put(x.getValue().getToscaResourceName(), x.getValue())); + if (nodeNamespaceMap != null && !nodeNamespaceMap.isEmpty()) { + nodeNamespaceMap.entrySet().stream().forEach(x -> existingnodeTypeMap.put(x.getValue().getToscaResourceName(), x.getValue())); } Iterator> nodesInfoValue = uploadResInstancesMap.entrySet().iterator(); @@ -4262,8 +4272,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { // updating type if the type is node type name - we need to take the // updated name log.debug("*************Going to create resource instances {}", uploadComponentInstanceInfo.getName()); - if (nodeTypeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) { - uploadComponentInstanceInfo.setType(nodeTypeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName()); + if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) { + uploadComponentInstanceInfo.setType(nodeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName()); } eitherResource = validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, existingnodeTypeMap); @@ -4339,11 +4349,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.left(eitherGerResource.left().value()); } - private Either validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo, Map nodeTypeNamespaceMap) { + private Either validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo, Map nodeNamespaceMap) { log.debug("validateResourceInstanceBeforeCreate - going to validate resource instance with name {} and type before create", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType()); Resource refResource = null; - if (nodeTypeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) { - refResource = nodeTypeNamespaceMap.get(uploadComponentInstanceInfo.getType()); + if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) { + refResource = nodeNamespaceMap.get(uploadComponentInstanceInfo.getType()); } else { Either findResourceEither = toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(uploadComponentInstanceInfo.getType()); if (findResourceEither.isRight()) { @@ -4352,7 +4362,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(responseFormat); } refResource = findResourceEither.left().value(); - nodeTypeNamespaceMap.put(refResource.getToscaResourceName(), refResource); + nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource); } String componentState = refResource.getComponentMetadataDefinition().getMetadataDataDefinition().getState(); if (componentState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) { @@ -4494,6 +4504,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return response; } + @SuppressWarnings("unchecked") private Either>, ResponseFormat> createPropModuleFromYaml(Map nodeTemplateJsonMap) { Map> moduleProp = new HashMap>(); Either>, ResponseFormat> response = Either.left(moduleProp); @@ -4567,6 +4578,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return response; } + @SuppressWarnings("unchecked") private void createInputPropList(UploadPropInfo propertyDef, List propValueList) { for (Object objValue : propValueList) { @@ -4600,6 +4612,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } + @SuppressWarnings("unchecked") private void createGetInputModuleFromMap(String propName, Map propValue, UploadPropInfo propertyDef) { if (propValue.containsKey(ToscaTagNamesEnum.GET_INPUT.getElementName())) { @@ -4692,6 +4705,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } + @SuppressWarnings("unchecked") private Either>, ResponseFormat> createCapModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map nodeTemplateJsonMap) { Map> moduleCap = new HashMap>(); Either>, ResponseFormat> response = Either.left(moduleCap); @@ -4717,15 +4731,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { list.add(requirementDef); moduleCap.put(capName, list); } - } } - } - return response; } + @SuppressWarnings("unchecked") private Either>, ResponseFormat> createReqModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map nodeTemplateJsonMap) { Map> moduleRequirements = new HashMap>(); Either>, ResponseFormat> response = Either.left(moduleRequirements); @@ -4751,14 +4763,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { list.add(requirementDef); moduleRequirements.put(requirementName, list); } - } } - } return response; } + @SuppressWarnings("unchecked") private Either createModuleNodeTemplateCap(Object capObject) { UploadCapInfo capTemplateInfo = new UploadCapInfo(); Either result = Either.left(capTemplateInfo); @@ -4793,10 +4804,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } } - return result; } + @SuppressWarnings("unchecked") private Either createModuleNodeTemplateReg(Object regObject) { UploadReqInfo regTemplateInfo = new UploadReqInfo(); @@ -4816,7 +4827,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { regTemplateInfo.setCapabilityName((String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.CAPABILITY.getElementName())); } } - return result; } @@ -4879,7 +4889,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { * createOrUpdateResourceByImport(resource, user, isNormative, false, needLock); } */ - public Either, ResponseFormat> createOrUpdateResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction, boolean needLock) { + public Either, ResponseFormat> createOrUpdateResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction, boolean needLock, CsarInfo csarInfo) { // check if resource already exist Either latestByName = toscaOperationFacade.getLatestByName(resource.getName()); @@ -4890,7 +4900,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either latestByToscaName = toscaOperationFacade.getLatestByToscaResourceName(resource.getToscaResourceName()); if (latestByToscaName.isRight() && latestByToscaName.right().value().equals(StorageOperationStatus.NOT_FOUND)) - result = createResourceByImport(resource, user, isNormative, isInTransaction); + result = createResourceByImport(resource, user, isNormative, isInTransaction, csarInfo); else { StorageOperationStatus status = latestByName.right().value(); @@ -4920,9 +4930,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } - private Either, ResponseFormat> createResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction) { + private Either, ResponseFormat> createResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction, CsarInfo csarInfo) { log.debug("resource with name {} does not exist. create new resource", resource.getName()); - Either response = validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isInTransaction); + Either response = validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isInTransaction, csarInfo); if (response.isRight()) { return Either.right(response.right().value()); } @@ -5084,7 +5094,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return result; } - public Either validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum, boolean inTransaction) { + public Either validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum, boolean inTransaction, CsarInfo csarInfo) { Either eitherValidation = validateResourceFieldsBeforeCreate(user, resource, actionEnum, inTransaction); if (eitherValidation.isRight()) { @@ -5107,8 +5117,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resource.setCreatorUserId(user.getUserId()); resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName()); resource.setContactId(resource.getContactId().toLowerCase()); - if (!ToscaUtils.isAtomicType(resource) && resource.getResourceType() != ResourceTypeEnum.CVFC) { - resource.setToscaResourceName(CommonBeUtils.generateToscaResourceName(resource.getResourceType().name(), resource.getSystemName())); + if (StringUtils.isEmpty(resource.getToscaResourceName()) && !ToscaUtils.isAtomicType(resource)) { + String resourceSystemName; + if(csarInfo != null && StringUtils.isNotEmpty(csarInfo.getVfResourceName())){ + resourceSystemName = ValidationUtils.convertToSystemName(csarInfo.getVfResourceName()); + } else { + resourceSystemName = resource.getSystemName(); + } + resource.setToscaResourceName(CommonBeUtils.generateToscaResourceName(resource.getResourceType().name().toLowerCase(), resourceSystemName)); } // Generate invariant UUID - must be here and not in operation since it @@ -5187,7 +5203,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } // @param typeObject- the object to which the validation is done - private Either validateCapabilityTypeExists(User user, ICapabilityTypeOperation capabilityTypeOperation, Resource resource, List validationObjects, AuditingActionEnum actionEnum, Either eitherResult, String type, + private Either validateCapabilityTypeExists(User user, ICapabilityTypeOperation capabilityTypeOperation, Resource resource, List validationObjects, AuditingActionEnum actionEnum, Either eitherResult, String type, boolean inTransaction) { Either eitherCapTypeFound = capabilityTypeOperation.getCapabilityType(type, inTransaction); if (eitherCapTypeFound.isRight()) { @@ -5721,7 +5737,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { .orElse(null).getMetadataDataDefinition() ) .orElse(null).getName(); if ( with != null && replacePattern != null ){ - Either result = updateComponentGroupName( replacePattern , with ,currentResource.getGroups()); + Either,Boolean> result = updateComponentGroupName( replacePattern , with ,currentResource.getGroups()); if (result.isLeft()) newResource.setGroups( (List)result.left().value() ); } @@ -6221,7 +6237,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either dataModelResponse = toscaOperationFacade.validateToscaResourceNameExists(templateName); if (dataModelResponse.isRight()) { StorageOperationStatus storageStatus = dataModelResponse.right().value(); - BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Create Resource - validateDerivedFromExist"); BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateDerivedFromExist"); log.debug("request to data model failed with error: {}", storageStatus.name()); ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus), resource); @@ -6782,6 +6797,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return result; } + @SuppressWarnings("unchecked") private Either createGroupInfo(String groupName, Object groupTemplateJson) { GroupDefinition groupInfo = new GroupDefinition(); @@ -6845,6 +6861,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return result; } + @SuppressWarnings("unchecked") private Either, ResponseFormat> createPropertiesValueModuleFromYaml(Object properties, String groupName, String groupType) { List result = new ArrayList<>(); @@ -7048,37 +7065,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return nodeTypeArtifactsToHandleRes; } - private String buildNestedVfcToscaNamespace(String nodeTypeFullName) { - - String actualName = this.getNodeTypeActualName(nodeTypeFullName); - return ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + ResourceTypeEnum.VFC.name().toLowerCase() + actualName; - } - - private String buildNestedVfcToscaResourceName(String vfResourceName, String nodeTypeFullName) { - String toscaResourceName; - String nameWithouNamespacePrefix = getNodeTypeActualName(nodeTypeFullName); - if (nameWithouNamespacePrefix.startsWith(Constants.ABSTRACT)) { - toscaResourceName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + ResourceTypeEnum.VFC.name().toLowerCase() + '.' + vfResourceName + '.' + nameWithouNamespacePrefix; - } else { - toscaResourceName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + ResourceTypeEnum.VFC.name().toLowerCase() + '.' + vfResourceName + '.' + Constants.ABSTRACT + nameWithouNamespacePrefix; - } - return toscaResourceName; - } - - private String buildNodeToscaResourceName(String vfResourceName, String nodeTypeFullName) { - String toscaResourceName; + private String buildNestedToscaResourceName(String nodeResourceType, String vfResourceName, String nodeTypeFullName) { + StringBuilder toscaResourceName = new StringBuilder(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX); String nameWithouNamespacePrefix = nodeTypeFullName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length()); String[] findTypes = nameWithouNamespacePrefix.split("\\."); String resourceType = findTypes[0]; String actualName = nameWithouNamespacePrefix.substring(resourceType.length()); if (actualName.startsWith(Constants.ABSTRACT)) { - toscaResourceName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + ResourceTypeEnum.VFC.name().toLowerCase() + '.' + vfResourceName + '.' + actualName; + toscaResourceName.append(resourceType.toLowerCase()).append('.').append(ValidationUtils.convertToSystemName(vfResourceName)); } else { - toscaResourceName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + resourceType.toLowerCase() + '.' + vfResourceName + '.' + Constants.ABSTRACT + actualName; + toscaResourceName.append(nodeResourceType.toLowerCase()).append('.').append(ValidationUtils.convertToSystemName(vfResourceName)).append('.').append(Constants.ABSTRACT); } - return toscaResourceName; + return toscaResourceName.append(actualName.toLowerCase()).toString(); } public ICacheMangerOperation getCacheManagerOperation() { @@ -7090,7 +7090,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } ///////////////////////////////////////// DataModel refactoring///////////////////////////////////////////// - + @Override public Either getUiComponentDataTransferByComponentId(String resourceId, List dataParamsToReturn) { ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index d2743aa039..ac6183db00 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -36,6 +36,7 @@ import java.util.stream.Collectors; import javax.servlet.ServletContext; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.auditing.api.IAuditingManager; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; @@ -55,6 +56,7 @@ import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.CsarInfo; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.PropertyDefinition; @@ -124,7 +126,7 @@ public class ResourceImportManager { lifecycleChangeInfo.setUserRemarks("certification on import"); Function> validator = (resource) -> resourceBusinessLogic.validatePropertiesDefaultValues(resource); - return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false); + return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false, null); } public Either, ResponseFormat> importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) { @@ -133,11 +135,11 @@ public class ResourceImportManager { lifecycleChangeInfo.setUserRemarks("certification on import"); Function> validator = (resource) -> resourceBusinessLogic.validatePropertiesDefaultValues(resource); - return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false); + return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false, null); } public Either, ResponseFormat> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, Function> validationFunction, - LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map> nodeTypeArtifactsToHandle, List nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed) { + LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map> nodeTypeArtifactsToHandle, List nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo) { Resource resource = new Resource(); ImmutablePair responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED); Either, ResponseFormat> response = Either.left(responsePair); @@ -166,14 +168,14 @@ public class ResourceImportManager { } } - response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock); + response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo); Either changeStateResponse; if (response.isLeft()) { resource = response.left().value().left; if(nodeTypeArtifactsToHandle !=null && !nodeTypeArtifactsToHandle.isEmpty()){ Either, ResponseFormat> handleNodeTypeArtifactsRes = - resourceBusinessLogic.handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, creator, isInTransaction); + resourceBusinessLogic.handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, creator, isInTransaction, false); if(handleNodeTypeArtifactsRes.isRight()){ return Either.right(handleNodeTypeArtifactsRes.right().value()); } @@ -254,7 +256,7 @@ public class ResourceImportManager { Either validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource); if (validatePropertiesTypes.isLeft()) { - response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true); + response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true, null); } else { ResponseFormat validationErrorResponse = validatePropertiesTypes.right().value(); auditErrorImport(resourceMetaData, creator, validationErrorResponse, false); @@ -287,7 +289,8 @@ public class ResourceImportManager { return Either.right(setDerivedFrom.right().value()); } Resource parentResource = setDerivedFrom.left().value(); - setToscaResourceName(toscaJson, resource); + if(StringUtils.isEmpty(resource.getToscaResourceName())) + setToscaResourceName(toscaJson, resource); setAttributes(toscaJson, resource); eitherResult = setCapabilities(toscaJson, resource, parentResource); if (eitherResult.isRight()) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java index 4fe0965ef6..dfe04f919d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java @@ -484,7 +484,7 @@ public class LifecycleBusinessLogic { } try{ if(result == null){ - certifyResourceRes = lifecycleOperation.forceCerificationOfToscaElement(resource.getUniqueId(), user.getUserId(), user.getUserId()); + certifyResourceRes = lifecycleOperation.forceCerificationOfToscaElement(resource.getUniqueId(), user.getUserId(), user.getUserId(), resource.getVersion()); if (certifyResourceRes.isRight()) { StorageOperationStatus status = certifyResourceRes.right().value(); log.debug("Failed to perform a force certification of resource {}. The status is {}. ", resource.getName(), status); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java index 6b16e71e82..55ad44db0c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java @@ -102,7 +102,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { } - private synchronized void initLog(Logger log) { + protected synchronized void initLog(Logger log) { if (this.log == null) { this.log = log; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java index 5eed7eeb0d..98e966e6eb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java @@ -44,6 +44,42 @@ public class RepresentationUtils { private static Logger log = LoggerFactory.getLogger(RepresentationUtils.class.getName()); + public static ArtifactDefinition convertJsonToArtifactDefinitionForUpdate(String content, Class clazz) { + + JsonObject jsonElement = new JsonObject(); + ArtifactDefinition resourceInfo = null; + + try { + Gson gson = new Gson(); + jsonElement = gson.fromJson(content, jsonElement.getClass()); + String payload = null; + jsonElement.remove(Constants.ARTIFACT_GROUP_TYPE_FIELD); + //in update the group type is ignored but this spagheti code makes it too complex to remove this field. + jsonElement.addProperty(Constants.ARTIFACT_GROUP_TYPE_FIELD, ArtifactGroupTypeEnum.INFORMATIONAL.getType()); + JsonElement artifactPayload = jsonElement.get(Constants.ARTIFACT_PAYLOAD_DATA); + if (artifactPayload != null && !artifactPayload.isJsonNull()) { + payload = artifactPayload.getAsString(); + } + jsonElement.remove(Constants.ARTIFACT_PAYLOAD_DATA); + String json = gson.toJson(jsonElement); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.configure(Feature.FAIL_ON_EMPTY_BEANS, false); + mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); + + resourceInfo = mapper.readValue(json, clazz); + resourceInfo.setPayloadData(payload); + + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeArtifactInformationInvalidError, "Artifact Upload / Update"); + BeEcompErrorManager.getInstance().logBeArtifactInformationInvalidError("Artifact Upload / Update"); + log.debug("Failed to convert the content {} to object.", content.substring(0, Math.min(50, content.length())), e); + } + + return resourceInfo; + } + + public static class ResourceRep { } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 9fdd2d3b0f..f802d0f412 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -94,7 +94,7 @@ public class ToscaExportHandler { private static Logger log = LoggerFactory.getLogger(ToscaExportHandler.class.getName()); - public static final String TOSCA_VERSION = "tosca_simple_yaml_1_0"; + public static final String TOSCA_VERSION = "tosca_simple_yaml_1_1"; public static final String SERVICE_NODE_TYPE_PREFIX = "org.openecomp.service."; public static final String IMPORTS_FILE_KEY = "file"; public static final String TOSCA_TEMPLATE_NAME = "-template.yml"; diff --git a/catalog-be/src/main/resources/config/configuration.yaml b/catalog-be/src/main/resources/config/configuration.yaml index bbb1969255..5242652188 100644 --- a/catalog-be/src/main/resources/config/configuration.yaml +++ b/catalog-be/src/main/resources/config/configuration.yaml @@ -306,6 +306,10 @@ serviceDeploymentArtifacts: MODEL_QUERY_SPEC: acceptedTypes: - xml + UCPE_LAYER_2_CONFIGURATION: + acceptedTypes: + - xml + #AAI Artifacts AAI_SERVICE_MODEL: acceptedTypes: diff --git a/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json b/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json new file mode 100644 index 0000000000..1ef72856a4 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json @@ -0,0 +1,7 @@ +{ + "heat": [ + "Generic_PNF" + ], + "normative": [ + ] +} \ No newline at end of file diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py new file mode 100644 index 0000000000..75afe33eba --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py @@ -0,0 +1,110 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importCommon import * +from importNormativeTypes import * +import importCommon +import json + + +################################################################################################################################################ +# # +# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file # +# # +# activation : # +# python upgradeHeatAndNormativeTypes.py [-i | --ip=] [-p | --port= ] [-f | --ifile= ] # +# # +# shortest activation (be host = localhost, be port = 8080): # +# python upgradeHeatAndNormativeTypes.py [-f | --ifile= ] # +# # +################################################################################################################################################ +def upgradeTypesPerConfigFile(beHost, bePort, adminUser, baseDir, updateversion): + responseCodes = [200, 201] + if (updateversion == 'false'): + responseCodes = [200, 201, 409] + with open("typesToUpgrade.json", 'r') as stream: + try: + types = json.load(stream) + heatTypes = types["heat"] + debug(heatTypes) + normativeTypes = types["normative"] + debug(normativeTypes) + heatFileDir = baseDir + "heat-types/" + debug(heatFileDir) + normativeFileDir = baseDir + "normative-types/" + debug(normativeFileDir) + results = [] + for heatType in heatTypes: + result = createNormativeType(beHost, bePort, adminUser, heatFileDir, heatType.encode('ascii', 'ignore'), updateversion) + results.append(result) + if (result[1] == None or result[1] not in responseCodes): + print "Failed creating heat type " + heatType + ". " + str(result[1]) + for normativeType in normativeTypes: + result = createNormativeType(beHost, bePort, adminUser, normativeFileDir, normativeType.encode('ascii', 'ignore'), updateversion) + results.append(result) + if (result[1] == None or result[1] not in responseCodes): + print "Failed creating normative type " + normativeType + ". " + str(result[1]) + return results + except yaml.YAMLError as exc: + print(exc) + + + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + updateversion = 'true' + + try: + opts, args = getopt.getopt(argv, "i:p:u:v:h:", ["ip=", "port=", "user=", "updateversion="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + # print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-v", "--updateversion"): + if (arg.lower() == "false" or arg.lower() == "no"): + updateversion = 'false' + + print 'be host =', beHost, ', be port =', bePort, ', user =', adminUser + + if (beHost == None): + usage() + sys.exit(3) + + results = upgradeTypesPerConfigFile(beHost, bePort, adminUser, "../../../import/tosca/", updateversion) + + print "-----------------------------" + for result in results: + print "{0:20} | {1:6}".format(result[0], result[1]) + print "-----------------------------" + + responseCodes = [200, 201] + + if (updateversion == 'false'): + responseCodes = [200, 201, 409] + + failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results) + if (len(failedNormatives) > 0): + errorAndExit(1, None) + else: + errorAndExit(0, None) + + +if __name__ == "__main__": + main(sys.argv[1:]) \ No newline at end of file diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py index 488d4d739d..085467e09a 100644 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py +++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py @@ -5,23 +5,28 @@ import json import copy import time from importCategoryTypes import importCategories -from upgradeHeatTypes1707 import upgradeHeatTypes1707 +from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile from importDataTypes import importDataTypes +from importPolicyTypes import importPolicyTypes +from importGroupTypes import importGroupTypes +from importNormativeCapabilities import importNormativeCapabilities +from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType + from importCommon import * import importCommon ################################################################################################################################################################################################# -# # +# # # Upgrades the normative types # -# # +# # # activation : # # python upgradeNormative.py [-i | --ip=] [-p | --port= ] [-u | --user= ] [-d | --debug=] # # # -# # +# # # shortest activation (be host = localhost, be port = 8080, user = jh0003): # # # # python upgradeNormative.py # -# # +# # ################################################################################################################################################################################################# def usage(): @@ -32,7 +37,7 @@ def handleResults(results, updateversion): for result in results: printNameAndReturnCode(result[0], result[1]) printFrameLine() - + failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results) if (len(failedResults) > 0): errorAndExit(1, None) @@ -40,23 +45,23 @@ def handleResults(results, updateversion): def main(argv): print 'Number of arguments:', len(sys.argv), 'arguments.' - beHost = 'localhost' + beHost = 'localhost' bePort = '8080' adminUser = 'jh0003' debugf = None updateversion = 'true' - importCommon.debugFlag = False + importCommon.debugFlag = False try: opts, args = getopt.getopt(argv,"i:p:u:d:h",["ip=","port=","user=","debug="]) except getopt.GetoptError: usage() errorAndExit(2, 'Invalid input') - + for opt, arg in opts: #print opt, arg if opt == '-h': - usage() + usage() sys.exit(3) elif opt in ("-i", "--ip"): beHost = arg @@ -73,13 +78,13 @@ def main(argv): if (debugf != None): print 'set debug mode to ' + str(debugf) importCommon.debugFlag = debugf - + if ( beHost == None ): usage() sys.exit(3) print sys.argv[0] - pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) + pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) debug("path dir =" + pathdir) baseFileLocation = pathdir + "/../../../import/tosca/" @@ -90,15 +95,25 @@ def main(argv): fileLocation = baseFileLocation + "data-types/" importDataTypes(beHost, bePort, adminUser, False, fileLocation) + fileLocation = baseFileLocation + "policy-types/" + importPolicyTypes(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "group-types/" + importGroupTypes(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "capability-types/" + importNormativeCapabilities(beHost, bePort, adminUser, False, fileLocation) + + fileLocation = baseFileLocation + "interface-lifecycle-types/" + importNormativeInterfaceLifecycleType(beHost, bePort, adminUser, False, fileLocation) + print 'sleep until data type cache is updated' time.sleep( 70 ) - fileLocation = baseFileLocation + "heat-types/" - resultsHeat = upgradeHeatTypes1707(beHost, bePort, adminUser, fileLocation, updateversion) + resultsHeat = upgradeTypesPerConfigFile(beHost, bePort, adminUser, baseFileLocation, updateversion) handleResults(resultsHeat, 'false') - errorAndExit(0, None) + errorAndExit(0, None) if __name__ == "__main__": main(sys.argv[1:]) - diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java index f0b2865373..a453df2563 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java @@ -157,7 +157,7 @@ public class ResourceImportManagerTest { // Mockito.verify(log).error(Mockito.anyString(), Mockito.anyString(), // Mockito.anyString()); - Mockito.verify(resourceBusinessLogic, Mockito.times(0)).createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.eq(user), Mockito.eq(true), Mockito.eq(false), Mockito.eq(true)); + Mockito.verify(resourceBusinessLogic, Mockito.times(0)).createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.eq(user), Mockito.eq(true), Mockito.eq(false), Mockito.eq(true), Mockito.eq(null)); Mockito.verify(resourceBusinessLogic, Mockito.times(0)).propagateStateToCertified(Mockito.eq(user), Mockito.any(Resource.class), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true), Mockito.eq(false)); @@ -182,7 +182,7 @@ public class ResourceImportManagerTest { testSetCapabilities(resource); Mockito.verify(resourceBusinessLogic, Mockito.times(1)).propagateStateToCertified(Mockito.eq(user), Mockito.eq(resource), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true), Mockito.eq(false)); - Mockito.verify(resourceBusinessLogic, Mockito.times(1)).createOrUpdateResourceByImport(resource, user, true, false, true); + Mockito.verify(resourceBusinessLogic, Mockito.times(1)).createOrUpdateResourceByImport(resource, user, true, false, true, null); } @@ -207,7 +207,7 @@ public class ResourceImportManagerTest { private void setResourceBusinessLogicMock() { when(resourceBusinessLogic.getUserAdmin()).thenReturn(userAdmin); - when(resourceBusinessLogic.createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean())) + when(resourceBusinessLogic.createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.eq(null))) .thenAnswer(new Answer, ResponseFormat>>() { public Either, ResponseFormat> answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); @@ -230,7 +230,7 @@ public class ResourceImportManagerTest { } }); - when(resourceBusinessLogic.validateResourceBeforeCreate(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(AuditingActionEnum.class), Mockito.eq(false))).thenAnswer(new Answer>() { + when(resourceBusinessLogic.validateResourceBeforeCreate(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(AuditingActionEnum.class), Mockito.eq(false), Mockito.eq(null))).thenAnswer(new Answer>() { public Either answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return Either.left((Resource) args[0]); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index bbfa8bf236..f3c7a7d24c 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -1328,7 +1328,7 @@ public class ResourceBusinessLogicTest { Resource resourceToUpdtae = createResourceObject(false); - Either, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false); + Either, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null); assertTrue(createOrUpdateResource.isLeft()); Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(Mockito.any(Resource.class), Mockito.any(Resource.class)); @@ -1356,7 +1356,7 @@ public class ResourceBusinessLogicTest { Resource resourceToUpdtae = createResourceObject(false); - Either, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false); + Either, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null); assertTrue(createOrUpdateResource.isLeft()); Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class)); @@ -1374,7 +1374,7 @@ public class ResourceBusinessLogicTest { Either getLatestToscaNameResult = Either.right(StorageOperationStatus.NOT_FOUND); when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdtae.getToscaResourceName())).thenReturn(getLatestToscaNameResult); - Either, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false); + Either, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null); assertTrue(createOrUpdateResource.isLeft()); Mockito.verify(toscaOperationFacade, Mockito.times(0)).overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class)); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java index d41e95da9d..2b33fbd704 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java @@ -20,6 +20,17 @@ package org.openecomp.sdc.be.servlets; +import fj.data.Either; +import org.apache.commons.codec.binary.Base64; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sdc.be.model.UploadResourceInfo; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.common.datastructure.Wrapper; +import org.openecomp.sdc.exception.ResponseFormat; +import org.slf4j.Logger; + +import javax.ws.rs.core.Response; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -27,19 +38,20 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Map; -import org.apache.commons.codec.binary.Base64; -import org.junit.Assert; -import org.junit.Test; -import org.openecomp.sdc.be.model.UploadResourceInfo; -import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; -import org.openecomp.sdc.exception.ResponseFormat; - -import fj.data.Either; +import java.util.stream.Stream; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; public class AbstractValidationsServletTest { - private static AbstractValidationsServlet servlet = mock(AbstractValidationsServlet.class); + private static AbstractValidationsServlet servlet = new AbstractValidationsServlet() {}; + + private static final String BASIC_TOSCA_TEMPLATE = "tosca_definitions_version: tosca_simple_yaml_%s"; + + @Before + public void setUp() throws Exception { + servlet.initLog(mock(Logger.class)); + } @SuppressWarnings("unchecked") @Test @@ -65,8 +77,23 @@ public class AbstractValidationsServletTest { } catch (IOException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); } - Assert.assertTrue(returnValue.isLeft()); + assertTrue(returnValue.isLeft()); Map csar = returnValue.left().value(); - Assert.assertTrue(csar != null); + assertTrue(csar != null); + } + + @Test + public void testValidToscaVersion() throws Exception { + Stream.of("1_0", "1_0_0", "1_1", "1_1_0").forEach(this::testValidToscaVersion); } + + + private void testValidToscaVersion(String version) { + Wrapper responseWrapper = new Wrapper<>(); + servlet.validatePayloadIsTosca(responseWrapper, new UploadResourceInfo(), new User(), String.format(BASIC_TOSCA_TEMPLATE, version)); + assertTrue(responseWrapper.isEmpty()); + } + + + } diff --git a/catalog-be/src/test/resources/config/catalog-be/configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/configuration.yaml index 6a94f7268a..8be1322c2c 100644 --- a/catalog-be/src/test/resources/config/catalog-be/configuration.yaml +++ b/catalog-be/src/test/resources/config/catalog-be/configuration.yaml @@ -296,6 +296,9 @@ serviceDeploymentArtifacts: YANG_XML: acceptedTypes: - xml + UCPE_LAYER_2_CONFIGURATION: + acceptedTypes: + - xml VNF_CATALOG: acceptedTypes: - xml diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactAccessor.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactAccessor.java new file mode 100644 index 0000000000..61e23b8de2 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactAccessor.java @@ -0,0 +1,19 @@ +package org.openecomp.sdc.be.dao.cassandra; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Param; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent; + + +/** + * Created by chaya on 7/5/2017. + */ +@Accessor +public interface ArtifactAccessor { + // ***** get the number of artifacts with a specific id + @Query("SELECT COUNT(*) FROM sdcartifact.resources WHERE ID = :uniqueId") + ResultSet getNumOfArtifactsById(@Param("uniqueId") String uniqueId); +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java index a9a4a99de1..5b37d3df2c 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.be.dao.cassandra; import javax.annotation.PostConstruct; +import com.datastax.driver.core.ResultSet; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.resources.data.ESArtifactData; import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; @@ -38,6 +39,7 @@ import fj.data.Either; public class ArtifactCassandraDao extends CassandraDao { private static Logger logger = LoggerFactory.getLogger(ArtifactCassandraDao.class.getName()); + private ArtifactAccessor artifactAccessor; public ArtifactCassandraDao() { super(); @@ -52,6 +54,7 @@ public class ArtifactCassandraDao extends CassandraDao { if (result.isLeft()) { session = result.left().value().left; manager = result.left().value().right; + artifactAccessor = manager.createAccessor(ArtifactAccessor.class); logger.info("** ArtifactCassandraDao created"); } else { logger.info("** ArtifactCassandraDao failed"); @@ -107,4 +110,12 @@ public class ArtifactCassandraDao extends CassandraDao { return super.isTableEmpty(tableName); } + public Either getCountOfArtifactById(String uniqeId) { + ResultSet artifactCount = artifactAccessor.getNumOfArtifactsById(uniqeId); + if (artifactCount == null) { + return Either.right(CassandraOperationStatus.NOT_FOUND); + } + return Either.left(artifactCount.one().getLong(0)); + } + } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/CsarInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/CsarInfo.java new file mode 100644 index 0000000000..575cc68f7f --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/CsarInfo.java @@ -0,0 +1,89 @@ +package org.openecomp.sdc.be.model; + +import java.util.HashMap; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Queue; + +public class CsarInfo { + String vfResourceName; + User modifier; + String csarUUID; + Map csar; + Map createdNodesToscaResourceNames; + Queue cvfcToCreateQueue; + boolean isUpdate; + Map createdNodes; + + public CsarInfo(String vfResourceName, User modifier, String csarUUID, Map csar, boolean isUpdate){ + this.vfResourceName = vfResourceName; + this.modifier = modifier; + this.csarUUID = csarUUID; + this.csar = csar; + this.createdNodesToscaResourceNames = new HashMap<>(); + this.cvfcToCreateQueue = new PriorityQueue<>(); + this.isUpdate = isUpdate; + this.createdNodes = new HashMap<>(); + } + + public String getVfResourceName() { + return vfResourceName; + } + + public void setVfResourceName(String vfResourceName) { + this.vfResourceName = vfResourceName; + } + + public User getModifier() { + return modifier; + } + + public void setModifier(User modifier) { + this.modifier = modifier; + } + + public String getCsarUUID() { + return csarUUID; + } + + public void setCsarUUID(String csarUUID) { + this.csarUUID = csarUUID; + } + + public Map getCsar() { + return csar; + } + + public void setCsar(Map csar) { + this.csar = csar; + } + + public Map getCreatedNodesToscaResourceNames() { + return createdNodesToscaResourceNames; + } + + public void setCreatedNodesToscaResourceNames(Map createdNodesToscaResourceNames) { + this.createdNodesToscaResourceNames = createdNodesToscaResourceNames; + } + + public Queue getCvfcToCreateQueue() { + return cvfcToCreateQueue; + } + + public void setCvfcToCreateQueue(Queue cvfcToCreateQueue) { + this.cvfcToCreateQueue = cvfcToCreateQueue; + } + + public boolean isUpdate() { + return isUpdate; + } + + public void setUpdate(boolean isUpdate) { + this.isUpdate = isUpdate; + } + + public Map getCreatedNodes() { + return createdNodes; + } + +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ImportCsarInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ImportCsarInfo.java deleted file mode 100644 index 460a107c89..0000000000 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ImportCsarInfo.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.openecomp.sdc.be.model; - -import java.util.HashMap; -import java.util.Map; -import java.util.PriorityQueue; -import java.util.Queue; - -public class ImportCsarInfo { - String vfResourceName; - User modifier; - String csarUUID; - Map csar; - Map createdNodesToscaResourceNames; - Queue cvfcToCreateQueue; - - public ImportCsarInfo(String vfResourceName, User modifier, String csarUUID, Map csar){ - this.vfResourceName = vfResourceName; - this.modifier = modifier; - this.csarUUID = csarUUID; - this.csar = csar; - this.createdNodesToscaResourceNames = new HashMap<>(); - this.cvfcToCreateQueue = new PriorityQueue<>(); - } - - public String getVfResourceName() { - return vfResourceName; - } - - public void setVfResourceName(String vfResourceName) { - this.vfResourceName = vfResourceName; - } - - public User getModifier() { - return modifier; - } - - public void setModifier(User modifier) { - this.modifier = modifier; - } - - public String getCsarUUID() { - return csarUUID; - } - - public void setCsarUUID(String csarUUID) { - this.csarUUID = csarUUID; - } - - public Map getCsar() { - return csar; - } - - public void setCsar(Map csar) { - this.csar = csar; - } - - public Map getCreatedNodesToscaResourceNames() { - return createdNodesToscaResourceNames; - } - - public void setCreatedNodesToscaResourceNames(Map createdNodesToscaResourceNames) { - this.createdNodesToscaResourceNames = createdNodesToscaResourceNames; - } - - public Queue getCvfcToCreateQueue() { - return cvfcToCreateQueue; - } - - public void setCvfcToCreateQueue(Queue cvfcToCreateQueue) { - this.cvfcToCreateQueue = cvfcToCreateQueue; - } - -} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java index 4282a2cba8..d34d3aa9f9 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java @@ -882,8 +882,9 @@ public class ToscaElementLifecycleOperation extends BaseOperation { // check if component with the next version doesn't exist. Iterator nextVersionComponentIter = toscaElementVertex.getVertex().edges(Direction.OUT, EdgeLabelEnum.VERSION.name()); if (nextVersionComponentIter != null && nextVersionComponentIter.hasNext()) { - String fetchedVersion = (String) nextVersionComponentIter.next().inVertex().property(GraphPropertyEnum.VERSION.getProperty()).value(); - String fetchedName = (String) nextVersionComponentIter.next().inVertex().property(GraphPropertyEnum.NORMALIZED_NAME.getProperty()).value(); + Vertex nextVersionVertex = nextVersionComponentIter.next().inVertex(); + String fetchedVersion = (String) nextVersionVertex.property(GraphPropertyEnum.VERSION.getProperty()).value(); + String fetchedName = (String)nextVersionVertex.property(GraphPropertyEnum.NORMALIZED_NAME.getProperty()).value(); CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to checkout component {} with version {}. The component with name {} and version {} was fetched from graph as existing following version. ", toscaElementVertex.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME).toString(), toscaElementVertex.getMetadataProperty(GraphPropertyEnum.VERSION).toString(), fetchedName, fetchedVersion); result = Either.right(StorageOperationStatus.ENTITY_ALREADY_EXISTS); @@ -1429,6 +1430,13 @@ public class ToscaElementLifecycleOperation extends BaseOperation { return verticesToGetParameters; } + + private String getNextCertifiedVersion(String version) { + String[] versionParts = version.split(VERSION_DELIMETER_REGEXP); + Integer nextMajorVersion = Integer.parseInt(versionParts[0]) + 1; + return nextMajorVersion + VERSION_DELIMETER + "0"; + } + private String getNextVersion(String currVersion) { String[] versionParts = currVersion.split(VERSION_DELIMETER_REGEXP); Integer minorVersion = Integer.parseInt(versionParts[1]) + 1; @@ -1452,7 +1460,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation { return false; } - public Either forceCerificationOfToscaElement(String toscaElementId, String modifierId, String ownerId) { + public Either forceCerificationOfToscaElement(String toscaElementId, String modifierId, String ownerId, String currVersion) { Either resultUpdate = null; Either result = null; GraphVertex toscaElement = null; @@ -1478,7 +1486,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation { LifecycleStateEnum nextState = LifecycleStateEnum.CERTIFIED; toscaElement.addMetadataProperty(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); - toscaElement.addMetadataProperty(GraphPropertyEnum.VERSION, "1.0"); + toscaElement.addMetadataProperty(GraphPropertyEnum.VERSION, getNextCertifiedVersion(currVersion)); resultUpdate = updateToscaElementVertexMetadataPropertiesAndJson(toscaElement); if (resultUpdate.isRight()) { diff --git a/catalog-ui/src/app/app.ts b/catalog-ui/src/app/app.ts index 707d7e456e..805e5f0b5d 100644 --- a/catalog-ui/src/app/app.ts +++ b/catalog-ui/src/app/app.ts @@ -53,6 +53,7 @@ import {downgradeComponent} from "@angular/upgrade/static"; import {AppModule} from './ng2/app.module'; import {PropertiesAssignmentComponent} from "./ng2/pages/properties-assignment/properties-assignment.page.component"; +import { SearchWithAutoCompleteComponent } from "./ng2/shared/search-with-autocomplete/search-with-autocomplete.component"; import {Component} from "./models/components/component"; import {ComponentServiceNg2} from "./ng2/services/component-services/component.service"; import {ComponentMetadata} from "./models/component-metadata"; @@ -145,6 +146,13 @@ _.each(hostedApplications, (hostedApp)=> { export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules); angular.module('sdcApp').directive('propertiesAssignment', downgradeComponent({component: PropertiesAssignmentComponent}) as angular.IDirectiveFactory); +angular.module('sdcApp').directive('ng2SearchWithAutocomplete', + downgradeComponent({ + component: SearchWithAutoCompleteComponent, + inputs: ['searchPlaceholder', 'searchBarClass', 'autoCompleteValues'], + outputs: ['searchChanged', 'searchButtonClicked'] + }) as angular.IDirectiveFactory); + ng1appModule.config([ '$stateProvider', @@ -161,7 +169,7 @@ ng1appModule.config([ NotificationProvider:any):void => { NotificationProvider.setOptions({ - delay: 10000, + delay: 5000, startTop: 10, startRight: 10, closeOnClick: true, @@ -170,6 +178,7 @@ ng1appModule.config([ positionX: 'right', positionY: 'top' }); + NotificationProvider.options.templateUrl = 'notification-custom-template.html'; $translateProvider.useStaticFilesLoader({ prefix: pathPrefix + 'assets/languages/', @@ -617,6 +626,7 @@ ng1appModule.run([ 'LeftPaletteLoaderService', 'Sdc.Services.DataTypesService', 'AngularJSBridge', + '$templateCache', ($http:ng.IHttpService, cacheService:CacheService, cookieService:CookieService, @@ -632,8 +642,9 @@ ng1appModule.run([ ecompHeaderService:EcompHeaderService, LeftPaletteLoaderService:LeftPaletteLoaderService, DataTypesService:DataTypesService, - AngularJSBridge):void => { - + AngularJSBridge, + $templateCache:ng.ITemplateCacheService):void => { + $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html')); //handle cache data - version let initAsdcVersion:Function = ():void => { diff --git a/catalog-ui/src/app/directives/graphs-v2/common/style/component-instances-nodes-style.ts b/catalog-ui/src/app/directives/graphs-v2/common/style/component-instances-nodes-style.ts index 0dcc93dfa7..64197594e2 100644 --- a/catalog-ui/src/app/directives/graphs-v2/common/style/component-instances-nodes-style.ts +++ b/catalog-ui/src/app/directives/graphs-v2/common/style/component-instances-nodes-style.ts @@ -231,7 +231,7 @@ export class ComponentInstanceNodesStyle { public static getBasicNodeHanlde = () => { return { - positionX: "center", + positionX: "right", positionY: "top", offsetX: 15, offsetY: -20, @@ -248,7 +248,7 @@ export class ComponentInstanceNodesStyle { public static getBasicSmallNodeHandle = () => { return { - positionX: "center", + positionX: "right", positionY: "top", offsetX: 3, offsetY: -25, diff --git a/catalog-ui/src/app/directives/graphs-v2/composition-graph/composition-graph.directive.ts b/catalog-ui/src/app/directives/graphs-v2/composition-graph/composition-graph.directive.ts index 651a4281fa..9aa7941272 100644 --- a/catalog-ui/src/app/directives/graphs-v2/composition-graph/composition-graph.directive.ts +++ b/catalog-ui/src/app/directives/graphs-v2/composition-graph/composition-graph.directive.ts @@ -47,7 +47,8 @@ interface ICompositionGraphScope extends ng.IScope { component:Component; isLoading: boolean; - isViewOnly:boolean; + isViewOnly: boolean; + withSidebar: boolean; // Link menu - create link menu relationMenuDirectiveObj:RelationMenuDirectiveObj; isLinkMenuOpen:boolean; @@ -65,6 +66,14 @@ interface ICompositionGraphScope extends ng.IScope { //Links menus deleteRelation(link:Cy.CollectionEdges):void; hideRelationMenu(); + + //search,zoom in/out/all + componentInstanceNames: Array; //id, name + zoom(zoomIn: boolean): void; + zoomAll(nodes?:Cy.CollectionNodes): void; + getAutoCompleteValues(searchTerm: string):void; + highlightSearchMatches(searchTerm: string): void; + /*//asset popover menu assetPopoverObj:AssetPopoverObj; assetPopoverOpen:boolean; @@ -101,7 +110,8 @@ export class CompositionGraph implements ng.IDirective { template = require('./composition-graph.html'); scope = { component: '=', - isViewOnly: '=' + isViewOnly: '=', + withSidebar: '=' }; link = (scope:ICompositionGraphScope, el:JQuery) => { @@ -147,7 +157,11 @@ export class CompositionGraph implements ng.IDirective { this._cy = cytoscape({ container: graphEl, style: ComponentInstanceNodesStyle.getCompositionGraphStyle(), - zoomingEnabled: false, + zoomingEnabled: true, + maxZoom: 2.5, + minZoom: .1, + userZoomingEnabled: false, + userPanningEnabled: true, selectionType: 'single', boxSelectionEnabled: true, autolock: isViewOnly, @@ -270,6 +284,40 @@ export class CompositionGraph implements ng.IDirective { this.loadGraphData(scope); }); + scope.zoom = (zoomIn: boolean):void => { + let currentZoom: number = this._cy.zoom(); + if (zoomIn) { + this.GeneralGraphUtils.zoomGraphTo(this._cy, currentZoom + .1); + } else { + this.GeneralGraphUtils.zoomGraphTo(this._cy, currentZoom - .1); + } + } + + //Zooms to fit all of the nodes in the collection passed in. If no nodes are passed in, will zoom to fit all nodes on graph + scope.zoomAll = (nodes?:Cy.CollectionNodes) => { + scope.withSidebar = false; + this._cy.animate({ + fit: { eles: nodes, padding: 20 }, + center: { eles: nodes } + }, { duration: 400 }); + }; + + scope.getAutoCompleteValues = (searchTerm: string) => { + if (searchTerm.length > 1) { //US requirement: only display search results after 2nd letter typed. + let nodes: Cy.CollectionNodes = this.NodesGraphUtils.getMatchingNodesByName(this._cy, searchTerm); + scope.componentInstanceNames = _.map(nodes, node => node.data('name')); + } else { + scope.componentInstanceNames = []; + } + }; + + scope.highlightSearchMatches = (searchTerm: string) => { + if (searchTerm === undefined) return; //dont zoom & highlight if click on Search initially (searchTerm will be undefined). However, allow highlights to be cleared after subsequent search (searchTerm will be "") + + this.NodesGraphUtils.highlightMatchingNodesByName(this._cy, searchTerm); + let matchingNodes: Cy.CollectionNodes = this.NodesGraphUtils.getMatchingNodesByName(this._cy, searchTerm); + scope.zoomAll(matchingNodes); + }; scope.createLinkFromMenu = (chosenMatch:MatchBase):void => { scope.isLinkMenuOpen = false; @@ -367,7 +415,7 @@ export class CompositionGraph implements ng.IDirective { });*/ this._cy.on('handlemouseover', (event, payload) => { - if (payload.node.grabbed() /* || this._cy.scratch('_edge_editation_highlights') === true*/) { //no need to add opacity while we are dragging and hovering othe nodes- or if opacity was already calculated for these nodes + if (payload.node.grabbed() || this._cy.scratch('_edge_editation_highlights') === true) { //no need to add opacity while we are dragging and hovering othe nodes- or if opacity was already calculated for these nodes return; } let nodesData = this.NodesGraphUtils.getAllNodesData(this._cy.nodes()); @@ -377,9 +425,9 @@ export class CompositionGraph implements ng.IDirective { let filteredNodesData = this.matchCapabilitiesRequirementsUtils.findByMatchingCapabilitiesToRequirements(payload.node.data().componentInstance, linkableNodes, nodesLinks); this.matchCapabilitiesRequirementsUtils.highlightMatchingComponents(filteredNodesData, this._cy); this.matchCapabilitiesRequirementsUtils.fadeNonMachingComponents(filteredNodesData, nodesData, this._cy, payload.node.data()); - /* + this._cy.scratch()._edge_editation_highlights = true; - scope.hideAssetPopover();*/ + /*scope.hideAssetPopover();*/ }); this._cy.on('handlemouseout', () => { diff --git a/catalog-ui/src/app/directives/graphs-v2/composition-graph/composition-graph.html b/catalog-ui/src/app/directives/graphs-v2/composition-graph/composition-graph.html index 1e69d3384a..248f19fb70 100644 --- a/catalog-ui/src/app/directives/graphs-v2/composition-graph/composition-graph.html +++ b/catalog-ui/src/app/directives/graphs-v2/composition-graph/composition-graph.html @@ -20,4 +20,11 @@ +
+ +
+
+
+
diff --git a/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-general-utils.ts b/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-general-utils.ts index 608031430b..0ea38af825 100644 --- a/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-general-utils.ts +++ b/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-general-utils.ts @@ -64,6 +64,14 @@ export class CompositionGraphGeneralUtils { }; + public zoomGraphTo = (cy:Cy.Instance, zoomLevel: number):void => { + let zy = cy.height() / 2; + let zx = cy.width() / 2; + cy.zoom({ + level: zoomLevel, + renderedPosition: { x: zx, y: zy } + }); + } /** * will return true/false if two nodes overlapping * diff --git a/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-nodes-utils.ts b/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-nodes-utils.ts index feb6ac9a54..449d551cc0 100644 --- a/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-nodes-utils.ts +++ b/catalog-ui/src/app/directives/graphs-v2/composition-graph/utils/composition-graph-nodes-utils.ts @@ -48,6 +48,21 @@ export class CompositionGraphNodesUtils { }) }; + + public highlightMatchingNodesByName = (cy: Cy.Instance, nameToMatch: string) => { + + cy.batch(() => { + cy.nodes("[name !@^= '" + nameToMatch + "']").style({ 'background-image-opacity': 0.4 }); + cy.nodes("[name @^= '" + nameToMatch + "']").style({ 'background-image-opacity': 1 }); + }) + + } + + //Returns all nodes whose name starts with searchTerm + public getMatchingNodesByName = (cy: Cy.Instance, nameToMatch: string): Cy.CollectionNodes => { + return cy.nodes("[name @^= '" + nameToMatch + "']"); + }; + /** * Deletes component instances on server and then removes it from the graph as well * @param cy diff --git a/catalog-ui/src/app/models/components/component.ts b/catalog-ui/src/app/models/components/component.ts index 9b2c942483..53e8f05cbe 100644 --- a/catalog-ui/src/app/models/components/component.ts +++ b/catalog-ui/src/app/models/components/component.ts @@ -923,16 +923,17 @@ export abstract class Component implements IComponent { } public toJSON = ():any => { - this.componentService = undefined; - this.filterTerm = undefined; - this.iconSprite = undefined; - this.mainCategory = undefined; - this.subCategory = undefined; - this.selectedInstance = undefined; - this.showMenu = undefined; - this.$q = undefined; - this.selectedCategory = undefined; - return this; + let temp = angular.copy(this); + temp.componentService = undefined; + temp.filterTerm = undefined; + temp.iconSprite = undefined; + temp.mainCategory = undefined; + temp.subCategory = undefined; + temp.selectedInstance = undefined; + temp.showMenu = undefined; + temp.$q = undefined; + temp.selectedCategory = undefined; + return temp; }; } diff --git a/catalog-ui/src/app/models/components/resource.ts b/catalog-ui/src/app/models/components/resource.ts index 138b413028..cd839786c5 100644 --- a/catalog-ui/src/app/models/components/resource.ts +++ b/catalog-ui/src/app/models/components/resource.ts @@ -163,17 +163,18 @@ export class Resource extends Component { }; public toJSON = ():any => { - this.componentService = undefined; - this.filterTerm = undefined; - this.iconSprite = undefined; - this.mainCategory = undefined; - this.subCategory = undefined; - this.selectedInstance = undefined; - this.showMenu = undefined; - this.$q = undefined; - this.selectedCategory = undefined; - this.importedFile = undefined; - return this; + let temp = angular.copy(this); + temp.componentService = undefined; + temp.filterTerm = undefined; + temp.iconSprite = undefined; + temp.mainCategory = undefined; + temp.subCategory = undefined; + temp.selectedInstance = undefined; + temp.showMenu = undefined; + temp.$q = undefined; + temp.selectedCategory = undefined; + temp.importedFile = undefined; + return temp; }; } diff --git a/catalog-ui/src/app/ng2/app.module.ts b/catalog-ui/src/app/ng2/app.module.ts index 09b40e920f..57adb8fd66 100644 --- a/catalog-ui/src/app/ng2/app.module.ts +++ b/catalog-ui/src/app/ng2/app.module.ts @@ -40,6 +40,8 @@ import {ComponentInstanceServiceNg2} from "./services/component-instance-service import { InterceptorService } from 'ng2-interceptors'; import { XHRBackend, RequestOptions } from '@angular/http'; import {HttpInterceptor} from "./services/http.interceptor.service"; +import { SearchBarComponent } from './shared/search-bar/search-bar.component'; +import { SearchWithAutoCompleteComponent } from './shared/search-with-autocomplete/search-with-autocomplete.component'; export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule)); @@ -60,7 +62,9 @@ export function interceptorFactory(xhrBackend: XHRBackend, requestOptions: Reque @NgModule({ declarations: [ - AppComponent + AppComponent, + SearchBarComponent, + SearchWithAutoCompleteComponent ], imports: [ BrowserModule, @@ -70,7 +74,7 @@ export function interceptorFactory(xhrBackend: XHRBackend, requestOptions: Reque PropertiesAssignmentModule ], exports: [], - entryComponents: [], + entryComponents: [SearchWithAutoCompleteComponent], providers: [ DataTypesServiceProvider, SharingServiceProvider, diff --git a/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.less b/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.less index 05378f0eb9..89c7287449 100644 --- a/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.less +++ b/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.less @@ -85,7 +85,7 @@ border-right:#d2d2d2 solid 1px; } &.col1 { - flex: 0 0 300px; + flex: 1 0 200px; max-width:300px; display: flex; justify-content: space-between; diff --git a/catalog-ui/src/app/ng2/components/properties-table/properties-table.component.less b/catalog-ui/src/app/ng2/components/properties-table/properties-table.component.less index 3eb7e960ab..9ede84faff 100644 --- a/catalog-ui/src/app/ng2/components/properties-table/properties-table.component.less +++ b/catalog-ui/src/app/ng2/components/properties-table/properties-table.component.less @@ -91,7 +91,7 @@ border-right:#d2d2d2 solid 1px; } &.col1 { - flex: 0 0 300px; + flex: 1 0 210px; max-width:300px; display: flex; justify-content: space-between; @@ -100,7 +100,7 @@ .property-name { flex: 1; display: flex; - max-width: 270px; + max-width: 90%; } .property-description-icon { @@ -123,7 +123,7 @@ } &.valueCol { - flex: 1 0 350px; + flex: 2 0 300px; display: flex; @media @smaller-screen { flex: 1 0 40%;} } diff --git a/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.html b/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.html new file mode 100644 index 0000000000..36629594b0 --- /dev/null +++ b/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.html @@ -0,0 +1,5 @@ +
+ + x + +
\ No newline at end of file diff --git a/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.less b/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.less new file mode 100644 index 0000000000..cfeb8d3b01 --- /dev/null +++ b/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.less @@ -0,0 +1,58 @@ +.search-bar-container { + display:flex; + border-radius: 4px; + box-shadow: 0px 2px 3.88px 0.12px rgba(0, 0, 0, 0.29); + + .search-bar-input { + border: 1px solid #cdcdcd; + border-radius: 4px; + border-right:none; + border-top-right-radius: 0; + border-bottom-right-radius: 0; + outline:none; + padding:2px 50px 2px 10px; + color: #5a5a5a; + font-size: 1em; + font-style: italic; + } + + .clear-search-x { + position:absolute; + right:40px; + top:5px; + padding: 0 5px; + + &:hover { + border-radius:2px; + background-color: #ebebeb; + cursor:pointer; + } + } + + .search-bar-button { + //background: url('../../../../assets/styles/svg/source/search-magnify.svg') no-repeat 50%; + background: url('../../../../assets/styles/images/sprites/sprite-global.png') no-repeat -206px -1275px; + background-color: rgba(234, 234, 234, 0.88); + width: 30px; + height: 30px; + padding: 0; + cursor:pointer; + border:solid 1px #cdcdcd; + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; + + &:hover { + background-position:-126px -1275px; + } + + &:active { + background-color: rgba(31, 171, 223, 0.88); + background-position:-45px -1275px; + border-left:none; + } + &:focus { + outline:none; + } + + } +} diff --git a/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.ts b/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.ts new file mode 100644 index 0000000000..2835d20ba4 --- /dev/null +++ b/catalog-ui/src/app/ng2/shared/search-bar/search-bar.component.ts @@ -0,0 +1,30 @@ +import { Component, Input, Output, EventEmitter, ViewEncapsulation } from '@angular/core'; + +@Component({ + selector: 'search-bar', + templateUrl: './search-bar.component.html', + styleUrls: ['./search-bar.component.less'], + encapsulation: ViewEncapsulation.None +}) +export class SearchBarComponent { + + @Input() placeholder: string; + @Input() class: string; + @Input() searchQuery: string; + @Output() searchChanged: EventEmitter = new EventEmitter(); + @Output() searchButtonClicked: EventEmitter = new EventEmitter(); + + searchButtonClick = (): void => { + this.searchButtonClicked.emit(this.searchQuery); + } + + searchQueryChange = ($event): void => { + this.searchChanged.emit($event); + } + + private clearSearchQuery = (): void => { + this.searchQuery = ""; + this.searchButtonClick(); + } +} + diff --git a/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.html b/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.html new file mode 100644 index 0000000000..c9769ba5ae --- /dev/null +++ b/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.html @@ -0,0 +1,6 @@ +
+ +
+
{{item}}
+
+
\ No newline at end of file diff --git a/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.less b/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.less new file mode 100644 index 0000000000..92b054cd85 --- /dev/null +++ b/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.less @@ -0,0 +1,35 @@ + +.search-with-autocomplete-container{ + &.autocomplete-visible { + + .search-bar-input { + border-bottom-left-radius: 0; + } + .search-bar-button { + border-bottom-right-radius: 0; + } + .autocomplete-results { + border: solid 1px #d2d2d2; + border-top:none; + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + background-color: #fff; + padding: 10px 20px; + width:100%; + position:absolute; + max-height: 200px; + overflow-y: scroll; + } + + .autocomplete-result-item { + color:#5a5a5a; + padding: 5px 0; + cursor:pointer; + + &:hover { + color: #999; + } + } + } +} + diff --git a/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.ts b/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.ts new file mode 100644 index 0000000000..ced056d1fc --- /dev/null +++ b/catalog-ui/src/app/ng2/shared/search-with-autocomplete/search-with-autocomplete.component.ts @@ -0,0 +1,30 @@ +import { Component, Input, Output, EventEmitter, ViewEncapsulation } from '@angular/core'; +import { SearchBarComponent } from '../search-bar/search-bar.component'; + +@Component({ + selector: 'search-with-autocomplete', + templateUrl: './search-with-autocomplete.component.html', + styleUrls: ['./search-with-autocomplete.component.less'], + encapsulation: ViewEncapsulation.None +}) +export class SearchWithAutoCompleteComponent { + + @Input() searchPlaceholder: string; + @Input() searchBarClass: string; + @Input() searchQuery: string; + @Input() autoCompleteValues: Array; + @Output() searchChanged: EventEmitter = new EventEmitter(); + @Output() searchButtonClicked: EventEmitter = new EventEmitter(); + + searchChange = (searchTerm: string) => { + this.searchQuery = searchTerm; + this.searchChanged.emit(searchTerm); + } + + updateSearch = (searchTerm: string) => { + this.searchQuery = searchTerm; + this.searchButtonClicked.emit(searchTerm); + this.autoCompleteValues = []; + } +} + diff --git a/catalog-ui/src/app/view-models/shared/notification-custom-template.html b/catalog-ui/src/app/view-models/shared/notification-custom-template.html new file mode 100644 index 0000000000..d8fdf135b9 --- /dev/null +++ b/catalog-ui/src/app/view-models/shared/notification-custom-template.html @@ -0,0 +1,14 @@ +
+
+
+
+
+
+
+
+
+

+
+
+
+
diff --git a/catalog-ui/src/app/view-models/workspace/tabs/composition/composition-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/composition/composition-view-model.ts index fbd32cc967..0e5a5fcd6c 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/composition/composition-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/composition/composition-view-model.ts @@ -30,7 +30,8 @@ import {ResourceType} from "../../../../utils/constants"; export interface ICompositionViewModelScope extends IWorkspaceViewModelScope { currentComponent:Component; - selectedComponent:Component; + selectedComponent: Component; + componentInstanceNames: Array; isLoading:boolean; graphApi:any; sharingService:SharingService; @@ -130,7 +131,6 @@ export class CompositionViewModel { private openUpdateComponentInstanceNameModal = ():void => { this.ModalsHandler.openUpdateComponentInstanceNameModal(this.$scope.currentComponent).then(()=> { this.eventListenerService.notifyObservers(GRAPH_EVENTS.ON_COMPONENT_INSTANCE_NAME_CHANGED, this.$scope.currentComponent.selectedInstance); - }); }; @@ -225,7 +225,7 @@ export class CompositionViewModel { this.$scope.openUpdateModal = ():void => { this.openUpdateComponentInstanceNameModal(); }; - + this.$scope.deleteSelectedComponentInstance = ():void => { let state = "deleteInstance"; let onOk = ():void => { diff --git a/catalog-ui/src/app/view-models/workspace/tabs/composition/composition-view.html b/catalog-ui/src/app/view-models/workspace/tabs/composition/composition-view.html index cef942e853..e05574e8c8 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/composition/composition-view.html +++ b/catalog-ui/src/app/view-models/workspace/tabs/composition/composition-view.html @@ -6,7 +6,7 @@ is-loading="isLoading"> + is-view-only="isViewOnly" with-sidebar="displayDesignerRightSidebar">
diff --git a/catalog-ui/src/app/view-models/workspace/tabs/composition/composition.less b/catalog-ui/src/app/view-models/workspace/tabs/composition/composition.less index 7a775bdb11..262dfd9be8 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/composition/composition.less +++ b/catalog-ui/src/app/view-models/workspace/tabs/composition/composition.less @@ -781,6 +781,71 @@ line-height: 18px; } + //Canvas search menu + .w-sdc-search-menu { + position:absolute; + right: 18px; + top:53px; + transition: right 0.2s; + display: flex; + flex-direction: column; + align-items: flex-end; + margin-right:10px; + + &.with-sidebar { + right:320px; + } + + .search-with-autocomplete-container.composition-search { + margin-top: 12px; + + .search-bar-input { + width: 250px; + padding:2px 50px 2px 10px; + transition:all 0.4s; + } + .clear-search-x { + top: 17px + } + + &:not(:hover):not(.autocomplete-visible):not(.active){ + border-radius: 0; + box-shadow:none; + + .search-bar-input:not(:focus){ + width: 0px; + padding:0; + border:none; + } + .clear-search-x { + display:none; + } + .search-bar-input:not(:focus) ~ .search-bar-button { + border-radius: 2px; + border:solid 1px #fff; + } + } + } + + .zoom-icons { + border:solid 1px #fff; + border-radius: 2px; + box-shadow: 0px 2px 3.88px 0.12px rgba(0, 0, 0, 0.29); + background-color: rgba(234, 234, 234, 0.88); + background-repeat: no-repeat; + margin-top: 10px; + + &:hover { + cursor:pointer; + } + + &:active { + border:none; + background-color: rgba(31, 171, 223, 0.88); + } + } + } + // --------------------------------------------------------------------------------------------------- // Canvas inline menu // --------------------------------------------------------------------------------------------------- diff --git a/catalog-ui/src/app/view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view-model.ts index 83e4653954..c4c63fae06 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view-model.ts @@ -33,13 +33,14 @@ import {ICompositionViewModelScope} from "../../composition-view-model"; import {ArtifactsUtils, ModalsHandler, ArtifactGroupType} from "app/utils"; import {GRAPH_EVENTS} from "app/utils/constants"; import {EventListenerService} from "app/services/event-listener-service"; +import {Dictionary} from "../../../../../../utils/dictionary/dictionary"; export interface IArtifactsViewModelScope extends ICompositionViewModelScope { artifacts:Array; artifactType:string; downloadFile:IFileDownload; isLoading:boolean; - + displayDeleteButtonMap:Dictionary; getTitle():string; addOrUpdate(artifact:ArtifactModel):void; delete(artifact:ArtifactModel):void; @@ -125,6 +126,10 @@ export class ResourceArtifactsViewModel { } } this.$scope.artifacts = artifacts; + this.$scope.displayDeleteButtonMap = new Dictionary(); + _.forEach(this.$scope.artifacts, (artifact:ArtifactModel)=>{ + this.$scope.displayDeleteButtonMap[artifact.artifactLabel] = this.displayDeleteButton(artifact); + }); this.$scope.isLoading = false; }; @@ -229,6 +234,17 @@ export class ResourceArtifactsViewModel { }); }; + private displayDeleteButton = (artifact:ArtifactModel):boolean => { + if(!this.$scope.isViewMode() && artifact.esId){ + if(this.$scope.isComponentInstanceSelected()){//is artifact of instance + return !this.$scope.selectedComponent.deploymentArtifacts || !this.$scope.selectedComponent.deploymentArtifacts[artifact.artifactLabel];//if the artifact is not from instance parent + }else{//is artifact of main component + return (!artifact.isHEAT() && !artifact.isThirdParty() && !this.$scope.isLicenseArtifact(artifact)); + } + } + return false; +}; + private initScope = ():void => { this.$scope.isLoading = false; diff --git a/catalog-ui/src/app/view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html b/catalog-ui/src/app/view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html index 8221c67eca..dfbd639eb4 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html +++ b/catalog-ui/src/app/view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html @@ -36,7 +36,7 @@ Description:{{artifact.description}} -