From ed7e1c3dfe332abc67ed943717db2ee94406f95e Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Thu, 29 Jun 2017 19:30:00 +0300 Subject: [SDC] rebase code Change-Id: I456ec65a233d277e6bae35e140f2e3da5765bae6 Signed-off-by: Tal Gitelman Signed-off-by: Michael Lando --- .gitignore | 2 + .../ci/tests/execute/imports/CsarUtilsTest.java | 3 + .../src/main/resources/ci/testSuites/sanity.xml | 1 + .../v1707/Migration1707ArtifactUuidFix.java | 5 +- .../migration/v1707/ToscaTemplateRegeneration.java | 5 +- .../v1707/jsonmodel/ComponentMigration.java | 21 +- .../jsonmodel/NodeTemplateMissingDataResolver.java | 225 ++++++++- .../openecomp/sdc/asdctool/main/MigrationMenu.java | 44 +- catalog-be/pom.xml | 46 +- .../be/components/impl/ArtifactsBusinessLogic.java | 27 +- .../impl/ComponentInstanceBusinessLogic.java | 12 +- .../be/components/impl/ElementBusinessLogic.java | 85 ++-- .../be/components/impl/InputsBusinessLogic.java | 513 ++++++++++++--------- .../be/components/impl/ResourceBusinessLogic.java | 16 + .../servlet/DistributionCatalogServlet.java | 137 ++++-- .../distribution/servlet/DistributionServlet.java | 183 ++++++-- .../servlet/ArtifactExternalServlet.java | 39 +- .../be/externalapi/servlet/AssetsDataServlet.java | 317 +++++++------ .../be/servlets/AdditionalInformationServlet.java | 100 +++- .../sdc/be/servlets/ComponentInstanceServlet.java | 1 + catalog-be/src/main/webapp/WEB-INF/web.xml | 29 +- .../externalapi/servlet/AssetsDataServletTest.java | 5 +- catalog-fe/src/main/webapp/WEB-INF/web.xml | 14 +- .../sdc/be/model/ComponentInstanceInput.java | 14 +- .../sdc/be/model/GroupInstanceProperty.java | 1 + .../jsontitan/operations/ArtifactsOperations.java | 84 ++-- .../model/jsontitan/operations/BaseOperation.java | 6 + .../operations/NodeTemplateOperation.java | 16 +- .../jsontitan/operations/ToscaOperationFacade.java | 13 +- catalog-ui/package.json | 9 +- .../app/models/properties-inputs/input-be-model.ts | 42 +- .../app/models/properties-inputs/input-fe-model.ts | 57 +-- catalog-ui/src/app/models/properties.ts | 2 + catalog-ui/src/app/ng2/app.module.ts | 17 +- .../properties-assignment.module.ts | 4 +- .../properties-assignment.page.component.ts | 52 +-- .../properties-assignment/properties.utils.ts | 18 +- .../component-instance.service.ts | 4 +- .../component-services/component.service.ts | 6 +- .../services/component-services/service.service.ts | 4 +- .../app/ng2/services/http.interceptor.service.ts | 57 +++ catalog-ui/src/app/ng2/services/posts.service.ts | 54 --- .../responses/component-generic-response.ts | 4 +- catalog-ui/src/app/utils/common-utils.ts | 10 +- .../workspace/tabs/properties/properties-view.html | 4 +- .../assets/styles/images/sprites/sprite-global.png | Bin 89666 -> 90334 bytes catalog-ui/src/assets/styles/sprite.less | 4 +- .../org/openecomp/sdc/common/api/Constants.java | 1 + .../elements/ComponentInstanceDataDefinition.java | 13 + .../datatypes/elements/PropertyDataDefinition.java | 43 +- openecomp-be/lib/openecomp-migration-lib/pom.xml | 192 -------- .../src/main/assembly/migration-lib-assembly.xml | 26 -- .../org/openecomp/sdc/migration/TestScript.java | 11 - .../sdc/migration/ToscaNamespaceMigration.java | 290 ------------ .../src/main/resources/logback.xml | 280 ----------- .../src/main/resources/openecomp-migration-lib.zip | Bin 36707747 -> 0 bytes .../openecomp-sdc-translator-core/pom.xml | 2 +- .../openecomp-sdc-translator-impl/pom.xml | 2 +- openecomp-be/lib/pom.xml | 1 - .../core/tools/Commands/ExportDataCommand.java | 62 +++ .../core/tools/Commands/ImportCommand.java | 43 ++ .../core/tools/Commands/ResetOldVersion.java | 12 +- .../tools/Commands/exportdata/ElementHandler.java | 100 ++++ .../Commands/exportdata/ImportProperties.java | 20 + .../tools/Commands/exportdata/ItemHandler.java | 62 +++ .../tools/Commands/exportdata/VersionHandler.java | 74 +++ .../tools/Commands/importdata/ElementImport.java | 116 +++++ .../core/tools/Commands/importdata/ItemImport.java | 42 ++ .../core/tools/Commands/importdata/TreeWalker.java | 51 ++ .../tools/Commands/importdata/VersionImport.java | 41 ++ .../Commands/importdata/VersionInfoImport.java | 41 ++ .../core/tools/main/ZusammenMainTool.java | 14 +- .../core/tools/store/ElementCassandraLoader.java | 74 +++ .../core/tools/store/ElementNamespaceHandler.java | 27 ++ .../core/tools/store/VersionCassandraLoader.java | 78 ++++ .../tools/store/VersionInfoCassandraLoader.java | 62 +++ .../core/tools/store/VspGeneralLoader.java | 40 ++ .../store/zusammen/datatypes/ElementEntity.java | 168 +++++++ .../store/zusammen/datatypes/VersionEntity.java | 128 +++++ .../org/openecomp/core/tools/util/ZipUtils.java | 89 ++++ .../src/main/resources/zusammenMainTool.sh | 6 +- pom.xml | 9 + test-apis-ci/pom.xml | 2 +- .../sdc/ci/tests/execute/devCI/AndreyTest.java | 32 +- .../utils/validation/AuditValidationUtils.java | 15 +- .../sdc/externalApis/CRUDExternalAPI.java | 64 +-- .../src/main/resources/ci/scripts/startTest.sh | 2 +- .../src/main/resources/ci/scripts/userList.txt | 2 +- .../main/resources/ci/testSuites/externalAPIs.xml | 4 +- ...portUpdateInformationalDeploymentArtifacts.java | 10 +- .../tests/execute/sanity/DeploymentViewTests.java | 20 +- .../sdc/ci/tests/execute/sanity/VfArtifacts.java | 26 +- .../sdc/ci/tests/execute/setup/SetupCDTest.java | 42 +- .../sdc/ci/tests/utilities/ArtifactUIUtils.java | 6 +- .../sdc/ci/tests/utilities/FileHandling.java | 12 +- .../sdc/ci/tests/utilities/OnboardingUtils.java | 18 +- .../ci/tests/verificator/ServiceVerificator.java | 5 - ui-ci/src/main/resources/ci/conf/credentials.yaml | 48 -- .../main/resources/ci/conf/credentials.yaml_prod | 48 -- .../resources/ci/conf/credentials.yaml_webtest | 48 -- ui-ci/src/main/resources/ci/scripts/startTest.sh | 2 +- ui-ci/src/main/resources/ci/scripts/userList.txt | 1 - 102 files changed, 3037 insertions(+), 1902 deletions(-) create mode 100644 catalog-ui/src/app/ng2/services/http.interceptor.service.ts delete mode 100644 catalog-ui/src/app/ng2/services/posts.service.ts delete mode 100644 openecomp-be/lib/openecomp-migration-lib/pom.xml delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml delete mode 100644 openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java delete mode 100644 ui-ci/src/main/resources/ci/conf/credentials.yaml delete mode 100644 ui-ci/src/main/resources/ci/conf/credentials.yaml_prod delete mode 100644 ui-ci/src/main/resources/ci/conf/credentials.yaml_webtest delete mode 100644 ui-ci/src/main/resources/ci/scripts/userList.txt diff --git a/.gitignore b/.gitignore index 5daf9895ac..e9f00350d3 100644 --- a/.gitignore +++ b/.gitignore @@ -148,3 +148,5 @@ sdc-os-chef/.idea/* # chef .delivery + +common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-core/logs/* diff --git a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java index e99ecc7303..16d3fcb092 100644 --- a/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java +++ b/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/imports/CsarUtilsTest.java @@ -234,7 +234,10 @@ public class CsarUtilsTest extends ComponentBaseTest { while ((len = zip.read(buffer)) > 0) { sb.append(new String(buffer, 0, len)); } + assertTrue(nextEntry.getName().equals("csar.meta")); + readNextEntry(sb, len, buffer, zip); + nextEntry = zip.getNextEntry(); assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta")); YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter(); diff --git a/asdc-tests/src/main/resources/ci/testSuites/sanity.xml b/asdc-tests/src/main/resources/ci/testSuites/sanity.xml index 21b7043ad3..6a3d1178f5 100644 --- a/asdc-tests/src/main/resources/ci/testSuites/sanity.xml +++ b/asdc-tests/src/main/resources/ci/testSuites/sanity.xml @@ -152,6 +152,7 @@ + diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java index 6f645dc8dd..d8b2f62705 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java @@ -147,10 +147,9 @@ public class Migration1707ArtifactUuidFix { vfLst.add(resource); writeModuleResultToFile(writer, resource, null); writer.flush(); - break; } + titanDao.commit(); } - titanDao.commit(); } catch (Exception e) { log.info("Failed to fetch vf resources ", e); @@ -510,7 +509,7 @@ public class Migration1707ArtifactUuidFix { List groupsList = resource.getGroups(); if (groupsList != null && artifactsMap != null) { for (GroupDefinition group : groupsList) { - if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) { + if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) && group.getArtifacts() != null) { log.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", resource.getUniqueId(), group.getName()); List groupArtifacts = new ArrayList(group.getArtifacts()); group.getArtifacts().clear(); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java index 09e52619f0..555a54d038 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java @@ -72,7 +72,8 @@ public class ToscaTemplateRegeneration implements Migration1707Task { private boolean regenerateToscaTemplateArtifacts(List components) { boolean result = true; for(GraphVertex componentV : components){ - Either getComponentsRes = toscaOperationFacade.getToscaElement(componentV); + String componentId = componentV.getUniqueId(); + Either getComponentsRes = toscaOperationFacade.getToscaElement(componentId); if (getComponentsRes.isRight()) { result = false; break; @@ -135,7 +136,7 @@ public class ToscaTemplateRegeneration implements Migration1707Task { Map propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); List components = null; - Either, TitanOperationStatus> getVerticiesRes = toscaOperationFacade.getTitanDao().getByCriteria(null, propertiesToMatch,JsonParseFlagEnum.ParseMetadata); + Either, TitanOperationStatus> getVerticiesRes = toscaOperationFacade.getTitanDao().getByCriteria(null, propertiesToMatch,JsonParseFlagEnum.NoParse); if (getVerticiesRes.isRight() && getVerticiesRes.right().value() != TitanOperationStatus.NOT_FOUND) { LOGGER.debug("Failed to fetch all certified components. Status is {}", getVerticiesRes.right().value()); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java index 30d14e686b..51e51d4c02 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java @@ -4,18 +4,24 @@ import fj.data.Either; import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.RequirementsCapabilitiesMigrationService; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; +import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.GroupInstance; import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.migration.MigrationMalformedDataLogger; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; +import org.openecomp.sdc.common.api.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -83,12 +89,21 @@ public abstract class ComponentMigration extends JsonModel protected void setMissingTemplateInfo(List components) { Map origCompMap = new HashMap<>(); for (T component : components) { - for (ComponentInstance instance : component.getComponentInstances()){ - nodeTemplateMissingDataResolver.resolveNodeTemplateInfo(instance, origCompMap, component); - } + List instances = component.getComponentInstances(); + if(null != instances) { + for (ComponentInstance instance : instances) { + nodeTemplateMissingDataResolver.resolveNodeTemplateInfo(instance, origCompMap, component); + nodeTemplateMissingDataResolver.fixVFGroupInstances(component, instance); + } + } + nodeTemplateMissingDataResolver.fixVFGroups(component); } } + + + + diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java index 275d499bae..f0763a138c 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java @@ -1,29 +1,34 @@ package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.annotation.Resource; - +import fj.data.Either; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; +import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentInstanceInput; +import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.GroupInstance; 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.jsontitan.operations.ToscaElementLifecycleOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; +import org.openecomp.sdc.common.api.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import fj.data.Either; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; public class NodeTemplateMissingDataResolver { @@ -38,8 +43,10 @@ public class NodeTemplateMissingDataResolver { public void resolveNodeTemplateInfo(ComponentInstanceDataDefinition vfInst, Map origCompMap, T component) { lifecycleOperation.resolveToscaComponentName(vfInst, origCompMap); - if(OriginTypeEnum.VF == vfInst.getOriginType()) - collectVFInstanceInputs(component.getComponentInstancesInputs(), origCompMap, vfInst); + if(OriginTypeEnum.VF == vfInst.getOriginType()) { + Map> componentInstancesInputs = Optional.ofNullable(component.getComponentInstancesInputs()).orElse(new HashMap<>()); + collectVFInstanceInputs(componentInstancesInputs, origCompMap, vfInst); + } } private void collectVFInstanceInputs(Map> instInputs, Map origCompMap, ComponentInstanceDataDefinition vfInst) { @@ -51,7 +58,7 @@ public class NodeTemplateMissingDataResolver { Map origVFInputs = ((TopologyTemplate)origComp.left().value()).getInputs(); if (origVFInputs != null && !origVFInputs.isEmpty()) { Map collectedVFInputs = origVFInputs.values().stream() - .collect(Collectors.toMap(p -> p.getName(), p -> new ComponentInstanceInput(p))); + .collect(Collectors.toMap(PropertyDataDefinition::getName, ComponentInstanceInput::new)); List instInputList = instInputs.get(ciUid); Map existingInstInputs = ToscaDataDefinition.listToMapByName(instInputList); collectedVFInputs.putAll(existingInstInputs); @@ -72,4 +79,198 @@ public class NodeTemplateMissingDataResolver { } return Either.left(origCompMap.get(origCompUid)); } + + protected boolean isProblematicGroup(GroupDefinition gr, String resourceName, Map deploymentArtifacts) { + List artifacts = gr.getArtifacts(); + List artifactsUuid = gr.getArtifactsUuid(); + + if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) { + LOGGER.debug("No groups in resource {} ", resourceName); + return false; + } + if (artifacts.size() < artifactsUuid.size()) { + LOGGER.debug(" artifacts.size() < artifactsUuid.size() group {} in resource {} ", gr.getName(), resourceName); + return true; + } + if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) { + LOGGER.debug(" artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() group {} in resource {} ", gr.getName(), resourceName); + return true; + } + if (artifactsUuid.contains(null)) { + LOGGER.debug(" artifactsUuid.contains(null) group {} in resource {} ", gr.getName(), resourceName); + return true; + } + + for (String artifactId : artifacts) { + String artifactlabel = findArtifactLabelFromArtifactId(artifactId); + ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel); + if (artifactDefinition == null) { + LOGGER.debug(" artifactDefinition == null label {} group {} in resource {} ", artifactlabel, gr.getName(), resourceName); + return true; + } + ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactDefinition.getArtifactType()); + if (artifactType != ArtifactTypeEnum.HEAT_ENV) { + if (!artifactId.equals(artifactDefinition.getUniqueId())) { + LOGGER.debug(" !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} group {} in resource {} ", artifactlabel, artifactId, gr.getName(), resourceName); + return true; + } + if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) { + LOGGER.debug(" artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} group {} in resource {} ", artifactlabel, gr.getName(), resourceName); + return true; + } + } + } + return false; + } + + protected boolean isProblematicGroupInstance(GroupInstance gi, String instName, String servicename, Map deploymentArtifacts) { + List artifacts = gi.getArtifacts(); + List artifactsUuid = gi.getArtifactsUuid(); + List instArtifactsUuid = gi.getGroupInstanceArtifactsUuid(); + + if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) { + LOGGER.debug("No instance groups for instance {} in service {} ", instName, servicename); + return false; + } + if (artifacts.size() < artifactsUuid.size()) { + LOGGER.debug(" artifacts.size() < artifactsUuid.size() inst {} in service {} ", instName, servicename); + return true; + } + if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) { + LOGGER.debug(" artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() inst {} in service {} ", instName, servicename); + return true; + } + if (artifactsUuid.contains(null)) { + LOGGER.debug(" artifactsUuid.contains(null) inst {} in service {} ", instName, servicename); + return true; + } + + for (String artifactId : artifacts) { + String artifactlabel = findArtifactLabelFromArtifactId(artifactId); + ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel); + if (artifactDefinition == null) { + LOGGER.debug(" artifactDefinition == null label {} inst {} in service {} ", artifactlabel, instName, servicename); + return true; + } + ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactDefinition.getArtifactType()); + if (artifactType != ArtifactTypeEnum.HEAT_ENV) { + if (!artifactId.equals(artifactDefinition.getUniqueId())) { + LOGGER.debug(" !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} inst {} in service {} ", artifactlabel, artifactId, instName, servicename); + return true; + } + if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) { + LOGGER.debug(" artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ", artifactlabel, instName, servicename); + return true; + } + } else { + if (!instArtifactsUuid.contains(artifactDefinition.getArtifactUUID())) { + LOGGER.debug(" instArtifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ", artifactlabel, instName, servicename); + return true; + } + } + } + return false; + } + + private String findArtifactLabelFromArtifactId(String artifactId) { + String artifactLabel = ""; + + int index = artifactId.lastIndexOf("."); + if (index > 0 && index + 1 < artifactId.length()) + artifactLabel = artifactId.substring(index + 1); + return artifactLabel; + } + + protected boolean fixVFGroups(Component component){ + boolean res = true; + + Map deploymentArtifacts = component.getDeploymentArtifacts(); + List groups = component.getGroups(); + if (groups == null || groups.isEmpty()) { + LOGGER.debug("No groups in component {} id {} ", component.getName(), component.getUniqueId()); + return res; + } + + for (GroupDefinition group : groups) { + if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) && deploymentArtifacts != null) { + if (isProblematicGroup(group, component.getName(), deploymentArtifacts)) { + List groupArtifacts = new ArrayList(group.getArtifacts()); + group.getArtifacts().clear(); + group.getArtifactsUuid().clear(); + for (String artifactId : groupArtifacts) { + String artifactlabel = findArtifactLabelFromArtifactId(artifactId); + LOGGER.debug("fix group: group name {} artifactId for fix {} artifactlabel {} ", group.getName(), artifactId, artifactlabel); + if (!artifactlabel.isEmpty() && deploymentArtifacts.containsKey(artifactlabel)) { + ArtifactDefinition artifact = deploymentArtifacts.get(artifactlabel); + String correctArtifactId = artifact.getUniqueId(); + String correctArtifactUUID = artifact.getArtifactUUID(); + LOGGER.debug(" fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID); + group.getArtifacts().add(correctArtifactId); + if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) { + group.getArtifactsUuid().add(correctArtifactUUID); + } + + } + } + } + } + + } + + return res; + } + + protected boolean fixVFGroupInstances(Component component, ComponentInstance instance){ + boolean res = true; + + Map deploymentArtifacts = instance.getDeploymentArtifacts(); + List groupInstances = instance.getGroupInstances(); + if (groupInstances == null || groupInstances.isEmpty()) { + LOGGER.debug("No instance groups for instance {} in service {} id {} ", instance.getName(), component.getName(), component.getUniqueId()); + return res; + } + for (GroupInstance group : groupInstances) { + if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) { + if (isProblematicGroupInstance(group, instance.getName(), component.getName(), deploymentArtifacts)) { + + LOGGER.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", component.getUniqueId(), group.getName()); + List groupArtifacts = Optional.ofNullable(group.getArtifacts()).orElse(new ArrayList<>()); + + group.setArtifacts(new ArrayList<>()); + group.setArtifactsUuid(new ArrayList<>()); + group.setGroupInstanceArtifacts(new ArrayList<>()); + group.setGroupInstanceArtifactsUuid(new ArrayList<>()); + + for (String artifactId : groupArtifacts) { + String artifactlabel = findArtifactLabelFromArtifactId(artifactId); + LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} artifactId for fix {} artifactlabel {} ", group.getName(), artifactId, artifactlabel); + if (!artifactlabel.isEmpty() && deploymentArtifacts.containsKey(artifactlabel)) { + ArtifactDefinition artifact = deploymentArtifacts.get(artifactlabel); + ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType()); + String correctArtifactId = artifact.getUniqueId(); + String correctArtifactUUID = artifact.getArtifactUUID(); + if (artifactType != ArtifactTypeEnum.HEAT_ENV) { + + LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID); + group.getArtifacts().add(correctArtifactId); + if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) { + group.getArtifactsUuid().add(correctArtifactUUID); + } + } else { + LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID); + group.getGroupInstanceArtifacts().add(correctArtifactId); + if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) { + group.getGroupInstanceArtifactsUuid().add(correctArtifactUUID); + } + } + } + } + + } + } + } + + return res; + } + } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java index cfb1ec0b27..0c06052654 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java @@ -246,30 +246,30 @@ public class MigrationMenu { break; case MIGRATION_1702_1707://this migration is currently not needed, but will be commented out for production env - log.info("Start ASDC migration from 1702 to 1707"); - Migration1707 migration1707 = (Migration1707) context.getBean(operationEnum.getBeanName()); - isSuccessful = migration1707.migrate(); - if (isSuccessful) { - log.info("SDC migration from 1702 to 1707 was finished successfully"); - System.exit(0); - } else{ - log.info("SDC migration from 1702 to 1707 has failed"); - System.exit(2); - } - //System.exit(0); +// log.info("Start ASDC migration from 1702 to 1707"); +// Migration1707 migration1707 = (Migration1707) context.getBean(operationEnum.getBeanName()); +// isSuccessful = migration1707.migrate(); +// if (isSuccessful) { +// log.info("SDC migration from 1702 to 1707 was finished successfully"); +// System.exit(0); +// } else{ +// log.info("SDC migration from 1702 to 1707 has failed"); +// System.exit(2); +// } + System.exit(0); break; case VFMODULES_PROPERTIES_ADDING://this migration is currently not needed, but will be commented out for production env - log.info("Start adding new properties to vfModules"); - VfModulesPropertiesAdding migrationVfModulesProperties = (VfModulesPropertiesAdding) context.getBean(operationEnum.getBeanName()); - isSuccessful = migrationVfModulesProperties.migrate(args[1]); - if (isSuccessful) { - log.info("Adding new properties to vfModules was finished successfully"); - System.exit(0); - } else{ - log.info("Adding new properties to vfModules has failed"); - System.exit(2); - } - //System.exit(0); +// log.info("Start adding new properties to vfModules"); +// VfModulesPropertiesAdding migrationVfModulesProperties = (VfModulesPropertiesAdding) context.getBean(operationEnum.getBeanName()); +// isSuccessful = migrationVfModulesProperties.migrate(args[1]); +// if (isSuccessful) { +// log.info("Adding new properties to vfModules was finished successfully"); +// System.exit(0); +// } else{ +// log.info("Adding new properties to vfModules has failed"); +// System.exit(2); +// } + System.exit(0); break; case MIGRATION_1707_UUID_FIX: if (args == null || args.length < 5) { diff --git a/catalog-be/pom.xml b/catalog-be/pom.xml index 42d3e47886..2efa9e9302 100644 --- a/catalog-be/pom.xml +++ b/catalog-be/pom.xml @@ -90,10 +90,8 @@ compile 1.5.15 - - - + org.openecomp.sdc common-app-api @@ -493,7 +491,7 @@ - org.openecomp.sdc.common + ${dox-common-lib.groupId} openecomp-common-lib ${dox-common-lib.version} pom @@ -662,26 +660,6 @@ - - - com.googlecode.maven-download-plugin - download-maven-plugin - 1.2.1 - - - swagger-ui - - wget - - - https://github.com/swagger-api/swagger-ui/archive/v${swagger-ui-version}.tar.gz - true - ${project.build.directory} - - - - - maven-clean-plugin 2.6.1 @@ -711,26 +689,6 @@ maven-resources-plugin 2.6 - - copy-resources - process-resources - - copy-resources - - - target/${project.artifactId}-${project.version} - - - ${project.build.directory}/swagger-ui-${swagger-ui-version}/dist - true - - index.html - - - - - - copy-normatives install 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 003fe66d9d..e5d380a836 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 @@ -23,7 +23,6 @@ package org.openecomp.sdc.be.components.impl; import java.io.ByteArrayInputStream; import java.io.IOException; import java.math.BigDecimal; -import java.rmi.activation.ActivationSystem; import java.util.ArrayList; import java.util.Comparator; import java.util.EnumMap; @@ -1335,7 +1334,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { isUpdated = true; } if (CollectionUtils.isNotEmpty(group.getArtifactsUuid()) && group.getArtifactsUuid().contains(foundArtifact.getArtifactUUID())) { - group.getArtifacts().remove(foundArtifact.getArtifactUUID()); + group.getArtifactsUuid().remove(foundArtifact.getArtifactUUID()); isUpdated = true; } if (isUpdated) { @@ -4087,7 +4086,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { Wrapper errorWrapper = new Wrapper<>(); Either result; byte[] downloadedArtifact = null; - Component component = getLatestComponentByUuid(componentType, componentUuid, errorWrapper); + Component component = getComponentByUuid(componentType, componentUuid, errorWrapper); if (errorWrapper.isEmpty()) { auditAdditionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, component.getName()); downloadedArtifact = downloadArtifact(component.getDeploymentArtifacts(), artifactUUID, errorWrapper, component.getName()); @@ -4686,7 +4685,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { private ComponentInstance getRelatedComponentInstance(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, Wrapper errorWrapper) { ComponentInstance componentInstance = null; String normalizedName = ValidationUtils.normalizeComponentInstanceName(resourceInstanceName); - Component component = getLatestComponentByUuid(componentType, componentUuid, errorWrapper); + Component component = getComponentByUuid(componentType, componentUuid, errorWrapper); if (errorWrapper.isEmpty()) { componentInstance = component.getComponentInstances().stream().filter(ci -> ValidationUtils.normalizeComponentInstanceName(ci.getName()).equals(normalizedName)).findFirst().orElse(null); if (componentInstance == null) { @@ -4767,6 +4766,26 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } return component; } + + private Component getComponentByUuid(ComponentTypeEnum componentType, String componentUuid, Wrapper errorWrapper) { + Component component = null; + Either, StorageOperationStatus> getComponentRes = toscaOperationFacade.getComponentListByUuid(componentUuid, null); + if (getComponentRes.isRight()) { + StorageOperationStatus status = getComponentRes.right().value(); + log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status); + errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status))); + } else { + List value = getComponentRes.left().value(); + if (value.isEmpty()){ + log.debug("Could not fetch component with type {} and uuid {}.", componentType, componentUuid); + ActionStatus status = componentType == ComponentTypeEnum.RESOURCE ? ActionStatus.RESOURCE_NOT_FOUND : ActionStatus.SERVICE_NOT_FOUND; + errorWrapper.setInnerElement(componentsUtils.getResponseFormat(status)); + } else { + component = value.get(0); + } + } + return component; + } private String getLatestParentArtifactDataIdByArtifactUUID(String artifactUUID, Wrapper errorWrapper, String parentId, ComponentTypeEnum componentType) { String artifactId = null; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index 203a63894b..f917d60553 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -617,6 +617,7 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic { Either resultOp = null; Optional componentInstanceOptional = null; Either, StorageOperationStatus> updateRes = null; + ComponentInstance oldComponentInstance = null; if (resultOp == null) { componentInstanceOptional = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(componentInstance.getUniqueId())).findFirst(); @@ -626,7 +627,7 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } } if (resultOp == null) { - ComponentInstance oldComponentInstance = componentInstanceOptional.get(); + oldComponentInstance = componentInstanceOptional.get(); String newInstanceName = componentInstance.getName(); Boolean isUniqueName = validateInstanceNameUniquenessUponUpdate(containerComponent, oldComponentInstance, newInstanceName); if (!isUniqueName) { @@ -635,7 +636,7 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } } if (resultOp == null) { - updateRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, origComponent, componentInstance); + updateRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, origComponent, updateComponentInstanceMetadata(oldComponentInstance, componentInstance)); if (updateRes.isRight()) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update metadata of component instance {} belonging to container component {}. Status is {}. ", componentInstance.getName(), containerComponent.getName(), updateRes.right().value()); @@ -660,6 +661,13 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic { return resultOp; } + private ComponentInstance updateComponentInstanceMetadata(ComponentInstance oldComponentInstance, ComponentInstance newComponentInstance) { + oldComponentInstance.setName(newComponentInstance.getName()); + oldComponentInstance.setModificationTime(System.currentTimeMillis()); + oldComponentInstance.setCustomizationUUID(UUID.randomUUID().toString()); + return oldComponentInstance; + } + public Either deleteComponentInstance(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId) { Either resp = validateUserExists(userId, "delete Component Instance", false); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java index dbcc0aec68..669b84f229 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -110,7 +111,11 @@ public class ElementBusinessLogic extends BaseBusinessLogic { * @return */ public Either>, ResponseFormat> getFollowed(User user) { - Either>, ResponseFormat> response = null; + // Used for not getting duplicated followed. Cheaper than checking ArrayList.contains + Either>, ResponseFormat> response = null; + // Used for returning as the code requires. + Either>, ResponseFormat> arrayResponse = null; + // Getting the role String role = user.getRole(); String userId = null; @@ -155,12 +160,25 @@ public class ElementBusinessLogic extends BaseBusinessLogic { response = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)); break; } - return response; + //converting the Set to List so the rest of the code will handle it normally (Was changed because the same element with the same uuid was returned twice) + return convertedToListResponse(response); } - private Either>, ResponseFormat> handleAdmin() { - Either>, ResponseFormat> response; + private Either>,ResponseFormat> convertedToListResponse(Either>, ResponseFormat> setResponse) { + + Map> arrayResponse = new HashMap<>(); + if (setResponse.isLeft()) { + for (Map.Entry> entry : setResponse.left().value().entrySet()) { + arrayResponse.put(entry.getKey(), (new ArrayList(new HashSet(entry.getValue())))); + } + return Either.left(arrayResponse); + } + return Either.right(setResponse.right().value()); + } + + private Either>, ResponseFormat> handleAdmin() { + Either>, ResponseFormat> response; // userId should stay null Set lifecycleStates = new HashSet(); Set lastStateStates = new HashSet(); @@ -169,10 +187,10 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return response; } - private Either>, ResponseFormat> handleDesigner(String userId) { + private Either>, ResponseFormat> handleDesigner(String userId) { Set lifecycleStates = new HashSet(); Set lastStateStates = new HashSet(); - Either>, ResponseFormat> response; + Either>, ResponseFormat> response; lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION); @@ -184,22 +202,22 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return response; } - private Either>, ResponseFormat> handleGovernor(String userId) { - Either>, ResponseFormat> result = handleFollowedCertifiedServices(null); + private Either>, ResponseFormat> handleGovernor(String userId) { + Either>, ResponseFormat> result = handleFollowedCertifiedServices(null); return result; } - private Either>, ResponseFormat> handleProductStrategist(String userId) { + private Either>, ResponseFormat> handleProductStrategist(String userId) { // Should be empty list according to Ella, 13/03/16 - Map> result = new HashMap>(); - result.put("products", new ArrayList<>()); + Map> result = new HashMap>(); + result.put("products", new HashSet<>()); return Either.left(result); } - private Either>, ResponseFormat> handleProductManager(String userId) { + private Either>, ResponseFormat> handleProductManager(String userId) { Set lifecycleStates = new HashSet(); Set lastStateStates = new HashSet(); - Either>, ResponseFormat> response; + Either>, ResponseFormat> response; lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION); @@ -211,47 +229,47 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return response; } - private Either>, ResponseFormat> handleOps(String userId) { + private Either>, ResponseFormat> handleOps(String userId) { Set distStatus = new HashSet(); distStatus.add(DistributionStatusEnum.DISTRIBUTION_APPROVED); distStatus.add(DistributionStatusEnum.DISTRIBUTED); - Either>, ResponseFormat> result = handleFollowedCertifiedServices(distStatus); + Either>, ResponseFormat> result = handleFollowedCertifiedServices(distStatus); return result; } - private Either>, ResponseFormat> handleFollowedCertifiedServices(Set distStatus) { + private Either>, ResponseFormat> handleFollowedCertifiedServices(Set distStatus) { Either, StorageOperationStatus> services = toscaOperationFacade.getCertifiedServicesWithDistStatus(distStatus); if (services.isLeft()) { - Map> result = new HashMap>(); - List list = new ArrayList<>(); - list.addAll(services.left().value()); - result.put("services", list); + Map> result = new HashMap<>(); + Set set = new HashSet<>(); + set.addAll(services.left().value()); + result.put("services", set); return Either.left(result); } else { return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(services.right().value()))); } } - private Either>, ResponseFormat> handleTester(String userId) { + private Either>, ResponseFormat> handleTester(String userId) { Set lifecycleStates = new HashSet(); lifecycleStates.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS); lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION); - Either>, ResponseFormat> result = getFollowedResourcesAndServices(null, lifecycleStates, null); + Either>, ResponseFormat> result = getFollowedResourcesAndServices(null, lifecycleStates, null); return result; } - private Either>, ResponseFormat> getFollowedResourcesAndServices(String userId, Set lifecycleStates, Set lastStateStates) { + private Either>, ResponseFormat> getFollowedResourcesAndServices(String userId, Set lifecycleStates, Set lastStateStates) { try { - Either, StorageOperationStatus> resources = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.RESOURCE); + Either, StorageOperationStatus> resources = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.RESOURCE); if (resources.isLeft()) { - Either, StorageOperationStatus> services = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.SERVICE); + Either, StorageOperationStatus> services = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.SERVICE); if (services.isLeft()) { - Map> result = new HashMap>(); + Map> result = new HashMap>(); result.put("services", services.left().value()); result.put("resources", resources.left().value()); return Either.left(result); @@ -266,10 +284,10 @@ public class ElementBusinessLogic extends BaseBusinessLogic { } } - private Either>, ResponseFormat> getFollowedProducts(String userId, Set lifecycleStates, Set lastStateStates) { - Either, StorageOperationStatus> products = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.PRODUCT); + private Either>, ResponseFormat> getFollowedProducts(String userId, Set lifecycleStates, Set lastStateStates) { + Either, StorageOperationStatus> products = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.PRODUCT); if (products.isLeft()) { - Map> result = new HashMap>(); + Map> result = new HashMap<>(); result.put("products", products.left().value()); return Either.left(result); } else { @@ -1031,10 +1049,9 @@ public class ElementBusinessLogic extends BaseBusinessLogic { } Either, StorageOperationStatus> result = getFilteredComponents(filters, assetTypeEnum, false); - - if (result.isRight()) {// category hierarchy mismatch or - // category/subCategory/distributionStatus not - // found + + // category hierarchy mismatch or category/subCategory/distributionStatus not found + if (result.isRight()) { List params = getErrorResponseParams(filters, assetTypeEnum); return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value()), params.get(0), params.get(1), params.get(2))); } @@ -1046,7 +1063,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { } private Either, StorageOperationStatus> getFilteredComponents(Map filters, ComponentTypeEnum assetType, boolean inTransaction) { - Either, StorageOperationStatus> assetResult = null; + Either, StorageOperationStatus> assetResult = Either.left(new LinkedList<>()); if(assetType == ComponentTypeEnum.RESOURCE){ assetResult = getFilteredResouces(filters, inTransaction); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java index c3471e46e1..f545548b95 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java @@ -20,16 +20,14 @@ package org.openecomp.sdc.be.components.impl; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.Map.Entry; import java.util.function.BiConsumer; import java.util.stream.Collectors; +import jline.internal.Log; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.json.simple.JSONObject; import org.openecomp.sdc.be.components.validation.ComponentValidations; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -77,13 +75,15 @@ public class InputsBusinessLogic extends BaseBusinessLogic { private static final String GET_INPUT = "get_input"; + private static final short LOOP_PROTECTION_LEVEL = 10 ; + private static String ASSOCIATING_INPUT_TO_PROP = "AssociatingInputToComponentInstanceProperty"; - private Gson gson = new Gson(); - + private Gson gson = new Gson(); + /** * associate inputs to a given component with paging - * + * * @param componentId * @param userId * @param fromId @@ -97,10 +97,10 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if (resp.isRight()) { return Either.right(resp.right().value()); } - - + + ComponentParametersView filters = new ComponentParametersView(); - filters.disableAll(); + filters.disableAll(); filters.setIgnoreInputs(false); Either getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters); @@ -108,15 +108,15 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); - + } org.openecomp.sdc.be.model.Component component = getComponentEither.left().value(); List inputs = component.getInputs(); - + return Either.left(inputs); } - + public Either, ResponseFormat> getComponentInstanceInputs(String userId, String componentId, String componentInstanceId) { Either resp = validateUserExists(userId, "get Inputs", false); @@ -124,10 +124,10 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if (resp.isRight()) { return Either.right(resp.right().value()); } - - + + ComponentParametersView filters = new ComponentParametersView(); - filters.disableAll(); + filters.disableAll(); filters.setIgnoreInputs(false); filters.setIgnoreComponentInstances(false); filters.setIgnoreComponentInstancesInputs(false); @@ -137,7 +137,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); - + } org.openecomp.sdc.be.model.Component component = getComponentEither.left().value(); @@ -152,7 +152,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { /** * associate properties to a given component instance input - * + * * @param instanceId * @param userId * @param inputId @@ -169,58 +169,58 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ComponentParametersView filters = new ComponentParametersView(); filters.disableAll(); filters.setIgnoreComponentInstances(false); - + if(!instanceId.equals(inputId)){ - - + + Either getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters); - + if(getComponentEither.isRight()){ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); - + } component = getComponentEither.left().value(); Optional ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(instanceId)).findAny(); if(ciOp.isPresent()){ parentId = ciOp.get().getComponentUid(); } - - } - - filters.setIgnoreInputs(false); - + + } + + filters.setIgnoreInputs(false); + filters.setIgnoreComponentInstancesProperties(false); filters.setIgnoreComponentInstancesInputs(false); filters.setIgnoreProperties(false); - + Either getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters); - + if(getComponentEither.isRight()){ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); - + } component = getComponentEither.left().value(); - + Optional op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst(); if(!op.isPresent()){ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug("Failed to found input {} under component {}, error: {}", inputId, parentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); } - + return Either.left(getComponentInstancePropertiesByInputId(component, inputId)); } - + public Either updateInputValue(ComponentTypeEnum componentType, String componentId, InputDefinition input, String userId, boolean shouldLockComp, boolean inTransaction) { - + Either result = null; org.openecomp.sdc.be.model.Component component = null; - + try { Either resp = validateUserExists(userId, "get input", false); @@ -232,7 +232,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ComponentParametersView componentParametersView = new ComponentParametersView(); componentParametersView.disableAll(); - componentParametersView.setIgnoreInputs(false); + componentParametersView.setIgnoreInputs(false); componentParametersView.setIgnoreUsers(false); Either validateComponent = validateComponentExists(componentId, componentType, componentParametersView); @@ -264,7 +264,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } Map dataTypes = allDataTypes.left().value(); - + Optional op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(input.getUniqueId())).findFirst(); if(!op.isPresent()){ ActionStatus actionStatus = ActionStatus.COMPONENT_NOT_FOUND; @@ -273,7 +273,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return result; } InputDefinition currentInput = op.get(); - + String innerType = null; String propertyType = currentInput.getType(); ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType); @@ -293,7 +293,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { innerType = propDef.getType(); } // Specific Update Logic - + Either isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, input.getDefaultValue(), true, innerType, allDataTypes.left().value()); String newValue = currentInput.getDefaultValue(); @@ -308,23 +308,23 @@ public class InputsBusinessLogic extends BaseBusinessLogic { newValue = object.toString(); } } - + currentInput.setDefaultValue(newValue); - + Either status = toscaOperationFacade.updateInputOfComponent(component, currentInput); - + if(status.isRight()){ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status.right().value()); result = Either.right(componentsUtils.getResponseFormat(actionStatus, "")); return result; } - - + + result = Either.left(status.left().value()); - + return result; - - + + }finally { if (false == inTransaction) { @@ -357,28 +357,28 @@ public class InputsBusinessLogic extends BaseBusinessLogic { org.openecomp.sdc.be.model.Component component = null; ComponentParametersView filters = new ComponentParametersView(); filters.disableAll(); - filters.setIgnoreComponentInstances(false); - filters.setIgnoreInputs(false); + filters.setIgnoreComponentInstances(false); + filters.setIgnoreInputs(false); filters.setIgnoreComponentInstancesInputs(false); filters.setIgnoreProperties(false); - + Either getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters); - + if(getComponentEither.isRight()){ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); - + } component = getComponentEither.left().value(); - + Optional op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst(); if(!op.isPresent()){ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug("Failed to found input {} under component {}, error: {}", inputId, parentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); } - + return Either.left(getComponentInstanceInputsByInputId(component, inputId)); } @@ -387,11 +387,11 @@ public class InputsBusinessLogic extends BaseBusinessLogic { Either, ResponseFormat> result = null; org.openecomp.sdc.be.model.Component component = null; - + Map> inputsValueToCreateMap = new HashMap<>(); - Map> propertiesToCreateMap = new HashMap<>(); + Map> propertiesToCreateMap = new HashMap<>(); Map inputsToCreate = new HashMap<>(); - + try { Either resp = validateUserExists(userId, "get Properties by input", false); @@ -441,7 +441,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ////////////////////////////////////////////////////////////////////////////////////////////////////// - + List resList = new ArrayList(); Map> newInputsMap = componentInstInputsMapUi.getComponentInstanceInputsMap(); List ciList = component.getComponentInstances(); @@ -450,7 +450,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { for (Entry> entry : newInputsMap.entrySet()) { List inputsValueToCreate = new ArrayList<>(); String compInstId = entry.getKey(); - + Optional op = ciList.stream().filter(ci -> ci.getUniqueId().equals(compInstId)).findAny(); if(!op.isPresent()){ ActionStatus actionStatus = ActionStatus.INVALID_CONTENT; @@ -468,12 +468,12 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return result; } org.openecomp.sdc.be.model.Component origComponent = origComponentEither.left().value(); - + List inputs = entry.getValue(); if (inputs != null && !inputs.isEmpty()) { - - for (InputDefinition input : inputs) { + + for (InputDefinition input : inputs) { StorageOperationStatus status = addInputsToComponent(componentId, inputsToCreate, allDataTypes.left().value(), resList, index, inputsValueToCreate, compInstId, compInstname, origComponent, input); if(status != StorageOperationStatus.OK ){ @@ -489,51 +489,51 @@ public class InputsBusinessLogic extends BaseBusinessLogic { inputsValueToCreateMap.put(compInstId, inputsValueToCreate); } } - + } - + Map> newInputsPropsMap = componentInstInputsMapUi.getComponentInstanceProperties(); if (newInputsPropsMap != null && !newInputsPropsMap.isEmpty()) { - + result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, dataTypes, resList, newInputsPropsMap); - + if (result.isRight()) { log.debug("Failed to create inputs of resource for id {} error {}", component.getUniqueId(), result.right().value()); return result; } resList = result.left().value(); - + } - - + + Either, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.addInputsToComponent(inputsToCreate, component.getUniqueId()); if(assotiateInputsEither.isRight()){ log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value()); result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value()))); return result; } - + Either>, StorageOperationStatus> assotiatePropsEither = toscaOperationFacade.addComponentInstancePropertiesToComponent(component, propertiesToCreateMap, component.getUniqueId()); if(assotiatePropsEither.isRight()){ log.debug("Failed to add inputs values under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value()); result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value()))); return result; } - + Either>, StorageOperationStatus> addciInputsEither = toscaOperationFacade.addComponentInstanceInputsToComponent(component, inputsValueToCreateMap); if(addciInputsEither.isRight()){ log.debug("Failed to add inputs values under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value()); result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value()))); return result; } - - - - + + + + result = Either.left(resList); return result; - /////////////////////////////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////////////////////////////// + } finally { if (false == inTransaction) { @@ -558,29 +558,29 @@ public class InputsBusinessLogic extends BaseBusinessLogic { private StorageOperationStatus addInputsToComponent(String componentId, Map inputsToCreate, Map allDataTypes, List resList, int index, List inputsValueToCreate, String compInstId, String compInstname, org.openecomp.sdc.be.model.Component origComponent, InputDefinition input) { - + Either, ResponseFormat> result; String innerType = null; InputDefinition oldInput = origComponent.getInputs().stream().filter(ciIn -> ciIn.getUniqueId().equals(input.getUniqueId())).findAny().get(); String serviceInputName = compInstname + "_" + input.getName(); input.setName(serviceInputName); - + JSONObject jobject = new JSONObject(); jobject.put(GET_INPUT, input.getName()); - + ComponentInstanceInput inputValue = new ComponentInstanceInput(oldInput, jobject.toJSONString(), null); - + Either validatevalueEiter = validateInputValueBeforeCreate(inputValue, jobject.toJSONString(), false, innerType, allDataTypes); - if (validatevalueEiter.isRight()) { - + if (validatevalueEiter.isRight()) { + return validatevalueEiter.right().value(); - } - - String uniqueId = UniqueIdBuilder.buildResourceInstanceInputValueUid(compInstId, index++); + } + + String uniqueId = UniqueIdBuilder.buildResourceInstanceInputValueUid(compInstId, index++); inputValue.setUniqueId(uniqueId); inputValue.setValue(validatevalueEiter.left().value()); - - + + input.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(componentId, input.getName())); input.setSchema(oldInput.getSchema()); input.setDefaultValue(oldInput.getDefaultValue()); @@ -592,20 +592,21 @@ public class InputsBusinessLogic extends BaseBusinessLogic { input.setRequired(oldInput.isRequired()); input.setOwnerId(null); input.setParentUniqueId(null); + input.setInstanceUniqueId(compInstId); inputsToCreate.put(input.getName(), input); - - - + + + List getInputValues = new ArrayList<>(); GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); getInputValueDataDefinition.setInputId(input.getUniqueId()); getInputValueDataDefinition.setInputName(input.getName()); getInputValues.add(getInputValueDataDefinition); - inputValue.setGetInputValues(getInputValues); - + inputValue.setGetInputValues(getInputValues); + inputsValueToCreate.add(inputValue); input.setInputs(inputsValueToCreate); - + resList.add(input); return StorageOperationStatus.OK; } @@ -685,11 +686,11 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } public Either, ResponseFormat> createInputsInGraph(Map inputs, org.openecomp.sdc.be.model.Component component, User user, boolean inTransaction) { - - List resList = inputs.values().stream().collect(Collectors.toList()); + + List resList = inputs.values().stream().collect(Collectors.toList()); Either, ResponseFormat> result = Either.left(resList); List resourceProperties = component.getInputs(); - + if(inputs != null && !inputs.isEmpty()){ Either, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache); if (allDataTypes.isRight()) { @@ -697,16 +698,16 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } Map dataTypes = allDataTypes.left().value(); - + for (Map.Entry inputDefinition : inputs.entrySet()) { String inputName = inputDefinition.getKey(); - inputDefinition.getValue().setName(inputName); - + inputDefinition.getValue().setName(inputName); + Either preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes); if(preparedInputEither.isRight()){ return Either.right(preparedInputEither.right().value()); } - + } if (resourceProperties != null) { Map generatedInputs = resourceProperties.stream().collect(Collectors.toMap(i -> i.getName(), i -> i)); @@ -716,28 +717,104 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } inputs = mergeEither.left().value(); } - + Either, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId()); if(assotiateInputsEither.isRight()){ log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value()); return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value()))); } result = Either.left(assotiateInputsEither.left().value()); - + } - - + + return result; } + + /* Mutates the object + * Tail recurse -> traverse the tosca elements and remove nested empty map properties + * this only handles nested maps, other objects are left untouched (even a Set containing a map) since behaviour is unexpected + * + * @param toscaElement - expected map of tosca values + * @return mutated @param toscaElement , where empty maps are deleted , return null for empty map. + **/ + private Object cleanEmptyNestedValuesInMap(Object toscaElement , short loopProtectionLevel ){ + //region - Stop if map is empty + if (loopProtectionLevel<=0 || toscaElement==null || !(toscaElement instanceof Map)) + return toscaElement; + //endregion + //region - Remove empty map entries & return null iff empty map + if ( MapUtils.isNotEmpty( (Map)toscaElement ) ) { + Object ret; + Set keysToRemove = new HashSet<>(); // use different set to avoid ConcurrentModificationException + for( Object key : ((Map)toscaElement).keySet() ) { + Object value = ((Map) toscaElement).get(key); + ret = cleanEmptyNestedValuesInMap(value , --loopProtectionLevel ); + if ( ret == null ) + keysToRemove.add(key); + } + Collection set = ((Map) toscaElement).keySet(); + if (CollectionUtils.isNotEmpty(set)) + set.removeAll(keysToRemove); + + if ( isEmptyNestedMap(toscaElement) ) // similar to < if ( MapUtils.isEmpty( (Map)toscaElement ) ) > ,but adds nested map check + return null; + } + //endregion + else + return null; + return toscaElement; + } + + //@returns true iff map nested maps are all empty + //ignores other collection objects + private boolean isEmptyNestedMap(Object element){ + boolean isEmpty = true; + if (element != null){ + if ( element instanceof Map ){ + if (MapUtils.isEmpty((Map)element)) + isEmpty = true; + else + { + for( Object key : ((Map)(element)).keySet() ){ + Object value = ((Map)(element)).get(key); + isEmpty &= isEmptyNestedMap( value ); + } + } + } else { + isEmpty = false; + } + } + return isEmpty; + } + + public Either cleanNestedMap( Map mappedToscaTemplate , boolean deepClone ){ + if (MapUtils.isNotEmpty( mappedToscaTemplate ) ){ + if (deepClone){ + if (!(mappedToscaTemplate instanceof HashMap)) + return Either.right("expecting mappedToscaTemplate as HashMap ,recieved "+ mappedToscaTemplate.getClass().getSimpleName() ); + else + mappedToscaTemplate = (HashMap)((HashMap) mappedToscaTemplate).clone(); + } + return Either.left( (Map) cleanEmptyNestedValuesInMap( mappedToscaTemplate , InputsBusinessLogic.LOOP_PROTECTION_LEVEL ) ); + } + else { + log.debug("mappedToscaTemplate is empty "); + return Either.right("mappedToscaTemplate is empty "); + } + } + + + /** * Delete input from service - * + * * @param componentType * @param inputId * @param component * @param user - * + * * @return */ public Either deleteInput(String componentType, String componentId, String userId, String inputId) { @@ -762,7 +839,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { componentParametersView.setIgnoreComponentInstancesInputs(false); componentParametersView.setIgnoreComponentInstancesProperties(false); componentParametersView.setIgnoreUsers(false); - + Either componentEither = toscaOperationFacade.getToscaElement(componentId, componentParametersView); if (componentEither.isRight()) { deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentEither.right().value()))); @@ -779,7 +856,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if (!optionalInput.isPresent()) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId)); } - + InputDefinition inputForDelete = optionalInput.get(); // Lock component @@ -798,11 +875,11 @@ public class InputsBusinessLogic extends BaseBusinessLogic { deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName())); return deleteEither; } - + List inputsValue= getComponentInstanceInputsByInputId(component, inputId); Map> insInputsMatToDelete = new HashMap<>(); - - if(inputsValue != null && !inputsValue.isEmpty()){ + + if(inputsValue != null && !inputsValue.isEmpty()){ for(ComponentInstanceInput inputValue: inputsValue){ List inputList = null; String ciId = inputValue.getComponentInstanceId(); @@ -821,22 +898,29 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return deleteEither; } } - + // US848813 delete service input that relates to VL / CP property - + List propertiesValue = getComponentInstancePropertiesByInputId(component, inputId); if(propertiesValue != null && !propertiesValue.isEmpty()){ - //propertyList = propertyValueStatus.left().value(); + //propertyList = propertyValueStatus.left().value(); for(ComponentInstanceProperty propertyValue: propertiesValue){ - + String value = propertyValue.getValue(); Map mappedToscaTemplate = (Map) new Yaml().load(value); - + resetInputName(mappedToscaTemplate, inputForDelete.getName()); - + value = ""; - if(!mappedToscaTemplate.isEmpty()) - value = gson.toJson(mappedToscaTemplate); + if(!mappedToscaTemplate.isEmpty()){ + Either result = cleanNestedMap(mappedToscaTemplate , true); + Map modifiedMappedToscaTemplate = mappedToscaTemplate; + if (result.isLeft()) + modifiedMappedToscaTemplate = (Map)result.left().value(); + else + Log.warn("Map cleanup failed -> " +result.right().value().toString()); //continue, don't break operation + value = gson.toJson(modifiedMappedToscaTemplate); + } propertyValue.setValue(value); String compInstId = propertyValue.getComponentInstanceId(); propertyValue.setRules(null); @@ -857,7 +941,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if (findDefaultValue.isRight()) { deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(findDefaultValue.right().value())))); return deleteEither; - + } String defaultValue = findDefaultValue.left().value(); propertyValue.setDefaultValue(defaultValue); @@ -868,10 +952,10 @@ public class InputsBusinessLogic extends BaseBusinessLogic { deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName())); return deleteEither; } - + } } - + deleteEither = Either.left(inputForDelete); return deleteEither; @@ -888,7 +972,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } private Either prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition, Map dataTypes) { - + // validate input default values Either defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition, dataTypes); @@ -918,7 +1002,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } return Either.left(newInputDefinition); } - + public boolean isInputExist(List inputs, String resourceUid, String inputName) { if (inputs == null) { @@ -937,18 +1021,18 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return false; } - - + + public Either getInputsAndPropertiesForComponentInput(String userId, String componentId, String inputId, boolean inTransaction) { Either result = null; try { - + Either resp = validateUserExists(userId, "get Properties by input", false); if (resp.isRight()) { return Either.right(resp.right().value()); } Either, StorageOperationStatus> propertiesEitherRes = null; - + ComponentParametersView filters = new ComponentParametersView(); filters.disableAll(); filters.setIgnoreComponentInstances(false); @@ -961,7 +1045,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); - + } org.openecomp.sdc.be.model.Component component = getComponentEither.left().value(); Optional op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst(); @@ -970,18 +1054,18 @@ public class InputsBusinessLogic extends BaseBusinessLogic { log.debug("Failed to found input {} under component {}, error: {}", inputId, componentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); } - + InputDefinition resObj = op.get(); - + List inputCIInput = getComponentInstanceInputsByInputId(component, inputId) ; - + resObj.setInputs(inputCIInput); - - + + List inputProps = getComponentInstancePropertiesByInputId(component, inputId) ; - - resObj.setProperties(inputProps); - + + resObj.setProperties(inputProps); + result = Either.left(resObj); @@ -1004,7 +1088,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } } - + private List getComponentInstancePropertiesByInputId(org.openecomp.sdc.be.model.Component component, String inputId){ List resList = new ArrayList<>(); Map> ciPropertiesMap = component.getComponentInstancesProperties(); @@ -1029,7 +1113,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } } } - + } } } @@ -1038,7 +1122,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return resList; } - + private List getComponentInstanceInputsByInputId(org.openecomp.sdc.be.model.Component component, String inputId){ List resList = new ArrayList<>(); Map> ciInputsMap = component.getComponentInstancesInputs(); @@ -1063,7 +1147,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } } } - + } } } @@ -1072,11 +1156,11 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return resList; } - + private Either getOriginComponent(ComponentInstance ci, Map origComponentMap){ Either result = null; String compInstname = ci.getNormalizedName(); - + ComponentParametersView componentParametersView = new ComponentParametersView(); componentParametersView.disableAll(); componentParametersView.setIgnoreInputs(false); @@ -1096,9 +1180,9 @@ public class InputsBusinessLogic extends BaseBusinessLogic { result = Either.left(origComponent); return result; } - - - + + + private Either, ResponseFormat> createInputsFromProperty(org.openecomp.sdc.be.model.Component component, Map origComponentMap, Map inputsToCreate, Map> propertiesToCreateMap, Map dataTypes, List resList, Map> newInputsPropsMap) { List ciList = component.getComponentInstances(); String componentId = component.getUniqueId(); @@ -1106,13 +1190,13 @@ public class InputsBusinessLogic extends BaseBusinessLogic { List propertiesToCreate = new ArrayList<>(); String compInstId = entry.getKey(); List properties = entry.getValue(); - + Optional op = ciList.stream().filter(ci -> ci.getUniqueId().equals(compInstId)).findAny(); if(!op.isPresent()){ ActionStatus actionStatus = ActionStatus.INVALID_CONTENT; log.debug("Failed to find component instance {} under component {}", compInstId, componentId); return Either.right(componentsUtils.getResponseFormat(actionStatus)); - + } ComponentInstance ci = op.get(); String compInstname = ci.getNormalizedName(); @@ -1121,33 +1205,34 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(origComponentEither.right().value()); log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name()); return Either.right(componentsUtils.getResponseFormat(actionStatus)); - + } org.openecomp.sdc.be.model.Component origComponent = origComponentEither.left().value(); - + //String originType = (String) titanGenericDao.getProperty(originVertex, GraphPropertiesDictionary.LABEL.getProperty()); - + String inputName = compInstname; - + if (properties != null && !properties.isEmpty()) { for (ComponentInstancePropInput propInput : properties) { propInput.setOwnerId(null); propInput.setParentUniqueId(null); + Either createInputRes = createInputForComponentInstance(component, origComponent,ci, inputsToCreate, propertiesToCreate, dataTypes, inputName, propInput); - + if (createInputRes.isRight()) { log.debug("Failed to create input of resource instance for id {} error {}", compInstId, createInputRes.right().value()); return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(createInputRes.right().value()))); - + } - + resList.add(createInputRes.left().value()); - + } propertiesToCreateMap.put(compInstId, propertiesToCreate); } - + } return Either.left(resList); } @@ -1156,7 +1241,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { String propertiesName = propInput.getPropertiesName() ; PropertyDefinition selectedProp = propInput.getInput(); String[] parsedPropNames = propInput.getParsedPropNames(); - + if(parsedPropNames != null){ for(String str: parsedPropNames){ inputName += "_" + str; @@ -1164,89 +1249,103 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } else { inputName += "_" + propInput.getName(); } - + InputDefinition input = null; - ComponentInstanceProperty prop = propInput; - + ComponentInstanceProperty prop = propInput; + + if(CollectionUtils.isNotEmpty(propertiesToCreate)){ + Optional propOpt = propertiesToCreate.stream().filter(p -> p.getName().equals(propInput.getName())).findFirst(); + if(propOpt.isPresent()){ + prop = propOpt.get(); + } + } + boolean complexProperty = false; if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){ + complexProperty = true; input = new InputDefinition(selectedProp); }else{ input = new InputDefinition(prop); input.setName(inputName + "_" + prop.getName()); - + } - input.setName(inputName); + input.setName(inputName); input.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(component.getUniqueId(), input.getName())); input.setInputPath(propertiesName); - + input.setInstanceUniqueId(ci.getUniqueId()); + input.setPropertyId(propInput.getUniqueId()); + JSONObject jobject = new JSONObject(); - - + + if(prop.getValue() == null || prop.getValue().isEmpty()){ - if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){ - - jobject = createJSONValueForProperty(parsedPropNames.length -1, parsedPropNames, jobject, inputName); - prop.setValue(jobject.toJSONString()); - + if(complexProperty){ + + jobject = createJSONValueForProperty(parsedPropNames.length -1, parsedPropNames, jobject, inputName); + prop.setValue(jobject.toJSONString()); + }else{ - + jobject.put(GET_INPUT, input.getName()); - prop.setValue(jobject.toJSONString()); - + prop.setValue(jobject.toJSONString()); + } - + }else{ - - String value = prop.getValue(); + + String value = prop.getValue(); Object objValue = new Yaml().load(value); if( objValue instanceof Map || objValue instanceof List ){ - if(propertiesName == null ||propertiesName.isEmpty()){ + if(!complexProperty){ jobject.put(GET_INPUT, input.getName()); prop.setValue(jobject.toJSONString()); prop.setRules(null); - + }else{ Map mappedToscaTemplate = (Map) objValue; createInputValue(mappedToscaTemplate, 1, parsedPropNames, inputName); - - String json = gson.toJson(mappedToscaTemplate); + + String json = gson.toJson(mappedToscaTemplate); prop.setValue(json); prop.setRules(null); } - + }else{ jobject.put(GET_INPUT, input.getName()); prop.setValue(jobject.toJSONString()); prop.setRules(null); } - + } prop.setComponentInstanceId(ci.getUniqueId()); prop.setComponentInstanceName(ci.getName()); - - List getInputValues = new ArrayList<>(); + + if(CollectionUtils.isEmpty(prop.getGetInputValues())){ + prop.setGetInputValues(new ArrayList<>()); + } + List getInputValues = prop.getGetInputValues(); + GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); getInputValueDataDefinition.setInputId(input.getUniqueId()); getInputValueDataDefinition.setInputName(input.getName()); getInputValues.add(getInputValueDataDefinition); - prop.setGetInputValues(getInputValues); - - propertiesToCreate.add(prop); - + + if(!propertiesToCreate.contains(prop)){ + propertiesToCreate.add(prop); + } + inputsToCreate.put(input.getName(), input); - List propertiesList = new ArrayList<>(); // adding the property with the new value for UI propertiesList.add(prop); input.setProperties(propertiesList); - + return Either.left(input); - + } - + private JSONObject createJSONValueForProperty (int i, String [] parsedPropNames, JSONObject ooj, String inputName){ - + while(i >= 1){ - if( i == parsedPropNames.length -1){ + if( i == parsedPropNames.length -1){ JSONObject jobProp = new JSONObject(); jobProp.put(GET_INPUT, inputName); ooj.put(parsedPropNames[i], jobProp); @@ -1260,17 +1359,17 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return res; } } - + return ooj; } - + public void resetInputName(Map lhm1, String inputName){ for (Map.Entry entry : lhm1.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof String && ((String) value).equalsIgnoreCase(inputName) && key.equals(GET_INPUT)) { value = ""; - lhm1.remove(key); + lhm1.remove(key); } else if (value instanceof Map) { Map subMap = (Map)value; resetInputName(subMap, inputName); @@ -1280,7 +1379,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } } - + private Map createInputValue(Map lhm1, int index, String[] inputNames, String inputName){ while(index < inputNames.length){ if(lhm1.containsKey(inputNames[index])){ @@ -1289,7 +1388,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if(index == inputNames.length -1){ ((Map) value).put(GET_INPUT, inputName); return ((Map) value); - + }else{ index++; return createInputValue((Map)value, index, inputNames, inputName); @@ -1299,14 +1398,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if(index == inputNames.length -1){ jobProp.put(GET_INPUT, inputName); lhm1.put(inputNames[index], jobProp); - return lhm1; - }else{ + return lhm1; + }else{ lhm1.put(inputNames[index], jobProp); index++; return createInputValue(jobProp, index, inputNames, inputName); } } - }else{ + }else{ Map jobProp = new HashMap<>(); lhm1.put(inputNames[index], jobProp); if(index == inputNames.length -1){ 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 d3492f8f40..cc4a6d9c71 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 @@ -44,6 +44,7 @@ import java.util.stream.Collectors; 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.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; @@ -2364,6 +2365,21 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { for (ArtifactDefinition artToDelete : listToDelete) { findArtifactToDelete(parsedGroup, artifactsToDelete, groupListEntry.getKey().getUniqueId(), artToDelete, createdDeplymentArtifacts); } + if(artifactsToDelete != null && !artifactsToDelete.isEmpty()){ + GroupDefinition group = groupListEntry.getKey(); + for(ArtifactDefinition artifactDefinition: artifactsToDelete){ + if (CollectionUtils.isNotEmpty(group.getArtifacts()) && group.getArtifacts().contains(artifactDefinition.getUniqueId())) { + group.getArtifacts().remove(artifactDefinition.getUniqueId()); + + } + if (CollectionUtils.isNotEmpty(group.getArtifactsUuid()) && group.getArtifactsUuid().contains(artifactDefinition.getArtifactUUID())) { + group.getArtifactsUuid().remove(artifactDefinition.getArtifactUUID()); + + } + } + + } + for (ArtifactTemplateInfo jsonMasterArtifact : jsonMasterArtifacts) { if (maserArtifact.getArtifactName().equalsIgnoreCase(jsonMasterArtifact.getFileName())) { MergedArtifactInfo mergedGroup = new MergedArtifactInfo(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java index 948968e367..8c0041af9a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java @@ -31,6 +31,7 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -51,13 +52,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.jcabi.aspects.Loggable; + +import fj.data.Either; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -import fj.data.Either; - /** * This Servlet serves external users to download artifacts. * @@ -76,18 +78,43 @@ public class DistributionCatalogServlet extends BeGenericServlet { // ******************************************************* // Download (GET) artifacts // **********************************************************/ - + /** + * + * @param request + * @param requestId + * @param instanceIdHeader + * @param accept + * @param authorization + * @param serviceName + * @param serviceVersion + * @param artifactName + * @return + */ @GET @Path("/services/{serviceName}/{serviceVersion}/artifacts/{artifactName}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_OCTET_STREAM) - @ApiOperation(value = "Download service artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), - @ApiResponse(code = 404, message = "Artifact not found") }) - public Response downloadServiceArtifact(@PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion, @PathParam("artifactName") final String artifactName, - @Context final HttpServletRequest request) { + @ApiOperation(value = "Download service artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = String.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "The artifact is found and streamed.", response = String.class), + @ApiResponse(code = 400, message = "Missing “X-ECOMP-InstanceID” HTTP header - POL5001"), + @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"), + @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), + @ApiResponse(code = 404, message = "Specified Service is not found - SVC4503"), + @ApiResponse(code = 404, message = "Specified Service Version is not found - SVC4504"), + @ApiResponse(code = 404, message = "Specified artifact is not found - SVC4505"), + @ApiResponse(code = 405, message = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"), + @ApiResponse(code = 500, message = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000")}) + public Response downloadServiceArtifact(@Context final HttpServletRequest request, + @ApiParam(value = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @ApiParam(value = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader, + @ApiParam(value = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept, + @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + @PathParam("serviceName") final String serviceName, + @PathParam("serviceVersion") final String serviceVersion, + @PathParam("artifactName") final String artifactName) { + Response response = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); AuditingActionEnum auditingActionEnum = AuditingActionEnum.DISTRIBUTION_ARTIFACT_DOWNLOAD; EnumMap additionalParam = new EnumMap(AuditingFieldsKeysEnum.class); @@ -128,18 +155,49 @@ public class DistributionCatalogServlet extends BeGenericServlet { return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } - + + /** + * + * @param request + * @param requestId + * @param instanceIdHeader + * @param accept + * @param authorization + * @param serviceName + * @param serviceVersion + * @param resourceName + * @param resourceVersion + * @param artifactName + * @return + */ @GET @Path("/services/{serviceName}/{serviceVersion}/resources/{resourceName}/{resourceVersion}/artifacts/{artifactName}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_OCTET_STREAM) - @ApiOperation(value = "Download resource artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), - @ApiResponse(code = 404, message = "Artifact not found") }) - public Response downloadResourceArtifact(@PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion, @PathParam("resourceName") final String resourceName, - @PathParam("resourceVersion") final String resourceVersion, @PathParam("artifactName") final String artifactName, @Context final HttpServletRequest request) { + @ApiOperation(value = "Download resource artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = String.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "The artifact is found and streamed.", response = String.class), + @ApiResponse(code = 400, message = "Missing “X-ECOMP-InstanceID” HTTP header - POL5001"), + @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"), + @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), + @ApiResponse(code = 404, message = "Specified Service is not found - SVC4503"), + @ApiResponse(code = 404, message = "Specified Resource Instance is not found - SVC4526"), + @ApiResponse(code = 404, message = "Specified Service Version is not found - SVC4504"), + @ApiResponse(code = 404, message = "Specified artifact is not found - SVC4505"), + @ApiResponse(code = 405, message = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"), + @ApiResponse(code = 500, message = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000")}) + public Response downloadResourceArtifact(@Context final HttpServletRequest request, + @ApiParam(value = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @ApiParam(value = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader, + @ApiParam(value = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept, + @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + @PathParam("serviceName") final String serviceName, + @PathParam("serviceVersion") final String serviceVersion, + @PathParam("resourceName") final String resourceName, + @PathParam("resourceVersion") final String resourceVersion, + @PathParam("artifactName") final String artifactName) { + Response response = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); AuditingActionEnum auditingActionEnum = AuditingActionEnum.DISTRIBUTION_ARTIFACT_DOWNLOAD; EnumMap additionalParam = new EnumMap(AuditingFieldsKeysEnum.class); @@ -181,22 +239,49 @@ public class DistributionCatalogServlet extends BeGenericServlet { } } - // -------------------------------- - + /** + * + * @param request + * @param requestId + * @param instanceIdHeader + * @param accept + * @param authorization + * @param serviceName + * @param serviceVersion + * @param resourceInstanceName + * @param artifactName + * @return + */ @GET @Path("/services/{serviceName}/{serviceVersion}/resourceInstances/{resourceInstanceName}/artifacts/{artifactName}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_OCTET_STREAM) - @ApiOperation(value = "Download resource artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), - @ApiResponse(code = 404, message = "Artifact not found") }) - public Response downloadResourceInstanceArtifact(@PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion, @PathParam("resourceInstanceName") final String resourceInstanceName, - @PathParam("artifactName") final String artifactName, @Context final HttpServletRequest request) { + @ApiOperation(value = "Download resource instance artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = String.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "The artifact is found and streamed.", response = String.class), + @ApiResponse(code = 400, message = "Missing “X-ECOMP-InstanceID” HTTP header - POL5001"), + @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"), + @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), + @ApiResponse(code = 404, message = "Specified Service is not found - SVC4503"), + @ApiResponse(code = 404, message = "Specified Resource Instance is not found - SVC4526"), + @ApiResponse(code = 404, message = "Specified Service Version is not found - SVC4504"), + @ApiResponse(code = 404, message = "Specified artifact is not found - SVC4505"), + @ApiResponse(code = 405, message = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"), + @ApiResponse(code = 500, message = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000")}) + public Response downloadResourceInstanceArtifact(@Context final HttpServletRequest request, + @ApiParam(value = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @ApiParam(value = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader, + @ApiParam(value = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept, + @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + @PathParam("serviceName") final String serviceName, + @PathParam("serviceVersion") final String serviceVersion, + @PathParam("resourceInstanceName") final String resourceInstanceName, + @PathParam("artifactName") final String artifactName) { + Response response = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); AuditingActionEnum auditingActionEnum = AuditingActionEnum.DISTRIBUTION_ARTIFACT_DOWNLOAD; - EnumMap additionalParam = new EnumMap(AuditingFieldsKeysEnum.class); + EnumMap additionalParam = new EnumMap<>(AuditingFieldsKeysEnum.class); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, instanceIdHeader); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, requestURI); @@ -234,6 +319,4 @@ public class DistributionCatalogServlet extends BeGenericServlet { return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } - - // -------------------------------- } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java index 8a7aa73e6a..532cc1767b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java @@ -40,6 +40,8 @@ import org.openecomp.sdc.be.distribution.AuditHandler; import org.openecomp.sdc.be.distribution.DistributionBusinessLogic; import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest; import org.openecomp.sdc.be.distribution.api.client.ServerListResponse; +import org.openecomp.sdc.be.distribution.api.client.TopicRegistrationResponse; +import org.openecomp.sdc.be.distribution.api.client.TopicUnregistrationResponse; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; @@ -55,12 +57,16 @@ import org.slf4j.LoggerFactory; import org.springframework.web.context.WebApplicationContext; import com.jcabi.aspects.Loggable; + +import fj.data.Either; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; - -import fj.data.Either; +import io.swagger.annotations.ResponseHeader; /** * This Servlet serves external users for distribution purposes. @@ -78,26 +84,51 @@ public class DistributionServlet extends BeGenericServlet { private static Logger log = LoggerFactory.getLogger(DistributionServlet.class.getName()); @Resource private DistributionBusinessLogic distributionLogic; - + + /** + * + * @param request + * @param requestId + * @param instanceId + * @param accept + * @param authorization + * @return + */ @GET @Path("/distributionUebCluster") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "UEB Server List", httpMethod = "GET", notes = "return the available UEB Server List", response = String.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "UEB server list fetched successfully"), @ApiResponse(code = 500, message = "One or more BE components (Titan, ES, BE) are down") }) - public Response getUebServerList(@Context final HttpServletRequest request, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, - @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, @HeaderParam(value = Constants.ACCEPT_HEADER) String accept) { + @ApiOperation(value = "UEB Server List", httpMethod = "GET", notes = "return the available UEB Server List", + //TODO Tal G fix response headers + responseHeaders = { + @ResponseHeader(name = Constants.CONTENT_TYPE_HEADER, description = "Determines the format of the response body", response = String.class), + @ResponseHeader(name = "Content-Length", description = "Length of the response body", response = String.class)}) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "ECOMP component is authenticated and list of Cambria API server’s FQDNs is returned", response = ServerListResponse.class), + @ApiResponse(code = 400, message = "Missing “X-ECOMP-InstanceID” HTTP header - POL5001"), + @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its credentials for Basic Authentication - POL5002"), + @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), + @ApiResponse(code = 405, message = "Method Not Allowed: Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"), + @ApiResponse(code = 500, message = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000")}) + public Response getUebServerList(@Context final HttpServletRequest request, + @ApiParam(value = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @ApiParam(value = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, + @ApiParam(value = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept, + @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization) { + init(request); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); Response response = null; ResponseFormat responseFormat = null; + if (instanceId == null) { responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID); response = buildErrorResponse(responseFormat); getComponentsUtils().auditMissingInstanceId(AuditingActionEnum.GET_UEB_CLUSTER, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage()); return response; } + try { Either actionResponse = distributionLogic.getUebServerList(); @@ -123,49 +154,45 @@ public class DistributionServlet extends BeGenericServlet { } } - + /** - * Returns list of valid artifact types for validation done in the distribution client.
- * The list is the representation of the values of the enum ArtifactTypeEnum. * * @param request - * @param instanceId * @param requestId - * @param authorization + * @param instanceId * @param accept + * @param contenType + * @param contenLength + * @param authorization + * @param requestJson * @return */ - @GET - @Path("/artifactTypes") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Artifact types list", httpMethod = "GET", notes = "Fetches available artifact types list", response = String.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact types list fetched successfully"), @ApiResponse(code = 500, message = "One or more BE components (Titan, ES, BE) are down") }) - public Response getValidArtifactTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, - @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, @HeaderParam(value = Constants.ACCEPT_HEADER) String accept) { - init(request); - String url = request.getMethod() + " " + request.getRequestURI(); - log.debug("Start handle request of {}", url); - Response response = null; - - Wrapper responseWrapper = new Wrapper<>(); - - validateHeaders(responseWrapper, request, AuditingActionEnum.GET_VALID_ARTIFACT_TYPES); - if (responseWrapper.isEmpty()) { - response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), ArtifactTypeEnum.values()); - } else { - response = responseWrapper.getInnerElement(); - } - return response; - } - @POST @Path("/registerForDistribution") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Subscription status", httpMethod = "POST", notes = "Subscribes for distribution notifications", response = String.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "Subscribed for distribution notifications successfull"), @ApiResponse(code = 500, message = "One or more BE components (Titan, ES, BE) are down") }) - public Response registerForDistribution(@Context final HttpServletRequest request, String requestJson) { + @ApiOperation(value = "Subscription status", httpMethod = "POST", notes = "Subscribes for distribution notifications") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "ECOMP component is successfully registered for distribution", response = TopicRegistrationResponse.class), + @ApiResponse(code = 400, message = "Missing “X-ECOMP-InstanceID” HTTP header - POL5001"), + @ApiResponse(code = 400, message = "Missing Body - POL4500"), + @ApiResponse(code = 400, message = "Invalid Body : missing mandatory parameter “apiPublicKey” - POL4501"), + @ApiResponse(code = 400, message = "Invalid Body : missing mandatory parameter “distrEnvName” - POL4502"), + @ApiResponse(code = 400, message = "Invalid Body : Specified “distrEnvName” doesn’t exist - POL4137"), + @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"), + @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), + @ApiResponse(code = 405, message = "Method Not Allowed : Invalid HTTP method type used to register for distribution ( PUT,DELETE,GET will be rejected) - POL4050"), + @ApiResponse(code = 500, message = "The registration failed due to internal SDC problem or Cambria Service failure ECOMP Component should continue the attempts to register for distribution - POL5000")}) + //TODO Tal G fix response headers and to check missing header validations with Michael L + @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.distribution.api.client.RegistrationRequest", paramType = "body", value = "json describe the artifact")}) + public Response registerForDistribution(@Context final HttpServletRequest request, + @ApiParam(value = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @ApiParam(value = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, + @ApiParam(value = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept, + @ApiParam(value = "Determines the format of the body of the request", required = true)@HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contenType, + @ApiParam(value = "Length of the request body", required = true)@HeaderParam(value = Constants.CONTENT_LENGTH_HEADER) String contenLength, + @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + String requestJson) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); init(request); @@ -191,14 +218,86 @@ public class DistributionServlet extends BeGenericServlet { return responseWrapper.getInnerElement(); } + + /** + * Returns list of valid artifact types for validation done in the distribution client.
+ * The list is the representation of the values of the enum ArtifactTypeEnum. + * + * @param request + * @param requestId + * @param instanceId + * @param authorization + * @param accept + * @return + */ + //TODO Get the missing AID for this API + @GET + @Path("/artifactTypes") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Artifact types list", httpMethod = "GET", notes = "Fetches available artifact types list", response = String.class) + @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact types list fetched successfully"), @ApiResponse(code = 500, message = "One or more BE components (Titan, ES, BE) are down") }) + public Response getValidArtifactTypes(@Context final HttpServletRequest request, + @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, + @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + @HeaderParam(value = Constants.ACCEPT_HEADER) String accept) { + init(request); + String url = request.getMethod() + " " + request.getRequestURI(); + log.debug("Start handle request of {}", url); + Response response = null; + + Wrapper responseWrapper = new Wrapper<>(); + validateHeaders(responseWrapper, request, AuditingActionEnum.GET_VALID_ARTIFACT_TYPES); + if (responseWrapper.isEmpty()) { + response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), ArtifactTypeEnum.values()); + } else { + response = responseWrapper.getInnerElement(); + } + return response; + } + + /** + * Removes from subscription for distribution notifications + * + * @param request + * @param requestId + * @param instanceId + * @param accept + * @param contenType + * @param contenLength + * @param authorization + * @param requestJson + * @return + */ @POST @Path("/unRegisterForDistribution") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Subscription status", httpMethod = "POST", notes = "Removes from subscription for distribution notifications", response = String.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "Successfully removed from subscription for distribution notifications"), @ApiResponse(code = 500, message = "One or more BE components (Titan, ES, BE) are down") }) - public Response unRegisterForDistribution(@Context final HttpServletRequest request, String requestJson) { + @ApiOperation(value = "Subscription status", httpMethod = "POST", notes = "Removes from subscription for distribution notifications") + //TODO Edit the responses + @ApiResponses(value = { + @ApiResponse(code = 204, message = "ECOMP component is successfully unregistered", response = TopicUnregistrationResponse.class), + @ApiResponse(code = 400, message = "Missing “X-ECOMP-InstanceID” HTTP header - POL5001"), + @ApiResponse(code = 400, message = "Missing Body - POL4500"), + @ApiResponse(code = 400, message = "Invalid Body : missing mandatory parameter “apiPublicKey” - POL4501"), + @ApiResponse(code = 400, message = "Invalid Body : missing mandatory parameter “distrEnvName” - SVC4506"), + @ApiResponse(code = 400, message = "Invalid Body : Specified “distrEnvName” doesn’t exist - POL4137"), + @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"), + @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), + @ApiResponse(code = 405, message = "Method Not Allowed : Invalid HTTP method type used to register for distribution ( PUT,DELETE,GET will be rejected) - POL4050"), + @ApiResponse(code = 500, message = "The registration failed due to internal SDC problem or Cambria Service failure ECOMP Component should continue the attempts to register for distribution - POL5000")}) + @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.distribution.api.client.RegistrationRequest", paramType = "body", value = "json describe the artifact")}) + public Response unRegisterForDistribution(@Context final HttpServletRequest request, + @ApiParam(value = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @ApiParam(value = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, + @ApiParam(value = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept, + @ApiParam(value = "Determines the format of the body of the request", required = true)@HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contenType, + @ApiParam(value = "Length of the request body", required = true)@HeaderParam(value = Constants.CONTENT_LENGTH_HEADER) String contenLength, + @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + String requestJson) { + String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); init(request); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java index bcd2fe8138..fea300a8bb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java @@ -31,6 +31,7 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -96,13 +97,12 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiOperation(value = "uploads of artifact to a resource or service", httpMethod = "POST", notes = "uploads of artifact to a resource or service", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact uploaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") }) - public Response uploadArtifact(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @ApiParam(value = "json describe the artifact", required = true) String data) { + public Response uploadArtifact(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @ApiParam(value = "json describe the artifact", required = true) String data, + @HeaderParam(value = Constants.USER_ID_HEADER) final String userId, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { init(log); Wrapper responseWrapper = new Wrapper<>(); - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); - String userId = request.getHeader(Constants.USER_ID_HEADER); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); @@ -166,13 +166,12 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact uploaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") }) public Response uploadArtifactToInstance(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName, - @ApiParam(value = "json describe the artifact", required = true) String data) { + @ApiParam(value = "json describe the artifact", required = true) String data, + @HeaderParam(value = Constants.USER_ID_HEADER) final String userId, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { Wrapper responseWrapper = new Wrapper<>(); ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); - String userId = request.getHeader(Constants.USER_ID_HEADER); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); @@ -238,13 +237,12 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact Updated"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") }) public Response updateArtifact(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("artifactUUID") final String artifactUUID, - @ApiParam(value = "json describe the artifact", required = true) String data) { + @ApiParam(value = "json describe the artifact", required = true) String data, + @HeaderParam(value = Constants.USER_ID_HEADER) final String userId, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { Wrapper responseWrapper = new Wrapper<>(); ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); - String userId = request.getHeader(Constants.USER_ID_HEADER); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); @@ -311,13 +309,12 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact Updated"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") }) public Response updateArtifactOnResourceInstance(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName, - @PathParam("artifactUUID") final String artifactUUID, @ApiParam(value = "json describe the artifact", required = true) String data) { + @PathParam("artifactUUID") final String artifactUUID, @ApiParam(value = "json describe the artifact", required = true) String data, + @HeaderParam(value = Constants.USER_ID_HEADER) final String userId, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { Wrapper responseWrapper = new Wrapper<>(); ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); - String userId = request.getHeader(Constants.USER_ID_HEADER); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); @@ -383,12 +380,11 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiOperation(value = "deletes an artifact of a resource or service", httpMethod = "DELETE", notes = "deletes an artifact of a resource or service", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact Deleted"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") }) - public Response deleteArtifact(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("artifactUUID") final String artifactUUID) { + public Response deleteArtifact(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("artifactUUID") final String artifactUUID, + @HeaderParam(value = Constants.USER_ID_HEADER) final String userId, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { Wrapper responseWrapper = new Wrapper<>(); ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); - String userId = request.getHeader(Constants.USER_ID_HEADER); String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); @@ -455,12 +451,11 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact Deleted"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") }) public Response deleteArtifactOnResourceInstance(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName, - @PathParam("artifactUUID") final String artifactUUID) { + @PathParam("artifactUUID") final String artifactUUID, + @HeaderParam(value = Constants.USER_ID_HEADER) final String userId, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { Wrapper responseWrapper = new Wrapper<>(); ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); - String userId = request.getHeader(Constants.USER_ID_HEADER); String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); @@ -529,11 +524,11 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiResponse(code = 404, message = "Artifact not found") }) public Response downloadComponentArtifact( @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("assetType") final String assetType, - @PathParam("uuid") final String uuid, @PathParam("artifactUUID") final String artifactUUID) { + @PathParam("uuid") final String uuid, @PathParam("artifactUUID") final String artifactUUID, + @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { Wrapper responseWrapper = new Wrapper<>(); ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); @@ -596,11 +591,11 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiResponse(code = 404, message = "Artifact not found") }) public Response downloadResourceInstanceArtifact( @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("assetType") final String assetType, - @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName, @PathParam("artifactUUID") final String artifactUUID) { + @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName, @PathParam("artifactUUID") final String artifactUUID, + @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { Wrapper responseWrapper = new Wrapper<>(); ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java index 27c3b409e2..2c1ef925c8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java @@ -68,6 +68,7 @@ import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.distribution.api.client.TopicRegistrationResponse; import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter; import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata; import org.openecomp.sdc.be.model.Component; @@ -117,19 +118,41 @@ public class AssetsDataServlet extends AbstractValidationsServlet { private HttpServletRequest request; private static Logger log = LoggerFactory.getLogger(AssetsDataServlet.class.getName()); - + + /** + * + * @param assetType + * @param category + * @param subCategory + * @param distributionStatus + * @param resourceType + * @param instanceIdHeader + * @return + */ @GET @Path("/{assetType}") @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Fetch list of assets", httpMethod = "GET", notes = "Returns list of assets", response = Response.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "Assets Fetched"), @ApiResponse(code = 400, message = "Invalid content / Missing content"), @ApiResponse(code = 401, message = "Authorization required"), - @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") }) - public Response getAssetList(@PathParam("assetType") final String assetType, @QueryParam("category") String category, @QueryParam("subCategory") String subCategory, @QueryParam("distributionStatus") String distributionStatus, - @QueryParam("resourceType") String resourceType) { + @ApiOperation(value = "Fetch list of assets", httpMethod = "GET", notes = "Returns list of assets", response = AssetMetadata.class, responseContainer="List") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned", response = AssetMetadata.class, responseContainer="List"), + @ApiResponse(code = 400, message = "Missing “X-ECOMP-InstanceID” HTTP header - POL5001"), + @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"), + @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), + @ApiResponse(code = 405, message = "Method Not Allowed : Invalid HTTP method type used to register for distribution (PUT,DELETE,POST will be rejected) - POL4050"), + @ApiResponse(code = 500, message = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")}) + public Response getAssetList( + @ApiParam(value = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @ApiParam(value = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader, + @ApiParam(value = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept, + @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + @ApiParam(value = "The requested asset type", required = true, allowableValues = "resources, services")@PathParam("assetType") final String assetType, + @ApiParam(value = "The filter key (resourceType only for resources)", required = false)@QueryParam("category") String category, + @ApiParam(value = "The filter key (resourceType only for resources)", required = false)@QueryParam("subCategory") String subCategory, + @ApiParam(value = "The filter key (resourceType only for resources)", required = false)@QueryParam("distributionStatus") String distributionStatus, + @ApiParam(value = "The filter key (resourceType only for resources)", required = false)@QueryParam("resourceType") String resourceType) { Response response = null; ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); String query = request.getQueryString(); String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; @@ -205,18 +228,26 @@ public class AssetsDataServlet extends AbstractValidationsServlet { return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } - + + /** + * + * @param assetType + * @param uuid + * @param request + * @param instanceIdHeader + * @return + */ @GET @Path("/{assetType}/{uuid}/metadata") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch metadata of asset by uuid", httpMethod = "GET", notes = "Returns metadata of asset", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Assets Fetched"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") }) - public Response getAssetListByUuid(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @Context final HttpServletRequest request) { + public Response getAssetListByUuid(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @Context final HttpServletRequest request, + @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { Response response = null; ResponseFormat responseFormat = null; - String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_ASSET_METADATA; String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; @@ -273,7 +304,15 @@ public class AssetsDataServlet extends AbstractValidationsServlet { return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } - + + /** + * + * @param uuid + * @param assetType + * @param authorization + * @param instanceIdHeader + * @return + */ @GET @Path("/{assetType}/{uuid}/toscaModel") @Produces(MediaType.APPLICATION_OCTET_STREAM) @@ -282,7 +321,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { @ApiResponse(code = 404, message = "Asset not found") }) public Response getToscaModel(@PathParam("uuid") final String uuid, @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("assetType") final String assetType, - @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization) { + @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { String url = request.getRequestURI(); log.debug("Start handle request of {} {}", request.getMethod(), url); @@ -291,14 +330,13 @@ public class AssetsDataServlet extends AbstractValidationsServlet { ServletContext context = request.getSession().getServletContext(); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_TOSCA_MODEL; - String userId = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER); EnumMap additionalParam = new EnumMap(AuditingFieldsKeysEnum.class); - additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, userId); + additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, instanceIdHeader); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, url); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, componentType.getValue()); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, uuid); - if (userId == null || userId.isEmpty()) { + if (instanceIdHeader == null || instanceIdHeader.isEmpty()) { log.debug("getToscaModel: Missing X-ECOMP-InstanceID header"); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID); getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam); @@ -341,6 +379,8 @@ public class AssetsDataServlet extends AbstractValidationsServlet { * * @param assetType * @param data + * @param userId + * @param instanceIdHeader * @return */ @POST @@ -353,12 +393,15 @@ public class AssetsDataServlet extends AbstractValidationsServlet { @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 201, message = "Resource created"), @ApiResponse(code = 400, message = "Invalid content / Missing content"), @ApiResponse(code = 409, message = "Resource already exist") }) - public Response createResource(@PathParam("assetType") final String assetType, @ApiParam(value = "json describe the artifact", required = true) String data) { + public Response createResource(@PathParam("assetType") final String assetType, + @ApiParam(value = "json describe the artifact", required = true) String data, + @HeaderParam(value = Constants.USER_ID_HEADER) final String userId, + @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader) { + init(log); Wrapper responseWrapper = new Wrapper<>(); String requestURI = request.getRequestURI(); - String userId = request.getHeader(Constants.USER_ID_HEADER); String url = request.getMethod() + " " + requestURI; log.debug("Start handle request of {}", url); Resource resource = null; @@ -369,8 +412,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { try { // Validate X-ECOMP-InstanceID Header if (responseWrapper.isEmpty()) { - validateXECOMPInstanceIDHeader(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), - responseWrapper); + validateXECOMPInstanceIDHeader(instanceIdHeader, responseWrapper); } // Validate USER_ID Header if (responseWrapper.isEmpty()) { @@ -457,7 +499,123 @@ public class AssetsDataServlet extends AbstractValidationsServlet { additionalParams); } } - + + /** + * Changing the lifecycle of an asset + * @param jsonChangeInfo The description - request body + * @param assetType The requested asset type.Valid values are: resources / services (for VFCMT – use "resources") + * @param uuid The uuid of the desired resource to be changed + * @param lifecycleTransition The lifecycle operation to be performed on the asset.Valid values are:Checkin / Checkout / CERTIFICATION_REQUEST + * @param userId + * @return + */ + @POST + @Path("/{assetType}/{uuid}/lifecycleState/{lifecycleOperation}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Change Resource lifecycle State", httpMethod = "POST", response = Response.class) + @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource state changed"), @ApiResponse(code = 403, message = "Asset is already checked-out by another user")}) + public Response changeResourceState(@ApiParam(value = "LifecycleChangeInfo - relevant for checkin", required = false) String jsonChangeInfo, + @ApiParam(value = "validValues: resources / services ", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam(value = "assetType") final String assetType, + @ApiParam(value = "id of component to be changed") @PathParam(value = "uuid") final String uuid, + @ApiParam(allowableValues = "checkout, checkin", required = true) @PathParam(value = "lifecycleOperation") final String lifecycleTransition, + @HeaderParam(value = Constants.USER_ID_HEADER) final String userId) { + + Response response = null; + EnumMap additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class); + + init(log); + + String requestURI = request.getRequestURI(); + String url = request.getMethod() + " " + requestURI; + log.debug("Start handle request of {}", url); + + //get the business logic + ServletContext context = request.getSession().getServletContext(); + LifecycleBusinessLogic businessLogic = getLifecycleBL(context); + + Wrapper responseWrapper = runValidations(assetType); + ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); + Component component = null; + Component responseObject = null; + User modifier = null; + + try{ + if (responseWrapper.isEmpty()) { + //get user + Either eitherGetUser = getUser(request, userId); + if (eitherGetUser.isRight()) { + ResponseFormat responseFormat = eitherGetUser.right().value(); + responseWrapper.setInnerElement(responseFormat); + return buildErrorResponse(responseFormat); + } + modifier = eitherGetUser.left().value(); + + //get the component id from the uuid + Either latestVersion = businessLogic.getLatestComponentByUuid(componentType, uuid); + if (latestVersion.isRight()) { + ResponseFormat responseFormat = latestVersion.right().value(); + responseWrapper.setInnerElement(responseFormat); + return buildErrorResponse(responseFormat); + } + component = latestVersion.left().value(); + String componentId = component.getUniqueId(); + + //validate the transition is valid + Either validateEnum = validateTransitionEnum(lifecycleTransition, modifier); + if (validateEnum.isRight()) { + ResponseFormat responseFormat = validateEnum.right().value(); + responseWrapper.setInnerElement(responseFormat); + return buildErrorResponse(responseFormat); + } + LifeCycleTransitionEnum transitionEnum = validateEnum.left().value(); + + //create changeInfo + LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction(); + try { + if (jsonChangeInfo != null && !jsonChangeInfo.isEmpty()) { + ObjectMapper mapper = new ObjectMapper(); + changeInfo = new LifecycleChangeInfoWithAction(mapper.readValue(jsonChangeInfo, LifecycleChangeInfoBase.class).getUserRemarks()); + } + } + catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject"); + BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject"); + log.debug("failed to convert from json {}", jsonChangeInfo, e); + ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorAndAudit(modifier, AuditingActionEnum.CHECKOUT_RESOURCE); + responseWrapper.setInnerElement(responseFormat); + return buildErrorResponse(responseFormat); + } + + //execute business logic + Either actionResponse = businessLogic.changeComponentState(componentType, componentId, modifier, transitionEnum, changeInfo, false, true); + if (actionResponse.isRight()) { + log.info("failed to change resource state"); + ResponseFormat responseFormat = actionResponse.right().value(); + responseWrapper.setInnerElement(responseFormat); + return buildErrorResponse(responseFormat); + } + + log.debug("change state successful !!!"); + responseObject = actionResponse.left().value(); + response = buildCreatedResourceResponse(responseObject, context, responseWrapper); + } else { + response = buildErrorResponse(responseWrapper.getInnerElement()); + } + + return response; + } catch (Exception e) { + BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Change Lifecycle State"); + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Change Lifecycle State"); + log.debug("change lifecycle state failed with exception", e); + ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR); + responseWrapper.setInnerElement(responseFormat); + return buildErrorResponse(responseFormat); + } finally{ + auditChnageLifecycleAction(additionalParams, responseWrapper, componentType, component, responseObject, modifier, userId); + } + } + private void prepareAdditionalAudit(Resource resource, EnumMap additionalParams) { additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION, StringUtils.EMPTY); additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_STATE, StringUtils.EMPTY); @@ -489,14 +647,12 @@ public class AssetsDataServlet extends AbstractValidationsServlet { responseFormat = resMetadata.right().value(); responseWrapper.setInnerElement(responseFormat); response = buildErrorResponse(responseFormat); - } - else{ + }else{ final AssetMetadata assetData = resMetadata.left().value(); assetData.setToscaModelURL(null); responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.CREATED)); Object representation = RepresentationUtils.toRepresentation(assetData); - responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), representation); } return response; @@ -575,119 +731,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { } - /** - * Changing the lifecycle of an asset - * @param jsonChangeInfo The description - request body - * @param assetType The requested asset type.Valid values are: resources / services (for VFCMT – use "resources") - * @param uuid The uuid of the desired resource to be changed - * @param lifecycleTransition The lifecycle operation to be performed on the asset.Valid values are:Checkin / Checkout / CERTIFICATION_REQUEST - * @return - */ - @POST - @Path("/{assetType}/{uuid}/lifecycleState/{lifecycleOperation}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Change Resource lifecycle State", httpMethod = "POST", response = Response.class) - @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource state changed"), @ApiResponse(code = 403, message = "Asset is already checked-out by another user")}) - public Response changeResourceState(@ApiParam(value = "LifecycleChangeInfo - relevant for checkin", required = false) String jsonChangeInfo, - @ApiParam(value = "validValues: resources / services ", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam(value = "assetType") final String assetType, - @ApiParam(value = "id of component to be changed") @PathParam(value = "uuid") final String uuid, - @ApiParam(allowableValues = "checkout, checkin", required = true) @PathParam(value = "lifecycleOperation") final String lifecycleTransition) { - Response response = null; - EnumMap additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class); - - init(log); - - String requestURI = request.getRequestURI(); - String url = request.getMethod() + " " + requestURI; - log.debug("Start handle request of {}", url); - - //get the business logic - ServletContext context = request.getSession().getServletContext(); - LifecycleBusinessLogic businessLogic = getLifecycleBL(context); - - Wrapper responseWrapper = runValidations(assetType); - ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); - Component component = null; - Component responseObject = null; - User modifier = null; - String userId = request.getHeader(Constants.USER_ID_HEADER); - - try{ - if (responseWrapper.isEmpty()) { - //get user - Either eitherGetUser = getUser(request, userId); - if (eitherGetUser.isRight()) { - ResponseFormat responseFormat = eitherGetUser.right().value(); - responseWrapper.setInnerElement(responseFormat); - return buildErrorResponse(responseFormat); - } - modifier = eitherGetUser.left().value(); - - //get the component id from the uuid - Either latestVersion = businessLogic.getLatestComponentByUuid(componentType, uuid); - if (latestVersion.isRight()) { - ResponseFormat responseFormat = latestVersion.right().value(); - responseWrapper.setInnerElement(responseFormat); - return buildErrorResponse(responseFormat); - } - component = latestVersion.left().value(); - String componentId = component.getUniqueId(); - - //validate the transition is valid - Either validateEnum = validateTransitionEnum(lifecycleTransition, modifier); - if (validateEnum.isRight()) { - ResponseFormat responseFormat = validateEnum.right().value(); - responseWrapper.setInnerElement(responseFormat); - return buildErrorResponse(responseFormat); - } - LifeCycleTransitionEnum transitionEnum = validateEnum.left().value(); - - //create changeInfo - LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction(); - try { - if (jsonChangeInfo != null && !jsonChangeInfo.isEmpty()) { - ObjectMapper mapper = new ObjectMapper(); - changeInfo = new LifecycleChangeInfoWithAction(mapper.readValue(jsonChangeInfo, LifecycleChangeInfoBase.class).getUserRemarks()); - } - } - catch (Exception e) { - BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject"); - BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject"); - log.debug("failed to convert from json {}", jsonChangeInfo, e); - ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorAndAudit(modifier, AuditingActionEnum.CHECKOUT_RESOURCE); - responseWrapper.setInnerElement(responseFormat); - return buildErrorResponse(responseFormat); - } - - //execute business logic - Either actionResponse = businessLogic.changeComponentState(componentType, componentId, modifier, transitionEnum, changeInfo, false, true); - if (actionResponse.isRight()) { - log.info("failed to change resource state"); - ResponseFormat responseFormat = actionResponse.right().value(); - responseWrapper.setInnerElement(responseFormat); - return buildErrorResponse(responseFormat); - } - - log.debug("change state successful !!!"); - responseObject = actionResponse.left().value(); - response = buildCreatedResourceResponse(responseObject, context, responseWrapper); - } else { - response = buildErrorResponse(responseWrapper.getInnerElement()); - } - - return response; - } catch (Exception e) { - BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Change Lifecycle State"); - BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Change Lifecycle State"); - log.debug("change lifecycle state failed with exception", e); - ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR); - responseWrapper.setInnerElement(responseFormat); - return buildErrorResponse(responseFormat); - } finally{ - auditChnageLifecycleAction(additionalParams, responseWrapper, componentType, component, responseObject, modifier, userId); - } - } + private void auditChnageLifecycleAction(EnumMap additionalParams, Wrapper responseWrapper, ComponentTypeEnum componentType, Component component, @@ -756,7 +800,6 @@ public class AssetsDataServlet extends AbstractValidationsServlet { return responseWrapper; } - private Either validateTransitionEnum(final String lifecycleTransition, User user) { LifeCycleTransitionEnum transitionEnum = LifeCycleTransitionEnum.CHECKOUT; try { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java index c1d74b5d85..15b3eb20c6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java @@ -66,7 +66,15 @@ import fj.data.Either; public class AdditionalInformationServlet extends BeGenericServlet { private static Logger log = LoggerFactory.getLogger(AdditionalInformationServlet.class.getName()); - + + /** + * + * @param resourceId + * @param data + * @param request + * @param userUserId + * @return + */ @POST @Path("/resources/{resourceId}/additionalinfo") @Consumes(MediaType.APPLICATION_JSON) @@ -80,7 +88,15 @@ public class AdditionalInformationServlet extends BeGenericServlet { return createAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, request, userUserId, data); } - + + /** + * + * @param serviceId + * @param data + * @param request + * @param userUserId + * @return + */ @POST @Path("/services/{serviceId}/additionalinfo") @Consumes(MediaType.APPLICATION_JSON) @@ -94,7 +110,16 @@ public class AdditionalInformationServlet extends BeGenericServlet { return createAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, request, userUserId, data); } - + + /** + * + * @param resourceId + * @param labelId + * @param data + * @param request + * @param userId + * @return + */ @PUT @Path("/resources/{resourceId}/additionalinfo/{labelId}") @Consumes(MediaType.APPLICATION_JSON) @@ -109,7 +134,16 @@ public class AdditionalInformationServlet extends BeGenericServlet { return updateAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, labelId, request, userId, data); } - + + /** + * + * @param serviceId + * @param labelId + * @param data + * @param request + * @param userId + * @return + */ @PUT @Path("/services/{serviceId}/additionalinfo/{labelId}") @Consumes(MediaType.APPLICATION_JSON) @@ -124,7 +158,15 @@ public class AdditionalInformationServlet extends BeGenericServlet { return updateAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, labelId, request, userId, data); } - + + /** + * + * @param resourceId + * @param labelId + * @param request + * @param userId + * @return + */ @DELETE @Path("/resources/{resourceId}/additionalinfo/{labelId}") @Consumes(MediaType.APPLICATION_JSON) @@ -138,7 +180,15 @@ public class AdditionalInformationServlet extends BeGenericServlet { return deleteAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, labelId, request, userId); } - + + /** + * + * @param serviceId + * @param labelId + * @param request + * @param userId + * @return + */ @DELETE @Path("/services/{serviceId}/additionalinfo/{labelId}") @Consumes(MediaType.APPLICATION_JSON) @@ -152,7 +202,15 @@ public class AdditionalInformationServlet extends BeGenericServlet { return deleteAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, labelId, request, userId); } - + + /** + * + * @param resourceId + * @param labelId + * @param request + * @param userId + * @return + */ @GET @Path("/resources/{resourceId}/additionalinfo/{labelId}") @Consumes(MediaType.APPLICATION_JSON) @@ -166,7 +224,15 @@ public class AdditionalInformationServlet extends BeGenericServlet { return getAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, labelId, request, userId); } - + + /** + * + * @param serviceId + * @param labelId + * @param request + * @param userId + * @return + */ @GET @Path("/services/{serviceId}/additionalinfo/{labelId}") @Consumes(MediaType.APPLICATION_JSON) @@ -180,7 +246,14 @@ public class AdditionalInformationServlet extends BeGenericServlet { return getAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, labelId, request, userId); } - + + /** + * + * @param resourceId + * @param request + * @param userId + * @return + */ @GET @Path("/resources/{resourceId}/additionalinfo") @Consumes(MediaType.APPLICATION_JSON) @@ -194,7 +267,14 @@ public class AdditionalInformationServlet extends BeGenericServlet { return getAllAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, request, userId); } - + + /** + * + * @param serviceId + * @param request + * @param userId + * @return + */ @GET @Path("/services/{serviceId}/additionalinfo") @Consumes(MediaType.APPLICATION_JSON) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java index 48a45ac04c..9bf4b681bd 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java @@ -110,6 +110,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { try { ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class); + componentInstance.setInvariantName(null); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum); if (componentInstanceLogic == null) { diff --git a/catalog-be/src/main/webapp/WEB-INF/web.xml b/catalog-be/src/main/webapp/WEB-INF/web.xml index fe228a3f97..b559d1b80f 100644 --- a/catalog-be/src/main/webapp/WEB-INF/web.xml +++ b/catalog-be/src/main/webapp/WEB-INF/web.xml @@ -130,7 +130,7 @@ swagger.api.basepath - http://localhost:8080/sdc/ + http://localhost:8080/sdc @@ -139,24 +139,6 @@ 2 - - - @@ -165,13 +147,6 @@ 3 true - - - - ViewStatusMessages @@ -190,7 +165,7 @@ true methods - GET,POST + GET,POST,PUT,DELETE mimeTypes diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java index d6808da5d6..4251749f5a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java @@ -101,7 +101,7 @@ public class AssetsDataServletTest extends JerseyTest { when(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER)).thenReturn("mockXEcompInstanceId"); when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn("mockAttID"); when(request.getRequestURL()).thenReturn(new StringBuffer("sdc/v1/catalog/resources")); - + when(session.getServletContext()).thenReturn(servletContext); when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper); when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext); @@ -159,7 +159,8 @@ public class AssetsDataServletTest extends JerseyTest { @Test public void createVfcmtHappyScenario() { final JSONObject createRequest = buildCreateJsonRequest(); - Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).post(Entity.json(createRequest.toJSONString()), Response.class); + Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).header(Constants.X_ECOMP_INSTANCE_ID_HEADER, "mockXEcompInstanceId").header(Constants.USER_ID_HEADER, "mockAttID") + .post(Entity.json(createRequest.toJSONString()), Response.class); assertTrue(response.getStatus() == HttpStatus.SC_CREATED); } diff --git a/catalog-fe/src/main/webapp/WEB-INF/web.xml b/catalog-fe/src/main/webapp/WEB-INF/web.xml index c2127dcdca..ac2e3bcdea 100644 --- a/catalog-fe/src/main/webapp/WEB-INF/web.xml +++ b/catalog-fe/src/main/webapp/WEB-INF/web.xml @@ -79,27 +79,31 @@ /kibanaProxy/* - + org.openecomp.sdc.fe.listen.FEAppContextListener diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInput.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInput.java index 9347f326d1..abcac352cc 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInput.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInput.java @@ -38,8 +38,6 @@ public class ComponentInstanceInput extends InputDefinition implements IComponen */ private String valueUniqueUid; - private String inputId; - private List path = null; private List rules = null; @@ -53,7 +51,7 @@ public class ComponentInstanceInput extends InputDefinition implements IComponen public ComponentInstanceInput(PropertyDataDefinition curPropertyDef, String inputId, String value, String valueUniqueUid) { super(curPropertyDef); - this.inputId = inputId; + setInputId(inputId); setValue(value); this.valueUniqueUid = valueUniqueUid; } @@ -68,7 +66,7 @@ public class ComponentInstanceInput extends InputDefinition implements IComponen public ComponentInstanceInput(PropertyDataDefinition propertyDefinition) { super(propertyDefinition); if(propertyDefinition.getGetInputValues() != null && !propertyDefinition.getGetInputValues().isEmpty()){ - this.inputId = propertyDefinition.getGetInputValues().get(0).getInputId(); + setInputId(propertyDefinition.getGetInputValues().get(0).getInputId()); } } @@ -88,14 +86,6 @@ public class ComponentInstanceInput extends InputDefinition implements IComponen this.componentInstanceId = componentInstanceId; } - public String getInputId() { - return inputId; - } - - public void setInputId(String inputId) { - this.inputId = inputId; - } - public String getValueUniqueUid() { return valueUniqueUid; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstanceProperty.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstanceProperty.java index e1e51729e0..683a2f2428 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstanceProperty.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstanceProperty.java @@ -48,6 +48,7 @@ public class GroupInstanceProperty extends GroupProperty { public GroupInstanceProperty(PropertyDataDefinition propertyDataDefinition) { super(propertyDataDefinition); + parentValue = getDefaultValue(); } public String getParentValue() { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java index 4d9ec8c2fe..224697246d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -98,7 +99,7 @@ public class ArtifactsOperations extends BaseOperation { ArtifactDataDefinition foundArtifact = null; if (componentType != null && componentType == ComponentTypeEnum.RESOURCE_INSTANCE) { foundArtifact = getInstanceArtifactByLabelAndId(parentId, id, containerId, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); - if ( foundArtifact == null ){ + if (foundArtifact == null) { foundArtifact = getInstanceArtifactByLabelAndId(parentId, id, containerId, EdgeLabelEnum.INSTANCE_ARTIFACTS); } } @@ -217,14 +218,14 @@ public class ArtifactsOperations extends BaseOperation { oldVesrion = "0"; String currentChecksum = artifactData.getArtifactChecksum(); - - if ( isUpdate ){ + + if (isUpdate) { ArtifactTypeEnum type = ArtifactTypeEnum.findType(artifactData.getArtifactType()); - switch ( type ){ - case HEAT_ENV: - if ( edgeLabel == EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS ){ + switch (type) { + case HEAT_ENV: + if (edgeLabel == EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS) { generateUUID(artifactData, oldVesrion); - }else{ + } else { updateVersionAndDate(artifactData, oldVesrion); } break; @@ -243,7 +244,7 @@ public class ArtifactsOperations extends BaseOperation { } break; } - }else{ + } else { if (oldChecksum == null || oldChecksum.isEmpty()) { if (currentChecksum != null) { generateUUID(artifactData, oldVesrion); @@ -287,7 +288,7 @@ public class ArtifactsOperations extends BaseOperation { } Map artifacts = artifactsEither.left().value(); - List envList = artifacts.values().stream().filter(a -> a.getGeneratedFromId()!= null && a.getGeneratedFromId().equals(artifactId)).collect(Collectors.toList()); + List envList = artifacts.values().stream().filter(a -> a.getGeneratedFromId() != null && a.getGeneratedFromId().equals(artifactId)).collect(Collectors.toList()); if (envList != null && !envList.isEmpty()) { envList.forEach(a -> { a.setGeneratedFromId(newArtifactId); @@ -366,7 +367,7 @@ public class ArtifactsOperations extends BaseOperation { Map artMap = null; Map artifactDataMap = null; - + if (edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) { Either, TitanOperationStatus> resultEither = getDataFromGraph(parentId, edgeLabelEnum); if (resultEither.isRight()) { @@ -374,7 +375,7 @@ public class ArtifactsOperations extends BaseOperation { return Either.right(resultEither.right().value()); } artifactDataMap = resultEither.left().value(); - }else{ + } else { Either, TitanOperationStatus> resultEither = getDataFromGraph(parentId, edgeLabelEnum); if (resultEither.isRight()) { log.debug("failed to fetch {} for tosca element with id {}, error {}", edgeLabelEnum, parentId, resultEither.right().value()); @@ -382,13 +383,13 @@ public class ArtifactsOperations extends BaseOperation { } Map mapArtifacts = resultEither.left().value(); MapArtifactDataDefinition artifactPerInstance = mapArtifacts.get(instanceId); - if ( artifactPerInstance != null ){ + if (artifactPerInstance != null) { artifactDataMap = artifactPerInstance.getMapToscaDataDefinition(); } } if (artifactDataMap != null && !artifactDataMap.isEmpty()) { artMap = artifactDataMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> convertArtifactDataToArtifactDefinition(null, e.getValue()))); - }else{ + } else { artMap = new HashMap<>(); } return Either.left(artMap); @@ -462,26 +463,28 @@ public class ArtifactsOperations extends BaseOperation { uniqueId = UniqueIdBuilder.buildPropertyUniqueId(instanceId, artifactToUpdate.getArtifactLabel()); } artifactToUpdate.setUniqueId(uniqueId); - + artifactToUpdate.setEsId(uniqueId); } else artifactToUpdate.setUniqueId(artifactId); - Map artifacts = null; + Map artifacts = new HashMap<>(); + Map artifactInst = null; if (edgeLabelEnum != EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS && edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) { Either, TitanOperationStatus> artifactsEither = this.getDataFromGraph(componentId, edgeLabelEnum); if (artifactsEither.isLeft() && artifactsEither.left().value() != null && !artifactsEither.left().value().isEmpty()) { artifacts = artifactsEither.left().value(); - if (isNeedToClone) { + if (isNeedToClone && artifacts != null) { artifacts.values().stream().forEach(a -> a.setDuplicated(Boolean.TRUE)); } } } else { + Either, TitanOperationStatus> artifactsEither = this.getDataFromGraph(componentId, edgeLabelEnum); if (artifactsEither.isLeft()) { - Map artifactInst = artifactsEither.left().value(); - if (isNeedToClone) { + artifactInst = artifactsEither.left().value(); + if (isNeedToClone && artifactInst != null) { artifactInst.values().forEach(ma -> ma.getMapToscaDataDefinition().values().forEach(a -> a.setDuplicated(Boolean.TRUE))); } MapArtifactDataDefinition artifatcsOnInstance = artifactInst.get(instanceId); @@ -496,6 +499,9 @@ public class ArtifactsOperations extends BaseOperation { ArtifactDataDefinition oldArtifactData = artifacts.get(artifactInfo.getArtifactLabel()); oldChecksum = oldArtifactData.getArtifactChecksum(); oldVersion = oldArtifactData.getArtifactVersion(); + //duplicated flag didn't receive from UI, take from DB + artifactToUpdate.setDuplicated(oldArtifactData.getDuplicated()); + if (isNeedToClone) artifactToUpdate.setDuplicated(Boolean.FALSE); else { @@ -503,11 +509,12 @@ public class ArtifactsOperations extends BaseOperation { String id = type != NodeTypeEnum.ResourceInstance ? componentId : instanceId; String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(id, artifactToUpdate.getArtifactLabel()); artifactToUpdate.setUniqueId(uniqueId); - artifactToUpdate.setDuplicated(Boolean.TRUE); + artifactToUpdate.setEsId(uniqueId); + artifactToUpdate.setDuplicated(Boolean.FALSE); } } } - updateUUID(artifactToUpdate, oldChecksum, oldVersion, isUpdate, edgeLabelEnum ); + updateUUID(artifactToUpdate, oldChecksum, oldVersion, isUpdate, edgeLabelEnum); if (artifactInfo.getPayloadData() == null) { if (!artifactToUpdate.getMandatory() || artifactToUpdate.getEsId() != null) { @@ -516,19 +523,44 @@ public class ArtifactsOperations extends BaseOperation { } else { if (artifactToUpdate.getEsId() == null) { artifactToUpdate.setEsId(artifactToUpdate.getUniqueId()); - } } - StorageOperationStatus status; + StorageOperationStatus status = StorageOperationStatus.OK; if (edgeLabelEnum != EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS && edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) { - status = updateToscaDataOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, artifactToUpdate, JsonPresentationFields.ARTIFACT_LABEL); + List toscaDataList = new ArrayList<>(); + toscaDataList.add(artifactToUpdate); + + if (isNeedToClone && artifacts != null) { + artifacts.values().stream().filter(a -> !a.getArtifactLabel().equals(artifactToUpdate.getArtifactLabel())).forEach(a -> toscaDataList.add(a)); + } + status = updateToscaDataOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataList, JsonPresentationFields.ARTIFACT_LABEL); } else { - List pathKeys = new ArrayList<>(); - pathKeys.add(instanceId); List toscaDataList = new ArrayList<>(); toscaDataList.add(artifactToUpdate); - status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataList, pathKeys, JsonPresentationFields.ARTIFACT_LABEL); + List pathKeys = new ArrayList<>(); + pathKeys.add(instanceId); + if (isNeedToClone) { + MapArtifactDataDefinition artifatcsOnInstance = artifactInst.get(instanceId); + if (artifatcsOnInstance != null) { + artifacts = artifatcsOnInstance.getMapToscaDataDefinition(); + artifacts.put(artifactToUpdate.getArtifactLabel(), artifactToUpdate); + } + + for ( Entry e : artifactInst.entrySet() ) { + List toscaDataListPerInst = e.getValue().getMapToscaDataDefinition().values().stream().collect(Collectors.toList()); + List pathKeysPerInst = new ArrayList<>(); + pathKeysPerInst.add(e.getKey()); + status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataListPerInst, pathKeysPerInst, JsonPresentationFields.ARTIFACT_LABEL); + if ( status != StorageOperationStatus.OK) { + log.debug("Failed to update atifacts group for instance {} in component {} edge type {} error {}", instanceId, componentId, edgeLabelEnum, status); + res = Either.right(status); + break; + } + } + } else { + status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataList, pathKeys, JsonPresentationFields.ARTIFACT_LABEL); + } } if (status == StorageOperationStatus.OK) res = Either.left(artifactToUpdate); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java index ed8846010b..407d711ed1 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java @@ -28,6 +28,7 @@ import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; @@ -1340,6 +1341,7 @@ public abstract class BaseOperation { groupInstance.setArtifacts(group.getArtifacts()); groupInstance.setArtifactsUuid(group.getArtifactsUuid()); groupInstance.setProperties(group.getProperties()); + convertPropertiesToInstanceProperties(groupInstance.getProperties()); groupInstance.setInvariantUUID(group.getInvariantUUID()); groupInstance.setGroupUUID(group.getGroupUUID()); groupInstance.setVersion(group.getVersion()); @@ -1354,5 +1356,9 @@ public abstract class BaseOperation { protected String generateCustomizationUUID() { return UUID.randomUUID().toString(); } + + protected void convertPropertiesToInstanceProperties(List properties){ + properties.forEach(p -> p.convertPropertyDataToInstancePropertyData()); + } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java index 58ee914046..0bb5476f1d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java @@ -602,18 +602,18 @@ public class NodeTemplateOperation extends BaseOperation { public MapArtifactDataDefinition prepareInstDeploymentArtifactPerInstance(Map deploymentArtifacts, String componentInstanceId, User user, String envType) { if (deploymentArtifacts != null && envType.equals(HEAT_VF_ENV_NAME)) { - Map instDeploymentArtifacts = new HashMap<>(); + deploymentArtifacts.entrySet().forEach(e -> { ArtifactDataDefinition artifact = e.getValue(); String type = artifact.getArtifactType(); - if (!(type.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()))) { - instDeploymentArtifacts.put(e.getKey(), artifact); + if (type.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) { + //instDeploymentArtifacts.put(e.getKey(), artifact); ArtifactDataDefinition artifactEnv = createArtifactPlaceHolderInfo(artifact, componentInstanceId, user, envType); - instDeploymentArtifacts.put(artifactEnv.getArtifactLabel(), artifactEnv); + deploymentArtifacts.put(artifactEnv.getArtifactLabel(), artifactEnv); } }); - MapArtifactDataDefinition instArtifacts = new MapArtifactDataDefinition(instDeploymentArtifacts); + MapArtifactDataDefinition instArtifacts = new MapArtifactDataDefinition(deploymentArtifacts); return instArtifacts; } return null; @@ -820,12 +820,16 @@ public class NodeTemplateOperation extends BaseOperation { ComponentInstanceDataDefinition dataDefinition = new ComponentInstanceDataDefinition(resourceInstance); Long creationDate = resourceInstance.getCreationTime(); + Long modificationTime; if (creationDate == null) { creationDate = System.currentTimeMillis(); + modificationTime = creationDate; + } else { + modificationTime = System.currentTimeMillis(); } dataDefinition.setComponentUid(ciOriginComponentUid); dataDefinition.setCreationTime(creationDate); - dataDefinition.setModificationTime(creationDate); + dataDefinition.setModificationTime(modificationTime); if (StringUtils.isNotEmpty(instanceNewName)) { dataDefinition.setName(instanceNewName); resourceInstance.setName(instanceNewName); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java index e078f8eb86..58b7d30252 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java @@ -1,14 +1,7 @@ package org.openecomp.sdc.be.model.jsontitan.operations; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; @@ -359,7 +352,7 @@ public class ToscaOperationFacade { } - public Either, StorageOperationStatus> getFollowed(String userId, Set lifecycleStates, Set lastStateStates, ComponentTypeEnum componentType) { + public Either, StorageOperationStatus> getFollowed(String userId, Set lifecycleStates, Set lastStateStates, ComponentTypeEnum componentType) { Either, StorageOperationStatus> followedResources; if (componentType == ComponentTypeEnum.RESOURCE) { followedResources = nodeTypeOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType); @@ -367,7 +360,7 @@ public class ToscaOperationFacade { followedResources = topologyTemplateOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType); } - List components = new ArrayList<>(); + Set components = new HashSet<>(); if (followedResources.isRight() && followedResources.right().value() != StorageOperationStatus.NOT_FOUND) { return Either.right(followedResources.right().value()); } diff --git a/catalog-ui/package.json b/catalog-ui/package.json index bc28d90e3b..4fd1f46734 100644 --- a/catalog-ui/package.json +++ b/catalog-ui/package.json @@ -82,6 +82,8 @@ "@angular/platform-browser-dynamic": "^2.4.8", "@angular/router": "^3.4.8", "@angular/upgrade": "^2.4.8", + "@bardit/cytoscape-expand-collapse": "^2.0.3", + "@bardit/cytoscape-qtip": "^2.5.1", "@types/core-js": "^0.9.35", "@types/js-md5": "^0.4.0", "@types/lodash": "^4.14.52", @@ -114,9 +116,6 @@ "codelyzer": "^2.0.1", "core-js": "^2.4.1", "cytoscape": "^2.7.15", - "@bardit/cytoscape-expand-collapse": "^2.0.3", - "@bardit/cytoscape-qtip": "^2.5.1", - "sdc-angular-dragdrop": "^1.0.14", "cytoscape.js-undo-redo": "^1.0.1", "express": "4.14.0", "jquery": "^2.2.4", @@ -126,15 +125,17 @@ "multer": "1.2.1", "ng-html2js": "2.0.0", "ng-infinite-scroll": "^1.3.0", + "ng2-interceptors": "^1.3.0-1", "perfect-scrollbar": "^0.6.16", "qtip2": "^3.0.3", "reflect-metadata": "^0.1.10", "restangular": "^1.6.1", "rxjs": "^5.2.0", + "sdc-angular-dragdrop": "^1.0.14", "ts-helpers": "^1.1.2", "ts-node": "^2.1.0", "tslint": "^4.4.2", - "typescript": "^2.1.6", + "typescript": "2.3.4", "typings": "^2.1.0", "underscore": "^1.8.3", "webpack": "^2.2.1", diff --git a/catalog-ui/src/app/models/properties-inputs/input-be-model.ts b/catalog-ui/src/app/models/properties-inputs/input-be-model.ts index 6d7854a6bf..6767bce729 100644 --- a/catalog-ui/src/app/models/properties-inputs/input-be-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/input-be-model.ts @@ -3,11 +3,17 @@ import {PropertyBEModel} from 'app/models'; * Created by rc2122 on 6/1/2017. */ export class InputBEModel extends PropertyBEModel { - properties:Array; - inputs:Array; + properties: Array; + inputs: Array; + instanceUniqueId: string; + propertyId: string; - constructor(input?: PropertyBEModel) { + constructor(input?: InputBEModel) { super(input); + this.instanceUniqueId = input.instanceUniqueId; + this.propertyId = input.propertyId; + this.properties = input.properties; + this.inputs = input.inputs; } @@ -17,33 +23,7 @@ export class InputBEModel extends PropertyBEModel { } -export class ComponentInstanceProperty extends PropertyBEModel { +export interface ComponentInstanceModel extends InputBEModel { componentInstanceId:string; - componentInstanceName:string; - - constructor(property?: PropertyBEModel) { - super(property); - } - - - - public toJSON = (): any => { - }; - -} - -export class ComponentInstanceInput extends InputBEModel { - componentInstanceId:string; - componentInstanceName:string; - - constructor(property?: PropertyBEModel) { - super(property); - } - - - - public toJSON = (): any => { - }; - + componentInstanceName: string; } - diff --git a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts index 4f3417186c..3af4431b55 100644 --- a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts @@ -5,41 +5,42 @@ import {InputBEModel} from "./input-be-model"; export class InputFEModel extends InputBEModel { isSimpleType: boolean; - isDataType: boolean; - instanceName: string; - instanceId: string; - propertyName: string; - + relatedProperty: SimpleRelatedProperty; constructor(input?: InputBEModel) { super(input); if (input) { this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1; - this.isDataType = PROPERTY_DATA.TYPES.indexOf(this.type) == -1; - - let propNameIndex:number = this.name.indexOf('_'); - this.instanceName = this.name.substring(0, propNameIndex); - - if(input.properties && input.properties.length){ - this.instanceId = input.properties[0].componentInstanceId; - this.propertyName = input.properties[0].name; - }else if(input.inputs && input.inputs.length){ - this.instanceId = input.inputs[0].componentInstanceId; - this.propertyName = input.inputs[0].name; - }else{ - if (input.inputPath && input.inputPath.indexOf('#') > -1) { - this.propertyName = input.inputPath.substring(0, input.inputPath.indexOf('#')) - } else { - this.inputPath = undefined; //input path may be populated even if its a parent - ensure its empty - this.propertyName = this.name.substring(propNameIndex + 1); - } - } + this.relatedProperty = new SimpleRelatedProperty(input); } } +} +export class SimpleRelatedProperty { + name: string; + value: string; + nestedPath: string; + + constructor(input: InputBEModel) { + if(!input.instanceUniqueId){ + return; + } + //Check if input is on DerivedFEProperty level, in which case we want to set a nested path + let instanceName = input.instanceUniqueId.split('.').pop(); + if (input.inputPath && input.inputPath.indexOf('#') > -1 + && instanceName + "_" + input.inputPath.split('#').join('_') == input.name) { //Ignore inputPath for a complex child on VL that was declared within VF, that was then dragged into service. For that case, input.name will be missing the vl name, so we'll know to ignore the path and fall into else case. + this.nestedPath = input.inputPath; + this.name = input.inputPath.substring(0, input.inputPath.indexOf('#')); + } else { //PropertyFEModel level. Can parse input name to get prop name. + let propNameLength = input.name.length - instanceName.length + 1; + this.name = input.name.substr(instanceName.length + 1, propNameLength); + } - public toJSON = (): any => { - }; - -} + //In declare response, input contains nested property, and we need to extract value so we can update our prop. + let nestedProperty = input.properties && input.properties[0] || input.inputs && input.inputs[0]; + if (nestedProperty) { + this.value = nestedProperty.value; + } + } +}; diff --git a/catalog-ui/src/app/models/properties.ts b/catalog-ui/src/app/models/properties.ts index 357dac2e7d..99a5b86fb9 100644 --- a/catalog-ui/src/app/models/properties.ts +++ b/catalog-ui/src/app/models/properties.ts @@ -50,6 +50,7 @@ export class PropertyModel implements IPropertyModel { schema:SchemaPropertyGroupModel; componentInstanceId:string; parentValue:string; + ownerId:string; //instance properties value:string; @@ -90,6 +91,7 @@ export class PropertyModel implements IPropertyModel { this.simpleType = property.simpleType; this.componentInstanceId = property.componentInstanceId; this.parentValue = property.parentValue; + this.ownerId = property.ownerId; } if (!this.schema || !this.schema.property) { diff --git a/catalog-ui/src/app/ng2/app.module.ts b/catalog-ui/src/app/ng2/app.module.ts index ea73d382e2..970c57de89 100644 --- a/catalog-ui/src/app/ng2/app.module.ts +++ b/catalog-ui/src/app/ng2/app.module.ts @@ -11,13 +11,15 @@ import { StateParamsServiceFactory, CacheServiceProvider, EventListenerServiceProvider } from "./utils/ng1-upgraded-provider"; import {ConfigService} from "./services/config.service"; -import {HttpService} from "./services/http.service"; import {HttpModule} from '@angular/http'; import {AuthenticationService} from './services/authentication.service'; import {Cookie2Service} from "./services/cookie.service"; import {ComponentServiceNg2} from "./services/component-services/component.service"; import {ServiceServiceNg2} from "./services/component-services/service.service"; import {ComponentInstanceServiceNg2} from "./services/component-instance-services/component-instance.service"; +import { InterceptorService } from 'ng2-interceptors'; +import { XHRBackend, RequestOptions } from '@angular/http'; +import {HttpInterceptor} from "./services/http.interceptor.service"; export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule)); @@ -25,6 +27,13 @@ export function configServiceFactory(config:ConfigService) { return () => config.loadValidationConfiguration(); } +export function interceptorFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions){ + let service = new InterceptorService(xhrBackend, requestOptions); + service.addInterceptor(new HttpInterceptor()); + return service; +} + + // export function httpServiceFactory(backend: XHRBackend, options: RequestOptions) { // return new HttpService(backend, options); // } @@ -43,7 +52,6 @@ export function configServiceFactory(config:ConfigService) { exports: [], entryComponents: [], providers: [ - HttpService, DataTypesServiceProvider, SharingServiceProvider, CookieServiceProvider, @@ -61,6 +69,11 @@ export function configServiceFactory(config:ConfigService) { useFactory: configServiceFactory, deps: [ConfigService], multi: true + }, + { + provide: InterceptorService, + useFactory: interceptorFactory, + deps: [XHRBackend, RequestOptions] } ], bootstrap: [AppComponent] diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts index b59ef9dbda..b14f3afd6b 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts @@ -15,7 +15,6 @@ import { DataTypeService } from './../../services/data-type.service'; import { PropertiesService } from './../../services/properties.service'; import { HierarchyNavService } from './../../services/hierarchy-nav.service'; import { PropertiesUtils } from './properties.utils'; -import { PostsService } from "../../services/posts.service"; import { DynamicElementModule } from 'app/ng2/components/dynamic-element/dynamic-element.module'; import { DynamicPropertyComponent } from './../../components/properties-table/dynamic-property/dynamic-property.component'; import {ConfirmationDeleteInputComponent} from "app/ng2/components/inputs-table/confirmation-delete-input/confirmation-delete-input.component" @@ -27,6 +26,7 @@ import {TooltipModule} from "../../components/tooltip/tooltip.module"; import { ComponentModeService } from "app/ng2/services/component-mode.service" import { ModalComponent } from "app/ng2/components/modal/modal.component" import {LoaderComponent} from "app/ng2/components/loader/loader.component" +import {HttpInterceptor} from "../../services/http.interceptor.service"; @NgModule({ declarations: [ @@ -63,7 +63,7 @@ import {LoaderComponent} from "app/ng2/components/loader/loader.component" // PopoverContentComponent, // PopoverComponent ], - providers: [PropertiesService, HierarchyNavService, PropertiesUtils, DataTypeService, PostsService, ContentAfterLastDotPipe, GroupByPipe, KeysPipe, ComponentModeService] + providers: [PropertiesService, HierarchyNavService, PropertiesUtils, DataTypeService,HttpInterceptor, ContentAfterLastDotPipe, GroupByPipe, KeysPipe, ComponentModeService] }) export class PropertiesAssignmentModule { diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts index 22d6f2fe51..e66ed59ad7 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts @@ -1,5 +1,4 @@ import {Component, ViewChild, ElementRef, Renderer, Inject} from "@angular/core"; -import {PostsService} from "../../services/posts.service"; import { PropertiesService } from "../../services/properties.service"; import { HierarchyNavService } from "../../services/hierarchy-nav.service"; import { PropertiesUtils } from './properties.utils'; @@ -8,15 +7,13 @@ import { PROPERTY_TYPES, ResourceType } from "app/utils"; import property = require("lodash/property"); import {ComponentServiceNg2} from "../../services/component-services/component.service"; import {ComponentInstanceServiceNg2} from "../../services/component-instance-services/component-instance.service" -import { InputFEModel, ComponentInstance, PropertyBEModel, DerivedPropertyType, DerivedFEProperty, ResourceInstance, SimpleFlatProperty } from "app/models"; +import { InputBEModel, InputFEModel, ComponentInstance, PropertyBEModel, DerivedPropertyType, DerivedFEProperty, ResourceInstance, SimpleFlatProperty } from "app/models"; import {HierarchyDisplayOptions} from "../../components/hierarchy-navigtion/hierarchy-display-options" import {PropertyRowSelectedEvent} from "./../../components/properties-table/properties-table.component"; import { KeysPipe } from 'app/ng2/pipes/keys.pipe'; import {FilterPropertiesAssignmentComponent} from "../../components/filter-properties-assignment/filter-properties-assignment.component"; import { ComponentModeService } from "app/ng2/services/component-mode.service" import {WorkspaceMode, EVENTS} from "../../../utils/constants"; -import {ComponentInstanceProperty, InputBEModel} from "app/models" -import {ComponentInstanceInput} from "../../../models/properties-inputs/input-be-model"; import {EventListenerService} from "app/services/event-listener-service" @Component({ templateUrl: './properties-assignment.page.component.html', @@ -102,6 +99,7 @@ export class PropertiesAssignmentComponent { } this.selectFirstInstanceByDefault(); }); + }; ngOnDestroy() { @@ -292,41 +290,23 @@ export class PropertiesAssignmentComponent { this.setInputTabIndication(response.length); this.checkedPropertiesCount = 0; _.forEach(response, (input: InputBEModel) => { - this.inputs.push(new InputFEModel(input)); - this.updatePropertyValueAfterDeclare(input); + let newInput: InputFEModel = new InputFEModel(input); + this.inputs.push(newInput); + this.updatePropertyValueAfterDeclare(newInput); }); }); }; - updatePropertyValueAfterDeclare = (input: InputBEModel) => { - _.forEach(input.properties, (property: ComponentInstanceProperty) => { - this.updatePropertyOrInputValueAfterDeclare(property, input); - }); - - _.forEach(input.inputs, (inputInstance: ComponentInstanceInput) => { - this.updatePropertyOrInputValueAfterDeclare(inputInstance, input); - }); - } - updatePropertyOrInputValueAfterDeclare = (inputSource: ComponentInstanceProperty | ComponentInstanceInput, input: InputBEModel) => { - if (this.instanceFePropertiesMap[inputSource.componentInstanceId]) { - let propertyForUpdatindVal = _.find(this.instanceFePropertiesMap[inputSource.componentInstanceId], (feProperty: PropertyFEModel) => { - return feProperty.name == inputSource.name; + updatePropertyValueAfterDeclare = (input: InputFEModel) => { + if (this.instanceFePropertiesMap[input.instanceUniqueId]) { + let propertyForUpdatindVal = _.find(this.instanceFePropertiesMap[input.instanceUniqueId], (feProperty: PropertyFEModel) => { + return feProperty.name == input.relatedProperty.name; }); - if (input.inputPath == propertyForUpdatindVal.name) input.inputPath = null; //Fix - if inputPath is sent for parent props, remove it - - propertyForUpdatindVal.setAsDeclared(input.inputPath); //set prop as declared before assigning value - this.propertiesService.disableRelatedProperties(propertyForUpdatindVal, input.inputPath); - this.propertiesUtils.resetPropertyValue(propertyForUpdatindVal, inputSource.value, input.inputPath); - // if (input.inputPath) { - // let childProp = _.find(propertyForUpdatindVal.flattenedChildren, (child: DerivedFEProperty) => { - // return child.propertiesName == input.inputPath; - // }); - // this.propertiesUtils.assignFlattenedChildrenValues(JSON.parse(inputSource.value), [childProp], inputSource.name); - // } else { - // propertyForUpdatindVal.valueObj = inputSource.value; - // } + propertyForUpdatindVal.setAsDeclared(input.relatedProperty.nestedPath); //set prop as declared before assigning value + this.propertiesService.disableRelatedProperties(propertyForUpdatindVal, input.relatedProperty.nestedPath); + this.propertiesUtils.resetPropertyValue(propertyForUpdatindVal, input.relatedProperty.value, input.relatedProperty.nestedPath); } } @@ -368,14 +348,6 @@ export class PropertiesAssignmentComponent { }); }; - getInstanceUniqueId = (instanceName: string): string => { - let wantedInstance: ComponentInstance = this.instances.find((instance) => { - return instance.normalizedName === instanceName; - }); - - return wantedInstance.uniqueId; - }; - /*** SEARCH RELATED FUNCTIONS ***/ diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties.utils.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties.utils.ts index 0eb8534595..bdfbc4c402 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties.utils.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties.utils.ts @@ -20,8 +20,8 @@ export class PropertiesUtils { */ public convertPropertiesMapToFEAndCreateChildren = (instancePropertiesMap:InstanceBePropertiesMap, inputs:Array): InstanceFePropertiesMap => { let instanceFePropertiesMap:InstanceFePropertiesMap = new InstanceFePropertiesMap(); - angular.forEach(instancePropertiesMap, (properties:Array, instanceName:string) => { - let instanceInputs: Array = inputs.filter(input => input.instanceName == instanceName.split('.').pop()); + angular.forEach(instancePropertiesMap, (properties:Array, instanceId:string) => { + let instanceInputs: Array = inputs.filter(input => input.instanceUniqueId == instanceId); let propertyFeArray: Array = []; _.forEach(properties, (property: PropertyBEModel) => { @@ -35,9 +35,9 @@ export class PropertiesUtils { newFEProp.flattenedChildren = this.createFlattenedChildren(newFEProp.type, newFEProp.name); } if (instanceInputs.length) { //if this prop (or any children) are declared, set isDeclared and disable checkbox on parents/children - instanceInputs.filter(input => input.propertyName == newFEProp.name).forEach((input) => { - newFEProp.setAsDeclared(input.inputPath); //if a path was sent, its a child prop. this param is optional - this.propertiesService.disableRelatedProperties(newFEProp, input.inputPath); + instanceInputs.filter(input => input.relatedProperty.name == newFEProp.name).forEach((input) => { + newFEProp.setAsDeclared(input.relatedProperty.nestedPath); //if a path was sent, its a child prop. this param is optional + this.propertiesService.disableRelatedProperties(newFEProp, input.relatedProperty.nestedPath); }); } this.initValueObjectRef(newFEProp); //initialize valueObj. @@ -46,7 +46,7 @@ export class PropertiesUtils { this.dataTypeService.checkForCustomBehavior(newFEProp); } }); - instanceFePropertiesMap[instanceName] = propertyFeArray; + instanceFePropertiesMap[instanceId] = propertyFeArray; }); return instanceFePropertiesMap; @@ -140,10 +140,10 @@ export class PropertiesUtils { }); } - public resetPropertyValue = (property: PropertyFEModel, newValue: string, inputPath?: string): void => { + public resetPropertyValue = (property: PropertyFEModel, newValue: string, nestedPath?: string): void => { property.value = newValue; - if (inputPath) { - let newProp = property.flattenedChildren.find(prop => prop.propertiesName == inputPath); + if (nestedPath) { + let newProp = property.flattenedChildren.find(prop => prop.propertiesName == nestedPath); newProp && this.assignFlattenedChildrenValues(JSON.parse(newValue), [newProp], property.name); } else { this.initValueObjectRef(property); diff --git a/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts b/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts index 85709894ff..fd7e7b62ce 100644 --- a/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts +++ b/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts @@ -1,18 +1,18 @@ import {Injectable} from '@angular/core'; import {Response, RequestOptions, Headers} from '@angular/http'; import { Observable } from 'rxjs/Observable'; -import {HttpService} from "../http.service"; import {sdc2Config} from "../../../../main"; import {PropertyBEModel} from "app/models"; import {CommonUtils} from "app/utils"; import {Component, ComponentInstance, InputModel} from "app/models"; +import {InterceptorService} from "ng2-interceptors/index"; @Injectable() export class ComponentInstanceServiceNg2 { protected baseUrl; - constructor(private http: HttpService) { + constructor(private http: InterceptorService) { this.baseUrl = sdc2Config.api.root + sdc2Config.api.component_api_root; } diff --git a/catalog-ui/src/app/ng2/services/component-services/component.service.ts b/catalog-ui/src/app/ng2/services/component-services/component.service.ts index 3fa9fde40c..976d18eac3 100644 --- a/catalog-ui/src/app/ng2/services/component-services/component.service.ts +++ b/catalog-ui/src/app/ng2/services/component-services/component.service.ts @@ -1,17 +1,17 @@ -import {Injectable, Query} from '@angular/core'; +import {Injectable} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/toPromise'; import {Response, URLSearchParams} from '@angular/http'; import { Component, PropertyBEModel, InstancePropertiesAPIMap, FilterPropertiesAssignmentData} from "app/models"; import {downgradeInjectable} from '@angular/upgrade/static'; -import {HttpService} from "../http.service"; import {COMPONENT_FIELDS} from "app/utils"; import {ComponentGenericResponse} from "../responses/component-generic-response"; import {sdc2Config} from "../../../../main"; import {InstanceBePropertiesMap} from "../../../models/properties-inputs/property-fe-map"; import {API_QUERY_PARAMS} from "app/utils"; import {ComponentType, ServerTypeUrl} from "../../../utils/constants"; +import {InterceptorService} from "ng2-interceptors/index"; declare var angular:angular.IAngularStatic; @@ -20,7 +20,7 @@ export class ComponentServiceNg2 { protected baseUrl; - constructor(private http:HttpService) { + constructor(private http:InterceptorService) { this.baseUrl = sdc2Config.api.root + sdc2Config.api.component_api_root; } diff --git a/catalog-ui/src/app/ng2/services/component-services/service.service.ts b/catalog-ui/src/app/ng2/services/component-services/service.service.ts index d2f7078599..147fe9385c 100644 --- a/catalog-ui/src/app/ng2/services/component-services/service.service.ts +++ b/catalog-ui/src/app/ng2/services/component-services/service.service.ts @@ -6,7 +6,7 @@ import { Response } from '@angular/http'; import {Service} from "app/models"; import { downgradeInjectable } from '@angular/upgrade/static'; import {sdc2Config} from "../../../../main"; -import {HttpService} from "../http.service"; +import {InterceptorService} from "ng2-interceptors/index"; @Injectable() @@ -14,7 +14,7 @@ export class ServiceServiceNg2 { protected baseUrl = ""; - constructor(private http: HttpService) { + constructor(private http: InterceptorService) { this.baseUrl = sdc2Config.api.root + sdc2Config.api.component_api_root; } diff --git a/catalog-ui/src/app/ng2/services/http.interceptor.service.ts b/catalog-ui/src/app/ng2/services/http.interceptor.service.ts new file mode 100644 index 0000000000..aebbdbf7af --- /dev/null +++ b/catalog-ui/src/app/ng2/services/http.interceptor.service.ts @@ -0,0 +1,57 @@ +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/toPromise'; +import 'rxjs/Rx'; +import { sdc2Config } from './../../../main'; +import { Interceptor, InterceptedRequest, InterceptedResponse } from 'ng2-interceptors'; +import {SharingService} from "../../services/sharing-service"; +import {ReflectiveInjector} from '@angular/core'; +import {Cookie2Service} from "./cookie.service"; +import {UUID} from "angular2-uuid"; +import {Dictionary} from "../../utils/dictionary/dictionary"; + +export class HttpInterceptor implements Interceptor { + + private cookieService: Cookie2Service; + private sharingService:SharingService; + constructor() { + let injector = ReflectiveInjector.resolveAndCreate([Cookie2Service,SharingService]); + this.cookieService = injector.get(Cookie2Service); + this.sharingService = injector.get(SharingService); + } + + public interceptBefore(request: InterceptedRequest): InterceptedRequest { + + /** + * For every request to the server, that the service id, or resource id is sent in the URL, need to pass UUID in the header. + * Check if the unique id exists in uuidMap, and if so get the UUID and add it to the header. + */ + + request.options.headers.append(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId()); + var uuidValue = this.getUuidValue(request.url); + if(uuidValue!= ''){ + request.options.headers.set('X-ECOMP-ServiceID',uuidValue); + } + request.options.headers.set('X-ECOMP-RequestID', UUID.UUID()); + return request; + + } + + public interceptAfter(response: InterceptedResponse): InterceptedResponse { + + return response; + + } + + private getUuidValue = (url: string) :string => { + let map:Dictionary = this.sharingService.getUuidMap(); + if (map && url.indexOf(sdc2Config.api.root) > 0) { + map.forEach((key:string) => { + if (url.indexOf(key) !== -1) { + return this.sharingService.getUuidValue(key); + } + }); + } + return ''; + } + +} diff --git a/catalog-ui/src/app/ng2/services/posts.service.ts b/catalog-ui/src/app/ng2/services/posts.service.ts deleted file mode 100644 index dbfd44f219..0000000000 --- a/catalog-ui/src/app/ng2/services/posts.service.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs/Observable'; -import 'rxjs/add/operator/map'; -import 'rxjs/add/operator/toPromise'; -import 'rxjs/Rx'; -import {Response, Headers, RequestOptions, Http} from '@angular/http'; -import { COMPONENT_INSTANCE_RESPONSE,COMPONENT_INPUT_RESPONSE,COMPONENT_PROPERTIES_RESPONSE } from './mocks/properties.mock'; -import { HttpService } from './http.service'; -import { sdc2Config } from './../../../main'; -import {IAppConfigurtaion} from "../../models/app-config"; - -@Injectable() -export class PostsService { - - private base; - - constructor(private http: HttpService) { - this.base = sdc2Config.api.root; - } - - getAppVersion(): Observable { - return this.http - .get(this.base + sdc2Config.api.GET_SDC_Version) - .map((res: Response) => res.json()); - } - - // getProperties(id:string): Observable { - // return this.http - // .get(this.base + sdc2Config.api.GET_SDC_Version) - // .map((res: Response) => res.json()); - // } - - getProperties(): Observable { - return Observable.create(observer => { - observer.next(COMPONENT_PROPERTIES_RESPONSE); - observer.complete(); - }); - } - - getInstance(): Observable { - return Observable.create(observer => { - observer.next(COMPONENT_INSTANCE_RESPONSE); - observer.complete(); - }); - } - - getInputs(): Observable { - return Observable.create(observer => { - observer.next(COMPONENT_INPUT_RESPONSE); - observer.complete(); - }); - } - -} diff --git a/catalog-ui/src/app/ng2/services/responses/component-generic-response.ts b/catalog-ui/src/app/ng2/services/responses/component-generic-response.ts index 7dcd95d712..38e23a58f3 100644 --- a/catalog-ui/src/app/ng2/services/responses/component-generic-response.ts +++ b/catalog-ui/src/app/ng2/services/responses/component-generic-response.ts @@ -3,7 +3,7 @@ */ import { ArtifactGroupModel, PropertyModel, PropertiesGroup, AttributeModel, AttributesGroup, ComponentInstance, - InputModel, Module, ComponentMetadata, RelationshipModel, RequirementsGroup, CapabilitiesGroup,InputFEModel} from "app/models"; + InputBEModel, Module, ComponentMetadata, RelationshipModel, RequirementsGroup, CapabilitiesGroup,InputFEModel} from "app/models"; import {CommonUtils} from "app/utils"; import {Serializable} from "../utils/serializable"; import {PropertyBEModel} from "../../../models/properties-inputs/property-be-model"; @@ -18,7 +18,7 @@ export class ComponentGenericResponse implements Serializable; public componentInstances:Array; - public inputs:Array; + public inputs:Array; public capabilities:CapabilitiesGroup; public requirements:RequirementsGroup; public properties:Array; diff --git a/catalog-ui/src/app/utils/common-utils.ts b/catalog-ui/src/app/utils/common-utils.ts index d8019d2f96..acfbd80ff4 100644 --- a/catalog-ui/src/app/utils/common-utils.ts +++ b/catalog-ui/src/app/utils/common-utils.ts @@ -1,6 +1,6 @@ import {Module, AttributeModel, ResourceInstance, PropertyModel, InputFEModel} from "../models"; import {ComponentInstanceFactory} from "./component-instance-factory"; -import {PropertyBEModel, RelationshipModel} from "app/models"; +import {InputBEModel, PropertyBEModel, RelationshipModel} from "app/models"; export class CommonUtils { @@ -57,13 +57,13 @@ export class CommonUtils { return modules; }; - static initInputs(inputsObj:Array):Array { + static initInputs(inputsObj: Array): Array { - let inputs = new Array(); + let inputs = new Array(); if(inputsObj) { - _.forEach(inputsObj, (input:PropertyBEModel):void => { - inputs.push(new PropertyBEModel(input)); + _.forEach(inputsObj, (input: InputBEModel):void => { + inputs.push(new InputBEModel(input)); }) } diff --git a/catalog-ui/src/app/view-models/workspace/tabs/properties/properties-view.html b/catalog-ui/src/app/view-models/workspace/tabs/properties/properties-view.html index d1e0582386..24011cc751 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/properties/properties-view.html +++ b/catalog-ui/src/app/view-models/workspace/tabs/properties/properties-view.html @@ -46,8 +46,8 @@
- +
diff --git a/catalog-ui/src/assets/styles/images/sprites/sprite-global.png b/catalog-ui/src/assets/styles/images/sprites/sprite-global.png index fb9e79894a..7a795c7a91 100644 Binary files a/catalog-ui/src/assets/styles/images/sprites/sprite-global.png and b/catalog-ui/src/assets/styles/images/sprites/sprite-global.png differ diff --git a/catalog-ui/src/assets/styles/sprite.less b/catalog-ui/src/assets/styles/sprite.less index 62defccca8..0c0f538388 100644 --- a/catalog-ui/src/assets/styles/sprite.less +++ b/catalog-ui/src/assets/styles/sprite.less @@ -232,8 +232,8 @@ .filter-icon { background-position: -48px -1040px; width: 19px; height: 20px;} .filter-icon:hover { background-position: -99px -1040px; width: 19px; height: 20px;} .filled-checkbox-icon { background-position: -100px -1079px; width: 14px; height: 14px;} -.round-checked-icon { background-position: -50px -1119px; width: 20px; height: 20px;} -.round-checked-icon.disabled { background-position: -100px -1119px; width: 20px; height: 20px;} +.round-checked-icon { background-position: -50px -1157px; width: 16px; height: 18px;} +.round-checked-icon.disabled { background-position: -100px -1157px; width: 16px; height: 18px;} .round-expand-icon { background-position: -50px -1188px; width: 15px; height: 15px; } .round-expand-icon:hover { background-position: -100px -1188px; width: 15px; height: 15px; } .round-expand-icon.open { background-position: -50px -1216px; width: 15px; height: 15px; } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java b/common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java index b1f4117aaf..04640e7fc7 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java @@ -40,6 +40,7 @@ public interface Constants { public static final String LAST_NAME_HEADER = "HTTP_CSP_LASTNAME"; public static final String USER_ID_HEADER = "USER_ID"; public static final String MD5_HEADER = "Content-MD5"; + public static final String CONTENT_LENGTH_HEADER = "Content-Length"; public static final String CONTENT_DISPOSITION_HEADER = "Content-Disposition"; public static final String CONTENT_TYPE_HEADER = "Content-Type"; public static final String ORIGIN_HEADER = "HTTP_IV_REMOTE_ADDRESS"; diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ComponentInstanceDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ComponentInstanceDataDefinition.java index e236fcb963..b6f9b82c45 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ComponentInstanceDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ComponentInstanceDataDefinition.java @@ -60,6 +60,7 @@ public class ComponentInstanceDataDefinition extends ToscaDataDefinition impleme private String componentName; private String componentVersion; private String toscaComponentName; + private String invariantName; public ComponentInstanceDataDefinition() { super(); @@ -82,6 +83,7 @@ public class ComponentInstanceDataDefinition extends ToscaDataDefinition impleme this.componentName = dataDefinition.componentName; this.componentVersion = dataDefinition.componentVersion; this.toscaComponentName = dataDefinition.toscaComponentName; + this.invariantName = dataDefinition.invariantName; } public String getIcon() { @@ -152,8 +154,19 @@ public class ComponentInstanceDataDefinition extends ToscaDataDefinition impleme } public void setName(String name) { + if(invariantName == null){ + invariantName = name; + } this.name = name; } + + public String getInvariantName() { + return invariantName; + } + + public void setInvariantName(String invariantName) { + this.invariantName = invariantName; + } public Integer getPropertyValueCounter() { return propertyValueCounter; diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java index e669d66c50..0b8456bd5c 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java @@ -66,7 +66,9 @@ public class PropertyDataDefinition extends ToscaDataDefinition implements Seria private String inputPath; private String status; - + private String inputId; + private String instanceUniqueId; + private String propertyId; /** * The resource id which this property belongs to */ @@ -85,7 +87,6 @@ public class PropertyDataDefinition extends ToscaDataDefinition implements Seria } public PropertyDataDefinition(PropertyDataDefinition p) { - super(); this.setUniqueId(p.getUniqueId()); this.setRequired(p.isRequired()); @@ -105,7 +106,9 @@ public class PropertyDataDefinition extends ToscaDataDefinition implements Seria this.setGetInputValues(p.getInputValues); this.setInputPath(p.getInputPath()); this.setStatus(p.getStatus()); - + this.setInputId(p.getInputId()); + this.setInstanceUniqueId(p.getInstanceUniqueId()); + this.setPropertyId(p.getPropertyId()); } public String getInputPath() { @@ -247,9 +250,36 @@ public class PropertyDataDefinition extends ToscaDataDefinition implements Seria this.status = status; } + public String getInputId() { + return inputId; + } + + public void setInputId(String inputId) { + this.inputId = inputId; + } + + public String getInstanceUniqueId() { + return instanceUniqueId; + } + + public void setInstanceUniqueId(String instanceUniqueId) { + this.instanceUniqueId = instanceUniqueId; + } + + public String getPropertyId() { + return propertyId; + } + + public void setPropertyId(String propertyId) { + this.propertyId = propertyId; + } + + @Override public String toString() { - return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", defaultValue=" + defaultValue + ", description=" + description + ", entrySchema=" + schema + ", parentUniqueId=" + parentUniqueId + ", password=" + password + "]"; + return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", definition=" + definition + ", defaultValue=" + defaultValue + ", description=" + description + ", schema=" + schema + ", password=" + + password + ", name=" + name + ", value=" + value + ", label=" + label + ", hidden=" + hidden + ", immutable=" + immutable + ", inputPath=" + inputPath + ", status=" + status + ", inputId=" + inputId + ", instanceUniqueId=" + + instanceUniqueId + ", propertyId=" + propertyId + ", parentUniqueId=" + parentUniqueId + ", getInputValues=" + getInputValues + "]"; } @Override @@ -362,6 +392,11 @@ public class PropertyDataDefinition extends ToscaDataDefinition implements Seria } return null; } + + public void convertPropertyDataToInstancePropertyData(){ + if(null != value) + defaultValue = value; + } diff --git a/openecomp-be/lib/openecomp-migration-lib/pom.xml b/openecomp-be/lib/openecomp-migration-lib/pom.xml deleted file mode 100644 index 7c33315fbc..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/pom.xml +++ /dev/null @@ -1,192 +0,0 @@ - - - 4.0.0 - - openecomp-migration-lib - openecomp-migration-lib - - - org.openecomp.sdc - openecomp-sdc-lib - 1.1.0-SNAPSHOT - .. - - - - 2.4.7 - 2.7.7 - - - - - org.openecomp.sdc - openecomp-sdc-vendor-software-product-manager - ${project.version} - - - - org.codehaus.groovy - groovy - ${groovy.version} - - - - org.openecomp.sdc.common - openecomp-configuration-management-core - ${openecomp.sdc.common.version} - runtime - - - org.slf4j - slf4j-log4j12 - - - - - - org.codehaus.janino - janino - ${janino.version} - - - - org.openecomp.sdc.core - openecomp-zusammen-core - ${project.version} - - - - org.codehaus.janino - commons-compiler - 3.0.6 - - - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - install - - copy-dependencies - - - ${project.build.directory}/lib - false - false - true - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${mvn.jar.version} - - - package - - - - - - true - custom - lib/${artifact.artifactId}-${baseVersion}.${artifact.extension} - org.openecomp.sdc.migration.ToscaNamespaceMigration - - - lib/ - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19.1 - - false - true - - - - - com.google.code.maven-replacer-plugin - maven-replacer-plugin - 1.3.5 - - - replace-for-migration - initialize - - replace - - - ../../tools/migration/1702_to_1707.sh - false - target - - - 1707.0.0-SNAPSHOT - ${project.version} - - - - - - - - - org.apache.maven.plugins - maven-antrun-plugin - - - ant-test - package - - - - - - - run - - - - - - - - - diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml b/openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml deleted file mode 100644 index 3cb9fc07b4..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/src/main/assembly/migration-lib-assembly.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - zip - - - false - - - - ${basedir}/target - - openecomp-migration-lib*.jar - 1702_to_1707.sh - - / - 0755 - - - ${basedir}/target/lib - /lib - - - - diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java b/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java deleted file mode 100644 index c6a23734e4..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/TestScript.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.openecomp.sdc.migration; - -/** - * Created by TALIO on 3/19/2017. - */ -public class TestScript { - - public static void main(String[] args){ - System.out.print("Test succeed!"); - } -} diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java b/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java deleted file mode 100644 index 4fa0ab368a..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/src/main/java/org/openecomp/sdc/migration/ToscaNamespaceMigration.java +++ /dev/null @@ -1,290 +0,0 @@ -package org.openecomp.sdc.migration; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.io.IOUtils; -import org.openecomp.core.model.dao.EnrichedServiceModelDao; -import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory; -import org.openecomp.core.model.dao.ServiceModelDao; -import org.openecomp.core.model.dao.ServiceModelDaoFactory; -import org.openecomp.core.model.types.ServiceElement; -import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import org.openecomp.sdc.tosca.datatypes.model.Import; -import org.openecomp.sdc.tosca.datatypes.model.Old1610ServiceTemplate; -import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; -import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; -import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; -import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory; -import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; -import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; -import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer; - - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; -import java.util.zip.ZipOutputStream; - - -/** - * Created by TALIO on 3/19/2017 - */ -public class ToscaNamespaceMigration { - - private static VendorSoftwareProductManager vendorSoftwareProductManager = - VspManagerFactory.getInstance().createInterface(); - private static OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager = - OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface(); - private static VendorSoftwareProductDao vendorSoftwareProductDao = - VendorSoftwareProductDaoFactory.getInstance().createInterface(); - private static ServiceModelDao serviceModelDao = - ServiceModelDaoFactory.getInstance().createInterface(); - private static EnrichedServiceModelDao - enrichedServiceModelDao = - EnrichedServiceModelDaoFactory.getInstance().createInterface(); - private static VendorSoftwareProductInfoDao vspInfoDao = - VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); - private static PackageInfoDao packageInfoDao = PackageInfoDaoFactory.getInstance() - .createInterface(); - private static final ComponentDao componentDao = - ComponentDaoFactory.getInstance().createInterface(); - private static Logger logger = LoggerFactory.getLogger(ToscaNamespaceMigration.class); - private static int status = 0; - - - public static void main(String[] args) { - //CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem(); - - Collection vspList = vspInfoDao.list(new VspDetails()); - - List packagesList = - packageInfoDao.listByCategory(null, null); - - for (VspDetails vspInfo : vspList) { - printMessage("Performing migration on vsp " + vspInfo.getName() + " and version " + vspInfo - .getVersion().toString() + "\n"); - performMigration(vspInfo); - } - - System.exit(status); - } - - private static void performMigration(VspDetails vspDetails) { - - changeComponentNamePrefix(vspDetails); - - try { - changeNamespaceInServiceTemplates(vspDetails); - } catch (Exception e) { - printMessage( - "Could not perform migration for service templates on vsp " + vspDetails.getName()); - status = -1; - } - - if (vspDetails.getVersion().isFinal()) { - changeNamespaceInPackage(vspDetails); - } - - } - - private static void changeComponentNamePrefix(VspDetails vspDetails){ - Collection componentsList = - componentDao.list(new ComponentEntity(vspDetails.getId(), vspDetails.getVersion(), null)); - - if(CollectionUtils.isEmpty(componentsList)){ - printMessage("No component namespace migration was performed on vsp with id" + vspDetails - .getId() + " and version " + vspDetails.getVersion().toString() + " since it has no " + - "components"); - return; - } - - for(ComponentEntity component : componentsList){ - String compositionData = component.getCompositionData(); - - if(Objects.isNull(compositionData)){ - continue; - } - - ComponentData componentData = - JsonUtil.json2Object(compositionData, ComponentData.class); - componentData.setName(componentData.getName().replace("com.att.d2", "org.openecomp")); - component.setCompositionData(JsonUtil.object2Json(componentData)); - - componentDao.update(component); - } - - printMessage("Component namespace migration was performed on vsp with id" + vspDetails - .getId() + " and version " + vspDetails.getVersion().toString()); - } - - private static void changeNamespaceInServiceTemplates(VspDetails vspDetails) throws IOException { - String vspId = vspDetails.getId(); - Version version = vspDetails.getVersion(); - ToscaServiceModel serviceModel; - ToscaServiceModel enrichedServiceModel; - - serviceModel = - serviceModelDao.getServiceModel(vspId, version); - enrichedServiceModel = - enrichedServiceModelDao.getServiceModel(vspId, version); - - printMessage("Working on vsp_service_template table in DB \n"); - changeNamespaceInServiceModel(serviceModel); - printMessage("Finished Working on vsp_service_template table in DB \n"); - - printMessage("Working on vsp_enriched_service_template table in DB \n"); - changeNamespaceInServiceModel(enrichedServiceModel); - printMessage("Finished Working on vsp_enriched_service_template table in DB \n"); - - serviceModelDao.storeServiceModel(vspId, version, serviceModel); - enrichedServiceModelDao.storeServiceModel(vspId, version, enrichedServiceModel); - } - - private static void changeNamespaceInServiceModel(ToscaServiceModel serviceModel) { - Map changedServiceTemplates = new HashMap<>(); - Map serviceTemplates = serviceModel.getServiceTemplates(); - - for (Map.Entry serviceTemplateEntry : serviceTemplates.entrySet()) { - printMessage( - "Changing namespace for Service Template " + serviceTemplateEntry.getKey() + "\n"); - - ServiceTemplate serviceTemplate = serviceTemplateEntry.getValue(); - String fileAsJson = JsonUtil.object2Json(serviceTemplate); - String replacedNamespace = fileAsJson.replace("org.openecomp.d2", "org.openecomp"); - ServiceTemplate newServiceTemplate; - try { - newServiceTemplate = - new ToscaExtensionYamlUtil().yamlToObject(replacedNamespace, ServiceTemplate.class); - } catch (Exception e) { - System.out.println("Found vsp with old-versioned tosca service template"); - Old1610ServiceTemplate oldServiceTemplate = - JsonUtil.json2Object(replacedNamespace, Old1610ServiceTemplate.class); - newServiceTemplate = mapOldSTToCurrentST(oldServiceTemplate); - - } - changedServiceTemplates.put( - serviceTemplateEntry.getKey(), newServiceTemplate); - } - - serviceModel.setServiceTemplates(changedServiceTemplates); - } - - private static org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate mapOldSTToCurrentST( - Old1610ServiceTemplate oldServiceTemplate) { - org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate - serviceTemplate = new org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate(); - - serviceTemplate.setArtifact_types(oldServiceTemplate.getArtifact_types()); - serviceTemplate.setCapability_types(oldServiceTemplate.getCapability_types()); - serviceTemplate.setData_types(oldServiceTemplate.getData_types()); - serviceTemplate.setDescription(oldServiceTemplate.getDescription()); - serviceTemplate.setGroup_types(oldServiceTemplate.getGroup_types()); - serviceTemplate.setInterface_types(oldServiceTemplate.getInterface_types()); - serviceTemplate.setMetadata(oldServiceTemplate.getMetadata()); - serviceTemplate.setNode_types(oldServiceTemplate.getNode_types()); - serviceTemplate.setPolicy_types(oldServiceTemplate.getPolicy_types()); - serviceTemplate.setRelationship_types(oldServiceTemplate.getRelationship_types()); - serviceTemplate.setTopology_template(oldServiceTemplate.getTopology_template()); - - List> imports = new ArrayList<>(); - for (Map.Entry importEntry : oldServiceTemplate.getImports().entrySet()) { - Map importMap = new HashMap<>(); - importMap.put(importEntry.getKey(), importEntry.getValue()); - imports.add(importMap); - } - serviceTemplate.setImports(imports); - - return serviceTemplate; - - } - - private static void changeNamespaceInPackage(VspDetails vspDetails) { - String vspId = vspDetails.getId(); - printMessage("Start updating CSAR file with new namespace in DB \n"); - - File translatedFile; - try { - translatedFile = - getTranslatedFile(vspId, vspDetails.getVersion()); - } catch (Exception e) { - printMessage("No translated file was found under vsp " + vspDetails.getName() + "\n"); - return; - } - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ZipOutputStream zos = new ZipOutputStream(baos); - ZipFile zipFile = new ZipFile(translatedFile)) { - Enumeration entries = zipFile.entries(); - - while (entries.hasMoreElements()) { - ZipEntry ze = entries.nextElement(); - InputStream zipEntryIs = zipFile.getInputStream(ze); - byte[] contentAsByte = IOUtils.toByteArray(zipEntryIs); - String fileContent = new String(contentAsByte); - - String replacedNamespace = fileContent.replace("org.openecomp.d2", "org.openecomp"); - - zos.putNextEntry(new ZipEntry(ze.getName())); - zos.write(replacedNamespace.getBytes()); - } - printMessage("Changed Tosca namesapce in package for vsp " + vspDetails.getName() + "\n"); - - - packageInfoDao.updateTranslatedContent( - vspId, vspDetails.getVersion(), ByteBuffer.wrap(baos.toByteArray())); - printMessage("Updated CSAR file with new namespace in DB \n"); - - } catch (Exception e) { - printMessage("Could not perform migration on csar"); - } - } - - private static void printMessage(String message) { - System.out.print(message); - logger.debug(message); - } - - private static File getTranslatedFile(String vspId, Version version) - throws IOException { - PackageInfo packageInfo = - packageInfoDao.get(new PackageInfo(vspId, version)); - ByteBuffer translatedFileBuffer = packageInfo == null ? null : packageInfo.getTranslatedFile(); - - File translatedFile = new File(VendorSoftwareProductConstants.VSP_PACKAGE_ZIP); - - FileOutputStream fos = new FileOutputStream(translatedFile); - fos.write(translatedFileBuffer.array()); - fos.close(); - - - return translatedFile; - } -} diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml b/openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml deleted file mode 100644 index 5596881329..0000000000 --- a/openecomp-be/lib/openecomp-migration-lib/src/main/resources/logback.xml +++ /dev/null @@ -1,280 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/all.log - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/all.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/Error.log - - - - - - AUDIT_MARKER - - NEUTRAL - DENY - - - - - - TRANSACTION_MARKER - - NEUTRAL - DENY - - - - - INFO - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/Error.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug.log - - - - - - - TRANSACTION_MARKER - - NEUTRAL - DENY - - - - - - - e.level.toInt() <= DEBUG.toInt() - - - DENY - NEUTRAL - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/migration_debug.log - - - - - - - TRANSACTION_MARKER - - NEUTRAL - DENY - - - - - - - e.level.toInt() <= DEBUG.toInt() - - - DENY - NEUTRAL - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug_by_package.log.%i - - 1 - 10 - - - - 20MB - - - ${asdc-debug-log-pattern} - - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/audit.log - - - - - - AUDIT_MARKER - - DENY - ACCEPT - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/audit.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/transaction.log - - - - - - TRANSACTION_MARKER - - DENY - ACCEPT - - - - ${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/transaction.log.%i - - 1 - 10 - - - - 20MB - - - ${default-log-pattern} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip b/openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip deleted file mode 100644 index 659a2381f7..0000000000 Binary files a/openecomp-be/lib/openecomp-migration-lib/src/main/resources/openecomp-migration-lib.zip and /dev/null differ diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/pom.xml b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/pom.xml index 0ae2578969..9a80aa9c24 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/pom.xml @@ -78,7 +78,7 @@ false true - true + true diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-impl/pom.xml b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-impl/pom.xml index c183fd4263..e8c39065a9 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-impl/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-impl/pom.xml @@ -56,10 +56,10 @@ ${mvn.surefire.version} false - true ${project.basedir}/configuration + true diff --git a/openecomp-be/lib/pom.xml b/openecomp-be/lib/pom.xml index 183f4187c1..44594f7488 100644 --- a/openecomp-be/lib/pom.xml +++ b/openecomp-be/lib/pom.xml @@ -29,7 +29,6 @@ openecomp-sdc-enrichment-lib openecomp-logging-lib openecomp-healing-lib - openecomp-migration-lib openecomp-sdc-activity-log-lib diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java new file mode 100644 index 0000000000..b92ba52000 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java @@ -0,0 +1,62 @@ +package org.openecomp.core.tools.Commands; + +import com.amdocs.zusammen.datatypes.SessionContext; +import org.apache.commons.io.FileUtils; +import org.openecomp.core.tools.Commands.exportdata.ElementHandler; +import org.openecomp.core.tools.Commands.exportdata.ImportProperties; +import org.openecomp.core.tools.Commands.exportdata.ItemHandler; +import org.openecomp.core.tools.Commands.exportdata.VersionHandler; +import org.openecomp.core.tools.util.ZipUtils; +import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import static java.nio.file.Files.createDirectories; +public class ExportDataCommand { + private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class); + + public static void exportData(SessionContext context, String filterItem) { + try { + ImportProperties.initParams(); + CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem(); + Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY); + initDir(rootDir); + if (filterItem != null) { + filterItem = filterItem.replaceAll("\\r", ""); + } + new ItemHandler().createItemsData(context, filterItem); + new VersionHandler().loadVersions(filterItem); + new ElementHandler().loadElements(filterItem); + zipPath(rootDir,filterItem); + FileUtils.forceDelete(rootDir.toFile()); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + ex.printStackTrace(); + } + + } + private static void zipPath(Path rootDir,String filterItem ) throws Exception{ + LocalDateTime date = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + String dateStr = date.format(formatter); + String zipFile = System.getProperty("user.home")+ File.separatorChar+"onboarding_import"+ dateStr + ".zip"; + ZipUtils.createZip(zipFile, rootDir,filterItem); + } + + + public static void initDir(Path rootDir ) throws IOException{ + if (Files.exists(rootDir)) { + FileUtils.forceDelete(rootDir.toFile()); + } + createDirectories(rootDir); + } + +} \ No newline at end of file diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java new file mode 100644 index 0000000000..57486b81e3 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java @@ -0,0 +1,43 @@ +package org.openecomp.core.tools.Commands; + +import com.amdocs.zusammen.datatypes.SessionContext; +import org.apache.commons.io.FileUtils; +import org.openecomp.core.tools.Commands.importdata.TreeWalker; +import org.openecomp.core.tools.Commands.exportdata.ImportProperties; +import org.openecomp.core.tools.util.ZipUtils; +import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class ImportCommand { + + private static final Logger logger = LoggerFactory.getLogger(ImportCommand.class); + + + public static void importData(SessionContext context, String zippedFile, String filterItem) { + try { + ImportProperties.initParams(); + CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem(); + if (zippedFile == null){ + logger.error("Import must have a valid file as an input."); + } + zippedFile = zippedFile.replaceAll("\\r", ""); + if(filterItem != null) { + filterItem = filterItem.replaceAll("\\r", ""); + } + Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY); + ExportDataCommand.initDir(rootDir); + ZipUtils.unzip(Paths.get(zippedFile), rootDir); + TreeWalker.walkFiles(context, rootDir, filterItem); + + FileUtils.forceDelete(rootDir.toFile()); // clear all unzip data at the end. + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + ex.printStackTrace(); + } + } + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java index 185e80030f..527efa5fc6 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java @@ -2,22 +2,16 @@ package org.openecomp.core.tools.Commands; import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.SessionContext; -import com.amdocs.zusammen.plugin.statestore.cassandra.dao.impl.ItemCassandraDao; import com.amdocs.zusammen.plugin.statestore.cassandra.dao.impl.VersionCassandraDao; -import org.openecomp.core.tools.loaders.VersionInfoCassandraLoader; -import org.openecomp.core.tools.loaders.zusammen.VspGeneralLoader; +import org.openecomp.core.tools.store.VersionInfoCassandraLoader; +import org.openecomp.core.tools.store.VspGeneralLoader; import org.openecomp.core.tools.store.ElementHandler; import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer; -import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository; import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class ResetOldVersion { diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java new file mode 100644 index 0000000000..ebce90fb4a --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java @@ -0,0 +1,100 @@ +package org.openecomp.core.tools.Commands.exportdata; + + +import org.openecomp.core.tools.store.ElementCassandraLoader; +import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.nio.ByteBuffer; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Objects; + +import static java.io.File.separator; +import static java.nio.file.Files.*; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*; + +public class ElementHandler { + + private static final Logger logger = LoggerFactory.getLogger(ElementHandler.class); + + public ElementHandler() { + } + + public void loadElements(String filteredItem) { + ElementCassandraLoader elementCassandraLoader = new ElementCassandraLoader(); + elementCassandraLoader.list().forEach(elementEntity -> handleElementEntity(elementEntity,filteredItem)); + } + + private void handleElementEntity(ElementEntity elementEntity, String filteredItem) { + try { + String itemId = elementEntity.getItemId(); + if (filteredItem != null && !itemId.contains(filteredItem)){ + return; + } + String versionId = elementEntity.getVersionId(); + String space = elementEntity.getSpace(); + String namespace = elementEntity.getNamespace(); + String elementId = elementEntity.getElement_id(); + + String namespacePath = separator; + if (!isNull(namespace)){ + namespacePath = namespace.replace(ELEMENT_NAMESPACE_SPLITTER,separator)+separator; + } + Path elementDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId + + separator + versionId + separator + space + separator + namespacePath+ separator + elementId); + if (notExists(elementDirectoryPath)) { + createDirectories(elementDirectoryPath); + } + + String info = elementEntity.getInfo(); + if (!isNull(info)) { + Path infoFilePath = Paths.get(elementDirectoryPath.toString() + separator + ELEMENT_INFO_PREFIX + + elementId + JSON_POSTFIX); + write(infoFilePath, info.getBytes()); + } + + String relations = elementEntity.getRelations(); + if (!isNull(relations)) { + Path realtionsFilePath = Paths.get(elementDirectoryPath.toString() + separator + + ELEMENT_RELATION_PREFIX + elementId + JSON_POSTFIX); + write(realtionsFilePath, relations.getBytes()); + } + + ByteBuffer data = elementEntity.getData(); + if (!Objects.isNull(data)) { + Path dataFilePath = Paths.get(elementDirectoryPath.toString() + separator + + ELEMENT_DATA_PREFIX + elementId + JSON_POSTFIX); + write(dataFilePath, data.array()); + } + + ByteBuffer visualization = elementEntity.getVisualization(); + if (!Objects.isNull(visualization)) { + Path visualFilePath = Paths.get(elementDirectoryPath.toString() + separator + + ELEMENT_VISUALIZATION_PREFIX + elementId ); + write(visualFilePath, visualization.array()); + } + + ByteBuffer searchableData = elementEntity.getSearchableData(); + if (!Objects.isNull(searchableData)) { + Path searchableFilePath = Paths.get(elementDirectoryPath.toString() + separator + + ELEMENT_SEARCHABLE_PREFIX + elementId); + write(searchableFilePath, searchableData.array()); + } + + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + ex.printStackTrace(); + } + + } + + private boolean isNull(String inStr){ + if (Objects.isNull(inStr)){ + return true; + } + return inStr.trim().equalsIgnoreCase("null"); + } + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java new file mode 100644 index 0000000000..3b7566fd1b --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java @@ -0,0 +1,20 @@ +package org.openecomp.core.tools.Commands.exportdata; + +import java.io.File; + +public class ImportProperties { + public static final String VERSION_FILE_PREFIX = "version_"; + public static final String VERSION_INFO_FILE_PREFIX = "version_info_"; + public static final String JSON_POSTFIX = ".json"; + + public static final String ELEMENT_INFO_PREFIX = "elem_info"; + public static final String ELEMENT_RELATION_PREFIX = "elem_relations"; + public static final String ELEMENT_DATA_PREFIX = "elem_data"; + public static final String ELEMENT_VISUALIZATION_PREFIX = "elem_visualization"; + public static final String ELEMENT_SEARCHABLE_PREFIX = "elem_searchableData"; + public static final String ELEMENT_NAMESPACE_SPLITTER = "/"; + public static String ROOT_DIRECTORY; + public static final void initParams(){ + ROOT_DIRECTORY = System.getProperty("user.home")+File.separator+ "onboarding_import"; + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java new file mode 100644 index 0000000000..9eea182609 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java @@ -0,0 +1,62 @@ +package org.openecomp.core.tools.Commands.exportdata; + +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.Item; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDao; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDaoFactory; +import org.openecomp.core.tools.Commands.ExportDataCommand; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import static java.nio.file.Files.*; +import static java.io.File.separator; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*; + +public class ItemHandler { + private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class); + + + public ItemHandler() { + ImportProperties.initParams(); + } + + public void createItemsData(SessionContext context, String filteredItem) throws URISyntaxException, IOException { + + List items = getItemDao(context).list(context); + items.parallelStream().forEach(item -> createItemDirectoryAndFiles(item,filteredItem)); + + } + + private final void createItemDirectoryAndFiles(Item item,String filteredItem) { + try { + String itemId = item.getId().getValue(); + if (filteredItem != null && !itemId.contains(filteredItem)){ + return; + } + Path itemPath = Paths.get( ImportProperties.ROOT_DIRECTORY + separator + itemId); + Path itemFilePath = Paths.get( ImportProperties.ROOT_DIRECTORY + separator + + itemId + separator + itemId + JSON_POSTFIX); + if (notExists(itemPath)) { + createDirectories(itemPath); + } + String itemJson = JsonUtil.object2Json(item); + write(itemFilePath, itemJson.getBytes()); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + ex.printStackTrace(); + } + + } + + + private ItemDao getItemDao(SessionContext context) { + return ItemDaoFactory.getInstance().createInterface(context); + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java new file mode 100644 index 0000000000..b8d82958c9 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java @@ -0,0 +1,74 @@ +package org.openecomp.core.tools.Commands.exportdata; + +import org.openecomp.core.tools.Commands.ExportDataCommand; +import org.openecomp.core.tools.store.VersionInfoCassandraLoader; +import org.openecomp.core.tools.store.VersionCassandraLoader; + +import org.openecomp.core.tools.store.zusammen.datatypes.VersionEntity; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; + +import static java.io.File.separator; +import static java.nio.file.Files.*; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.ROOT_DIRECTORY; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class VersionHandler { + private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class); + + public VersionHandler() { + } + + public void loadVersions(String filteredItem) { + VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader(); + versionCassandraLoader.list().forEach(versionEntity -> handleVersionEntity(versionEntity,filteredItem)); + VersionInfoCassandraLoader versionInfoCassandraLoader = new VersionInfoCassandraLoader(); + versionInfoCassandraLoader.list().forEach(versionInfoEntity -> handleVersionInfo(versionInfoEntity,filteredItem)); + } + + private void handleVersionEntity(VersionEntity versionEntity, String filteredItem) { + try { + String itemId = versionEntity.getItemId(); + if (filteredItem != null && !itemId.contains(filteredItem)){ + return; + } + String versionId = versionEntity.getVersionId(); + String space = versionEntity.getSpace(); + Path versionDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId + + separator + versionId + separator + space); + Path versionFilePath = Paths.get(versionDirectoryPath.toString() + separator + VERSION_FILE_PREFIX + + versionId + JSON_POSTFIX); + if (notExists(versionDirectoryPath)) { + createDirectories(versionDirectoryPath); + } + String versionJson = JsonUtil.object2Json(versionEntity); + write(versionFilePath, versionJson.getBytes()); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + ex.printStackTrace(); + } + + } + + private void handleVersionInfo(VersionInfoEntity versionInfoEntity, String filteredItem) { + try { + String itemId = versionInfoEntity.getEntityId(); + Path itemDirectory = Paths.get( ROOT_DIRECTORY + separator + itemId); + Path versionInfoFilePath = Paths.get(itemDirectory.toString() + separator + VERSION_INFO_FILE_PREFIX + + itemId + JSON_POSTFIX); + if (exists(itemDirectory)) { + String versionJson = JsonUtil.object2Json(versionInfoEntity); + write(versionInfoFilePath, versionJson.getBytes()); + } + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + ex.printStackTrace(); + } + + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java new file mode 100644 index 0000000000..7ba830906c --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java @@ -0,0 +1,116 @@ +package org.openecomp.core.tools.Commands.importdata; + +import com.amdocs.zusammen.datatypes.SessionContext; +import org.openecomp.core.tools.store.ElementCassandraLoader; +import org.openecomp.core.tools.store.ElementNamespaceHandler; +import org.openecomp.core.tools.store.VersionCassandraLoader; +import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.io.File.separator; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*; + +public class ElementImport { + private static final Logger logger = LoggerFactory.getLogger(ElementImport.class); + private ElementCassandraLoader elementCassandraLoader = new ElementCassandraLoader(); + private ElementNamespaceHandler cassandraElementRepository = new ElementNamespaceHandler(); + private VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader(); + + public void loadPath(SessionContext sessionContext, Path elementDir, String elementId, String[] pathObjects) { + try { + // load info file + ElementEntity elementEntity = new ElementEntity(); + Path infoFilePath = Paths.get(elementDir.toString() + separator + ELEMENT_INFO_PREFIX + + elementId + JSON_POSTFIX); + if (Files.exists(infoFilePath)) { + String info = new String(Files.readAllBytes(infoFilePath)); + elementEntity.setInfo(info); + } + + // load relation file + Path realtionsFilePath = Paths.get(elementDir.toString() + separator + + ELEMENT_RELATION_PREFIX + elementId + JSON_POSTFIX); + if (Files.exists(realtionsFilePath)) { + String relations = new String(Files.readAllBytes(realtionsFilePath)); + elementEntity.setRelations(relations); + } + + //load entity data + Path dataFilePath = Paths.get(elementDir.toString() + separator + + ELEMENT_DATA_PREFIX + elementId + JSON_POSTFIX); + if (Files.exists(dataFilePath)) { + byte[] bytes = Files.readAllBytes(dataFilePath); + ByteBuffer data = ByteBuffer.wrap(bytes); + elementEntity.setData(data); + } + + //load visualization + Path visualFilePath = Paths.get(elementDir.toString() + separator + + ELEMENT_VISUALIZATION_PREFIX + elementId ); + if (Files.exists(visualFilePath)) { + byte[] bytes = Files.readAllBytes(visualFilePath); + ByteBuffer visualization = ByteBuffer.wrap(bytes); + elementEntity.setVisualization(visualization); + } + + //load searchable + Path searchableFilePath = Paths.get(elementDir.toString() + separator + + ELEMENT_SEARCHABLE_PREFIX + elementId ); + if (Files.exists(searchableFilePath)) { + byte[] bytes = Files.readAllBytes(searchableFilePath); + ByteBuffer searchable = ByteBuffer.wrap(bytes); + elementEntity.setSearchableData(searchable); + } + + elementEntity.setSpace(pathObjects[2]); + elementEntity.setItemId(pathObjects[0]); + elementEntity.setVersionId(pathObjects[1]); + elementEntity.setElement_id(pathObjects[pathObjects.length - 1]); + elementEntity.setNamespace(getNameSpace(pathObjects)); + elementEntity.setParentId(getParentId(pathObjects)); + elementEntity.setSubElementIds(getAllSubElementsIds(elementDir)); + elementCassandraLoader.createEntity(elementEntity); + cassandraElementRepository.createElementNamespace(elementEntity); + versionCassandraLoader.insertElementToVersion(elementEntity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + + private String getParentId(String[] pathObjects) { + if (pathObjects.length <= 4) { + return null; + } + return pathObjects[pathObjects.length - 2]; + } + + private Set getAllSubElementsIds(Path root) throws IOException { + try (Stream walk = Files.walk(root)) { + return walk.filter(path -> Files.isDirectory(path)) + .map(path -> path.toFile().getName() ).collect(Collectors.toSet()); + } + } + + private String getNameSpace(String[] pathObjects) { + if (pathObjects.length <= 4) { + return null; + } + if (pathObjects.length == 5) { + return pathObjects[3]; + } + return Arrays.stream(pathObjects, 3, pathObjects.length - 1) + .reduce("", (s1, s2) -> s1 + File.separator + s2); + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java new file mode 100644 index 0000000000..c7042743c2 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java @@ -0,0 +1,42 @@ +package org.openecomp.core.tools.Commands.importdata; + +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.Item; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDao; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDaoFactory; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.JSON_POSTFIX; + +public class ItemImport { + private static final Logger logger = LoggerFactory.getLogger(ItemImport.class); + + public void loadPath(SessionContext sessionContext, Path itemDir, String itemName) { + try { + Path itemPath = Paths.get(itemDir.toString() + File.separator + itemName + JSON_POSTFIX); + if (!Files.exists(itemPath)) { + return; + } + String itemJson = new String(Files.readAllBytes(itemPath)); + if (itemJson == null || itemJson.trim().isEmpty()) { + return; + } + Item item = JsonUtil.json2Object(itemJson, Item.class); + ItemDao itemDao = getItemDao(sessionContext); + itemDao.create(sessionContext, item.getId(), item.getInfo(), item.getCreationTime()); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + + private ItemDao getItemDao(SessionContext context) { + return ItemDaoFactory.getInstance().createInterface(context); + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java new file mode 100644 index 0000000000..020b2f3c47 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java @@ -0,0 +1,51 @@ +package org.openecomp.core.tools.Commands.importdata; + +import com.amdocs.zusammen.datatypes.SessionContext; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.stream.Stream; + +public class TreeWalker { + private static final Logger logger = LoggerFactory.getLogger(TreeWalker.class); + + public static final void walkFiles(SessionContext sessionContext,Path rootDir, String filterItem) throws IOException { + try (Stream walk = Files.walk(rootDir)) { + walk.parallel().filter(path -> Files.isDirectory(path)). + forEach(path -> handlePath(sessionContext,path, rootDir, filterItem)); + } + } + + private static final void handlePath(SessionContext sessionContext, Path path, Path root,String filterItem) { + String logicalPath = path.toString().replace(root.toString()+File.separator, ""); + String[] splitted = logicalPath.split(File.separator); + if(filterItem != null && splitted.length > 0 && !splitted[0].contains(filterItem)){ + return; + } + switch (splitted.length) { + case 0: + //root - ignore + break; + case 1: // handle Item + new ItemImport().loadPath(sessionContext,path,splitted[splitted.length -1]); + new VersionInfoImport().loadPath(sessionContext,path,splitted[splitted.length -1]); + break; + case 2: + //ignore this level + break; + case 3: // handle version + new VersionImport().loadPath(sessionContext,path,splitted[splitted.length -2]); + break; + default: + //handle elements + new ElementImport().loadPath(sessionContext,path,splitted[splitted.length -1],splitted); + break; + } + + } + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java new file mode 100644 index 0000000000..8f6c67d212 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java @@ -0,0 +1,41 @@ +package org.openecomp.core.tools.Commands.importdata; + +import com.amdocs.zusammen.datatypes.SessionContext; +import org.openecomp.core.tools.store.VersionCassandraLoader; +import org.openecomp.core.tools.store.zusammen.datatypes.VersionEntity; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static java.io.File.separator; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.JSON_POSTFIX; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.VERSION_FILE_PREFIX; + +public class VersionImport { + private static final Logger logger = LoggerFactory.getLogger(VersionImport.class); + + public void loadPath(SessionContext sessionContext, Path versionDir , String versionId){ + try { + Path versionPath = Paths.get(versionDir.toString() + separator + VERSION_FILE_PREFIX + + versionId + JSON_POSTFIX); + if (!Files.exists(versionPath)) { + return; + } + String versionJson = new String(Files.readAllBytes(versionPath)); + if (versionJson == null || versionJson.trim().isEmpty()) { + return; + } + VersionEntity versionEntity = JsonUtil.json2Object(versionJson, VersionEntity.class); + VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader(); + versionCassandraLoader.insertVersion(versionEntity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java new file mode 100644 index 0000000000..5da7407c9f --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java @@ -0,0 +1,41 @@ +package org.openecomp.core.tools.Commands.importdata; + +import com.amdocs.zusammen.datatypes.SessionContext; +import org.openecomp.core.tools.store.VersionInfoCassandraLoader; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static java.io.File.separator; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.JSON_POSTFIX; +import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.VERSION_INFO_FILE_PREFIX; + +public class VersionInfoImport { + private static final Logger logger = LoggerFactory.getLogger(VersionInfoImport.class); + + public void loadPath(SessionContext sessionContext, Path itemPath, String itemId) { + try { + Path versionInfoFilePath = Paths.get(itemPath.toString() + separator + VERSION_INFO_FILE_PREFIX + + itemId + JSON_POSTFIX); + if (!Files.exists(versionInfoFilePath)) { + return; + } + String versionInfoJson = new String(Files.readAllBytes(versionInfoFilePath)); + if (versionInfoJson == null || versionInfoJson.trim().isEmpty()) { + return; + } + VersionInfoEntity versionInfoEntity = JsonUtil.json2Object(versionInfoJson, VersionInfoEntity.class); + VersionInfoCassandraLoader versionInfoCassandraLoader = new VersionInfoCassandraLoader(); + versionInfoCassandraLoader.insertVersionInfo(versionInfoEntity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java index 7bc4bb23fb..926566864f 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java @@ -2,6 +2,8 @@ package org.openecomp.core.tools.main; import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.UserInfo; +import org.openecomp.core.tools.Commands.ImportCommand; +import org.openecomp.core.tools.Commands.ExportDataCommand; import org.openecomp.core.tools.Commands.ResetOldVersion; import org.openecomp.core.tools.util.ToolsUtil; import org.openecomp.sdc.logging.api.Logger; @@ -23,8 +25,8 @@ public class ZusammenMainTool { String command = ToolsUtil.getParam("c",args); if(command == null){ printMessage(logger, - "parameter -c is mandatory. script usage: zusammenMainTool.sh -c {command name} " + - "[additional arguments depending on the command] "); + "parameter -c is mandatory. script usage: zusammenMainTool.sh -c {command name} " + + "[additional arguments depending on the command] "); System.exit(-1); } Instant startTime = Instant.now(); @@ -39,8 +41,10 @@ public class ZusammenMainTool { ResetOldVersion.reset(context,ToolsUtil.getParam("v",args)); break; case EXPORT: + ExportDataCommand.exportData(context,ToolsUtil.getParam("i",args)); break; case IMPORT: + ImportCommand.importData(context, ToolsUtil.getParam("f",args),ToolsUtil.getParam("i",args)); break; } @@ -52,9 +56,9 @@ public class ZusammenMainTool { printMessage(logger, - "Zusammen tools command:[] finished . Total run time was : " + minutesPart + ":" + - secondsPart - + " minutes"); + "Zusammen tools command:[] finished . Total run time was : " + minutesPart + ":" + + secondsPart + + " minutes"); System.exit(status); } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java new file mode 100644 index 0000000000..1c7e185e18 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.tools.store; + +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import com.datastax.driver.mapping.annotations.QueryParameters; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity; + +import java.nio.ByteBuffer; +import java.util.Set; + +public class ElementCassandraLoader { + + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static Mapper mapper = noSqlDb.getMappingManager().mapper(ElementEntity.class); + private static ElementAccessor accessor = noSqlDb.getMappingManager().createAccessor(ElementAccessor.class); + private String[] columns = {"space", "item_id", "version_id", "element_id", "data", "info", "namespace", "parent_id", + "relations", "searchable_data", "sub_element_ids"}; + + + public void createEntity(ElementEntity elementEntity) { + accessor.insertElement(elementEntity.getSpace(), + elementEntity.getItemId(), + elementEntity.getVersionId(), + elementEntity.getElement_id(), + elementEntity.getData(), + elementEntity.getInfo(), + elementEntity.getNamespace(), + elementEntity.getParentId(), + elementEntity.getRelations(), + elementEntity.getSearchableData(), + elementEntity.getSubElementIds()); + } + + public Result list() { + return accessor.getAll(); + } + + @Accessor + interface ElementAccessor { + + @Query("insert into zusammen_dox.element (space,item_id,version_id,element_id,data,info,namespace,parent_id,relations,searchable_data,sub_element_ids) values (?,?,?,?,?,?,?,?,?,?,?)") + void insertElement(String space, String itemId, String versionId, String elementId, ByteBuffer data, String info, String namespaceStr, + String parentId, String relations, ByteBuffer searchable, Set subElementsIds); + + + @Query("select * from zusammen_dox.element ") + @QueryParameters(fetchSize = 100) + Result getAll(); + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java new file mode 100644 index 0000000000..f1ed970b4d --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java @@ -0,0 +1,27 @@ +package org.openecomp.core.tools.store; + + +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Param; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity; + +public class ElementNamespaceHandler { + + private static NoSqlDb nnoSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static ElementNamespaceAccessor accessor = nnoSqlDb.getMappingManager().createAccessor(ElementNamespaceAccessor.class); + + public void createElementNamespace(ElementEntity elementEntity) { + accessor.create(elementEntity.getSpace(),elementEntity.getItemId(),elementEntity.getElement_id(),elementEntity.getNamespace()); + } + + @Accessor + interface ElementNamespaceAccessor { + @Query("UPDATE zusammen_dox.element_namespace SET namespace=:ns WHERE space=:space AND item_id=:item AND element_id=:id ") + void create(@Param("space") String space, @Param("item") String item, @Param("id") String id, @Param("ns") String ns); + } + + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java new file mode 100644 index 0000000000..851e92dcca --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.tools.store; + +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import com.datastax.driver.mapping.annotations.QueryParameters; +import com.google.common.collect.Sets; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity; +import org.openecomp.core.tools.store.zusammen.datatypes.VersionEntity; + +import java.util.Date; +import java.util.Set; + +public class VersionCassandraLoader { + + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static Mapper mapper = noSqlDb.getMappingManager().mapper(VersionEntity.class); + private static VersionAccessor accessor = noSqlDb.getMappingManager().createAccessor(VersionAccessor.class); + + public void insertElementToVersion(ElementEntity elementEntity) { + accessor.addElements(Sets.newHashSet(elementEntity.getElement_id()), elementEntity.getSpace(), elementEntity.getItemId(), elementEntity.getVersionId()); + } + + public void insertVersion(VersionEntity versionEntity) { + accessor.insertVersion( versionEntity.getSpace(), + versionEntity.getItemId(), + versionEntity.getVersionId(), + versionEntity.getBaseVersionId(), + versionEntity.getCreationTime(), + versionEntity.getInfo(), + versionEntity.getModificationTime(), + versionEntity.getRelations()); + } + + + public Result list() { + return accessor.getAll(); + } + + @Accessor + interface VersionAccessor { + + @Query("UPDATE zusammen_dox.version_elements SET element_ids=element_ids+? " + + "WHERE space=? AND item_id=? AND version_id=?") + void addElements(Set elementIds, String space, String itemId, String versionId); + + @Query("insert into zusammen_dox.version (space,item_id,version_id,base_version_id,creation_time,info,modification_time,relations) values (?,?,?,?,?,?,?,?)") + void insertVersion(String space, String itemId, String versionId, String baseVersionId, Date createTime, String info, Date modificationTime, String relations); + + + @Query("select * from zusammen_dox.version ") + @QueryParameters(fetchSize = 400) + Result getAll(); + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java new file mode 100644 index 0000000000..d7ec93962c --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.core.tools.store; + +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import com.datastax.driver.mapping.annotations.QueryParameters; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.versioning.dao.VersionInfoDao; +import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory; +import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; + +import java.util.Collection; + +public class VersionInfoCassandraLoader { + + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static Mapper mapper = + noSqlDb.getMappingManager().mapper(VersionInfoEntity.class); + private static VersionInfoAccessor accessor = + noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class); + private static VersionInfoDao versionInfoDao = + VersionInfoDaoFactory.getInstance().createInterface(); + + public void insertVersionInfo(VersionInfoEntity versionInfoEntity) { + versionInfoDao.create(versionInfoEntity); + } + + public Collection list() { + return accessor.getAll().all(); + } + + @Accessor + interface VersionInfoAccessor { + @Query("select * from dox.version_info ") + @QueryParameters(fetchSize = 400) + Result getAll(); + } + + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java new file mode 100644 index 0000000000..54a3dd9ada --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java @@ -0,0 +1,40 @@ +package org.openecomp.core.tools.store; + +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext; +import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository; +import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class VspGeneralLoader { + public static Map load(SessionContext context, + Map> vspItemVersionsMap) { + Map elementEntityMap = new HashMap<>(); + System.setProperty("cassandra.dox.keystore", "zusammen_dox"); + CassandraElementRepository cassandraElementRepository = new CassandraElementRepository(); + for (Map.Entry> entry : vspItemVersionsMap.entrySet()) { + + for (String version : entry.getValue()) { + + Optional result = + cassandraElementRepository.get(context, new ElementEntityContext( + context.getUser().getUserName(), + new Id(entry.getKey()), + new Id(version)), + new ElementEntity(new Id(StructureElement.General.name()))); + if (result.isPresent()) { + elementEntityMap.put(context.getUser().getUserName() + "_" + entry.getKey() + + "_" + version, result.get()); + } + } + } + + return elementEntityMap; + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java new file mode 100644 index 0000000000..f4f450db70 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java @@ -0,0 +1,168 @@ +package org.openecomp.core.tools.store.zusammen.datatypes; + +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; + +import java.nio.ByteBuffer; +import java.util.Set; + +/** + * CREATE TABLE zusammen_dox.element ( + * space text, + * item_id text, + * version_id text, + * element_id text, + * data blob, + * info text, + * namespace text, + * parent_id text, + * relations text, + * searchable_data blob, + * sub_element_ids set, + * visualization blob, + * PRIMARY KEY ((space, item_id, version_id, element_id)) + * ) + */ +@Table( + keyspace = "zusammen_dox", + name = "version" +) +public class ElementEntity { + @Column( name = "space" ) + @PartitionKey(0) + private String space; + + @Column( name = "item_id" ) + @PartitionKey(1) + private String itemId; + + @Column( name = "version_id" ) + @PartitionKey(2) + private String versionId; + + @Column(name = "element_id") + @PartitionKey(3) + private String element_id; + + @Column(name = "data") + private ByteBuffer data; + + @Column(name = "info") + private String info; + + @Column(name = "namespace") + private String namespace; + + @Column(name = "parent_id") + private String parentId; + + @Column(name = "relations") + private String relations; + + @Column(name = "searchable_data") + private ByteBuffer searchableData; + + @Column(name = "sub_element_ids") + private Set subElementIds; + + + @Column(name = "visualization") + private ByteBuffer visualization; + + public String getSpace() { + return space; + } + + public void setSpace(String space) { + this.space = space; + } + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getVersionId() { + return versionId; + } + + public void setVersionId(String versionId) { + this.versionId = versionId; + } + + public String getElement_id() { + return element_id; + } + + public void setElement_id(String element_id) { + this.element_id = element_id; + } + + public ByteBuffer getData() { + return data; + } + + public void setData(ByteBuffer data) { + this.data = data; + } + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public String getParentId() { + return parentId; + } + + public void setParentId(String parentId) { + this.parentId = parentId; + } + + public String getRelations() { + return relations; + } + + public void setRelations(String relations) { + this.relations = relations; + } + + public ByteBuffer getSearchableData() { + return searchableData; + } + + public void setSearchableData(ByteBuffer searchableData) { + this.searchableData = searchableData; + } + + public Set getSubElementIds() { + return subElementIds; + } + + public void setSubElementIds(Set subElementIds) { + this.subElementIds = subElementIds; + } + + public ByteBuffer getVisualization() { + return visualization; + } + + public void setVisualization(ByteBuffer visualization) { + this.visualization = visualization; + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java new file mode 100644 index 0000000000..c7280c8a9d --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java @@ -0,0 +1,128 @@ +package org.openecomp.core.tools.store.zusammen.datatypes; + +import com.datastax.driver.mapping.annotations.*; + +import java.util.Date; + +/** + * CREATE TABLE zusammen_dox.version ( + * space text, + * item_id text, + * version_id text, + * base_version_id text, + * creation_time timestamp, + * info text, + * modification_time timestamp, + * relations text, + * PRIMARY KEY ((space, item_id), version_id) + * ) WITH CLUSTERING ORDER BY (version_id ASC) + * AND bloom_filter_fp_chance = 0.01 + * AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}' + * AND comment = '' + * AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'} + * AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'} + * AND dclocal_read_repair_chance = 0.1 + * AND default_time_to_live = 0 + * AND gc_grace_seconds = 864000 + * AND max_index_interval = 2048 + * AND memtable_flush_period_in_ms = 0 + * AND min_index_interval = 128 + * AND read_repair_chance = 0.0 + * AND speculative_retry = '99.0PERCENTILE'; + */ +@Table( + keyspace = "zusammen_dox", + name = "version" +) +public class VersionEntity { + @Column(name = "space") + @PartitionKey(0) + private String space; + + @Column(name = "item_id") + @PartitionKey(1) + private String itemId; + + @Column(name = "version_id") + @PartitionKey(2) + private String versionId; + + @Column(name = "base_version_id") + private String baseVersionId; + + @Column(name = "creation_time") + private Date creationTime; + + @Column(name = "info") + private String info; + + @Column(name = "modification_time") + private Date modificationTime; + + @Column(name = "relations") + private String relations; + + public String getSpace() { + return space; + } + + public void setSpace(String space) { + this.space = space; + } + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getVersionId() { + return versionId; + } + + public void setVersionId(String versionId) { + this.versionId = versionId; + } + + public String getBaseVersionId() { + return baseVersionId; + } + + public void setBaseVersionId(String baseVersionId) { + this.baseVersionId = baseVersionId; + } + + public Date getCreationTime() { + return creationTime; + } + + public void setCreationTime(Date creationTime) { + this.creationTime = creationTime; + } + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } + + public Date getModificationTime() { + return modificationTime; + } + + public void setModificationTime(Date modificationTime) { + this.modificationTime = modificationTime; + } + + public String getRelations() { + return relations; + } + + public void setRelations(String relations) { + this.relations = relations; + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java new file mode 100644 index 0000000000..6447f85ea7 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java @@ -0,0 +1,89 @@ +package org.openecomp.core.tools.util; + +import com.google.common.io.ByteStreams; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Objects; +import java.util.Scanner; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +public class ZipUtils { + public static void createZip(String zipFileName, Path dir, String filterItem) throws Exception { + File dirObj = dir.toFile(); + try ( + FileOutputStream fileOutputStream = new FileOutputStream(zipFileName); + ZipOutputStream out = new ZipOutputStream(fileOutputStream)) { + addDir(dirObj, out, dir.toString(), filterItem); + } + } + + public static final String cleanStr(String inFilterStr) { + if (Objects.isNull(inFilterStr)) { + return inFilterStr; + } + Scanner scan = new Scanner(inFilterStr); + while (scan.hasNextLine()) { + inFilterStr = scan.nextLine().replaceAll("[^a-zA-Z0-9]", ""); + } + return inFilterStr; + } + + static void addDir(File dirObj, ZipOutputStream out, String root, String filterItem) throws IOException { + File[] files = dirObj.listFiles(); + filterItem = cleanStr(filterItem); + + for (int i = 0; i < files.length; i++) { + if (files[i].isDirectory()) { + addDir(files[i], out, root, filterItem); + continue; + } + try (FileInputStream in = new FileInputStream((files[i].getAbsolutePath()))) { + String filePath = files[i].getAbsolutePath().replace(root + File.separator, ""); + if (filterItem == null || filePath.contains(filterItem)) { + out.putNextEntry(new ZipEntry(filePath)); + try { + ByteStreams.copy(in, out); + + } finally { + out.closeEntry(); + } + } + + } + } + } + + public static void unzip(Path zipFile, Path outputFolder) throws IOException { + if (zipFile == null || outputFolder == null) { + return; + } + if (!Files.exists(outputFolder)) { + Files.createDirectories(outputFolder); + } + + try (FileInputStream fileInputStream = new FileInputStream(zipFile.toFile()); + ZipInputStream zis = new ZipInputStream(fileInputStream)) { + ZipEntry ze = zis.getNextEntry(); + while (ze != null) { + String fileName = ze.getName(); + File newFile = new File(outputFolder.toString() + File.separator + fileName); + new File(newFile.getParent()).mkdirs(); + try (FileOutputStream fos = new FileOutputStream(newFile)) { + ByteStreams.copy(zis, fos); + } + ze = zis.getNextEntry(); + } + + zis.closeEntry(); + } + + } +} + diff --git a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh index c274d84424..da043b130d 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh +++ b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh @@ -10,7 +10,5 @@ # change exist package and service templates in db -java -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=/apps/jetty/base/be/config/catalog-be/configuration.yaml -jar openecomp-zusammen-tools-1.0-SNAPSHOT.jar org.openecomp.core.tools.main.ZusammenMainTool $1 $2 $3 $4 - -STATUS="${?}" echo "${STATUS}" echo "All log messages for the zusammenMainTool -migration process are in /apps/jetty/base/be/logs/ASDC/ASDC-BE/zusammen_tool_debug.log" +java -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=/apps/jetty/base/be/config/catalog-be/configuration.yaml -jar openecomp-zusammen-tools-1.0-SNAPSHOT.jar org.openecomp.core.tools.main.ZusammenMainTool $1 $2 $3 $4 $5 $6 +STATUS="${?}" echo "${STATUS}" echo "All log messages for the zusammenMainTool migration process are in /apps/jetty/base/be/logs/ASDC/ASDC-BE/zusammen_tool_debug.log" diff --git a/pom.xml b/pom.xml index c0767d17ca..b566c36721 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ 1.1.0-SNAPSHOT 1.1.0-SNAPSHOT 1.1.0-SNAPSHOT + org.openecomp.sdc.common 1.1.0-SNAPSHOT @@ -86,6 +87,9 @@ 4.12 6.9.10 3.0.3 + + + 1.1.14-SNAPSHOT jacoco ${project.basedir}/target/jacoco.exec @@ -377,9 +381,12 @@ 1.2.7 1707.0.1-SNAPSHOT 1707.0.1-SNAPSHOT + org.openecomp.common 1707.0.0-SNAPSHOT + 1.1.14 + @@ -407,7 +414,9 @@ 1.2.7 1707.0.1-SNAPSHOT 1707.0.1-SNAPSHOT + org.openecomp.common 1707.0.0-SNAPSHOT + 1.1.14 diff --git a/test-apis-ci/pom.xml b/test-apis-ci/pom.xml index ec8eab07d3..80297c570e 100644 --- a/test-apis-ci/pom.xml +++ b/test-apis-ci/pom.xml @@ -280,7 +280,7 @@ org.openecomp.sdc.sdc-distribution-client sdc-tosca-parser - 1.1.9-SNAPSHOT + ${sdc-tosca-parser.version} compile diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/AndreyTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/AndreyTest.java index 8a5fe91065..6e36e1b675 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/AndreyTest.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/AndreyTest.java @@ -82,21 +82,45 @@ public class AndreyTest { long startTime = System.currentTimeMillis(); long estimatedTime = System.currentTimeMillis() - startTime; System.out.println("Time to init factory " + estimatedTime); - String fileStr1 = "src//test//resources//CI//csars//service-ServiceFdnt-csar-0904-2.csar";//ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-0904-2.csar").getFile(); + String fileStr1 = "C:\\Users\\ys9693\\NewDownload\\2016-006_vvm_vvm_30_1607_e2e.zip.csar";//ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-0904-2.csar").getFile(); File file1 = new File(fileStr1); String name = file1.getName(); String absolutePath = file1.getAbsolutePath(); ISdcCsarHelper fdntCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); List serviceVfList = fdntCsarHelper.getServiceVfList(); - serviceVfList.size(); + System.out.println("serviceVfList----->" + serviceVfList); + + List serviceNodeTemplatesByTypeVF = fdntCsarHelper.getServiceNodeTemplatesByType("VF"); + System.out.println("serviceNodeTemplatesByTypeVF----->" + serviceNodeTemplatesByTypeVF); + List serviceNodeTemplatesByTypeVFC = fdntCsarHelper.getServiceNodeTemplatesByType("VFC"); + System.out.println("serviceNodeTemplatesByTypeVFC -------->" + serviceNodeTemplatesByTypeVFC); + List serviceNodeTemplatesByTypeVL = fdntCsarHelper.getServiceNodeTemplatesByType("VL"); + System.out.println("serviceNodeTemplatesByTypeVL------>" +serviceNodeTemplatesByTypeVL); + List serviceNodeTemplatesByTypeCP = fdntCsarHelper.getServiceNodeTemplatesByType("CP"); + System.out.println("serviceNodeTemplatesByTypeCP ---------->" + serviceNodeTemplatesByTypeCP); + + System.out.println("getMetaData"+ serviceVfList.get(0).getMetaData()); + System.out.println("UUID"+ serviceVfList.get(0).getMetaData().getValue("UUID")); + System.out.println("customizationUUID"+ serviceVfList.get(0).getMetaData().getValue("customizationUUID")); + System.out.println("serviceVfList.size()------->"+ serviceVfList.size()); + System.out.println("getCpListByVf--------->" + fdntCsarHelper.getCpListByVf(serviceVfList.get(0).getMetaData().getValue("customizationUUID"))); + List vfcListByVf = fdntCsarHelper.getVfcListByVf(serviceVfList.get(0).getMetaData().getValue("customizationUUID")); + System.out.println("getVfcListByVf--------->" + vfcListByVf); + for (NodeTemplate nodeTemplate : vfcListByVf) { + + System.out.println("----> getCpPropertiesFromVfc--------->" + fdntCsarHelper.getCpPropertiesFromVfc(nodeTemplate)); + } + for (NodeTemplate nodeTemplate : serviceVfList) { + System.out.println("NodeName---->"+nodeTemplate.getName()); + System.out.println("getTypeOfNodeTemplate--------->" + fdntCsarHelper.getTypeOfNodeTemplate(nodeTemplate)); + System.out.println("getServiceInputLeafValueOfDefault--------->" + fdntCsarHelper.getServiceInputLeafValueOfDefault(serviceVfList.get(0).getMetaData().getValue("customizationUUID"))); + System.out.println("getVfModulesByVf--------->" + fdntCsarHelper.getVfModulesByVf(nodeTemplate.getMetaData().getValue("customizationUUID"))); ArrayList requirements = nodeTemplate.getRequirements(); requirements.size(); LinkedHashMap capabilities = nodeTemplate.getCapabilities(); ArrayList requirements2 = nodeTemplate.getRequirements(); - - System.out.println(nodeTemplate.getName()); } } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/validation/AuditValidationUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/validation/AuditValidationUtils.java index 7a5b7bb546..f4d9fe3f35 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/validation/AuditValidationUtils.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/validation/AuditValidationUtils.java @@ -91,13 +91,20 @@ public class AuditValidationUtils { } - public static String buildAuditDescription(ErrorInfo errorInfo, List variables) { + public static String buildAuditDescription(ErrorInfo errorInfo, List errorVariablesList) { String auditDesc = errorInfo.getMessageId() + ": " + errorInfo.getMessage(); - if(! variables.isEmpty() && variables.get(0) != null && ! variables.get(0).isEmpty()){ - for (int i = 0; i < variables.size(); i++) { +// if(! variables.isEmpty() && variables.get(0) != null && ! variables.get(0).isEmpty()){ +// for (int i = 0; i < variables.size(); i++) { +// if (auditDesc.contains("%" + (i + 1))) { +// auditDesc = auditDesc.replace("%" + (i + 1), variables.get(i)); +// } +// } +// } + if(! errorVariablesList.isEmpty() && errorVariablesList.get(0) != null){ + for (int i = 0; i < errorVariablesList.size(); i++) { if (auditDesc.contains("%" + (i + 1))) { - auditDesc = auditDesc.replace("%" + (i + 1), variables.get(i)); + auditDesc = auditDesc.replace("%" + (i + 1), errorVariablesList.get(i)); } } } diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/externalApis/CRUDExternalAPI.java b/test-apis-ci/src/main/java/org/openecomp/sdc/externalApis/CRUDExternalAPI.java index 0ba357e890..a680990af8 100644 --- a/test-apis-ci/src/main/java/org/openecomp/sdc/externalApis/CRUDExternalAPI.java +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/externalApis/CRUDExternalAPI.java @@ -129,7 +129,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { super(name, CRUDExternalAPI.class.getName()); } - @DataProvider(name="uploadArtifactOnVfcVlCpViaExternalAPI" , parallel=false) + @DataProvider(name="uploadArtifactOnVfcVlCpViaExternalAPI" , parallel=true) public static Object[][] dataProviderUploadArtifactOnVfcVlCpViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "YANG_XML", ResourceTypeEnum.VFC}, @@ -232,7 +232,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { uploadArtifactOnAssetViaExternalAPI(ComponentTypeEnum.RESOURCE, chosenLifeCycleState, artifactType, resourceTypeEnum); } - @DataProvider(name="uploadArtifactOnVFViaExternalAPI", parallel=false) + @DataProvider(name="uploadArtifactOnVFViaExternalAPI", parallel=true) public static Object[][] dataProviderUploadArtifactOnVFViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_JSON"}, @@ -288,7 +288,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="uploadArtifactOnServiceViaExternalAPI" , parallel=false) + @DataProvider(name="uploadArtifactOnServiceViaExternalAPI" , parallel=true) public static Object[][] dataProviderUploadArtifactOnServiceViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "YANG_XML"}, @@ -317,7 +317,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="uploadArtifactOnServiceViaExternalAPIIncludingDistribution", parallel=false) + @DataProvider(name="uploadArtifactOnServiceViaExternalAPIIncludingDistribution", parallel=true) public static Object[][] dataProviderUploadArtifactOnServiceViaExternalAPIIncludingDistribution() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "YANG_XML"}, @@ -587,7 +587,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="uploadArtifactOnRIViaExternalAPI", parallel=false) + @DataProvider(name="uploadArtifactOnRIViaExternalAPI", parallel=true) public static Object[][] dataProviderUploadArtifactOnRIViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_INVENTORY_TOSCA"}, @@ -633,7 +633,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="uploadArtifactOnVfcVlCpRIViaExternalAPI", parallel=false) + @DataProvider(name="uploadArtifactOnVfcVlCpRIViaExternalAPI", parallel=true) public static Object[][] dataProviderUploadArtifactOnVfcVlCpRIViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_INVENTORY_TOSCA", ResourceTypeEnum.VFC}, @@ -735,7 +735,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="uploadInvalidArtifactTypeExtensionLabelDescriptionCheckSumDuplicateLabelViaExternalAPI", parallel=false) + @DataProvider(name="uploadInvalidArtifactTypeExtensionLabelDescriptionCheckSumDuplicateLabelViaExternalAPI", parallel=true) public static Object[][] dataProviderUploadInvalidArtifactTypeExtensionLabelDescriptionCheckSumDuplicateLabelViaExternalAPI() { return new Object[][] { @@ -821,13 +821,13 @@ public class CRUDExternalAPI extends ComponentBaseTest { {LifeCycleStatesEnum.CHECKOUT, ComponentTypeEnum.RESOURCE, "uploadArtifactWithSameLabel"}, {LifeCycleStatesEnum.CHECKOUT, ComponentTypeEnum.SERVICE, "uploadArtifactWithSameLabel"}, - {LifeCycleStatesEnum.CHECKOUT, ComponentTypeEnum.RESOURCE_INSTANCE, "uploadArtifactWithSameLabel"}, +// DE306360 {LifeCycleStatesEnum.CHECKOUT, ComponentTypeEnum.RESOURCE_INSTANCE, "uploadArtifactWithSameLabel"}, {LifeCycleStatesEnum.CHECKIN, ComponentTypeEnum.RESOURCE, "uploadArtifactWithSameLabel"}, {LifeCycleStatesEnum.CHECKIN, ComponentTypeEnum.SERVICE, "uploadArtifactWithSameLabel"}, - {LifeCycleStatesEnum.CHECKIN, ComponentTypeEnum.RESOURCE_INSTANCE, "uploadArtifactWithSameLabel"}, +// DE306360 {LifeCycleStatesEnum.CHECKIN, ComponentTypeEnum.RESOURCE_INSTANCE, "uploadArtifactWithSameLabel"}, {LifeCycleStatesEnum.CERTIFICATIONREQUEST, ComponentTypeEnum.RESOURCE, "uploadArtifactWithSameLabel"}, {LifeCycleStatesEnum.CERTIFICATIONREQUEST, ComponentTypeEnum.SERVICE, "uploadArtifactWithSameLabel"}, - {LifeCycleStatesEnum.CERTIFICATIONREQUEST, ComponentTypeEnum.RESOURCE_INSTANCE, "uploadArtifactWithSameLabel"}, +// DE306360 {LifeCycleStatesEnum.CERTIFICATIONREQUEST, ComponentTypeEnum.RESOURCE_INSTANCE, "uploadArtifactWithSameLabel"}, {LifeCycleStatesEnum.CHECKOUT, ComponentTypeEnum.RESOURCE, "uploadArtifactWithInvalidCheckSum"}, {LifeCycleStatesEnum.CHECKOUT, ComponentTypeEnum.SERVICE, "uploadArtifactWithInvalidCheckSum"}, @@ -1140,7 +1140,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="uploadArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset", parallel=false) + @DataProvider(name="uploadArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset", parallel=true) public static Object[][] dataProviderUploadArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset() { return new Object[][] { {ComponentTypeEnum.RESOURCE, UserRoleEnum.DESIGNER2, LifeCycleStatesEnum.CHECKOUT}, @@ -1223,7 +1223,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="uploadArtifactOnAssetWhichNotExist", parallel=false) + @DataProvider(name="uploadArtifactOnAssetWhichNotExist", parallel=true) public static Object[][] dataProviderUploadArtifactOnAssetWhichNotExist() { return new Object[][] { {ComponentTypeEnum.SERVICE}, @@ -1273,7 +1273,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="uploadArtifactOnAssetWhichInInvalidStateForUploading", parallel=false) + @DataProvider(name="uploadArtifactOnAssetWhichInInvalidStateForUploading", parallel=true) public static Object[][] dataProviderUploadArtifactOnAssetWhichInInvalidStateForUploading() { return new Object[][] { {ComponentTypeEnum.SERVICE}, @@ -1318,7 +1318,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// - @DataProvider(name="updateArtifactForServiceViaExternalAPI", parallel=false) + @DataProvider(name="updateArtifactForServiceViaExternalAPI", parallel=true) public static Object[][] dataProviderUpdateArtifactForServiceViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "YANG_XML"}, @@ -1361,7 +1361,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } } - @DataProvider(name="updateArtifactForVFViaExternalAPI", parallel=false) + @DataProvider(name="updateArtifactForVFViaExternalAPI", parallel=true) public static Object[][] dataProviderUpdateArtifactForVFViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_JSON"}, @@ -1423,7 +1423,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } } - @DataProvider(name="updateArtifactForVfcVlCpViaExternalAPI", parallel=false) + @DataProvider(name="updateArtifactForVfcVlCpViaExternalAPI", parallel=true) public static Object[][] dataProviderUpdateArtifactForVfcVlCpViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "YANG_XML", ResourceTypeEnum.VFC}, @@ -1533,7 +1533,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } } - @DataProvider(name="updateArtifactOfVfcVlCpForVfciVliCpiViaExternalAPI", parallel=false) + @DataProvider(name="updateArtifactOfVfcVlCpForVfciVliCpiViaExternalAPI", parallel=true) public static Object[][] dataProviderUpdateArtifactOfVfcVlCpForVfciVliCpiViaExternalAPI() { return new Object[][] { {ResourceTypeEnum.VFC}, @@ -1575,7 +1575,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="updateArtifactOnRIViaExternalAPI", parallel=false) + @DataProvider(name="updateArtifactOnRIViaExternalAPI", parallel=true) public static Object[][] dataProviderUpdateArtifactOnRIViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_INVENTORY_TOSCA", null}, @@ -1625,7 +1625,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="updateArtifactOnVfcVlCpRIViaExternalAPI", parallel=false) + @DataProvider(name="updateArtifactOnVfcVlCpRIViaExternalAPI", parallel=true) public static Object[][] dataProviderUpdateArtifactOnVfcVlCpRIViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_INVENTORY_TOSCA", ResourceTypeEnum.VFC}, @@ -1741,7 +1741,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="updateArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset", parallel=false) + @DataProvider(name="updateArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset", parallel=true) public static Object[][] dataProviderUpdateArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset() { return new Object[][] { {ComponentTypeEnum.RESOURCE, UserRoleEnum.DESIGNER2, LifeCycleStatesEnum.CHECKOUT, "OTHER"}, @@ -1803,7 +1803,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="updateArtifactOnAssetWhichNotExist", parallel=false) + @DataProvider(name="updateArtifactOnAssetWhichNotExist", parallel=true) public static Object[][] dataProviderUpdateArtifactOnAssetWhichNotExist() { return new Object[][] { {ComponentTypeEnum.SERVICE, "OTHER", null}, @@ -1866,7 +1866,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="updateArtifactOnAssetWhichInInvalidStateForUploading", parallel=false) + @DataProvider(name="updateArtifactOnAssetWhichInInvalidStateForUploading", parallel=true) public static Object[][] dataProviderUpdateProviderDeleteArtifactOnAssetWhichInInvalidStateForUploading() { return new Object[][] { {ComponentTypeEnum.SERVICE, "OTHER"}, @@ -1891,7 +1891,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { - @DataProvider(name="updateInvalidArtifactTypeExtensionLabelDescriptionCheckSumDuplicateLabelViaExternalAPI", parallel=false) + @DataProvider(name="updateInvalidArtifactTypeExtensionLabelDescriptionCheckSumDuplicateLabelViaExternalAPI", parallel=true) public static Object[][] dataProviderUpdateInvalidArtifactTypeExtensionLabelDescriptionCheckSumDuplicateLabelViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, ComponentTypeEnum.RESOURCE, "updateArtifactWithInvalidCheckSum"}, @@ -2545,7 +2545,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// - @DataProvider(name="deleteArtifactForServiceViaExternalAPI", parallel=false) + @DataProvider(name="deleteArtifactForServiceViaExternalAPI", parallel=true) public static Object[][] dataProviderDeleteArtifactForServiceViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "YANG_XML"}, @@ -2582,7 +2582,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { deleteArtifactOnAssetViaExternalAPI(component, ComponentTypeEnum.SERVICE, lifeCycleStatesEnum); } - @DataProvider(name="deleteArtifactForVFViaExternalAPI", parallel=false) + @DataProvider(name="deleteArtifactForVFViaExternalAPI", parallel=true) public static Object[][] dataProviderDeleteArtifactForVFViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_JSON"}, @@ -2638,7 +2638,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { deleteArtifactOnAssetViaExternalAPI(component, ComponentTypeEnum.RESOURCE, lifeCycleStatesEnum); } - @DataProvider(name="deleteArtifactForVfcVlCpViaExternalAPI", parallel=false) + @DataProvider(name="deleteArtifactForVfcVlCpViaExternalAPI", parallel=true) public static Object[][] dataProviderDeleteArtifactForVfcVlCpViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "YANG_XML", ResourceTypeEnum.VFC}, @@ -2742,7 +2742,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { deleteArtifactOnAssetViaExternalAPI(component, ComponentTypeEnum.RESOURCE, lifeCycleStatesEnum); } - @DataProvider(name="deleteArtifactOnRIViaExternalAPI", parallel=false) + @DataProvider(name="deleteArtifactOnRIViaExternalAPI", parallel=true) public static Object[][] dataProviderDeleteArtifactOnRIViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_INVENTORY_TOSCA", null}, @@ -2781,7 +2781,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="deleteArtifactOnVfcVlCpRIViaExternalAPI", parallel=false) + @DataProvider(name="deleteArtifactOnVfcVlCpRIViaExternalAPI", parallel=true) public static Object[][] dataProviderDeleteArtifactOnVfcVlCpRIViaExternalAPI() { return new Object[][] { {LifeCycleStatesEnum.CHECKOUT, "DCAE_INVENTORY_TOSCA", ResourceTypeEnum.VFC}, @@ -2882,7 +2882,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="deleteArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset", parallel=false) + @DataProvider(name="deleteArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset", parallel=true) public static Object[][] dataProviderDeleteArtifactOnVFViaExternalAPIByDiffrentUserThenCreatorOfAsset() { return new Object[][] { {ComponentTypeEnum.RESOURCE, UserRoleEnum.DESIGNER2, LifeCycleStatesEnum.CHECKOUT, "OTHER"}, @@ -2966,7 +2966,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="deleteArtifactOnAssetWhichNotExist", parallel=false) + @DataProvider(name="deleteArtifactOnAssetWhichNotExist", parallel=true) public static Object[][] dataProviderDeleteArtifactOnAssetWhichNotExist() { return new Object[][] { {ComponentTypeEnum.SERVICE, "OTHER", null}, @@ -3032,7 +3032,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="deleteArtifactOnAssetWhichInInvalidStateForUploading", parallel=false) + @DataProvider(name="deleteArtifactOnAssetWhichInInvalidStateForUploading", parallel=true) public static Object[][] dataProviderDeleteArtifactOnAssetWhichInInvalidStateForUploading() { return new Object[][] { {ComponentTypeEnum.SERVICE, "OTHER"}, @@ -3075,7 +3075,7 @@ public class CRUDExternalAPI extends ComponentBaseTest { } - @DataProvider(name="deleteArtifactOfVfcVlCpForVfciVliCpiViaExternalAPI", parallel=false) + @DataProvider(name="deleteArtifactOfVfcVlCpForVfciVliCpiViaExternalAPI", parallel=true) public static Object[][] dataProviderDeleteArtifactOfVfcVlCpForVfciVliCpiViaExternalAPI() { return new Object[][] { {ResourceTypeEnum.VFC}, diff --git a/test-apis-ci/src/main/resources/ci/scripts/startTest.sh b/test-apis-ci/src/main/resources/ci/scripts/startTest.sh index d3c15026cd..9268d6f761 100644 --- a/test-apis-ci/src/main/resources/ci/scripts/startTest.sh +++ b/test-apis-ci/src/main/resources/ci/scripts/startTest.sh @@ -88,7 +88,7 @@ TARGET_LOG_DIR="${TARGET_DIR}/" BE_IP=`cat conf/attsdc.yaml | grep catalogBeHost| awk '{print $2}'` ADD_USERS_SCRIPT="addUsersFromList_new.sh" -USER_LIST="userList.txt" +USER_LIST="/conf/userList.txt" chmod +x ${ADD_USERS_SCRIPT} echo "add users..." `./${ADD_USERS_SCRIPT} -ip ${BE_IP} -f ${USER_LIST}` diff --git a/test-apis-ci/src/main/resources/ci/scripts/userList.txt b/test-apis-ci/src/main/resources/ci/scripts/userList.txt index 1a2026f291..7efe975168 100644 --- a/test-apis-ci/src/main/resources/ci/scripts/userList.txt +++ b/test-apis-ci/src/main/resources/ci/scripts/userList.txt @@ -1 +1 @@ -export USER_LIST=( "m99121 DESIGNER Carlos Santana carlos@email.com" "cs0008 DESIGNER Carlos Santana carlos@email.com" "kb0004 TESTER Carlos Santana carlos@email.com" "af0006 OPS Carlos Santana carlos@email.com" "ah0002 GOVERNOR Carlos Santana carlos@email.com" "m08740 DESIGNER Carlos Santana carlos@email.com" "m99124 TESTER Carlos Santana carlos@email.com" "m08743 TESTER Carlos Santana carlos@email.com" "m99123 OPS Carlos Santana carlos@email.com" "m08742 OPS" "m99125 GOVERNOR Carlos Santana carlos@email.com" "m08744 GOVERNOR Carlos Santana carlos@email.com" "m99122 ADMIN Carlos Santana carlos@email.com" "m08741 ADMIN Carlos Santana carlos@email.com" "m99126 PRODUCT_STRATEGIST Carlos Santana carlos@email.com" "m08745 PRODUCT_STRATEGISTCarlos Santana carlos@email.com" "m99127 PRODUCT_MANAGER Carlos Santana carlos@email.com" "m08746 PRODUCT_MANAGER Carlos Santana carlos@email.com" "md9897 DESIGNER Carlos Santana carlos@email.com" "m08748 DESIGNER Carlos Santana carlos@email.com" "m08749 TESTER Carlos Santana carlos@email.com" "be0695 DESIGNER Carlos Santana carlos@email.com" "er434w DESIGNER Carlos Santana carlos@email.com" "ya107f DESIGNER Carlos Santana carlos@email.com" "ds200p DESIGNER Carlos Santana carlos@email.com" "ak0333 ADMIN Carlos Santana carlos@email.com" "th0695 DESIGNER Carlos Santana carlos@email.com" "al714h DESIGNER Carlos Santana carlos@email.com" "ys9693 DESIGNER Carlos Santana carlos@email.com" "ss8214 DESIGNER Carlos Santana carlos@email.com" "bt750h DESIGNER Carlos Santana carlos@email.com" "rp955r DESIGNER Carlos Santana carlos@email.com" "ez6451 DESIGNER Carlos Santana carlos@email.com" "ia901h DESIGNER Carlos Santana carlos@email.com" "ah7840 DESIGNER Carlos Santana carlos@email.com" "ea394r DESIGNER Carlos Santana carlos@email.com" "ms656r DESIGNER Carlos Santana carlos@email.com" "ml636r DESIGNER Carlos Santana carlos@email.com" "it1721 DESIGNER Carlos Santana carlos@email.com" "sg473v DESIGNER Carlos Santana carlos@email.com" "sa997j DESIGNER Carlos Santana carlos@email.com" "az2497 DESIGNER Carlos Santana carlos@email.com" "ys189e DESIGNER Carlos Santana carlos@email.com" "ig642y DESIGNER Carlos Santana carlos@email.com") \ No newline at end of file +export USER_LIST=( "m99121 DESIGNER Carlos Santana carlos@email.com" "cs0008 DESIGNER Carlos Santana carlos@email.com" "jm0007 TESTER Johnny Depp carlos@email.com" "gv0001 GOVERNOR David Shadmi carlos@email.com" "op0001 DESIGNER Aretha Franklin carlos@email.com" "ps0001 PRODUCT_STRATEGIST Eden Rozin carlos@email.com" "pm0001 PRODUCT_MANAGER Teddy Isashar carlos@email.com" "me0009 DESIGNER Melissa Etheridge carlos@email.com" "jm0007 TESTER Johnny Depp carlos@email.com" "af0006 OPS Carlos Santana carlos@email.com" "ah0002 GOVERNOR Carlos Santana carlos@email.com" "m08740 DESIGNER Carlos Santana carlos@email.com" "m99124 TESTER Carlos Santana carlos@email.com" "m08743 TESTER Carlos Santana carlos@email.com" "m99123 OPS Carlos Santana carlos@email.com" "m08742 OPS" "m99125 GOVERNOR Carlos Santana carlos@email.com" "m08744 GOVERNOR Carlos Santana carlos@email.com" "m99122 ADMIN Carlos Santana carlos@email.com" "m08741 ADMIN Carlos Santana carlos@email.com" "m99126 PRODUCT_STRATEGIST Carlos Santana carlos@email.com" "m08745 PRODUCT_STRATEGISTCarlos Santana carlos@email.com" "m99127 PRODUCT_MANAGER Carlos Santana carlos@email.com" "m08746 PRODUCT_MANAGER Carlos Santana carlos@email.com" "md9897 DESIGNER Carlos Santana carlos@email.com" "m08748 DESIGNER Carlos Santana carlos@email.com" "m08749 TESTER Carlos Santana carlos@email.com" "be0695 DESIGNER Carlos Santana carlos@email.com" "er434w DESIGNER Carlos Santana carlos@email.com" "ya107f DESIGNER Carlos Santana carlos@email.com" "ds200p DESIGNER Carlos Santana carlos@email.com" "ak0333 ADMIN Carlos Santana carlos@email.com" "th0695 DESIGNER Carlos Santana carlos@email.com" "al714h DESIGNER Carlos Santana carlos@email.com" "ys9693 DESIGNER Carlos Santana carlos@email.com" "ss8214 DESIGNER Carlos Santana carlos@email.com" "bt750h DESIGNER Carlos Santana carlos@email.com" "rp955r DESIGNER Carlos Santana carlos@email.com" "ez6451 DESIGNER Carlos Santana carlos@email.com" "ia901h DESIGNER Carlos Santana carlos@email.com" "ah7840 DESIGNER Carlos Santana carlos@email.com" "ea394r DESIGNER Carlos Santana carlos@email.com" "ms656r DESIGNER Carlos Santana carlos@email.com" "ml636r DESIGNER Carlos Santana carlos@email.com" "it1721 DESIGNER Carlos Santana carlos@email.com" "sg473v DESIGNER Carlos Santana carlos@email.com" "sa997j DESIGNER Carlos Santana carlos@email.com" "az2497 DESIGNER Carlos Santana carlos@email.com" "ys189e DESIGNER Carlos Santana carlos@email.com" "ig642y DESIGNER Carlos Santana carlos@email.com") \ No newline at end of file diff --git a/test-apis-ci/src/main/resources/ci/testSuites/externalAPIs.xml b/test-apis-ci/src/main/resources/ci/testSuites/externalAPIs.xml index 3505dad3c4..275d07e426 100644 --- a/test-apis-ci/src/main/resources/ci/testSuites/externalAPIs.xml +++ b/test-apis-ci/src/main/resources/ci/testSuites/externalAPIs.xml @@ -1,7 +1,7 @@ - - + + diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/US/ImportUpdateInformationalDeploymentArtifacts.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/US/ImportUpdateInformationalDeploymentArtifacts.java index 913064b7fd..8fd3c469be 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/US/ImportUpdateInformationalDeploymentArtifacts.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/US/ImportUpdateInformationalDeploymentArtifacts.java @@ -57,7 +57,7 @@ public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest { public void importVfvArtifactsDeploymentArtifactsMultipleArtifactsMultipleTypes() throws Exception { if(true){ - throw new SkipException("Open bug 197126"); + throw new SkipException("Due to the new design the test should be updated accordingly"); } String filePath = FileHandling.getFilePath(folder); @@ -118,7 +118,7 @@ public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest { public void importVfcArtifactsInformationalArtifactsOnSingleVfc() throws Exception { if(true){ - throw new SkipException("Open bug 197126"); + throw new SkipException("Due to the new design the test should be updated accordingly"); } String filePath = FileHandling.getFilePath(folder); @@ -152,7 +152,7 @@ public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest { public void importVfcArtifactsDeploymentAndInformationalArtifactsMultipleVfcs() throws Exception { if(true){ - throw new SkipException("Open bug 197126"); + throw new SkipException("Due to the new design the test should be updated accordingly"); } String filePath = FileHandling.getFilePath(folder); @@ -212,7 +212,7 @@ public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest { public void importVfcArtifactsDeploymentArtifactsExtraFolderUnderVfcIdentification() throws Exception { if(true){ - throw new SkipException("Open bug 197126"); + throw new SkipException("Due to the new design the test should be updated accordingly"); } String filePath = FileHandling.getFilePath(folder); @@ -254,7 +254,7 @@ public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest { public void importVfcArtifactsDeploymentArtifactsInvalidArtifactType() throws Exception { if(true){ - throw new SkipException("Open bug 197126"); + throw new SkipException("Due to the new design the test should be updated accordingly"); } String filePath = FileHandling.getFilePath(folder); diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/sanity/DeploymentViewTests.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/sanity/DeploymentViewTests.java index 87bf7b0506..2e25eddd2c 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/sanity/DeploymentViewTests.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/sanity/DeploymentViewTests.java @@ -43,6 +43,7 @@ import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils; import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; import org.openecomp.sdc.ci.tests.verificator.DeploymentViewVerificator; import org.openqa.selenium.WebElement; +import org.testng.SkipException; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -152,7 +153,8 @@ public class DeploymentViewTests extends SetupCDTest { } @Test - public void deploymentScreenDCAEAssetUpdateWithNewGroupWithoutMembersCSAR_TC1368280_Test() throws Exception{ + public void deploymentScreenDCAEAssetUpdateWithNewGroupWithoutMembersCSAR_TC1368280_Test() throws Exception{ + String baseFileName = "baseUpdateMinusGroupFlowVF.csar"; String updateFileName = "baseUpdateAddGroupNoMembersUpdateFlow.csar"; String updateFileName2 = "baseUpdateFlowVF.csar"; @@ -175,6 +177,10 @@ public class DeploymentViewTests extends SetupCDTest { SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating VF with new file, should be %s groups now, base_ldsa group with members", 3)); ResourceUIUtils.updateVfWithCsar(filePath, updateFileName2); + if(true){ + throw new SkipException("Open bug 305812"); + } + // validate that member was added to base_ldsa group DeploymentViewVerificator.regularDepoymentScreenVerificator(metaDataFromUI, new DeploymentViewVerificator(filePath + updateFileName2)); DeploymentViewVerificator.validateModuleNameUpadate(); @@ -207,6 +213,10 @@ public class DeploymentViewTests extends SetupCDTest { // remove artifact from every group SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating VF with new file, should be 3 artifacts in every group")); ResourceUIUtils.updateVfWithCsar(filePath, updateFileName); + + if(true){ + throw new SkipException("Open bug 306329"); + } DeploymentViewVerificator.regularDepoymentScreenVerificator(metaDataFromUI, new DeploymentViewVerificator(filePath + updateFileName)); DeploymentViewVerificator.validateModuleNameUpadate(); @@ -227,6 +237,10 @@ public class DeploymentViewTests extends SetupCDTest { // add artifact to every group SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating VF with new file, should be 4 artifacts in every group")); ResourceUIUtils.updateVfWithCsar(filePath, baseFileName); + + if(true){ + throw new SkipException("Open bug 306005"); + } DeploymentViewVerificator.regularDepoymentScreenVerificator(metaDataFromUI, new DeploymentViewVerificator(filePath + baseFileName)); DeploymentViewVerificator.validateModuleNameUpadate(); @@ -248,6 +262,10 @@ public class DeploymentViewTests extends SetupCDTest { SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating VF with new file, mixing between artifacts and groups", 3)); ResourceUIUtils.updateVfWithCsar(filePath, updateFileName); + if(true){ + throw new SkipException("Open bug 306005"); + } + DeploymentViewVerificator.regularDepoymentScreenVerificator(metaDataFromUI, new DeploymentViewVerificator()); DeploymentViewVerificator.validateModuleNameUpadate(); }; diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/sanity/VfArtifacts.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/sanity/VfArtifacts.java index 2957379ff8..cf8bfa5e5e 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/sanity/VfArtifacts.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/sanity/VfArtifacts.java @@ -54,6 +54,7 @@ import org.openecomp.sdc.ci.tests.utilities.OnboardingUtils; import org.openecomp.sdc.ci.tests.utils.Utils; import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils; import org.openqa.selenium.WebElement; +import org.testng.SkipException; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -90,11 +91,11 @@ public class VfArtifacts extends SetupCDTest{ public Object[][] provideData() { return new Object[][] { - { "2016-043_vsaegw_fdnt_30_1607_e2e.zip", "FDNT_UpdateHeatParams.zip", "2", "1" }, // expected heat version 2 and heatEnv 1 - { "2016-043_vsaegw_fdnt_30_1607_e2e.zip", "FDNT_WithoutEnvFiles.zip", "1", "1" }, // expected heat version 1 and heatEnv 1 - { "2016-014_vlandslide_ldsa_30_1607_e2e.zip", "2016-209_vjsa_vjsa_30_1610_e2e.zip", "1", "0" }, // expected heat version 1 and heatEnv 0 - { "2016-045_vlb_lmsp_30_1607_e2e.zip", "2016-045_vlb_lmsp_30_1607_e2e.zip", "1", "1" }, // expected heat version 1 and heatEnv 1(DE270634) - { "2016-109_mobt_mobt_30_1607_e2e.zip", "2016-109_mobt_mobt_30_1607_e2e_DifferentParams.zip", "2", "1" } // expected heat version 2 and heatEnv 1 + { "2016-043_vsaegw_fdnt_30_1607_e2e.zip", "FDNT_UpdateHeatParams.zip", "2", "2" }, // expected heat version 2 and heatEnv 2 + { "2016-043_vsaegw_fdnt_30_1607_e2e.zip", "FDNT_WithoutEnvFiles.zip", "1", "2" }, // expected heat version 1 and heatEnv 2 + { "2016-014_vlandslide_ldsa_30_1607_e2e.zip", "2016-209_vjsa_vjsa_30_1610_e2e.zip", "1", "1" }, // expected heat version 1 and heatEnv 1 + { "2016-045_vlb_lmsp_30_1607_e2e.zip", "2016-045_vlb_lmsp_30_1607_e2e.zip", "1", "2" }, // expected heat version 1 and heatEnv 2(DE270634) + { "2016-109_mobt_mobt_30_1607_e2e.zip", "2016-109_mobt_mobt_30_1607_e2e_DifferentParams.zip", "2", "2" } // expected heat version 2 and heatEnv 2 }; } @@ -306,7 +307,10 @@ public class VfArtifacts extends SetupCDTest{ for(Entry envFileEntry : generatedEnvFileList.entrySet()){ GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue()+envFileEntry.getKey()); ArtifactUIUtils.compareYamlFilesByPattern(envFileEntry.getValue(), FileHandling.getLastModifiedFileFromDir(), PARAMETERS); - ArtifactUIUtils.validateArtifactVersionByTypeAndLabel(envFileEntry.getKey(), "0", ArtifactTypeEnum.HEAT_ENV); + if(true){ + throw new SkipException("Test skipped, new artifact version design should be developed"); + } + ArtifactUIUtils.validateArtifactVersionByTypeAndLabel(envFileEntry.getKey(), "1", ArtifactTypeEnum.HEAT_ENV); ArtifactUIUtils.validateArtifactVersionByTypeAndLabel(envFileEntry.getKey(), "1", ArtifactTypeEnum.HEAT); } } @@ -328,12 +332,15 @@ public class VfArtifacts extends SetupCDTest{ // TODO test will pass on case all objects on deployment view are visible GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue()+envFileEntry.getKey()); ArtifactUIUtils.compareYamlFilesByPattern(envFileEntry.getValue(), FileHandling.getLastModifiedFileFromDir(), PARAMETERS); + if(true){ + throw new SkipException("Test skipped, new artifact version design should be developed"); + } ArtifactUIUtils.validateArtifactVersionByTypeAndLabel(envFileEntry.getKey(), expectedHeatEnvVersion, ArtifactTypeEnum.HEAT_ENV); ArtifactUIUtils.validateArtifactVersionByTypeAndLabel(envFileEntry.getKey(), expectedHeatVersion, ArtifactTypeEnum.HEAT); } } -// expected heat version 1 and heatEnv 2 +// expected heat version 1 and heatEnv 3 @Test public void checkDefaultCreatedEnvArtifactsVspUpdatedWithSameVspTwice() throws Throwable{ String vnfFile = "2016-044_vfw_fcgi_30_1607_e2e.zip"; @@ -351,7 +358,10 @@ public class VfArtifacts extends SetupCDTest{ for(Entry envFileEntry : generatedUpdatedSecondTimeEnvFileList.entrySet()){ GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue()+envFileEntry.getKey()); ArtifactUIUtils.compareYamlFilesByPattern(envFileEntry.getValue(), FileHandling.getLastModifiedFileFromDir(), PARAMETERS); - ArtifactUIUtils.validateArtifactVersionByTypeAndLabel(envFileEntry.getKey(), "2", ArtifactTypeEnum.HEAT_ENV); + if(true){ + throw new SkipException("Test skipped, new artifact version design should be developed"); + } + ArtifactUIUtils.validateArtifactVersionByTypeAndLabel(envFileEntry.getKey(), "3", ArtifactTypeEnum.HEAT_ENV); ArtifactUIUtils.validateArtifactVersionByTypeAndLabel(envFileEntry.getKey(), "1", ArtifactTypeEnum.HEAT); } } diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/SetupCDTest.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/SetupCDTest.java index 1838d3969d..820c6997f5 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/SetupCDTest.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/setup/SetupCDTest.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.ci.tests.execute.setup; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; import java.util.Map; @@ -30,6 +31,7 @@ import java.util.logging.Handler; import java.util.logging.LogManager; import java.util.logging.Logger; +import org.json.simple.JSONObject; import org.littleshoot.proxy.impl.ClientToProxyConnection; import org.littleshoot.proxy.impl.ProxyToServerConnection; import org.openecomp.sdc.be.model.User; @@ -43,6 +45,7 @@ import org.openecomp.sdc.ci.tests.run.StartTest; import org.openecomp.sdc.ci.tests.utilities.FileHandling; import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils; import org.openecomp.sdc.ci.tests.utilities.RestCDUtils; +import org.openecomp.sdc.ci.tests.utils.rest.AutomationUtils; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; @@ -59,6 +62,7 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; +import com.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.Status; @@ -233,16 +237,48 @@ public abstract class SetupCDTest extends DriverFactory { getCsvReport().writeRow(result.getInstanceName(), name.replace(RE_RUN,""), status); } } + + public void generateReport4Jenkins(ITestResult result, ITestContext context) { + String suiteName = ExtentManager.getSuiteName(context); +// String outputDirectory = context.getOutputDirectory(); + JSONObject obj = new JSONObject(); + String success = Integer.toString(context.getPassedTests().size()); + String failed = Integer.toString(context.getFailedTests().size()); + String total = Integer.toString(context.getFailedTests().size()+context.getPassedTests().size()); + obj.put("projectName", "SDC-ONAP-UI-Automation-"+suiteName); + obj.put("projectVersion", AutomationUtils.getOSVersion()); + obj.put("platform", "Linux"); + obj.put("total", total); + obj.put("success", success); + obj.put("failed", failed); + + try (FileWriter file = new FileWriter(getReportFolder() + "jenkinsResults.json")) { + + file.write(obj.toJSONString()); + file.flush(); + + } catch (IOException e) { + e.printStackTrace(); + } + + System.out.print(obj); + + + } + + @AfterSuite(alwaysRun = true) - public void afterSuite() throws Exception { + public void afterSuite(ITestResult result, ITestContext context) throws Exception { if (getConfig().getUseBrowserMobProxy()){ MobProxy.getPoxyServer().stop(); } csvReport.closeFile(); + generateReport4Jenkins(result, context); RestCDUtils.deleteOnDemand(); + } protected static String setUrl() { @@ -262,7 +298,9 @@ public abstract class SetupCDTest extends DriverFactory { return; } File credentialsFileRemote = new File(FileHandling.getBasePath() + File.separator + "conf" + File.separator + CREDENTIALS_FILE); - File credentialsFileLocal = new File(FileHandling.getConfFilesPath() + CREDENTIALS_FILE); +// File credentialsFileLocal = new File(FileHandling.getConfFilesPath() + CREDENTIALS_FILE); + File credentialsFileLocal = new File(FileHandling.getSdcVncPath() + File.separator + "conf" + + File.separator + CREDENTIALS_FILE); File[] credentialFiles = {credentialsFileRemote, credentialsFileLocal}; for (File credentialsFile : credentialFiles){ if (credentialsFile.exists()){ diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/ArtifactUIUtils.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/ArtifactUIUtils.java index d55ace4374..c06a51ce91 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/ArtifactUIUtils.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/ArtifactUIUtils.java @@ -352,18 +352,18 @@ public final class ArtifactUIUtils { public static void validateArtifactNameVersionType(String artifactLabel, String artifactVersion, String artifactType) { // Assert.assertEquals(GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel + "']")).getAttribute("textContent").trim(), artifactLabel); if(!GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactLabel)) { - SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact label not equal - this warnning represent defect."); + SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact label not equal - this warning represent defect."); } if(artifactVersion != null) { // Assert.assertEquals(GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + artifactLabel + "']")).getAttribute("textContent").trim(), artifactVersion, "Artifact version not equal."); if(!GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactVersion)) { - SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact version not equal - this warnning represent defect."); + SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact version not equal - this warning represent defect."); } } if(artifactType != null) { // Assert.assertEquals(GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + artifactLabel + "']")).getAttribute("textContent").trim(), artifactType, "Artifact type not equal."); if(!GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactType)) { - SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact type not equal - this warnning represent defect."); + SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact type not equal - this warning represent defect."); } } } diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/FileHandling.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/FileHandling.java index 6008f200d2..a83e26d980 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/FileHandling.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/FileHandling.java @@ -31,6 +31,7 @@ import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; @@ -108,13 +109,22 @@ public class FileHandling { return System.getProperty("user.dir") + File.separator; } + public static String getSdcVncPath() { + return Paths.get(System.getProperty("user.dir"), "..", "..", "sdc-vnfs").toString(); + } + + + public static String getDriversPath() { return getBasePath() + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "ci" + File.separator + "drivers" + File.separator; } public static String getResourcesFilesPath() { - return getBasePath() + "src" + File.separator + "main" + File.separator + "resources" +// return getBasePath() + "src" + File.separator + "main" + File.separator + "resources" +// + File.separator + "Files" + File.separator; + + return getSdcVncPath()+ File.separator + "ui-tests" + File.separator + "Files" + File.separator; } diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/OnboardingUtils.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/OnboardingUtils.java index 95fbefa040..621cc26a12 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/OnboardingUtils.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/OnboardingUtils.java @@ -767,24 +767,16 @@ public class OnboardingUtils { LinkedList deploymentArtifacts = ((LinkedList) combinedMap.get("Deployment")); ArtifactsCorrelationManager.addVNFartifactDetails(vspName, deploymentArtifacts); - List heatEnvFilesFromCSAR = deploymentArtifacts.stream().filter(e -> e.getType().equals("HEAT_ENV")). - map(e -> e.getFileName()). - collect(Collectors.toList()); - - validateDeploymentArtifactsVersion(deploymentArtifacts, heatEnvFilesFromCSAR); - + validateDeploymentArtifactsVersion(deploymentArtifacts); DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile); return createVendorSoftwareProduct; } - public static void validateDeploymentArtifactsVersion(LinkedList deploymentArtifacts, - List heatEnvFilesFromCSAR) { - String artifactVersion; + public static void validateDeploymentArtifactsVersion(LinkedList deploymentArtifacts) { + String artifactVersion = "1"; String artifactName; for(HeatMetaFirstLevelDefinition deploymentArtifact: deploymentArtifacts) { - artifactVersion = "1"; - if(deploymentArtifact.getType().equals("HEAT_ENV")) { continue; } else if(deploymentArtifact.getFileName().contains(".")) { @@ -792,10 +784,6 @@ public class OnboardingUtils { } else { artifactName = deploymentArtifact.getFileName().trim(); } - - if (heatEnvFilesFromCSAR.contains(artifactName + ".env")){ - artifactVersion = "2"; - } ArtifactUIUtils.validateArtifactNameVersionType(artifactName, artifactVersion, deploymentArtifact.getType()); } } diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/ServiceVerificator.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/ServiceVerificator.java index 2c133e6246..e4c4840450 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/ServiceVerificator.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/verificator/ServiceVerificator.java @@ -270,11 +270,6 @@ public class ServiceVerificator { } else if (propertyName.equals("max_vf_module_instances")) { actualNumber = baseNumber + 1; } else if (propertyName.equals("min_vf_module_instances")){ - - if(true){ - throw new SkipException("Open bug 305331"); - } - actualNumber = baseNumber - 1; } diff --git a/ui-ci/src/main/resources/ci/conf/credentials.yaml b/ui-ci/src/main/resources/ci/conf/credentials.yaml deleted file mode 100644 index 481b12b1e0..0000000000 --- a/ui-ci/src/main/resources/ci/conf/credentials.yaml +++ /dev/null @@ -1,48 +0,0 @@ - designer: { - username: m08740, - password: 272v!suAL37, - firstname: ASDC, - lastname: VITI - } - admin: { - username: m08741, - password: 863B@rroN27, - firstname: ASDC, - lastname: VITI - } - ops: { - username: m08742, - password: 364K!NDRed63, - firstname: ASDC, - lastname: VITI - } - tester: { - username: m08743, - password: 373m@rBLE28, - firstname: ASDC, - lastname: VITI - } - governor: { - username: m08744, - password: 742M!DDLE44, - firstname: ASDC, - lastname: VITI - } - product_strategist1: { - username: m08745, - password: 824S@Nder35, - firstname: ASDC, - lastname: VITI - } - product_manager1: { - username: m08746, - password: 747ICK!Y99, - firstname: ASDC, - lastname: VITI - } - product_local: { - username: m08747, - password: 623z!Ggy75, - firstname: ASDC, - lastname: VITI - } \ No newline at end of file diff --git a/ui-ci/src/main/resources/ci/conf/credentials.yaml_prod b/ui-ci/src/main/resources/ci/conf/credentials.yaml_prod deleted file mode 100644 index 481b12b1e0..0000000000 --- a/ui-ci/src/main/resources/ci/conf/credentials.yaml_prod +++ /dev/null @@ -1,48 +0,0 @@ - designer: { - username: m08740, - password: 272v!suAL37, - firstname: ASDC, - lastname: VITI - } - admin: { - username: m08741, - password: 863B@rroN27, - firstname: ASDC, - lastname: VITI - } - ops: { - username: m08742, - password: 364K!NDRed63, - firstname: ASDC, - lastname: VITI - } - tester: { - username: m08743, - password: 373m@rBLE28, - firstname: ASDC, - lastname: VITI - } - governor: { - username: m08744, - password: 742M!DDLE44, - firstname: ASDC, - lastname: VITI - } - product_strategist1: { - username: m08745, - password: 824S@Nder35, - firstname: ASDC, - lastname: VITI - } - product_manager1: { - username: m08746, - password: 747ICK!Y99, - firstname: ASDC, - lastname: VITI - } - product_local: { - username: m08747, - password: 623z!Ggy75, - firstname: ASDC, - lastname: VITI - } \ No newline at end of file diff --git a/ui-ci/src/main/resources/ci/conf/credentials.yaml_webtest b/ui-ci/src/main/resources/ci/conf/credentials.yaml_webtest deleted file mode 100644 index ab37f7bee8..0000000000 --- a/ui-ci/src/main/resources/ci/conf/credentials.yaml_webtest +++ /dev/null @@ -1,48 +0,0 @@ - designer: { - username: cs0008, - password: 123123a, - firstname: ASDC, - lastname: KASPIN - } - admin: { - username: jh0003, - password: 123123a, - firstname: ASDC, - lastname: KASPIN - } - ops: { - username: af0006, - password: 123123a, - firstname: ASDC, - lastname: KASPIN - } - tester: { - username: kb0004, - password: 123123a, - firstname: ASDC, - lastname: KASPIN - } - governor: { - username: ah0002, - password: 123123a, - firstname: ASDC, - lastname: KASPIN - } - product_strategist: { - username: m99126, - password: 1910-FruitGum, - firstname: ASDC, - lastname: KASPIN - } - product_manager: { - username: m99127, - password: 747-Airplane, - firstname: ASDC, - lastname: KASPIN - } - product_local: { - username: pm0001, - password: 123123a, - firstname: ASDC, - lastname: KASPIN - } \ No newline at end of file diff --git a/ui-ci/src/main/resources/ci/scripts/startTest.sh b/ui-ci/src/main/resources/ci/scripts/startTest.sh index 737b538b01..c85b6f4cf0 100644 --- a/ui-ci/src/main/resources/ci/scripts/startTest.sh +++ b/ui-ci/src/main/resources/ci/scripts/startTest.sh @@ -89,7 +89,7 @@ TARGET_LOG_DIR="${TARGET_DIR}/" BE_IP=`cat conf/attsdc.yaml | grep catalogBeHost| awk '{print $2}'` ADD_USERS_SCRIPT="addUsersFromList_new.sh" -USER_LIST="userList.txt" +USER_LIST="/conf/userList.txt" chmod +x ${ADD_USERS_SCRIPT} echo "add users..." `./${ADD_USERS_SCRIPT} -ip ${BE_IP} -f ${USER_LIST}` diff --git a/ui-ci/src/main/resources/ci/scripts/userList.txt b/ui-ci/src/main/resources/ci/scripts/userList.txt deleted file mode 100644 index 1a2026f291..0000000000 --- a/ui-ci/src/main/resources/ci/scripts/userList.txt +++ /dev/null @@ -1 +0,0 @@ -export USER_LIST=( "m99121 DESIGNER Carlos Santana carlos@email.com" "cs0008 DESIGNER Carlos Santana carlos@email.com" "kb0004 TESTER Carlos Santana carlos@email.com" "af0006 OPS Carlos Santana carlos@email.com" "ah0002 GOVERNOR Carlos Santana carlos@email.com" "m08740 DESIGNER Carlos Santana carlos@email.com" "m99124 TESTER Carlos Santana carlos@email.com" "m08743 TESTER Carlos Santana carlos@email.com" "m99123 OPS Carlos Santana carlos@email.com" "m08742 OPS" "m99125 GOVERNOR Carlos Santana carlos@email.com" "m08744 GOVERNOR Carlos Santana carlos@email.com" "m99122 ADMIN Carlos Santana carlos@email.com" "m08741 ADMIN Carlos Santana carlos@email.com" "m99126 PRODUCT_STRATEGIST Carlos Santana carlos@email.com" "m08745 PRODUCT_STRATEGISTCarlos Santana carlos@email.com" "m99127 PRODUCT_MANAGER Carlos Santana carlos@email.com" "m08746 PRODUCT_MANAGER Carlos Santana carlos@email.com" "md9897 DESIGNER Carlos Santana carlos@email.com" "m08748 DESIGNER Carlos Santana carlos@email.com" "m08749 TESTER Carlos Santana carlos@email.com" "be0695 DESIGNER Carlos Santana carlos@email.com" "er434w DESIGNER Carlos Santana carlos@email.com" "ya107f DESIGNER Carlos Santana carlos@email.com" "ds200p DESIGNER Carlos Santana carlos@email.com" "ak0333 ADMIN Carlos Santana carlos@email.com" "th0695 DESIGNER Carlos Santana carlos@email.com" "al714h DESIGNER Carlos Santana carlos@email.com" "ys9693 DESIGNER Carlos Santana carlos@email.com" "ss8214 DESIGNER Carlos Santana carlos@email.com" "bt750h DESIGNER Carlos Santana carlos@email.com" "rp955r DESIGNER Carlos Santana carlos@email.com" "ez6451 DESIGNER Carlos Santana carlos@email.com" "ia901h DESIGNER Carlos Santana carlos@email.com" "ah7840 DESIGNER Carlos Santana carlos@email.com" "ea394r DESIGNER Carlos Santana carlos@email.com" "ms656r DESIGNER Carlos Santana carlos@email.com" "ml636r DESIGNER Carlos Santana carlos@email.com" "it1721 DESIGNER Carlos Santana carlos@email.com" "sg473v DESIGNER Carlos Santana carlos@email.com" "sa997j DESIGNER Carlos Santana carlos@email.com" "az2497 DESIGNER Carlos Santana carlos@email.com" "ys189e DESIGNER Carlos Santana carlos@email.com" "ig642y DESIGNER Carlos Santana carlos@email.com") \ No newline at end of file -- cgit 1.2.3-korg